-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 @@ -29,3 +29,5 @@ #include "checkbook.h" +#include "cbinfo.h" #include "transaction.h" +#include "traninfo.h" #include "graph.h" @@ -52,16 +54,11 @@ -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( " - " ); @@ -97,7 +94,2 @@ Checkbook::~Checkbook() -const QString &Checkbook::getName() -{ - return( name ); -} - QWidget *Checkbook::initInfo() @@ -275,13 +267,12 @@ 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(); @@ -296,53 +287,32 @@ 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 ) ); } @@ -351,3 +321,3 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con { - TranInfo *traninfo = transactions.first(); + TranInfo *traninfo = tranList->first(); while ( traninfo ) @@ -357,3 +327,3 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con break; - traninfo = transactions.next(); + traninfo = tranList->next(); } @@ -364,28 +334,10 @@ 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() ); @@ -396,3 +348,3 @@ void Checkbook::slotPasswordClicked() { - if ( password == "" && passwordCB->isChecked() ) + if ( info->password().isNull() && passwordCB->isChecked() ) { @@ -405,3 +357,3 @@ void Checkbook::slotPasswordClicked() } - password = pw->password; + info->setPassword( pw->password ); delete pw; @@ -409,6 +361,6 @@ void Checkbook::slotPasswordClicked() 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 ); } @@ -417,3 +369,3 @@ void Checkbook::slotPasswordClicked() } - else if ( password != "" && !passwordCB->isChecked() ) + else if ( !info->password().isNull() && !passwordCB->isChecked() ) { @@ -421,5 +373,5 @@ void Checkbook::slotPasswordClicked() 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; @@ -438,10 +390,14 @@ 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 ); } @@ -450,6 +406,5 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { - currBalance -= startBalance; bool ok; - startBalance = newbalance.toFloat( &ok ); - adjustBalance( startBalance ); + info->setStartingBalance( newbalance.toFloat( &ok ) ); + adjustBalance(); } @@ -461,3 +416,3 @@ void Checkbook::slotNewTran() - Transaction *currtran = new Transaction( this, name, + Transaction *currtran = new Transaction( this, info->name(), traninfo, @@ -467,3 +422,10 @@ void Checkbook::slotNewTran() { - 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() ) @@ -472,9 +434,4 @@ void Checkbook::slotNewTran() } - 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(), @@ -482,3 +439,3 @@ void Checkbook::slotNewTran() - adjustBalance( amount ); + adjustBalance(); } @@ -499,10 +456,6 @@ 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, @@ -512,4 +465,4 @@ void Checkbook::slotEditTran() { + curritem->setText( 0, traninfo->number() ); curritem->setText( 1, traninfo->datestr() ); - curritem->setText( 2, traninfo->desc() ); @@ -521,4 +474,2 @@ void Checkbook::slotEditTran() } - adjustBalance( origamt * -1 ); - adjustBalance( amount ); QString stramount; @@ -527,6 +478,6 @@ void Checkbook::slotEditTran() - balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); - - delete currtran; + adjustBalance(); } + + delete currtran; } @@ -545,13 +496,5 @@ void Checkbook::slotDeleteTran() { - float amount = traninfo->amount(); - if ( traninfo->withdrawal() ) - { - amount *= -1; - } - - transactions.remove( traninfo ); - delete traninfo; + info->removeTransaction( traninfo ); delete curritem; - - adjustBalance( amount * -1 ); + adjustBalance(); } @@ -584,3 +527,3 @@ void Checkbook::drawBalanceChart() - float balance = startBalance; + float balance = info->startingBalance(); float amount; @@ -588,5 +531,5 @@ void Checkbook::drawBalanceChart() 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() ) { @@ -618,3 +561,3 @@ void Checkbook::drawCategoryChart( bool withdrawals ) - TranInfo *tran = transactions.first(); + TranInfo *tran = tranList->first(); if ( tran && tran->withdrawal() == withdrawals ) @@ -623,6 +566,6 @@ void Checkbook::drawCategoryChart( bool withdrawals ) } - tran = transactions.next(); + tran = tranList->next(); DataPointInfo *cat; - for ( ; tran; tran = transactions.next() ) + for ( ; tran; tran = tranList->next() ) { @@ -714,2 +657,2 @@ 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 @@ -31,4 +31,2 @@ -#include "traninfo.h" - #include <qdialog.h> @@ -38,2 +36,3 @@ class OTabWidget; +class CBInfo; class Graph; @@ -47,2 +46,4 @@ class QMultiLineEdit; class QString; +class TranInfo; +class TranInfoList; @@ -53,16 +54,10 @@ 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; @@ -70,3 +65,3 @@ class Checkbook : public QDialog void loadCheckbook(); - void adjustBalance( float ); + void adjustBalance(); TranInfo *findTran( const QString &, const QString &, const QString & ); @@ -83,3 +78,2 @@ class Checkbook : public QDialog QMultiLineEdit *notesEdit; - float startBalance; @@ -89,3 +83,2 @@ class Checkbook : public QDialog QLabel *balanceLabel; - float currBalance; 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 @@ -3,15 +3,19 @@ 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 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 @@ -89,7 +89,2 @@ void Graph::initGraph() break; - case GraphInfo::LineChart : - { - //drawLineChart( p, s, min, max ); - } - break; case GraphInfo::PieChart : @@ -134,6 +129,2 @@ 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 @@ -59,3 +59,2 @@ class Graph : public QWidget 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 @@ -57,3 +57,3 @@ class GraphInfo public: - enum GraphType { BarChart, LineChart, PieChart }; + enum GraphType { BarChart, PieChart }; 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 @@ -29,2 +29,4 @@ #include "mainwindow.h" +#include "cbinfo.h" +#include "configuration.h" #include "password.h" @@ -41,4 +43,6 @@ #include <qaction.h> +#include <qcheckbox.h> #include <qdir.h> -#include <qlistbox.h> +#include <qlineedit.h> +#include <qlistview.h> #include <qpopupmenu.h> @@ -53,2 +57,10 @@ 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 ); @@ -84,13 +96,15 @@ MainWindow::MainWindow() - 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 ); @@ -98,14 +112,20 @@ MainWindow::MainWindow() { - 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(); } @@ -114,2 +134,64 @@ 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" ); } @@ -118,3 +200,5 @@ void MainWindow::slotNew() { - Checkbook *currcb = new Checkbook( this, "", cbDir, currencySymbol ); + CBInfo *cb = new CBInfo(); + + Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); currcb->showMaximized(); @@ -122,6 +206,6 @@ void MainWindow::slotNew() { - cbList->insertItem( currcb->getName() ); - cbList->sort(); - delete currcb; + checkbooks->inSort( cb ); + addCheckbook( cb ); } + delete currcb; } @@ -130,15 +214,30 @@ 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() ) { @@ -150,3 +249,3 @@ void MainWindow::slotEdit() - Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol ); + Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); currcb->showMaximized(); @@ -154,9 +253,11 @@ void MainWindow::slotEdit() { - 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() ) @@ -165,5 +266,28 @@ void MainWindow::slotEdit() } + + // 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; } @@ -172,8 +296,8 @@ 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() ) @@ -183,4 +307,26 @@ 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 @@ -32,6 +32,8 @@ #include <qmainwindow.h> +#include <qpixmap.h> +class CBInfo; +class CBInfoList; class QAction; -class QListBox; -class QListBoxItem; +class QListView; class QString; @@ -47,7 +49,20 @@ 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 & ); @@ -57,2 +72,3 @@ class MainWindow : public QMainWindow 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 @@ -55,3 +55,3 @@ class TranInfo float fee() const { return f; } - const QString &number() const { return cn; } + const QString &number() const { return cn; } const QString ¬es() const { return n; } @@ -59,10 +59,10 @@ class TranInfo 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; } @@ -89,4 +89,2 @@ class TranInfoList : public QList<TranInfo> -//typedef TranList<TranInfo> TranInfoList; - #endif |