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.cpp59
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
@@ -19,54 +19,61 @@
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 "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>
39#include <qfile.h> 41#include <qfile.h>
40#include <qlabel.h> 42#include <qlabel.h>
41#include <qlayout.h> 43#include <qlayout.h>
42#include <qlineedit.h> 44#include <qlineedit.h>
43#include <qlistview.h> 45#include <qlistview.h>
44#include <qmultilineedit.h> 46#include <qmultilineedit.h>
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
49Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) 51Checkbook::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 );
69 layout->setMargin( 2 ); 76 layout->setMargin( 2 );
70 layout->setSpacing( 4 ); 77 layout->setSpacing( 4 );
71 78
72 // Setup tabs for all info 79 // Setup tabs for all info
@@ -233,31 +240,32 @@ QWidget *Checkbook::initCharts()
233 240
234/* 241/*
235 QLabel *label = new QLabel( control ); 242 QLabel *label = new QLabel( control );
236 label->setText( tr( "Graph type:" ) ); 243 label->setText( tr( "Graph type:" ) );
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
258void Checkbook::loadCheckbook() 266void Checkbook::loadCheckbook()
259{ 267{
260 transactions.clear(); 268 transactions.clear();
261 269
262 Config config(filename, Config::File); 270 Config config(filename, Config::File);
263 271
@@ -267,26 +275,26 @@ void Checkbook::loadCheckbook()
267 QString temptext = config.readEntry( "Type" ); 275 QString temptext = config.readEntry( "Type" );
268 int i = typeList->count(); 276 int i = typeList->count();
269 while ( i > 0 ) 277 while ( i > 0 )
270 { 278 {
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
289 TranInfo *tran; 297 TranInfo *tran;
290 QString trandesc = ""; 298 QString trandesc = "";
291 float amount; 299 float amount;
292 QString stramount; 300 QString stramount;
@@ -300,29 +308,25 @@ void Checkbook::loadCheckbook()
300 amount = tran->amount(); 308 amount = tran->amount();
301 if ( tran->withdrawal() ) 309 if ( tran->withdrawal() )
302 { 310 {
303 amount *= -1; 311 amount *= -1;
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 ) );
325 329
326 highTranNum = transactions.count(); 330 highTranNum = transactions.count();
327} 331}
328 332
@@ -348,48 +352,53 @@ void Checkbook::accept()
348 QFile f( filename ); 352 QFile f( filename );
349 if ( f.exists() ) 353 if ( f.exists() )
350 { 354 {
351 f.remove(); 355 f.remove();
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 {
370 tran->write( config, i ); 374 tran->write( config, i );
371 tran = transactions.next(); 375 tran = transactions.next();
372 i++; 376 i++;
373 } 377 }
374 config->write(); 378 config->write();
375 379
376 QDialog::accept(); 380 QDialog::accept();
377} 381}
378 382
379void Checkbook::slotNameChanged( const QString &newname ) 383void 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
386void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 395void 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 );
392} 401}
393 402
394void Checkbook::slotNewTran() 403void Checkbook::slotNewTran()
395{ 404{
@@ -405,31 +414,26 @@ void Checkbook::slotNewTran()
405 float amount = traninfo->amount(); 414 float amount = traninfo->amount();
406 if ( traninfo->withdrawal() ) 415 if ( traninfo->withdrawal() )
407 { 416 {
408 amount *= -1; 417 amount *= -1;
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 }
432} 436}
433 437
434void Checkbook::slotEditTran() 438void Checkbook::slotEditTran()
435{ 439{
@@ -445,29 +449,25 @@ void Checkbook::slotEditTran()
445 float origamt = traninfo->amount(); 449 float origamt = traninfo->amount();
446 if ( traninfo->withdrawal() ) 450 if ( traninfo->withdrawal() )
447 { 451 {
448 origamt *= -1; 452 origamt *= -1;
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 }
470 adjustBalance( origamt * -1 ); 470 adjustBalance( origamt * -1 );
471 adjustBalance( amount ); 471 adjustBalance( amount );
472 QString stramount; 472 QString stramount;
473 stramount.sprintf( "%c%.2f", currencySymbol, amount ); 473 stramount.sprintf( "%c%.2f", currencySymbol, amount );
@@ -480,25 +480,24 @@ void Checkbook::slotEditTran()
480} 480}
481 481
482void Checkbook::slotDeleteTran() 482void Checkbook::slotDeleteTran()
483{ 483{
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;
501 } 500 }
502 501
503 transactions.remove( traninfo ); 502 transactions.remove( traninfo );
504 delete traninfo; 503 delete traninfo;