summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook
authormickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
committer mickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
commit951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (side-by-side diff)
tree46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook
parentf0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff)
downloadopie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip
opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz
opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2
merge noncore/apps/* except
- advancedfm (ljp, please...) - odict (tille, please...)
Diffstat (limited to 'noncore/apps/checkbook') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp116
-rw-r--r--noncore/apps/checkbook/cbinfo.h24
-rw-r--r--noncore/apps/checkbook/cfg.cpp213
-rw-r--r--noncore/apps/checkbook/cfg.h120
-rw-r--r--noncore/apps/checkbook/checkbook.cpp228
-rw-r--r--noncore/apps/checkbook/checkbook.h32
-rw-r--r--noncore/apps/checkbook/checkbook.pro12
-rw-r--r--noncore/apps/checkbook/configuration.cpp107
-rw-r--r--noncore/apps/checkbook/configuration.h18
-rw-r--r--noncore/apps/checkbook/listedit.cpp340
-rw-r--r--noncore/apps/checkbook/listedit.h78
-rw-r--r--noncore/apps/checkbook/main.cpp14
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp119
-rw-r--r--noncore/apps/checkbook/mainwindow.h15
-rw-r--r--noncore/apps/checkbook/tabledef.cpp76
-rw-r--r--noncore/apps/checkbook/tabledef.h99
-rw-r--r--noncore/apps/checkbook/traninfo.cpp54
-rw-r--r--noncore/apps/checkbook/traninfo.h17
-rw-r--r--noncore/apps/checkbook/transaction.cpp40
-rw-r--r--noncore/apps/checkbook/transaction.h6
20 files changed, 1478 insertions, 250 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp
index 9fdc6b2..36dde04 100644
--- a/noncore/apps/checkbook/cbinfo.cpp
+++ b/noncore/apps/checkbook/cbinfo.cpp
@@ -33,6 +33,7 @@
#include <qfile.h>
+// --- CBInfo -----------------------------------------------------------------
CBInfo::CBInfo()
{
n = "";
@@ -44,10 +45,15 @@ CBInfo::CBInfo()
p = "";
nt = "";
sb = 0.0;
+ _sLastTab="";
+ _first=-1;
+ _last=-1;
tl = new TranInfoList();
}
+
+// --- CBInfo -----------------------------------------------------------------
CBInfo::CBInfo( const QString &name, const QString &filename )
{
Config config( filename, Config::File );
@@ -62,6 +68,9 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
a = config.readEntryCrypt( "Number", "" );
p = config.readEntryCrypt( "PINNumber", "" );
nt = config.readEntry( "Notes", "" );
+ _sLastTab = config.readEntry("LastTab", "");
+ _first=config.readNumEntry("First", -1);
+ _sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") );
bool ok;
sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok );
@@ -69,23 +78,40 @@ CBInfo::CBInfo( const QString &name, const QString &filename )
loadTransactions();
}
+// --- balance ----------------------------------------------------------------
float CBInfo::balance()
{
calcBalance();
return b;
}
+// --- write ------------------------------------------------------------------
void CBInfo::write()
{
QFile f( fn );
if ( f.exists() )
- {
f.remove();
- }
Config *config = new Config(fn, Config::File);
- // Save info
+
+ // fix transaction numbers
+ _first=-1;
+ TranInfo *prev=NULL;
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
+ if( _first<0 ) _first=tran->id();
+ if( prev ) prev->setNext( tran->id() );
+ tran->setNext(-1);
+ prev=tran;
+ }
+
+ // Save transactions
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) {
+ tran->write(config);
+ }
+
+ // Save info
+ if( _first<0 && _last>=0 ) _first=_last;
config->setGroup( "Account" );
config->writeEntryCrypt( "Password", pw );
config->writeEntry( "Type", t );
@@ -93,49 +119,49 @@ void CBInfo::write()
config->writeEntryCrypt( "Number", a );
config->writeEntryCrypt( "PINNumber", p );
config->writeEntry( "Notes", nt );
+ config->writeEntry( "LastTab", _sLastTab );
QString balstr;
balstr.setNum( sb, 'f', 2 );
config->writeEntry( "Balance", balstr );
+ config->writeEntry( "First", _first );
+ config->writeEntry( "SortOrder", _sSortOrder );
- // Save transactions
- int i = 1;
- for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
- {
- tran->write( config, i );
- i++;
- }
- config->write();
-
+ config->write();
delete config;
}
-TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date,
- const QString &desc )
+
+// --- findTransaction --------------------------------------------------------
+TranInfo *CBInfo::findTransaction( const QString &sId )
{
- TranInfo *traninfo = tl->first();
- while ( traninfo )
- {
- if ( traninfo->number() == checknum && traninfo->datestr() == date &&
- traninfo->desc() == desc )
- break;
- traninfo = tl->next();
- }
- return( traninfo );
+ bool bOk;
+ int id=sId.toInt( &bOk );
+ if( !bOk )
+ return(false);
+ TranInfo *traninfo;
+ for(traninfo=tl->first(); traninfo; traninfo=tl->next()) {
+ if( traninfo->id() == id )
+ break;
+ }
+ return(traninfo);
}
void CBInfo::addTransaction( TranInfo *tran )
{
- tl->inSort( tran );
+ tl->append( tran );
calcBalance();
}
void CBInfo::removeTransaction( TranInfo *tran )
{
- tl->remove( tran );
- delete tran;
+ tl->removeRef( tran );
+ delete tran;
calcBalance();
}
+
+// --- loadTransactions -------------------------------------------------------
+// Reads the transactions. Either the old way 1-n or as linked list.
void CBInfo::loadTransactions()
{
TranInfo *tran;
@@ -144,24 +170,29 @@ void CBInfo::loadTransactions()
tl = new TranInfoList();
Config config( fn, Config::File );
-
- for ( int i = 1; trandesc != QString::null; i++ )
- {
- tran = new TranInfo( config, i );
- trandesc = tran->desc();
- if ( trandesc != QString::null )
- {
- tl->inSort( tran );
- }
- else
- {
- delete tran;
- }
- }
-
- calcBalance();
+ int i=_first;
+ bool bOld=false;
+ if( i==-1 ) {
+ i=1;
+ bOld=true;
+ }
+ while( i>=0 ) {
+ _last=i;
+ tran=new TranInfo(config, i);
+ trandesc = tran->desc();
+ if( trandesc==QString::null ) {
+ delete tran;
+ break;
+ }
+ tl->append(tran);
+ i= bOld ? i+1 : tran->getNext();
+ }
+
+ calcBalance();
}
+
+// --- calcBalance ------------------------------------------------------------
void CBInfo::calcBalance()
{
float amount;
@@ -180,6 +211,7 @@ void CBInfo::calcBalance()
}
}
+
int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
{
QString n1 = ((CBInfo *)item1)->name();
diff --git a/noncore/apps/checkbook/cbinfo.h b/noncore/apps/checkbook/cbinfo.h
index 5e65db2..0b5b818 100644
--- a/noncore/apps/checkbook/cbinfo.h
+++ b/noncore/apps/checkbook/cbinfo.h
@@ -29,6 +29,7 @@
#ifndef CBINFO_H
#define CBINFO_H
+#include <qwidget.h>
#include <qlist.h>
#include <qstring.h>
@@ -63,12 +64,25 @@ class CBInfo
void setNotes( const QString &notes ) { nt = notes; }
void setStartingBalance( float startbal ) { sb = startbal; }
+ // write
void write();
+ // transactions
TranInfoList *transactions() const { return tl; }
- TranInfo *findTransaction( const QString &, const QString &, const QString & );
- void addTransaction( TranInfo * );
- void removeTransaction( TranInfo * );
+ TranInfo *findTransaction( const QString & );
+ void addTransaction( TranInfo * );
+ void removeTransaction( TranInfo * );
+
+ // lastTab
+ void setLastTab(const QString &sLastTab) { _sLastTab=sLastTab; }
+ QString &getLastTab() { return(_sLastTab); }
+
+ // getNextNumber
+ int getNextNumber() { return( ++_last ); }
+
+ // sortOrder
+ void setSortOrder(const QString &sSortOrder) { _sSortOrder=sSortOrder; }
+ QString &getSortOrder() { return(_sSortOrder); }
private:
QString n;
@@ -81,6 +95,10 @@ class CBInfo
QString nt;
float sb;
float b;
+ QString _sLastTab;
+ int _first;
+ int _last;
+ QString _sSortOrder;
TranInfoList *tl;
diff --git a/noncore/apps/checkbook/cfg.cpp b/noncore/apps/checkbook/cfg.cpp
new file mode 100644
index 0000000..1e0ec5c
--- a/dev/null
+++ b/noncore/apps/checkbook/cfg.cpp
@@ -0,0 +1,213 @@
+/*
+                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 <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();
+}
+
+// --- 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 );
+
+ // 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();
+ }
+
+ // 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);
+ }
+}
+
+
+// --- 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 );
+
+ // write account types
+ writeStringList(config, "AccType", _AccountTypes);
+
+ // write categories
+ QStringList lst=getCategories();
+ writeStringList(config, "Category", lst );
+
+ // commit write
+ config.write();
+}
+
+
+// --- 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>()
+{
+ setAutoDelete(true);
+}
diff --git a/noncore/apps/checkbook/cfg.h b/noncore/apps/checkbook/cfg.h
new file mode 100644
index 0000000..2b69368
--- a/dev/null
+++ b/noncore/apps/checkbook/cfg.h
@@ -0,0 +1,120 @@
+/*
+                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.
+
+*/
+
+#ifndef CFG_H
+#define CFG_H
+
+#include <qstring.h>
+#include <qlist.h>
+#include <qstringlist.h>
+class Config;
+
+// --- Category ---------------------------------------------------------------
+class Category
+{
+ public:
+ // --- Constructor:
+ Category(QString &sName, bool bIncome=false) { _sName=sName; _bIncome=bIncome; }
+
+ // members
+ QString &getName() { return(_sName); }
+ bool isIncome() { return(_bIncome); }
+ void setName(QString &sName) { _sName=sName; }
+ 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); }
+
+ // --- 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);
+
+ // --- 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;
+ QString _sLastBook;
+ QStringList _AccountTypes;
+ CategoryList *_pCategories;
+};
+
+#endif
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 653ee4a..c53e889 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -33,6 +33,8 @@
#include "graph.h"
#include "graphinfo.h"
#include "password.h"
+#include "mainwindow.h"
+#include "cfg.h"
#include <opie/otabwidget.h>
#include <qpe/qpeapplication.h>
@@ -48,12 +50,21 @@
#include <qpushbutton.h>
#include <qwhatsthis.h>
-Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
+#define COL_ID 0
+#define COL_NUM 1
+#define COL_DATE 2
+#define COL_DESC 3
+#define COL_AMOUNT 4
+#define COL_BAL 5
+
+// --- Checkbook --------------------------------------------------------------
+Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
info = i;
- currencySymbol = symbol;
+ _pCfg=cfg;
+ // Title bar
if ( info->name() != "" )
{
QString tempstr = info->name();
@@ -66,6 +77,7 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
setCaption( tr( "New checkbook" ) );
}
+
// Setup layout to make everything pretty
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 2 );
@@ -74,11 +86,14 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
// 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" ) );
mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) );
- mainWidget->setCurrentTab( tr( "Info" ) );
+ if( _pCfg->isShowLastTab() )
+ mainWidget->setCurrentTab( info->getLastTab() );
+ else
+ mainWidget->setCurrentTab( tr( "Info" ) );
+ connect( mainWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( slotTab(QWidget *) ) );
// Load checkbook information
loadCheckbook();
@@ -88,9 +103,10 @@ Checkbook::~Checkbook()
{
}
+// --- initInfo ---------------------------------------------------------------
QWidget *Checkbook::initInfo()
{
- QWidget *control = new QWidget( mainWidget );
+ QWidget *control = new QWidget( mainWidget, tr("Info") );
QVBoxLayout *vb = new QVBoxLayout( control );
@@ -128,13 +144,8 @@ QWidget *Checkbook::initInfo()
layout->addWidget( label, 2, 0 );
typeList = new QComboBox( container );
QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) );
- typeList->insertItem( tr( "Savings" ) ); // 0
- typeList->insertItem( tr( "Checking" ) ); // 1
- typeList->insertItem( tr( "CD" ) ); // 2
- typeList->insertItem( tr( "Money market" ) ); // 3
- typeList->insertItem( tr( "Mutual fund" ) ); // 4
- typeList->insertItem( tr( "Other" ) ); // 5
- layout->addWidget( typeList, 2, 1 );
+ typeList->insertStringList( _pCfg->getAccountTypes() );
+ layout->addWidget( typeList, 2, 1 );
// Bank/institution name
label = new QLabel( tr( "Bank:" ), container );
@@ -183,34 +194,53 @@ QWidget *Checkbook::initInfo()
return control;
}
+
+// --- initTransactions -------------------------------------------------------
QWidget *Checkbook::initTransactions()
{
- QWidget *control = new QWidget( mainWidget );
+ QWidget *control = new QWidget( mainWidget, tr("Transactions") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
- balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ),
- control );
- QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) );
- layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 );
-
- tranTable = new QListView( control );
+ // 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( "Num" ) );
+ tranTable->addColumn( tr( "Id" ) );
+ tranTable->setColumnWidthMode( COL_ID, QListView::Manual );
+ tranTable->setColumnWidth( COL_ID, 0);
+ tranTable->addColumn( tr( "Num" ) );
tranTable->addColumn( tr( "Date" ) );
//tranTable->addColumn( tr( "Cleared" ) );
tranTable->addColumn( tr( "Description" ) );
- int colnum = tranTable->addColumn( tr( "Amount" ) );
- tranTable->setColumnAlignment( colnum, Qt::AlignRight );
+ 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 );
+ 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() ) );
+ _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() ) );
@@ -229,11 +259,13 @@ QWidget *Checkbook::initTransactions()
return( control );
}
+
+// --- initCharts -------------------------------------------------------------
QWidget *Checkbook::initCharts()
{
graphInfo = 0x0;
- QWidget *control = new QWidget( mainWidget );
+ QWidget *control = new QWidget( mainWidget, tr("Charts") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
@@ -259,6 +291,7 @@ QWidget *Checkbook::initCharts()
return control;
}
+// --- loadCheckbook ----------------------------------------------------------
void Checkbook::loadCheckbook()
{
if ( !info )
@@ -281,6 +314,10 @@ void Checkbook::loadCheckbook()
break;
}
}
+ if( i<=0 ) {
+ typeList->insertItem( temptext, 0 );
+ typeList->setCurrentItem(0);
+ }
bankEdit->setText( info->bank() );
acctNumEdit->setText( info->account() );
pinNumEdit->setText( info->pin() );
@@ -290,42 +327,61 @@ void Checkbook::loadCheckbook()
// Load transactions
float amount;
- QString stramount;
-
- for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
+ QString stramount;
+ for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
- stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
- ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount );
+ stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
+ ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount );
}
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
-
- highTranNum = tranList->count();
+ // 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()
{
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
+ // 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);
+ }
}
-TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
+// --- resort -----------------------------------------------------------------
+void Checkbook::resort()
{
- TranInfo *traninfo = tranList->first();
- while ( traninfo )
- {
- if ( traninfo->number() == checknum && traninfo->datestr() == date &&
- traninfo->desc() == desc )
- break;
- traninfo = tranList->next();
- }
- return( traninfo );
+ tranTable->setSorting(_sortCol);
+ tranTable->sort();
+ tranTable->setSorting(-1);
}
+
+// --- accept -----------------------------------------------------------------
void Checkbook::accept()
{
info->setName( nameEdit->text() );
@@ -398,6 +454,8 @@ void Checkbook::slotNameChanged( const QString &newname )
setCaption( namestr );
}
+
+// ---slotStartingBalanceChanged ----------------------------------------------
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
bool ok;
@@ -405,14 +463,16 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
adjustBalance();
}
+
void Checkbook::slotNewTran()
{
- highTranNum++;
- TranInfo *traninfo = new TranInfo( highTranNum );
+ TranInfo *traninfo = new TranInfo( info->getNextNumber() );
+ if( !_dLastNew.isNull() )
+ traninfo->setDate(_dLastNew);
Transaction *currtran = new Transaction( this, info->name(),
traninfo,
- currencySymbol );
+ _pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
@@ -422,22 +482,19 @@ void Checkbook::slotNewTran()
// Add to transaction table
float amount;
QString stramount;
-
- amount = traninfo->amount();
- if ( traninfo->withdrawal() )
- {
- amount *= -1;
- }
- stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
-
- ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
- 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(),
+ stramount );
+ resort();
adjustBalance();
+
+ // save last date
+ _dLastNew = traninfo->date();
}
else
{
- highTranNum--;
delete traninfo;
}
}
@@ -446,22 +503,19 @@ void Checkbook::slotEditTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
- {
return;
- }
-
- TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ),
- curritem->text( 2 ) );
+
+ TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
Transaction *currtran = new Transaction( this, info->name(),
traninfo,
- currencySymbol );
+ _pCfg );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
- curritem->setText( 0, traninfo->number() );
- curritem->setText( 1, traninfo->datestr() );
- curritem->setText( 2, traninfo->desc() );
+ curritem->setText( COL_NUM, traninfo->number() );
+ curritem->setText( COL_DATE, traninfo->datestr() );
+ curritem->setText( COL_DESC, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
@@ -469,10 +523,10 @@ void Checkbook::slotEditTran()
amount *= -1;
}
QString stramount;
- stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
- curritem->setText( 3, stramount );
-
- adjustBalance();
+ stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
+ curritem->setText( COL_AMOUNT, stramount );
+ resort();
+ adjustBalance();
}
delete currtran;
@@ -482,17 +536,15 @@ void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
- {
return;
- }
- TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
+ TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
info->removeTransaction( traninfo );
delete curritem;
- adjustBalance();
+ adjustBalance();
}
}
@@ -589,11 +641,12 @@ void Checkbook::drawCategoryChart( bool withdrawals )
graphInfo = new GraphInfo( GraphInfo::PieChart, list );
}
-CBListItem::CBListItem( QListView *parent, QString label1, QString label2,
+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;
}
@@ -652,3 +705,26 @@ bool CBListItem::isAltBackground()
}
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;
+ }
+ info->setSortOrder( selc );
+ resort();
+}
diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h
index 4a5011b..1b6a2d3 100644
--- a/noncore/apps/checkbook/checkbook.h
+++ b/noncore/apps/checkbook/checkbook.h
@@ -29,6 +29,7 @@
#ifndef CHECKBOOK_H
#define CHECKBOOK_H
+#include <qdatetime.h>
#include <qdialog.h>
#include <qlistview.h>
@@ -46,25 +47,29 @@ class QMultiLineEdit;
class QString;
class TranInfo;
class TranInfoList;
+class Cfg;
+
+// --- Checkbook --------------------------------------------------------------
class Checkbook : public QDialog
{
Q_OBJECT
public:
- Checkbook( QWidget * = 0x0, CBInfo * = 0x0, const QString & = "$" );
+ Checkbook( QWidget *, CBInfo *, Cfg *cfg );
~Checkbook();
+ // resort
+ void resort();
+
private:
- CBInfo *info;
+ CBInfo *info;
TranInfoList *tranList;
- QString currencySymbol;
- int highTranNum;
+ Cfg *_pCfg;
OTabWidget *mainWidget;
void loadCheckbook();
void adjustBalance();
- TranInfo *findTran( const QString &, const QString &, const QString & );
// Info tab
QWidget *initInfo();
@@ -76,11 +81,13 @@ class Checkbook : public QDialog
QLineEdit *pinNumEdit;
QLineEdit *balanceEdit;
QMultiLineEdit *notesEdit;
+ int _sortCol;
// Transactions tab
- QWidget *initTransactions();
+ QWidget *initTransactions();
QListView *tranTable;
- QLabel *balanceLabel;
+ QComboBox *_cbSortType;
+ QDate _dLastNew;
// Charts tab
QWidget *initCharts();
@@ -91,8 +98,10 @@ class Checkbook : public QDialog
void drawBalanceChart();
void drawCategoryChart( bool = TRUE );
+
protected slots:
void accept();
+ void slotTab(QWidget *tab);
private slots:
void slotPasswordClicked();
@@ -102,20 +111,26 @@ class Checkbook : public QDialog
void slotEditTran();
void slotDeleteTran();
void slotDrawGraph();
+ void slotSortChanged( const QString & );
};
+// --- CBListItem -------------------------------------------------------------
class CBListItem : public QListViewItem
{
//Q_OBJECT
public:
- CBListItem( QListView *, QString = QString::null, QString = QString::null,
+ 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:
+ TranInfo *_pTran;
QListView *owner;
bool m_known;
bool m_odd;
@@ -123,4 +138,5 @@ class CBListItem : public QListViewItem
bool isAltBackground();
};
+
#endif
diff --git a/noncore/apps/checkbook/checkbook.pro b/noncore/apps/checkbook/checkbook.pro
index 9a16a56..c574aff 100644
--- a/noncore/apps/checkbook/checkbook.pro
+++ b/noncore/apps/checkbook/checkbook.pro
@@ -1,5 +1,4 @@
-TEMPLATE = app
-CONFIG = qt warn_on release
+CONFIG = qt warn_on release quick-app
HEADERS = mainwindow.h \
cbinfo.h \
traninfo.h \
@@ -8,6 +7,9 @@ HEADERS = mainwindow.h \
password.h \
checkbook.h \
transaction.h \
+ tabledef.h \
+ listedit.h \
+ cfg.h \
graph.h
SOURCES = main.cpp \
mainwindow.cpp \
@@ -17,13 +19,15 @@ SOURCES = main.cpp \
configuration.cpp \
password.cpp \
checkbook.cpp \
- transaction.cpp \
+ transaction.cpp \
+ tabledef.cpp \
+ listedit.cpp \
+ cfg.cpp \
graph.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = checkbook
-DESTDIR = $(OPIEDIR)/bin
TRANSLATIONS = ../../../i18n/de/checkbook.ts \
../../../i18n/nl/checkbook.ts \
diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp
index 7731cf3..3f5662d 100644
--- a/noncore/apps/checkbook/configuration.cpp
+++ b/noncore/apps/checkbook/configuration.cpp
@@ -27,48 +27,135 @@
*/
#include "configuration.h"
+#include "mainwindow.h"
+#include "listedit.h"
+#include "tabledef.h"
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qwhatsthis.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qtabwidget.h>
+#include <qpe/resource.h>
-Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool sb )
+Configuration::Configuration( QWidget *parent, Cfg &cfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
setCaption( tr( "Configure Checkbook" ) );
- QFontMetrics fm = fontMetrics();
+ // 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" ) );
+}
+
+Configuration::~Configuration()
+{
+}
+
+// ---- initSettings ----------------------------------------------------------
+QWidget *Configuration::initSettings(Cfg &cfg)
+{
+ QWidget *control = new QWidget( _mainWidget );
+
+ QFontMetrics fm = fontMetrics();
int fh = fm.height();
- QGridLayout *layout = new QGridLayout( this );
+ 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:" ), this );
+ 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( cs, this );
+ 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" ), this );
+ 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( sl );
+ lockCB->setChecked( cfg.getShowLocks() );
layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 );
- balCB = new QCheckBox( tr( "Show checkbook balances" ), this );
+ 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( sb );
+ 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 );
+
+ return(control);
}
-Configuration::~Configuration()
+// --- 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() );
+
+ // Typelist
+ _listEditTypes->storeInList( cfg.getAccountTypes() );
+
+ // Category list
+ QStringList lst;
+ _listEditCategories->storeInList( lst );
+ cfg.setCategories( lst );
}
diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h
index 9a8de02..5893502 100644
--- a/noncore/apps/checkbook/configuration.h
+++ b/noncore/apps/checkbook/configuration.h
@@ -30,22 +30,38 @@
#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:
- Configuration( QWidget * = 0x0, const QString & = "$", bool = FALSE, bool = FALSE );
+ // Constructor
+ Configuration( QWidget *, Cfg &cfg);
~Configuration();
QLineEdit *symbolEdit;
QCheckBox *lockCB;
QCheckBox *balCB;
+ QCheckBox *openLastBookCB;
+ QCheckBox *lastTabCB;
+ QTabWidget *_mainWidget;
+ ListEdit *_listEditTypes;
+ ListEdit *_listEditCategories;
+
+ // 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
new file mode 100644
index 0000000..99a6531
--- a/dev/null
+++ b/noncore/apps/checkbook/listedit.cpp
@@ -0,0 +1,340 @@
+/*
+                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 "listedit.h"
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qlistview.h>
+#include <qwidgetstack.h>
+#include <qcombobox.h>
+#include <qpushbutton.h>
+#include <qpe/resource.h>
+
+
+// --- ListEdit ---------------------------------------------------------------
+ListEdit::ListEdit( QWidget *parent, const char *sName )
+ : QWidget(parent, sName), TableDef(sName)
+{
+ // get font height
+ int fh = fontMetrics().height();
+
+ // create layout
+ QGridLayout *layout=new QGridLayout(this);
+ layout->setSpacing( 2 );
+ layout->setMargin( 4 );
+
+ // type table
+ _typeTable = new QListView( this );
+ ColumnDef *def=first();
+ while( def ) {
+ _typeTable->addColumn( def->getName() );
+ def=next();
+ }
+ connect( _typeTable, SIGNAL( clicked(QListViewItem *, const QPoint &, int) ), this, SLOT( slotClick(QListViewItem *, const QPoint &, int ) ) );
+ layout->addMultiCellWidget(_typeTable, 0,4,0,4);
+ _currentItem=NULL;
+
+ // edit field
+ _stack=new QWidgetStack( this );
+ _stack->setMaximumHeight(fh+5);
+ layout->addMultiCellWidget(_stack, 5,5,0,2);
+ _typeEdit = new QLineEdit( _stack );
+ _stack->raiseWidget(_typeEdit );
+ connect( _typeEdit, SIGNAL( textChanged(const QString &) ), this, SLOT( slotEditChanged(const QString &) ) );
+
+ // combo box
+ _box=new QComboBox( _stack );
+ connect( _box, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) );
+
+
+ // add button
+ QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/add" ), tr( "Add" ), this );
+ connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
+ layout->addWidget( btn, 5, 3 );
+
+ // delete button
+ btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this );
+ connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) );
+ layout->addWidget( btn, 5, 4 );
+}
+
+// --- ~ListEdit --------------------------------------------------------------
+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 );
+}
+
+// --- 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>
+{
+ public:
+ ColList() : QList<QString>() { }
+
+ protected:
+ int compareItems(QCollection::Item, QCollection::Item);
+};
+
+int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) {
+ return( ((QString *)i1)->compare(*(QString *)i2) );
+}
+
+void ListEdit::fixTypes(int iColumn)
+{
+ // get column def
+ ColumnDef *pDef=this->at(iColumn);
+
+ // create map of entries
+ if( !_typeTable->childCount() ) return;
+ ColMap **colMap=new (ColMap *)[_typeTable->childCount()];
+ QListViewItem *cur=_typeTable->firstChild();
+ ColList lst;
+ for(int i=0; i<_typeTable->childCount(); i++) {
+ colMap[i]=new ColMap(cur->text(iColumn), cur);
+ lst.append( &(colMap[i]->getValue()) );
+ cur=cur->nextSibling();
+ }
+
+ // fix empty entries
+ int i=0;
+ for(QString *ptr=lst.first(); ptr; ptr=lst.next()) {
+ *ptr=ptr->stripWhiteSpace();
+ if( ptr->isEmpty() ) {
+ i++;
+ if( i==1 ) *ptr=pDef->getNewValue();
+ else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i);
+ }
+ }
+
+ // fix dups
+ lst.sort();
+ QString repl;
+ for(uint iCur=0; iCur<lst.count()-1; iCur++) {
+ QString *current=lst.at(iCur);
+ for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) {
+ if( *current!=*lst.at(iNext) ) continue;
+ for(int i=2; ; i++) {
+ repl.sprintf("%s %d", (const char *)*current, i);
+ bool bDup=false;
+ uint iChk=iNext+1;
+ while( iChk<lst.count() ) {
+ QString *chk=lst.at(iChk);
+ if( !chk->startsWith(*current) ) break;
+ if( *chk==repl ) {
+ bDup=true;
+ break;
+ }
+ iChk++;
+ }
+ if( !bDup ) {
+ *lst.at(iNext)=repl;
+ break;
+ }
+ }
+ }
+ }
+ lst.sort();
+
+ // copy back clean up col map
+ for(int i=0; i<_typeTable->childCount(); i++) {
+ colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue());
+ delete colMap[i];
+ }
+ delete colMap;
+}
+
+void ListEdit::fixTypes()
+{
+ int i;
+ ColumnDef *pDef;
+ for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) {
+ if( pDef->hasFlag(ColumnDef::typeUnique) )
+ fixTypes(i);
+ }
+ _typeTable->sort();
+}
+
+
+// --- storeInList ------------------------------------------------------------
+void ListEdit::storeInList(QStringList &lst)
+{
+ // delete old content
+ lst.clear();
+
+ // add new one
+ fixTypes();
+ QListViewItem *itm=_typeTable->firstChild();
+ while( itm ) {
+ int i=0;
+ QString sAdd;
+ ColumnDef *pDef;
+ for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) {
+ if( i>=1 ) sAdd+=";";
+ sAdd += itm->text(i);
+ }
+ lst.append( sAdd );
+ itm=itm->nextSibling();
+ }
+}
+
+
+// --- slotClicked ------------------------------------------------------------
+void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col)
+{
+ (void)pnt; // get rid of unused warning;
+
+ // save values
+ _currentItem=itm;
+ _currentColumn=col;
+ if( itm==NULL ) {
+ _typeEdit->setText("");
+ _stack->raiseWidget(_typeEdit);
+ return;
+ }
+
+ // display value
+ if( _currentColumn<0 ) _currentColumn=0;
+ ColumnDef *pDef=this->at(_currentColumn);
+ if( pDef->isType(ColumnDef::typeString) ) {
+ _typeEdit->setText( _currentItem->text(_currentColumn) );
+ _stack->raiseWidget(_typeEdit);
+ } else if( pDef->isType(ColumnDef::typeList) ){
+ _box->clear();
+ _box->insertStringList( pDef->getValueList() );
+ QStringList::Iterator itr;
+ int i=0;
+ for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) {
+ if( (*itr)==_currentItem->text(_currentColumn) ) {
+ _box->setCurrentItem(i);
+ i=-1;
+ break;
+ }
+ i++;
+ }
+ if( i>=0 ) {
+ _box->insertItem( _currentItem->text(_currentColumn) );
+ _box->setCurrentItem(i);
+ }
+ _stack->raiseWidget(_box);
+ } else {
+ qDebug( "Unsupported column type for column %s", (const char *)pDef->getName() );
+ _typeEdit->setText("");
+ _stack->raiseWidget(_typeEdit);
+ }
+}
+
+
+// --- addColumnDef -----------------------------------------------------------
+void ListEdit::addColumnDef(ColumnDef *pDef)
+{
+ _typeTable->addColumn( pDef->getName() );
+ _vColumns.append(pDef);
+}
+
+// --- addData ----------------------------------------------------------------
+void ListEdit::addData(QStringList &lst)
+{
+ // run through list
+ QStringList::Iterator itr;
+ for(itr=lst.begin(); itr!=lst.end(); itr++) {
+ QStringList split=QStringList::split(";", *itr, true);
+ QStringList::Iterator entry;
+ QString args[8];
+ int i=0;
+ for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) {
+ args[i]= (*entry);
+ }
+ while(i<8) {
+ args[i++]="";
+ }
+ new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
+ }
+}
+
+// --- slotActivated ----------------------------------------------------------
+void ListEdit::slotActivated(const QString &str)
+{
+ if( _currentItem==NULL || _currentColumn<0 ) return;
+ _currentItem->setText(_currentColumn, str);
+}
diff --git a/noncore/apps/checkbook/listedit.h b/noncore/apps/checkbook/listedit.h
new file mode 100644
index 0000000..d2135ea
--- a/dev/null
+++ b/noncore/apps/checkbook/listedit.h
@@ -0,0 +1,78 @@
+/*
+                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.
+
+*/
+
+#ifndef LISTEDIT_H
+#define LISTEDIT_H
+
+#include <qwidget.h>
+#include "tabledef.h"
+class QListView;
+class QLineEdit;
+class QListViewItem;
+class QPoint;
+class QWidgetStack;
+class QComboBox;
+
+class ListEdit : public QWidget, public TableDef
+{
+ Q_OBJECT
+
+ public:
+ ListEdit( QWidget *, const char *sName);
+ virtual ~ListEdit();
+
+ QListView *_typeTable;
+ QLineEdit *_typeEdit;
+ QWidgetStack *_stack;
+ QComboBox *_box;
+ QListViewItem *_currentItem;
+ int _currentColumn;
+
+ // resolves dups and empty entries
+ void fixTypes();
+ void fixTypes(int iColumn);
+
+ // stores content in string list
+ void storeInList(QStringList &lst);
+
+ // adds a column definition
+ virtual void addColumnDef(ColumnDef *pDef);
+
+ // adds data to table
+ void addData(QStringList &lst);
+
+
+ public slots:
+ void slotClick(QListViewItem *, const QPoint &pnt, int col);
+ void slotEditChanged(const QString &);
+ void slotAdd();
+ void slotDel();
+ void slotActivated(const QString &);
+};
+
+#endif
diff --git a/noncore/apps/checkbook/main.cpp b/noncore/apps/checkbook/main.cpp
index abfa633..dcaab4a 100644
--- a/noncore/apps/checkbook/main.cpp
+++ b/noncore/apps/checkbook/main.cpp
@@ -26,17 +26,9 @@
*/
-#include "mainwindow.h"
-
#include <qpe/qpeapplication.h>
+#include <opie/oapplicationfactory.h>
-int main(int argc, char **argv)
-{
- QPEApplication app(argc, argv);
-
- MainWindow *cb = new MainWindow();
- app.setMainWidget(cb);
- cb->showMaximized();
+#include "mainwindow.h"
- return app.exec();
-}
+OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index 6d1d7b9..8d64cad 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -31,6 +31,7 @@
#include "configuration.h"
#include "password.h"
#include "checkbook.h"
+#include "listedit.h"
#include <qpe/config.h>
#include <qpe/global.h>
@@ -46,8 +47,9 @@
#include <qlineedit.h>
#include <qwhatsthis.h>
-MainWindow::MainWindow()
- : QMainWindow( 0x0, 0x0, WStyle_ContextHelp )
+
+MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
+ : QMainWindow( parent, name, fl || WStyle_ContextHelp )
{
setCaption( tr( "Checkbook" ) );
@@ -56,10 +58,9 @@ MainWindow::MainWindow()
// Load configuration options
Config config( "checkbook" );
- config.setGroup( "Config" );
- currencySymbol = config.readEntry( "CurrencySymbol", "$" );
- showLocks = config.readBoolEntry( "ShowLocks", FALSE );
- showBalances = config.readBoolEntry( "ShowBalances", FALSE );
+qDebug( "Reading config" );
+ _cfg.readConfig( config );
+
// Build menu and tool bars
setToolBarsMovable( FALSE );
@@ -125,24 +126,40 @@ MainWindow::MainWindow()
// Build Checkbook selection list control
cbList = 0x0;
buildList();
+
+ // open last book?
+ if( _cfg.isOpenLastBook() ) {
+ this->show();
+ this->showMaximized();
+ QListViewItem *itm=cbList->firstChild();
+ while( itm ) {
+ if( itm->text(posName)==_cfg.getLastBook() ) {
+ openBook( itm );
+ break;
+ }
+ itm=itm->nextSibling();
+ }
+ }
}
+
+// --- ~MainWindow ------------------------------------------------------------
MainWindow::~MainWindow()
{
-// config.write();
+ writeConfig();
}
+
+// --- buildList --------------------------------------------------------------
void MainWindow::buildList()
{
if ( cbList )
- {
- delete cbList;
- }
+ delete cbList;
cbList = new QListView( this );
QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
- if ( showLocks )
+ if ( _cfg.getShowLocks() )
{
cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
posName = 1;
@@ -152,7 +169,7 @@ void MainWindow::buildList()
posName = 0;
}
cbList->addColumn( tr( "Checkbook Name" ) );
- if ( showBalances )
+ if ( _cfg.getShowBalances() )
{
int colnum = cbList->addColumn( tr( "Balance" ) );
cbList->setColumnAlignment( colnum, Qt::AlignRight );
@@ -173,15 +190,15 @@ void MainWindow::buildList()
void MainWindow::addCheckbook( CBInfo *cb )
{
QListViewItem *lvi = new QListViewItem( cbList );
- if ( showLocks && !cb->password().isNull() )
+ if ( _cfg.getShowLocks() && !cb->password().isNull() )
{
lvi->setPixmap( 0, lockIcon );
}
lvi->setText( posName, cb->name() );
- if ( showBalances )
+ if ( _cfg.getShowBalances() )
{
QString balance;
- balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
lvi->setText( posName + 1, balance );
}
}
@@ -197,12 +214,13 @@ void MainWindow::slotNew()
{
CBInfo *cb = new CBInfo();
- Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
+ Checkbook *currcb = new Checkbook( this, cb, &_cfg );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
// Save new checkbook
buildFilename( cb->name() );
+ _cfg.setLastBook( cb->name() );
cb->setFilename( tempFilename );
cb->write();
@@ -213,28 +231,31 @@ void MainWindow::slotNew()
delete currcb;
}
+// --- slotEdit ---------------------------------------------------------------
void MainWindow::slotEdit()
{
-
+ // get name and open it
QListViewItem *curritem = cbList->currentItem();
if ( !curritem )
- {
return;
- }
- QString currname = curritem->text( posName );
+ openBook( curritem );
+}
- CBInfo *cb = checkbooks->first();
- while ( cb )
- {
+
+// --- openBook ---------------------------------------------------------------
+void MainWindow::openBook(QListViewItem *curritem)
+{
+ // find book in List
+ QString currname=curritem->text(posName);
+ CBInfo *cb = checkbooks->first();
+ while ( cb ) {
if ( cb->name() == currname )
break;
cb = checkbooks->next();
}
- if ( !cb )
- {
- return;
- }
+ if ( !cb ) return;
+ //
buildFilename( currname );
float currbalance = cb->balance();
bool currlock = !cb->password().isNull();
@@ -250,7 +271,8 @@ void MainWindow::slotEdit()
delete pw;
}
- Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
+ _cfg.setLastBook( currname );
+ Checkbook *currcb = new Checkbook( this, cb, &_cfg );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
@@ -258,15 +280,16 @@ void MainWindow::slotEdit()
if ( currname != newname )
{
// Update name if changed
- curritem->setText( posName, newname );
- cbList->sort();
+ if( curritem ) {
+ curritem->setText( posName, newname );
+ cbList->sort();
+ }
+ _cfg.setLastBook( newname );
// Remove old file
QFile f( tempFilename );
if ( f.exists() )
- {
f.remove();
- }
// Get new filename
buildFilename( newname );
@@ -276,7 +299,7 @@ void MainWindow::slotEdit()
cb->write();
// Update lock if changed
- if ( showLocks && !cb->password().isNull() != currlock )
+ if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
{
if ( !cb->password().isNull() )
curritem->setPixmap( 0, lockIcon );
@@ -285,16 +308,17 @@ void MainWindow::slotEdit()
}
// Update balance if changed
- if ( showBalances && cb->balance() != currbalance )
+ if ( _cfg.getShowBalances() && cb->balance() != currbalance )
{
QString tempstr;
- tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
curritem->setText( posName + 1, tempstr );
}
}
delete currcb;
}
+// --- slotDelete -------------------------------------------------------------
void MainWindow::slotDelete()
{
QString currname = cbList->currentItem()->text( posName );
@@ -312,24 +336,25 @@ void MainWindow::slotDelete()
}
}
+// --- slotConfigure ----------------------------------------------------------
void MainWindow::slotConfigure()
{
- Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances );
+ Configuration *cfgdlg = new Configuration( this, _cfg );
cfgdlg->showMaximized();
if ( cfgdlg->exec() == QDialog::Accepted )
{
- currencySymbol = cfgdlg->symbolEdit->text();
- showLocks = cfgdlg->lockCB->isChecked();
- showBalances = cfgdlg->balCB->isChecked();
-
- Config config( "checkbook" );
- config.setGroup( "Config" );
- config.writeEntry( "CurrencySymbol", currencySymbol );
- config.writeEntry( "ShowLocks", showLocks );
- config.writeEntry( "ShowBalances", showBalances );
- config.write();
-
+ // read data from config dialog & save it
+ cfgdlg->saveConfig( _cfg );
+ writeConfig();
buildList();
}
delete cfgdlg;
}
+
+
+// --- writeConfig --------------------------------------------------------------
+void MainWindow::writeConfig()
+{
+ Config config("checkbook");
+ _cfg.writeConfig( config );
+}
diff --git a/noncore/apps/checkbook/mainwindow.h b/noncore/apps/checkbook/mainwindow.h
index 2bc70b3..6275f94 100644
--- a/noncore/apps/checkbook/mainwindow.h
+++ b/noncore/apps/checkbook/mainwindow.h
@@ -31,20 +31,29 @@
#include <qmainwindow.h>
#include <qpixmap.h>
+#include "cfg.h"
class CBInfo;
class CBInfoList;
class QAction;
class QListView;
class QString;
+class QListViewItem;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~MainWindow();
+ static QString appName() { return QString::fromLatin1("checkbook"); };
+
+ // safe config
+ void writeConfig();
+
+ // open a check book
+ void openBook(QListViewItem *curr);
private:
QListView *cbList;
@@ -52,9 +61,7 @@ class MainWindow : public QMainWindow
QAction *actionOpen;
QAction *actionDelete;
- QString currencySymbol;
- bool showLocks;
- bool showBalances;
+ Cfg _cfg;
int posName;
CBInfoList *checkbooks;
diff --git a/noncore/apps/checkbook/tabledef.cpp b/noncore/apps/checkbook/tabledef.cpp
new file mode 100644
index 0000000..13edded
--- a/dev/null
+++ b/noncore/apps/checkbook/tabledef.cpp
@@ -0,0 +1,76 @@
+/*
+                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 "tabledef.h"
+
+#include <qstring.h>
+#include <qpe/resource.h>
+
+// --- ColumnDef --------------------------------------------------------------
+ColumnDef::ColumnDef(const char *sName, ColumnType type, const char *sNewValue)
+{
+ _sName=sName;
+ _type=type;
+ _sNewValue=sNewValue;
+}
+
+
+// --- addColumnValue ---------------------------------------------------------
+void ColumnDef::addColumnValue(const QString &sValue)
+{
+ if( (_type & 0x00ffffff) !=typeList )
+ qDebug("Column %s is not a list", (const char *)_sName);
+ else
+ _valueList.append(sValue);
+}
+void ColumnDef::addColumnValue(const char *sValue)
+{
+ if( (_type & 0x00ffffff)!=typeList )
+ qDebug("Column %s is not a list", (const char *)_sName);
+ else
+ _valueList.append(sValue);
+}
+
+// --- TableDef ---------------------------------------------------------------
+TableDef::TableDef(const char *sName)
+{
+ _sName=sName;
+ _vColumns.setAutoDelete(TRUE);
+}
+
+
+// --- ~TableDef --------------------------------------------------------------
+TableDef::~TableDef()
+{
+}
+
+// --- addColumnDef -----------------------------------------------------------
+void TableDef::addColumnDef(ColumnDef *pDef)
+{
+ _vColumns.append(pDef);
+}
diff --git a/noncore/apps/checkbook/tabledef.h b/noncore/apps/checkbook/tabledef.h
new file mode 100644
index 0000000..5891ad7
--- a/dev/null
+++ b/noncore/apps/checkbook/tabledef.h
@@ -0,0 +1,99 @@
+/*
+                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.
+
+*/
+
+#ifndef TABLEDEF_H
+#define TABLEDEF_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qlist.h>
+
+
+
+// --- ColumnDef -------------------------------------------------------------
+class ColumnDef
+{
+ public:
+ enum ColumnType {
+ typeString=0x1,
+ typeList=0x2,
+ typeUnique=0x80000000
+ };
+
+ // Constructor
+ ColumnDef(const char *sName, ColumnType type, const char *sNewValue);
+
+ // add column value
+ void addColumnValue(const QString &Value);
+ void addColumnValue(const char *sValue);
+
+ // member functions
+ const QString getName() { return(_sName); }
+ const QString getNewValue() { return(_sNewValue); }
+
+ // test for type
+ int isType(ColumnType x) { return( (_type & 0x00ffffff)==x ); }
+ int hasFlag(ColumnType x) { return( (_type & x) ); }
+
+ // get value list
+ QStringList &getValueList() { return(_valueList); }
+
+ private:
+ QString _sName;
+ QString _sNewValue;
+ enum ColumnType _type;
+ QStringList _valueList;
+};
+
+typedef QList<ColumnDef> ColumnDefList;
+
+
+// --- TableDef ---------------------------------------------------------------
+class TableDef
+{
+ public:
+ // Constructor & Destructor
+ TableDef(const char *sName);
+ virtual ~TableDef();
+
+ // adds a column definition
+ virtual void addColumnDef(ColumnDef *pDef);
+
+ // movement operators
+ ColumnDef *first() { return(_vColumns.first() ); }
+ ColumnDef *last() { return(_vColumns.last() ); }
+ ColumnDef *next() { return(_vColumns.next() ); }
+ ColumnDef *prev() { return(_vColumns.prev() ); }
+ ColumnDef *at(int i) { return(_vColumns.at(i)); }
+
+ protected:
+ QString _sName;
+ ColumnDefList _vColumns;
+};
+
+#endif
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp
index 65c190c..d880bb4 100644
--- a/noncore/apps/checkbook/traninfo.cpp
+++ b/noncore/apps/checkbook/traninfo.cpp
@@ -34,7 +34,7 @@ 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 )
+ float fee, const QString &number, const QString &notes, int next )
{
i = id;
d = desc;
@@ -46,6 +46,7 @@ TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdra
f = fee;
cn = number;
n = notes;
+ _next=next;
}
TranInfo::TranInfo( Config config, int entry )
@@ -111,32 +112,37 @@ TranInfo::TranInfo( Config config, int entry )
stramount = config.readEntry( "TransactionFee", "0.00" );
f = stramount.toFloat( &ok );
- // Transaction number
+ // Transaction number
cn = config.readEntry( "CheckNumber", "" );
// Notes
n = config.readEntry( "Comments", "" );
+
+ // next
+ _next = config.readNumEntry("Next", -1);
}
}
+// --- datestr ----------------------------------------------------------------
const QString &TranInfo::datestr()
{
- tempstr = QString::number( td.year() );
- tempstr.append( '/' );
- int tempfield = td.month();
- if ( tempfield < 10 ) tempstr.append( '0' );
- tempstr.append( QString::number( tempfield ) );
- tempstr.append( '/' );
- tempfield = td.day();
- if ( tempfield < 10 ) tempstr.append( '0' );
- tempstr.append( QString::number( tempfield ) );
+ int y=td.year();
+ y= y>=2000 && y<=2099 ? y-2000 : y;
+ tempstr.sprintf( "%02d/%02d/%02d", y ,td.month(), td.day() );
+ return( tempstr );
+}
- return( tempstr );
+// --- getIdStr ---------------------------------------------------------------
+const QString &TranInfo::getIdStr()
+{
+ tempstr.sprintf("%04d", i);
+ return( tempstr );
}
-void TranInfo::write( Config *config, int entry )
+// --- write ------------------------------------------------------------------
+void TranInfo::write( Config *config )
{
- config->setGroup( QString::number( entry ) );
+ config->setGroup( QString::number( id() ) );
config->writeEntry( "Description", d );
@@ -169,11 +175,12 @@ void TranInfo::write( Config *config, int entry )
tempstr.setNum( f, 'f', 2 );
config->writeEntry( "TransactionFee", tempstr );
- config->writeEntry( "CheckNumber", cn );
-
+ config->writeEntry( "CheckNumber", cn );
config->writeEntry( "Comments", n );
+ config->writeEntry( "Next", _next );
}
+
int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
{
QDate d1 = ((TranInfo *)item1)->date();
@@ -188,3 +195,18 @@ int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2
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);
+}
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h
index f6c5cae..0abdc61 100644
--- a/noncore/apps/checkbook/traninfo.h
+++ b/noncore/apps/checkbook/traninfo.h
@@ -40,10 +40,13 @@ class TranInfo
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 );
+ 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();
@@ -54,8 +57,10 @@ class TranInfo
float fee() const { return f; }
const QString &number() const { return cn; }
const QString &notes() const { return n; }
+ int getNext() { return(_next); }
- void setDesc( const QString &desc ) { d = desc; }
+ // 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; }
@@ -64,8 +69,13 @@ class TranInfo
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 * );
- void write( Config *, int );
+ // toString
+ QString toString();
private:
int i;
@@ -78,6 +88,7 @@ class TranInfo
float f;
QString cn;
QString n;
+ int _next;
};
class TranInfoList : public QList<TranInfo>
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp
index c94b989..138d0e6 100644
--- a/noncore/apps/checkbook/transaction.cpp
+++ b/noncore/apps/checkbook/transaction.cpp
@@ -28,6 +28,7 @@
#include "transaction.h"
#include "traninfo.h"
+#include "cfg.h"
#include <qpe/datebookmonth.h>
@@ -41,7 +42,7 @@
#include <qwhatsthis.h>
Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info,
- const QString &symbol )
+ Cfg *pCfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
QString tempstr = tr( "Transaction for " );
@@ -49,7 +50,7 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
setCaption( tempstr );
tran = info;
- currencySymbol = symbol;
+ _pCfg=pCfg;
QVBoxLayout *vb = new QVBoxLayout( this );
@@ -223,28 +224,20 @@ void Transaction::accept()
tran->setFee( feeEdit->text().toFloat( &ok ) );
tran->setNumber( numEdit->text() );
tran->setNotes( noteEdit->text() );
-
+
QDialog::accept();
}
void Transaction::slotWithdrawalClicked()
{
catList->clear();
- catList->insertItem( tr( "Automobile" ) );
- catList->insertItem( tr( "Bills" ) );
- catList->insertItem( tr( "CDs" ) );
- catList->insertItem( tr( "Clothing" ) );
- catList->insertItem( tr( "Computer" ) );
- catList->insertItem( tr( "DVDs" ) );
- catList->insertItem( tr( "Electronics" ) );
- catList->insertItem( tr( "Entertainment" ) );
- catList->insertItem( tr( "Food" ) );
- catList->insertItem( tr( "Gasoline" ) );
- catList->insertItem( tr( "Misc" ) );
- catList->insertItem( tr( "Movies" ) );
- catList->insertItem( tr( "Rent" ) );
- catList->insertItem( tr( "Travel" ) );
- catList->setCurrentItem( 0 );
+ 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" ) );
@@ -255,10 +248,13 @@ void Transaction::slotWithdrawalClicked()
void Transaction::slotDepositClicked()
{
catList->clear();
- catList->insertItem( tr( "Work" ) );
- catList->insertItem( tr( "Family Member" ) );
- catList->insertItem( tr( "Misc. Credit" ) );
- catList->setCurrentItem( 0 );
+ 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" ) );
diff --git a/noncore/apps/checkbook/transaction.h b/noncore/apps/checkbook/transaction.h
index 000aee7..fbe9cd3 100644
--- a/noncore/apps/checkbook/transaction.h
+++ b/noncore/apps/checkbook/transaction.h
@@ -40,20 +40,20 @@ class QRadioButton;
class QString;
class QWidget;
class TranInfo;
+class Cfg;
class Transaction : public QDialog
{
Q_OBJECT
public:
- Transaction( QWidget * = 0x0, const QString & = 0x0, TranInfo * = 0x0,
- const QString & = "$" );
+ Transaction( QWidget *, const QString &, TranInfo *, Cfg *);
~Transaction();
private:
TranInfo *tran;
- QString currencySymbol;
+ Cfg *_pCfg;
QRadioButton *withBtn;
QRadioButton *depBtn;