summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook
Unidiff
Diffstat (limited to 'noncore/apps/checkbook') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp18
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp6
2 files changed, 17 insertions, 7 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 706d970..44d3764 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -313,89 +313,94 @@ void Checkbook::loadCheckbook()
313 int i = typeList->count(); 313 int i = typeList->count();
314 while ( i > 0 ) 314 while ( i > 0 )
315 { 315 {
316 i--; 316 i--;
317 typeList->setCurrentItem( i ); 317 typeList->setCurrentItem( i );
318 if ( typeList->currentText() == temptext ) 318 if ( typeList->currentText() == temptext )
319 { 319 {
320 break; 320 break;
321 } 321 }
322 } 322 }
323 if( i<=0 ) { 323 if( i<=0 ) {
324 typeList->insertItem( temptext, 0 ); 324 typeList->insertItem( temptext, 0 );
325 typeList->setCurrentItem(0); 325 typeList->setCurrentItem(0);
326 } 326 }
327 bankEdit->setText( info->bank() ); 327 bankEdit->setText( info->bank() );
328 acctNumEdit->setText( info->account() ); 328 acctNumEdit->setText( info->account() );
329 pinNumEdit->setText( info->pin() ); 329 pinNumEdit->setText( info->pin() );
330 temptext.setNum( info->startingBalance(), 'f', 2 ); 330 temptext.setNum( info->startingBalance(), 'f', 2 );
331 balanceEdit->setText( temptext ); 331 balanceEdit->setText( temptext );
332 notesEdit->setText( info->notes() ); 332 notesEdit->setText( info->notes() );
333 333
334 // Load transactions 334 // Load transactions
335 float amount; 335 float amount;
336 QString stramount; 336 QString stramount;
337 QString symbol = _pCfg->getCurrencySymbol();
337 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 338 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
338 { 339 {
339 amount = tran->amount(); 340 amount = tran->amount();
340 if ( tran->withdrawal() ) 341 if ( tran->withdrawal() )
341 { 342 {
342 amount *= -1; 343 amount *= -1;
343 } 344 }
344 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 345 stramount.sprintf( "%.2f", amount );
346 stramount.prepend( symbol );
345 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount ); 347 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
346 } 348 }
347 349
348 // set sort order 350 // set sort order
349 bool bOk=false; 351 bool bOk=false;
350 for(int i=0; i<_cbSortType->count(); i++) { 352 for(int i=0; i<_cbSortType->count(); i++) {
351 if( _cbSortType->text(i)==info->getSortOrder() ) { 353 if( _cbSortType->text(i)==info->getSortOrder() ) {
352 _cbSortType->setCurrentItem(i); 354 _cbSortType->setCurrentItem(i);
353 slotSortChanged( info->getSortOrder() ); 355 slotSortChanged( info->getSortOrder() );
354 bOk=true; 356 bOk=true;
355 break; 357 break;
356 } 358 }
357 } 359 }
358 if( !bOk ) { 360 if( !bOk ) {
359 _cbSortType->setCurrentItem(0); 361 _cbSortType->setCurrentItem(0);
360 slotSortChanged( _cbSortType->currentText() ); 362 slotSortChanged( _cbSortType->currentText() );
361 } 363 }
362 364
363 // calc running balance 365 // calc running balance
364 adjustBalance(); 366 adjustBalance();
365} 367}
366 368
367 369
368// --- adjustBalance ---------------------------------------------------------- 370// --- adjustBalance ----------------------------------------------------------
369void Checkbook::adjustBalance() 371void Checkbook::adjustBalance()
370{ 372{
371 // update running balance in register 373 // update running balance in register
372 QString sRunning; 374 QString sRunning;
375 QString symbol = _pCfg->getCurrencySymbol();
373 float bal=info->startingBalance(); 376 float bal=info->startingBalance();
377
374 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { 378 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) {
375 TranInfo *tran=item->getTranInfo(); 379 TranInfo *tran=item->getTranInfo();
376 bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); 380 bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee();
377 sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); 381 sRunning.sprintf( "%.2f", bal );
382 sRunning.prepend(symbol);
378 item->setText( COL_BAL, sRunning); 383 item->setText( COL_BAL, sRunning);
379 } 384 }
380} 385}
381 386
382// --- resort ----------------------------------------------------------------- 387// --- resort -----------------------------------------------------------------
383void Checkbook::resort() 388void Checkbook::resort()
384{ 389{
385 tranTable->setSorting(_sortCol); 390 tranTable->setSorting(_sortCol);
386 tranTable->sort(); 391 tranTable->sort();
387 tranTable->setSorting(-1); 392 tranTable->setSorting(-1);
388} 393}
389 394
390 395
391// --- accept ----------------------------------------------------------------- 396// --- accept -----------------------------------------------------------------
392void Checkbook::accept() 397void Checkbook::accept()
393{ 398{
394 info->setName( nameEdit->text() ); 399 info->setName( nameEdit->text() );
395 info->setType( typeList->currentText() ); 400 info->setType( typeList->currentText() );
396 info->setBank( bankEdit->text() ); 401 info->setBank( bankEdit->text() );
397 info->setAccount( acctNumEdit->text() ); 402 info->setAccount( acctNumEdit->text() );
398 info->setPin( pinNumEdit->text() ); 403 info->setPin( pinNumEdit->text() );
399 bool ok; 404 bool ok;
400 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); 405 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
401 info->setNotes( notesEdit->text() ); 406 info->setNotes( notesEdit->text() );
@@ -461,58 +466,60 @@ void Checkbook::slotNameChanged( const QString &newname )
461 namestr.append( tr( "Checkbook" ) ); 466 namestr.append( tr( "Checkbook" ) );
462 setCaption( namestr ); 467 setCaption( namestr );
463} 468}
464 469
465 470
466// ---slotStartingBalanceChanged ---------------------------------------------- 471// ---slotStartingBalanceChanged ----------------------------------------------
467void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 472void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
468{ 473{
469 bool ok; 474 bool ok;
470 info->setStartingBalance( newbalance.toFloat( &ok ) ); 475 info->setStartingBalance( newbalance.toFloat( &ok ) );
471 adjustBalance(); 476 adjustBalance();
472} 477}
473 478
474 479
475// --- slotNewTran ------------------------------------------------------------ 480// --- slotNewTran ------------------------------------------------------------
476void Checkbook::slotNewTran() 481void Checkbook::slotNewTran()
477{ 482{
478 TranInfo *traninfo = new TranInfo( info->getNextNumber() ); 483 TranInfo *traninfo = new TranInfo( info->getNextNumber() );
479 if( !_dLastNew.isNull() ) 484 if( !_dLastNew.isNull() )
480 traninfo->setDate(_dLastNew); 485 traninfo->setDate(_dLastNew);
481 486
482 Transaction *currtran = new Transaction( this, true, info->name(), 487 Transaction *currtran = new Transaction( this, true, info->name(),
483 traninfo, 488 traninfo,
484 _pCfg ); 489 _pCfg );
490 QString symbol = _pCfg->getCurrencySymbol();
485 if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) 491 if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted )
486 { 492 {
487 // Add to transaction list 493 // Add to transaction list
488 info->addTransaction( traninfo ); 494 info->addTransaction( traninfo );
489 495
490 // Add to transaction table 496 // Add to transaction table
491 float amount; 497 float amount;
492 QString stramount; 498 QString stramount;
493 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); 499 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
494 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 500 stramount.sprintf( "%.2f", amount );
501 stramount.prepend(symbol);
495 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false), 502 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
496 traninfo->number(), traninfo->datestr(true), traninfo->desc(), 503 traninfo->number(), traninfo->datestr(true), traninfo->desc(),
497 stramount ); 504 stramount );
498 resort(); 505 resort();
499 adjustBalance(); 506 adjustBalance();
500 507
501 // save last date 508 // save last date
502 _dLastNew = traninfo->date(); 509 _dLastNew = traninfo->date();
503 510
504 // save description in list of payees, if not in there 511 // save description in list of payees, if not in there
505 QStringList *pLst=&_pCfg->getPayees(); 512 QStringList *pLst=&_pCfg->getPayees();
506 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { 513 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
507 pLst->append( traninfo->desc() ); 514 pLst->append( traninfo->desc() );
508 pLst->sort(); 515 pLst->sort();
509 _pCfg->setDirty(true); 516 _pCfg->setDirty(true);
510 } 517 }
511 } 518 }
512 else 519 else
513 { 520 {
514 delete traninfo; 521 delete traninfo;
515 } 522 }
516} 523}
517 524
518 525
@@ -520,49 +527,50 @@ void Checkbook::slotNewTran()
520void Checkbook::slotEditTran() 527void Checkbook::slotEditTran()
521{ 528{
522 QListViewItem *curritem = tranTable->currentItem(); 529 QListViewItem *curritem = tranTable->currentItem();
523 if ( !curritem ) 530 if ( !curritem )
524 return; 531 return;
525 532
526 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); 533 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
527 534
528 Transaction *currtran = new Transaction( this, false, info->name(), 535 Transaction *currtran = new Transaction( this, false, info->name(),
529 traninfo, 536 traninfo,
530 _pCfg ); 537 _pCfg );
531 if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) 538 if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted )
532 { 539 {
533 curritem->setText( COL_NUM, traninfo->number() ); 540 curritem->setText( COL_NUM, traninfo->number() );
534 curritem->setText( COL_SORTDATE, traninfo->datestr(false) ); 541 curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
535 curritem->setText( COL_DATE, traninfo->datestr(true) ); 542 curritem->setText( COL_DATE, traninfo->datestr(true) );
536 curritem->setText( COL_DESC, traninfo->desc() ); 543 curritem->setText( COL_DESC, traninfo->desc() );
537 544
538 float amount = traninfo->amount(); 545 float amount = traninfo->amount();
539 if ( traninfo->withdrawal() ) 546 if ( traninfo->withdrawal() )
540 { 547 {
541 amount *= -1; 548 amount *= -1;
542 } 549 }
543 QString stramount; 550 QString stramount;
544 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 551 stramount.sprintf( "%.2f", amount );
552 stramount.prepend( _pCfg->getCurrencySymbol() );
545 curritem->setText( COL_AMOUNT, stramount ); 553 curritem->setText( COL_AMOUNT, stramount );
546 resort(); 554 resort();
547 adjustBalance(); 555 adjustBalance();
548 556
549 // save description in list of payees, if not in there 557 // save description in list of payees, if not in there
550 QStringList *pLst=&_pCfg->getPayees(); 558 QStringList *pLst=&_pCfg->getPayees();
551 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { 559 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
552 pLst->append( traninfo->desc() ); 560 pLst->append( traninfo->desc() );
553 pLst->sort(); 561 pLst->sort();
554 _pCfg->setDirty(true); 562 _pCfg->setDirty(true);
555 } 563 }
556 } 564 }
557 565
558 delete currtran; 566 delete currtran;
559} 567}
560 568
561// --- slotMenuTran ----------------------------------------------------------- 569// --- slotMenuTran -----------------------------------------------------------
562void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt) 570void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
563{ 571{
564 // active item? 572 // active item?
565 if( !item ) 573 if( !item )
566 return; 574 return;
567 575
568 // Display menu 576 // Display menu
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index ce15e3e..c7ffa7c 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -172,49 +172,50 @@ void MainWindow::buildList()
172 cbList->setAllColumnsShowFocus( TRUE ); 172 cbList->setAllColumnsShowFocus( TRUE );
173 cbList->setSorting( posName ); 173 cbList->setSorting( posName );
174 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); 174 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
175 connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), 175 connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ),
176 this, SLOT( slotEdit() ) ); 176 this, SLOT( slotEdit() ) );
177 setCentralWidget( cbList ); 177 setCentralWidget( cbList );
178 178
179 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) 179 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
180 { 180 {
181 addCheckbook( cb ); 181 addCheckbook( cb );
182 } 182 }
183} 183}
184 184
185void MainWindow::addCheckbook( CBInfo *cb ) 185void MainWindow::addCheckbook( CBInfo *cb )
186{ 186{
187 QListViewItem *lvi = new QListViewItem( cbList ); 187 QListViewItem *lvi = new QListViewItem( cbList );
188 if ( _cfg.getShowLocks() && !cb->password().isNull() ) 188 if ( _cfg.getShowLocks() && !cb->password().isNull() )
189 { 189 {
190 lvi->setPixmap( 0, lockIcon ); 190 lvi->setPixmap( 0, lockIcon );
191 } 191 }
192 lvi->setText( posName, cb->name() ); 192 lvi->setText( posName, cb->name() );
193 if ( _cfg.getShowBalances() ) 193 if ( _cfg.getShowBalances() )
194 { 194 {
195 QString balance; 195 QString balance;
196 balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); 196 balance.sprintf( "%.2f", cb->balance() );
197 balance.prepend( _cfg.getCurrencySymbol() );
197 lvi->setText( posName + 1, balance ); 198 lvi->setText( posName + 1, balance );
198 } 199 }
199} 200}
200 201
201void MainWindow::buildFilename( const QString &name ) 202void MainWindow::buildFilename( const QString &name )
202{ 203{
203 tempFilename = cbDir; 204 tempFilename = cbDir;
204 tempFilename.append( name ); 205 tempFilename.append( name );
205 tempFilename.append( ".qcb" ); 206 tempFilename.append( ".qcb" );
206} 207}
207 208
208void MainWindow::slotNew() 209void MainWindow::slotNew()
209{ 210{
210 CBInfo *cb = new CBInfo(); 211 CBInfo *cb = new CBInfo();
211 212
212 Checkbook *currcb = new Checkbook( this, cb, &_cfg ); 213 Checkbook *currcb = new Checkbook( this, cb, &_cfg );
213 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) 214 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
214 { 215 {
215 // Save new checkbook 216 // Save new checkbook
216 buildFilename( cb->name() ); 217 buildFilename( cb->name() );
217 _cfg.setLastBook( cb->name() ); 218 _cfg.setLastBook( cb->name() );
218 cb->setFilename( tempFilename ); 219 cb->setFilename( tempFilename );
219 cb->write(); 220 cb->write();
220 221
@@ -283,49 +284,50 @@ void MainWindow::openBook(QListViewItem *curritem)
283 QFile f( tempFilename ); 284 QFile f( tempFilename );
284 if ( f.exists() ) 285 if ( f.exists() )
285 f.remove(); 286 f.remove();
286 287
287 // Get new filename 288 // Get new filename
288 buildFilename( newname ); 289 buildFilename( newname );
289 cb->setFilename( tempFilename ); 290 cb->setFilename( tempFilename );
290 } 291 }
291 292
292 cb->write(); 293 cb->write();
293 294
294 // Update lock if changed 295 // Update lock if changed
295 if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) 296 if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
296 { 297 {
297 if ( !cb->password().isNull() ) 298 if ( !cb->password().isNull() )
298 curritem->setPixmap( 0, lockIcon ); 299 curritem->setPixmap( 0, lockIcon );
299 else 300 else
300 curritem->setPixmap( 0, nullIcon ); 301 curritem->setPixmap( 0, nullIcon );
301 } 302 }
302 303
303 // Update balance if changed 304 // Update balance if changed
304 if ( _cfg.getShowBalances() && cb->balance() != currbalance ) 305 if ( _cfg.getShowBalances() && cb->balance() != currbalance )
305 { 306 {
306 QString tempstr; 307 QString tempstr;
307 tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); 308 tempstr.sprintf( "%.2f", cb->balance() );
309 tempstr.prepend( _cfg.getCurrencySymbol() );
308 curritem->setText( posName + 1, tempstr ); 310 curritem->setText( posName + 1, tempstr );
309 } 311 }
310 312
311 // write config, if needed 313 // write config, if needed
312 if( _cfg.isDirty() ) { 314 if( _cfg.isDirty() ) {
313 Config config("checkbook"); 315 Config config("checkbook");
314 _cfg.writeConfig( config ); 316 _cfg.writeConfig( config );
315 } 317 }
316 } 318 }
317 delete currcb; 319 delete currcb;
318} 320}
319 321
320// --- slotDelete ------------------------------------------------------------- 322// --- slotDelete -------------------------------------------------------------
321void MainWindow::slotDelete() 323void MainWindow::slotDelete()
322{ 324{
323 QString currname = cbList->currentItem()->text( posName ); 325 QString currname = cbList->currentItem()->text( posName );
324 326
325 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) 327 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
326 { 328 {
327 buildFilename( currname ); 329 buildFilename( currname );
328 QFile f( tempFilename ); 330 QFile f( tempFilename );
329 if ( f.exists() ) 331 if ( f.exists() )
330 { 332 {
331 f.remove(); 333 f.remove();