summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/cbinfo.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp90
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
@@ -35,2 +35,3 @@
35 35
36// --- CBInfo -----------------------------------------------------------------
36CBInfo::CBInfo() 37CBInfo::CBInfo()
@@ -46,2 +47,5 @@ CBInfo::CBInfo()
46 sb = 0.0; 47 sb = 0.0;
48 _sLastTab="";
49 _first=-1;
50 _last=-1;
47 51
@@ -50,2 +54,4 @@ CBInfo::CBInfo()
50 54
55
56// --- CBInfo -----------------------------------------------------------------
51CBInfo::CBInfo( const QString &name, const QString &filename ) 57CBInfo::CBInfo( const QString &name, const QString &filename )
@@ -64,2 +70,5 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
64 nt = config.readEntry( "Notes", "" ); 70 nt = config.readEntry( "Notes", "" );
71 _sLastTab = config.readEntry("LastTab", "");
72 _first=config.readNumEntry("First", -1);
73 _sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") );
65 74
@@ -71,2 +80,3 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
71 80
81// --- balance ----------------------------------------------------------------
72float CBInfo::balance() 82float CBInfo::balance()
@@ -77,2 +87,3 @@ float CBInfo::balance()
77 87
88// --- write ------------------------------------------------------------------
78void CBInfo::write() 89void CBInfo::write()
@@ -81,5 +92,3 @@ void CBInfo::write()
81 if ( f.exists() ) 92 if ( f.exists() )
82 {
83 f.remove(); 93 f.remove();
84 }
85 94
@@ -87,3 +96,20 @@ void CBInfo::write()
87 96
97
98 // fix transaction numbers
99 _first=-1;
100 TranInfo *prev=NULL;
101 for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
102 if( _first<0 ) _first=tran->id();
103 if( prev ) prev->setNext( tran->id() );
104 tran->setNext(-1);
105 prev=tran;
106 }
107
108 // Save transactions
109 for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
110 tran->write(config);
111 }
112
88 // Save info 113 // Save info
114 if( _first<0 && _last>=0 ) _first=_last;
89 config->setGroup( "Account" ); 115 config->setGroup( "Account" );
@@ -95,2 +121,3 @@ void CBInfo::write()
95 config->writeEntry( "Notes", nt ); 121 config->writeEntry( "Notes", nt );
122 config->writeEntry( "LastTab", _sLastTab );
96 QString balstr; 123 QString balstr;
@@ -98,12 +125,6 @@ void CBInfo::write()
98 config->writeEntry( "Balance", balstr ); 125 config->writeEntry( "Balance", balstr );
126 config->writeEntry( "First", _first );
127 config->writeEntry( "SortOrder", _sSortOrder );
99 128
100 // Save transactions
101 int i = 1;
102 for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
103 {
104 tran->write( config, i );
105 i++;
106 }
107 config->write(); 129 config->write();
108
109 delete config; 130 delete config;
@@ -111,12 +132,14 @@ void CBInfo::write()
111 132
112TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, 133
113 const QString &desc ) 134// --- findTransaction --------------------------------------------------------
114{ 135TranInfo *CBInfo::findTransaction( const QString &sId )
115 TranInfo *traninfo = tl->first();
116 while ( traninfo )
117 { 136 {
118 if ( traninfo->number() == checknum && traninfo->datestr() == date && 137 bool bOk;
119 traninfo->desc() == desc ) 138 int id=sId.toInt( &bOk );
139 if( !bOk )
140 return(false);
141 TranInfo *traninfo;
142 for(traninfo=tl->first(); traninfo; traninfo=tl->next()) {
143 if( traninfo->id() == id )
120 break; 144 break;
121 traninfo = tl->next();
122 } 145 }
@@ -127,3 +150,3 @@ void CBInfo::addTransaction( TranInfo *tran )
127{ 150{
128 tl->inSort( tran ); 151 tl->append( tran );
129 calcBalance(); 152 calcBalance();
@@ -133,3 +156,3 @@ void CBInfo::removeTransaction( TranInfo *tran )
133{ 156{
134 tl->remove( tran ); 157 tl->removeRef( tran );
135 delete tran; 158 delete tran;
@@ -138,2 +161,5 @@ void CBInfo::removeTransaction( TranInfo *tran )
138 161
162
163// --- loadTransactions -------------------------------------------------------
164// Reads the transactions. Either the old way 1-n or as linked list.
139void CBInfo::loadTransactions() 165void CBInfo::loadTransactions()
@@ -146,15 +172,18 @@ void CBInfo::loadTransactions()
146 Config config( fn, Config::File ); 172 Config config( fn, Config::File );
147 173 int i=_first;
148 for ( int i = 1; trandesc != QString::null; i++ ) 174 bool bOld=false;
149 { 175 if( i==-1 ) {
176 i=1;
177 bOld=true;
178 }
179 while( i>=0 ) {
180 _last=i;
150 tran = new TranInfo( config, i ); 181 tran = new TranInfo( config, i );
151 trandesc = tran->desc(); 182 trandesc = tran->desc();
152 if ( trandesc != QString::null ) 183 if( trandesc==QString::null ) {
153 {
154 tl->inSort( tran );
155 }
156 else
157 {
158 delete tran; 184 delete tran;
185 break;
159 } 186 }
187 tl->append(tran);
188 i= bOld ? i+1 : tran->getNext();
160 } 189 }
@@ -164,2 +193,4 @@ void CBInfo::loadTransactions()
164 193
194
195// --- calcBalance ------------------------------------------------------------
165void CBInfo::calcBalance() 196void CBInfo::calcBalance()
@@ -182,2 +213,3 @@ void CBInfo::calcBalance()
182 213
214
183int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) 215int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )