-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 196 | ||||
-rw-r--r-- | noncore/apps/checkbook/cbinfo.h | 97 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 223 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.h | 21 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.pro | 4 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.cpp | 76 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.h | 51 | ||||
-rw-r--r-- | noncore/apps/checkbook/graph.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/checkbook/graph.h | 1 | ||||
-rw-r--r-- | noncore/apps/checkbook/graphinfo.h | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 226 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.h | 22 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.h | 2 |
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 ¬es() 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 ¬es ) { 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 @@ -27,7 +27,9 @@ */ #include "checkbook.h" +#include "cbinfo.h" #include "transaction.h" +#include "traninfo.h" #include "graph.h" #include "graphinfo.h" #include "password.h" @@ -50,20 +52,15 @@ #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 ); @@ -95,11 +92,6 @@ Checkbook::~Checkbook() { } -const QString &Checkbook::getName() -{ - return( name ); -} - QWidget *Checkbook::initInfo() { QWidget *control = new QWidget( mainWidget ); @@ -273,17 +265,16 @@ QWidget *Checkbook::initCharts() 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 ) { @@ -294,107 +285,68 @@ void Checkbook::loadCheckbook() 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 ) @@ -403,25 +355,25 @@ void Checkbook::slotPasswordClicked() 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; } @@ -436,22 +388,25 @@ void Checkbook::slotPasswordClicked() 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() @@ -459,28 +414,30 @@ 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 { @@ -497,21 +454,17 @@ void Checkbook::slotEditTran() 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(); @@ -519,17 +472,15 @@ void Checkbook::slotEditTran() { 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() { @@ -543,17 +494,9 @@ void Checkbook::slotDeleteTran() 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(); } } @@ -582,13 +525,13 @@ 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(); @@ -616,15 +559,15 @@ 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 ) { 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 @@ -29,13 +29,12 @@ #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; @@ -45,30 +44,26 @@ 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 @@ -81,13 +76,11 @@ class Checkbook : public QDialog QLineEdit *pinNumEdit; QLineEdit *balanceEdit; QMultiLineEdit *notesEdit; - float startBalance; // Transactions tab QWidget *initTransactions(); QListView *tranTable; QLabel *balanceLabel; - float currBalance; // Charts tab QWidget *initCharts(); 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,16 +1,20 @@ 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 \ 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 @@ -87,11 +87,6 @@ void Graph::initGraph() drawBarChart( width(), height(), data->maxValue() ); } break; - case GraphInfo::LineChart : - { - //drawLineChart( p, s, min, max ); - } - break; case GraphInfo::PieChart : { drawPieChart( width(), height(), data->totalValue() ); @@ -132,10 +127,6 @@ void Graph::drawBarChart( int width, int height, float max ) } } -void Graph::drawLineChart( int width, int height, float max ) -{ -} - void Graph::drawPieChart( int width, int height, float sum ) { QPainter p( &graph ); 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 @@ -57,7 +57,6 @@ class Graph : public QWidget void initGraph(); void drawBarChart( int, int, float ); - void drawLineChart( int, int, float ); void drawPieChart( int, int, float ); }; 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 @@ -55,7 +55,7 @@ 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 ); 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 @@ -27,6 +27,8 @@ */ #include "mainwindow.h" +#include "cbinfo.h" +#include "configuration.h" #include "password.h" #include "checkbook.h" @@ -39,8 +41,10 @@ #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> @@ -51,6 +55,14 @@ MainWindow::MainWindow() 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 ); @@ -82,65 +94,152 @@ MainWindow::MainWindow() 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; @@ -148,39 +247,86 @@ void MainWindow::slotEdit() 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 @@ -30,10 +30,12 @@ #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 @@ -45,16 +47,30 @@ class MainWindow : public QMainWindow ~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 @@ -87,6 +87,4 @@ class TranInfoList : public QList<TranInfo> int compareItems( QCollection::Item, QCollection::Item ); }; -//typedef TranList<TranInfo> TranInfoList; - #endif |