summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp235
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
@@ -29,3 +29,5 @@
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"
@@ -52,16 +54,11 @@
52 54
53Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol ) 55Checkbook::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( " - " );
@@ -97,7 +94,2 @@ Checkbook::~Checkbook()
97 94
98const QString &Checkbook::getName()
99{
100 return( name );
101}
102
103QWidget *Checkbook::initInfo() 95QWidget *Checkbook::initInfo()
@@ -275,13 +267,12 @@ 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();
@@ -296,53 +287,32 @@ void Checkbook::loadCheckbook()
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
343void Checkbook::adjustBalance( float amount ) 315void 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}
@@ -351,3 +321,3 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con
351{ 321{
352 TranInfo *traninfo = transactions.first(); 322 TranInfo *traninfo = tranList->first();
353 while ( traninfo ) 323 while ( traninfo )
@@ -357,3 +327,3 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con
357 break; 327 break;
358 traninfo = transactions.next(); 328 traninfo = tranList->next();
359 } 329 }
@@ -364,28 +334,10 @@ 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
@@ -396,3 +348,3 @@ void Checkbook::slotPasswordClicked()
396{ 348{
397 if ( password == "" && passwordCB->isChecked() ) 349 if ( info->password().isNull() && passwordCB->isChecked() )
398 { 350 {
@@ -405,3 +357,3 @@ void Checkbook::slotPasswordClicked()
405 } 357 }
406 password = pw->password; 358 info->setPassword( pw->password );
407 delete pw; 359 delete pw;
@@ -409,6 +361,6 @@ void Checkbook::slotPasswordClicked()
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 }
@@ -417,3 +369,3 @@ void Checkbook::slotPasswordClicked()
417 } 369 }
418 else if ( password != "" && !passwordCB->isChecked() ) 370 else if ( !info->password().isNull() && !passwordCB->isChecked() )
419 { 371 {
@@ -421,5 +373,5 @@ void Checkbook::slotPasswordClicked()
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;
@@ -438,10 +390,14 @@ 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}
@@ -450,6 +406,5 @@ 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}
@@ -461,3 +416,3 @@ void Checkbook::slotNewTran()
461 416
462 Transaction *currtran = new Transaction( this, name, 417 Transaction *currtran = new Transaction( this, info->name(),
463 traninfo, 418 traninfo,
@@ -467,3 +422,10 @@ void Checkbook::slotNewTran()
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() )
@@ -472,9 +434,4 @@ void Checkbook::slotNewTran()
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(),
@@ -482,3 +439,3 @@ void Checkbook::slotNewTran()
482 439
483 adjustBalance( amount ); 440 adjustBalance();
484 } 441 }
@@ -499,10 +456,6 @@ void Checkbook::slotEditTran()
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,
@@ -512,4 +465,4 @@ void Checkbook::slotEditTran()
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() );
@@ -521,4 +474,2 @@ void Checkbook::slotEditTran()
521 } 474 }
522 adjustBalance( origamt * -1 );
523 adjustBalance( amount );
524 QString stramount; 475 QString stramount;
@@ -527,6 +478,6 @@ void Checkbook::slotEditTran()
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}
@@ -545,13 +496,5 @@ void Checkbook::slotDeleteTran()
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 }
@@ -584,3 +527,3 @@ void Checkbook::drawBalanceChart()
584 527
585 float balance = startBalance; 528 float balance = info->startingBalance();
586 float amount; 529 float amount;
@@ -588,5 +531,5 @@ void Checkbook::drawBalanceChart()
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 {
@@ -618,3 +561,3 @@ void Checkbook::drawCategoryChart( bool withdrawals )
618 561
619 TranInfo *tran = transactions.first(); 562 TranInfo *tran = tranList->first();
620 if ( tran && tran->withdrawal() == withdrawals ) 563 if ( tran && tran->withdrawal() == withdrawals )
@@ -623,6 +566,6 @@ void Checkbook::drawCategoryChart( bool withdrawals )
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 {
@@ -714,2 +657,2 @@ bool CBListItem::isAltBackground()
714 return false; 657 return false;
715} \ No newline at end of file 658}