summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-30 13:18:08 (UTC)
committer mickeyl <mickeyl>2003-10-30 13:18:08 (UTC)
commit37414f207b147af4cf6778b323a0aa23127901bd (patch) (side-by-side diff)
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
@@ -42,8 +42,9 @@ Cfg::Cfg()
_currencySymbol="$";
_showLocks=FALSE;
_showBalances=FALSE;
_pCategories=new CategoryList();
+ _bDirty=false;
}
// --- readStringList ---------------------------------------------------------
// Reads the entries for the control from a configuration file and returns
@@ -51,10 +52,8 @@ Cfg::Cfg()
// is assumed, that the group is already set. Key is used to enumerate the
// entries.
void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
{
-qDebug( "%s", sKey );
-
QString sEntry;
int iCount;
// read count of elements
@@ -85,8 +84,9 @@ void Cfg::readConfig(Config &config)
_showBalances = config.readBoolEntry( "ShowBalances", FALSE );
_openLastBook = config.readBoolEntry( "OpenLastBook", FALSE );
_sLastBook = config.readEntry("LastBook", "");
_showLastTab = config.readBoolEntry( "ShowLastTab", FALSE );
+ _bSavePayees = config.readBoolEntry( "SavePayees", FALSE );
// Account types
readStringList(config, "AccType", _AccountTypes);
if( _AccountTypes.isEmpty() ) {
@@ -99,8 +99,11 @@ void Cfg::readConfig(Config &config)
writeStringList(config, "AccType", _AccountTypes);
config.write();
}
+ // Payees
+ readStringList(config, "Payee", _Payees);
+
// Read Categories
QStringList lst;
readStringList(config, "Category", lst);
if( lst.isEmpty() ) {
@@ -130,8 +133,11 @@ void Cfg::readConfig(Config &config)
config.write();
} else {
setCategories(lst);
}
+
+ // not dirty
+ _bDirty=false;
}
// --- writeStringList --------------------------------------------------------
@@ -165,18 +171,23 @@ void Cfg::writeConfig(Config &config)
config.writeEntry( "ShowBalances", _showBalances );
config.writeEntry( "OpenLastBook", _openLastBook );
config.writeEntry( "LastBook", _sLastBook );
config.writeEntry( "ShowLastTab", _showLastTab );
+ config.writeEntry( "SavePayees", _bSavePayees );
// write account types
writeStringList(config, "AccType", _AccountTypes);
+ // write payees
+ writeStringList(config, "Payee", _Payees);
+
// write categories
QStringList lst=getCategories();
writeStringList(config, "Category", lst );
// commit write
config.write();
+ _bDirty=false;
}
// --- getCategories ----------------------------------------------------------
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
@@ -76,8 +76,13 @@ class Cfg
void setCurrencySymbol(QString n) {_currencySymbol= n; }
void setCurrencySymbol(const char *n) { _currencySymbol=n; }
QStringList &getAccountTypes() { return(_AccountTypes); }
+ // --- Payees
+ QStringList &getPayees() { return(_Payees); }
+ bool getSavePayees() { return(_bSavePayees); }
+ void setSavePayees(bool bSave) { _bSavePayees=bSave; }
+
// --- Categories
QStringList getCategories();
void setCategories(QStringList &lst);
CategoryList *getCategoryList() { return(_pCategories); }
@@ -97,24 +102,31 @@ class Cfg
// --- writes data to config file
void writeConfig(Config &cfg);
+ // --- dirty flag
+ bool isDirty() { return(_bDirty); }
+ void setDirty(bool bDirty) { _bDirty=bDirty; }
+
+ protected:
// --- reads list from config file
static void readStringList(Config &cfg, const char *sKey, QStringList &lst);
// --- writes list in configuration file
static void writeStringList(Config &cfg, const char *sKey, QStringList &lst);
-
-
private:
QString _currencySymbol;
bool _showLocks;
bool _showBalances;
bool _openLastBook;
bool _showLastTab;
+ bool _bDirty;
+ bool _bSavePayees;
QString _sLastBook;
QStringList _AccountTypes;
CategoryList *_pCategories;
+ QStringList _Payees;
+
};
#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
@@ -48,15 +48,17 @@
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#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_ID 0
+#define COL_SORTDATE 1
+#define COL_NUM 2
+#define COL_DATE 3
+#define COL_DESC 4
+#define COL_AMOUNT 5
+#define COL_BAL 6
// --- Checkbook --------------------------------------------------------------
Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
@@ -223,8 +225,11 @@ QWidget *Checkbook::initTransactions()
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." ) );
tranTable->addColumn( tr( "Id" ) );
tranTable->setColumnWidthMode( COL_ID, QListView::Manual );
tranTable->setColumnWidth( COL_ID, 0);
+ tranTable->addColumn( tr( "SortDate" ) );
+ tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
+ tranTable->setColumnWidth( COL_SORTDATE, 0);
tranTable->addColumn( tr( "Num" ) );
tranTable->addColumn( tr( "Date" ) );
//tranTable->addColumn( tr( "Cleared" ) );
tranTable->addColumn( tr( "Description" ) );
@@ -236,9 +241,11 @@ QWidget *Checkbook::initTransactions()
tranTable->setSorting( -1 );
layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
- this, SLOT( slotEditTran() ) );
+ this, SLOT( slotMenuTran(QListViewItem *, const QPoint &) ) );
+ connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
+ this, SLOT( slotEditTran() ) );
_sortCol=COL_ID;
// Buttons
QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
@@ -335,9 +342,9 @@ void Checkbook::loadCheckbook()
{
amount *= -1;
}
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 );
}
// set sort order
bool bOk=false;
@@ -357,8 +364,9 @@ void Checkbook::loadCheckbook()
// calc running balance
adjustBalance();
}
+
// --- adjustBalance ----------------------------------------------------------
void Checkbook::adjustBalance()
{
// update running balance in register
@@ -395,8 +403,9 @@ void Checkbook::accept()
QDialog::accept();
}
+// --- slotPasswordClicked ----------------------------------------------------
void Checkbook::slotPasswordClicked()
{
if ( info->password().isNull() && passwordCB->isChecked() )
{
@@ -463,15 +472,16 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
adjustBalance();
}
+// --- slotNewTran ------------------------------------------------------------
void Checkbook::slotNewTran()
{
TranInfo *traninfo = new TranInfo( info->getNextNumber() );
if( !_dLastNew.isNull() )
traninfo->setDate(_dLastNew);
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, true, info->name(),
traninfo,
_pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
@@ -483,39 +493,50 @@ void Checkbook::slotNewTran()
float amount;
QString stramount;
amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
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 );
resort();
adjustBalance();
// save last date
_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);
+ }
}
else
{
delete traninfo;
}
}
+
+// --- slotEditTran -----------------------------------------------------------
void Checkbook::slotEditTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
return;
-
+
TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
- Transaction *currtran = new Transaction( this, info->name(),
+ Transaction *currtran = new Transaction( this, false, info->name(),
traninfo,
_pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
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() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
@@ -526,13 +547,49 @@ void Checkbook::slotEditTran()
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
curritem->setText( COL_AMOUNT, stramount );
resort();
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);
+ }
}
delete currtran;
}
+// --- 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()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
@@ -590,9 +647,9 @@ void Checkbook::drawBalanceChart()
}
balance += amount;
if ( i == 1 || i == count / 2 || i == count )
{
- label = tran->datestr();
+ label = tran->datestr(true);
}
else
{
label = "";
@@ -665,8 +722,9 @@ void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int
QListViewItem::paintCell(p, _cg, column, width, align);
}
+// --- CBListItem::isAltBackground --------------------------------------------
bool CBListItem::isAltBackground()
{
QListView *lv = static_cast<QListView *>( listView() );
if ( lv )
@@ -722,9 +780,10 @@ void Checkbook::slotSortChanged( const QString &selc )
_sortCol=COL_ID;
} else if( selc==tr("Number") ) {
_sortCol=COL_NUM;
} else if( selc==tr("Date") ) {
- _sortCol=COL_DATE;
+ _sortCol=COL_SORTDATE;
}
info->setSortOrder( selc );
resort();
}
+
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
@@ -47,8 +47,9 @@ class QMultiLineEdit;
class QString;
class TranInfo;
class TranInfoList;
class Cfg;
+class QMouseEvent;
// --- Checkbook --------------------------------------------------------------
class Checkbook : public QDialog
@@ -61,8 +62,11 @@ class Checkbook : public QDialog
// resort
void resort();
+ // members
+ TranInfoList *getTranList() { return(tranList); }
+
private:
CBInfo *info;
TranInfoList *tranList;
Cfg *_pCfg;
@@ -108,13 +112,15 @@ class Checkbook : public QDialog
void slotNameChanged( const QString & );
void slotStartingBalanceChanged( const QString & );
void slotNewTran();
void slotEditTran();
+ void slotMenuTran(QListViewItem *, const QPoint &);
void slotDeleteTran();
void slotDrawGraph();
void slotSortChanged( const QString & );
};
+
// --- CBListItem -------------------------------------------------------------
class CBListItem : public QListViewItem
{
//Q_OBJECT
@@ -128,9 +134,9 @@ class CBListItem : public QListViewItem
// --- members
TranInfo *getTranInfo() { return(_pTran); }
- private:
+ private:
TranInfo *_pTran;
QListView *owner;
bool m_known;
bool m_odd;
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
@@ -75,8 +75,14 @@ Configuration::Configuration( QWidget *parent, Cfg &cfg )
_listEditCategories->addColumnDef( d );
QStringList lst=cfg.getCategories();
_listEditCategories->addData( lst );
_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") );
}
Configuration::~Configuration()
{
@@ -137,8 +143,14 @@ QWidget *Configuration::initSettings(Cfg &cfg)
lastTabCB->setMaximumHeight(fh+5);
lastTabCB->setChecked( cfg.isShowLastTab() );
layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 );
+ 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);
}
// --- saveConfig -------------------------------------------------------------
@@ -149,13 +161,17 @@ void Configuration::saveConfig(Cfg &cfg)
cfg.setShowLocks( lockCB->isChecked() );
cfg.setShowBalances( balCB->isChecked() );
cfg.setOpenLastBook( openLastBookCB->isChecked() );
cfg.setShowLastTab( lastTabCB->isChecked() );
+ cfg.setSavePayees( savePayees->isChecked() );
// Typelist
_listEditTypes->storeInList( cfg.getAccountTypes() );
// Category list
QStringList lst;
_listEditCategories->storeInList( lst );
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
@@ -51,11 +51,13 @@ class Configuration : public QDialog
QCheckBox *lockCB;
QCheckBox *balCB;
QCheckBox *openLastBookCB;
QCheckBox *lastTabCB;
+ QCheckBox *savePayees;
QTabWidget *_mainWidget;
ListEdit *_listEditTypes;
ListEdit *_listEditCategories;
+ ListEdit *_listEditPayees;
// saves settings in config struct
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
@@ -115,8 +115,12 @@ void ListEdit::slotAdd()
// display col 0 of new value
QPoint pnt;
slotClick(_currentItem, pnt, 0);
_typeTable->setSelected( _currentItem, true );
+
+ // make it selected
+ _typeEdit->setCursorPosition(0);
+ _typeEdit->setSelection(0, _typeEdit->text().length() );
}
// --- slotDel -------------------------------------------------------------
void ListEdit::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
@@ -57,9 +57,8 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
lockIcon = Resource::loadPixmap( "locked" );
// Load configuration options
Config config( "checkbook" );
-qDebug( "Reading config" );
_cfg.readConfig( config );
// Build menu and tool bars
@@ -313,8 +312,14 @@ void MainWindow::openBook(QListViewItem *curritem)
QString tempstr;
tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
curritem->setText( posName + 1, tempstr );
}
+
+ // write config, if needed
+ if( _cfg.isDirty() ) {
+ Config config("checkbook");
+ _cfg.writeConfig( config );
+ }
}
delete currcb;
}
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
@@ -28,8 +28,9 @@
#include "traninfo.h"
#include <qpe/config.h>
+#include <qpe/timestring.h>
QString tempstr;
TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdrawal,
@@ -123,16 +124,19 @@ 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() );
- return( tempstr );
+ if( bDisplayDate ) {
+ tempstr=TimeString::numberDateString( td );
+ } else {
+ tempstr.sprintf( "%04d-%02d-%02d", td.year() ,td.month(), td.day() );
+ }
+ return(tempstr);
}
+
// --- getIdStr ---------------------------------------------------------------
const QString &TranInfo::getIdStr()
{
tempstr.sprintf("%04d", i);
@@ -209,4 +213,15 @@ QString TranInfo::toString()
fee()
);
return(ret);
}
+
+
+// --- 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
@@ -48,9 +48,9 @@ class TranInfo
const QString &getIdStr();
const QString &desc() const { return d; }
const QDate &date() const { return td; }
- const QString &datestr();
+ const QString &datestr(bool = false);
bool withdrawal() const { return w; }
const QString &type() const { return t; }
const QString &category() const { return c; }
float amount() const { return a; }
@@ -92,8 +92,11 @@ class TranInfo
};
class TranInfoList : public QList<TranInfo>
{
+ public:
+ TranInfo *findMostRecentByDesc( const QString &desc );
+
protected:
int compareItems( QCollection::Item, QCollection::Item );
};
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
@@ -28,10 +28,12 @@
#include "transaction.h"
#include "traninfo.h"
#include "cfg.h"
+#include "checkbook.h"
#include <qpe/datebookmonth.h>
+#include <qpe/resource.h>
#include <qbuttongroup.h>
#include <qcombobox.h>
#include <qlabel.h>
@@ -40,16 +42,17 @@
#include <qmultilineedit.h>
#include <qradiobutton.h>
#include <qwhatsthis.h>
-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 )
{
QString tempstr = tr( "Transaction for " );
tempstr.append( acctname );
setCaption( tempstr );
+ _bNew=bNew;
tran = info;
_pCfg=pCfg;
QVBoxLayout *vb = new QVBoxLayout( this );
@@ -113,11 +116,14 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
// Description
label = new QLabel( tr( "Description:" ), container );
QWhatsThis::add( label, tr( "Enter description of transaction here." ) );
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 &) ) );
+
// Category
label = new QLabel( tr( "Category:" ), container );
QWhatsThis::add( label, tr( "Select transaction category here." ) );
@@ -133,8 +139,9 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
typeList = new QComboBox( container );
QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
layout->addMultiCellWidget( typeList, 4, 4, 1, 3 );
+
// Amount
label = new QLabel( tr( "Amount:" ), container );
QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
layout->addWidget( label, 5, 0 );
@@ -157,8 +164,24 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
noteEdit = new QMultiLineEdit( container );
QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) );
layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 );
+ // 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
if ( info )
{
if ( info->withdrawal() )
@@ -170,15 +193,29 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
{
depBtn->setChecked( TRUE );
slotDepositClicked();
}
- QDate dt = info->date();
- slotDateChanged( dt.year(), dt.month(), dt.day() );
- datePicker->setDate( dt );
- numEdit->setText( info->number() );
- descEdit->setText( info->desc() );
+
+ if( !bPopulateOld ) {
+ QDate dt = info->date();
+ slotDateChanged( dt.year(), dt.month(), dt.day() );
+ datePicker->setDate( dt );
+ numEdit->setText( info->number() );
+ }
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 )
{
i--;
catList->setCurrentItem( i );
@@ -207,15 +244,18 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
withBtn->setChecked( TRUE );
}
}
+
+// --- ~Transaction -----------------------------------------------------------
Transaction::~Transaction()
{
}
+// --- accept -----------------------------------------------------------------
void Transaction::accept()
{
- tran->setDesc( descEdit->text() );
+ tran->setDesc( _cbDesc->currentText() );
tran->setDate( datePicker->selectedDate() );
tran->setWithdrawal( withBtn->isChecked() );
tran->setType( typeList->currentText() );
tran->setCategory( catList->currentText() );
@@ -261,10 +301,38 @@ void Transaction::slotDepositClicked()
typeList->insertItem( tr( "Transfer" ) );
typeList->insertItem( tr( "Cash" ) );
}
+// --- slotDateChanged --------------------------------------------------------
void Transaction::slotDateChanged( int y, int m, int d )
{
QDate date;
date.setYMD( y, m, d );
dateBtn->setText( TimeString::shortDate( date ) );
}
+
+
+
+// --- 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
@@ -46,22 +46,24 @@ class Transaction : public QDialog
{
Q_OBJECT
public:
- Transaction( QWidget *, const QString &, TranInfo *, Cfg *);
+ Transaction( QWidget *, bool, const QString &, TranInfo *, Cfg *);
~Transaction();
- private:
- TranInfo *tran;
+ void initFromInfo(TranInfo *, bool=false);
+ private:
+ TranInfo *tran;
+ bool _bNew;
Cfg *_pCfg;
QRadioButton *withBtn;
QRadioButton *depBtn;
QPushButton *dateBtn;
DateBookMonth *datePicker;
QLineEdit *numEdit;
- QLineEdit *descEdit;
+ QComboBox *_cbDesc;
QComboBox *catList;
QComboBox *typeList;
QLineEdit *amtEdit;
QLineEdit *feeEdit;
@@ -73,7 +75,9 @@ class Transaction : public QDialog
private slots:
void slotWithdrawalClicked();
void slotDepositClicked();
void slotDateChanged( int, int, int );
+ void slotActivated(const QString & );
+ void slotNotNew();
};
#endif