summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/cbinfo.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp116
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 @@
34#include <qfile.h> 34#include <qfile.h>
35 35
36// --- CBInfo -----------------------------------------------------------------
36CBInfo::CBInfo() 37CBInfo::CBInfo()
37{ 38{
@@ -45,8 +46,13 @@ CBInfo::CBInfo()
45 nt = ""; 46 nt = "";
46 sb = 0.0; 47 sb = 0.0;
48 _sLastTab="";
49 _first=-1;
50 _last=-1;
47 51
48 tl = new TranInfoList(); 52 tl = new TranInfoList();
49} 53}
50 54
55
56// --- CBInfo -----------------------------------------------------------------
51CBInfo::CBInfo( const QString &name, const QString &filename ) 57CBInfo::CBInfo( const QString &name, const QString &filename )
52{ 58{
@@ -63,4 +69,7 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
63 p = config.readEntryCrypt( "PINNumber", "" ); 69 p = config.readEntryCrypt( "PINNumber", "" );
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
66 bool ok; 75 bool ok;
@@ -70,4 +79,5 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
70} 79}
71 80
81// --- balance ----------------------------------------------------------------
72float CBInfo::balance() 82float CBInfo::balance()
73{ 83{
@@ -76,15 +86,31 @@ float CBInfo::balance()
76} 86}
77 87
88// --- write ------------------------------------------------------------------
78void CBInfo::write() 89void CBInfo::write()
79{ 90{
80 QFile f( fn ); 91 QFile f( fn );
81 if ( f.exists() ) 92 if ( f.exists() )
82 {
83 f.remove(); 93 f.remove();
84 }
85 94
86 Config *config = new Config(fn, Config::File); 95 Config *config = new Config(fn, Config::File);
87 96
88 // Save info 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
113 // Save info
114 if( _first<0 && _last>=0 ) _first=_last;
89 config->setGroup( "Account" ); 115 config->setGroup( "Account" );
90 config->writeEntryCrypt( "Password", pw ); 116 config->writeEntryCrypt( "Password", pw );
@@ -94,37 +120,34 @@ void CBInfo::write()
94 config->writeEntryCrypt( "PINNumber", p ); 120 config->writeEntryCrypt( "PINNumber", p );
95 config->writeEntry( "Notes", nt ); 121 config->writeEntry( "Notes", nt );
122 config->writeEntry( "LastTab", _sLastTab );
96 QString balstr; 123 QString balstr;
97 balstr.setNum( sb, 'f', 2 ); 124 balstr.setNum( sb, 'f', 2 );
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 129 config->write();
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();
108
109 delete config; 130 delete config;
110} 131}
111 132
112TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, 133
113 const QString &desc ) 134// --- findTransaction --------------------------------------------------------
135TranInfo *CBInfo::findTransaction( const QString &sId )
114{ 136{
115 TranInfo *traninfo = tl->first(); 137 bool bOk;
116 while ( traninfo ) 138 int id=sId.toInt( &bOk );
117 { 139 if( !bOk )
118 if ( traninfo->number() == checknum && traninfo->datestr() == date && 140 return(false);
119 traninfo->desc() == desc ) 141 TranInfo *traninfo;
120 break; 142 for(traninfo=tl->first(); traninfo; traninfo=tl->next()) {
121 traninfo = tl->next(); 143 if( traninfo->id() == id )
122 } 144 break;
123 return( traninfo ); 145 }
146 return(traninfo);
124} 147}
125 148
126void CBInfo::addTransaction( TranInfo *tran ) 149void CBInfo::addTransaction( TranInfo *tran )
127{ 150{
128 tl->inSort( tran ); 151 tl->append( tran );
129 calcBalance(); 152 calcBalance();
130} 153}
@@ -132,9 +155,12 @@ void CBInfo::addTransaction( TranInfo *tran )
132void CBInfo::removeTransaction( TranInfo *tran ) 155void CBInfo::removeTransaction( TranInfo *tran )
133{ 156{
134 tl->remove( tran ); 157 tl->removeRef( tran );
135 delete tran; 158 delete tran;
136 calcBalance(); 159 calcBalance();
137} 160}
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()
140{ 166{
@@ -145,22 +171,27 @@ void CBInfo::loadTransactions()
145 171
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 ) {
150 tran = new TranInfo( config, i ); 176 i=1;
151 trandesc = tran->desc(); 177 bOld=true;
152 if ( trandesc != QString::null ) 178 }
153 { 179 while( i>=0 ) {
154 tl->inSort( tran ); 180 _last=i;
155 } 181 tran=new TranInfo(config, i);
156 else 182 trandesc = tran->desc();
157 { 183 if( trandesc==QString::null ) {
158 delete tran; 184 delete tran;
159 } 185 break;
160 } 186 }
161 187 tl->append(tran);
162 calcBalance(); 188 i= bOld ? i+1 : tran->getNext();
189 }
190
191 calcBalance();
163} 192}
164 193
194
195// --- calcBalance ------------------------------------------------------------
165void CBInfo::calcBalance() 196void CBInfo::calcBalance()
166{ 197{
@@ -181,4 +212,5 @@ void CBInfo::calcBalance()
181} 212}
182 213
214
183int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) 215int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
184{ 216{