Diffstat (limited to 'noncore/apps/checkbook/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index d9e2047..8e2e2e3 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp | |||
@@ -198,134 +198,133 @@ void MainWindow::addCheckbook( CBInfo *cb ) | |||
198 | QString balance; | 198 | QString balance; |
199 | balance.sprintf( "%.2f", cb->balance() ); | 199 | balance.sprintf( "%.2f", cb->balance() ); |
200 | balance.prepend( _cfg.getCurrencySymbol() ); | 200 | balance.prepend( _cfg.getCurrencySymbol() ); |
201 | lvi->setText( posName + 1, balance ); | 201 | lvi->setText( posName + 1, balance ); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | void MainWindow::buildFilename( const QString &name ) | 205 | void MainWindow::buildFilename( const QString &name ) |
206 | { | 206 | { |
207 | tempFilename = cbDir; | 207 | tempFilename = cbDir; |
208 | tempFilename.append( name ); | 208 | tempFilename.append( name ); |
209 | tempFilename.append( ".qcb" ); | 209 | tempFilename.append( ".qcb" ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void MainWindow::slotNew() | 212 | void MainWindow::slotNew() |
213 | { | 213 | { |
214 | CBInfo *cb = new CBInfo(); | 214 | CBInfo *cb = new CBInfo(); |
215 | 215 | ||
216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
217 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) | 217 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) |
218 | { | 218 | { |
219 | // Save new checkbook | 219 | // Save new checkbook |
220 | buildFilename( cb->name() ); | 220 | buildFilename( cb->name() ); |
221 | _cfg.setLastBook( cb->name() ); | 221 | _cfg.setLastBook( cb->name() ); |
222 | cb->setFilename( tempFilename ); | 222 | cb->setFilename( tempFilename ); |
223 | cb->write(); | 223 | cb->write(); |
224 | 224 | ||
225 | // Add to listbox | 225 | // Add to listbox |
226 | checkbooks->inSort( cb ); | 226 | checkbooks->inSort( cb ); |
227 | addCheckbook( cb ); | 227 | addCheckbook( cb ); |
228 | } | 228 | } |
229 | delete currcb; | 229 | delete currcb; |
230 | } | 230 | } |
231 | 231 | ||
232 | // --- slotEdit --------------------------------------------------------------- | 232 | // --- slotEdit --------------------------------------------------------------- |
233 | void MainWindow::slotEdit() | 233 | void MainWindow::slotEdit() |
234 | { | 234 | { |
235 | // get name and open it | 235 | // get name and open it |
236 | QListViewItem *curritem = cbList->currentItem(); | 236 | QListViewItem *curritem = cbList->currentItem(); |
237 | if ( !curritem ) | 237 | if ( !curritem ) |
238 | return; | 238 | return; |
239 | openBook( curritem ); | 239 | openBook( curritem ); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | // --- openBook --------------------------------------------------------------- | 243 | // --- openBook --------------------------------------------------------------- |
244 | void MainWindow::openBook(QListViewItem *curritem) | 244 | void MainWindow::openBook(QListViewItem *curritem) |
245 | { | 245 | { |
246 | if ( !curritem ) return; | ||
246 | // find book in List | 247 | // find book in List |
247 | QString currname=curritem->text(posName); | 248 | QString currname=curritem->text(posName); |
248 | CBInfo *cb = checkbooks->first(); | 249 | CBInfo *cb = checkbooks->first(); |
249 | while ( cb ) { | 250 | while ( cb ) { |
250 | if ( cb->name() == currname ) | 251 | if ( cb->name() == currname ) |
251 | break; | 252 | break; |
252 | cb = checkbooks->next(); | 253 | cb = checkbooks->next(); |
253 | } | 254 | } |
254 | if ( !cb ) return; | 255 | if ( !cb ) return; |
255 | 256 | ||
256 | // | 257 | // |
257 | buildFilename( currname ); | 258 | buildFilename( currname ); |
258 | float currbalance = cb->balance(); | 259 | float currbalance = cb->balance(); |
259 | bool currlock = !cb->password().isNull(); | 260 | bool currlock = !cb->password().isNull(); |
260 | 261 | ||
261 | if ( currlock ) | 262 | if ( currlock ) |
262 | { | 263 | { |
263 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 264 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
264 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) | 265 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) |
265 | { | 266 | { |
266 | delete pw; | 267 | delete pw; |
267 | return; | 268 | return; |
268 | } | 269 | } |
269 | delete pw; | 270 | delete pw; |
270 | } | 271 | } |
271 | 272 | ||
272 | _cfg.setLastBook( currname ); | 273 | _cfg.setLastBook( currname ); |
273 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 274 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
274 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) | 275 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) |
275 | { | 276 | { |
276 | QString newname = cb->name(); | 277 | QString newname = cb->name(); |
277 | if ( currname != newname ) | 278 | if ( currname != newname ) |
278 | { | 279 | { |
279 | // Update name if changed | 280 | // Update name if changed |
280 | if( curritem ) { | 281 | curritem->setText( posName, newname ); |
281 | curritem->setText( posName, newname ); | 282 | cbList->sort(); |
282 | cbList->sort(); | ||
283 | } | ||
284 | _cfg.setLastBook( newname ); | 283 | _cfg.setLastBook( newname ); |
285 | 284 | ||
286 | // Remove old file | 285 | // Remove old file |
287 | QFile f( tempFilename ); | 286 | QFile f( tempFilename ); |
288 | if ( f.exists() ) | 287 | if ( f.exists() ) |
289 | f.remove(); | 288 | f.remove(); |
290 | 289 | ||
291 | // Get new filename | 290 | // Get new filename |
292 | buildFilename( newname ); | 291 | buildFilename( newname ); |
293 | cb->setFilename( tempFilename ); | 292 | cb->setFilename( tempFilename ); |
294 | } | 293 | } |
295 | 294 | ||
296 | cb->write(); | 295 | cb->write(); |
297 | 296 | ||
298 | // Update lock if changed | 297 | // Update lock if changed |
299 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) | 298 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) |
300 | { | 299 | { |
301 | if ( !cb->password().isNull() ) | 300 | if ( !cb->password().isNull() ) |
302 | curritem->setPixmap( 0, lockIcon ); | 301 | curritem->setPixmap( 0, lockIcon ); |
303 | else | 302 | else |
304 | curritem->setPixmap( 0, nullIcon ); | 303 | curritem->setPixmap( 0, nullIcon ); |
305 | } | 304 | } |
306 | 305 | ||
307 | // Update balance if changed | 306 | // Update balance if changed |
308 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) | 307 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) |
309 | { | 308 | { |
310 | QString tempstr; | 309 | QString tempstr; |
311 | tempstr.sprintf( "%.2f", cb->balance() ); | 310 | tempstr.sprintf( "%.2f", cb->balance() ); |
312 | tempstr.prepend( _cfg.getCurrencySymbol() ); | 311 | tempstr.prepend( _cfg.getCurrencySymbol() ); |
313 | curritem->setText( posName + 1, tempstr ); | 312 | curritem->setText( posName + 1, tempstr ); |
314 | } | 313 | } |
315 | 314 | ||
316 | // write config, if needed | 315 | // write config, if needed |
317 | if( _cfg.isDirty() ) { | 316 | if( _cfg.isDirty() ) { |
318 | Config config("checkbook"); | 317 | Config config("checkbook"); |
319 | _cfg.writeConfig( config ); | 318 | _cfg.writeConfig( config ); |
320 | } | 319 | } |
321 | } | 320 | } |
322 | delete currcb; | 321 | delete currcb; |
323 | } | 322 | } |
324 | 323 | ||
325 | // --- slotDelete ------------------------------------------------------------- | 324 | // --- slotDelete ------------------------------------------------------------- |
326 | void MainWindow::slotDelete() | 325 | void MainWindow::slotDelete() |
327 | { | 326 | { |
328 | QString currname = cbList->currentItem()->text( posName ); | 327 | QString currname = cbList->currentItem()->text( posName ); |
329 | 328 | ||
330 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) | 329 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) |
331 | { | 330 | { |