summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cfg.cpp15
-rw-r--r--noncore/apps/checkbook/cfg.h16
-rw-r--r--noncore/apps/checkbook/checkbook.cpp91
-rw-r--r--noncore/apps/checkbook/checkbook.h8
-rw-r--r--noncore/apps/checkbook/configuration.cpp16
-rw-r--r--noncore/apps/checkbook/configuration.h2
-rw-r--r--noncore/apps/checkbook/listedit.cpp4
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp7
-rw-r--r--noncore/apps/checkbook/traninfo.cpp25
-rw-r--r--noncore/apps/checkbook/traninfo.h5
-rw-r--r--noncore/apps/checkbook/transaction.cpp92
-rw-r--r--noncore/apps/checkbook/transaction.h12
12 files changed, 249 insertions, 44 deletions
diff --git a/noncore/apps/checkbook/cfg.cpp b/noncore/apps/checkbook/cfg.cpp
index 1e0ec5c..0d5d9ed 100644
--- a/noncore/apps/checkbook/cfg.cpp
+++ b/noncore/apps/checkbook/cfg.cpp
@@ -43,6 +43,7 @@ Cfg::Cfg()
43 _showLocks=FALSE; 43 _showLocks=FALSE;
44 _showBalances=FALSE; 44 _showBalances=FALSE;
45 _pCategories=new CategoryList(); 45 _pCategories=new CategoryList();
46 _bDirty=false;
46} 47}
47 48
48// --- readStringList --------------------------------------------------------- 49// --- readStringList ---------------------------------------------------------
@@ -52,8 +53,6 @@ Cfg::Cfg()
52// entries. 53// entries.
53void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) 54void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
54{ 55{
55qDebug( "%s", sKey );
56
57 QString sEntry; 56 QString sEntry;
58 int iCount; 57 int iCount;
59 58
@@ -86,6 +85,7 @@ void Cfg::readConfig(Config &config)
86 _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE ); 85 _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE );
87 _sLastBook = config.readEntry("LastBook", ""); 86 _sLastBook = config.readEntry("LastBook", "");
88 _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE ); 87 _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE );
88 _bSavePayees = config.readBoolEntry( "SavePayees", FALSE );
89 89
90 // Account types 90 // Account types
91 readStringList(config, "AccType", _AccountTypes); 91 readStringList(config, "AccType", _AccountTypes);
@@ -100,6 +100,9 @@ void Cfg::readConfig(Config &config)
100 config.write(); 100 config.write();
101 } 101 }
102 102
103 // Payees
104 readStringList(config, "Payee", _Payees);
105
103 // Read Categories 106 // Read Categories
104 QStringList lst; 107 QStringList lst;
105 readStringList(config, "Category", lst); 108 readStringList(config, "Category", lst);
@@ -131,6 +134,9 @@ void Cfg::readConfig(Config &config)
131 } else { 134 } else {
132 setCategories(lst); 135 setCategories(lst);
133 } 136 }
137
138 // not dirty
139 _bDirty=false;
134} 140}
135 141
136 142
@@ -166,16 +172,21 @@ void Cfg::writeConfig(Config &config)
166 config.writeEntry( "OpenLastBook", _openLastBook ); 172 config.writeEntry( "OpenLastBook", _openLastBook );
167 config.writeEntry( "LastBook", _sLastBook ); 173 config.writeEntry( "LastBook", _sLastBook );
168 config.writeEntry( "ShowLastTab", _showLastTab ); 174 config.writeEntry( "ShowLastTab", _showLastTab );
175 config.writeEntry( "SavePayees", _bSavePayees );
169 176
170 // write account types 177 // write account types
171 writeStringList(config, "AccType", _AccountTypes); 178 writeStringList(config, "AccType", _AccountTypes);
172 179
180 // write payees
181 writeStringList(config, "Payee", _Payees);
182
173 // write categories 183 // write categories
174 QStringList lst=getCategories(); 184 QStringList lst=getCategories();
175 writeStringList(config, "Category", lst ); 185 writeStringList(config, "Category", lst );
176 186
177 // commit write 187 // commit write
178 config.write(); 188 config.write();
189 _bDirty=false;
179} 190}
180 191
181 192
diff --git a/noncore/apps/checkbook/cfg.h b/noncore/apps/checkbook/cfg.h
index 2b69368..20692b4 100644
--- a/noncore/apps/checkbook/cfg.h
+++ b/noncore/apps/checkbook/cfg.h
@@ -77,6 +77,11 @@ class Cfg
77 void setCurrencySymbol(const char *n) { _currencySymbol=n; } 77 void setCurrencySymbol(const char *n) { _currencySymbol=n; }
78 QStringList &getAccountTypes() { return(_AccountTypes); } 78 QStringList &getAccountTypes() { return(_AccountTypes); }
79 79
80 // --- Payees
81 QStringList &getPayees() { return(_Payees); }
82 bool getSavePayees() { return(_bSavePayees); }
83 void setSavePayees(bool bSave) { _bSavePayees=bSave; }
84
80 // --- Categories 85 // --- Categories
81 QStringList getCategories(); 86 QStringList getCategories();
82 void setCategories(QStringList &lst); 87 void setCategories(QStringList &lst);
@@ -98,23 +103,30 @@ class Cfg
98 // --- writes data to config file 103 // --- writes data to config file
99 void writeConfig(Config &cfg); 104 void writeConfig(Config &cfg);
100 105
106 // --- dirty flag
107 bool isDirty() { return(_bDirty); }
108 void setDirty(bool bDirty) { _bDirty=bDirty; }
109
110 protected:
101 // --- reads list from config file 111 // --- reads list from config file
102 static void readStringList(Config &cfg, const char *sKey, QStringList &lst); 112 static void readStringList(Config &cfg, const char *sKey, QStringList &lst);
103 113
104 // --- writes list in configuration file 114 // --- writes list in configuration file
105 static void writeStringList(Config &cfg, const char *sKey, QStringList &lst); 115 static void writeStringList(Config &cfg, const char *sKey, QStringList &lst);
106 116
107
108
109 private: 117 private:
110 QString _currencySymbol; 118 QString _currencySymbol;
111 bool _showLocks; 119 bool _showLocks;
112 bool _showBalances; 120 bool _showBalances;
113 bool _openLastBook; 121 bool _openLastBook;
114 bool _showLastTab; 122 bool _showLastTab;
123 bool _bDirty;
124 bool _bSavePayees;
115 QString _sLastBook; 125 QString _sLastBook;
116 QStringList _AccountTypes; 126 QStringList _AccountTypes;
117 CategoryList *_pCategories; 127 CategoryList *_pCategories;
128 QStringList _Payees;
129
118}; 130};
119 131
120#endif 132#endif
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index c53e889..a42c824 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -49,13 +49,15 @@
49#include <qmultilineedit.h> 49#include <qmultilineedit.h>
50#include <qpushbutton.h> 50#include <qpushbutton.h>
51#include <qwhatsthis.h> 51#include <qwhatsthis.h>
52#include <qpopupmenu.h>
52 53
53#define COL_ID 0 54#define COL_ID 0
54#define COL_NUM 1 55#define COL_SORTDATE 1
55#define COL_DATE 2 56#define COL_NUM 2
56#define COL_DESC 3 57#define COL_DATE 3
57#define COL_AMOUNT 4 58#define COL_DESC 4
58#define COL_BAL 5 59#define COL_AMOUNT 5
60#define COL_BAL 6
59 61
60// --- Checkbook -------------------------------------------------------------- 62// --- Checkbook --------------------------------------------------------------
61Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) 63Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
@@ -224,6 +226,9 @@ QWidget *Checkbook::initTransactions()
224 tranTable->addColumn( tr( "Id" ) ); 226 tranTable->addColumn( tr( "Id" ) );
225 tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); 227 tranTable->setColumnWidthMode( COL_ID, QListView::Manual );
226 tranTable->setColumnWidth( COL_ID, 0); 228 tranTable->setColumnWidth( COL_ID, 0);
229 tranTable->addColumn( tr( "SortDate" ) );
230 tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
231 tranTable->setColumnWidth( COL_SORTDATE, 0);
227 tranTable->addColumn( tr( "Num" ) ); 232 tranTable->addColumn( tr( "Num" ) );
228 tranTable->addColumn( tr( "Date" ) ); 233 tranTable->addColumn( tr( "Date" ) );
229 //tranTable->addColumn( tr( "Cleared" ) ); 234 //tranTable->addColumn( tr( "Cleared" ) );
@@ -237,7 +242,9 @@ QWidget *Checkbook::initTransactions()
237 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); 242 layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
238 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); 243 QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
239 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), 244 connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
240 this, SLOT( slotEditTran() ) ); 245 this, SLOT( slotMenuTran(QListViewItem *, const QPoint &) ) );
246 connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
247 this, SLOT( slotEditTran() ) );
241 _sortCol=COL_ID; 248 _sortCol=COL_ID;
242 249
243 // Buttons 250 // Buttons
@@ -336,7 +343,7 @@ void Checkbook::loadCheckbook()
336 amount *= -1; 343 amount *= -1;
337 } 344 }
338 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 345 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
339 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount ); 346 ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
340 } 347 }
341 348
342 // set sort order 349 // set sort order
@@ -358,6 +365,7 @@ void Checkbook::loadCheckbook()
358 adjustBalance(); 365 adjustBalance();
359} 366}
360 367
368
361// --- adjustBalance ---------------------------------------------------------- 369// --- adjustBalance ----------------------------------------------------------
362void Checkbook::adjustBalance() 370void Checkbook::adjustBalance()
363{ 371{
@@ -396,6 +404,7 @@ void Checkbook::accept()
396 QDialog::accept(); 404 QDialog::accept();
397} 405}
398 406
407// --- slotPasswordClicked ----------------------------------------------------
399void Checkbook::slotPasswordClicked() 408void Checkbook::slotPasswordClicked()
400{ 409{
401 if ( info->password().isNull() && passwordCB->isChecked() ) 410 if ( info->password().isNull() && passwordCB->isChecked() )
@@ -464,13 +473,14 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
464} 473}
465 474
466 475
476// --- slotNewTran ------------------------------------------------------------
467void Checkbook::slotNewTran() 477void Checkbook::slotNewTran()
468{ 478{
469 TranInfo *traninfo = new TranInfo( info->getNextNumber() ); 479 TranInfo *traninfo = new TranInfo( info->getNextNumber() );
470 if( !_dLastNew.isNull() ) 480 if( !_dLastNew.isNull() )
471 traninfo->setDate(_dLastNew); 481 traninfo->setDate(_dLastNew);
472 482
473 Transaction *currtran = new Transaction( this, info->name(), 483 Transaction *currtran = new Transaction( this, true, info->name(),
474 traninfo, 484 traninfo,
475 _pCfg ); 485 _pCfg );
476 currtran->showMaximized(); 486 currtran->showMaximized();
@@ -484,14 +494,22 @@ void Checkbook::slotNewTran()
484 QString stramount; 494 QString stramount;
485 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); 495 amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
486 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 496 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
487 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), 497 ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
488 traninfo->number(), traninfo->datestr(), traninfo->desc(), 498 traninfo->number(), traninfo->datestr(true), traninfo->desc(),
489 stramount ); 499 stramount );
490 resort(); 500 resort();
491 adjustBalance(); 501 adjustBalance();
492 502
493 // save last date 503 // save last date
494 _dLastNew = traninfo->date(); 504 _dLastNew = traninfo->date();
505
506 // save description in list of payees, if not in there
507 QStringList *pLst=&_pCfg->getPayees();
508 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
509 pLst->append( traninfo->desc() );
510 pLst->sort();
511 _pCfg->setDirty(true);
512 }
495 } 513 }
496 else 514 else
497 { 515 {
@@ -499,22 +517,25 @@ void Checkbook::slotNewTran()
499 } 517 }
500} 518}
501 519
520
521// --- slotEditTran -----------------------------------------------------------
502void Checkbook::slotEditTran() 522void Checkbook::slotEditTran()
503{ 523{
504 QListViewItem *curritem = tranTable->currentItem(); 524 QListViewItem *curritem = tranTable->currentItem();
505 if ( !curritem ) 525 if ( !curritem )
506 return; 526 return;
507 527
508 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); 528 TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
509 529
510 Transaction *currtran = new Transaction( this, info->name(), 530 Transaction *currtran = new Transaction( this, false, info->name(),
511 traninfo, 531 traninfo,
512 _pCfg ); 532 _pCfg );
513 currtran->showMaximized(); 533 currtran->showMaximized();
514 if ( currtran->exec() == QDialog::Accepted ) 534 if ( currtran->exec() == QDialog::Accepted )
515 { 535 {
516 curritem->setText( COL_NUM, traninfo->number() ); 536 curritem->setText( COL_NUM, traninfo->number() );
517 curritem->setText( COL_DATE, traninfo->datestr() ); 537 curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
538 curritem->setText( COL_DATE, traninfo->datestr(true) );
518 curritem->setText( COL_DESC, traninfo->desc() ); 539 curritem->setText( COL_DESC, traninfo->desc() );
519 540
520 float amount = traninfo->amount(); 541 float amount = traninfo->amount();
@@ -527,11 +548,47 @@ void Checkbook::slotEditTran()
527 curritem->setText( COL_AMOUNT, stramount ); 548 curritem->setText( COL_AMOUNT, stramount );
528 resort(); 549 resort();
529 adjustBalance(); 550 adjustBalance();
551
552 // save description in list of payees, if not in there
553 QStringList *pLst=&_pCfg->getPayees();
554 if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
555 pLst->append( traninfo->desc() );
556 pLst->sort();
557 _pCfg->setDirty(true);
558 }
530 } 559 }
531 560
532 delete currtran; 561 delete currtran;
533} 562}
534 563
564// --- slotMenuTran -----------------------------------------------------------
565void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
566{
567 // active item?
568 if( !item )
569 return;
570
571 // Display menu
572 QPopupMenu m;
573 m.insertItem( QWidget::tr( "Edit" ), 1 );
574 m.insertItem( QWidget::tr( "New" ), 2 );
575 m.insertItem( QWidget::tr( "Delete" ), 3 );
576 int r = m.exec( pnt );
577 switch(r) {
578 case 1:
579 slotEditTran();
580 break;
581 case 2:
582 slotNewTran();
583 break;
584 case 3:
585 slotDeleteTran();
586 break;
587 }
588}
589
590
591// --- slotDeleteTran ---------------------------------------------------------
535void Checkbook::slotDeleteTran() 592void Checkbook::slotDeleteTran()
536{ 593{
537 QListViewItem *curritem = tranTable->currentItem(); 594 QListViewItem *curritem = tranTable->currentItem();
@@ -591,7 +648,7 @@ void Checkbook::drawBalanceChart()
591 balance += amount; 648 balance += amount;
592 if ( i == 1 || i == count / 2 || i == count ) 649 if ( i == 1 || i == count / 2 || i == count )
593 { 650 {
594 label = tran->datestr(); 651 label = tran->datestr(true);
595 } 652 }
596 else 653 else
597 { 654 {
@@ -666,6 +723,7 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int
666 QListViewItem::paintCell(p, _cg, column, width, align); 723 QListViewItem::paintCell(p, _cg, column, width, align);
667} 724}
668 725
726// --- CBListItem::isAltBackground --------------------------------------------
669bool CBListItem::isAltBackground() 727bool CBListItem::isAltBackground()
670{ 728{
671 QListView *lv = static_cast<QListView *>( listView() ); 729 QListView *lv = static_cast<QListView *>( listView() );
@@ -723,8 +781,9 @@ void Checkbook::slotSortChanged( const QString &selc )
723 } else if( selc==tr("Number") ) { 781 } else if( selc==tr("Number") ) {
724 _sortCol=COL_NUM; 782 _sortCol=COL_NUM;
725 } else if( selc==tr("Date") ) { 783 } else if( selc==tr("Date") ) {
726 _sortCol=COL_DATE; 784 _sortCol=COL_SORTDATE;
727 } 785 }
728 info->setSortOrder( selc ); 786 info->setSortOrder( selc );
729 resort(); 787 resort();
730} 788}
789
diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h
index 1b6a2d3..e18f00c 100644
--- a/noncore/apps/checkbook/checkbook.h
+++ b/noncore/apps/checkbook/checkbook.h
@@ -48,6 +48,7 @@ class QString;
48class TranInfo; 48class TranInfo;
49class TranInfoList; 49class TranInfoList;
50class Cfg; 50class Cfg;
51class QMouseEvent;
51 52
52 53
53// --- Checkbook -------------------------------------------------------------- 54// --- Checkbook --------------------------------------------------------------
@@ -62,6 +63,9 @@ class Checkbook : public QDialog
62 // resort 63 // resort
63 void resort(); 64 void resort();
64 65
66 // members
67 TranInfoList *getTranList() { return(tranList); }
68
65 private: 69 private:
66 CBInfo *info; 70 CBInfo *info;
67 TranInfoList *tranList; 71 TranInfoList *tranList;
@@ -109,11 +113,13 @@ class Checkbook : public QDialog
109 void slotStartingBalanceChanged( const QString & ); 113 void slotStartingBalanceChanged( const QString & );
110 void slotNewTran(); 114 void slotNewTran();
111 void slotEditTran(); 115 void slotEditTran();
116 void slotMenuTran(QListViewItem *, const QPoint &);
112 void slotDeleteTran(); 117 void slotDeleteTran();
113 void slotDrawGraph(); 118 void slotDrawGraph();
114 void slotSortChanged( const QString & ); 119 void slotSortChanged( const QString & );
115}; 120};
116 121
122
117// --- CBListItem ------------------------------------------------------------- 123// --- CBListItem -------------------------------------------------------------
118class CBListItem : public QListViewItem 124class CBListItem : public QListViewItem
119{ 125{
@@ -129,7 +135,7 @@ class CBListItem : public QListViewItem
129 // --- members 135 // --- members
130 TranInfo *getTranInfo() { return(_pTran); } 136 TranInfo *getTranInfo() { return(_pTran); }
131 137
132 private: 138 private:
133 TranInfo *_pTran; 139 TranInfo *_pTran;
134 QListView *owner; 140 QListView *owner;
135 bool m_known; 141 bool m_known;
diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp
index 3f5662d..dfae446 100644
--- a/noncore/apps/checkbook/configuration.cpp
+++ b/noncore/apps/checkbook/configuration.cpp
@@ -76,6 +76,12 @@ Configuration::Configuration( QWidget *parent, Cfg &cfg )
76 QStringList lst=cfg.getCategories(); 76 QStringList lst=cfg.getCategories();
77 _listEditCategories->addData( lst ); 77 _listEditCategories->addData( lst );
78 _mainWidget->addTab( _listEditCategories, tr( "&Categories" ) ); 78 _mainWidget->addTab( _listEditCategories, tr( "&Categories" ) );
79
80 // Payees tab
81 _listEditPayees=new ListEdit(_mainWidget, "PAYEES");
82 _listEditPayees->addColumnDef( new ColumnDef( tr("Payee"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Payee")) );
83 _listEditPayees->addData( cfg.getPayees() );
84 _mainWidget->addTab( _listEditPayees, tr("&Payees") );
79} 85}
80 86
81Configuration::~Configuration() 87Configuration::~Configuration()
@@ -138,6 +144,12 @@ QWidget *Configuration::initSettings(Cfg &cfg)
138 lastTabCB->setChecked( cfg.isShowLastTab() ); 144 lastTabCB->setChecked( cfg.isShowLastTab() );
139 layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 ); 145 layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 );
140 146
147 savePayees = new QCheckBox( tr("Save new description as payee"), container );
148 QWhatsThis::add( savePayees, tr("Click here to save new descriptions in the list of payess.") );
149 savePayees->setMaximumHeight(fh+5);
150 savePayees->setChecked( cfg.getSavePayees() );
151 layout->addMultiCellWidget( savePayees, 5, 5, 0, 1 );
152
141 return(control); 153 return(control);
142} 154}
143 155
@@ -150,6 +162,7 @@ void Configuration::saveConfig(Cfg &cfg)
150 cfg.setShowBalances( balCB->isChecked() ); 162 cfg.setShowBalances( balCB->isChecked() );
151 cfg.setOpenLastBook( openLastBookCB->isChecked() ); 163 cfg.setOpenLastBook( openLastBookCB->isChecked() );
152 cfg.setShowLastTab( lastTabCB->isChecked() ); 164 cfg.setShowLastTab( lastTabCB->isChecked() );
165 cfg.setSavePayees( savePayees->isChecked() );
153 166
154 // Typelist 167 // Typelist
155 _listEditTypes->storeInList( cfg.getAccountTypes() ); 168 _listEditTypes->storeInList( cfg.getAccountTypes() );
@@ -158,4 +171,7 @@ void Configuration::saveConfig(Cfg &cfg)
158 QStringList lst; 171 QStringList lst;
159 _listEditCategories->storeInList( lst ); 172 _listEditCategories->storeInList( lst );
160 cfg.setCategories( lst ); 173 cfg.setCategories( lst );
174
175 // Payees
176 _listEditPayees->storeInList( cfg.getPayees() );
161} 177}
diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h
index 5893502..663514d 100644
--- a/noncore/apps/checkbook/configuration.h
+++ b/noncore/apps/checkbook/configuration.h
@@ -52,9 +52,11 @@ class Configuration : public QDialog
52 QCheckBox *balCB; 52 QCheckBox *balCB;
53 QCheckBox *openLastBookCB; 53 QCheckBox *openLastBookCB;
54 QCheckBox *lastTabCB; 54 QCheckBox *lastTabCB;
55 QCheckBox *savePayees;
55 QTabWidget *_mainWidget; 56 QTabWidget *_mainWidget;
56 ListEdit *_listEditTypes; 57 ListEdit *_listEditTypes;
57 ListEdit *_listEditCategories; 58 ListEdit *_listEditCategories;
59 ListEdit *_listEditPayees;
58 60
59 // saves settings in config struct 61 // saves settings in config struct
60 void saveConfig(Cfg &cfg); 62 void saveConfig(Cfg &cfg);
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp
index 99a6531..37f05f0 100644
--- a/noncore/apps/checkbook/listedit.cpp
+++ b/noncore/apps/checkbook/listedit.cpp
@@ -116,6 +116,10 @@ void ListEdit::slotAdd()
116 QPoint pnt; 116 QPoint pnt;
117 slotClick(_currentItem, pnt, 0); 117 slotClick(_currentItem, pnt, 0);
118 _typeTable->setSelected( _currentItem, true ); 118 _typeTable->setSelected( _currentItem, true );
119
120 // make it selected
121 _typeEdit->setCursorPosition(0);
122 _typeEdit->setSelection(0, _typeEdit->text().length() );
119} 123}
120 124
121// --- slotDel ------------------------------------------------------------- 125// --- slotDel -------------------------------------------------------------
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index 8d64cad..bf00102 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -58,7 +58,6 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
58 58
59 // Load configuration options 59 // Load configuration options
60 Config config( "checkbook" ); 60 Config config( "checkbook" );
61qDebug( "Reading config" );
62 _cfg.readConfig( config ); 61 _cfg.readConfig( config );
63 62
64 63
@@ -314,6 +313,12 @@ void MainWindow::openBook(QListViewItem *curritem)
314 tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); 313 tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
315 curritem->setText( posName + 1, tempstr ); 314 curritem->setText( posName + 1, tempstr );
316 } 315 }
316
317 // write config, if needed
318 if( _cfg.isDirty() ) {
319 Config config("checkbook");
320 _cfg.writeConfig( config );
321 }
317 } 322 }
318 delete currcb; 323 delete currcb;
319} 324}
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp
index d880bb4..506f567 100644
--- a/noncore/apps/checkbook/traninfo.cpp
+++ b/noncore/apps/checkbook/traninfo.cpp
@@ -29,6 +29,7 @@
29#include "traninfo.h" 29#include "traninfo.h"
30 30
31#include <qpe/config.h> 31#include <qpe/config.h>
32#include <qpe/timestring.h>
32 33
33QString tempstr; 34QString tempstr;
34 35
@@ -124,14 +125,17 @@ TranInfo::TranInfo( Config config, int entry )
124} 125}
125 126
126// --- datestr ---------------------------------------------------------------- 127// --- datestr ----------------------------------------------------------------
127const QString &TranInfo::datestr() 128const QString &TranInfo::datestr(bool bDisplayDate)
128{ 129{
129 int y=td.year(); 130 if( bDisplayDate ) {
130 y= y>=2000 && y<=2099 ? y-2000 : y; 131 tempstr=TimeString::numberDateString( td );
131 tempstr.sprintf( "%02d/%02d/%02d", y ,td.month(), td.day() ); 132 } else {
132 return( tempstr ); 133 tempstr.sprintf( "%04d-%02d-%02d", td.year() ,td.month(), td.day() );
134 }
135 return(tempstr);
133} 136}
134 137
138
135// --- getIdStr --------------------------------------------------------------- 139// --- getIdStr ---------------------------------------------------------------
136const QString &TranInfo::getIdStr() 140const QString &TranInfo::getIdStr()
137{ 141{
@@ -210,3 +214,14 @@ QString TranInfo::toString()
210 ); 214 );
211 return(ret); 215 return(ret);
212} 216}
217
218
219// --- findMostRecentByDesc ---------------------------------------------------
220TranInfo *TranInfoList::findMostRecentByDesc( const QString &desc )
221{
222 for(TranInfo *cur=last(); cur; cur=prev()) {
223 if( cur->desc()==desc )
224 return( cur );
225 }
226 return(NULL);
227} \ No newline at end of file
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h
index 0abdc61..cbe0238 100644
--- a/noncore/apps/checkbook/traninfo.h
+++ b/noncore/apps/checkbook/traninfo.h
@@ -49,7 +49,7 @@ class TranInfo
49 49
50 const QString &desc() const { return d; } 50 const QString &desc() const { return d; }
51 const QDate &date() const { return td; } 51 const QDate &date() const { return td; }
52 const QString &datestr(); 52 const QString &datestr(bool = false);
53 bool withdrawal()const { return w; } 53 bool withdrawal()const { return w; }
54 const QString &type() const { return t; } 54 const QString &type() const { return t; }
55 const QString &category()const { return c; } 55 const QString &category()const { return c; }
@@ -93,6 +93,9 @@ class TranInfo
93 93
94class TranInfoList : public QList<TranInfo> 94class TranInfoList : public QList<TranInfo>
95{ 95{
96 public:
97 TranInfo *findMostRecentByDesc( const QString &desc );
98
96 protected: 99 protected:
97 int compareItems( QCollection::Item, QCollection::Item ); 100 int compareItems( QCollection::Item, QCollection::Item );
98}; 101};
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp
index 138d0e6..9379da0 100644
--- a/noncore/apps/checkbook/transaction.cpp
+++ b/noncore/apps/checkbook/transaction.cpp
@@ -29,8 +29,10 @@
29#include "transaction.h" 29#include "transaction.h"
30#include "traninfo.h" 30#include "traninfo.h"
31#include "cfg.h" 31#include "cfg.h"
32#include "checkbook.h"
32 33
33#include <qpe/datebookmonth.h> 34#include <qpe/datebookmonth.h>
35#include <qpe/resource.h>
34 36
35#include <qbuttongroup.h> 37#include <qbuttongroup.h>
36#include <qcombobox.h> 38#include <qcombobox.h>
@@ -41,14 +43,15 @@
41#include <qradiobutton.h> 43#include <qradiobutton.h>
42#include <qwhatsthis.h> 44#include <qwhatsthis.h>
43 45
44Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, 46Transaction::Transaction( QWidget *parent, bool bNew, const QString &acctname,
45 Cfg *pCfg ) 47 TranInfo *info, Cfg *pCfg )
46 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 48 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
47{ 49{
48 QString tempstr = tr( "Transaction for " ); 50 QString tempstr = tr( "Transaction for " );
49 tempstr.append( acctname ); 51 tempstr.append( acctname );
50 setCaption( tempstr ); 52 setCaption( tempstr );
51 53
54 _bNew=bNew;
52 tran = info; 55 tran = info;
53 _pCfg=pCfg; 56 _pCfg=pCfg;
54 57
@@ -114,9 +117,12 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
114 label = new QLabel( tr( "Description:" ), container ); 117 label = new QLabel( tr( "Description:" ), container );
115 QWhatsThis::add( label, tr( "Enter description of transaction here." ) ); 118 QWhatsThis::add( label, tr( "Enter description of transaction here." ) );
116 layout->addWidget( label, 2, 0 ); 119 layout->addWidget( label, 2, 0 );
117 descEdit = new QLineEdit( container ); 120 _cbDesc=new QComboBox( true, container );
118 QWhatsThis::add( descEdit, tr( "Enter description of transaction here." ) ); 121 _cbDesc->insertStringList( _pCfg->getPayees() );
119 layout->addMultiCellWidget( descEdit, 2, 2, 1, 3 ); 122 QWhatsThis::add( _cbDesc, tr( "Enter description of transaction here." ) );
123 layout->addMultiCellWidget( _cbDesc, 2, 2, 1, 3 );
124 connect( _cbDesc, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) );
125
120 126
121 // Category 127 // Category
122 label = new QLabel( tr( "Category:" ), container ); 128 label = new QLabel( tr( "Category:" ), container );
@@ -134,6 +140,7 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
134 QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); 140 QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
135 layout->addMultiCellWidget( typeList, 4, 4, 1, 3 ); 141 layout->addMultiCellWidget( typeList, 4, 4, 1, 3 );
136 142
143
137 // Amount 144 // Amount
138 label = new QLabel( tr( "Amount:" ), container ); 145 label = new QLabel( tr( "Amount:" ), container );
139 QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); 146 QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
@@ -158,6 +165,22 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
158 QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) ); 165 QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) );
159 layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 ); 166 layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 );
160 167
168 // init date
169 initFromInfo( info );
170
171 // not new handlers
172 connect( withBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
173 connect( depBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
174 connect( catList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
175 connect( typeList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
176 connect( amtEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
177 connect( feeEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
178 connect( noteEdit, SIGNAL(textChanged()), this, SLOT( slotNotNew() ) );
179}
180
181// --- initFromInfo -----------------------------------------------------------
182void Transaction::initFromInfo(TranInfo *info, bool bPopulateOld)
183{
161 // Populate current values if provided 184 // Populate current values if provided
162 if ( info ) 185 if ( info )
163 { 186 {
@@ -171,13 +194,27 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
171 depBtn->setChecked( TRUE ); 194 depBtn->setChecked( TRUE );
172 slotDepositClicked(); 195 slotDepositClicked();
173 } 196 }
174 QDate dt = info->date(); 197
175 slotDateChanged( dt.year(), dt.month(), dt.day() ); 198 if( !bPopulateOld ) {
176 datePicker->setDate( dt ); 199 QDate dt = info->date();
177 numEdit->setText( info->number() ); 200 slotDateChanged( dt.year(), dt.month(), dt.day() );
178 descEdit->setText( info->desc() ); 201 datePicker->setDate( dt );
202 numEdit->setText( info->number() );
203 }
179 QString temptext = info->category(); 204 QString temptext = info->category();
180 int i = catList->count(); 205
206 // set description field
207 int i;
208 for(i=_cbDesc->count()-1; i>=0; i--) {
209 if( _cbDesc->text(i)==info->desc() ) {
210 _cbDesc->setCurrentItem(i);
211 break;
212 }
213 }
214 if( i<=0 )
215 _cbDesc->setEditText( info->desc() );
216
217 i = catList->count();
181 while ( i > 0 ) 218 while ( i > 0 )
182 { 219 {
183 i--; 220 i--;
@@ -208,13 +245,16 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
208 } 245 }
209} 246}
210 247
248
249// --- ~Transaction -----------------------------------------------------------
211Transaction::~Transaction() 250Transaction::~Transaction()
212{ 251{
213} 252}
214 253
254// --- accept -----------------------------------------------------------------
215void Transaction::accept() 255void Transaction::accept()
216{ 256{
217 tran->setDesc( descEdit->text() ); 257 tran->setDesc( _cbDesc->currentText() );
218 tran->setDate( datePicker->selectedDate() ); 258 tran->setDate( datePicker->selectedDate() );
219 tran->setWithdrawal( withBtn->isChecked() ); 259 tran->setWithdrawal( withBtn->isChecked() );
220 tran->setType( typeList->currentText() ); 260 tran->setType( typeList->currentText() );
@@ -262,9 +302,37 @@ void Transaction::slotDepositClicked()
262 typeList->insertItem( tr( "Cash" ) ); 302 typeList->insertItem( tr( "Cash" ) );
263} 303}
264 304
305// --- slotDateChanged --------------------------------------------------------
265void Transaction::slotDateChanged( int y, int m, int d ) 306void Transaction::slotDateChanged( int y, int m, int d )
266{ 307{
267 QDate date; 308 QDate date;
268 date.setYMD( y, m, d ); 309 date.setYMD( y, m, d );
269 dateBtn->setText( TimeString::shortDate( date ) ); 310 dateBtn->setText( TimeString::shortDate( date ) );
270} 311}
312
313
314
315// --- slotActivated ----------------------------------------------------------
316// Search for the most recent transaction with this description/payee and
317// fill amount etc here, as long the new flag is set
318void Transaction::slotActivated(const QString &arg )
319{
320 if( !_bNew ) return;
321 TranInfoList *pTl=((Checkbook *)parentWidget())->getTranList();
322 if( pTl ) {
323 TranInfo *pTi=pTl->findMostRecentByDesc( arg );
324 if( pTi ) {
325 initFromInfo( pTi, true );
326 amtEdit->setFocus();
327 amtEdit->setSelection(0, amtEdit->text().length() );
328 amtEdit->setCursorPosition(0);
329 }
330 }
331}
332
333// slotNotNew -----------------------------------------------------------------
334void Transaction::slotNotNew()
335{
336 qDebug("Not new");
337 _bNew=false;
338}
diff --git a/noncore/apps/checkbook/transaction.h b/noncore/apps/checkbook/transaction.h
index fbe9cd3..130d769 100644
--- a/noncore/apps/checkbook/transaction.h
+++ b/noncore/apps/checkbook/transaction.h
@@ -47,12 +47,14 @@ class Transaction : public QDialog
47 Q_OBJECT 47 Q_OBJECT
48 48
49 public: 49 public:
50 Transaction( QWidget *, const QString &, TranInfo *, Cfg *); 50 Transaction( QWidget *, bool, const QString &, TranInfo *, Cfg *);
51 ~Transaction(); 51 ~Transaction();
52 52
53 private: 53 void initFromInfo(TranInfo *, bool=false);
54 TranInfo *tran;
55 54
55 private:
56 TranInfo *tran;
57 bool _bNew;
56 Cfg *_pCfg; 58 Cfg *_pCfg;
57 59
58 QRadioButton *withBtn; 60 QRadioButton *withBtn;
@@ -60,7 +62,7 @@ class Transaction : public QDialog
60 QPushButton *dateBtn; 62 QPushButton *dateBtn;
61 DateBookMonth *datePicker; 63 DateBookMonth *datePicker;
62 QLineEdit *numEdit; 64 QLineEdit *numEdit;
63 QLineEdit *descEdit; 65 QComboBox *_cbDesc;
64 QComboBox *catList; 66 QComboBox *catList;
65 QComboBox *typeList; 67 QComboBox *typeList;
66 QLineEdit *amtEdit; 68 QLineEdit *amtEdit;
@@ -74,6 +76,8 @@ class Transaction : public QDialog
74 void slotWithdrawalClicked(); 76 void slotWithdrawalClicked();
75 void slotDepositClicked(); 77 void slotDepositClicked();
76 void slotDateChanged( int, int, int ); 78 void slotDateChanged( int, int, int );
79 void slotActivated(const QString & );
80 void slotNotNew();
77}; 81};
78 82
79#endif 83#endif