author | drw <drw> | 2002-12-08 23:52:11 (UTC) |
---|---|---|
committer | drw <drw> | 2002-12-08 23:52:11 (UTC) |
commit | 9c2b4d917af88b6051a3bc4273d6a50d124f65dd (patch) (side-by-side diff) | |
tree | 6bff583be5510315f516c43e0a1e1edefecce027 | |
parent | f6735fca221658fa6d638f7826f89eb8d79caa26 (diff) | |
download | opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.zip opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.tar.gz opie-9c2b4d917af88b6051a3bc4273d6a50d124f65dd.tar.bz2 |
Fixed saving of new checkbooks and incorrect setting of notes.
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp index 3a39317..9fdc6b2 100644 --- a/noncore/apps/checkbook/cbinfo.cpp +++ b/noncore/apps/checkbook/cbinfo.cpp @@ -1,191 +1,191 @@ /* 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 ); + config->writeEntry( "Notes", nt ); 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 ) diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 68c6aee..cabd231 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp @@ -111,192 +111,198 @@ MainWindow::MainWindow() 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(); } 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() { CBInfo *cb = new CBInfo(); Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); currcb->showMaximized(); if ( currcb->exec() == QDialog::Accepted ) { + // Save new checkbook + buildFilename( cb->name() ); + cb->setFilename( tempFilename ); + cb->write(); + + // Add to listbox checkbooks->inSort( cb ); addCheckbook( cb ); } delete currcb; } void MainWindow::slotEdit() { 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 != cb->password() ) { delete pw; return; } delete pw; } Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); currcb->showMaximized(); if ( currcb->exec() == QDialog::Accepted ) { QString newname = cb->name(); if ( currname != newname ) { // Update name if changed curritem->setText( posName, newname ); cbList->sort(); // 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; } void MainWindow::slotDelete() { QString currname = cbList->currentItem()->text( posName ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) { buildFilename( currname ); QFile f( tempFilename ); |