author | drw <drw> | 2002-12-08 23:52:11 (UTC) |
---|---|---|
committer | drw <drw> | 2002-12-08 23:52:11 (UTC) |
commit | 9c2b4d917af88b6051a3bc4273d6a50d124f65dd (patch) (unidiff) | |
tree | 6bff583be5510315f516c43e0a1e1edefecce027 | |
parent | f6735fca221658fa6d638f7826f89eb8d79caa26 (diff) | |
download | opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.zip opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.tar.gz opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.tar.bz2 |
Fixed saving of new checkbooks and incorrect setting of notes.
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp index 3a39317..9fdc6b2 100644 --- a/noncore/apps/checkbook/cbinfo.cpp +++ b/noncore/apps/checkbook/cbinfo.cpp | |||
@@ -47,97 +47,97 @@ CBInfo::CBInfo() | |||
47 | 47 | ||
48 | tl = new TranInfoList(); | 48 | tl = new TranInfoList(); |
49 | } | 49 | } |
50 | 50 | ||
51 | CBInfo::CBInfo( const QString &name, const QString &filename ) | 51 | CBInfo::CBInfo( const QString &name, const QString &filename ) |
52 | { | 52 | { |
53 | Config config( filename, Config::File ); | 53 | Config config( filename, Config::File ); |
54 | config.setGroup( "Account" ); | 54 | config.setGroup( "Account" ); |
55 | 55 | ||
56 | n = name; | 56 | n = name; |
57 | fn = filename; | 57 | fn = filename; |
58 | pw = config.readEntryCrypt( "Password", QString::null ); | 58 | pw = config.readEntryCrypt( "Password", QString::null ); |
59 | 59 | ||
60 | t = config.readEntry( "Type" ); | 60 | t = config.readEntry( "Type" ); |
61 | bn = config.readEntry( "Bank", "" ); | 61 | bn = config.readEntry( "Bank", "" ); |
62 | a = config.readEntryCrypt( "Number", "" ); | 62 | a = config.readEntryCrypt( "Number", "" ); |
63 | p = config.readEntryCrypt( "PINNumber", "" ); | 63 | p = config.readEntryCrypt( "PINNumber", "" ); |
64 | nt = config.readEntry( "Notes", "" ); | 64 | nt = config.readEntry( "Notes", "" ); |
65 | 65 | ||
66 | bool ok; | 66 | bool ok; |
67 | sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok ); | 67 | sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok ); |
68 | 68 | ||
69 | loadTransactions(); | 69 | loadTransactions(); |
70 | } | 70 | } |
71 | 71 | ||
72 | float CBInfo::balance() | 72 | float CBInfo::balance() |
73 | { | 73 | { |
74 | calcBalance(); | 74 | calcBalance(); |
75 | return b; | 75 | return b; |
76 | } | 76 | } |
77 | 77 | ||
78 | void CBInfo::write() | 78 | void CBInfo::write() |
79 | { | 79 | { |
80 | QFile f( fn ); | 80 | QFile f( fn ); |
81 | if ( f.exists() ) | 81 | if ( f.exists() ) |
82 | { | 82 | { |
83 | f.remove(); | 83 | f.remove(); |
84 | } | 84 | } |
85 | 85 | ||
86 | Config *config = new Config(fn, Config::File); | 86 | Config *config = new Config(fn, Config::File); |
87 | 87 | ||
88 | // Save info | 88 | // Save info |
89 | config->setGroup( "Account" ); | 89 | config->setGroup( "Account" ); |
90 | config->writeEntryCrypt( "Password", pw ); | 90 | config->writeEntryCrypt( "Password", pw ); |
91 | config->writeEntry( "Type", t ); | 91 | config->writeEntry( "Type", t ); |
92 | config->writeEntry( "Bank", bn ); | 92 | config->writeEntry( "Bank", bn ); |
93 | config->writeEntryCrypt( "Number", a ); | 93 | config->writeEntryCrypt( "Number", a ); |
94 | config->writeEntryCrypt( "PINNumber", p ); | 94 | config->writeEntryCrypt( "PINNumber", p ); |
95 | config->writeEntry( "Notes", n ); | 95 | config->writeEntry( "Notes", nt ); |
96 | QString balstr; | 96 | QString balstr; |
97 | balstr.setNum( sb, 'f', 2 ); | 97 | balstr.setNum( sb, 'f', 2 ); |
98 | config->writeEntry( "Balance", balstr ); | 98 | config->writeEntry( "Balance", balstr ); |
99 | 99 | ||
100 | // Save transactions | 100 | // Save transactions |
101 | int i = 1; | 101 | int i = 1; |
102 | for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) | 102 | for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) |
103 | { | 103 | { |
104 | tran->write( config, i ); | 104 | tran->write( config, i ); |
105 | i++; | 105 | i++; |
106 | } | 106 | } |
107 | config->write(); | 107 | config->write(); |
108 | 108 | ||
109 | delete config; | 109 | delete config; |
110 | } | 110 | } |
111 | 111 | ||
112 | TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, | 112 | TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, |
113 | const QString &desc ) | 113 | const QString &desc ) |
114 | { | 114 | { |
115 | TranInfo *traninfo = tl->first(); | 115 | TranInfo *traninfo = tl->first(); |
116 | while ( traninfo ) | 116 | while ( traninfo ) |
117 | { | 117 | { |
118 | if ( traninfo->number() == checknum && traninfo->datestr() == date && | 118 | if ( traninfo->number() == checknum && traninfo->datestr() == date && |
119 | traninfo->desc() == desc ) | 119 | traninfo->desc() == desc ) |
120 | break; | 120 | break; |
121 | traninfo = tl->next(); | 121 | traninfo = tl->next(); |
122 | } | 122 | } |
123 | return( traninfo ); | 123 | return( traninfo ); |
124 | } | 124 | } |
125 | 125 | ||
126 | void CBInfo::addTransaction( TranInfo *tran ) | 126 | void CBInfo::addTransaction( TranInfo *tran ) |
127 | { | 127 | { |
128 | tl->inSort( tran ); | 128 | tl->inSort( tran ); |
129 | calcBalance(); | 129 | calcBalance(); |
130 | } | 130 | } |
131 | 131 | ||
132 | void CBInfo::removeTransaction( TranInfo *tran ) | 132 | void CBInfo::removeTransaction( TranInfo *tran ) |
133 | { | 133 | { |
134 | tl->remove( tran ); | 134 | tl->remove( tran ); |
135 | delete tran; | 135 | delete tran; |
136 | calcBalance(); | 136 | calcBalance(); |
137 | } | 137 | } |
138 | 138 | ||
139 | void CBInfo::loadTransactions() | 139 | void CBInfo::loadTransactions() |
140 | { | 140 | { |
141 | TranInfo *tran; | 141 | TranInfo *tran; |
142 | QString trandesc = ""; | 142 | QString trandesc = ""; |
143 | 143 | ||
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 68c6aee..cabd231 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp | |||
@@ -159,96 +159,102 @@ void MainWindow::buildList() | |||
159 | { | 159 | { |
160 | int colnum = cbList->addColumn( tr( "Balance" ) ); | 160 | int colnum = cbList->addColumn( tr( "Balance" ) ); |
161 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); | 161 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); |
162 | } | 162 | } |
163 | cbList->setAllColumnsShowFocus( TRUE ); | 163 | cbList->setAllColumnsShowFocus( TRUE ); |
164 | cbList->setSorting( posName ); | 164 | cbList->setSorting( posName ); |
165 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); | 165 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); |
166 | connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), | 166 | connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), |
167 | this, SLOT( slotEdit() ) ); | 167 | this, SLOT( slotEdit() ) ); |
168 | setCentralWidget( cbList ); | 168 | setCentralWidget( cbList ); |
169 | 169 | ||
170 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) | 170 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) |
171 | { | 171 | { |
172 | addCheckbook( cb ); | 172 | addCheckbook( cb ); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | void MainWindow::addCheckbook( CBInfo *cb ) | 176 | void MainWindow::addCheckbook( CBInfo *cb ) |
177 | { | 177 | { |
178 | QListViewItem *lvi = new QListViewItem( cbList ); | 178 | QListViewItem *lvi = new QListViewItem( cbList ); |
179 | if ( showLocks && !cb->password().isNull() ) | 179 | if ( showLocks && !cb->password().isNull() ) |
180 | { | 180 | { |
181 | lvi->setPixmap( 0, lockIcon ); | 181 | lvi->setPixmap( 0, lockIcon ); |
182 | } | 182 | } |
183 | lvi->setText( posName, cb->name() ); | 183 | lvi->setText( posName, cb->name() ); |
184 | if ( showBalances ) | 184 | if ( showBalances ) |
185 | { | 185 | { |
186 | QString balance; | 186 | QString balance; |
187 | balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); | 187 | balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); |
188 | lvi->setText( posName + 1, balance ); | 188 | lvi->setText( posName + 1, balance ); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | void MainWindow::buildFilename( const QString &name ) | 192 | void MainWindow::buildFilename( const QString &name ) |
193 | { | 193 | { |
194 | tempFilename = cbDir; | 194 | tempFilename = cbDir; |
195 | tempFilename.append( name ); | 195 | tempFilename.append( name ); |
196 | tempFilename.append( ".qcb" ); | 196 | tempFilename.append( ".qcb" ); |
197 | } | 197 | } |
198 | 198 | ||
199 | void MainWindow::slotNew() | 199 | void MainWindow::slotNew() |
200 | { | 200 | { |
201 | CBInfo *cb = new CBInfo(); | 201 | CBInfo *cb = new CBInfo(); |
202 | 202 | ||
203 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); | 203 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); |
204 | currcb->showMaximized(); | 204 | currcb->showMaximized(); |
205 | if ( currcb->exec() == QDialog::Accepted ) | 205 | if ( currcb->exec() == QDialog::Accepted ) |
206 | { | 206 | { |
207 | // Save new checkbook | ||
208 | buildFilename( cb->name() ); | ||
209 | cb->setFilename( tempFilename ); | ||
210 | cb->write(); | ||
211 | |||
212 | // Add to listbox | ||
207 | checkbooks->inSort( cb ); | 213 | checkbooks->inSort( cb ); |
208 | addCheckbook( cb ); | 214 | addCheckbook( cb ); |
209 | } | 215 | } |
210 | delete currcb; | 216 | delete currcb; |
211 | } | 217 | } |
212 | 218 | ||
213 | void MainWindow::slotEdit() | 219 | void MainWindow::slotEdit() |
214 | { | 220 | { |
215 | 221 | ||
216 | QListViewItem *curritem = cbList->currentItem(); | 222 | QListViewItem *curritem = cbList->currentItem(); |
217 | if ( !curritem ) | 223 | if ( !curritem ) |
218 | { | 224 | { |
219 | return; | 225 | return; |
220 | } | 226 | } |
221 | QString currname = curritem->text( posName ); | 227 | QString currname = curritem->text( posName ); |
222 | 228 | ||
223 | CBInfo *cb = checkbooks->first(); | 229 | CBInfo *cb = checkbooks->first(); |
224 | while ( cb ) | 230 | while ( cb ) |
225 | { | 231 | { |
226 | if ( cb->name() == currname ) | 232 | if ( cb->name() == currname ) |
227 | break; | 233 | break; |
228 | cb = checkbooks->next(); | 234 | cb = checkbooks->next(); |
229 | } | 235 | } |
230 | if ( !cb ) | 236 | if ( !cb ) |
231 | { | 237 | { |
232 | return; | 238 | return; |
233 | } | 239 | } |
234 | 240 | ||
235 | buildFilename( currname ); | 241 | buildFilename( currname ); |
236 | float currbalance = cb->balance(); | 242 | float currbalance = cb->balance(); |
237 | bool currlock = !cb->password().isNull(); | 243 | bool currlock = !cb->password().isNull(); |
238 | 244 | ||
239 | if ( currlock ) | 245 | if ( currlock ) |
240 | { | 246 | { |
241 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 247 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
242 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) | 248 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) |
243 | { | 249 | { |
244 | delete pw; | 250 | delete pw; |
245 | return; | 251 | return; |
246 | } | 252 | } |
247 | delete pw; | 253 | delete pw; |
248 | } | 254 | } |
249 | 255 | ||
250 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); | 256 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); |
251 | currcb->showMaximized(); | 257 | currcb->showMaximized(); |
252 | if ( currcb->exec() == QDialog::Accepted ) | 258 | if ( currcb->exec() == QDialog::Accepted ) |
253 | { | 259 | { |
254 | QString newname = cb->name(); | 260 | QString newname = cb->name(); |