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
@@ -14,197 +14,208 @@
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qwidget.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include "cfg.h"
// --- Cfg --------------------------------------------------------------------
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
// them in a StringList. Later this list can be used to create the control. It
// 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
sEntry.sprintf("%s_Count", sKey);
iCount=cfg.readNumEntry(sEntry, 0);
// read entries
for(int i=1; i<=iCount; i++) {
sEntry.sprintf("%s%d", sKey, i);
QString sType=cfg.readEntry(sEntry);
if( sType!=NULL )
lst.append(sType);
}
}
// --- readConfig -------------------------------------------------------------
// Reads the member data from the given config file. It will also set the group
// "Config"
void Cfg::readConfig(Config &config)
{
// set group
config.setGroup( "Config" );
// read scalars
_currencySymbol = config.readEntry( "CurrencySymbol", "$" );
_showLocks = config.readBoolEntry( "ShowLocks", FALSE );
_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() ) {
_AccountTypes+= (const char *)QWidget::tr("Savings");
_AccountTypes+= (const char *)QWidget::tr("Checking");
_AccountTypes+= (const char *)QWidget::tr("CD");
_AccountTypes+= (const char *)QWidget::tr("Money market");
_AccountTypes+= (const char *)QWidget::tr("Mutual fund");
_AccountTypes+= (const char *)QWidget::tr("Other");
writeStringList(config, "AccType", _AccountTypes);
config.write();
}
+ // Payees
+ readStringList(config, "Payee", _Payees);
+
// Read Categories
QStringList lst;
readStringList(config, "Category", lst);
if( lst.isEmpty() ) {
QString type=QWidget::tr("Expense");
lst += QWidget::tr( "Automobile" )+";"+type;
lst += QWidget::tr( "Bills" )+";"+type;
lst += QWidget::tr( "CDs" )+";"+type;
lst += QWidget::tr( "Clothing" )+";"+type;
lst += QWidget::tr( "Computer" )+";"+type;
lst += QWidget::tr( "DVDs" )+";"+type;
lst += QWidget::tr( "Electronics" )+";"+type;
lst += QWidget::tr( "Entertainment" )+";"+type;
lst += QWidget::tr( "Food" )+";"+type;
lst += QWidget::tr( "Gasoline" )+";"+type;
lst += QWidget::tr( "Misc" )+";"+type;
lst += QWidget::tr( "Movies" )+";"+type;
lst += QWidget::tr( "Rent" )+";"+type;
lst += QWidget::tr( "Travel" )+";"+type;
type=QWidget::tr( "Income" );
lst += QWidget::tr( "Work" )+";"+type;
lst += QWidget::tr( "Family Member" )+";"+type;
lst += QWidget::tr( "Misc. Credit" )+";"+type;
setCategories(lst);
writeStringList(config, "Category", lst);
config.write();
} else {
setCategories(lst);
}
+
+ // not dirty
+ _bDirty=false;
}
// --- writeStringList --------------------------------------------------------
// Writes the entries in the control in a configuration file. It is assumed,
// that the group is already set. Key is used to enumerate the entries
void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst)
{
QString sEntry;
int iCount=0;
QStringList::Iterator itr;
for(itr=lst.begin(); itr!=lst.end(); itr++) {
sEntry.sprintf("%s%d", sKey, ++iCount);
cfg.writeEntry(sEntry, *itr );
}
sEntry.sprintf("%s_Count", sKey);
cfg.writeEntry(sEntry, iCount);
}
// --- writeConfig -----------------------------------------------------------
// Writes all config data back to the config file. The group will be set to
// "Config" and the write be commited
void Cfg::writeConfig(Config &config)
{
// set the group
config.setGroup( "Config" );
// write scalars
config.writeEntry( "CurrencySymbol", _currencySymbol );
config.writeEntry( "ShowLocks", _showLocks );
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 ----------------------------------------------------------
QStringList Cfg::getCategories()
{
QStringList ret;
for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) {
QString sEntry;
sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) );
ret.append(sEntry);
}
return(ret);
}
// --- setCategories ----------------------------------------------------------
void Cfg::setCategories(QStringList &lst)
{
_pCategories->clear();
QStringList::Iterator itr;
for(itr=lst.begin(); itr!=lst.end(); itr++) {
QStringList split=QStringList::split(";", *itr, true);
if( split.count()<2 ) continue;
bool bIncome= (split[1]==QWidget::tr("Income"));
_pCategories->append( new Category(split[0], bIncome) );
}
}
// --- CategoryList ------------------------------------------------------------
CategoryList::CategoryList() : QList<Category>()
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
@@ -48,73 +48,85 @@ class Category
void setIncome(bool bIncome) { _bIncome=bIncome; }
private:
QString _sName;
bool _bIncome;
};
class CategoryList : public QList<Category>
{
public:
// --- Constructor
CategoryList();
};
// --- Cfg --------------------------------------------------------------------
class Cfg
{
public:
// --- Constructor
Cfg();
// --- members
bool getShowLocks() { return(_showLocks); }
void setShowLocks(bool n) { _showLocks=n; }
bool getShowBalances() { return(_showBalances); }
void setShowBalances(bool n) { _showBalances=n; }
QString &getCurrencySymbol() { return(_currencySymbol); }
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); }
// --- last book
void setOpenLastBook(bool openLastBook) { _openLastBook=openLastBook; }
bool isOpenLastBook() { return(_openLastBook); }
void setLastBook(const QString &lastBook) { _sLastBook=lastBook; }
QString &getLastBook() { return(_sLastBook); }
// --- last tab
void setShowLastTab(bool showLastTab) { _showLastTab=showLastTab; }
bool isShowLastTab() { return(_showLastTab); }
// --- reads data from config file
void readConfig(Config &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
@@ -20,71 +20,73 @@
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "checkbook.h"
#include "cbinfo.h"
#include "transaction.h"
#include "traninfo.h"
#include "graph.h"
#include "graphinfo.h"
#include "password.h"
#include "mainwindow.h"
#include "cfg.h"
#include <opie/otabwidget.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#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 )
{
info = i;
_pCfg=cfg;
// Title bar
if ( info->name() != "" )
{
QString tempstr = info->name();
tempstr.append( " - " );
tempstr.append( tr( "Checkbook" ) );
setCaption( tempstr );
}
else
{
setCaption( tr( "New checkbook" ) );
}
// Setup layout to make everything pretty
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 2 );
layout->setSpacing( 4 );
// Setup tabs for all info
mainWidget = new OTabWidget( this );
layout->addWidget( mainWidget );
mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) );
mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) );
@@ -195,78 +197,83 @@ QWidget *Checkbook::initInfo()
}
// --- initTransactions -------------------------------------------------------
QWidget *Checkbook::initTransactions()
{
QWidget *control = new QWidget( mainWidget, tr("Transactions") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
// Sort selector
QLabel *label = new QLabel( tr( "Sort by:" ), control );
QWhatsThis::add( label, tr( "Select checkbook sorting here." ) );
layout->addMultiCellWidget( label, 0, 0, 0, 1 );
_cbSortType=new QComboBox( control );
_cbSortType->insertItem( tr("Entry Order") );
_cbSortType->insertItem( tr("Date") );
_cbSortType->insertItem( tr("Number") );
layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 );
connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) );
// Table
tranTable = new QListView( control );
QFont fnt(QPEApplication::font());
fnt.setPointSize( fnt.pointSize()-1 );
tranTable->setFont( fnt );
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" ) );
int column = tranTable->addColumn( tr( "Amount" ) );
tranTable->setColumnAlignment( column, Qt::AlignRight );
column=tranTable->addColumn( tr("Balance") );
tranTable->setColumnAlignment( column, Qt::AlignRight );
tranTable->setAllColumnsShowFocus( TRUE );
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 );
QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
layout->addWidget( btn, 2, 0 );
btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control );
QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) );
layout->addWidget( btn, 2, 1 );
btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control );
QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) );
layout->addWidget( btn, 2, 2 );
return( control );
}
// --- initCharts -------------------------------------------------------------
QWidget *Checkbook::initCharts()
{
graphInfo = 0x0;
QWidget *control = new QWidget( mainWidget, tr("Charts") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
@@ -307,124 +314,126 @@ void Checkbook::loadCheckbook()
int i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
if( i<=0 ) {
typeList->insertItem( temptext, 0 );
typeList->setCurrentItem(0);
}
bankEdit->setText( info->bank() );
acctNumEdit->setText( info->account() );
pinNumEdit->setText( info->pin() );
temptext.setNum( info->startingBalance(), 'f', 2 );
balanceEdit->setText( temptext );
notesEdit->setText( info->notes() );
// Load transactions
float amount;
QString stramount;
for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
amount = tran->amount();
if ( tran->withdrawal() )
{
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;
for(int i=0; i<_cbSortType->count(); i++) {
if( _cbSortType->text(i)==info->getSortOrder() ) {
_cbSortType->setCurrentItem(i);
slotSortChanged( info->getSortOrder() );
bOk=true;
break;
}
}
if( !bOk ) {
_cbSortType->setCurrentItem(0);
slotSortChanged( _cbSortType->currentText() );
}
// calc running balance
adjustBalance();
}
+
// --- adjustBalance ----------------------------------------------------------
void Checkbook::adjustBalance()
{
// update running balance in register
QString sRunning;
float bal=info->startingBalance();
for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) {
TranInfo *tran=item->getTranInfo();
bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee();
sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal );
item->setText( COL_BAL, sRunning);
}
}
// --- resort -----------------------------------------------------------------
void Checkbook::resort()
{
tranTable->setSorting(_sortCol);
tranTable->sort();
tranTable->setSorting(-1);
}
// --- accept -----------------------------------------------------------------
void Checkbook::accept()
{
info->setName( nameEdit->text() );
info->setType( typeList->currentText() );
info->setBank( bankEdit->text() );
info->setAccount( acctNumEdit->text() );
info->setPin( pinNumEdit->text() );
bool ok;
info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
info->setNotes( notesEdit->text() );
QDialog::accept();
}
+// --- slotPasswordClicked ----------------------------------------------------
void Checkbook::slotPasswordClicked()
{
if ( info->password().isNull() && passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
if ( pw->exec() != QDialog::Accepted )
{
passwordCB->setChecked( FALSE );
delete pw;
return;
}
info->setPassword( pw->password );
delete pw;
pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) );
if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
{
passwordCB->setChecked( FALSE );
info->setPassword( QString::null );
}
delete pw;
}
else if ( !info->password().isNull() && !passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ),
tr( "Please enter your password to confirm removal of password protection:" ) );
if ( pw->exec() == QDialog::Accepted && pw->password == info->password() )
{
info->setPassword( QString::null );
delete pw;
return;
@@ -435,192 +444,240 @@ void Checkbook::slotPasswordClicked()
}
delete pw;
}
}
void Checkbook::slotNameChanged( const QString &newname )
{
info->setName( newname );
// TODO - need filedir
// QString namestr = filedir;
// namestr.append( newname );
// namestr.append( ".qcb" );
// info->setFilename( namestr );
QString namestr = newname;
namestr.append( " - " );
namestr.append( tr( "Checkbook" ) );
setCaption( namestr );
}
// ---slotStartingBalanceChanged ----------------------------------------------
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
bool ok;
info->setStartingBalance( newbalance.toFloat( &ok ) );
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 )
{
// Add to transaction list
info->addTransaction( traninfo );
// Add to transaction table
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() )
{
amount *= -1;
}
QString stramount;
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 )
return;
TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
info->removeTransaction( traninfo );
delete curritem;
adjustBalance();
}
}
void Checkbook::slotDrawGraph()
{
if ( graphInfo )
{
delete graphInfo;
}
switch ( graphList->currentItem() )
{
case 0 : drawBalanceChart();
break;
case 1 : drawCategoryChart( TRUE );
break;
case 2 : drawCategoryChart( FALSE );
break;
};
graphWidget->setGraphInfo( graphInfo );
graphWidget->drawGraph( TRUE );
}
void Checkbook::drawBalanceChart()
{
DataPointList *list = new DataPointList();
float balance = info->startingBalance();
float amount;
QString label;
int i = 0;
int count = tranList->count();
for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
i++;
balance -= tran->fee();
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
balance += amount;
if ( i == 1 || i == count / 2 || i == count )
{
- label = tran->datestr();
+ label = tran->datestr(true);
}
else
{
label = "";
}
list->append( new DataPointInfo( label, balance ) );
}
graphInfo = new GraphInfo( GraphInfo::BarChart, list );
}
void Checkbook::drawCategoryChart( bool withdrawals )
{
DataPointList *list = new DataPointList();
TranInfo *tran = tranList->first();
if ( tran && tran->withdrawal() == withdrawals )
{
list->append( new DataPointInfo( tran->category(), tran->amount() ) );
}
tran = tranList->next();
DataPointInfo *cat;
for ( ; tran; tran = tranList->next() )
{
if ( tran->withdrawal() == withdrawals )
{
// Find category in list
for ( cat = list->first(); cat; cat = list->next() )
{
if ( cat->label() == tran->category() )
{
@@ -637,94 +694,96 @@ void Checkbook::drawCategoryChart( bool withdrawals )
}
}
}
graphInfo = new GraphInfo( GraphInfo::PieChart, list );
}
CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2,
QString label3, QString label4, QString label5, QString label6, QString label7,
QString label8 )
: QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
{
_pTran=pTran;
m_known = FALSE;
owner = parent;
}
void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if ( pm && !pm->isNull() )
{
_cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAltBackground() )
_cg.setColor(QColorGroup::Base, cg.background() );
QListViewItem::paintCell(p, _cg, column, width, align);
}
+// --- CBListItem::isAltBackground --------------------------------------------
bool CBListItem::isAltBackground()
{
QListView *lv = static_cast<QListView *>( listView() );
if ( lv )
{
CBListItem *above = 0;
above = (CBListItem *)( itemAbove() );
m_known = above ? above->m_known : true;
if ( m_known )
{
m_odd = above ? !above->m_odd : false;
}
else
{
CBListItem *item;
bool previous = true;
if ( parent() )
{
item = (CBListItem *)( parent() );
if ( item )
previous = item->m_odd;
item = (CBListItem *)( parent()->firstChild() );
}
else
{
item = (CBListItem *)( lv->firstChild() );
}
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = (CBListItem *)( item->nextSibling() );
}
}
return m_odd;
}
return false;
}
// --- slotTab ----------------------------------------------------------------
void Checkbook::slotTab(QWidget *tab)
{
if( !tab || !info ) return;
info->setLastTab( tab->name() );
}
// --- slotSortChanged ---------------------------------------------------------
void Checkbook::slotSortChanged( const QString &selc )
{
if( selc==tr("Entry Order") ) {
_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
@@ -19,124 +19,130 @@
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef CHECKBOOK_H
#define CHECKBOOK_H
#include <qdatetime.h>
#include <qdialog.h>
#include <qlistview.h>
class OTabWidget;
class CBInfo;
class Graph;
class GraphInfo;
class QCheckBox;
class QComboBox;
class QLabel;
class QLineEdit;
class QListView;
class QMultiLineEdit;
class QString;
class TranInfo;
class TranInfoList;
class Cfg;
+class QMouseEvent;
// --- Checkbook --------------------------------------------------------------
class Checkbook : public QDialog
{
Q_OBJECT
public:
Checkbook( QWidget *, CBInfo *, Cfg *cfg );
~Checkbook();
// resort
void resort();
+ // members
+ TranInfoList *getTranList() { return(tranList); }
+
private:
CBInfo *info;
TranInfoList *tranList;
Cfg *_pCfg;
OTabWidget *mainWidget;
void loadCheckbook();
void adjustBalance();
// Info tab
QWidget *initInfo();
QCheckBox *passwordCB;
QLineEdit *nameEdit;
QComboBox *typeList;
QLineEdit *bankEdit;
QLineEdit *acctNumEdit;
QLineEdit *pinNumEdit;
QLineEdit *balanceEdit;
QMultiLineEdit *notesEdit;
int _sortCol;
// Transactions tab
QWidget *initTransactions();
QListView *tranTable;
QComboBox *_cbSortType;
QDate _dLastNew;
// Charts tab
QWidget *initCharts();
GraphInfo *graphInfo;
QComboBox *graphList;
Graph *graphWidget;
void drawBalanceChart();
void drawCategoryChart( bool = TRUE );
protected slots:
void accept();
void slotTab(QWidget *tab);
private slots:
void slotPasswordClicked();
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
public:
CBListItem( TranInfo *, QListView *, QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null, QString = QString::null );
void paintCell( QPainter *, const QColorGroup &, int, int, int );
// --- members
TranInfo *getTranInfo() { return(_pTran); }
- private:
+ private:
TranInfo *_pTran;
QListView *owner;
bool m_known;
bool m_odd;
bool isAltBackground();
};
#endif
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
@@ -47,115 +47,131 @@ Configuration::Configuration( QWidget *parent, Cfg &cfg )
setCaption( tr( "Configure Checkbook" ) );
// Setup layout to make everything pretty
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 2 );
layout->setSpacing( 4 );
// Setup tabs for all info
_mainWidget = new QTabWidget( this );
layout->addWidget( _mainWidget );
// Settings tab
_mainWidget->addTab( initSettings(cfg), tr( "&Settings" ) );
// Account Types tab
ColumnDef *d;
_listEditTypes=new ListEdit(_mainWidget, "TYPES" );
d=new ColumnDef( tr("Type"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Account Type"));
_listEditTypes->addColumnDef( d );
_listEditTypes->addData( cfg.getAccountTypes() );
_mainWidget->addTab( _listEditTypes, tr( "&Account Types" ) );
// Categories tab
_listEditCategories=new ListEdit(_mainWidget, "CATEGORIES" );
_listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) );
d=new ColumnDef( tr("Type"), ColumnDef::typeList, tr("Expense") );
d->addColumnValue( tr("Expense") );
d->addColumnValue( tr("Income") );
_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()
{
}
// ---- initSettings ----------------------------------------------------------
QWidget *Configuration::initSettings(Cfg &cfg)
{
QWidget *control = new QWidget( _mainWidget );
QFontMetrics fm = fontMetrics();
int fh = fm.height();
QVBoxLayout *vb = new QVBoxLayout( control );
QScrollView *sv = new QScrollView( control );
vb->addWidget( sv, 0, 0 );
sv->setResizePolicy( QScrollView::AutoOneFit );
sv->setFrameStyle( QFrame::NoFrame );
QWidget *container = new QWidget( sv->viewport() );
sv->addChild( container );
QGridLayout *layout = new QGridLayout( container );
layout->setSpacing( 4 );
layout->setMargin( 4 );
QLabel *label = new QLabel( tr( "Enter currency symbol:" ), container );
QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) );
label->setMaximumHeight( fh + 3 );
layout->addWidget( label, 0, 0 );
symbolEdit = new QLineEdit( cfg.getCurrencySymbol(), container );
QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) );
symbolEdit->setMaximumHeight( fh + 5 );
symbolEdit->setFocus();
layout->addWidget( symbolEdit, 0, 1 );
lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), container );
QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) );
lockCB->setChecked( cfg.getShowLocks() );
layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 );
balCB = new QCheckBox( tr( "Show checkbook balances" ), container );
QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) );
balCB->setMaximumHeight( fh + 5 );
balCB->setChecked( cfg.getShowBalances() );
layout->addMultiCellWidget( balCB, 2, 2, 0, 1 );
openLastBookCB = new QCheckBox( tr("Open last checkbook" ), container );
QWhatsThis::add( openLastBookCB, tr("Click here to select whether the last open checkbook will be opened at startup.") );
openLastBookCB->setMaximumHeight(fh+5);
openLastBookCB->setChecked( cfg.isOpenLastBook() );
layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 );
lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container );
QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") );
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 -------------------------------------------------------------
void Configuration::saveConfig(Cfg &cfg)
{
// Settings
cfg.setCurrencySymbol( symbolEdit->text() );
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
@@ -23,45 +23,47 @@
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <qdialog.h>
#include "cfg.h"
class QCheckBox;
class QLineEdit;
class QString;
class QTabWidget;
class ListEdit;
class Configuration : public QDialog
{
Q_OBJECT
public:
// Constructor
Configuration( QWidget *, Cfg &cfg);
~Configuration();
QLineEdit *symbolEdit;
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);
protected:
// creates settings tap from configuration
QWidget *initSettings(Cfg &cfg);
};
#endif
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
@@ -87,64 +87,68 @@ ListEdit::ListEdit( QWidget *parent, const char *sName )
ListEdit::~ListEdit()
{
}
// --- slotEditTypeChanged ----------------------------------------------------
void ListEdit::slotEditChanged(const QString &str)
{
if( !_currentItem || _currentColumn<0 ) return;
_currentItem->setText(_currentColumn, str);
}
// --- slotAddType ------------------------------------------------------------
void ListEdit::slotAdd()
{
// construct new row
QString args[8];
ColumnDef *pCol=this->first();
int i=0;
while( pCol && i<8 ) {
args[i++]=pCol->getNewValue();
pCol=this->next();
}
_currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] );
// fix uniques
fixTypes();
// 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()
{
if( !_currentItem ) return;
delete _currentItem;
_currentItem=NULL;
_typeEdit->setText("");
_stack->raiseWidget(_typeEdit);
}
// --- fixTypes ----------------------------------------------------------------
// Makes sure all entries have a unique name and empty entries are replaced
// by a generic string. The first version performs the operation on a particular
// column, whereas the 2nd does it for all unique columns.
class ColMap {
public:
ColMap(QString sValue, QListViewItem *pEntry) {
_sValue=sValue;
_pEntry=pEntry;
}
QString &getValue() { return(_sValue); }
QListViewItem *getItem() { return(_pEntry); }
protected:
QString _sValue;
QListViewItem *_pEntry;
};
class ColList : public QList<QString>
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
@@ -29,65 +29,64 @@
#include "mainwindow.h"
#include "cbinfo.h"
#include "configuration.h"
#include "password.h"
#include "checkbook.h"
#include "listedit.h"
#include <qpe/config.h>
#include <qpe/global.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpemessagebox.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qaction.h>
#include <qcheckbox.h>
#include <qdir.h>
#include <qlineedit.h>
#include <qwhatsthis.h>
MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
: QMainWindow( parent, name, fl || WStyle_ContextHelp )
{
setCaption( tr( "Checkbook" ) );
cbDir = Global::applicationFileName( "checkbook", "" );
lockIcon = Resource::loadPixmap( "locked" );
// Load configuration options
Config config( "checkbook" );
-qDebug( "Reading config" );
_cfg.readConfig( config );
// Build menu and tool bars
setToolBarsMovable( FALSE );
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
QPEMenuBar *mb = new QPEMenuBar( bar );
mb->setMargin( 0 );
QPopupMenu *popup = new QPopupMenu( this );
bar = new QPEToolBar( this );
QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) );
connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) );
a->addTo( popup );
a->addTo( bar );
actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
0, this, 0 );
actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) );
connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) );
actionOpen->addTo( popup );
actionOpen->addTo( bar );
actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
0, this, 0 );
actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) );
connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) );
actionDelete->addTo( popup );
actionDelete->addTo( bar );
@@ -285,64 +284,70 @@ void MainWindow::openBook(QListViewItem *curritem)
cbList->sort();
}
_cfg.setLastBook( newname );
// Remove old file
QFile f( tempFilename );
if ( f.exists() )
f.remove();
// Get new filename
buildFilename( newname );
cb->setFilename( tempFilename );
}
cb->write();
// Update lock if changed
if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
{
if ( !cb->password().isNull() )
curritem->setPixmap( 0, lockIcon );
else
curritem->setPixmap( 0, nullIcon );
}
// Update balance if changed
if ( _cfg.getShowBalances() && cb->balance() != currbalance )
{
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;
}
// --- slotDelete -------------------------------------------------------------
void MainWindow::slotDelete()
{
QString currname = cbList->currentItem()->text( posName );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
{
buildFilename( currname );
QFile f( tempFilename );
if ( f.exists() )
{
f.remove();
}
delete cbList->currentItem();
}
}
// --- slotConfigure ----------------------------------------------------------
void MainWindow::slotConfigure()
{
Configuration *cfgdlg = new Configuration( this, _cfg );
cfgdlg->showMaximized();
if ( cfgdlg->exec() == QDialog::Accepted )
{
// read data from config dialog & save it
cfgdlg->saveConfig( _cfg );
writeConfig();
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
@@ -1,63 +1,64 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#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,
const QString &type, const QString &category, float amount,
float fee, const QString &number, const QString &notes, int next )
{
i = id;
d = desc;
td = date;
w = withdrawal;
t = type;
c = category;
a = amount;
f = fee;
cn = number;
n = notes;
_next=next;
}
TranInfo::TranInfo( Config config, int entry )
{
config.setGroup( QString::number( entry ) );
QString desc = config.readEntry( "Description", "Not Found" );
if ( desc != "Not Found" )
{
// ID
i = entry;
// Description
d = desc;
@@ -95,72 +96,75 @@ TranInfo::TranInfo( Config config, int entry )
else if( type == "1" )
t = "Automatic Payment";
else if( type == "2" )
t = "Transfer";
else if( type == "3" )
t = "Cash";
}
// Category
c = config.readEntry( "Category", "" );
// Transaction amount
QString stramount = config.readEntry( "Amount", "0.00" );
bool ok;
a = stramount.toFloat( &ok );
// Transaction fee
stramount = config.readEntry( "TransactionFee", "0.00" );
f = stramount.toFloat( &ok );
// Transaction number
cn = config.readEntry( "CheckNumber", "" );
// Notes
n = config.readEntry( "Comments", "" );
// next
_next = config.readNumEntry("Next", -1);
}
}
// --- 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);
return( tempstr );
}
// --- write ------------------------------------------------------------------
void TranInfo::write( Config *config )
{
config->setGroup( QString::number( id() ) );
config->writeEntry( "Description", d );
tempstr = QString::number( td.month() );
tempstr.append( '/' );
tempstr.append( QString::number( td.day() ) );
tempstr.append( '/' );
tempstr.append( QString::number( td.year() ) );
config->writeEntry( "Date", tempstr );
w ? tempstr = "true"
: tempstr = "false";
config->writeEntry( "Payment", tempstr );
if ( t == "Debit Charge" || t == "Written Check" )
tempstr = "0";
else if ( t == "Written Check" || t == "Automatic Payment" )
tempstr = "1";
else if ( t == "Transfer" )
tempstr = "2";
else if ( t == "Credit Card" || t == "Cash" )
@@ -181,32 +185,43 @@ void TranInfo::write( Config *config )
}
int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
{
QDate d1 = ((TranInfo *)item1)->date();
QDate d2 = ((TranInfo *)item2)->date();
int r = -1;
if ( d1 < d2 )
r = -1;
else if ( d1 == d2 )
r = 0;
else if ( d1 > d2 )
r = 1;
return( r );
}
// --- toString ---------------------------------------------------------------
QString TranInfo::toString()
{
QString ret;
ret.sprintf("(%4d) %10s %4s %-10s %5.2f %5.2f",
id(),
(const char *)datestr(),
(const char *)number(),
(const char *)desc(),
(withdrawal() ? -1 : 1) * amount(),
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
@@ -20,81 +20,84 @@
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef TRANINFO_H
#define TRANINFO_H
#include <qdatetime.h>
#include <qlist.h>
class Config;
class TranInfo
{
public:
TranInfo( int = 0, const QString & = 0x0, const QDate & = QDate::currentDate(),
bool = TRUE, const QString & = 0x0, const QString & = 0x0,
float = 0.0, float = 0.0,
const QString & = 0x0, const QString & = 0x0, int =-1 );
TranInfo( Config, int );
// getters
int id() const { return i; }
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; }
float fee() const { return f; }
const QString &number() const { return cn; }
const QString &notes() const { return n; }
int getNext() { return(_next); }
// setters
void setDesc( const QString &desc ) { d = desc; }
void setDate( const QDate &date ) { td = date; }
void setWithdrawal( bool withdrawal ) { w = withdrawal; }
void setType( const QString &type ) { t = type; }
void setCategory( const QString &cat ) { c = cat; }
void setAmount( float amount ) { a = amount; }
void setFee( float fee ) { f = fee; }
void setNumber( const QString &num ) { cn = num; }
void setNotes( const QString &notes ) { n = notes; }
void setNext(int next) { _next=next; }
// write
void write( Config * );
// toString
QString toString();
private:
int i;
QString d;
QDate td;
bool w;
QString t;
QString c;
float a;
float f;
QString cn;
QString n;
int _next;
};
class TranInfoList : public QList<TranInfo>
{
+ public:
+ TranInfo *findMostRecentByDesc( const QString &desc );
+
protected:
int compareItems( QCollection::Item, QCollection::Item );
};
#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
@@ -1,83 +1,86 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#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>
#include <qlayout.h>
#include <qlineedit.h>
#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 );
QScrollView *sv = new QScrollView( this );
vb->addWidget( sv, 0, 0 );
sv->setResizePolicy( QScrollView::AutoOneFit );
sv->setFrameStyle( QFrame::NoFrame );
QWidget *container = new QWidget( sv->viewport() );
sv->addChild( container );
QGridLayout *layout = new QGridLayout( container );
layout->setSpacing( 2 );
layout->setMargin( 4 );
// Withdrawal/Deposit
QButtonGroup *btngrp = new QButtonGroup( container );
btngrp->setColumnLayout(0, Qt::Vertical );
btngrp->layout()->setSpacing( 0 );
btngrp->layout()->setMargin( 0 );
btngrp->setMaximumWidth( 220 );
QGridLayout *layout2 = new QGridLayout( btngrp->layout() );
layout2->setSpacing( 2 );
layout2->setMargin( 2 );
withBtn = new QRadioButton( tr( "Withdrawal" ), btngrp );
QWhatsThis::add( withBtn, tr( "Select whether the transaction is a withdrawal or deposit here." ) );
layout2->addWidget( withBtn, 0, 0 );
connect( withBtn, SIGNAL( clicked() ), this, SLOT( slotWithdrawalClicked() ) );
depBtn = new QRadioButton( tr( "Deposit" ), btngrp );
QWhatsThis::add( depBtn, tr( "Select whether the transaction is a withdrawal or deposit here." ) );
@@ -85,186 +88,251 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
btngrp->setMaximumSize( 320, withBtn->height() );
connect( depBtn, SIGNAL( clicked() ), this, SLOT( slotDepositClicked() ) );
layout->addMultiCellWidget( btngrp, 0, 0, 0, 3 );
// Date
QLabel *label = new QLabel( tr( "Date:" ), container );
QWhatsThis::add( label, tr( "Select date of transaction here." ) );
layout->addWidget( label, 1, 0 );
dateBtn = new QPushButton( TimeString::shortDate( QDate::currentDate() ),
container );
QWhatsThis::add( dateBtn, tr( "Select date of transaction here." ) );
QPopupMenu *m1 = new QPopupMenu( container );
datePicker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( datePicker );
dateBtn->setPopup( m1 );
connect( datePicker, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( slotDateChanged( int, int, int ) ) );
layout->addWidget( dateBtn, 1, 1 );
// Check number
label = new QLabel( tr( "Number:" ), container );
QWhatsThis::add( label, tr( "Enter check number here." ) );
layout->addWidget( label, 1, 2 );
numEdit = new QLineEdit( container );
QWhatsThis::add( numEdit, tr( "Enter check number here." ) );
numEdit->setMaximumWidth( 40 );
layout->addWidget( numEdit, 1, 3 );
// 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." ) );
layout->addWidget( label, 3, 0 );
catList = new QComboBox( container );
QWhatsThis::add( catList, tr( "Select transaction category here." ) );
layout->addMultiCellWidget( catList, 3, 3, 1, 3 );
// Type
label = new QLabel( tr( "Type:" ), container );
QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
layout->addWidget( label, 4, 0 );
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 );
amtEdit = new QLineEdit( container );
QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
layout->addMultiCellWidget( amtEdit, 5, 5, 1, 3 );
// Fee
label = new QLabel( tr( "Fee:" ), container );
QWhatsThis::add( label, tr( "Enter any fee amount assoiciated with this transaction.\n\nThe value entered should always be positive." ) );
layout->addWidget( label, 6, 0 );
feeEdit = new QLineEdit( container );
QWhatsThis::add( feeEdit, tr( "Enter any fee amount assoiciated with this transaction.\n\nThe value entered should always be positive." ) );
layout->addMultiCellWidget( feeEdit, 6, 6, 1, 3 );
// Notes
label = new QLabel( tr( "Notes:" ), container );
QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) );
layout->addWidget( label, 7, 0 );
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() )
{
withBtn->setChecked( TRUE );
slotWithdrawalClicked();
}
else
{
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 );
if ( catList->currentText() == temptext )
{
break;
}
}
temptext = info->type();
i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
amtEdit->setText( QString( "%1" ).arg( info->amount(), 0, 'f', 2 ) );
feeEdit->setText( QString( "%1" ).arg( info->fee(), 0, 'f', 2 ) );
noteEdit->setText( info->notes() );
}
else
{
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() );
bool ok;
tran->setAmount( amtEdit->text().toFloat( &ok ) );
tran->setFee( feeEdit->text().toFloat( &ok ) );
tran->setNumber( numEdit->text() );
tran->setNotes( noteEdit->text() );
QDialog::accept();
}
void Transaction::slotWithdrawalClicked()
{
catList->clear();
CategoryList *pCatList=_pCfg->getCategoryList();
for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) {
if( !pCat->isIncome() )
catList->insertItem( pCat->getName() );
}
catList->setCurrentItem(0);
typeList->clear();
typeList->insertItem( tr( "Debit Charge" ) );
typeList->insertItem( tr( "Written Check" ) );
typeList->insertItem( tr( "Transfer" ) );
typeList->insertItem( tr( "Credit Card" ) );
}
void Transaction::slotDepositClicked()
{
catList->clear();
CategoryList *pCatList=_pCfg->getCategoryList();
for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) {
if( pCat->isIncome() )
catList->insertItem( pCat->getName() );
}
catList->setCurrentItem( 0 );
typeList->clear();
typeList->insertItem( tr( "Written Check" ) );
typeList->insertItem( tr( "Automatic Payment" ) );
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
@@ -18,62 +18,66 @@
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <qdialog.h>
class DateBookMonth;
class QComboBox;
class QLineEdit;
class QMultiLineEdit;
class QPushButton;
class QRadioButton;
class QString;
class QWidget;
class TranInfo;
class Cfg;
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;
QMultiLineEdit *noteEdit;
protected slots:
void accept();
private slots:
void slotWithdrawalClicked();
void slotDepositClicked();
void slotDateChanged( int, int, int );
+ void slotActivated(const QString & );
+ void slotNotNew();
};
#endif