summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp18
-rw-r--r--noncore/apps/checkbook/listedit.cpp6
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp2
-rw-r--r--noncore/apps/checkbook/password.cpp2
-rw-r--r--noncore/apps/checkbook/transaction.cpp14
5 files changed, 21 insertions, 21 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 26b2533..1b933f2 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -1,436 +1,436 @@
/*
                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 "cfg.h"
#include <qpe/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>
#include <qpopupmenu.h>
#define COL_ID 0
#define COL_SORTDATE 1
#define COL_NUM 2
#define COL_DATE 3
#define COL_DESC 4
#define COL_AMOUNT 5
#define COL_BAL 6
// --- Checkbook --------------------------------------------------------------
Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
info = i;
_pCfg=cfg;
// Title bar
if ( info->name() != "" )
{
QString tempstr = info->name();
tempstr.append( " - " );
tempstr.append( tr( "Checkbook" ) );
setCaption( tempstr );
}
else
{
setCaption( tr( "New checkbook" ) );
}
// Setup layout to make everything pretty
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 2 );
layout->setSpacing( 4 );
// Setup tabs for all info
mainWidget = new OTabWidget( this );
layout->addWidget( mainWidget );
mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) );
mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) );
mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) );
if( _pCfg->isShowLastTab() )
mainWidget->setCurrentTab( info->getLastTab() );
else
mainWidget->setCurrentTab( tr( "Info" ) );
- connect( mainWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( slotTab(QWidget *) ) );
+ connect( mainWidget, SIGNAL( currentChanged(QWidget*) ), this, SLOT( slotTab(QWidget*) ) );
// Load checkbook information
loadCheckbook();
}
Checkbook::~Checkbook()
{
}
// --- initInfo ---------------------------------------------------------------
QWidget *Checkbook::initInfo()
{
QWidget *control = new QWidget( mainWidget, tr("Info") );
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 & ) ) );
+ 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->insertStringList( _pCfg->getAccountTypes() );
layout->addWidget( typeList, 2, 1 );
// Bank/institution name
label = new QLabel( tr( "Bank:" ), container );
QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) );
layout->addWidget( label, 3, 0 );
bankEdit = new QLineEdit( container );
QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) );
layout->addWidget( bankEdit, 3, 1 );
// Account number
label = new QLabel( tr( "Account number:" ), container );
QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) );
layout->addWidget( label, 4, 0 );
acctNumEdit = new QLineEdit( container );
QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) );
layout->addWidget( acctNumEdit, 4, 1 );
// PIN number
label = new QLabel( tr( "PIN number:" ), container );
QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) );
layout->addWidget( label, 5, 0 );
pinNumEdit = new QLineEdit( container );
QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) );
layout->addWidget( pinNumEdit, 5, 1 );
// Starting balance
label = new QLabel( tr( "Starting balance:" ), container );
QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) );
layout->addWidget( label, 6, 0 );
balanceEdit = new QLineEdit( container );
QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) );
- connect( balanceEdit, SIGNAL( textChanged( const QString & ) ),
- this, SLOT( slotStartingBalanceChanged( const QString & ) ) );
+ connect( balanceEdit, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( slotStartingBalanceChanged(const QString&) ) );
layout->addWidget( balanceEdit, 6, 1 );
// Notes
label = new QLabel( tr( "Notes:" ), container );
QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) );
layout->addWidget( label, 7, 0 );
notesEdit = new QMultiLineEdit( container );
QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) );
notesEdit->setMinimumHeight( 25 );
notesEdit->setMaximumHeight( 65 );
layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 );
return control;
}
// --- initTransactions -------------------------------------------------------
QWidget *Checkbook::initTransactions()
{
QWidget *control = new QWidget( mainWidget, tr("Transactions") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
// Sort selector
QLabel *label = new QLabel( tr( "Sort by:" ), control );
QWhatsThis::add( label, tr( "Select checkbook sorting here." ) );
layout->addMultiCellWidget( label, 0, 0, 0, 1 );
_cbSortType=new QComboBox( control );
_cbSortType->insertItem( tr("Entry Order") );
_cbSortType->insertItem( tr("Date") );
_cbSortType->insertItem( tr("Number") );
layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 );
- connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) );
+ connect( _cbSortType, SIGNAL( activated(const QString&) ), this, SLOT( slotSortChanged(const QString&) ) );
// Table
tranTable = new QListView( control );
QFont fnt(QPEApplication::font());
fnt.setPointSize( fnt.pointSize()-1 );
tranTable->setFont( fnt );
QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) );
tranTable->addColumn( tr( "Id" ) );
tranTable->setColumnWidthMode( COL_ID, QListView::Manual );
tranTable->setColumnWidth( COL_ID, 0);
tranTable->addColumn( tr( "SortDate" ) );
tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual );
tranTable->setColumnWidth( COL_SORTDATE, 0);
tranTable->addColumn( tr( "Num" ) );
tranTable->addColumn( tr( "Date" ) );
//tranTable->addColumn( tr( "Cleared" ) );
tranTable->addColumn( tr( "Description" ) );
int column = tranTable->addColumn( tr( "Amount" ) );
tranTable->setColumnAlignment( column, Qt::AlignRight );
column=tranTable->addColumn( tr("Balance") );
tranTable->setColumnAlignment( column, Qt::AlignRight );
tranTable->setAllColumnsShowFocus( TRUE );
tranTable->setSorting( -1 );
layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 );
QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold );
- connect( tranTable, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
- this, SLOT( slotMenuTran(QListViewItem *, const QPoint &) ) );
- connect( tranTable, SIGNAL( doubleClicked( QListViewItem * ) ),
+ connect( tranTable, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ),
+ this, SLOT( slotMenuTran(QListViewItem*,const QPoint&) ) );
+ connect( tranTable, SIGNAL( doubleClicked(QListViewItem*) ),
this, SLOT( slotEditTran() ) );
_sortCol=COL_ID;
// Buttons
QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control );
QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) );
layout->addWidget( btn, 2, 0 );
btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control );
QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) );
layout->addWidget( btn, 2, 1 );
btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control );
QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) );
connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) );
layout->addWidget( btn, 2, 2 );
return( control );
}
// --- initCharts -------------------------------------------------------------
QWidget *Checkbook::initCharts()
{
graphInfo = 0x0;
QWidget *control = new QWidget( mainWidget, tr("Charts") );
QGridLayout *layout = new QGridLayout( control );
layout->setSpacing( 2 );
layout->setMargin( 4 );
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;
}
// --- loadCheckbook ----------------------------------------------------------
void Checkbook::loadCheckbook()
{
if ( !info )
{
return;
}
tranList = info->transactions();
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;
}
}
if( i<=0 ) {
typeList->insertItem( temptext, 0 );
typeList->setCurrentItem(0);
}
bankEdit->setText( info->bank() );
acctNumEdit->setText( info->account() );
pinNumEdit->setText( info->pin() );
temptext.setNum( info->startingBalance(), 'f', 2 );
balanceEdit->setText( temptext );
notesEdit->setText( info->notes() );
// Load transactions
float amount;
QString stramount;
for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() )
{
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount );
}
// set sort order
bool bOk=false;
for(int i=0; i<_cbSortType->count(); i++) {
if( _cbSortType->text(i)==info->getSortOrder() ) {
_cbSortType->setCurrentItem(i);
slotSortChanged( info->getSortOrder() );
bOk=true;
break;
}
}
if( !bOk ) {
_cbSortType->setCurrentItem(0);
slotSortChanged( _cbSortType->currentText() );
}
// calc running balance
adjustBalance();
}
// --- adjustBalance ----------------------------------------------------------
void Checkbook::adjustBalance()
{
// update running balance in register
QString sRunning;
float bal=info->startingBalance();
for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) {
TranInfo *tran=item->getTranInfo();
bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee();
sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal );
item->setText( COL_BAL, sRunning);
}
}
// --- resort -----------------------------------------------------------------
void Checkbook::resort()
{
tranTable->setSorting(_sortCol);
tranTable->sort();
tranTable->setSorting(-1);
}
// --- accept -----------------------------------------------------------------
void Checkbook::accept()
{
info->setName( nameEdit->text() );
info->setType( typeList->currentText() );
info->setBank( bankEdit->text() );
info->setAccount( acctNumEdit->text() );
info->setPin( pinNumEdit->text() );
bool ok;
info->setStartingBalance( balanceEdit->text().toFloat( &ok ) );
info->setNotes( notesEdit->text() );
QDialog::accept();
}
// --- slotPasswordClicked ----------------------------------------------------
void Checkbook::slotPasswordClicked()
{
if ( info->password().isNull() && passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
if ( pw->exec() != QDialog::Accepted )
{
passwordCB->setChecked( FALSE );
delete pw;
return;
}
info->setPassword( pw->password );
delete pw;
pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) );
if ( pw->exec() != QDialog::Accepted || pw->password != info->password() )
{
passwordCB->setChecked( FALSE );
info->setPassword( QString::null );
}
delete pw;
}
else if ( !info->password().isNull() && !passwordCB->isChecked() )
{
Password *pw = new Password( this, tr( "Enter password" ),
tr( "Please enter your password to confirm removal of password protection:" ) );
if ( pw->exec() == QDialog::Accepted && pw->password == info->password() )
{
info->setPassword( QString::null );
delete pw;
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp
index 37f05f0..d00e305 100644
--- a/noncore/apps/checkbook/listedit.cpp
+++ b/noncore/apps/checkbook/listedit.cpp
@@ -1,264 +1,264 @@
/*
                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 ) ) );
+ 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 &) ) );
+ 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 &) ) );
+ 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 );
// make it selected
_typeEdit->setCursorPosition(0);
_typeEdit->setSelection(0, _typeEdit->text().length() );
}
// --- slotDel -------------------------------------------------------------
void ListEdit::slotDel()
{
if( !_currentItem ) return;
delete _currentItem;
_currentItem=NULL;
_typeEdit->setText("");
_stack->raiseWidget(_typeEdit);
}
// --- fixTypes ----------------------------------------------------------------
// Makes sure all entries have a unique name and empty entries are replaced
// by a generic string. The first version performs the operation on a particular
// column, whereas the 2nd does it for all unique columns.
class ColMap {
public:
ColMap(QString sValue, QListViewItem *pEntry) {
_sValue=sValue;
_pEntry=pEntry;
}
QString &getValue() { return(_sValue); }
QListViewItem *getItem() { return(_pEntry); }
protected:
QString _sValue;
QListViewItem *_pEntry;
};
class ColList : public QList<QString>
{
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();
}
}
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index d0fac3b..254ce6a 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -1,358 +1,358 @@
/*
                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/qpeapplication.h>
#include <qpe/qpemessagebox.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qmenubar.h>
#include <qaction.h>
#include <qdir.h>
#include <qwhatsthis.h>
MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ )
: QMainWindow( parent, name, WStyle_ContextHelp )
{
setCaption( tr( "Checkbook" ) );
cbDir = Global::applicationFileName( "checkbook", "" );
lockIcon = Resource::loadPixmap( "locked" );
// Load configuration options
Config config( "checkbook" );
_cfg.readConfig( config );
// Build menu and tool bars
setToolBarsMovable( FALSE );
QToolBar *bar = new QToolBar( this );
bar->setHorizontalStretchable( TRUE );
QMenuBar *mb = new QMenuBar( bar );
mb->setMargin( 0 );
QPopupMenu *popup = new QPopupMenu( this );
bar = new QToolBar( 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 );
popup->insertSeparator();
a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), 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 cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
QDir::Time );
CBInfo *cb = 0x0;
QString filename;
for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ )
{
filename = cbDir;
filename.append( (*it) );
cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename );
checkbooks->inSort( cb );
}
}
// 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()
{
writeConfig();
}
// --- buildList --------------------------------------------------------------
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 ( _cfg.getShowLocks() )
{
cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
posName = 1;
}
else
{
posName = 0;
}
cbList->addColumn( tr( "Checkbook Name" ) );
if ( _cfg.getShowBalances() )
{
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 ) ),
+ 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 ( _cfg.getShowLocks() && !cb->password().isNull() )
{
lvi->setPixmap( 0, lockIcon );
}
lvi->setText( posName, cb->name() );
if ( _cfg.getShowBalances() )
{
QString balance;
balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().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()
{
CBInfo *cb = new CBInfo();
Checkbook *currcb = new Checkbook( this, cb, &_cfg );
if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
{
// Save new checkbook
buildFilename( cb->name() );
_cfg.setLastBook( cb->name() );
cb->setFilename( tempFilename );
cb->write();
// Add to listbox
checkbooks->inSort( cb );
addCheckbook( cb );
}
delete currcb;
}
// --- slotEdit ---------------------------------------------------------------
void MainWindow::slotEdit()
{
// get name and open it
QListViewItem *curritem = cbList->currentItem();
if ( !curritem )
return;
openBook( curritem );
}
// --- 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;
//
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 != cb->password() )
{
delete pw;
return;
}
delete pw;
}
_cfg.setLastBook( currname );
Checkbook *currcb = new Checkbook( this, cb, &_cfg );
if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
{
QString newname = cb->name();
if ( currname != newname )
{
// Update name if changed
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 );
cb->setFilename( tempFilename );
}
cb->write();
// Update lock if changed
if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
{
if ( !cb->password().isNull() )
curritem->setPixmap( 0, lockIcon );
else
curritem->setPixmap( 0, nullIcon );
}
// Update balance if changed
if ( _cfg.getShowBalances() && cb->balance() != currbalance )
{
QString tempstr;
tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
curritem->setText( posName + 1, tempstr );
}
// write config, if needed
if( _cfg.isDirty() ) {
Config config("checkbook");
_cfg.writeConfig( config );
}
}
delete currcb;
}
// --- slotDelete -------------------------------------------------------------
void MainWindow::slotDelete()
{
QString currname = cbList->currentItem()->text( posName );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
{
buildFilename( currname );
QFile f( tempFilename );
if ( f.exists() )
{
f.remove();
}
delete cbList->currentItem();
}
}
// --- slotConfigure ----------------------------------------------------------
void MainWindow::slotConfigure()
{
Configuration *cfgdlg = new Configuration( this, _cfg );
if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted )
{
// 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/password.cpp b/noncore/apps/checkbook/password.cpp
index f381271..89a6bc6 100644
--- a/noncore/apps/checkbook/password.cpp
+++ b/noncore/apps/checkbook/password.cpp
@@ -1,97 +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.
*/
#include "password.h"
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
static const char* const showhideimage_data[] = {
"16 16 2 1",
". c None",
"# c #000000",
"................",
"...#...###...##.",
"..#.#..#..#.##..",
"..###..###.##...",
".#...#.#..##....",
".#...#.#.##.....",
"........##.#..#.",
"..##...##...##..",
".#..#.###...##..",
".#...##..#.#..#.",
".#..##..........",
".#.##.#..#.#..#.",
"..##...##...##..",
".##....##...##..",
".#....#..#.#..#.",
"................"};
Password::Password( QWidget *parent, const char *caption, const char *prompt )
: QDialog( parent, 0x0, TRUE, 0x0 )
{
setCaption( caption );
QGridLayout *layout = new QGridLayout( this );
layout->setSpacing( 2 );
layout->setMargin( 4 );
QLabel *label = new QLabel( prompt, this );
label->setAlignment( AlignLeft | AlignTop | WordBreak );
layout->addMultiCellWidget( label, 0, 0, 0, 1 );
pw = new QLineEdit( this );
pw->setEchoMode( QLineEdit::Password );
layout->addWidget( pw, 1, 0 );
QPixmap *pic = new QPixmap( ( const char** ) showhideimage_data );
QPushButton *btn = new QPushButton( ( QIconSet ) *pic, QString::null, this );
btn->setMaximumSize( pic->width() + 10, pic->height() + 10 );
btn->setToggleButton( TRUE );
- connect( btn, SIGNAL( toggled( bool ) ), this, SLOT( slotTogglePassword( bool ) ) );
+ connect( btn, SIGNAL( toggled(bool) ), this, SLOT( slotTogglePassword(bool) ) );
layout->addWidget( btn, 1, 1 );
password == "";
}
Password::~Password()
{
}
void Password::accept()
{
password = pw->text();
QDialog::accept();
}
void Password::slotTogglePassword( bool showPW )
{
showPW ? pw->setEchoMode( QLineEdit::Normal ) : pw->setEchoMode( QLineEdit::Password );
}
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp
index a72a48b..1b08b24 100644
--- a/noncore/apps/checkbook/transaction.cpp
+++ b/noncore/apps/checkbook/transaction.cpp
@@ -1,337 +1,337 @@
/*
                This file is part of the OPIE Project
=.
             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "transaction.h"
#include "traninfo.h"
#include "cfg.h"
#include "checkbook.h"
#include <qpe/datebookmonth.h>
#include <qbuttongroup.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qradiobutton.h>
#include <qwhatsthis.h>
Transaction::Transaction( QWidget *parent, bool bNew, const QString &acctname,
TranInfo *info, Cfg *pCfg )
: QDialog( parent, 0, TRUE, WStyle_ContextHelp )
{
QString tempstr = tr( "Transaction for " );
tempstr.append( acctname );
setCaption( tempstr );
_bNew=bNew;
tran = info;
_pCfg=pCfg;
QVBoxLayout *vb = new QVBoxLayout( this );
QScrollView *sv = new QScrollView( this );
vb->addWidget( sv, 0, 0 );
sv->setResizePolicy( QScrollView::AutoOneFit );
sv->setFrameStyle( QFrame::NoFrame );
QWidget *container = new QWidget( sv->viewport() );
sv->addChild( container );
QGridLayout *layout = new QGridLayout( container );
layout->setSpacing( 2 );
layout->setMargin( 4 );
// Withdrawal/Deposit
QButtonGroup *btngrp = new QButtonGroup( container );
btngrp->setColumnLayout(0, Qt::Vertical );
btngrp->layout()->setSpacing( 0 );
btngrp->layout()->setMargin( 0 );
btngrp->setMaximumWidth( 220 );
QGridLayout *layout2 = new QGridLayout( btngrp->layout() );
layout2->setSpacing( 2 );
layout2->setMargin( 2 );
withBtn = new QRadioButton( tr( "Withdrawal" ), btngrp );
QWhatsThis::add( withBtn, tr( "Select whether the transaction is a withdrawal or deposit here." ) );
layout2->addWidget( withBtn, 0, 0 );
connect( withBtn, SIGNAL( clicked() ), this, SLOT( slotWithdrawalClicked() ) );
depBtn = new QRadioButton( tr( "Deposit" ), btngrp );
QWhatsThis::add( depBtn, tr( "Select whether the transaction is a withdrawal or deposit here." ) );
layout2->addWidget( depBtn, 0, 1 );
btngrp->setMaximumSize( 320, withBtn->height() );
connect( depBtn, SIGNAL( clicked() ), this, SLOT( slotDepositClicked() ) );
layout->addMultiCellWidget( btngrp, 0, 0, 0, 3 );
// Date
QLabel *label = new QLabel( tr( "Date:" ), container );
QWhatsThis::add( label, tr( "Select date of transaction here." ) );
layout->addWidget( label, 1, 0 );
dateBtn = new QPushButton( TimeString::shortDate( QDate::currentDate() ),
container );
QWhatsThis::add( dateBtn, tr( "Select date of transaction here." ) );
QPopupMenu *m1 = new QPopupMenu( container );
datePicker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( datePicker );
dateBtn->setPopup( m1 );
- connect( datePicker, SIGNAL( dateClicked( int, int, int ) ),
- this, SLOT( slotDateChanged( int, int, int ) ) );
+ connect( datePicker, SIGNAL( dateClicked(int,int,int) ),
+ this, SLOT( slotDateChanged(int,int,int) ) );
layout->addWidget( dateBtn, 1, 1 );
// Check number
label = new QLabel( tr( "Number:" ), container );
QWhatsThis::add( label, tr( "Enter check number here." ) );
layout->addWidget( label, 1, 2 );
numEdit = new QLineEdit( container );
QWhatsThis::add( numEdit, tr( "Enter check number here." ) );
numEdit->setMaximumWidth( 40 );
layout->addWidget( numEdit, 1, 3 );
// Description
label = new QLabel( tr( "Description:" ), container );
QWhatsThis::add( label, tr( "Enter description of transaction here." ) );
layout->addWidget( label, 2, 0 );
_cbDesc=new QComboBox( true, container );
_cbDesc->insertStringList( _pCfg->getPayees() );
QWhatsThis::add( _cbDesc, tr( "Enter description of transaction here." ) );
layout->addMultiCellWidget( _cbDesc, 2, 2, 1, 3 );
- connect( _cbDesc, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) );
+ connect( _cbDesc, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) );
// Category
label = new QLabel( tr( "Category:" ), container );
QWhatsThis::add( label, tr( "Select transaction category here." ) );
layout->addWidget( label, 3, 0 );
catList = new QComboBox( container );
QWhatsThis::add( catList, tr( "Select transaction category here." ) );
layout->addMultiCellWidget( catList, 3, 3, 1, 3 );
// Type
label = new QLabel( tr( "Type:" ), container );
QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
layout->addWidget( label, 4, 0 );
typeList = new QComboBox( container );
QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
layout->addMultiCellWidget( typeList, 4, 4, 1, 3 );
// Amount
label = new QLabel( tr( "Amount:" ), container );
QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
layout->addWidget( label, 5, 0 );
amtEdit = new QLineEdit( container );
QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
layout->addMultiCellWidget( amtEdit, 5, 5, 1, 3 );
// Fee
label = new QLabel( tr( "Fee:" ), container );
QWhatsThis::add( label, tr( "Enter any fee amount assoiciated with this transaction.\n\nThe value entered should always be positive." ) );
layout->addWidget( label, 6, 0 );
feeEdit = new QLineEdit( container );
QWhatsThis::add( feeEdit, tr( "Enter any fee amount assoiciated with this transaction.\n\nThe value entered should always be positive." ) );
layout->addMultiCellWidget( feeEdit, 6, 6, 1, 3 );
// Notes
label = new QLabel( tr( "Notes:" ), container );
QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) );
layout->addWidget( label, 7, 0 );
noteEdit = new QMultiLineEdit( container );
QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) );
layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 );
// init date
initFromInfo( info );
// not new handlers
connect( withBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
connect( depBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
- connect( catList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
- connect( typeList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
- connect( amtEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
- connect( feeEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
+ connect( catList, SIGNAL(activated(const QString&)), this, SLOT( slotNotNew() ) );
+ connect( typeList, SIGNAL(activated(const QString&)), this, SLOT( slotNotNew() ) );
+ connect( amtEdit, SIGNAL(textChanged(const QString&)), this, SLOT( slotNotNew() ) );
+ connect( feeEdit, SIGNAL(textChanged(const QString&)), this, SLOT( slotNotNew() ) );
connect( noteEdit, SIGNAL(textChanged()), this, SLOT( slotNotNew() ) );
}
// --- initFromInfo -----------------------------------------------------------
void Transaction::initFromInfo(TranInfo *info, bool bPopulateOld)
{
// Populate current values if provided
if ( info )
{
if ( info->withdrawal() )
{
withBtn->setChecked( TRUE );
slotWithdrawalClicked();
}
else
{
depBtn->setChecked( TRUE );
slotDepositClicked();
}
if( !bPopulateOld ) {
QDate dt = info->date();
slotDateChanged( dt.year(), dt.month(), dt.day() );
datePicker->setDate( dt );
numEdit->setText( info->number() );
}
QString temptext = info->category();
// set description field
int i;
for(i=_cbDesc->count()-1; i>=0; i--) {
if( _cbDesc->text(i)==info->desc() ) {
_cbDesc->setCurrentItem(i);
break;
}
}
if( i<=0 )
_cbDesc->setEditText( info->desc() );
i = catList->count();
while ( i > 0 )
{
i--;
catList->setCurrentItem( i );
if ( catList->currentText() == temptext )
{
break;
}
}
temptext = info->type();
i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
amtEdit->setText( QString( "%1" ).arg( info->amount(), 0, 'f', 2 ) );
feeEdit->setText( QString( "%1" ).arg( info->fee(), 0, 'f', 2 ) );
noteEdit->setText( info->notes() );
}
else
{
withBtn->setChecked( TRUE );
}
}
// --- ~Transaction -----------------------------------------------------------
Transaction::~Transaction()
{
}
// --- accept -----------------------------------------------------------------
void Transaction::accept()
{
tran->setDesc( _cbDesc->currentText() );
tran->setDate( datePicker->selectedDate() );
tran->setWithdrawal( withBtn->isChecked() );
tran->setType( typeList->currentText() );
tran->setCategory( catList->currentText() );
bool ok;
tran->setAmount( amtEdit->text().toFloat( &ok ) );
tran->setFee( feeEdit->text().toFloat( &ok ) );
tran->setNumber( numEdit->text() );
tran->setNotes( noteEdit->text() );
QDialog::accept();
}
void Transaction::slotWithdrawalClicked()
{
catList->clear();
CategoryList *pCatList=_pCfg->getCategoryList();
for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) {
if( !pCat->isIncome() )
catList->insertItem( pCat->getName() );
}
catList->setCurrentItem(0);
typeList->clear();
typeList->insertItem( tr( "Debit Charge" ) );
typeList->insertItem( tr( "Written Check" ) );
typeList->insertItem( tr( "Transfer" ) );
typeList->insertItem( tr( "Credit Card" ) );
}
void Transaction::slotDepositClicked()
{
catList->clear();
CategoryList *pCatList=_pCfg->getCategoryList();
for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) {
if( pCat->isIncome() )
catList->insertItem( pCat->getName() );
}
catList->setCurrentItem( 0 );
typeList->clear();
typeList->insertItem( tr( "Written Check" ) );
typeList->insertItem( tr( "Automatic Payment" ) );
typeList->insertItem( tr( "Transfer" ) );
typeList->insertItem( tr( "Cash" ) );
}
// --- slotDateChanged --------------------------------------------------------
void Transaction::slotDateChanged( int y, int m, int d )
{
QDate date;
date.setYMD( y, m, d );
dateBtn->setText( TimeString::shortDate( date ) );
}
// --- slotActivated ----------------------------------------------------------
// Search for the most recent transaction with this description/payee and
// fill amount etc here, as long the new flag is set
void Transaction::slotActivated(const QString &arg )
{
if( !_bNew ) return;
TranInfoList *pTl=((Checkbook *)parentWidget())->getTranList();
if( pTl ) {
TranInfo *pTi=pTl->findMostRecentByDesc( arg );
if( pTi ) {
initFromInfo( pTi, true );
amtEdit->setFocus();
amtEdit->setSelection(0, amtEdit->text().length() );
amtEdit->setCursorPosition(0);
}
}
}
// slotNotNew -----------------------------------------------------------------
void Transaction::slotNotNew()
{
qDebug("Not new");
_bNew=false;
}