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 | |||
@@ -34,4 +34,5 @@ | |||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | 35 | ||
36 | // --- CBInfo ----------------------------------------------------------------- | ||
36 | CBInfo::CBInfo() | 37 | CBInfo::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 ----------------------------------------------------------------- | ||
51 | CBInfo::CBInfo( const QString &name, const QString &filename ) | 57 | CBInfo::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 ---------------------------------------------------------------- | ||
72 | float CBInfo::balance() | 82 | float CBInfo::balance() |
73 | { | 83 | { |
@@ -76,15 +86,31 @@ float CBInfo::balance() | |||
76 | } | 86 | } |
77 | 87 | ||
88 | // --- write ------------------------------------------------------------------ | ||
78 | void CBInfo::write() | 89 | void 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 | ||
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" ); |
90 | config->writeEntryCrypt( "Password", pw ); | 116 | config->writeEntryCrypt( "Password", pw ); |
@@ -94,30 +120,27 @@ 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 | ||
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; |
110 | } | 131 | } |
111 | 132 | ||
112 | TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, | 133 | |
113 | const QString &desc ) | 134 | // --- findTransaction -------------------------------------------------------- |
114 | { | 135 | TranInfo *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 | } |
123 | return( traninfo ); | 146 | return( traninfo ); |
@@ -126,5 +149,5 @@ TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, | |||
126 | void CBInfo::addTransaction( TranInfo *tran ) | 149 | void 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 ) | |||
132 | void CBInfo::removeTransaction( TranInfo *tran ) | 155 | void 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. | ||
139 | void CBInfo::loadTransactions() | 165 | void CBInfo::loadTransactions() |
140 | { | 166 | { |
@@ -145,17 +171,20 @@ 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 ) { |
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 | } |
161 | 190 | ||
@@ -163,4 +192,6 @@ void CBInfo::loadTransactions() | |||
163 | } | 192 | } |
164 | 193 | ||
194 | |||
195 | // --- calcBalance ------------------------------------------------------------ | ||
165 | void CBInfo::calcBalance() | 196 | void CBInfo::calcBalance() |
166 | { | 197 | { |
@@ -181,4 +212,5 @@ void CBInfo::calcBalance() | |||
181 | } | 212 | } |
182 | 213 | ||
214 | |||
183 | int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) | 215 | int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) |
184 | { | 216 | { |