-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 | 235 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.h | 25 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.pro | 28 | ||||
-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 | 230 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.h | 30 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.h | 16 |
13 files changed, 753 insertions, 243 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 @@ -28,5 +28,7 @@ #include "checkbook.h" +#include "cbinfo.h" #include "transaction.h" +#include "traninfo.h" #include "graph.h" #include "graphinfo.h" @@ -51,18 +53,13 @@ #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" ) ); @@ -96,9 +93,4 @@ Checkbook::~Checkbook() } -const QString &Checkbook::getName() -{ - return( name ); -} - QWidget *Checkbook::initInfo() { @@ -274,15 +266,14 @@ 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 ) @@ -295,60 +286,39 @@ void Checkbook::loadCheckbook() } } - 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 ) - { - 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 ); - } - else + for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) + { + amount = tran->amount(); + if ( tran->withdrawal() ) { - delete tran; + amount *= -1; } + stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); + ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); } - 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 ) { @@ -356,5 +326,5 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con traninfo->desc() == desc ) break; - traninfo = transactions.next(); + traninfo = tranList->next(); } return( traninfo ); @@ -363,30 +333,12 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con 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(); @@ -395,5 +347,5 @@ void Checkbook::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:" ) ); @@ -404,23 +356,23 @@ void Checkbook::slotPasswordClicked() 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; @@ -437,20 +389,23 @@ 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(); } @@ -460,5 +415,5 @@ void Checkbook::slotNewTran() TranInfo *traninfo = new TranInfo( highTranNum ); - Transaction *currtran = new Transaction( this, name, + Transaction *currtran = new Transaction( this, info->name(), traninfo, currencySymbol ); @@ -466,20 +421,22 @@ void Checkbook::slotNewTran() 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 @@ -498,12 +455,8 @@ void Checkbook::slotEditTran() } - 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 ); @@ -511,6 +464,6 @@ void Checkbook::slotEditTran() if ( currtran->exec() == QDialog::Accepted ) { + curritem->setText( 0, traninfo->number() ); curritem->setText( 1, traninfo->datestr() ); - curritem->setText( 2, traninfo->desc() ); @@ -520,14 +473,12 @@ 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 ) ); - - delete currtran; + adjustBalance(); } + + delete currtran; } @@ -544,15 +495,7 @@ 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(); } } @@ -583,11 +526,11 @@ 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++; @@ -617,13 +560,13 @@ 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 ) @@ -713,3 +656,3 @@ bool CBListItem::isAltBackground() } return false; -}
\ No newline at end of file +} 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 @@ -30,6 +30,4 @@ #define CHECKBOOK_H -#include "traninfo.h" - #include <qdialog.h> #include <qlistview.h> @@ -37,4 +35,5 @@ class OTabWidget; +class CBInfo; class Graph; class GraphInfo; @@ -46,4 +45,6 @@ class QListView; class QMultiLineEdit; class QString; +class TranInfo; +class TranInfoList; class Checkbook : public QDialog @@ -52,22 +53,16 @@ class Checkbook : public QDialog 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; - QString currencySymbol; - QString password; - int highTranNum; + CBInfo *info; + TranInfoList *tranList; + QString currencySymbol; + int highTranNum; OTabWidget *mainWidget; void loadCheckbook(); - void adjustBalance( float ); + void adjustBalance(); TranInfo *findTran( const QString &, const QString &, const QString & ); @@ -82,5 +77,4 @@ class Checkbook : public QDialog QLineEdit *balanceEdit; QMultiLineEdit *notesEdit; - float startBalance; // Transactions tab @@ -88,5 +82,4 @@ class Checkbook : public QDialog QListView *tranTable; QLabel *balanceLabel; - float currBalance; // Charts tab 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 @@ -2,17 +2,21 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = mainwindow.h \ - traninfo.h \ - graphinfo.h \ - password.h \ - checkbook.h \ - transaction.h \ + cbinfo.h \ + traninfo.h \ + graphinfo.h \ + configuration.h \ + password.h \ + checkbook.h \ + transaction.h \ graph.h -SOURCES = main.cpp \ - mainwindow.cpp \ - traninfo.cpp \ - graphinfo.cpp \ - password.cpp \ - checkbook.cpp \ - transaction.cpp \ +SOURCES = main.cpp \ + mainwindow.cpp \ + cbinfo.cpp \ + traninfo.cpp \ + graphinfo.cpp \ + configuration.cpp \ + password.cpp \ + checkbook.cpp \ + transaction.cpp \ graph.cpp INCLUDEPATH += $(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 @@ -88,9 +88,4 @@ void Graph::initGraph() } break; - case GraphInfo::LineChart : - { - //drawLineChart( p, s, min, max ); - } - break; case GraphInfo::PieChart : { @@ -133,8 +128,4 @@ 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 ) { 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 @@ -58,5 +58,4 @@ 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 @@ -56,5 +56,5 @@ class GraphInfo { public: - enum GraphType { BarChart, LineChart, PieChart }; + enum GraphType { BarChart, PieChart }; GraphInfo( GraphType = BarChart, DataPointList * = 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 @@ -28,4 +28,6 @@ #include "mainwindow.h" +#include "cbinfo.h" +#include "configuration.h" #include "password.h" #include "checkbook.h" @@ -40,6 +42,8 @@ #include <qaction.h> +#include <qcheckbox.h> #include <qdir.h> -#include <qlistbox.h> +#include <qlineedit.h> +#include <qlistview.h> #include <qpopupmenu.h> #include <qstring.h> @@ -52,4 +56,12 @@ MainWindow::MainWindow() 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 @@ -83,63 +95,150 @@ MainWindow::MainWindow() 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" ); - - Config config( tempstr, Config::File ); - config.setGroup( "Account" ); - QString password = config.readEntryCrypt( "Password", "" ); - if ( password != "" ) + + QListViewItem *curritem = cbList->currentItem(); + if ( !curritem ) + { + return; + } + QString currname = curritem->text( posName ); + + 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; @@ -149,32 +248,57 @@ void MainWindow::slotEdit() } - 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 ); + } + + 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; } + 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() ) { @@ -182,5 +306,27 @@ void MainWindow::slotDelete() } - 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 @@ -31,8 +31,10 @@ #include <qmainwindow.h> +#include <qpixmap.h> +class CBInfo; +class CBInfoList; class QAction; -class QListBox; -class QListBoxItem; +class QListView; class QString; @@ -46,9 +48,22 @@ class MainWindow : public QMainWindow private: - QListBox *cbList; - QString cbDir; - QAction *actionOpen; - QAction *actionDelete; - QString currencySymbol; + 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: @@ -56,4 +71,5 @@ class MainWindow : public QMainWindow void slotEdit(); void slotDelete(); + void slotConfigure(); }; 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 @@ -54,16 +54,16 @@ class TranInfo float amount() const { return a; } float fee() const { return f; } - const QString &number() const { return cn; } + const QString &number() const { return cn; } const QString ¬es() const { return n; } void setDesc( const QString &desc ) { d = desc; } - void setDate( const QDate &date ) { td = date; } - void setWithdrawal( bool withdrawal ) { w = withdrawal; } + void setDate( const QDate &date ) { td = date; } + void setWithdrawal( bool withdrawal ) { w = withdrawal; } void setType( const QString &type ) { t = type; } void setCategory( const QString &cat ) { c = cat; } - void setAmount( float amount ) { a = amount; } - void setFee( float fee ) { f = fee; } - void setNumber( const QString &num ) { cn = num; } - void setNotes( const QString ¬es ) { n = notes; } + void setAmount( float amount ) { a = amount; } + void setFee( float fee ) { f = fee; } + void setNumber( const QString &num ) { cn = num; } + void setNotes( const QString ¬es ) { n = notes; } void write( Config *, int ); @@ -88,5 +88,3 @@ class TranInfoList : public QList<TranInfo> }; -//typedef TranList<TranInfo> TranInfoList; - #endif |