Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 235 |
1 files changed, 89 insertions, 146 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 5a6d607..7a6b7cc 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -28,5 +28,7 @@ | |||
28 | 28 | ||
29 | #include "checkbook.h" | 29 | #include "checkbook.h" |
30 | #include "cbinfo.h" | ||
30 | #include "transaction.h" | 31 | #include "transaction.h" |
32 | #include "traninfo.h" | ||
31 | #include "graph.h" | 33 | #include "graph.h" |
32 | #include "graphinfo.h" | 34 | #include "graphinfo.h" |
@@ -51,18 +53,13 @@ | |||
51 | #include <qwidget.h> | 53 | #include <qwidget.h> |
52 | 54 | ||
53 | Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol ) | 55 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) |
54 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 56 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
55 | { | 57 | { |
56 | name = n; | 58 | info = i; |
57 | filename = fd; | ||
58 | filename.append( name ); | ||
59 | filename.append( ".qcb" ); | ||
60 | filedir = fd; | ||
61 | currencySymbol = symbol; | 59 | currencySymbol = symbol; |
62 | currBalance = 0.0; | ||
63 | 60 | ||
64 | if ( name != "" ) | 61 | if ( info->name() != "" ) |
65 | { | 62 | { |
66 | QString tempstr = name; | 63 | QString tempstr = info->name(); |
67 | tempstr.append( " - " ); | 64 | tempstr.append( " - " ); |
68 | tempstr.append( tr( "Checkbook" ) ); | 65 | tempstr.append( tr( "Checkbook" ) ); |
@@ -96,9 +93,4 @@ Checkbook::~Checkbook() | |||
96 | } | 93 | } |
97 | 94 | ||
98 | const QString &Checkbook::getName() | ||
99 | { | ||
100 | return( name ); | ||
101 | } | ||
102 | |||
103 | QWidget *Checkbook::initInfo() | 95 | QWidget *Checkbook::initInfo() |
104 | { | 96 | { |
@@ -274,15 +266,14 @@ QWidget *Checkbook::initCharts() | |||
274 | void Checkbook::loadCheckbook() | 266 | void Checkbook::loadCheckbook() |
275 | { | 267 | { |
276 | transactions.clear(); | 268 | if ( !info ) |
277 | 269 | { | |
278 | Config config( filename, Config::File ); | 270 | return; |
271 | } | ||
279 | 272 | ||
280 | // Load info | 273 | tranList = info->transactions(); |
281 | config.setGroup( "Account" ); | ||
282 | 274 | ||
283 | password = config.readEntryCrypt( "Password", "" ); | 275 | passwordCB->setChecked( !info->password().isNull() ); |
284 | passwordCB->setChecked( password != "" ); | 276 | nameEdit->setText( info->name() ); |
285 | nameEdit->setText( name ); | 277 | QString temptext = info->type(); |
286 | QString temptext = config.readEntry( "Type" ); | ||
287 | int i = typeList->count(); | 278 | int i = typeList->count(); |
288 | while ( i > 0 ) | 279 | while ( i > 0 ) |
@@ -295,60 +286,39 @@ void Checkbook::loadCheckbook() | |||
295 | } | 286 | } |
296 | } | 287 | } |
297 | bankEdit->setText( config.readEntry( "Bank", "" ) ); | 288 | bankEdit->setText( info->bank() ); |
298 | acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) ); | 289 | acctNumEdit->setText( info->account() ); |
299 | pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) ); | 290 | pinNumEdit->setText( info->pin() ); |
300 | balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); | 291 | temptext.setNum( info->startingBalance(), 'f', 2 ); |
301 | notesEdit->setText( config.readEntry( "Notes", "" ) ); | 292 | balanceEdit->setText( temptext ); |
302 | 293 | notesEdit->setText( info->notes() ); | |
303 | bool ok; | ||
304 | currBalance = balanceEdit->text().toFloat( &ok ); | ||
305 | startBalance = currBalance; | ||
306 | 294 | ||
307 | // Load transactions | 295 | // Load transactions |
308 | TranInfo *tran; | ||
309 | QString trandesc = ""; | ||
310 | float amount; | 296 | float amount; |
311 | QString stramount; | 297 | QString stramount; |
312 | for ( int i = 1; trandesc != QString::null; i++ ) | ||
313 | { | ||
314 | tran = new TranInfo( config, i ); | ||
315 | trandesc = tran->desc(); | ||
316 | if ( trandesc != QString::null ) | ||
317 | { | ||
318 | currBalance -= tran->fee(); | ||
319 | amount = tran->amount(); | ||
320 | if ( tran->withdrawal() ) | ||
321 | { | ||
322 | amount *= -1; | ||
323 | } | ||
324 | currBalance += amount; | ||
325 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | ||
326 | |||
327 | // Add to transaction list | ||
328 | transactions.inSort( tran ); | ||
329 | 298 | ||
330 | // Add to transaction table | 299 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) |
331 | ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount ); | 300 | { |
332 | } | 301 | amount = tran->amount(); |
333 | else | 302 | if ( tran->withdrawal() ) |
334 | { | 303 | { |
335 | delete tran; | 304 | amount *= -1; |
336 | } | 305 | } |
306 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | ||
307 | ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); | ||
337 | } | 308 | } |
338 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | ||
339 | 309 | ||
340 | highTranNum = transactions.count(); | 310 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); |
311 | |||
312 | highTranNum = tranList->count(); | ||
341 | } | 313 | } |
342 | 314 | ||
343 | void Checkbook::adjustBalance( float amount ) | 315 | void Checkbook::adjustBalance() |
344 | { | 316 | { |
345 | currBalance += amount; | 317 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); |
346 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | ||
347 | |||
348 | } | 318 | } |
349 | 319 | ||
350 | TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) | 320 | TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) |
351 | { | 321 | { |
352 | TranInfo *traninfo = transactions.first(); | 322 | TranInfo *traninfo = tranList->first(); |
353 | while ( traninfo ) | 323 | while ( traninfo ) |
354 | { | 324 | { |
@@ -356,5 +326,5 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con | |||
356 | traninfo->desc() == desc ) | 326 | traninfo->desc() == desc ) |
357 | break; | 327 | break; |
358 | traninfo = transactions.next(); | 328 | traninfo = tranList->next(); |
359 | } | 329 | } |
360 | return( traninfo ); | 330 | return( traninfo ); |
@@ -363,30 +333,12 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con | |||
363 | void Checkbook::accept() | 333 | void Checkbook::accept() |
364 | { | 334 | { |
365 | QFile f( filename ); | 335 | info->setName( nameEdit->text() ); |
366 | if ( f.exists() ) | 336 | info->setType( typeList->currentText() ); |
367 | { | 337 | info->setBank( bankEdit->text() ); |
368 | f.remove(); | 338 | info->setAccount( acctNumEdit->text() ); |
369 | } | 339 | info->setPin( pinNumEdit->text() ); |
370 | 340 | bool ok; | |
371 | Config *config = new Config(filename, Config::File); | 341 | info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); |
372 | 342 | info->setNotes( notesEdit->text() ); | |
373 | // Save info | ||
374 | config->setGroup( "Account" ); | ||
375 | config->writeEntryCrypt( "Password", password ); | ||
376 | config->writeEntry( "Type", typeList->currentText() ); | ||
377 | config->writeEntry( "Bank", bankEdit->text() ); | ||
378 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); | ||
379 | config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); | ||
380 | config->writeEntry( "Balance", balanceEdit->text() ); | ||
381 | config->writeEntry( "Notes", notesEdit->text() ); | ||
382 | |||
383 | // Save transactions | ||
384 | int i = 1; | ||
385 | for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) | ||
386 | { | ||
387 | tran->write( config, i ); | ||
388 | i++; | ||
389 | } | ||
390 | config->write(); | ||
391 | 343 | ||
392 | QDialog::accept(); | 344 | QDialog::accept(); |
@@ -395,5 +347,5 @@ void Checkbook::accept() | |||
395 | void Checkbook::slotPasswordClicked() | 347 | void Checkbook::slotPasswordClicked() |
396 | { | 348 | { |
397 | if ( password == "" && passwordCB->isChecked() ) | 349 | if ( info->password().isNull() && passwordCB->isChecked() ) |
398 | { | 350 | { |
399 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 351 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
@@ -404,23 +356,23 @@ void Checkbook::slotPasswordClicked() | |||
404 | return; | 356 | return; |
405 | } | 357 | } |
406 | password = pw->password; | 358 | info->setPassword( pw->password ); |
407 | delete pw; | 359 | delete pw; |
408 | 360 | ||
409 | pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); | 361 | pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); |
410 | if ( pw->exec() != QDialog::Accepted || pw->password != password ) | 362 | if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) |
411 | { | 363 | { |
412 | passwordCB->setChecked( FALSE ); | 364 | passwordCB->setChecked( FALSE ); |
413 | password = ""; | 365 | info->setPassword( QString::null ); |
414 | } | 366 | } |
415 | 367 | ||
416 | delete pw; | 368 | delete pw; |
417 | } | 369 | } |
418 | else if ( password != "" && !passwordCB->isChecked() ) | 370 | else if ( !info->password().isNull() && !passwordCB->isChecked() ) |
419 | { | 371 | { |
420 | Password *pw = new Password( this, tr( "Enter password" ), | 372 | Password *pw = new Password( this, tr( "Enter password" ), |
421 | tr( "Please enter your password to confirm removal of password protection:" ) ); | 373 | tr( "Please enter your password to confirm removal of password protection:" ) ); |
422 | if ( pw->exec() == QDialog::Accepted && pw->password == password ) | 374 | if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) |
423 | { | 375 | { |
424 | password = ""; | 376 | info->setPassword( QString::null ); |
425 | delete pw; | 377 | delete pw; |
426 | return; | 378 | return; |
@@ -437,20 +389,23 @@ void Checkbook::slotPasswordClicked() | |||
437 | void Checkbook::slotNameChanged( const QString &newname ) | 389 | void Checkbook::slotNameChanged( const QString &newname ) |
438 | { | 390 | { |
439 | name = newname; | 391 | info->setName( newname ); |
440 | filename = filedir; | 392 | |
441 | filename.append( newname ); | 393 | // TODO - need filedir |
442 | filename.append( ".qcb" ); | 394 | //QString namestr = filedir; |
443 | QString tempstr = name; | 395 | //namestr.append( newname ); |
444 | tempstr.append( " - " ); | 396 | //namestr.append( ".qcb" ); |
445 | tempstr.append( tr( "Checkbook" ) ); | 397 | //info->setFilename( namestr ); |
446 | setCaption( tempstr ); | 398 | |
399 | QString namestr = newname; | ||
400 | namestr.append( " - " ); | ||
401 | namestr.append( tr( "Checkbook" ) ); | ||
402 | setCaption( namestr ); | ||
447 | } | 403 | } |
448 | 404 | ||
449 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | 405 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) |
450 | { | 406 | { |
451 | currBalance -= startBalance; | ||
452 | bool ok; | 407 | bool ok; |
453 | startBalance = newbalance.toFloat( &ok ); | 408 | info->setStartingBalance( newbalance.toFloat( &ok ) ); |
454 | adjustBalance( startBalance ); | 409 | adjustBalance(); |
455 | } | 410 | } |
456 | 411 | ||
@@ -460,5 +415,5 @@ void Checkbook::slotNewTran() | |||
460 | TranInfo *traninfo = new TranInfo( highTranNum ); | 415 | TranInfo *traninfo = new TranInfo( highTranNum ); |
461 | 416 | ||
462 | Transaction *currtran = new Transaction( this, name, | 417 | Transaction *currtran = new Transaction( this, info->name(), |
463 | traninfo, | 418 | traninfo, |
464 | currencySymbol ); | 419 | currencySymbol ); |
@@ -466,20 +421,22 @@ void Checkbook::slotNewTran() | |||
466 | if ( currtran->exec() == QDialog::Accepted ) | 421 | if ( currtran->exec() == QDialog::Accepted ) |
467 | { | 422 | { |
468 | float amount = traninfo->amount(); | 423 | // Add to transaction list |
424 | info->addTransaction( traninfo ); | ||
425 | |||
426 | // Add to transaction table | ||
427 | float amount; | ||
428 | QString stramount; | ||
429 | |||
430 | amount = traninfo->amount(); | ||
469 | if ( traninfo->withdrawal() ) | 431 | if ( traninfo->withdrawal() ) |
470 | { | 432 | { |
471 | amount *= -1; | 433 | amount *= -1; |
472 | } | 434 | } |
473 | QString stramount; | ||
474 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 435 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); |
475 | 436 | ||
476 | // Add to transaction list | ||
477 | transactions.inSort( traninfo ); | ||
478 | |||
479 | // Add to transaction table | ||
480 | ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), | 437 | ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), |
481 | stramount ); | 438 | stramount ); |
482 | 439 | ||
483 | adjustBalance( amount ); | 440 | adjustBalance(); |
484 | } | 441 | } |
485 | else | 442 | else |
@@ -498,12 +455,8 @@ void Checkbook::slotEditTran() | |||
498 | } | 455 | } |
499 | 456 | ||
500 | TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); | 457 | TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), |
501 | float origamt = traninfo->amount(); | 458 | curritem->text( 2 ) ); |
502 | if ( traninfo->withdrawal() ) | ||
503 | { | ||
504 | origamt *= -1; | ||
505 | } | ||
506 | 459 | ||
507 | Transaction *currtran = new Transaction( this, name, | 460 | Transaction *currtran = new Transaction( this, info->name(), |
508 | traninfo, | 461 | traninfo, |
509 | currencySymbol ); | 462 | currencySymbol ); |
@@ -511,6 +464,6 @@ void Checkbook::slotEditTran() | |||
511 | if ( currtran->exec() == QDialog::Accepted ) | 464 | if ( currtran->exec() == QDialog::Accepted ) |
512 | { | 465 | { |
466 | curritem->setText( 0, traninfo->number() ); | ||
513 | curritem->setText( 1, traninfo->datestr() ); | 467 | curritem->setText( 1, traninfo->datestr() ); |
514 | |||
515 | curritem->setText( 2, traninfo->desc() ); | 468 | curritem->setText( 2, traninfo->desc() ); |
516 | 469 | ||
@@ -520,14 +473,12 @@ void Checkbook::slotEditTran() | |||
520 | amount *= -1; | 473 | amount *= -1; |
521 | } | 474 | } |
522 | adjustBalance( origamt * -1 ); | ||
523 | adjustBalance( amount ); | ||
524 | QString stramount; | 475 | QString stramount; |
525 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 476 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); |
526 | curritem->setText( 3, stramount ); | 477 | curritem->setText( 3, stramount ); |
527 | 478 | ||
528 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | 479 | adjustBalance(); |
529 | |||
530 | delete currtran; | ||
531 | } | 480 | } |
481 | |||
482 | delete currtran; | ||
532 | } | 483 | } |
533 | 484 | ||
@@ -544,15 +495,7 @@ void Checkbook::slotDeleteTran() | |||
544 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) | 495 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) |
545 | { | 496 | { |
546 | float amount = traninfo->amount(); | 497 | info->removeTransaction( traninfo ); |
547 | if ( traninfo->withdrawal() ) | ||
548 | { | ||
549 | amount *= -1; | ||
550 | } | ||
551 | |||
552 | transactions.remove( traninfo ); | ||
553 | delete traninfo; | ||
554 | delete curritem; | 498 | delete curritem; |
555 | 499 | adjustBalance(); | |
556 | adjustBalance( amount * -1 ); | ||
557 | } | 500 | } |
558 | } | 501 | } |
@@ -583,11 +526,11 @@ void Checkbook::drawBalanceChart() | |||
583 | DataPointList *list = new DataPointList(); | 526 | DataPointList *list = new DataPointList(); |
584 | 527 | ||
585 | float balance = startBalance; | 528 | float balance = info->startingBalance(); |
586 | float amount; | 529 | float amount; |
587 | QString label; | 530 | QString label; |
588 | int i = 0; | 531 | int i = 0; |
589 | int count = transactions.count(); | 532 | int count = tranList->count(); |
590 | 533 | ||
591 | for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) | 534 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) |
592 | { | 535 | { |
593 | i++; | 536 | i++; |
@@ -617,13 +560,13 @@ void Checkbook::drawCategoryChart( bool withdrawals ) | |||
617 | DataPointList *list = new DataPointList(); | 560 | DataPointList *list = new DataPointList(); |
618 | 561 | ||
619 | TranInfo *tran = transactions.first(); | 562 | TranInfo *tran = tranList->first(); |
620 | if ( tran && tran->withdrawal() == withdrawals ) | 563 | if ( tran && tran->withdrawal() == withdrawals ) |
621 | { | 564 | { |
622 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | 565 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); |
623 | } | 566 | } |
624 | tran = transactions.next(); | 567 | tran = tranList->next(); |
625 | 568 | ||
626 | DataPointInfo *cat; | 569 | DataPointInfo *cat; |
627 | for ( ; tran; tran = transactions.next() ) | 570 | for ( ; tran; tran = tranList->next() ) |
628 | { | 571 | { |
629 | if ( tran->withdrawal() == withdrawals ) | 572 | if ( tran->withdrawal() == withdrawals ) |
@@ -713,3 +656,3 @@ bool CBListItem::isAltBackground() | |||
713 | } | 656 | } |
714 | return false; | 657 | return false; |
715 | } \ No newline at end of file | 658 | } |