Diffstat (limited to 'noncore/apps/checkbook/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 119 |
1 files changed, 72 insertions, 47 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 6d1d7b9..8d64cad 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp @@ -33,2 +33,3 @@ #include "checkbook.h" +#include "listedit.h" @@ -48,4 +49,5 @@ -MainWindow::MainWindow() - : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) + +MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) + : QMainWindow( parent, name, fl || WStyle_ContextHelp ) { @@ -58,6 +60,5 @@ MainWindow::MainWindow() Config config( "checkbook" ); - config.setGroup( "Config" ); - currencySymbol = config.readEntry( "CurrencySymbol", "$" ); - showLocks = config.readBoolEntry( "ShowLocks", FALSE ); - showBalances = config.readBoolEntry( "ShowBalances", FALSE ); +qDebug( "Reading config" ); + _cfg.readConfig( config ); + @@ -127,9 +128,27 @@ MainWindow::MainWindow() 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() { -// config.write(); + writeConfig(); } + +// --- buildList -------------------------------------------------------------- void MainWindow::buildList() @@ -137,5 +156,3 @@ void MainWindow::buildList() if ( cbList ) - { - delete cbList; - } + delete cbList; @@ -144,3 +161,3 @@ void MainWindow::buildList() - if ( showLocks ) + if ( _cfg.getShowLocks() ) { @@ -154,3 +171,3 @@ void MainWindow::buildList() cbList->addColumn( tr( "Checkbook Name" ) ); - if ( showBalances ) + if ( _cfg.getShowBalances() ) { @@ -175,3 +192,3 @@ void MainWindow::addCheckbook( CBInfo *cb ) QListViewItem *lvi = new QListViewItem( cbList ); - if ( showLocks && !cb->password().isNull() ) + if ( _cfg.getShowLocks() && !cb->password().isNull() ) { @@ -180,6 +197,6 @@ void MainWindow::addCheckbook( CBInfo *cb ) lvi->setText( posName, cb->name() ); - if ( showBalances ) + if ( _cfg.getShowBalances() ) { QString balance; - balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); + balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); lvi->setText( posName + 1, balance ); @@ -199,3 +216,3 @@ void MainWindow::slotNew() - Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); + Checkbook *currcb = new Checkbook( this, cb, &_cfg ); currcb->showMaximized(); @@ -205,2 +222,3 @@ void MainWindow::slotNew() buildFilename( cb->name() ); + _cfg.setLastBook( cb->name() ); cb->setFilename( tempFilename ); @@ -215,15 +233,20 @@ void MainWindow::slotNew() +// --- slotEdit --------------------------------------------------------------- void MainWindow::slotEdit() { - + // get name and open it QListViewItem *curritem = cbList->currentItem(); if ( !curritem ) - { return; - } - QString currname = curritem->text( posName ); + openBook( curritem ); +} - CBInfo *cb = checkbooks->first(); - while ( cb ) - { + +// --- 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 ) @@ -232,7 +255,5 @@ void MainWindow::slotEdit() } - if ( !cb ) - { - return; - } + if ( !cb ) return; + // buildFilename( currname ); @@ -252,3 +273,4 @@ void MainWindow::slotEdit() - Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); + _cfg.setLastBook( currname ); + Checkbook *currcb = new Checkbook( this, cb, &_cfg ); currcb->showMaximized(); @@ -260,4 +282,7 @@ void MainWindow::slotEdit() // Update name if changed - curritem->setText( posName, newname ); - cbList->sort(); + if( curritem ) { + curritem->setText( posName, newname ); + cbList->sort(); + } + _cfg.setLastBook( newname ); @@ -266,5 +291,3 @@ void MainWindow::slotEdit() if ( f.exists() ) - { f.remove(); - } @@ -278,3 +301,3 @@ void MainWindow::slotEdit() // Update lock if changed - if ( showLocks && !cb->password().isNull() != currlock ) + if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) { @@ -287,6 +310,6 @@ void MainWindow::slotEdit() // Update balance if changed - if ( showBalances && cb->balance() != currbalance ) + if ( _cfg.getShowBalances() && cb->balance() != currbalance ) { QString tempstr; - tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); + tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); curritem->setText( posName + 1, tempstr ); @@ -297,2 +320,3 @@ void MainWindow::slotEdit() +// --- slotDelete ------------------------------------------------------------- void MainWindow::slotDelete() @@ -314,5 +338,6 @@ void MainWindow::slotDelete() +// --- slotConfigure ---------------------------------------------------------- void MainWindow::slotConfigure() { - Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances ); + Configuration *cfgdlg = new Configuration( this, _cfg ); cfgdlg->showMaximized(); @@ -320,13 +345,5 @@ void MainWindow::slotConfigure() { - 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(); - + // read data from config dialog & save it + cfgdlg->saveConfig( _cfg ); + writeConfig(); buildList(); @@ -335 +352,9 @@ void MainWindow::slotConfigure() } + + +// --- writeConfig -------------------------------------------------------------- +void MainWindow::writeConfig() +{ + Config config("checkbook"); + _cfg.writeConfig( config ); +} |