summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-30 13:18:08 (UTC)
committer mickeyl <mickeyl>2003-10-30 13:18:08 (UTC)
commit37414f207b147af4cf6778b323a0aa23127901bd (patch) (unidiff)
treeb08c10043ab689b0a40425d268cd72226799b0cf
parentd53637f46cf217fc760d7aac58b4596843a73803 (diff)
downloadopie-37414f207b147af4cf6778b323a0aa23127901bd.zip
opie-37414f207b147af4cf6778b323a0aa23127901bd.tar.gz
opie-37414f207b147af4cf6778b323a0aa23127901bd.tar.bz2
apply patch to HEAD
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
@@ -38,27 +38,26 @@
38 38
39// --- Cfg -------------------------------------------------------------------- 39// --- Cfg --------------------------------------------------------------------
40Cfg::Cfg() 40Cfg::Cfg()
41{ 41{
42 _currencySymbol="$"; 42 _currencySymbol="$";
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 ---------------------------------------------------------
49// Reads the entries for the control from a configuration file and returns 50// Reads the entries for the control from a configuration file and returns
50// them in a StringList. Later this list can be used to create the control. It 51// them in a StringList. Later this list can be used to create the control. It
51// is assumed, that the group is already set. Key is used to enumerate the 52// is assumed, that the group is already set. Key is used to enumerate the
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
60 // read count of elements 59 // read count of elements
61 sEntry.sprintf("%s_Count", sKey); 60 sEntry.sprintf("%s_Count", sKey);
62 iCount=cfg.readNumEntry(sEntry, 0); 61 iCount=cfg.readNumEntry(sEntry, 0);
63 62
64 // read entries 63 // read entries
@@ -81,30 +80,34 @@ void Cfg::readConfig(Config &config)
81 80
82 // read scalars 81 // read scalars
83 _currencySymbol = config.readEntry( "CurrencySymbol", "$" ); 82 _currencySymbol = config.readEntry( "CurrencySymbol", "$" );
84 _showLocks = config.readBoolEntry( "ShowLocks", FALSE ); 83 _showLocks = config.readBoolEntry( "ShowLocks", FALSE );
85 _showBalances = config.readBoolEntry( "ShowBalances", FALSE ); 84 _showBalances = config.readBoolEntry( "ShowBalances", FALSE );
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);
92 if( _AccountTypes.isEmpty() ) { 92 if( _AccountTypes.isEmpty() ) {
93 _AccountTypes+= (const char *)QWidget::tr("Savings"); 93 _AccountTypes+= (const char *)QWidget::tr("Savings");
94 _AccountTypes+= (const char *)QWidget::tr("Checking"); 94 _AccountTypes+= (const char *)QWidget::tr("Checking");
95 _AccountTypes+= (const char *)QWidget::tr("CD"); 95 _AccountTypes+= (const char *)QWidget::tr("CD");
96 _AccountTypes+= (const char *)QWidget::tr("Money market"); 96 _AccountTypes+= (const char *)QWidget::tr("Money market");
97 _AccountTypes+= (const char *)QWidget::tr("Mutual fund"); 97 _AccountTypes+= (const char *)QWidget::tr("Mutual fund");
98 _AccountTypes+= (const char *)QWidget::tr("Other"); 98 _AccountTypes+= (const char *)QWidget::tr("Other");
99 writeStringList(config, "AccType", _AccountTypes); 99 writeStringList(config, "AccType", _AccountTypes);
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);
106 if( lst.isEmpty() ) { 109 if( lst.isEmpty() ) {
107 QString type=QWidget::tr("Expense"); 110 QString type=QWidget::tr("Expense");
108 lst += QWidget::tr( "Automobile" )+";"+type; 111 lst += QWidget::tr( "Automobile" )+";"+type;
109 lst += QWidget::tr( "Bills" )+";"+type; 112 lst += QWidget::tr( "Bills" )+";"+type;
110 lst += QWidget::tr( "CDs" )+";"+type; 113 lst += QWidget::tr( "CDs" )+";"+type;
@@ -126,16 +129,19 @@ void Cfg::readConfig(Config &config)
126 lst += QWidget::tr( "Misc. Credit" )+";"+type; 129 lst += QWidget::tr( "Misc. Credit" )+";"+type;
127 130
128 setCategories(lst); 131 setCategories(lst);
129 writeStringList(config, "Category", lst); 132 writeStringList(config, "Category", lst);
130 config.write(); 133 config.write();
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
137// --- writeStringList -------------------------------------------------------- 143// --- writeStringList --------------------------------------------------------
138// Writes the entries in the control in a configuration file. It is assumed, 144// Writes the entries in the control in a configuration file. It is assumed,
139// that the group is already set. Key is used to enumerate the entries 145// that the group is already set. Key is used to enumerate the entries
140void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) 146void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst)
141{ 147{
@@ -161,26 +167,31 @@ void Cfg::writeConfig(Config &config)
161 167
162 // write scalars 168 // write scalars
163 config.writeEntry( "CurrencySymbol", _currencySymbol ); 169 config.writeEntry( "CurrencySymbol", _currencySymbol );
164 config.writeEntry( "ShowLocks", _showLocks ); 170 config.writeEntry( "ShowLocks", _showLocks );
165 config.writeEntry( "ShowBalances", _showBalances ); 171 config.writeEntry( "ShowBalances", _showBalances );
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
182// --- getCategories ---------------------------------------------------------- 193// --- getCategories ----------------------------------------------------------
183QStringList Cfg::getCategories() 194QStringList Cfg::getCategories()
184{ 195{
185 QStringList ret; 196 QStringList ret;
186 for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) { 197 for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) {
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
@@ -72,16 +72,21 @@ class Cfg
72 void setShowLocks(bool n) { _showLocks=n; } 72 void setShowLocks(bool n) { _showLocks=n; }
73 bool getShowBalances() { return(_showBalances); } 73 bool getShowBalances() { return(_showBalances); }
74 void setShowBalances(bool n) { _showBalances=n; } 74 void setShowBalances(bool n) { _showBalances=n; }
75 QString &getCurrencySymbol() { return(_currencySymbol); } 75 QString &getCurrencySymbol() { return(_currencySymbol); }
76 void setCurrencySymbol(QString n) {_currencySymbol= n; } 76 void setCurrencySymbol(QString n) {_currencySymbol= n; }
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);
83 CategoryList *getCategoryList() { return(_pCategories); } 88 CategoryList *getCategoryList() { return(_pCategories); }
84 89
85 // --- last book 90 // --- last book
86 void setOpenLastBook(bool openLastBook) { _openLastBook=openLastBook; } 91 void setOpenLastBook(bool openLastBook) { _openLastBook=openLastBook; }
87 bool isOpenLastBook() { return(_openLastBook); } 92 bool isOpenLastBook() { return(_openLastBook); }
@@ -93,28 +98,35 @@ class Cfg
93 bool isShowLastTab() { return(_showLastTab); } 98 bool isShowLastTab() { return(_showLastTab); }
94 99
95 // --- reads data from config file 100 // --- reads data from config file
96 void readConfig(Config &cfg); 101 void readConfig(Config &cfg);
97 102
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
@@ -44,23 +44,25 @@
44#include <qcheckbox.h> 44#include <qcheckbox.h>
45#include <qcombobox.h> 45#include <qcombobox.h>
46#include <qlabel.h> 46#include <qlabel.h>
47#include <qlayout.h> 47#include <qlayout.h>
48#include <qlineedit.h> 48#include <qlineedit.h>
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 )
62 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 64 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
63{ 65{
64 info = i; 66 info = i;
65 _pCfg=cfg; 67 _pCfg=cfg;
66 68
@@ -219,30 +221,35 @@ QWidget *Checkbook::initTransactions()
219 tranTable = new QListView( control ); 221 tranTable = new QListView( control );
220 QFont fnt(QPEApplication::font()); 222 QFont fnt(QPEApplication::font());
221 fnt.setPointSize( fnt.pointSize()-1 ); 223 fnt.setPointSize( fnt.pointSize()-1 );
222 tranTable->setFont( fnt ); 224 tranTable->setFont( fnt );
223 QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); 225 QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) );
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" ) );
230 tranTable->addColumn( tr( "Description" ) ); 235 tranTable->addColumn( tr( "Description" ) );
231 int column = tranTable->addColumn( tr( "Amount" ) ); 236 int column = tranTable->addColumn( tr( "Amount" ) );
232 tranTable->setColumnAlignment( column, Qt::AlignRight ); 237 tranTable->setColumnAlignment( column, Qt::AlignRight );
233 column=tranTable->addColumn( tr("Balance") ); 238 column=tranTable->addColumn( tr("Balance") );
234 tranTable->setColumnAlignment( column, Qt::AlignRight ); 239 tranTable->setColumnAlignment( column, Qt::AlignRight );
235 tranTable->setAllColumnsShowFocus( TRUE ); 240 tranTable->setAllColumnsShowFocus( TRUE );
236 tranTable->setSorting( -1 ); 241 tranTable->setSorting( -1 );
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
244 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); 251 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
245 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); 252 QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
246 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); 253 connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
247 layout->addWidget( btn, 2, 0 ); 254 layout->addWidget( btn, 2, 0 );
248 255
@@ -331,17 +338,17 @@ void Checkbook::loadCheckbook()
331 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) 338 for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
332 { 339 {
333 amount = tran->amount(); 340 amount = tran->amount();
334 if ( tran->withdrawal() ) 341 if ( tran->withdrawal() )
335 { 342 {
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
343 bool bOk=false; 350 bool bOk=false;
344 for(int i=0; i<_cbSortType->count(); i++) { 351 for(int i=0; i<_cbSortType->count(); i++) {
345 if( _cbSortType->text(i)==info->getSortOrder() ) { 352 if( _cbSortType->text(i)==info->getSortOrder() ) {
346 _cbSortType->setCurrentItem(i); 353 _cbSortType->setCurrentItem(i);
347 slotSortChanged( info->getSortOrder() ); 354 slotSortChanged( info->getSortOrder() );
@@ -353,16 +360,17 @@ void Checkbook::loadCheckbook()
353 _cbSortType->setCurrentItem(0); 360 _cbSortType->setCurrentItem(0);
354 slotSortChanged( _cbSortType->currentText() ); 361 slotSortChanged( _cbSortType->currentText() );
355 } 362 }
356 363
357 // calc running balance 364 // calc running balance
358 adjustBalance(); 365 adjustBalance();
359} 366}
360 367
368
361// --- adjustBalance ---------------------------------------------------------- 369// --- adjustBalance ----------------------------------------------------------
362void Checkbook::adjustBalance() 370void Checkbook::adjustBalance()
363{ 371{
364 // update running balance in register 372 // update running balance in register
365 QString sRunning; 373 QString sRunning;
366 float bal=info->startingBalance(); 374 float bal=info->startingBalance();
367 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { 375 for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) {
368 TranInfo *tran=item->getTranInfo(); 376 TranInfo *tran=item->getTranInfo();
@@ -391,16 +399,17 @@ void Checkbook::accept()
391 info->setPin( pinNumEdit->text() ); 399 info->setPin( pinNumEdit->text() );
392 bool ok; 400 bool ok;
393 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); 401 info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
394 info->setNotes( notesEdit->text() ); 402 info->setNotes( notesEdit->text() );
395 403
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() )
402 { 411 {
403 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 412 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
404 if ( pw->exec() != QDialog::Accepted ) 413 if ( pw->exec() != QDialog::Accepted )
405 { 414 {
406 passwordCB->setChecked( FALSE ); 415 passwordCB->setChecked( FALSE );
@@ -459,84 +468,132 @@ void Checkbook::slotNameChanged( const QString &newname )
459void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) 468void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
460{ 469{
461 bool ok; 470 bool ok;
462 info->setStartingBalance( newbalance.toFloat( &ok ) ); 471 info->setStartingBalance( newbalance.toFloat( &ok ) );
463 adjustBalance(); 472 adjustBalance();
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();
477 if ( currtran->exec() == QDialog::Accepted ) 487 if ( currtran->exec() == QDialog::Accepted )
478 { 488 {
479 // Add to transaction list 489 // Add to transaction list
480 info->addTransaction( traninfo ); 490 info->addTransaction( traninfo );
481 491
482 // Add to transaction table 492 // Add to transaction table
483 float amount; 493 float amount;
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 {
498 delete traninfo; 516 delete traninfo;
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();
521 if ( traninfo->withdrawal() ) 542 if ( traninfo->withdrawal() )
522 { 543 {
523 amount *= -1; 544 amount *= -1;
524 } 545 }
525 QString stramount; 546 QString stramount;
526 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); 547 stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
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();
538 if ( !curritem ) 595 if ( !curritem )
539 return; 596 return;
540 597
541 TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); 598 TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) );
542 599
@@ -586,17 +643,17 @@ void Checkbook::drawBalanceChart()
586 amount = tran->amount(); 643 amount = tran->amount();
587 if ( tran->withdrawal() ) 644 if ( tran->withdrawal() )
588 { 645 {
589 amount *= -1; 646 amount *= -1;
590 } 647 }
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 {
598 label = ""; 655 label = "";
599 } 656 }
600 list->append( new DataPointInfo( label, balance ) ); 657 list->append( new DataPointInfo( label, balance ) );
601 } 658 }
602 659
@@ -661,16 +718,17 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int
661 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 718 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
662 } 719 }
663 else if ( isAltBackground() ) 720 else if ( isAltBackground() )
664 _cg.setColor(QColorGroup::Base, cg.background() ); 721 _cg.setColor(QColorGroup::Base, cg.background() );
665 722
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() );
672 if ( lv ) 730 if ( lv )
673 { 731 {
674 CBListItem *above = 0; 732 CBListItem *above = 0;
675 above = (CBListItem *)( itemAbove() ); 733 above = (CBListItem *)( itemAbove() );
676 m_known = above ? above->m_known : true; 734 m_known = above ? above->m_known : true;
@@ -718,13 +776,14 @@ void Checkbook::slotTab(QWidget *tab)
718// --- slotSortChanged --------------------------------------------------------- 776// --- slotSortChanged ---------------------------------------------------------
719void Checkbook::slotSortChanged( const QString &selc ) 777void Checkbook::slotSortChanged( const QString &selc )
720{ 778{
721 if( selc==tr("Entry Order") ) { 779 if( selc==tr("Entry Order") ) {
722 _sortCol=COL_ID; 780 _sortCol=COL_ID;
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
@@ -43,30 +43,34 @@ class QComboBox;
43class QLabel; 43class QLabel;
44class QLineEdit; 44class QLineEdit;
45class QListView; 45class QListView;
46class QMultiLineEdit; 46class QMultiLineEdit;
47class QString; 47class QString;
48class TranInfo; 48class TranInfo;
49class TranInfoList; 49class TranInfoList;
50class Cfg; 50class Cfg;
51class QMouseEvent;
51 52
52 53
53// --- Checkbook -------------------------------------------------------------- 54// --- Checkbook --------------------------------------------------------------
54class Checkbook : public QDialog 55class Checkbook : public QDialog
55{ 56{
56 Q_OBJECT 57 Q_OBJECT
57 58
58 public: 59 public:
59 Checkbook( QWidget *, CBInfo *, Cfg *cfg ); 60 Checkbook( QWidget *, CBInfo *, Cfg *cfg );
60 ~Checkbook(); 61 ~Checkbook();
61 62
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;
68 Cfg *_pCfg; 72 Cfg *_pCfg;
69 73
70 OTabWidget *mainWidget; 74 OTabWidget *mainWidget;
71 void loadCheckbook(); 75 void loadCheckbook();
72 void adjustBalance(); 76 void adjustBalance();
@@ -104,37 +108,39 @@ class Checkbook : public QDialog
104 void slotTab(QWidget *tab); 108 void slotTab(QWidget *tab);
105 109
106 private slots: 110 private slots:
107 void slotPasswordClicked(); 111 void slotPasswordClicked();
108 void slotNameChanged( const QString & ); 112 void slotNameChanged( const QString & );
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{
120 //Q_OBJECT 126 //Q_OBJECT
121 127
122 public: 128 public:
123 CBListItem( TranInfo *, QListView *, QString = QString::null, QString = QString::null, 129 CBListItem( TranInfo *, QListView *, QString = QString::null, QString = QString::null,
124 QString = QString::null, QString = QString::null, QString = QString::null, 130 QString = QString::null, QString = QString::null, QString = QString::null,
125 QString = QString::null, QString = QString::null, QString = QString::null ); 131 QString = QString::null, QString = QString::null, QString = QString::null );
126 132
127 void paintCell( QPainter *, const QColorGroup &, int, int, int ); 133 void paintCell( QPainter *, const QColorGroup &, int, int, int );
128 134
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;
136 bool m_odd; 142 bool m_odd;
137 143
138 bool isAltBackground(); 144 bool isAltBackground();
139}; 145};
140 146
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
@@ -71,16 +71,22 @@ Configuration::Configuration( QWidget *parent, Cfg &cfg )
71 _listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) ); 71 _listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) );
72 d=new ColumnDef( tr("Type"), ColumnDef::typeList, tr("Expense") ); 72 d=new ColumnDef( tr("Type"), ColumnDef::typeList, tr("Expense") );
73 d->addColumnValue( tr("Expense") ); 73 d->addColumnValue( tr("Expense") );
74 d->addColumnValue( tr("Income") ); 74 d->addColumnValue( tr("Income") );
75 _listEditCategories->addColumnDef( d ); 75 _listEditCategories->addColumnDef( d );
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()
82{ 88{
83} 89}
84 90
85// ---- initSettings ---------------------------------------------------------- 91// ---- initSettings ----------------------------------------------------------
86QWidget *Configuration::initSettings(Cfg &cfg) 92QWidget *Configuration::initSettings(Cfg &cfg)
@@ -133,29 +139,39 @@ QWidget *Configuration::initSettings(Cfg &cfg)
133 layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 ); 139 layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 );
134 140
135 lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container ); 141 lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container );
136 QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") ); 142 QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") );
137 lastTabCB->setMaximumHeight(fh+5); 143 lastTabCB->setMaximumHeight(fh+5);
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
144// --- saveConfig ------------------------------------------------------------- 156// --- saveConfig -------------------------------------------------------------
145void Configuration::saveConfig(Cfg &cfg) 157void Configuration::saveConfig(Cfg &cfg)
146{ 158{
147 // Settings 159 // Settings
148 cfg.setCurrencySymbol( symbolEdit->text() ); 160 cfg.setCurrencySymbol( symbolEdit->text() );
149 cfg.setShowLocks( lockCB->isChecked() ); 161 cfg.setShowLocks( lockCB->isChecked() );
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() );
156 169
157 // Category list 170 // Category list
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
@@ -47,19 +47,21 @@ class Configuration : public QDialog
47 Configuration( QWidget *, Cfg &cfg); 47 Configuration( QWidget *, Cfg &cfg);
48 ~Configuration(); 48 ~Configuration();
49 49
50 QLineEdit *symbolEdit; 50 QLineEdit *symbolEdit;
51 QCheckBox *lockCB; 51 QCheckBox *lockCB;
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);
61 63
62 protected: 64 protected:
63 // creates settings tap from configuration 65 // creates settings tap from configuration
64 QWidget *initSettings(Cfg &cfg); 66 QWidget *initSettings(Cfg &cfg);
65}; 67};
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
@@ -111,16 +111,20 @@ void ListEdit::slotAdd()
111 111
112 // fix uniques 112 // fix uniques
113 fixTypes(); 113 fixTypes();
114 114
115 // display col 0 of new value 115 // display col 0 of new value
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 -------------------------------------------------------------
122void ListEdit::slotDel() 126void ListEdit::slotDel()
123{ 127{
124 if( !_currentItem ) return; 128 if( !_currentItem ) return;
125 delete _currentItem; 129 delete _currentItem;
126 _currentItem=NULL; 130 _currentItem=NULL;
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
@@ -53,17 +53,16 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
53{ 53{
54 setCaption( tr( "Checkbook" ) ); 54 setCaption( tr( "Checkbook" ) );
55 55
56 cbDir = Global::applicationFileName( "checkbook", "" ); 56 cbDir = Global::applicationFileName( "checkbook", "" );
57 lockIcon = Resource::loadPixmap( "locked" ); 57 lockIcon = Resource::loadPixmap( "locked" );
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
65 // Build menu and tool bars 64 // Build menu and tool bars
66 setToolBarsMovable( FALSE ); 65 setToolBarsMovable( FALSE );
67 66
68 QPEToolBar *bar = new QPEToolBar( this ); 67 QPEToolBar *bar = new QPEToolBar( this );
69 bar->setHorizontalStretchable( TRUE ); 68 bar->setHorizontalStretchable( TRUE );
@@ -309,16 +308,22 @@ void MainWindow::openBook(QListViewItem *curritem)
309 308
310 // Update balance if changed 309 // Update balance if changed
311 if ( _cfg.getShowBalances() && cb->balance() != currbalance ) 310 if ( _cfg.getShowBalances() && cb->balance() != currbalance )
312 { 311 {
313 QString tempstr; 312 QString tempstr;
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}
320 325
321// --- slotDelete ------------------------------------------------------------- 326// --- slotDelete -------------------------------------------------------------
322void MainWindow::slotDelete() 327void MainWindow::slotDelete()
323{ 328{
324 QString currname = cbList->currentItem()->text( posName ); 329 QString currname = cbList->currentItem()->text( posName );
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
@@ -24,16 +24,17 @@
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 "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
35TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal, 36TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal,
36 const QString &type, const QString &category, float amount, 37 const QString &type, const QString &category, float amount,
37 float fee, const QString &number, const QString &notes, int next ) 38 float fee, const QString &number, const QString &notes, int next )
38{ 39{
39 i = id; 40 i = id;
@@ -119,24 +120,27 @@ TranInfo::TranInfo( Config config, int entry )
119 n = config.readEntry( "Comments", "" ); 120 n = config.readEntry( "Comments", "" );
120 121
121 // next 122 // next
122 _next = config.readNumEntry("Next", -1); 123 _next = config.readNumEntry("Next", -1);
123 } 124 }
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{
138 tempstr.sprintf("%04d", i); 142 tempstr.sprintf("%04d", i);
139 return( tempstr ); 143 return( tempstr );
140} 144}
141 145
142// --- write ------------------------------------------------------------------ 146// --- write ------------------------------------------------------------------
@@ -205,8 +209,19 @@ QString TranInfo::toString()
205 (const char *)datestr(), 209 (const char *)datestr(),
206 (const char *)number(), 210 (const char *)number(),
207 (const char *)desc(), 211 (const char *)desc(),
208 (withdrawal() ? -1 : 1) * amount(), 212 (withdrawal() ? -1 : 1) * amount(),
209 fee() 213 fee()
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
@@ -44,17 +44,17 @@ class TranInfo
44 TranInfo( Config, int ); 44 TranInfo( Config, int );
45 45
46 // getters 46 // getters
47 int id() const { return i; } 47 int id() const { return i; }
48 const QString &getIdStr(); 48 const QString &getIdStr();
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; }
56 float amount() const { return a; } 56 float amount() const { return a; }
57 float fee() const { return f; } 57 float fee() const { return f; }
58 const QString &number()const { return cn; } 58 const QString &number()const { return cn; }
59 const QString &notes() const { return n; } 59 const QString &notes() const { return n; }
60 int getNext() { return(_next); } 60 int getNext() { return(_next); }
@@ -88,13 +88,16 @@ class TranInfo
88 float f; 88 float f;
89 QString cn; 89 QString cn;
90 QString n; 90 QString n;
91 int _next; 91 int _next;
92}; 92};
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};
99 102
100#endif 103#endif
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
@@ -24,36 +24,39 @@
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 "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>
37#include <qlabel.h> 39#include <qlabel.h>
38#include <qlayout.h> 40#include <qlayout.h>
39#include <qlineedit.h> 41#include <qlineedit.h>
40#include <qmultilineedit.h> 42#include <qmultilineedit.h>
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
55 QVBoxLayout *vb = new QVBoxLayout( this ); 58 QVBoxLayout *vb = new QVBoxLayout( this );
56 59
57 QScrollView *sv = new QScrollView( this ); 60 QScrollView *sv = new QScrollView( this );
58 vb->addWidget( sv, 0, 0 ); 61 vb->addWidget( sv, 0, 0 );
59 sv->setResizePolicy( QScrollView::AutoOneFit ); 62 sv->setResizePolicy( QScrollView::AutoOneFit );
@@ -109,19 +112,22 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
109 QWhatsThis::add( numEdit, tr( "Enter check number here." ) ); 112 QWhatsThis::add( numEdit, tr( "Enter check number here." ) );
110 numEdit->setMaximumWidth( 40 ); 113 numEdit->setMaximumWidth( 40 );
111 layout->addWidget( numEdit, 1, 3 ); 114 layout->addWidget( numEdit, 1, 3 );
112 115
113 // Description 116 // Description
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 );
123 QWhatsThis::add( label, tr( "Select transaction category here." ) ); 129 QWhatsThis::add( label, tr( "Select transaction category here." ) );
124 layout->addWidget( label, 3, 0 ); 130 layout->addWidget( label, 3, 0 );
125 catList = new QComboBox( container ); 131 catList = new QComboBox( container );
126 QWhatsThis::add( catList, tr( "Select transaction category here." ) ); 132 QWhatsThis::add( catList, tr( "Select transaction category here." ) );
127 layout->addMultiCellWidget( catList, 3, 3, 1, 3 ); 133 layout->addMultiCellWidget( catList, 3, 3, 1, 3 );
@@ -129,16 +135,17 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
129 // Type 135 // Type
130 label = new QLabel( tr( "Type:" ), container ); 136 label = new QLabel( tr( "Type:" ), container );
131 QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); 137 QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
132 layout->addWidget( label, 4, 0 ); 138 layout->addWidget( label, 4, 0 );
133 typeList = new QComboBox( container ); 139 typeList = new QComboBox( container );
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." ) );
140 layout->addWidget( label, 5, 0 ); 147 layout->addWidget( label, 5, 0 );
141 amtEdit = new QLineEdit( container ); 148 amtEdit = new QLineEdit( container );
142 QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); 149 QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
143 layout->addMultiCellWidget( amtEdit, 5, 5, 1, 3 ); 150 layout->addMultiCellWidget( amtEdit, 5, 5, 1, 3 );
144 151
@@ -153,36 +160,66 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
153 // Notes 160 // Notes
154 label = new QLabel( tr( "Notes:" ), container ); 161 label = new QLabel( tr( "Notes:" ), container );
155 QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) ); 162 QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) );
156 layout->addWidget( label, 7, 0 ); 163 layout->addWidget( label, 7, 0 );
157 noteEdit = new QMultiLineEdit( container ); 164 noteEdit = new QMultiLineEdit( container );
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 {
164 if ( info->withdrawal() ) 187 if ( info->withdrawal() )
165 { 188 {
166 withBtn->setChecked( TRUE ); 189 withBtn->setChecked( TRUE );
167 slotWithdrawalClicked(); 190 slotWithdrawalClicked();
168 } 191 }
169 else 192 else
170 { 193 {
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--;
184 catList->setCurrentItem( i ); 221 catList->setCurrentItem( i );
185 if ( catList->currentText() == temptext ) 222 if ( catList->currentText() == temptext )
186 { 223 {
187 break; 224 break;
188 } 225 }
@@ -203,23 +240,26 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
203 noteEdit->setText( info->notes() ); 240 noteEdit->setText( info->notes() );
204 } 241 }
205 else 242 else
206 { 243 {
207 withBtn->setChecked( TRUE ); 244 withBtn->setChecked( TRUE );
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() );
221 tran->setCategory( catList->currentText() ); 261 tran->setCategory( catList->currentText() );
222 bool ok; 262 bool ok;
223 tran->setAmount( amtEdit->text().toFloat( &ok ) ); 263 tran->setAmount( amtEdit->text().toFloat( &ok ) );
224 tran->setFee( feeEdit->text().toFloat( &ok ) ); 264 tran->setFee( feeEdit->text().toFloat( &ok ) );
225 tran->setNumber( numEdit->text() ); 265 tran->setNumber( numEdit->text() );
@@ -257,14 +297,42 @@ void Transaction::slotDepositClicked()
257 297
258 typeList->clear(); 298 typeList->clear();
259 typeList->insertItem( tr( "Written Check" ) ); 299 typeList->insertItem( tr( "Written Check" ) );
260 typeList->insertItem( tr( "Automatic Payment" ) ); 300 typeList->insertItem( tr( "Automatic Payment" ) );
261 typeList->insertItem( tr( "Transfer" ) ); 301 typeList->insertItem( tr( "Transfer" ) );
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
@@ -42,38 +42,42 @@ class QWidget;
42class TranInfo; 42class TranInfo;
43class Cfg; 43class Cfg;
44 44
45class Transaction : public QDialog 45class Transaction : public QDialog
46{ 46{
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;
59 QRadioButton *depBtn; 61 QRadioButton *depBtn;
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;
67 QLineEdit *feeEdit; 69 QLineEdit *feeEdit;
68 QMultiLineEdit *noteEdit; 70 QMultiLineEdit *noteEdit;
69 71
70 protected slots: 72 protected slots:
71 void accept(); 73 void accept();
72 74
73 private slots: 75 private slots:
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