summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp196
-rw-r--r--noncore/apps/checkbook/cbinfo.h97
-rw-r--r--noncore/apps/checkbook/checkbook.cpp235
-rw-r--r--noncore/apps/checkbook/checkbook.h25
-rw-r--r--noncore/apps/checkbook/checkbook.pro28
-rw-r--r--noncore/apps/checkbook/configuration.cpp76
-rw-r--r--noncore/apps/checkbook/configuration.h51
-rw-r--r--noncore/apps/checkbook/graph.cpp9
-rw-r--r--noncore/apps/checkbook/graph.h1
-rw-r--r--noncore/apps/checkbook/graphinfo.h2
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp230
-rw-r--r--noncore/apps/checkbook/mainwindow.h30
-rw-r--r--noncore/apps/checkbook/traninfo.h16
13 files changed, 753 insertions, 243 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp
new file mode 100644
index 0000000..3a39317
--- a/dev/null
+++ b/noncore/apps/checkbook/cbinfo.cpp
@@ -0,0 +1,196 @@
+/*
+                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 "cbinfo.h"
+#include "traninfo.h"
+
+#include <qpe/config.h>
+
+#include <qfile.h>
+
+CBInfo::CBInfo()
+{
+ n = "";
+ fn = "";
+ pw = QString::null;
+ t = "";
+ bn = "";
+ a = "";
+ p = "";
+ nt = "";
+ sb = 0.0;
+
+ tl = new TranInfoList();
+}
+
+CBInfo::CBInfo( const QString &name, const QString &filename )
+{
+ Config config( filename, Config::File );
+ config.setGroup( "Account" );
+
+ n = name;
+ fn = filename;
+ pw = config.readEntryCrypt( "Password", QString::null );
+
+ t = config.readEntry( "Type" );
+ bn = config.readEntry( "Bank", "" );
+ a = config.readEntryCrypt( "Number", "" );
+ p = config.readEntryCrypt( "PINNumber", "" );
+ nt = config.readEntry( "Notes", "" );
+
+ bool ok;
+ sb = config.readEntry( "Balance", "0.0" ).toFloat( &ok );
+
+ loadTransactions();
+}
+
+float CBInfo::balance()
+{
+ calcBalance();
+ return b;
+}
+
+void CBInfo::write()
+{
+ QFile f( fn );
+ if ( f.exists() )
+ {
+ f.remove();
+ }
+
+ Config *config = new Config(fn, Config::File);
+
+ // Save info
+ config->setGroup( "Account" );
+ config->writeEntryCrypt( "Password", pw );
+ config->writeEntry( "Type", t );
+ config->writeEntry( "Bank", bn );
+ config->writeEntryCrypt( "Number", a );
+ config->writeEntryCrypt( "PINNumber", p );
+ config->writeEntry( "Notes", n );
+ QString balstr;
+ balstr.setNum( sb, 'f', 2 );
+ config->writeEntry( "Balance", balstr );
+
+ // Save transactions
+ int i = 1;
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
+ {
+ tran->write( config, i );
+ i++;
+ }
+ config->write();
+
+ delete config;
+}
+
+TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date,
+ const QString &desc )
+{
+ TranInfo *traninfo = tl->first();
+ while ( traninfo )
+ {
+ if ( traninfo->number() == checknum && traninfo->datestr() == date &&
+ traninfo->desc() == desc )
+ break;
+ traninfo = tl->next();
+ }
+ return( traninfo );
+}
+
+void CBInfo::addTransaction( TranInfo *tran )
+{
+ tl->inSort( tran );
+ calcBalance();
+}
+
+void CBInfo::removeTransaction( TranInfo *tran )
+{
+ tl->remove( tran );
+ delete tran;
+ calcBalance();
+}
+
+void CBInfo::loadTransactions()
+{
+ TranInfo *tran;
+ QString trandesc = "";
+
+ 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();
+}
+
+void CBInfo::calcBalance()
+{
+ float amount;
+
+ b = sb;
+
+ for ( TranInfo *tran = tl->first(); tran; tran = tl->next() )
+ {
+ b -= tran->fee();
+ amount = tran->amount();
+ if ( tran->withdrawal() )
+ {
+ amount *= -1;
+ }
+ b += amount;
+ }
+}
+
+int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )
+{
+ QString n1 = ((CBInfo *)item1)->name();
+ QString n2 = ((CBInfo *)item2)->name();
+ int r = -1;
+
+ if ( n1 < n2 )
+ r = -1;
+ else if ( n1 == n2 )
+ r = 0;
+ else if ( n1 > n2 )
+ r = 1;
+ return( r );
+}
diff --git a/noncore/apps/checkbook/cbinfo.h b/noncore/apps/checkbook/cbinfo.h
new file mode 100644
index 0000000..5e65db2
--- a/dev/null
+++ b/noncore/apps/checkbook/cbinfo.h
@@ -0,0 +1,97 @@
+/*
+                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 CBINFO_H
+#define CBINFO_H
+
+#include <qlist.h>
+#include <qstring.h>
+
+class Config;
+class TranInfo;
+class TranInfoList;
+
+class CBInfo
+{
+ public:
+ CBInfo();
+ CBInfo( const QString &, const QString & );
+
+ const QString &name() const { return n; }
+ const QString &filename() const { return fn; }
+ const QString &password() const { return pw; }
+ const QString &type() const { return t; }
+ const QString &bank() const { return bn; }
+ const QString &account() const { return a; }
+ const QString &pin() const { return p; }
+ const QString &notes() const { return nt; }
+ float startingBalance() const { return sb; }
+ float balance();
+
+ void setName( const QString &name ) { n = name; }
+ void setFilename( const QString &filename ) { fn = filename; }
+ void setPassword( const QString &password ) { pw = password; }
+ void setType( const QString &type ) { t = type; }
+ void setBank( const QString &bank ) { bn = bank; }
+ void setAccount( const QString &account ) { a = account; }
+ void setPin( const QString &pin ) { p = pin; }
+ void setNotes( const QString &notes ) { nt = notes; }
+ void setStartingBalance( float startbal ) { sb = startbal; }
+
+ void write();
+
+ TranInfoList *transactions() const { return tl; }
+ TranInfo *findTransaction( const QString &, const QString &, const QString & );
+ void addTransaction( TranInfo * );
+ void removeTransaction( TranInfo * );
+
+ private:
+ QString n;
+ QString fn;
+ QString pw;
+ QString t;
+ QString bn;
+ QString a;
+ QString p;
+ QString nt;
+ float sb;
+ float b;
+
+ TranInfoList *tl;
+
+ void loadTransactions();
+ void calcBalance();
+};
+
+class CBInfoList : public QList<CBInfo>
+{
+ protected:
+ int compareItems( QCollection::Item, QCollection::Item );
+};
+
+#endif
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 5a6d607..7a6b7cc 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -1,150 +1,142 @@
/*
                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 "checkbook.h"
+#include "cbinfo.h"
#include "transaction.h"
+#include "traninfo.h"
#include "graph.h"
#include "graphinfo.h"
#include "password.h"
#include <opie/otabwidget.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qfile.h>
#include <qfontmetrics.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
#include <qwidget.h>
-Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol )
+Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
- name = n;
- filename = fd;
- filename.append( name );
- filename.append( ".qcb" );
- filedir = fd;
+ info = i;
currencySymbol = symbol;
- currBalance = 0.0;
- if ( name != "" )
+ if ( info->name() != "" )
{
- QString tempstr = 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" ) );
mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) );
mainWidget->setCurrentTab( tr( "Info" ) );
// Load checkbook information
loadCheckbook();
}
Checkbook::~Checkbook()
{
}
-const QString &Checkbook::getName()
-{
- return( name );
-}
-
QWidget *Checkbook::initInfo()
{
QWidget *control = new QWidget( mainWidget );
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( 2 );
layout->setMargin( 4 );
// Password protection
passwordCB = new QCheckBox( tr( "Password protect" ), container );
QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) );
connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) );
layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 );
// Account name
QLabel *label = new QLabel( tr( "Name:" ), container );
QWhatsThis::add( label, tr( "Enter name of checkbook here." ) );
layout->addWidget( label, 1, 0 );
nameEdit = new QLineEdit( container );
QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) );
connect( nameEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( slotNameChanged( const QString & ) ) );
layout->addWidget( nameEdit, 1, 1 );
// Type of account
label = new QLabel( tr( "Type:" ), container );
QWhatsThis::add( label, tr( "Select type of checkbook here." ) );
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 );
@@ -228,488 +220,439 @@ QWidget *Checkbook::initTransactions()
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 );
}
QWidget *Checkbook::initCharts()
{
graphInfo = 0x0;
QWidget *control = new QWidget( mainWidget );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
graphWidget = new Graph( control );
QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) );
layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 );
graphList = new QComboBox( control );
QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) );
graphList->insertItem( tr( "Account balance" ) );
graphList->insertItem( tr( "Withdrawals by category" ) );
graphList->insertItem( tr( "Deposits by category" ) );
layout->addMultiCellWidget( graphList, 1, 1, 0, 1 );
QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control );
QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) );
layout->addWidget( btn, 1, 2 );
return control;
}
void Checkbook::loadCheckbook()
{
- transactions.clear();
-
- Config config( filename, Config::File );
+ if ( !info )
+ {
+ return;
+ }
- // Load info
- config.setGroup( "Account" );
+ tranList = info->transactions();
- password = config.readEntryCrypt( "Password", "" );
- passwordCB->setChecked( password != "" );
- nameEdit->setText( name );
- QString temptext = config.readEntry( "Type" );
+ passwordCB->setChecked( !info->password().isNull() );
+ nameEdit->setText( info->name() );
+ QString temptext = info->type();
int i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
- bankEdit->setText( config.readEntry( "Bank", "" ) );
- acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) );
- pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) );
- balanceEdit->setText( config.readEntry( "Balance", "0.0" ) );
- notesEdit->setText( config.readEntry( "Notes", "" ) );
-
- bool ok;
- currBalance = balanceEdit->text().toFloat( &ok );
- startBalance = currBalance;
+ 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
- TranInfo *tran;
- QString trandesc = "";
float amount;
QString stramount;
- for ( int i = 1; trandesc != QString::null; i++ )
- {
- tran = new TranInfo( config, i );
- trandesc = tran->desc();
- if ( trandesc != QString::null )
- {
- currBalance -= tran->fee();
- amount = tran->amount();
- if ( tran->withdrawal() )
- {
- amount *= -1;
- }
- currBalance += amount;
- stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
-
- // Add to transaction list
- transactions.inSort( tran );
- // Add to transaction table
- ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount );
- }
- else
+ for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
+ {
+ amount = tran->amount();
+ if ( tran->withdrawal() )
{
- delete tran;
+ amount *= -1;
}
+ stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
+ ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount );
}
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
- highTranNum = transactions.count();
+ balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
+
+ highTranNum = tranList->count();
}
-void Checkbook::adjustBalance( float amount )
+void Checkbook::adjustBalance()
{
- currBalance += amount;
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
-
+ balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) );
}
TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc )
{
- TranInfo *traninfo = transactions.first();
+ TranInfo *traninfo = tranList->first();
while ( traninfo )
{
if ( traninfo->number() == checknum && traninfo->datestr() == date &&
traninfo->desc() == desc )
break;
- traninfo = transactions.next();
+ traninfo = tranList->next();
}
return( traninfo );
}
void Checkbook::accept()
{
- QFile f( filename );
- if ( f.exists() )
- {
- f.remove();
- }
-
- Config *config = new Config(filename, Config::File);
-
- // Save info
- config->setGroup( "Account" );
- config->writeEntryCrypt( "Password", password );
- config->writeEntry( "Type", typeList->currentText() );
- config->writeEntry( "Bank", bankEdit->text() );
- config->writeEntryCrypt( "Number", acctNumEdit->text() );
- config->writeEntryCrypt( "PINNumber", pinNumEdit->text() );
- config->writeEntry( "Balance", balanceEdit->text() );
- config->writeEntry( "Notes", notesEdit->text() );
-
- // Save transactions
- int i = 1;
- for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
- {
- tran->write( config, i );
- i++;
- }
- config->write();
+ 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();
}
void Checkbook::slotPasswordClicked()
{
- if ( password == "" && passwordCB->isChecked() )
+ 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;
}
- password = pw->password;
+ 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 != password )
+ if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
{
passwordCB->setChecked( FALSE );
- password = "";
+ info->setPassword( QString::null );
}
delete pw;
}
- else if ( password != "" && !passwordCB->isChecked() )
+ 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 == password )
+ if ( pw->exec() == QDialog::Accepted && pw->password == info->password() )
{
- password = "";
+ info->setPassword( QString::null );
delete pw;
return;
}
else
{
passwordCB->setChecked( TRUE );
}
delete pw;
}
}
void Checkbook::slotNameChanged( const QString &newname )
{
- name = newname;
- filename = filedir;
- filename.append( newname );
- filename.append( ".qcb" );
- QString tempstr = name;
- tempstr.append( " - " );
- tempstr.append( tr( "Checkbook" ) );
- setCaption( tempstr );
+ 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 );
}
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
- currBalance -= startBalance;
bool ok;
- startBalance = newbalance.toFloat( &ok );
- adjustBalance( startBalance );
+ info->setStartingBalance( newbalance.toFloat( &ok ) );
+ adjustBalance();
}
void Checkbook::slotNewTran()
{
highTranNum++;
TranInfo *traninfo = new TranInfo( highTranNum );
- Transaction *currtran = new Transaction( this, name,
+ Transaction *currtran = new Transaction( this, info->name(),
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
- float amount = traninfo->amount();
+ // Add to transaction list
+ info->addTransaction( traninfo );
+
+ // Add to transaction table
+ float amount;
+ QString stramount;
+
+ amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
- QString stramount;
stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
- // Add to transaction list
- transactions.inSort( traninfo );
-
- // Add to transaction table
( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(),
stramount );
- adjustBalance( amount );
+ adjustBalance();
}
else
{
highTranNum--;
delete traninfo;
}
}
void Checkbook::slotEditTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
- TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
- float origamt = traninfo->amount();
- if ( traninfo->withdrawal() )
- {
- origamt *= -1;
- }
+ TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ),
+ curritem->text( 2 ) );
- Transaction *currtran = new Transaction( this, name,
+ Transaction *currtran = new Transaction( this, info->name(),
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
+ curritem->setText( 0, traninfo->number() );
curritem->setText( 1, traninfo->datestr() );
-
curritem->setText( 2, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
- adjustBalance( origamt * -1 );
- adjustBalance( amount );
QString stramount;
stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount );
curritem->setText( 3, stramount );
- balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
-
- delete currtran;
+ adjustBalance();
}
+
+ delete currtran;
}
void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
- float amount = traninfo->amount();
- if ( traninfo->withdrawal() )
- {
- amount *= -1;
- }
-
- transactions.remove( traninfo );
- delete traninfo;
+ info->removeTransaction( traninfo );
delete curritem;
-
- adjustBalance( amount * -1 );
+ 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 = startBalance;
+ float balance = info->startingBalance();
float amount;
QString label;
int i = 0;
- int count = transactions.count();
+ int count = tranList->count();
- for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
+ 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();
}
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 = transactions.first();
+ TranInfo *tran = tranList->first();
if ( tran && tran->withdrawal() == withdrawals )
{
list->append( new DataPointInfo( tran->category(), tran->amount() ) );
}
- tran = transactions.next();
+ tran = tranList->next();
DataPointInfo *cat;
- for ( ; tran; tran = transactions.next() )
+ 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() )
{
break;
}
}
if ( cat && cat->label() == tran->category() )
{ // Found category, add to transaction to category total
cat->addToValue( tran->amount() );
}
else
{ // Didn't find category, add category to list
list->append( new DataPointInfo( tran->category(), tran->amount() ) );
}
}
}
graphInfo = new GraphInfo( GraphInfo::PieChart, list );
}
CBListItem::CBListItem( 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 )
{
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, QColor( 200, 255, 200 ) );
QListViewItem::paintCell(p, _cg, column, width, align);
}
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;
-} \ No newline at end of file
+}
diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h
index 27658ff..4a5011b 100644
--- a/noncore/apps/checkbook/checkbook.h
+++ b/noncore/apps/checkbook/checkbook.h
@@ -1,133 +1,126 @@
/*
                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 CHECKBOOK_H
#define CHECKBOOK_H
-#include "traninfo.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 Checkbook : public QDialog
{
Q_OBJECT
public:
- Checkbook( QWidget * = 0x0, const QString & = 0x0, const QString & = 0x0,
- const QString & = "$" );
+ Checkbook( QWidget * = 0x0, CBInfo * = 0x0, const QString & = "$" );
~Checkbook();
- const QString &getName();
-
private:
- TranInfoList transactions;
- QString name;
- QString filename;
- QString filedir;
- QString currencySymbol;
- QString password;
- int highTranNum;
+ CBInfo *info;
+ TranInfoList *tranList;
+ QString currencySymbol;
+ int highTranNum;
OTabWidget *mainWidget;
void loadCheckbook();
- void adjustBalance( float );
+ void adjustBalance();
TranInfo *findTran( const QString &, const QString &, const QString & );
// Info tab
QWidget *initInfo();
QCheckBox *passwordCB;
QLineEdit *nameEdit;
QComboBox *typeList;
QLineEdit *bankEdit;
QLineEdit *acctNumEdit;
QLineEdit *pinNumEdit;
QLineEdit *balanceEdit;
QMultiLineEdit *notesEdit;
- float startBalance;
// Transactions tab
QWidget *initTransactions();
QListView *tranTable;
QLabel *balanceLabel;
- float currBalance;
// Charts tab
QWidget *initCharts();
GraphInfo *graphInfo;
QComboBox *graphList;
Graph *graphWidget;
void drawBalanceChart();
void drawCategoryChart( bool = TRUE );
protected slots:
void accept();
private slots:
void slotPasswordClicked();
void slotNameChanged( const QString & );
void slotStartingBalanceChanged( const QString & );
void slotNewTran();
void slotEditTran();
void slotDeleteTran();
void slotDrawGraph();
};
class CBListItem : public QListViewItem
{
//Q_OBJECT
public:
CBListItem( 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 );
private:
QListView *owner;
bool m_known;
bool m_odd;
bool isAltBackground();
};
#endif
diff --git a/noncore/apps/checkbook/checkbook.pro b/noncore/apps/checkbook/checkbook.pro
index 53b5ff4..05cac15 100644
--- a/noncore/apps/checkbook/checkbook.pro
+++ b/noncore/apps/checkbook/checkbook.pro
@@ -1,38 +1,42 @@
TEMPLATE = app
CONFIG = qt warn_on release
HEADERS = mainwindow.h \
- traninfo.h \
- graphinfo.h \
- password.h \
- checkbook.h \
- transaction.h \
+ cbinfo.h \
+ traninfo.h \
+ graphinfo.h \
+ configuration.h \
+ password.h \
+ checkbook.h \
+ transaction.h \
graph.h
-SOURCES = main.cpp \
- mainwindow.cpp \
- traninfo.cpp \
- graphinfo.cpp \
- password.cpp \
- checkbook.cpp \
- transaction.cpp \
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ cbinfo.cpp \
+ traninfo.cpp \
+ graphinfo.cpp \
+ configuration.cpp \
+ password.cpp \
+ checkbook.cpp \
+ transaction.cpp \
graph.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = checkbook
DESTDIR = $(OPIEDIR)/bin
TRANSLATIONS = ../../../i18n/de/checkbook.ts \
../../../i18n/en/checkbook.ts \
../../../i18n/es/checkbook.ts \
../../../i18n/fr/checkbook.ts \
../../../i18n/hu/checkbook.ts \
../../../i18n/ja/checkbook.ts \
../../../i18n/ko/checkbook.ts \
../../../i18n/no/checkbook.ts \
../../../i18n/pl/checkbook.ts \
../../../i18n/pt/checkbook.ts \
../../../i18n/pt_BR/checkbook.ts \
../../../i18n/sl/checkbook.ts \
../../../i18n/zh_CN/checkbook.ts \
../../../i18n/zh_TW/checkbook.ts \
../../../i18n/it/checkbook.ts
diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp
new file mode 100644
index 0000000..37208da
--- a/dev/null
+++ b/noncore/apps/checkbook/configuration.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 "configuration.h"
+
+#include <qcheckbox.h>
+#include <qfontmetrics.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qstring.h>
+#include <qwhatsthis.h>
+
+Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool sb )
+ : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
+{
+ setCaption( tr( "Configure Checkbook" ) );
+
+ QFontMetrics fm = fontMetrics();
+ int fh = fm.height();
+
+ QGridLayout *layout = new QGridLayout( this );
+ layout->setSpacing( 4 );
+ layout->setMargin( 4 );
+
+ QLabel *label = new QLabel( tr( "Enter currency symbol:" ), this );
+ QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) );
+ label->setMaximumHeight( fh + 3 );
+ layout->addWidget( label, 0, 0 );
+
+ symbolEdit = new QLineEdit( cs, this );
+ 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 );
+ 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 );
+ layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 );
+
+ balCB = new QCheckBox( tr( "Show checkbook balances" ), this );
+ 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 );
+ layout->addMultiCellWidget( balCB, 2, 2, 0, 1 );
+}
+
+Configuration::~Configuration()
+{
+}
diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h
new file mode 100644
index 0000000..9a8de02
--- a/dev/null
+++ b/noncore/apps/checkbook/configuration.h
@@ -0,0 +1,51 @@
+/*
+                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 CONFIGURATION_H
+#define CONFIGURATION_H
+
+#include <qdialog.h>
+
+class QCheckBox;
+class QLineEdit;
+class QString;
+
+class Configuration : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ Configuration( QWidget * = 0x0, const QString & = "$", bool = FALSE, bool = FALSE );
+ ~Configuration();
+
+ QLineEdit *symbolEdit;
+ QCheckBox *lockCB;
+ QCheckBox *balCB;
+};
+
+#endif
diff --git a/noncore/apps/checkbook/graph.cpp b/noncore/apps/checkbook/graph.cpp
index 8ae835c..acdb846 100644
--- a/noncore/apps/checkbook/graph.cpp
+++ b/noncore/apps/checkbook/graph.cpp
@@ -42,140 +42,131 @@ Graph::Graph( QWidget *parent, GraphInfo *d, const QString &name, int flags )
graph.setOptimization( QPixmap::BestOptim );
}
void Graph::setGraphInfo( GraphInfo *d )
{
data = d;
}
void Graph::drawGraph( bool regen )
{
if ( regen )
{
initGraph();
}
QPainter p( this );
p.drawPixmap( 0, 0, graph );
}
void Graph::paintEvent( QPaintEvent * )
{
drawGraph( FALSE );
}
void Graph::resizeEvent( QResizeEvent * )
{
drawGraph( TRUE );
}
void Graph::initGraph()
{
graph.resize( width(), height() );
graph.fill( QColor( 255, 255, 255 ) );
if ( !data )
{
return;
}
// Any common stuff here (titles, ???)
switch ( data->graphType() )
{
case GraphInfo::BarChart :
{
drawBarChart( width(), height(), data->maxValue() );
}
break;
- case GraphInfo::LineChart :
- {
- //drawLineChart( p, s, min, max );
- }
- break;
case GraphInfo::PieChart :
{
drawPieChart( width(), height(), data->totalValue() );
}
};
}
void Graph::drawBarChart( int width, int height, float max )
{
QPainter p( &graph );
// Try to set the font size smaller for text
QFont f = font();
f.setPointSize( 8 );
p.setFont( f );
int x = 0;
int i = 0;
int n = data->numberDataPoints();
QFontMetrics fm=fontMetrics();
int fh = fm.height();
int fw;
QColor c( 0, 0, 255);
p.setBrush( c );
for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() )
{
int bw = ( width - width / 4 - x ) / ( n - i );
int bh = int( ( height - height / 4 - 1 ) * dp->value() / max );
p.drawRect( width / 8 + x, height - height / 8 - 1 - bh, bw, bh );
fw = fm.width( dp->label() );
p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8, fw,
fh + height / 8, AlignTop | AlignHCenter, dp->label() );
// WordBreak | AlignTop | AlignHCenter, dp->label() );
i++;
x += bw;
}
}
-void Graph::drawLineChart( int width, int height, float max )
-{
-}
-
void Graph::drawPieChart( int width, int height, float sum )
{
QPainter p( &graph );
// Try to set the font size smaller for text
QFont f = font();
f.setPointSize( 8 );
p.setFont( f );
int n = data->numberDataPoints();
int apos = -90 * 16;
int xd = width - width / 5;
int yd = height - height / 5;
int i = 0;
QColor c;
for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() )
{
c.setHsv( ( i *255) / n, 255, 255 );
p.setBrush( c );
int a = int( ( dp->value() * 360.0 ) / sum * 16.0 + 0.5 );
p.drawPie( width/10, height/10, xd, yd, -apos, -a );
apos += a;
i++;
}
double apos2 = -90 * 3.14159 / 180;
for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() )
{
double a = dp->value() *360 / sum * 3.14159 / 180;
int x = int( cos( apos2 + a/2 ) * width * 5/16 + width/2 + 0.5 );
int y = int( sin( apos2 + a/2 ) * height * 5/16 + height/2 + 0.5 );
p.drawText( x - width/8, y - height/8, width/4, height/4, WordBreak | AlignCenter,
dp->label() );
apos2 += a;
}
}
diff --git a/noncore/apps/checkbook/graph.h b/noncore/apps/checkbook/graph.h
index 0361718..340e910 100644
--- a/noncore/apps/checkbook/graph.h
+++ b/noncore/apps/checkbook/graph.h
@@ -12,53 +12,52 @@
    .%`+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 GRAPH_H
#define GRAPH_H
#include <qpixmap.h>
#include <qwidget.h>
class GraphInfo;
class QPainter;
class Graph : public QWidget
{
Q_OBJECT
public:
Graph( QWidget * = 0x0, GraphInfo * = 0x0, const QString & = 0x0, int = 0 );
void setGraphInfo( GraphInfo * );
void drawGraph( bool = FALSE );
protected:
void paintEvent( QPaintEvent * );
void resizeEvent( QResizeEvent * );
private:
GraphInfo *data;
QPixmap graph;
void initGraph();
void drawBarChart( int, int, float );
- void drawLineChart( int, int, float );
void drawPieChart( int, int, float );
};
#endif
diff --git a/noncore/apps/checkbook/graphinfo.h b/noncore/apps/checkbook/graphinfo.h
index 3bcf676..41927b4 100644
--- a/noncore/apps/checkbook/graphinfo.h
+++ b/noncore/apps/checkbook/graphinfo.h
@@ -10,79 +10,79 @@
 - .   .-<_>     .<> 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 GRAPHINFO_H
#define GRAPHINFO_H
#include <qlist.h>
#include <qstringlist.h>
class DataPointInfo
{
public:
DataPointInfo()
: l( 0x0 ), v( 0.0 ) {}
DataPointInfo( const QString &label, float value )
: l( label ), v( value ) {}
const QString &label() { return l; }
float value() { return v; }
void addToValue( float value ) { v += value; }
private:
QString l;
float v;
};
typedef QList<DataPointInfo> DataPointList;
class GraphInfo
{
public:
- enum GraphType { BarChart, LineChart, PieChart };
+ enum GraphType { BarChart, PieChart };
GraphInfo( GraphType = BarChart, DataPointList * = 0x0,
const QString & = 0x0, const QString & = 0x0, const QString & = 0x0 );
~GraphInfo();
GraphInfo::GraphType graphType();
void setGraphType( GraphType );
DataPointList *dataPoints();
void setDataPoints( DataPointList * );
DataPointInfo *firstDataPoint();
DataPointInfo *nextDataPoint();
int numberDataPoints();
float maxValue();
float totalValue();
void setGraphTitle( const QString & );
void setXAxisTitle( const QString & );
void setYAxisTitle( const QString & );
private:
GraphType t;
DataPointList *d;
QString gt;
QString xt;
QString yt;
};
#endif
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index 2c0abf1..68c6aee 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -1,186 +1,332 @@
/*
                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 "mainwindow.h"
+#include "cbinfo.h"
+#include "configuration.h"
#include "password.h"
#include "checkbook.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 <qlistbox.h>
+#include <qlineedit.h>
+#include <qlistview.h>
#include <qpopupmenu.h>
#include <qstring.h>
#include <qwhatsthis.h>
MainWindow::MainWindow()
: QMainWindow( 0x0, 0x0, WStyle_ContextHelp )
{
setCaption( tr( "Checkbook" ) );
cbDir = Global::applicationFileName( "checkbook", "" );
+ lockIcon = Resource::loadPixmap( "locked" );
+
+ // Load configuration options
+ Config config( "checkbook" );
+ config.setGroup( "Config" );
+ currencySymbol = config.readEntry( "CurrencySymbol", "$" );
+ showLocks = config.readBoolEntry( "ShowLocks", FALSE );
+ showBalances = config.readBoolEntry( "ShowBalances", FALSE );
// 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 );
- mb->insertItem( tr( "Checkbook" ), popup );
+ popup->insertSeparator();
- // Build Checkbook selection list control
- cbList = new QListBox( this );
- QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
- QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
- connect( cbList, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint & ) ),
- this, SLOT( slotEdit() ) );
- setCentralWidget( cbList );
+ a = new QAction( tr( "Configure" ), Resource::loadPixmap( "checkbook/config" ), QString::null, 0, this, 0 );
+ a->setWhatsThis( tr( "Click here to configure this app." ) );
+ connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) );
+ a->addTo( popup );
+ a->addTo( bar );
+
+ mb->insertItem( tr( "Checkbook" ), popup );
// Load Checkbook selection list
+ checkbooks = new CBInfoList();
+
QDir checkdir( cbDir );
if (checkdir.exists() == true)
{
- QStringList checkbooks = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
+ QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
QDir::Time );
- for ( QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++ )
+ CBInfo *cb = 0x0;
+ QString filename;
+
+ for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ )
{
- (*it) = (*it).remove( (*it).find('.'), (*it).length() );
+ filename = cbDir;
+ filename.append( (*it) );
+
+ cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename );
+ checkbooks->inSort( cb );
}
- cbList->insertStringList( checkbooks );
}
- cbList->sort();
- cbList->setSelected( 0, TRUE );
- currencySymbol = "$";
+ // Build Checkbook selection list control
+ cbList = 0x0;
+ buildList();
}
MainWindow::~MainWindow()
{
+// config.write();
+}
+
+void MainWindow::buildList()
+{
+ if ( cbList )
+ {
+ delete cbList;
+ }
+
+ cbList = new QListView( this );
+ QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
+
+ if ( showLocks )
+ {
+ cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
+ posName = 1;
+ }
+ else
+ {
+ posName = 0;
+ }
+ cbList->addColumn( tr( "Checkbook Name" ) );
+ if ( showBalances )
+ {
+ int colnum = cbList->addColumn( tr( "Balance" ) );
+ cbList->setColumnAlignment( colnum, Qt::AlignRight );
+ }
+ cbList->setAllColumnsShowFocus( TRUE );
+ cbList->setSorting( posName );
+ QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
+ connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
+ this, SLOT( slotEdit() ) );
+ setCentralWidget( cbList );
+
+ for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
+ {
+ addCheckbook( cb );
+ }
+}
+
+void MainWindow::addCheckbook( CBInfo *cb )
+{
+ QListViewItem *lvi = new QListViewItem( cbList );
+ if ( showLocks && !cb->password().isNull() )
+ {
+ lvi->setPixmap( 0, lockIcon );
+ }
+ lvi->setText( posName, cb->name() );
+ if ( showBalances )
+ {
+ QString balance;
+ balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ lvi->setText( posName + 1, balance );
+ }
+}
+
+void MainWindow::buildFilename( const QString &name )
+{
+ tempFilename = cbDir;
+ tempFilename.append( name );
+ tempFilename.append( ".qcb" );
}
void MainWindow::slotNew()
{
- Checkbook *currcb = new Checkbook( this, "", cbDir, currencySymbol );
+ CBInfo *cb = new CBInfo();
+
+ Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
- cbList->insertItem( currcb->getName() );
- cbList->sort();
- delete currcb;
+ checkbooks->inSort( cb );
+ addCheckbook( cb );
}
+ delete currcb;
}
void MainWindow::slotEdit()
{
- QString currname = cbList->currentText();
-
- QString tempstr = cbDir;
- tempstr.append( currname );
- tempstr.append( ".qcb" );
-
- Config config( tempstr, Config::File );
- config.setGroup( "Account" );
- QString password = config.readEntryCrypt( "Password", "" );
- if ( password != "" )
+
+ QListViewItem *curritem = cbList->currentItem();
+ if ( !curritem )
+ {
+ return;
+ }
+ QString currname = curritem->text( posName );
+
+ CBInfo *cb = checkbooks->first();
+ while ( cb )
+ {
+ if ( cb->name() == currname )
+ break;
+ cb = checkbooks->next();
+ }
+ if ( !cb )
+ {
+ return;
+ }
+
+ buildFilename( currname );
+ float currbalance = cb->balance();
+ bool currlock = !cb->password().isNull();
+
+ if ( currlock )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
- if ( pw->exec() != QDialog::Accepted || pw->password != password )
+ if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
{
delete pw;
return;
}
delete pw;
}
- Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol );
+ Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
currcb->showMaximized();
if ( currcb->exec() == QDialog::Accepted )
{
- QString newname = currcb->getName();
+ QString newname = cb->name();
if ( currname != newname )
{
- cbList->changeItem( newname, cbList->currentItem() );
+ // Update name if changed
+ curritem->setText( posName, newname );
cbList->sort();
- QFile f( tempstr );
+ // 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 ( showLocks && !cb->password().isNull() != currlock )
+ {
+ if ( !cb->password().isNull() )
+ curritem->setPixmap( 0, lockIcon );
+ else
+ curritem->setPixmap( 0, nullIcon );
+ }
+
+ // Update balance if changed
+ if ( showBalances && cb->balance() != currbalance )
+ {
+ QString tempstr;
+ tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
+ curritem->setText( posName + 1, tempstr );
}
- delete currcb;
}
+ delete currcb;
}
void MainWindow::slotDelete()
{
- if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), cbList->currentText() ) )
+ QString currname = cbList->currentItem()->text( posName );
+
+ if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
{
- QString tempstr = cbDir;
- tempstr.append( cbList->currentText() );
- tempstr.append( ".qcb" );
- QFile f( tempstr );
+ buildFilename( currname );
+ QFile f( tempFilename );
if ( f.exists() )
{
f.remove();
}
- cbList->removeItem( cbList->currentItem() );
+ delete cbList->currentItem();
+ }
+}
+
+void MainWindow::slotConfigure()
+{
+ Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances );
+ 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();
+
+ buildList();
}
+ delete cfgdlg;
}
diff --git a/noncore/apps/checkbook/mainwindow.h b/noncore/apps/checkbook/mainwindow.h
index 11a3343..2bc70b3 100644
--- a/noncore/apps/checkbook/mainwindow.h
+++ b/noncore/apps/checkbook/mainwindow.h
@@ -1,60 +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.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <qmainwindow.h>
+#include <qpixmap.h>
+class CBInfo;
+class CBInfoList;
class QAction;
-class QListBox;
-class QListBoxItem;
+class QListView;
class QString;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private:
- QListBox *cbList;
- QString cbDir;
- QAction *actionOpen;
- QAction *actionDelete;
- QString currencySymbol;
+ QListView *cbList;
+ QString cbDir;
+ QAction *actionOpen;
+ QAction *actionDelete;
+
+ QString currencySymbol;
+ bool showLocks;
+ bool showBalances;
+ int posName;
+
+ CBInfoList *checkbooks;
+ QString tempFilename;
+ QPixmap lockIcon;
+ QPixmap nullIcon;
+
+ void buildList();
+ void addCheckbook( CBInfo * );
+ void buildFilename( const QString & );
private slots:
void slotNew();
void slotEdit();
void slotDelete();
+ void slotConfigure();
};
#endif
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h
index 59cfe14..5f67262 100644
--- a/noncore/apps/checkbook/traninfo.h
+++ b/noncore/apps/checkbook/traninfo.h
@@ -8,85 +8,83 @@
:`=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 TRANINFO_H
#define TRANINFO_H
#include <qdatetime.h>
#include <qlist.h>
#include <qstring.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 );
TranInfo( Config, int );
int id() const { return i; }
const QString &desc() const { return d; }
const QDate &date() const { return td; }
const QString &datestr();
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 &number() const { return cn; }
const QString &notes() const { return n; }
void setDesc( const QString &desc ) { d = desc; }
- void setDate( const QDate &date ) { td = date; }
- void setWithdrawal( bool withdrawal ) { w = withdrawal; }
+ 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 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 write( Config *, int );
private:
int i;
QString d;
QDate td;
bool w;
QString t;
QString c;
float a;
float f;
QString cn;
QString n;
};
class TranInfoList : public QList<TranInfo>
{
protected:
int compareItems( QCollection::Item, QCollection::Item );
};
-//typedef TranList<TranInfo> TranInfoList;
-
#endif