summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp59
1 files changed, 29 insertions, 30 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 4b81c6d..20b42b5 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -19,54 +19,61 @@
++=   -.     .`     .:
 :     =  ...= . :.=- 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 "transaction.h"
+#include "graph.h"
+#include "graphinfo.h"
#include <opie/otabwidget.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qcombobox.h>
#include <qfile.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
#include <qwidget.h>
Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
name = n;
- filename = fd + name + ".qcb";
+ filename = fd;
+ filename.append( name );
+ filename.append( ".qcb" );
filedir = fd;
currencySymbol = symbol;
currBalance = 0.0;
if ( name != "" )
{
- setCaption( name + " - " + tr( "Checkbook" ) );
+ QString tempstr = 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
@@ -233,31 +240,32 @@ QWidget *Checkbook::initCharts()
/*
QLabel *label = new QLabel( control );
label->setText( tr( "Graph type:" ) );
layout->addWidget( label, 0, 0 );
graphList = new QComboBox( control );
graphList->insertItem( tr( "By category" ) );
graphList->insertItem( tr( "..." ) );
graphList->insertItem( tr( "..." ) );
layout->addWidget( graphList, 0, 1 );
*/
- QWidget *graphWidget = new QWidget( control );
- QWhatsThis::add( graphWidget, tr( "Graph not implemented yet." ) );
+ GraphInfo* info = new GraphInfo( GraphInfo::BarChart, 0x0, tr( "Graph Title" ),
+ tr( "X-Axis" ), tr( "Y-Axis" ) );
+ graphWidget = new Graph( control, info );
+ QWhatsThis::add( graphWidget, tr( "Charting is not implemented yet." ) );
layout->addMultiCellWidget( graphWidget, 0, 0, 0, 1 );
- graphWidget->setBackgroundMode( QWidget::PaletteBase );
QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control );
- QWhatsThis::add( btn, tr( "Click here to draw the graph." ) );
+ QWhatsThis::add( btn, tr( "Click here to draw the chart." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) );
layout->addWidget( btn, 1, 1 );
return control;
}
void Checkbook::loadCheckbook()
{
transactions.clear();
Config config(filename, Config::File);
@@ -267,26 +275,26 @@ void Checkbook::loadCheckbook()
QString temptext = config.readEntry( "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.readEntry( "Number", "" ) );
- pinNumEdit->setText( config.readEntry( "PINNumber", "" ) );
+ 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;
// Load transactions
TranInfo *tran;
QString trandesc = "";
float amount;
QString stramount;
@@ -300,29 +308,25 @@ void Checkbook::loadCheckbook()
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
currBalance += amount;
stramount.sprintf( "%c%.2f", currencySymbol, amount );
// Add to transaction list
transactions.append( tran );
// Add to transaction table
- QDate date = tran->date();
- QString datestr = QString::number( date.month() ) + "/" +
- QString::number( date.day() ) + "/" +
- QString::number( date.year() );
- ( void ) new QListViewItem( tranTable, QString::number( i ), datestr,
+ ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(),
trandesc, stramount );
}
else
{
delete tran;
}
}
balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
highTranNum = transactions.count();
}
@@ -348,48 +352,53 @@ void Checkbook::accept()
QFile f( filename );
if ( f.exists() )
{
f.remove();
}
Config *config = new Config(filename, Config::File);
// Save info
config->setGroup( "Account" );
config->writeEntry( "Type", typeList->currentText() );
config->writeEntry( "Bank", bankEdit->text() );
- config->writeEntry( "Number", acctNumEdit->text() );
- config->writeEntry( "PINNumber", pinNumEdit->text() );
+ config->writeEntryCrypt( "Number", acctNumEdit->text() );
+ config->writeEntryCrypt( "PINNumber", pinNumEdit->text() );
config->writeEntry( "Balance", balanceEdit->text() );
config->writeEntry( "Notes", notesEdit->text() );
// Save transactions
TranInfo *tran = transactions.first();
int i = 1;
while ( tran )
{
tran->write( config, i );
tran = transactions.next();
i++;
}
config->write();
QDialog::accept();
}
void Checkbook::slotNameChanged( const QString &newname )
{
name = newname;
- filename = filedir + newname + ".qcb";
- setCaption( name + " - " + tr( "Checkbook" ) );
+ filename = filedir;
+ filename.append( newname );
+ filename.append( ".qcb" );
+ QString tempstr = name;
+ tempstr.append( " - " );
+ tempstr.append( tr( "Checkbook" ) );
+ setCaption( tempstr );
}
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
currBalance -= startBalance;
bool ok;
startBalance = newbalance.toFloat( &ok );
adjustBalance( startBalance );
}
void Checkbook::slotNewTran()
{
@@ -405,31 +414,26 @@ void Checkbook::slotNewTran()
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
QString stramount;
stramount.sprintf( "%c%.2f", currencySymbol, amount );
// Add to transaction list
transactions.append( traninfo );
// Add to transaction table
-
- QDate date = traninfo->date();
- QString datestr = QString::number( date.month() ) + "/" +
- QString::number( date.day() ) + "/" +
- QString::number( date.year() );
- ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), datestr,
- traninfo->desc(), stramount );
+ ( void ) new QListViewItem( tranTable, QString::number( highTranNum ),
+ traninfo->datestr(), traninfo->desc(), stramount );
adjustBalance( amount );
}
else
{
highTranNum--;
delete traninfo;
}
}
void Checkbook::slotEditTran()
{
@@ -445,29 +449,25 @@ void Checkbook::slotEditTran()
float origamt = traninfo->amount();
if ( traninfo->withdrawal() )
{
origamt *= -1;
}
Transaction *currtran = new Transaction( this, name,
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
- QDate date = traninfo->date();
- QString datestr = QString::number( date.month() ) + "/" +
- QString::number( date.day() ) + "/" +
- QString::number( date.year() );
- curritem->setText( 1, datestr );
+ 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( "%c%.2f", currencySymbol, amount );
@@ -480,25 +480,24 @@ void Checkbook::slotEditTran()
}
void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
bool ok;
int tranid = curritem->text( 0 ).toInt( &ok );
- //TranInfo *traninfo = transactions.at( tranid - 1 );
TranInfo *traninfo = findTranByID( tranid );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) )
{
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
transactions.remove( traninfo );
delete traninfo;