summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show 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.cpp85
-rw-r--r--noncore/apps/checkbook/checkbook.h6
-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.cpp23
-rw-r--r--noncore/apps/checkbook/traninfo.h5
-rw-r--r--noncore/apps/checkbook/transaction.cpp84
-rw-r--r--noncore/apps/checkbook/transaction.h10
12 files changed, 239 insertions, 34 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
@@ -45,2 +45,3 @@ Cfg::Cfg()
_pCategories=new CategoryList();
+ _bDirty=false;
}
@@ -54,4 +55,2 @@ void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
{
-qDebug( "%s", sKey );
-
QString sEntry;
@@ -88,2 +87,3 @@ void Cfg::readConfig(Config &config)
_showLastTab = config.readBoolEntry( "ShowLastTab", FALSE );
+ _bSavePayees = config.readBoolEntry( "SavePayees", FALSE );
@@ -102,2 +102,5 @@ void Cfg::readConfig(Config &config)
+ // Payees
+ readStringList(config, "Payee", _Payees);
+
// Read Categories
@@ -133,2 +136,5 @@ void Cfg::readConfig(Config &config)
}
+
+ // not dirty
+ _bDirty=false;
}
@@ -168,2 +174,3 @@ void Cfg::writeConfig(Config &config)
config.writeEntry( "ShowLastTab", _showLastTab );
+ config.writeEntry( "SavePayees", _bSavePayees );
@@ -172,2 +179,5 @@ void Cfg::writeConfig(Config &config)
+ // write payees
+ writeStringList(config, "Payee", _Payees);
+
// write categories
@@ -178,2 +188,3 @@ void Cfg::writeConfig(Config &config)
config.write();
+ _bDirty=false;
}
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
@@ -79,2 +79,7 @@ class Cfg
+ // --- Payees
+ QStringList &getPayees() { return(_Payees); }
+ bool getSavePayees() { return(_bSavePayees); }
+ void setSavePayees(bool bSave) { _bSavePayees=bSave; }
+
// --- Categories
@@ -100,2 +105,7 @@ class Cfg
+ // --- dirty flag
+ bool isDirty() { return(_bDirty); }
+ void setDirty(bool bDirty) { _bDirty=bDirty; }
+
+ protected:
// --- reads list from config file
@@ -106,4 +116,2 @@ class Cfg
-
-
private:
@@ -114,2 +122,4 @@ class Cfg
bool _showLastTab;
+ bool _bDirty;
+ bool _bSavePayees;
QString _sLastBook;
@@ -117,2 +127,4 @@ class Cfg
CategoryList *_pCategories;
+ QStringList _Payees;
+
};
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
@@ -51,9 +51,11 @@
#include <qwhatsthis.h>
+#include <qpopupmenu.h>
#define COL_ID 0
-#define COL_NUM 1
-#define COL_DATE 2
-#define COL_DESC 3
-#define COL_AMOUNT 4
-#define COL_BAL 5
+#define COL_SORTDATE 1
+#define COL_NUM 2
+#define COL_DATE 3
+#define COL_DESC 4
+#define COL_AMOUNT 5
+#define COL_BAL 6
@@ -226,2 +228,5 @@ QWidget *Checkbook::initTransactions()
tranTable->setColumnWidth( COL_ID, 0);
+ tranTable->addColumn( tr( "SortDate" ) );
+ tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
+ tranTable->setColumnWidth( COL_SORTDATE, 0);
tranTable->addColumn( tr( "Num" ) );
@@ -239,2 +244,4 @@ QWidget *Checkbook::initTransactions()
connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
+ this, SLOT( slotMenuTran(QListViewItem *, const QPoint &) ) );
+ connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
this, SLOT( slotEditTran() ) );
@@ -338,3 +345,3 @@ void Checkbook::loadCheckbook()
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
- ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount );
+ ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
}
@@ -360,2 +367,3 @@ void Checkbook::loadCheckbook()
+
// --- adjustBalance ----------------------------------------------------------
@@ -398,2 +406,3 @@ void Checkbook::accept()
+// --- slotPasswordClicked ----------------------------------------------------
void Checkbook::slotPasswordClicked()
@@ -466,2 +475,3 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
+// --- slotNewTran ------------------------------------------------------------
void Checkbook::slotNewTran()
@@ -472,3 +482,3 @@ void Checkbook::slotNewTran()
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, true, info->name(),
traninfo,
@@ -486,4 +496,4 @@ void Checkbook::slotNewTran()
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
- ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(),
- traninfo->number(), traninfo->datestr(), traninfo->desc(),
+ ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
+ traninfo->number(), traninfo->datestr(true), traninfo->desc(),
stramount );
@@ -494,2 +504,10 @@ void Checkbook::slotNewTran()
_dLastNew = traninfo->date();
+
+ // save description in list of payees, if not in there
+ QStringList *pLst=&_pCfg->getPayees();
+ if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
+ pLst->append( traninfo->desc() );
+ pLst->sort();
+ _pCfg->setDirty(true);
+ }
}
@@ -501,2 +519,4 @@ void Checkbook::slotNewTran()
+
+// --- slotEditTran -----------------------------------------------------------
void Checkbook::slotEditTran()
@@ -509,3 +529,3 @@ void Checkbook::slotEditTran()
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, false, info->name(),
traninfo,
@@ -516,3 +536,4 @@ void Checkbook::slotEditTran()
curritem->setText( COL_NUM, traninfo->number() );
- curritem->setText( COL_DATE, traninfo->datestr() );
+ curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
+ curritem->setText( COL_DATE, traninfo->datestr(true) );
curritem->setText( COL_DESC, traninfo->desc() );
@@ -529,2 +550,10 @@ void Checkbook::slotEditTran()
adjustBalance();
+
+ // save description in list of payees, if not in there
+ QStringList *pLst=&_pCfg->getPayees();
+ if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
+ pLst->append( traninfo->desc() );
+ pLst->sort();
+ _pCfg->setDirty(true);
+ }
}
@@ -534,2 +563,30 @@ void Checkbook::slotEditTran()
+// --- slotMenuTran -----------------------------------------------------------
+void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
+{
+ // active item?
+ if( !item )
+ return;
+
+ // Display menu
+ QPopupMenu m;
+ m.insertItem( QWidget::tr( "Edit" ), 1 );
+ m.insertItem( QWidget::tr( "New" ), 2 );
+ m.insertItem( QWidget::tr( "Delete" ), 3 );
+ int r = m.exec( pnt );
+ switch(r) {
+ case 1:
+ slotEditTran();
+ break;
+ case 2:
+ slotNewTran();
+ break;
+ case 3:
+ slotDeleteTran();
+ break;
+ }
+}
+
+
+// --- slotDeleteTran ---------------------------------------------------------
void Checkbook::slotDeleteTran()
@@ -593,3 +650,3 @@ void Checkbook::drawBalanceChart()
{
- label = tran->datestr();
+ label = tran->datestr(true);
}
@@ -668,2 +725,3 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int
+// --- CBListItem::isAltBackground --------------------------------------------
bool CBListItem::isAltBackground()
@@ -725,3 +783,3 @@ void Checkbook::slotSortChanged( const QString &selc )
} else if( selc==tr("Date") ) {
- _sortCol=COL_DATE;
+ _sortCol=COL_SORTDATE;
}
@@ -730 +788,2 @@ void Checkbook::slotSortChanged( const QString &selc )
}
+
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
@@ -50,2 +50,3 @@ class TranInfoList;
class Cfg;
+class QMouseEvent;
@@ -64,2 +65,5 @@ class Checkbook : public QDialog
+ // members
+ TranInfoList *getTranList() { return(tranList); }
+
private:
@@ -111,2 +115,3 @@ class Checkbook : public QDialog
void slotEditTran();
+ void slotMenuTran(QListViewItem *, const QPoint &);
void slotDeleteTran();
@@ -116,2 +121,3 @@ class Checkbook : public QDialog
+
// --- CBListItem -------------------------------------------------------------
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
@@ -78,2 +78,8 @@ Configuration::Configuration( QWidget *parent, Cfg &cfg )
_mainWidget->addTab( _listEditCategories, tr( "&Categories" ) );
+
+ // Payees tab
+ _listEditPayees=new ListEdit(_mainWidget, "PAYEES");
+ _listEditPayees->addColumnDef( new ColumnDef( tr("Payee"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Payee")) );
+ _listEditPayees->addData( cfg.getPayees() );
+ _mainWidget->addTab( _listEditPayees, tr("&Payees") );
}
@@ -140,2 +146,8 @@ QWidget *Configuration::initSettings(Cfg &cfg)
+ savePayees = new QCheckBox( tr("Save new description as payee"), container );
+ QWhatsThis::add( savePayees, tr("Click here to save new descriptions in the list of payess.") );
+ savePayees->setMaximumHeight(fh+5);
+ savePayees->setChecked( cfg.getSavePayees() );
+ layout->addMultiCellWidget( savePayees, 5, 5, 0, 1 );
+
return(control);
@@ -152,2 +164,3 @@ void Configuration::saveConfig(Cfg &cfg)
cfg.setShowLastTab( lastTabCB->isChecked() );
+ cfg.setSavePayees( savePayees->isChecked() );
@@ -160,2 +173,5 @@ void Configuration::saveConfig(Cfg &cfg)
cfg.setCategories( lst );
+
+ // Payees
+ _listEditPayees->storeInList( cfg.getPayees() );
}
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
@@ -54,2 +54,3 @@ class Configuration : public QDialog
QCheckBox *lastTabCB;
+ QCheckBox *savePayees;
QTabWidget *_mainWidget;
@@ -57,2 +58,3 @@ class Configuration : public QDialog
ListEdit *_listEditCategories;
+ ListEdit *_listEditPayees;
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
@@ -118,2 +118,6 @@ void ListEdit::slotAdd()
_typeTable->setSelected( _currentItem, true );
+
+ // make it selected
+ _typeEdit->setCursorPosition(0);
+ _typeEdit->setSelection(0, _typeEdit->text().length() );
}
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
@@ -60,3 +60,2 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
Config config( "checkbook" );
-qDebug( "Reading config" );
_cfg.readConfig( config );
@@ -316,2 +315,8 @@ void MainWindow::openBook(QListViewItem *curritem)
}
+
+ // write config, if needed
+ if( _cfg.isDirty() ) {
+ Config config("checkbook");
+ _cfg.writeConfig( config );
+ }
}
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
@@ -31,2 +31,3 @@
#include <qpe/config.h>
+#include <qpe/timestring.h>
@@ -126,7 +127,9 @@ TranInfo::TranInfo( Config config, int entry )
// --- datestr ----------------------------------------------------------------
-const QString &TranInfo::datestr()
+const QString &TranInfo::datestr(bool bDisplayDate)
{
- int y=td.year();
- y= y>=2000 && y<=2099 ? y-2000 : y;
- tempstr.sprintf( "%02d/%02d/%02d", y ,td.month(), td.day() );
+ if( bDisplayDate ) {
+ tempstr=TimeString::numberDateString( td );
+ } else {
+ tempstr.sprintf( "%04d-%02d-%02d", td.year() ,td.month(), td.day() );
+ }
return( tempstr );
@@ -134,2 +137,3 @@ const QString &TranInfo::datestr()
+
// --- getIdStr ---------------------------------------------------------------
@@ -212 +216,12 @@ QString TranInfo::toString()
}
+
+
+// --- findMostRecentByDesc ---------------------------------------------------
+TranInfo *TranInfoList::findMostRecentByDesc( const QString &desc )
+{
+ for(TranInfo *cur=last(); cur; cur=prev()) {
+ if( cur->desc()==desc )
+ return( cur );
+ }
+ return(NULL);
+} \ 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
@@ -51,3 +51,3 @@ class TranInfo
const QDate &date() const { return td; }
- const QString &datestr();
+ const QString &datestr(bool = false);
bool withdrawal() const { return w; }
@@ -95,2 +95,5 @@ class TranInfoList : public QList<TranInfo>
{
+ public:
+ TranInfo *findMostRecentByDesc( const QString &desc );
+
protected:
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
@@ -31,4 +31,6 @@
#include "cfg.h"
+#include "checkbook.h"
#include <qpe/datebookmonth.h>
+#include <qpe/resource.h>
@@ -43,4 +45,4 @@
-Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info,
- Cfg *pCfg )
+Transaction::Transaction( QWidget *parent, bool bNew, const QString &acctname,
+ TranInfo *info, Cfg *pCfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
@@ -51,2 +53,3 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
+ _bNew=bNew;
tran = info;
@@ -116,5 +119,8 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
layout->addWidget( label, 2, 0 );
- descEdit = new QLineEdit( container );
- QWhatsThis::add( descEdit, tr( "Enter description of transaction here." ) );
- layout->addMultiCellWidget( descEdit, 2, 2, 1, 3 );
+ _cbDesc=new QComboBox( true, container );
+ _cbDesc->insertStringList( _pCfg->getPayees() );
+ QWhatsThis::add( _cbDesc, tr( "Enter description of transaction here." ) );
+ layout->addMultiCellWidget( _cbDesc, 2, 2, 1, 3 );
+ connect( _cbDesc, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) );
+
@@ -136,2 +142,3 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
+
// Amount
@@ -160,2 +167,18 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
+ // init date
+ initFromInfo( info );
+
+ // not new handlers
+ connect( withBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
+ connect( depBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
+ connect( catList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
+ connect( typeList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
+ connect( amtEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
+ connect( feeEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
+ connect( noteEdit, SIGNAL(textChanged()), this, SLOT( slotNotNew() ) );
+}
+
+// --- initFromInfo -----------------------------------------------------------
+void Transaction::initFromInfo(TranInfo *info, bool bPopulateOld)
+{
// Populate current values if provided
@@ -173,2 +196,4 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
}
+
+ if( !bPopulateOld ) {
QDate dt = info->date();
@@ -177,5 +202,17 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
numEdit->setText( info->number() );
- descEdit->setText( info->desc() );
+ }
QString temptext = info->category();
- int i = catList->count();
+
+ // set description field
+ int i;
+ for(i=_cbDesc->count()-1; i>=0; i--) {
+ if( _cbDesc->text(i)==info->desc() ) {
+ _cbDesc->setCurrentItem(i);
+ break;
+ }
+ }
+ if( i<=0 )
+ _cbDesc->setEditText( info->desc() );
+
+ i = catList->count();
while ( i > 0 )
@@ -210,2 +247,4 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
+
+// --- ~Transaction -----------------------------------------------------------
Transaction::~Transaction()
@@ -214,5 +253,6 @@ Transaction::~Transaction()
+// --- accept -----------------------------------------------------------------
void Transaction::accept()
{
- tran->setDesc( descEdit->text() );
+ tran->setDesc( _cbDesc->currentText() );
tran->setDate( datePicker->selectedDate() );
@@ -264,2 +304,3 @@ void Transaction::slotDepositClicked()
+// --- slotDateChanged --------------------------------------------------------
void Transaction::slotDateChanged( int y, int m, int d )
@@ -270 +311,28 @@ void Transaction::slotDateChanged( int y, int m, int d )
}
+
+
+
+// --- slotActivated ----------------------------------------------------------
+// Search for the most recent transaction with this description/payee and
+// fill amount etc here, as long the new flag is set
+void Transaction::slotActivated(const QString &arg )
+{
+ if( !_bNew ) return;
+ TranInfoList *pTl=((Checkbook *)parentWidget())->getTranList();
+ if( pTl ) {
+ TranInfo *pTi=pTl->findMostRecentByDesc( arg );
+ if( pTi ) {
+ initFromInfo( pTi, true );
+ amtEdit->setFocus();
+ amtEdit->setSelection(0, amtEdit->text().length() );
+ amtEdit->setCursorPosition(0);
+ }
+ }
+}
+
+// slotNotNew -----------------------------------------------------------------
+void Transaction::slotNotNew()
+{
+ qDebug("Not new");
+ _bNew=false;
+}
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
@@ -49,8 +49,10 @@ class Transaction : public QDialog
public:
- Transaction( QWidget *, const QString &, TranInfo *, Cfg *);
+ Transaction( QWidget *, bool, const QString &, TranInfo *, Cfg *);
~Transaction();
+ void initFromInfo(TranInfo *, bool=false);
+
private:
TranInfo *tran;
-
+ bool _bNew;
Cfg *_pCfg;
@@ -62,3 +64,3 @@ class Transaction : public QDialog
QLineEdit *numEdit;
- QLineEdit *descEdit;
+ QComboBox *_cbDesc;
QComboBox *catList;
@@ -76,2 +78,4 @@ class Transaction : public QDialog
void slotDateChanged( int, int, int );
+ void slotActivated(const QString & );
+ void slotNotNew();
};