author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (side-by-side diff) | |
tree | 46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/mainwindow.cpp | |
parent | f0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff) | |
download | opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2 |
merge noncore/apps/* except
- advancedfm (ljp, please...)
- odict (tille, please...)
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 @@ -32,4 +32,5 @@ #include "password.h" #include "checkbook.h" +#include "listedit.h" #include <qpe/config.h> @@ -47,6 +48,7 @@ #include <qwhatsthis.h> -MainWindow::MainWindow() - : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) + +MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) + : QMainWindow( parent, name, fl || WStyle_ContextHelp ) { setCaption( tr( "Checkbook" ) ); @@ -57,8 +59,7 @@ MainWindow::MainWindow() // Load configuration options 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 ); + // Build menu and tool bars @@ -126,22 +127,38 @@ MainWindow::MainWindow() 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() { -// config.write(); + writeConfig(); } + +// --- buildList -------------------------------------------------------------- void MainWindow::buildList() { if ( cbList ) - { - delete cbList; - } + delete cbList; cbList = new QListView( this ); QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); - if ( showLocks ) + if ( _cfg.getShowLocks() ) { cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); @@ -153,5 +170,5 @@ void MainWindow::buildList() } cbList->addColumn( tr( "Checkbook Name" ) ); - if ( showBalances ) + if ( _cfg.getShowBalances() ) { int colnum = cbList->addColumn( tr( "Balance" ) ); @@ -174,13 +191,13 @@ void MainWindow::addCheckbook( CBInfo *cb ) { QListViewItem *lvi = new QListViewItem( cbList ); - if ( showLocks && !cb->password().isNull() ) + if ( _cfg.getShowLocks() && !cb->password().isNull() ) { lvi->setPixmap( 0, lockIcon ); } 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 ); } @@ -198,5 +215,5 @@ void MainWindow::slotNew() CBInfo *cb = new CBInfo(); - Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); + Checkbook *currcb = new Checkbook( this, cb, &_cfg ); currcb->showMaximized(); if ( currcb->exec() == QDialog::Accepted ) @@ -204,4 +221,5 @@ void MainWindow::slotNew() // Save new checkbook buildFilename( cb->name() ); + _cfg.setLastBook( cb->name() ); cb->setFilename( tempFilename ); cb->write(); @@ -214,26 +232,29 @@ 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 ) break; cb = checkbooks->next(); } - if ( !cb ) - { - return; - } + if ( !cb ) return; + // buildFilename( currname ); float currbalance = cb->balance(); @@ -251,5 +272,6 @@ void MainWindow::slotEdit() } - Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); + _cfg.setLastBook( currname ); + Checkbook *currcb = new Checkbook( this, cb, &_cfg ); currcb->showMaximized(); if ( currcb->exec() == QDialog::Accepted ) @@ -259,13 +281,14 @@ void MainWindow::slotEdit() { // Update name if changed - curritem->setText( posName, newname ); - cbList->sort(); + 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 @@ -277,5 +300,5 @@ void MainWindow::slotEdit() // Update lock if changed - if ( showLocks && !cb->password().isNull() != currlock ) + if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) { if ( !cb->password().isNull() ) @@ -286,8 +309,8 @@ 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 ); } @@ -296,4 +319,5 @@ void MainWindow::slotEdit() } +// --- slotDelete ------------------------------------------------------------- void MainWindow::slotDelete() { @@ -313,23 +337,24 @@ void MainWindow::slotDelete() } +// --- slotConfigure ---------------------------------------------------------- void MainWindow::slotConfigure() { - Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances ); + Configuration *cfgdlg = new Configuration( this, _cfg ); cfgdlg->showMaximized(); if ( cfgdlg->exec() == QDialog::Accepted ) { - 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(); } delete cfgdlg; } + + +// --- writeConfig -------------------------------------------------------------- +void MainWindow::writeConfig() +{ + Config config("checkbook"); + _cfg.writeConfig( config ); +} |