author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (side-by-side diff) | |
tree | 46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/cbinfo.cpp | |
parent | f0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff) | |
download | opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2 |
merge noncore/apps/* except
- advancedfm (ljp, please...)
- odict (tille, please...)
Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 90 |
1 files changed, 61 insertions, 29 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 @@ -30,27 +30,33 @@ #include "traninfo.h" #include <qpe/config.h> #include <qfile.h> +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo() { n = ""; fn = ""; pw = QString::null; t = ""; bn = ""; a = ""; p = ""; nt = ""; sb = 0.0; + _sLastTab=""; + _first=-1; + _last=-1; tl = new TranInfoList(); } + +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo( const QString &name, const QString &filename ) { Config config( filename, Config::File ); config.setGroup( "Account" ); n = name; @@ -59,112 +65,137 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) t = config.readEntry( "Type" ); bn = config.readEntry( "Bank", "" ); a = config.readEntryCrypt( "Number", "" ); 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; sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok ); loadTransactions(); } +// --- balance ---------------------------------------------------------------- float CBInfo::balance() { calcBalance(); return b; } +// --- write ------------------------------------------------------------------ void CBInfo::write() { QFile f( fn ); if ( f.exists() ) - { f.remove(); - } Config *config = new Config(fn, Config::File); + + // 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 ); config->writeEntry( "Type", t ); config->writeEntry( "Bank", bn ); config->writeEntryCrypt( "Number", a ); 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(); - delete config; } -TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, - const QString &desc ) -{ - TranInfo *traninfo = tl->first(); - while ( traninfo ) + +// --- findTransaction -------------------------------------------------------- +TranInfo *CBInfo::findTransaction( const QString &sId ) { - if ( traninfo->number() == checknum && traninfo->datestr() == date && - traninfo->desc() == desc ) + 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; - traninfo = tl->next(); } return( traninfo ); } void CBInfo::addTransaction( TranInfo *tran ) { - tl->inSort( tran ); + tl->append( tran ); calcBalance(); } void CBInfo::removeTransaction( TranInfo *tran ) { - tl->remove( tran ); + tl->removeRef( tran ); delete tran; calcBalance(); } + +// --- loadTransactions ------------------------------------------------------- +// Reads the transactions. Either the old way 1-n or as linked list. void CBInfo::loadTransactions() { TranInfo *tran; QString trandesc = ""; tl = new TranInfoList(); Config config( fn, Config::File ); - - for ( int i = 1; trandesc != QString::null; i++ ) - { + 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 ) - { - tl->inSort( tran ); - } - else - { + if( trandesc==QString::null ) { delete tran; + break; } + tl->append(tran); + i= bOld ? i+1 : tran->getNext(); } calcBalance(); } + +// --- calcBalance ------------------------------------------------------------ void CBInfo::calcBalance() { float amount; b = sb; @@ -177,12 +208,13 @@ void CBInfo::calcBalance() 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; |