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 | |||
@@ -18,61 +18,58 @@ | |||
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
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" |
33 | #include "password.h" | 35 | #include "password.h" |
34 | 36 | ||
35 | #include <opie/otabwidget.h> | 37 | #include <opie/otabwidget.h> |
36 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
37 | #include <qpe/qpeapplication.h> | 39 | #include <qpe/qpeapplication.h> |
38 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
39 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
40 | 42 | ||
41 | #include <qcheckbox.h> | 43 | #include <qcheckbox.h> |
42 | #include <qcombobox.h> | 44 | #include <qcombobox.h> |
43 | #include <qfile.h> | 45 | #include <qfile.h> |
44 | #include <qfontmetrics.h> | 46 | #include <qfontmetrics.h> |
45 | #include <qlabel.h> | 47 | #include <qlabel.h> |
46 | #include <qlayout.h> | 48 | #include <qlayout.h> |
47 | #include <qlineedit.h> | 49 | #include <qlineedit.h> |
48 | #include <qmultilineedit.h> | 50 | #include <qmultilineedit.h> |
49 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
50 | #include <qwhatsthis.h> | 52 | #include <qwhatsthis.h> |
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" ) ); |
69 | setCaption( tempstr ); | 66 | setCaption( tempstr ); |
70 | } | 67 | } |
71 | else | 68 | else |
72 | { | 69 | { |
73 | setCaption( tr( "New checkbook" ) ); | 70 | setCaption( tr( "New checkbook" ) ); |
74 | } | 71 | } |
75 | 72 | ||
76 | // Setup layout to make everything pretty | 73 | // Setup layout to make everything pretty |
77 | QVBoxLayout *layout = new QVBoxLayout( this ); | 74 | QVBoxLayout *layout = new QVBoxLayout( this ); |
78 | layout->setMargin( 2 ); | 75 | layout->setMargin( 2 ); |
@@ -86,29 +83,24 @@ Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, cons | |||
86 | mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); | 83 | mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); |
87 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); | 84 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); |
88 | mainWidget->setCurrentTab( tr( "Info" ) ); | 85 | mainWidget->setCurrentTab( tr( "Info" ) ); |
89 | 86 | ||
90 | // Load checkbook information | 87 | // Load checkbook information |
91 | loadCheckbook(); | 88 | loadCheckbook(); |
92 | } | 89 | } |
93 | 90 | ||
94 | Checkbook::~Checkbook() | 91 | Checkbook::~Checkbook() |
95 | { | 92 | { |
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 | { |
105 | QWidget *control = new QWidget( mainWidget ); | 97 | QWidget *control = new QWidget( mainWidget ); |
106 | 98 | ||
107 | QVBoxLayout *vb = new QVBoxLayout( control ); | 99 | QVBoxLayout *vb = new QVBoxLayout( control ); |
108 | 100 | ||
109 | QScrollView *sv = new QScrollView( control ); | 101 | QScrollView *sv = new QScrollView( control ); |
110 | vb->addWidget( sv, 0, 0 ); | 102 | vb->addWidget( sv, 0, 0 ); |
111 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 103 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
112 | sv->setFrameStyle( QFrame::NoFrame ); | 104 | sv->setFrameStyle( QFrame::NoFrame ); |
113 | 105 | ||
114 | QWidget *container = new QWidget( sv->viewport() ); | 106 | QWidget *container = new QWidget( sv->viewport() ); |
@@ -264,305 +256,256 @@ QWidget *Checkbook::initCharts() | |||
264 | layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); | 256 | layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); |
265 | 257 | ||
266 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); | 258 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); |
267 | QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); | 259 | QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); |
268 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); | 260 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); |
269 | layout->addWidget( btn, 1, 2 ); | 261 | layout->addWidget( btn, 1, 2 ); |
270 | 262 | ||
271 | return control; | 263 | return control; |
272 | } | 264 | } |
273 | 265 | ||
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 ) |
289 | { | 280 | { |
290 | i--; | 281 | i--; |
291 | typeList->setCurrentItem( i ); | 282 | typeList->setCurrentItem( i ); |
292 | if ( typeList->currentText() == temptext ) | 283 | if ( typeList->currentText() == temptext ) |
293 | { | 284 | { |
294 | break; | 285 | break; |
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 | { |
355 | if ( traninfo->number() == checknum && traninfo->datestr() == date && | 325 | if ( traninfo->number() == checknum && traninfo->datestr() == date && |
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 ); |
361 | } | 331 | } |
362 | 332 | ||
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(); |
393 | } | 345 | } |
394 | 346 | ||
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:" ) ); |
400 | if ( pw->exec() != QDialog::Accepted ) | 352 | if ( pw->exec() != QDialog::Accepted ) |
401 | { | 353 | { |
402 | passwordCB->setChecked( FALSE ); | 354 | passwordCB->setChecked( FALSE ); |
403 | delete pw; | 355 | delete pw; |
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; |
427 | } | 379 | } |
428 | else | 380 | else |
429 | { | 381 | { |
430 | passwordCB->setChecked( TRUE ); | 382 | passwordCB->setChecked( TRUE ); |
431 | } | 383 | } |
432 | 384 | ||
433 | delete pw; | 385 | delete pw; |
434 | } | 386 | } |
435 | } | 387 | } |
436 | 388 | ||
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 | ||
457 | void Checkbook::slotNewTran() | 412 | void Checkbook::slotNewTran() |
458 | { | 413 | { |
459 | highTranNum++; | 414 | highTranNum++; |
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 ); |
465 | currtran->showMaximized(); | 420 | currtran->showMaximized(); |
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 |
486 | { | 443 | { |
487 | highTranNum--; | 444 | highTranNum--; |
488 | delete traninfo; | 445 | delete traninfo; |
489 | } | 446 | } |
490 | } | 447 | } |
491 | 448 | ||
492 | void Checkbook::slotEditTran() | 449 | void Checkbook::slotEditTran() |
493 | { | 450 | { |
494 | QListViewItem *curritem = tranTable->currentItem(); | 451 | QListViewItem *curritem = tranTable->currentItem(); |
495 | if ( !curritem ) | 452 | if ( !curritem ) |
496 | { | 453 | { |
497 | return; | 454 | return; |
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 ); |
510 | currtran->showMaximized(); | 463 | currtran->showMaximized(); |
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 | ||
517 | float amount = traninfo->amount(); | 470 | float amount = traninfo->amount(); |
518 | if ( traninfo->withdrawal() ) | 471 | if ( traninfo->withdrawal() ) |
519 | { | 472 | { |
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 | ||
534 | void Checkbook::slotDeleteTran() | 485 | void Checkbook::slotDeleteTran() |
535 | { | 486 | { |
536 | QListViewItem *curritem = tranTable->currentItem(); | 487 | QListViewItem *curritem = tranTable->currentItem(); |
537 | if ( !curritem ) | 488 | if ( !curritem ) |
538 | { | 489 | { |
539 | return; | 490 | return; |
540 | } | 491 | } |
541 | 492 | ||
542 | TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); | 493 | TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); |
543 | 494 | ||
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 | } |
559 | 502 | ||
560 | void Checkbook::slotDrawGraph() | 503 | void Checkbook::slotDrawGraph() |
561 | { | 504 | { |
562 | if ( graphInfo ) | 505 | if ( graphInfo ) |
563 | { | 506 | { |
564 | delete graphInfo; | 507 | delete graphInfo; |
565 | } | 508 | } |
566 | 509 | ||
567 | switch ( graphList->currentItem() ) | 510 | switch ( graphList->currentItem() ) |
568 | { | 511 | { |
@@ -573,31 +516,31 @@ void Checkbook::slotDrawGraph() | |||
573 | case 2 : drawCategoryChart( FALSE ); | 516 | case 2 : drawCategoryChart( FALSE ); |
574 | break; | 517 | break; |
575 | }; | 518 | }; |
576 | 519 | ||
577 | graphWidget->setGraphInfo( graphInfo ); | 520 | graphWidget->setGraphInfo( graphInfo ); |
578 | graphWidget->drawGraph( TRUE ); | 521 | graphWidget->drawGraph( TRUE ); |
579 | } | 522 | } |
580 | 523 | ||
581 | void Checkbook::drawBalanceChart() | 524 | void Checkbook::drawBalanceChart() |
582 | { | 525 | { |
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++; |
594 | balance -= tran->fee(); | 537 | balance -= tran->fee(); |
595 | amount = tran->amount(); | 538 | amount = tran->amount(); |
596 | if ( tran->withdrawal() ) | 539 | if ( tran->withdrawal() ) |
597 | { | 540 | { |
598 | amount *= -1; | 541 | amount *= -1; |
599 | } | 542 | } |
600 | balance += amount; | 543 | balance += amount; |
601 | if ( i == 1 || i == count / 2 || i == count ) | 544 | if ( i == 1 || i == count / 2 || i == count ) |
602 | { | 545 | { |
603 | label = tran->datestr(); | 546 | label = tran->datestr(); |
@@ -607,33 +550,33 @@ void Checkbook::drawBalanceChart() | |||
607 | label = ""; | 550 | label = ""; |
608 | } | 551 | } |
609 | list->append( new DataPointInfo( label, balance ) ); | 552 | list->append( new DataPointInfo( label, balance ) ); |
610 | } | 553 | } |
611 | 554 | ||
612 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); | 555 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); |
613 | } | 556 | } |
614 | 557 | ||
615 | void Checkbook::drawCategoryChart( bool withdrawals ) | 558 | void Checkbook::drawCategoryChart( bool withdrawals ) |
616 | { | 559 | { |
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 ) |
630 | { | 573 | { |
631 | // Find category in list | 574 | // Find category in list |
632 | for ( cat = list->first(); cat; cat = list->next() ) | 575 | for ( cat = list->first(); cat; cat = list->next() ) |
633 | { | 576 | { |
634 | if ( cat->label() == tran->category() ) | 577 | if ( cat->label() == tran->category() ) |
635 | { | 578 | { |
636 | break; | 579 | break; |
637 | } | 580 | } |
638 | } | 581 | } |
639 | if ( cat && cat->label() == tran->category() ) | 582 | if ( cat && cat->label() == tran->category() ) |
@@ -703,13 +646,13 @@ bool CBListItem::isAltBackground() | |||
703 | } | 646 | } |
704 | 647 | ||
705 | while(item) | 648 | while(item) |
706 | { | 649 | { |
707 | item->m_odd = previous = !previous; | 650 | item->m_odd = previous = !previous; |
708 | item->m_known = true; | 651 | item->m_known = true; |
709 | item = (CBListItem *)( item->nextSibling() ); | 652 | item = (CBListItem *)( item->nextSibling() ); |
710 | } | 653 | } |
711 | } | 654 | } |
712 | return m_odd; | 655 | return m_odd; |
713 | } | 656 | } |
714 | return false; | 657 | return false; |
715 | } \ No newline at end of file | 658 | } |