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
@@ -30,27 +30,33 @@
30#include "traninfo.h" 30#include "traninfo.h"
31 31
32#include <qpe/config.h> 32#include <qpe/config.h>
33 33
34#include <qfile.h> 34#include <qfile.h>
35 35
36// --- CBInfo -----------------------------------------------------------------
36CBInfo::CBInfo() 37CBInfo::CBInfo()
37{ 38{
38 n = ""; 39 n = "";
39 fn = ""; 40 fn = "";
40 pw = QString::null; 41 pw = QString::null;
41 t = ""; 42 t = "";
42 bn = ""; 43 bn = "";
43 a = ""; 44 a = "";
44 p = ""; 45 p = "";
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{
53 Config config( filename, Config::File ); 59 Config config( filename, Config::File );
54 config.setGroup( "Account" ); 60 config.setGroup( "Account" );
55 61
56 n = name; 62 n = name;
@@ -59,112 +65,137 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
59 65
60 t = config.readEntry( "Type" ); 66 t = config.readEntry( "Type" );
61 bn = config.readEntry( "Bank", "" ); 67 bn = config.readEntry( "Bank", "" );
62 a = config.readEntryCrypt( "Number", "" ); 68 a = config.readEntryCrypt( "Number", "" );
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;
67 sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok ); 76 sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok );
68 77
69 loadTransactions(); 78 loadTransactions();
70} 79}
71 80
81// --- balance ----------------------------------------------------------------
72float CBInfo::balance() 82float CBInfo::balance()
73{ 83{
74 calcBalance(); 84 calcBalance();
75 return b; 85 return b;
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 );
91 config->writeEntry( "Type", t ); 117 config->writeEntry( "Type", t );
92 config->writeEntry( "Bank", bn ); 118 config->writeEntry( "Bank", bn );
93 config->writeEntryCrypt( "Number", a ); 119 config->writeEntryCrypt( "Number", a );
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}
131 154
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{
141 TranInfo *tran; 167 TranInfo *tran;
142 QString trandesc = ""; 168 QString trandesc = "";
143 169
144 tl = new TranInfoList(); 170 tl = new TranInfoList();
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{
167 float amount; 198 float amount;
168 199
169 b = sb; 200 b = sb;
170 201
@@ -177,12 +208,13 @@ void CBInfo::calcBalance()
177 amount *= -1; 208 amount *= -1;
178 } 209 }
179 b += amount; 210 b += amount;
180 } 211 }
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{
185 QString n1 = ((CBInfo *)item1)->name(); 217 QString n1 = ((CBInfo *)item1)->name();
186 QString n2 = ((CBInfo *)item2)->name(); 218 QString n2 = ((CBInfo *)item2)->name();
187 int r = -1; 219 int r = -1;
188 220