Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 235 |
1 files changed, 89 insertions, 146 deletions
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 +} |