Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 116 |
1 files changed, 74 insertions, 42 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp index 9fdc6b2..36dde04 100644 --- a/noncore/apps/checkbook/cbinfo.cpp +++ b/noncore/apps/checkbook/cbinfo.cpp @@ -34,4 +34,5 @@ #include <qfile.h> +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo() { @@ -45,8 +46,13 @@ CBInfo::CBInfo() nt = ""; sb = 0.0; + _sLastTab=""; + _first=-1; + _last=-1; tl = new TranInfoList(); } + +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo( const QString &name, const QString &filename ) { @@ -63,4 +69,7 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) p = config.readEntryCrypt( "PINNumber", "" ); nt = config.readEntry( "Notes", "" ); + _sLastTab = config.readEntry("LastTab", ""); + _first=config.readNumEntry("First", -1); + _sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") ); bool ok; @@ -70,4 +79,5 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) } +// --- balance ---------------------------------------------------------------- float CBInfo::balance() { @@ -76,15 +86,31 @@ float CBInfo::balance() } +// --- write ------------------------------------------------------------------ void CBInfo::write() { QFile f( fn ); if ( f.exists() ) - { f.remove(); - } Config *config = new Config(fn, Config::File); - // Save info + + // fix transaction numbers + _first=-1; + TranInfo *prev=NULL; + for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { + if( _first<0 ) _first=tran->id(); + if( prev ) prev->setNext( tran->id() ); + tran->setNext(-1); + prev=tran; + } + + // Save transactions + for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { + tran->write(config); + } + + // Save info + if( _first<0 && _last>=0 ) _first=_last; config->setGroup( "Account" ); config->writeEntryCrypt( "Password", pw ); @@ -94,37 +120,34 @@ void CBInfo::write() config->writeEntryCrypt( "PINNumber", p ); config->writeEntry( "Notes", nt ); + config->writeEntry( "LastTab", _sLastTab ); QString balstr; balstr.setNum( sb, 'f', 2 ); config->writeEntry( "Balance", balstr ); + config->writeEntry( "First", _first ); + config->writeEntry( "SortOrder", _sSortOrder ); - // Save transactions - int i = 1; - for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) - { - tran->write( config, i ); - i++; - } - config->write(); - + config->write(); delete config; } -TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, - const QString &desc ) + +// --- findTransaction -------------------------------------------------------- +TranInfo *CBInfo::findTransaction( const QString &sId ) { - TranInfo *traninfo = tl->first(); - while ( traninfo ) - { - if ( traninfo->number() == checknum && traninfo->datestr() == date && - traninfo->desc() == desc ) - break; - traninfo = tl->next(); - } - return( traninfo ); + bool bOk; + int id=sId.toInt( &bOk ); + if( !bOk ) + return(false); + TranInfo *traninfo; + for(traninfo=tl->first(); traninfo; traninfo=tl->next()) { + if( traninfo->id() == id ) + break; + } + return(traninfo); } void CBInfo::addTransaction( TranInfo *tran ) { - tl->inSort( tran ); + tl->append( tran ); calcBalance(); } @@ -132,9 +155,12 @@ void CBInfo::addTransaction( TranInfo *tran ) void CBInfo::removeTransaction( TranInfo *tran ) { - tl->remove( tran ); - delete tran; + tl->removeRef( tran ); + delete tran; calcBalance(); } + +// --- loadTransactions ------------------------------------------------------- +// Reads the transactions. Either the old way 1-n or as linked list. void CBInfo::loadTransactions() { @@ -145,22 +171,27 @@ void CBInfo::loadTransactions() 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(); + int i=_first; + bool bOld=false; + if( i==-1 ) { + i=1; + bOld=true; + } + while( i>=0 ) { + _last=i; + tran=new TranInfo(config, i); + trandesc = tran->desc(); + if( trandesc==QString::null ) { + delete tran; + break; + } + tl->append(tran); + i= bOld ? i+1 : tran->getNext(); + } + + calcBalance(); } + +// --- calcBalance ------------------------------------------------------------ void CBInfo::calcBalance() { @@ -181,4 +212,5 @@ void CBInfo::calcBalance() } + int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) { |