Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 4b81c6d..20b42b5 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -23,16 +23,18 @@ | |||
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 "transaction.h" | 30 | #include "transaction.h" |
31 | #include "graph.h" | ||
32 | #include "graphinfo.h" | ||
31 | 33 | ||
32 | #include <opie/otabwidget.h> | 34 | #include <opie/otabwidget.h> |
33 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
34 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/qpemessagebox.h> | 37 | #include <qpe/qpemessagebox.h> |
36 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
37 | 39 | ||
38 | #include <qcombobox.h> | 40 | #include <qcombobox.h> |
@@ -45,24 +47,29 @@ | |||
45 | #include <qpushbutton.h> | 47 | #include <qpushbutton.h> |
46 | #include <qwhatsthis.h> | 48 | #include <qwhatsthis.h> |
47 | #include <qwidget.h> | 49 | #include <qwidget.h> |
48 | 50 | ||
49 | Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) | 51 | Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) |
50 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 52 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
51 | { | 53 | { |
52 | name = n; | 54 | name = n; |
53 | filename = fd + name + ".qcb"; | 55 | filename = fd; |
56 | filename.append( name ); | ||
57 | filename.append( ".qcb" ); | ||
54 | filedir = fd; | 58 | filedir = fd; |
55 | currencySymbol = symbol; | 59 | currencySymbol = symbol; |
56 | currBalance = 0.0; | 60 | currBalance = 0.0; |
57 | 61 | ||
58 | if ( name != "" ) | 62 | if ( name != "" ) |
59 | { | 63 | { |
60 | setCaption( name + " - " + tr( "Checkbook" ) ); | 64 | QString tempstr = name; |
65 | tempstr.append( " - " ); | ||
66 | tempstr.append( tr( "Checkbook" ) ); | ||
67 | setCaption( tempstr ); | ||
61 | } | 68 | } |
62 | else | 69 | else |
63 | { | 70 | { |
64 | setCaption( tr( "New checkbook" ) ); | 71 | setCaption( tr( "New checkbook" ) ); |
65 | } | 72 | } |
66 | 73 | ||
67 | // Setup layout to make everything pretty | 74 | // Setup layout to make everything pretty |
68 | QVBoxLayout *layout = new QVBoxLayout( this ); | 75 | QVBoxLayout *layout = new QVBoxLayout( this ); |
@@ -237,23 +244,24 @@ QWidget *Checkbook::initCharts() | |||
237 | layout->addWidget( label, 0, 0 ); | 244 | layout->addWidget( label, 0, 0 ); |
238 | graphList = new QComboBox( control ); | 245 | graphList = new QComboBox( control ); |
239 | graphList->insertItem( tr( "By category" ) ); | 246 | graphList->insertItem( tr( "By category" ) ); |
240 | graphList->insertItem( tr( "..." ) ); | 247 | graphList->insertItem( tr( "..." ) ); |
241 | graphList->insertItem( tr( "..." ) ); | 248 | graphList->insertItem( tr( "..." ) ); |
242 | layout->addWidget( graphList, 0, 1 ); | 249 | layout->addWidget( graphList, 0, 1 ); |
243 | */ | 250 | */ |
244 | 251 | ||
245 | QWidget *graphWidget = new QWidget( control ); | 252 | GraphInfo* info = new GraphInfo( GraphInfo::BarChart, 0x0, tr( "Graph Title" ), |
246 | QWhatsThis::add( graphWidget, tr( "Graph not implemented yet." ) ); | 253 | tr( "X-Axis" ), tr( "Y-Axis" ) ); |
254 | graphWidget = new Graph( control, info ); | ||
255 | QWhatsThis::add( graphWidget, tr( "Charting is not implemented yet." ) ); | ||
247 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 1 ); | 256 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 1 ); |
248 | graphWidget->setBackgroundMode( QWidget::PaletteBase ); | ||
249 | 257 | ||
250 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); | 258 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); |
251 | QWhatsThis::add( btn, tr( "Click here to draw the graph." ) ); | 259 | QWhatsThis::add( btn, tr( "Click here to draw the chart." ) ); |
252 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); | 260 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); |
253 | layout->addWidget( btn, 1, 1 ); | 261 | layout->addWidget( btn, 1, 1 ); |
254 | 262 | ||
255 | return control; | 263 | return control; |
256 | } | 264 | } |
257 | 265 | ||
258 | void Checkbook::loadCheckbook() | 266 | void Checkbook::loadCheckbook() |
259 | { | 267 | { |
@@ -271,18 +279,18 @@ void Checkbook::loadCheckbook() | |||
271 | i--; | 279 | i--; |
272 | typeList->setCurrentItem( i ); | 280 | typeList->setCurrentItem( i ); |
273 | if ( typeList->currentText() == temptext ) | 281 | if ( typeList->currentText() == temptext ) |
274 | { | 282 | { |
275 | break; | 283 | break; |
276 | } | 284 | } |
277 | } | 285 | } |
278 | bankEdit->setText( config.readEntry( "Bank", "" ) ); | 286 | bankEdit->setText( config.readEntry( "Bank", "" ) ); |
279 | acctNumEdit->setText( config.readEntry( "Number", "" ) ); | 287 | acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) ); |
280 | pinNumEdit->setText( config.readEntry( "PINNumber", "" ) ); | 288 | pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) ); |
281 | balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); | 289 | balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); |
282 | notesEdit->setText( config.readEntry( "Notes", "" ) ); | 290 | notesEdit->setText( config.readEntry( "Notes", "" ) ); |
283 | 291 | ||
284 | bool ok; | 292 | bool ok; |
285 | currBalance = balanceEdit->text().toFloat( &ok ); | 293 | currBalance = balanceEdit->text().toFloat( &ok ); |
286 | startBalance = currBalance; | 294 | startBalance = currBalance; |
287 | 295 | ||
288 | // Load transactions | 296 | // Load transactions |
@@ -304,21 +312,17 @@ void Checkbook::loadCheckbook() | |||
304 | } | 312 | } |
305 | currBalance += amount; | 313 | currBalance += amount; |
306 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 314 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); |
307 | 315 | ||
308 | // Add to transaction list | 316 | // Add to transaction list |
309 | transactions.append( tran ); | 317 | transactions.append( tran ); |
310 | 318 | ||
311 | // Add to transaction table | 319 | // Add to transaction table |
312 | QDate date = tran->date(); | 320 | ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), |
313 | QString datestr = QString::number( date.month() ) + "/" + | ||
314 | QString::number( date.day() ) + "/" + | ||
315 | QString::number( date.year() ); | ||
316 | ( void ) new QListViewItem( tranTable, QString::number( i ), datestr, | ||
317 | trandesc, stramount ); | 321 | trandesc, stramount ); |
318 | } | 322 | } |
319 | else | 323 | else |
320 | { | 324 | { |
321 | delete tran; | 325 | delete tran; |
322 | } | 326 | } |
323 | } | 327 | } |
324 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | 328 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); |
@@ -352,18 +356,18 @@ void Checkbook::accept() | |||
352 | } | 356 | } |
353 | 357 | ||
354 | Config *config = new Config(filename, Config::File); | 358 | Config *config = new Config(filename, Config::File); |
355 | 359 | ||
356 | // Save info | 360 | // Save info |
357 | config->setGroup( "Account" ); | 361 | config->setGroup( "Account" ); |
358 | config->writeEntry( "Type", typeList->currentText() ); | 362 | config->writeEntry( "Type", typeList->currentText() ); |
359 | config->writeEntry( "Bank", bankEdit->text() ); | 363 | config->writeEntry( "Bank", bankEdit->text() ); |
360 | config->writeEntry( "Number", acctNumEdit->text() ); | 364 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); |
361 | config->writeEntry( "PINNumber", pinNumEdit->text() ); | 365 | config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); |
362 | config->writeEntry( "Balance", balanceEdit->text() ); | 366 | config->writeEntry( "Balance", balanceEdit->text() ); |
363 | config->writeEntry( "Notes", notesEdit->text() ); | 367 | config->writeEntry( "Notes", notesEdit->text() ); |
364 | 368 | ||
365 | // Save transactions | 369 | // Save transactions |
366 | TranInfo *tran = transactions.first(); | 370 | TranInfo *tran = transactions.first(); |
367 | int i = 1; | 371 | int i = 1; |
368 | while ( tran ) | 372 | while ( tran ) |
369 | { | 373 | { |
@@ -374,18 +378,23 @@ void Checkbook::accept() | |||
374 | config->write(); | 378 | config->write(); |
375 | 379 | ||
376 | QDialog::accept(); | 380 | QDialog::accept(); |
377 | } | 381 | } |
378 | 382 | ||
379 | void Checkbook::slotNameChanged( const QString &newname ) | 383 | void Checkbook::slotNameChanged( const QString &newname ) |
380 | { | 384 | { |
381 | name = newname; | 385 | name = newname; |
382 | filename = filedir + newname + ".qcb"; | 386 | filename = filedir; |
383 | setCaption( name + " - " + tr( "Checkbook" ) ); | 387 | filename.append( newname ); |
388 | filename.append( ".qcb" ); | ||
389 | QString tempstr = name; | ||
390 | tempstr.append( " - " ); | ||
391 | tempstr.append( tr( "Checkbook" ) ); | ||
392 | setCaption( tempstr ); | ||
384 | } | 393 | } |
385 | 394 | ||
386 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | 395 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) |
387 | { | 396 | { |
388 | currBalance -= startBalance; | 397 | currBalance -= startBalance; |
389 | bool ok; | 398 | bool ok; |
390 | startBalance = newbalance.toFloat( &ok ); | 399 | startBalance = newbalance.toFloat( &ok ); |
391 | adjustBalance( startBalance ); | 400 | adjustBalance( startBalance ); |
@@ -409,23 +418,18 @@ void Checkbook::slotNewTran() | |||
409 | } | 418 | } |
410 | QString stramount; | 419 | QString stramount; |
411 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 420 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); |
412 | 421 | ||
413 | // Add to transaction list | 422 | // Add to transaction list |
414 | transactions.append( traninfo ); | 423 | transactions.append( traninfo ); |
415 | 424 | ||
416 | // Add to transaction table | 425 | // Add to transaction table |
417 | 426 | ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), | |
418 | QDate date = traninfo->date(); | 427 | traninfo->datestr(), traninfo->desc(), stramount ); |
419 | QString datestr = QString::number( date.month() ) + "/" + | ||
420 | QString::number( date.day() ) + "/" + | ||
421 | QString::number( date.year() ); | ||
422 | ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), datestr, | ||
423 | traninfo->desc(), stramount ); | ||
424 | 428 | ||
425 | adjustBalance( amount ); | 429 | adjustBalance( amount ); |
426 | } | 430 | } |
427 | else | 431 | else |
428 | { | 432 | { |
429 | highTranNum--; | 433 | highTranNum--; |
430 | delete traninfo; | 434 | delete traninfo; |
431 | } | 435 | } |
@@ -449,21 +453,17 @@ void Checkbook::slotEditTran() | |||
449 | } | 453 | } |
450 | 454 | ||
451 | Transaction *currtran = new Transaction( this, name, | 455 | Transaction *currtran = new Transaction( this, name, |
452 | traninfo, | 456 | traninfo, |
453 | currencySymbol ); | 457 | currencySymbol ); |
454 | currtran->showMaximized(); | 458 | currtran->showMaximized(); |
455 | if ( currtran->exec() == QDialog::Accepted ) | 459 | if ( currtran->exec() == QDialog::Accepted ) |
456 | { | 460 | { |
457 | QDate date = traninfo->date(); | 461 | curritem->setText( 1, traninfo->datestr() ); |
458 | QString datestr = QString::number( date.month() ) + "/" + | ||
459 | QString::number( date.day() ) + "/" + | ||
460 | QString::number( date.year() ); | ||
461 | curritem->setText( 1, datestr ); | ||
462 | 462 | ||
463 | curritem->setText( 2, traninfo->desc() ); | 463 | curritem->setText( 2, traninfo->desc() ); |
464 | 464 | ||
465 | float amount = traninfo->amount(); | 465 | float amount = traninfo->amount(); |
466 | if ( traninfo->withdrawal() ) | 466 | if ( traninfo->withdrawal() ) |
467 | { | 467 | { |
468 | amount *= -1; | 468 | amount *= -1; |
469 | } | 469 | } |
@@ -484,17 +484,16 @@ void Checkbook::slotDeleteTran() | |||
484 | QListViewItem *curritem = tranTable->currentItem(); | 484 | QListViewItem *curritem = tranTable->currentItem(); |
485 | if ( !curritem ) | 485 | if ( !curritem ) |
486 | { | 486 | { |
487 | return; | 487 | return; |
488 | } | 488 | } |
489 | 489 | ||
490 | bool ok; | 490 | bool ok; |
491 | int tranid = curritem->text( 0 ).toInt( &ok ); | 491 | int tranid = curritem->text( 0 ).toInt( &ok ); |
492 | //TranInfo *traninfo = transactions.at( tranid - 1 ); | ||
493 | TranInfo *traninfo = findTranByID( tranid ); | 492 | TranInfo *traninfo = findTranByID( tranid ); |
494 | 493 | ||
495 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) | 494 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) |
496 | { | 495 | { |
497 | float amount = traninfo->amount(); | 496 | float amount = traninfo->amount(); |
498 | if ( traninfo->withdrawal() ) | 497 | if ( traninfo->withdrawal() ) |
499 | { | 498 | { |
500 | amount *= -1; | 499 | amount *= -1; |