summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp196
-rw-r--r--noncore/apps/checkbook/cbinfo.h97
-rw-r--r--noncore/apps/checkbook/checkbook.cpp223
-rw-r--r--noncore/apps/checkbook/checkbook.h21
-rw-r--r--noncore/apps/checkbook/checkbook.pro4
-rw-r--r--noncore/apps/checkbook/configuration.cpp76
-rw-r--r--noncore/apps/checkbook/configuration.h51
-rw-r--r--noncore/apps/checkbook/graph.cpp9
-rw-r--r--noncore/apps/checkbook/graph.h1
-rw-r--r--noncore/apps/checkbook/graphinfo.h2
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp226
-rw-r--r--noncore/apps/checkbook/mainwindow.h22
-rw-r--r--noncore/apps/checkbook/traninfo.h2
13 files changed, 720 insertions, 210 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp
new file mode 100644
index 0000000..3a39317
--- a/dev/null
+++ b/noncore/apps/checkbook/cbinfo.cpp
@@ -0,0 +1,196 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "cbinfo.h"
+#include "traninfo.h"
+
+#include <qpe/config.h>
+
+#include <qfile.h>
+
+CBInfo::CBInfo()
+{
+ n = "";
+ fn = "";
+ pw = QString::null;
+ t = "";
+ bn = "";
+ a = "";
+ p = "";
+ nt = "";
+ sb = 0.0;
+
+ tl = new TranInfoList();
+}
+
+CBInfo::CBInfo( const QString &name, const QString &filename )
+{
+ Config config( filename, Config::File );
+ config.setGroup( "Account" );
+
+ n = name;
+ fn = filename;
+ pw = config.readEntryCrypt( "Password", QString::null );
+
+ t = config.readEntry( "Type" );
+ bn = config.readEntry( "Bank", "" );
+ a = config.readEntryCrypt( "Number", "" );
+ p = config.readEntryCrypt( "PINNumber", "" );
+ nt = config.readEntry( "Notes", "" );
+
+ bool ok;
+ sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok );
+
+ loadTransactions();
+}
+
+float CBInfo::balance()
+{
+ calcBalance();
+ return b;
+}
+
+void CBInfo::write()
+{
+ QFile f( fn );
+ if ( f.exists() )
+ {
+ f.remove();
+ }
+
+ Config *config = new Config(fn, Config::File);
+
+ // Save info
+ config->setGroup( "Account" );
+ config->writeEntryCrypt( "Password", pw );
+ config->writeEntry( "Type", t );
+ config->writeEntry( "Bank", bn );
+ config->writeEntryCrypt( "Number", a );
+ config->writeEntryCrypt( "PINNumber", p );
+ config->writeEntry( "Notes", n );
+ QString balstr;
+ balstr.setNum( sb, 'f', 2 );
+ config->writeEntry( "Balance", balstr );
+
+ // Save transactions
+ int i = 1;
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
+ {
+ tran->write( config, i );
+ i++;
+ }
+ config->write();
+
+ delete config;
+}
+
+TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date,
+ const QString &desc )
+{
+ TranInfo *traninfo = tl->first();
+ while ( traninfo )
+ {
+ if ( traninfo->number() == checknum && traninfo->datestr() == date &&
+ traninfo->desc() == desc )
+ break;
+ traninfo = tl->next();
+ }
+ return( traninfo );
+}
+
+void CBInfo::addTransaction( TranInfo *tran )
+{
+ tl->inSort( tran );
+ calcBalance();
+}
+
+void CBInfo::removeTransaction( TranInfo *tran )
+{
+ tl->remove( tran );
+ delete tran;
+ calcBalance();
+}
+
+void CBInfo::loadTransactions()
+{
+ TranInfo *tran;
+ QString trandesc = "";
+
+ tl = new TranInfoList();
+
+ Config config( fn, Config::File );
+
+ for ( int i = 1; trandesc != QString::null; i++ )
+ {
+ tran = new TranInfo( config, i );
+ trandesc = tran->desc();
+ if ( trandesc != QString::null )
+ {
+ tl->inSort( tran );
+ }
+ else
+ {
+ delete tran;
+ }
+ }
+
+ calcBalance();
+}
+
+void CBInfo::calcBalance()
+{
+ float amount;
+
+ b = sb;
+
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
+ {
+ b -= tran->fee();
+ amount = tran->amount();
+ if ( tran->withdrawal() )
+ {
+ amount *= -1;
+ }
+ b += amount;
+ }
+}
+
+int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
+{
+ QString n1 = ((CBInfo *)item1)->name();
+ QString n2 = ((CBInfo *)item2)->name();
+ int r = -1;
+
+ if ( n1 < n2 )
+ r = -1;
+ else if ( n1 == n2 )
+ r = 0;
+ else if ( n1 > n2 )
+ r = 1;
+ return( r );
+}
diff --git a/noncore/apps/checkbook/cbinfo.h b/noncore/apps/checkbook/cbinfo.h
new file mode 100644
index 0000000..5e65db2
--- a/dev/null
+++ b/noncore/apps/checkbook/cbinfo.h
@@ -0,0 +1,97 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef CBINFO_H
+#define CBINFO_H
+
+#include <qlist.h>
+#include <qstring.h>
+
+class Config;
+class TranInfo;
+class TranInfoList;
+
+class CBInfo
+{
+ public:
+ CBInfo();
+ CBInfo( const QString &, const QString & );
+
+ const QString &name() const { return n; }
+ const QString &filename() const { return fn; }
+ const QString &password() const { return pw; }
+ const QString &type() const { return t; }
+ const QString &bank() const { return bn; }
+ const QString &account() const { return a; }
+ const QString &pin() const { return p; }
+ const QString &notes() const { return nt; }
+ float startingBalance() const { return sb; }
+ float balance();
+
+ void setName( const QString &name ) { n = name; }
+ void setFilename( const QString &filename ) { fn = filename; }
+ void setPassword( const QString &password ) { pw = password; }
+ void setType( const QString &type ) { t = type; }
+ void setBank( const QString &bank ) { bn = bank; }
+ void setAccount( const QString &account ) { a = account; }
+ void setPin( const QString &pin ) { p = pin; }
+ void setNotes( const QString &notes ) { nt = notes; }
+ void setStartingBalance( float startbal ) { sb = startbal; }
+
+ void write();
+
+ TranInfoList *transactions() const { return tl; }
+ TranInfo *findTransaction( const QString &, const QString &, const QString & );
+ void addTransaction( TranInfo * );
+ void removeTransaction( TranInfo * );
+
+ private:
+ QString n;
+ QString fn;
+ QString pw;
+ QString t;
+ QString bn;
+ QString a;
+ QString p;
+ QString nt;
+ float sb;
+ float b;
+
+ TranInfoList *tl;
+
+ void loadTransactions();
+ void calcBalance();
+};
+
+class CBInfoList : public QList<CBInfo>
+{
+ protected:
+ int compareItems( QCollection::Item, QCollection::Item );
+};
+
+#endif
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 5a6d607..7a6b7cc 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -24,13 +24,15 @@
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "checkbook.h"
+#include "cbinfo.h"
#include "transaction.h"
+#include "traninfo.h"
#include "graph.h"
#include "graphinfo.h"
#include "password.h"
#include <opie/otabwidget.h>
#include <qpe/config.h>
@@ -47,26 +49,21 @@
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
#include <qwidget.h>
-Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol )
+Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
- name = n;
- filename = fd;
- filename.append( name );
- filename.append( ".qcb" );
- filedir = fd;
+ info = i;
currencySymbol = symbol;
- currBalance = 0.0;
- if ( name != "" )
+ if ( info->name() != "" )
{
- QString tempstr = name;
+ QString tempstr = info->name();
tempstr.append( " - " );
tempstr.append( tr( "Checkbook" ) );
setCaption( tempstr );
}
else
{
@@ -92,17 +89,12 @@ Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, cons
}
Checkbook::~Checkbook()
{
}
-const QString &Checkbook::getName()
-{
- return( name );
-}
-
QWidget *Checkbook::initInfo()
{
QWidget *control = new QWidget( mainWidget );
QVBoxLayout *vb = new QVBoxLayout( control );
@@ -270,161 +262,121 @@ QWidget *Checkbook::initCharts()
return control;
}
void Checkbook::loadCheckbook()
{
- transactions.clear();
-
- Config config( filename, Config::File );
+ if ( !info )
+ {
+ return;
+ }
- // Load info
- config.setGroup( "Account" );
+ tranList = info->transactions();
- password = config.readEntryCrypt( "Password", "" );
- passwordCB->setChecked( password != "" );
- nameEdit->setText( name );
- QString temptext = config.readEntry( "Type" );
+ passwordCB->setChecked( !info->password().isNull() );
+ nameEdit->setText( info->name() );
+ QString temptext = info->type();
int i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
- bankEdit->setText( config.readEntry( "Bank", "" ) );
- acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) );
- pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) );
- balanceEdit->setText( config.readEntry( "Balance", "0.0" ) );
- notesEdit->setText( config.readEntry( "Notes", "" ) );
-
- bool ok;
- currBalance = balanceEdit->text().toFloat( &ok );
- startBalance = currBalance;
+ bankEdit->setText( info->bank() );
+ acctNumEdit->setText( info->account() );
+ pinNumEdit->setText( info->pin() );
+ temptext.setNum( info->startingBalance(), 'f', 2 );
+ balanceEdit->setText( temptext );
+ notesEdit->setText( info->notes() );
// Load transactions
- TranInfo *tran;
- QString trandesc = "";
float amount;
QString stramount;
- for ( int i = 1; trandesc != QString::null; i++ )
- {
- tran = new TranInfo( config, i );
- trandesc = tran->desc();
- if ( trandesc != QString::null )
+
+ for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
- currBalance -= tran->fee();
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
- currBalance += amount;
stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
-
- // Add to transaction list
- transactions.inSort( tran );
-
- // Add to transaction table
- ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount );
+ ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount );
}
- else
- {
- delete tran;
- }
- }
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
- highTranNum = transactions.count();
+ balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
+
+ highTranNum = tranList->count();
}
-void Checkbook::adjustBalance( float amount )
+void Checkbook::adjustBalance()
{
- currBalance += amount;
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
-
+ balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
}
TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
{
- TranInfo *traninfo = transactions.first();
+ TranInfo *traninfo = tranList->first();
while ( traninfo )
{
if ( traninfo->number() == checknum && traninfo->datestr() == date &&
traninfo->desc() == desc )
break;
- traninfo = transactions.next();
+ traninfo = tranList->next();
}
return( traninfo );
}
void Checkbook::accept()
{
- QFile f( filename );
- if ( f.exists() )
- {
- f.remove();
- }
-
- Config *config = new Config(filename, Config::File);
-
- // Save info
- config->setGroup( "Account" );
- config->writeEntryCrypt( "Password", password );
- config->writeEntry( "Type", typeList->currentText() );
- config->writeEntry( "Bank", bankEdit->text() );
- config->writeEntryCrypt( "Number", acctNumEdit->text() );
- config->writeEntryCrypt( "PINNumber", pinNumEdit->text() );
- config->writeEntry( "Balance", balanceEdit->text() );
- config->writeEntry( "Notes", notesEdit->text() );
-
- // Save transactions
- int i = 1;
- for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
- {
- tran->write( config, i );
- i++;
- }
- config->write();
+ info->setName( nameEdit->text() );
+ info->setType( typeList->currentText() );
+ info->setBank( bankEdit->text() );
+ info->setAccount( acctNumEdit->text() );
+ info->setPin( pinNumEdit->text() );
+ bool ok;
+ info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
+ info->setNotes( notesEdit->text() );
QDialog::accept();
}
void Checkbook::slotPasswordClicked()
{
- if ( password == "" && passwordCB->isChecked() )
+ if ( info->password().isNull() && passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
if ( pw->exec() != QDialog::Accepted )
{
passwordCB->setChecked( FALSE );
delete pw;
return;
}
- password = pw->password;
+ info->setPassword( pw->password );
delete pw;
pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) );
- if ( pw->exec() != QDialog::Accepted || pw->password != password )
+ if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
{
passwordCB->setChecked( FALSE );
- password = "";
+ info->setPassword( QString::null );
}
delete pw;
}
- else if ( password != "" && !passwordCB->isChecked() )
+ else if ( !info->password().isNull() && !passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ),
tr( "Please enter your password to confirm removal of password protection:" ) );
- if ( pw->exec() == QDialog::Accepted && pw->password == password )
+ if ( pw->exec() == QDialog::Accepted && pw->password == info->password() )
{
- password = "";
+ info->setPassword( QString::null );
delete pw;
return;
}
else
{
passwordCB->setChecked( TRUE );
@@ -433,57 +385,62 @@ void Checkbook::slotPasswordClicked()
delete pw;
}
}
void Checkbook::slotNameChanged( const QString &newname )
{
- name = newname;
- filename = filedir;
- filename.append( newname );
- filename.append( ".qcb" );
- QString tempstr = name;
- tempstr.append( " - " );
- tempstr.append( tr( "Checkbook" ) );
- setCaption( tempstr );
+ info->setName( newname );
+
+ // TODO - need filedir
+// QString namestr = filedir;
+// namestr.append( newname );
+// namestr.append( ".qcb" );
+// info->setFilename( namestr );
+
+ QString namestr = newname;
+ namestr.append( " - " );
+ namestr.append( tr( "Checkbook" ) );
+ setCaption( namestr );
}
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
- currBalance -= startBalance;
bool ok;
- startBalance = newbalance.toFloat( &ok );
- adjustBalance( startBalance );
+ info->setStartingBalance( newbalance.toFloat( &ok ) );
+ adjustBalance();
}
void Checkbook::slotNewTran()
{
highTranNum++;
TranInfo *traninfo = new TranInfo( highTranNum );
- Transaction *currtran = new Transaction( this, name,
+ Transaction *currtran = new Transaction( this, info->name(),
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
- float amount = traninfo->amount();
+ // Add to transaction list
+ info->addTransaction( traninfo );
+
+ // Add to transaction table
+ float amount;
+ QString stramount;
+
+ amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
- QString stramount;
stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
- // Add to transaction list
- transactions.inSort( traninfo );
-
- // Add to transaction table
( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
stramount );
- adjustBalance( amount );
+ adjustBalance();
}
else
{
highTranNum--;
delete traninfo;
}
@@ -494,45 +451,39 @@ void Checkbook::slotEditTran()
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
- TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
- float origamt = traninfo->amount();
- if ( traninfo->withdrawal() )
- {
- origamt *= -1;
- }
+ TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ),
+ curritem->text( 2 ) );
- Transaction *currtran = new Transaction( this, name,
+ Transaction *currtran = new Transaction( this, info->name(),
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
+ curritem->setText( 0, traninfo->number() );
curritem->setText( 1, traninfo->datestr() );
-
curritem->setText( 2, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
- adjustBalance( origamt * -1 );
- adjustBalance( amount );
QString stramount;
stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
curritem->setText( 3, stramount );
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
+ adjustBalance();
+ }
delete currtran;
}
-}
void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
@@ -540,23 +491,15 @@ void Checkbook::slotDeleteTran()
}
TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
- float amount = traninfo->amount();
- if ( traninfo->withdrawal() )
- {
- amount *= -1;
- }
-
- transactions.remove( traninfo );
- delete traninfo;
+ info->removeTransaction( traninfo );
delete curritem;
-
- adjustBalance( amount * -1 );
+ adjustBalance();
}
}
void Checkbook::slotDrawGraph()
{
if ( graphInfo )
@@ -579,19 +522,19 @@ void Checkbook::slotDrawGraph()
}
void Checkbook::drawBalanceChart()
{
DataPointList *list = new DataPointList();
- float balance = startBalance;
+ float balance = info->startingBalance();
float amount;
QString label;
int i = 0;
- int count = transactions.count();
+ int count = tranList->count();
- for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
+ for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
i++;
balance -= tran->fee();
amount = tran->amount();
if ( tran->withdrawal() )
{
@@ -613,21 +556,21 @@ void Checkbook::drawBalanceChart()
}
void Checkbook::drawCategoryChart( bool withdrawals )
{
DataPointList *list = new DataPointList();
- TranInfo *tran = transactions.first();
+ TranInfo *tran = tranList->first();
if ( tran && tran->withdrawal() == withdrawals )
{
list->append( new DataPointInfo( tran->category(), tran->amount() ) );
}
- tran = transactions.next();
+ tran = tranList->next();
DataPointInfo *cat;
- for ( ; tran; tran = transactions.next() )
+ for ( ; tran; tran = tranList->next() )
{
if ( tran->withdrawal() == withdrawals )
{
// Find category in list
for ( cat = list->first(); cat; cat = list->next() )
{
diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h
index 27658ff..4a5011b 100644
--- a/noncore/apps/checkbook/checkbook.h
+++ b/noncore/apps/checkbook/checkbook.h
@@ -26,71 +26,64 @@
*/
#ifndef CHECKBOOK_H
#define CHECKBOOK_H
-#include "traninfo.h"
-
#include <qdialog.h>
#include <qlistview.h>
class OTabWidget;
+class CBInfo;
class Graph;
class GraphInfo;
class QCheckBox;
class QComboBox;
class QLabel;
class QLineEdit;
class QListView;
class QMultiLineEdit;
class QString;
+class TranInfo;
+class TranInfoList;
class Checkbook : public QDialog
{
Q_OBJECT
public:
- Checkbook( QWidget * = 0x0, const QString & = 0x0, const QString & = 0x0,
- const QString & = "$" );
+ Checkbook( QWidget * = 0x0, CBInfo * = 0x0, const QString & = "$" );
~Checkbook();
- const QString &getName();
-
private:
- TranInfoList transactions;
- QString name;
- QString filename;
- QString filedir;
+ CBInfo *info;
+ TranInfoList *tranList;
QString currencySymbol;
- QString password;
int highTranNum;
OTabWidget *mainWidget;
void loadCheckbook();
- void adjustBalance( float );
+ void adjustBalance();
TranInfo *findTran( const QString &, const QString &, const QString & );
// Info tab
QWidget *initInfo();
QCheckBox *passwordCB;
QLineEdit *nameEdit;
QComboBox *typeList;
QLineEdit *bankEdit;
QLineEdit *acctNumEdit;
QLineEdit *pinNumEdit;
QLineEdit *balanceEdit;
QMultiLineEdit *notesEdit;
- float startBalance;
// Transactions tab
QWidget *initTransactions();
QListView *tranTable;
QLabel *balanceLabel;
- float currBalance;
// Charts tab
QWidget *initCharts();
GraphInfo *graphInfo;
QComboBox *graphList;
Graph *graphWidget;
diff --git a/noncore/apps/checkbook/checkbook.pro b/noncore/apps/checkbook/checkbook.pro
index 53b5ff4..05cac15 100644
--- a/noncore/apps/checkbook/checkbook.pro
+++ b/noncore/apps/checkbook/checkbook.pro
@@ -1,19 +1,23 @@
TEMPLATE = app
CONFIG = qt warn_on release
HEADERS = mainwindow.h \
+ cbinfo.h \
traninfo.h \
graphinfo.h \
+ configuration.h \
password.h \
checkbook.h \
transaction.h \
graph.h
SOURCES = main.cpp \
mainwindow.cpp \
+ cbinfo.cpp \
traninfo.cpp \
graphinfo.cpp \
+ configuration.cpp \
password.cpp \
checkbook.cpp \
transaction.cpp \
graph.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp
new file mode 100644
index 0000000..37208da
--- a/dev/null
+++ b/noncore/apps/checkbook/configuration.cpp
@@ -0,0 +1,76 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "configuration.h"
+
+#include <qcheckbox.h>
+#include <qfontmetrics.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qstring.h>
+#include <qwhatsthis.h>
+
+Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool sb )
+ : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
+{
+ setCaption( tr( "Configure Checkbook" ) );
+
+ QFontMetrics fm = fontMetrics();
+ int fh = fm.height();
+
+ QGridLayout *layout = new QGridLayout( this );
+ layout->setSpacing( 4 );
+ layout->setMargin( 4 );
+
+ QLabel *label = new QLabel( tr( "Enter currency symbol:" ), this );
+ QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) );
+ label->setMaximumHeight( fh + 3 );
+ layout->addWidget( label, 0, 0 );
+
+ symbolEdit = new QLineEdit( cs, this );
+ QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) );
+ symbolEdit->setMaximumHeight( fh + 5 );
+ symbolEdit->setFocus();
+ layout->addWidget( symbolEdit, 0, 1 );
+
+ lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), this );
+ QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) );
+ lockCB->setChecked( sl );
+ layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 );
+
+ balCB = new QCheckBox( tr( "Show checkbook balances" ), this );
+ QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) );
+ balCB->setMaximumHeight( fh + 5 );
+ balCB->setChecked( sb );
+ layout->addMultiCellWidget( balCB, 2, 2, 0, 1 );
+}
+
+Configuration::~Configuration()
+{
+}
diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h
new file mode 100644
index 0000000..9a8de02
--- a/dev/null
+++ b/noncore/apps/checkbook/configuration.h
@@ -0,0 +1,51 @@
+/*
+                This file is part of the OPIE Project
+ =.
+             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef CONFIGURATION_H
+#define CONFIGURATION_H
+
+#include <qdialog.h>
+
+class QCheckBox;
+class QLineEdit;
+class QString;
+
+class Configuration : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ Configuration( QWidget * = 0x0, const QString & = "$", bool = FALSE, bool = FALSE );
+ ~Configuration();
+
+ QLineEdit *symbolEdit;
+ QCheckBox *lockCB;
+ QCheckBox *balCB;
+};
+
+#endif
diff --git a/noncore/apps/checkbook/graph.cpp b/noncore/apps/checkbook/graph.cpp
index 8ae835c..acdb846 100644
--- a/noncore/apps/checkbook/graph.cpp
+++ b/noncore/apps/checkbook/graph.cpp
@@ -84,17 +84,12 @@ void Graph::initGraph()
{
case GraphInfo::BarChart :
{
drawBarChart( width(), height(), data->maxValue() );
}
break;
- case GraphInfo::LineChart :
- {
- //drawLineChart( p, s, min, max );
- }
- break;
case GraphInfo::PieChart :
{
drawPieChart( width(), height(), data->totalValue() );
}
};
}
@@ -129,16 +124,12 @@ void Graph::drawBarChart( int width, int height, float max )
// WordBreak | AlignTop | AlignHCenter, dp->label() );
i++;
x += bw;
}
}
-void Graph::drawLineChart( int width, int height, float max )
-{
-}
-
void Graph::drawPieChart( int width, int height, float sum )
{
QPainter p( &graph );
// Try to set the font size smaller for text
QFont f = font();
diff --git a/noncore/apps/checkbook/graph.h b/noncore/apps/checkbook/graph.h
index 0361718..340e910 100644
--- a/noncore/apps/checkbook/graph.h
+++ b/noncore/apps/checkbook/graph.h
@@ -54,11 +54,10 @@ class Graph : public QWidget
GraphInfo *data;
QPixmap graph;
void initGraph();
void drawBarChart( int, int, float );
- void drawLineChart( int, int, float );
void drawPieChart( int, int, float );
};
#endif
diff --git a/noncore/apps/checkbook/graphinfo.h b/noncore/apps/checkbook/graphinfo.h
index 3bcf676..41927b4 100644
--- a/noncore/apps/checkbook/graphinfo.h
+++ b/noncore/apps/checkbook/graphinfo.h
@@ -52,13 +52,13 @@ class DataPointInfo
typedef QList<DataPointInfo> DataPointList;
class GraphInfo
{
public:
- enum GraphType { BarChart, LineChart, PieChart };
+ enum GraphType { BarChart, PieChart };
GraphInfo( GraphType = BarChart, DataPointList * = 0x0,
const QString & = 0x0, const QString & = 0x0, const QString & = 0x0 );
~GraphInfo();
GraphInfo::GraphType graphType();
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index 2c0abf1..68c6aee 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -24,36 +24,48 @@
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "mainwindow.h"
+#include "cbinfo.h"
+#include "configuration.h"
#include "password.h"
#include "checkbook.h"
#include <qpe/config.h>
#include <qpe/global.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpemessagebox.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qaction.h>
+#include <qcheckbox.h>
#include <qdir.h>
-#include <qlistbox.h>
+#include <qlineedit.h>
+#include <qlistview.h>
#include <qpopupmenu.h>
#include <qstring.h>
#include <qwhatsthis.h>
MainWindow::MainWindow()
: QMainWindow( 0x0, 0x0, WStyle_ContextHelp )
{
setCaption( tr( "Checkbook" ) );
cbDir = Global::applicationFileName( "checkbook", "" );
+ lockIcon = Resource::loadPixmap( "locked" );
+
+ // Load configuration options
+ Config config( "checkbook" );
+ config.setGroup( "Config" );
+ currencySymbol = config.readEntry( "CurrencySymbol", "$" );
+ showLocks = config.readBoolEntry( "ShowLocks", FALSE );
+ showBalances = config.readBoolEntry( "ShowBalances", FALSE );
// Build menu and tool bars
setToolBarsMovable( FALSE );
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
@@ -79,108 +91,242 @@ MainWindow::MainWindow()
0, this, 0 );
actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) );
connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) );
actionDelete->addTo( popup );
actionDelete->addTo( bar );
- mb->insertItem( tr( "Checkbook" ), popup );
+ popup->insertSeparator();
- // Build Checkbook selection list control
- cbList = new QListBox( this );
- QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
- QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
- connect( cbList, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint & ) ),
- this, SLOT( slotEdit() ) );
- setCentralWidget( cbList );
+ a = new QAction( tr( "Configure" ), Resource::loadPixmap( "checkbook/config" ), QString::null, 0, this, 0 );
+ a->setWhatsThis( tr( "Click here to configure this app." ) );
+ connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) );
+ a->addTo( popup );
+ a->addTo( bar );
+
+ mb->insertItem( tr( "Checkbook" ), popup );
// Load Checkbook selection list
+ checkbooks = new CBInfoList();
+
QDir checkdir( cbDir );
if (checkdir.exists() == true)
{
- QStringList checkbooks = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
+ QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
QDir::Time );
- for ( QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++ )
+ CBInfo *cb = 0x0;
+ QString filename;
+
+ for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ )
{
- (*it) = (*it).remove( (*it).find('.'), (*it).length() );
+ filename = cbDir;
+ filename.append( (*it) );
+
+ cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename );
+ checkbooks->inSort( cb );
}
- cbList->insertStringList( checkbooks );
}
- cbList->sort();
- cbList->setSelected( 0, TRUE );
- currencySymbol = "$";
+ // Build Checkbook selection list control
+ cbList = 0x0;
+ buildList();
}
MainWindow::~MainWindow()
{
+// config.write();
+}
+
+void MainWindow::buildList()
+{
+ if ( cbList )
+ {
+ delete cbList;
+ }
+
+ cbList = new QListView( this );
+ QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
+
+ if ( showLocks )
+ {
+ cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
+ posName = 1;
+ }
+ else
+ {
+ posName = 0;
+ }
+ cbList->addColumn( tr( "Checkbook Name" ) );
+ if ( showBalances )
+ {
+ int colnum = cbList->addColumn( tr( "Balance" ) );
+ cbList->setColumnAlignment( colnum, Qt::AlignRight );
+ }
+ cbList->setAllColumnsShowFocus( TRUE );
+ cbList->setSorting( posName );
+ QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
+ connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
+ this, SLOT( slotEdit() ) );
+ setCentralWidget( cbList );
+
+ for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
+ {
+ addCheckbook( cb );
+ }
+}
+
+void MainWindow::addCheckbook( CBInfo *cb )
+{
+ QListViewItem *lvi = new QListViewItem( cbList );
+ if ( showLocks && !cb->password().isNull() )
+ {
+ lvi->setPixmap( 0, lockIcon );
+ }
+ lvi->setText( posName, cb->name() );
+ if ( showBalances )
+ {
+ QString balance;
+ balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ lvi->setText( posName + 1, balance );
+ }
+}
+
+void MainWindow::buildFilename( const QString &name )
+{
+ tempFilename = cbDir;
+ tempFilename.append( name );
+ tempFilename.append( ".qcb" );
}
void MainWindow::slotNew()
{
- Checkbook *currcb = new Checkbook( this, "", cbDir, currencySymbol );
+ CBInfo *cb = new CBInfo();
+
+ Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
- cbList->insertItem( currcb->getName() );
- cbList->sort();
- delete currcb;
+ checkbooks->inSort( cb );
+ addCheckbook( cb );
}
+ delete currcb;
}
void MainWindow::slotEdit()
{
- QString currname = cbList->currentText();
- QString tempstr = cbDir;
- tempstr.append( currname );
- tempstr.append( ".qcb" );
+ QListViewItem *curritem = cbList->currentItem();
+ if ( !curritem )
+ {
+ return;
+ }
+ QString currname = curritem->text( posName );
- Config config( tempstr, Config::File );
- config.setGroup( "Account" );
- QString password = config.readEntryCrypt( "Password", "" );
- if ( password != "" )
+ CBInfo *cb = checkbooks->first();
+ while ( cb )
+ {
+ if ( cb->name() == currname )
+ break;
+ cb = checkbooks->next();
+ }
+ if ( !cb )
+ {
+ return;
+ }
+
+ buildFilename( currname );
+ float currbalance = cb->balance();
+ bool currlock = !cb->password().isNull();
+
+ if ( currlock )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
- if ( pw->exec() != QDialog::Accepted || pw->password != password )
+ if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
{
delete pw;
return;
}
delete pw;
}
- Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol );
+ Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
- QString newname = currcb->getName();
+ QString newname = cb->name();
if ( currname != newname )
{
- cbList->changeItem( newname, cbList->currentItem() );
+ // Update name if changed
+ curritem->setText( posName, newname );
cbList->sort();
- QFile f( tempstr );
+ // Remove old file
+ QFile f( tempFilename );
if ( f.exists() )
{
f.remove();
}
+
+ // Get new filename
+ buildFilename( newname );
+ cb->setFilename( tempFilename );
}
- delete currcb;
+
+ cb->write();
+
+ // Update lock if changed
+ if ( showLocks && !cb->password().isNull() != currlock )
+ {
+ if ( !cb->password().isNull() )
+ curritem->setPixmap( 0, lockIcon );
+ else
+ curritem->setPixmap( 0, nullIcon );
}
+
+ // Update balance if changed
+ if ( showBalances && cb->balance() != currbalance )
+ {
+ QString tempstr;
+ tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ curritem->setText( posName + 1, tempstr );
+ }
+ }
+ delete currcb;
}
void MainWindow::slotDelete()
{
- if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), cbList->currentText() ) )
+ QString currname = cbList->currentItem()->text( posName );
+
+ if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
{
- QString tempstr = cbDir;
- tempstr.append( cbList->currentText() );
- tempstr.append( ".qcb" );
- QFile f( tempstr );
+ buildFilename( currname );
+ QFile f( tempFilename );
if ( f.exists() )
{
f.remove();
}
- cbList->removeItem( cbList->currentItem() );
+ delete cbList->currentItem();
+ }
+}
+
+void MainWindow::slotConfigure()
+{
+ Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances );
+ cfgdlg->showMaximized();
+ if ( cfgdlg->exec() == QDialog::Accepted )
+ {
+ currencySymbol = cfgdlg->symbolEdit->text();
+ showLocks = cfgdlg->lockCB->isChecked();
+ showBalances = cfgdlg->balCB->isChecked();
+
+ Config config( "checkbook" );
+ config.setGroup( "Config" );
+ config.writeEntry( "CurrencySymbol", currencySymbol );
+ config.writeEntry( "ShowLocks", showLocks );
+ config.writeEntry( "ShowBalances", showBalances );
+ config.write();
+
+ buildList();
}
+ delete cfgdlg;
}
diff --git a/noncore/apps/checkbook/mainwindow.h b/noncore/apps/checkbook/mainwindow.h
index 11a3343..2bc70b3 100644
--- a/noncore/apps/checkbook/mainwindow.h
+++ b/noncore/apps/checkbook/mainwindow.h
@@ -27,34 +27,50 @@
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <qmainwindow.h>
+#include <qpixmap.h>
+class CBInfo;
+class CBInfoList;
class QAction;
-class QListBox;
-class QListBoxItem;
+class QListView;
class QString;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private:
- QListBox *cbList;
+ QListView *cbList;
QString cbDir;
QAction *actionOpen;
QAction *actionDelete;
+
QString currencySymbol;
+ bool showLocks;
+ bool showBalances;
+ int posName;
+
+ CBInfoList *checkbooks;
+ QString tempFilename;
+ QPixmap lockIcon;
+ QPixmap nullIcon;
+
+ void buildList();
+ void addCheckbook( CBInfo * );
+ void buildFilename( const QString & );
private slots:
void slotNew();
void slotEdit();
void slotDelete();
+ void slotConfigure();
};
#endif
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h
index 59cfe14..5f67262 100644
--- a/noncore/apps/checkbook/traninfo.h
+++ b/noncore/apps/checkbook/traninfo.h
@@ -84,9 +84,7 @@ class TranInfo
class TranInfoList : public QList<TranInfo>
{
protected:
int compareItems( QCollection::Item, QCollection::Item );
};
-//typedef TranList<TranInfo> TranInfoList;
-
#endif