-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 @@ -47,97 +47,97 @@ CBInfo::CBInfo() 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 = ""; 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 @@ -159,96 +159,102 @@ void MainWindow::buildList() { 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(); |