summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/mainwindow.cpp
authormickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
committer mickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
commit951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (unidiff)
tree46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/mainwindow.cpp
parentf0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff)
downloadopie-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.cpp119
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 @@
33#include "checkbook.h" 33#include "checkbook.h"
34#include "listedit.h"
34 35
@@ -48,4 +49,5 @@
48 49
49MainWindow::MainWindow() 50
50 : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) 51MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
52 : QMainWindow( parent, name, fl || WStyle_ContextHelp )
51{ 53{
@@ -58,6 +60,5 @@ MainWindow::MainWindow()
58 Config config( "checkbook" ); 60 Config config( "checkbook" );
59 config.setGroup( "Config" ); 61qDebug( "Reading config" );
60 currencySymbol = config.readEntry( "CurrencySymbol", "$" ); 62 _cfg.readConfig( config );
61 showLocks = config.readBoolEntry( "ShowLocks", FALSE ); 63
62 showBalances = config.readBoolEntry( "ShowBalances", FALSE );
63 64
@@ -127,9 +128,27 @@ MainWindow::MainWindow()
127 buildList(); 128 buildList();
129
130 // open last book?
131 if( _cfg.isOpenLastBook() ) {
132 this->show();
133 this->showMaximized();
134 QListViewItem *itm=cbList->firstChild();
135 while( itm ) {
136 if( itm->text(posName)==_cfg.getLastBook() ) {
137 openBook( itm );
138 break;
139 }
140 itm=itm->nextSibling();
141 }
142 }
128} 143}
129 144
145
146// --- ~MainWindow ------------------------------------------------------------
130MainWindow::~MainWindow() 147MainWindow::~MainWindow()
131{ 148{
132 //config.write(); 149 writeConfig();
133} 150}
134 151
152
153// --- buildList --------------------------------------------------------------
135void MainWindow::buildList() 154void MainWindow::buildList()
@@ -137,5 +156,3 @@ void MainWindow::buildList()
137 if ( cbList ) 156 if ( cbList )
138 { 157 delete cbList;
139 delete cbList;
140 }
141 158
@@ -144,3 +161,3 @@ void MainWindow::buildList()
144 161
145 if ( showLocks ) 162 if ( _cfg.getShowLocks() )
146 { 163 {
@@ -154,3 +171,3 @@ void MainWindow::buildList()
154 cbList->addColumn( tr( "Checkbook Name" ) ); 171 cbList->addColumn( tr( "Checkbook Name" ) );
155 if ( showBalances ) 172 if ( _cfg.getShowBalances() )
156 { 173 {
@@ -175,3 +192,3 @@ void MainWindow::addCheckbook( CBInfo *cb )
175 QListViewItem *lvi = new QListViewItem( cbList ); 192 QListViewItem *lvi = new QListViewItem( cbList );
176 if ( showLocks && !cb->password().isNull() ) 193 if ( _cfg.getShowLocks() && !cb->password().isNull() )
177 { 194 {
@@ -180,6 +197,6 @@ void MainWindow::addCheckbook( CBInfo *cb )
180 lvi->setText( posName, cb->name() ); 197 lvi->setText( posName, cb->name() );
181 if ( showBalances ) 198 if ( _cfg.getShowBalances() )
182 { 199 {
183 QString balance; 200 QString balance;
184 balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); 201 balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
185 lvi->setText( posName + 1, balance ); 202 lvi->setText( posName + 1, balance );
@@ -199,3 +216,3 @@ void MainWindow::slotNew()
199 216
200 Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); 217 Checkbook *currcb = new Checkbook( this, cb, &_cfg );
201 currcb->showMaximized(); 218 currcb->showMaximized();
@@ -205,2 +222,3 @@ void MainWindow::slotNew()
205 buildFilename( cb->name() ); 222 buildFilename( cb->name() );
223 _cfg.setLastBook( cb->name() );
206 cb->setFilename( tempFilename ); 224 cb->setFilename( tempFilename );
@@ -215,15 +233,20 @@ void MainWindow::slotNew()
215 233
234// --- slotEdit ---------------------------------------------------------------
216void MainWindow::slotEdit() 235void MainWindow::slotEdit()
217{ 236{
218 237 // get name and open it
219 QListViewItem *curritem = cbList->currentItem(); 238 QListViewItem *curritem = cbList->currentItem();
220 if ( !curritem ) 239 if ( !curritem )
221 {
222 return; 240 return;
223 } 241 openBook( curritem );
224 QString currname = curritem->text( posName ); 242}
225 243
226 CBInfo *cb = checkbooks->first(); 244
227 while ( cb ) 245// --- openBook ---------------------------------------------------------------
228 { 246void MainWindow::openBook(QListViewItem *curritem)
247{
248 // find book in List
249 QString currname=curritem->text(posName);
250 CBInfo *cb = checkbooks->first();
251 while ( cb ) {
229 if ( cb->name() == currname ) 252 if ( cb->name() == currname )
@@ -232,7 +255,5 @@ void MainWindow::slotEdit()
232 } 255 }
233 if ( !cb ) 256 if ( !cb ) return;
234 {
235 return;
236 }
237 257
258 //
238 buildFilename( currname ); 259 buildFilename( currname );
@@ -252,3 +273,4 @@ void MainWindow::slotEdit()
252 273
253 Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); 274 _cfg.setLastBook( currname );
275 Checkbook *currcb = new Checkbook( this, cb, &_cfg );
254 currcb->showMaximized(); 276 currcb->showMaximized();
@@ -260,4 +282,7 @@ void MainWindow::slotEdit()
260 // Update name if changed 282 // Update name if changed
261 curritem->setText( posName, newname ); 283 if( curritem ) {
262 cbList->sort(); 284 curritem->setText( posName, newname );
285 cbList->sort();
286 }
287 _cfg.setLastBook( newname );
263 288
@@ -266,5 +291,3 @@ void MainWindow::slotEdit()
266 if ( f.exists() ) 291 if ( f.exists() )
267 {
268 f.remove(); 292 f.remove();
269 }
270 293
@@ -278,3 +301,3 @@ void MainWindow::slotEdit()
278 // Update lock if changed 301 // Update lock if changed
279 if ( showLocks && !cb->password().isNull() != currlock ) 302 if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
280 { 303 {
@@ -287,6 +310,6 @@ void MainWindow::slotEdit()
287 // Update balance if changed 310 // Update balance if changed
288 if ( showBalances && cb->balance() != currbalance ) 311 if ( _cfg.getShowBalances() && cb->balance() != currbalance )
289 { 312 {
290 QString tempstr; 313 QString tempstr;
291 tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); 314 tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
292 curritem->setText( posName + 1, tempstr ); 315 curritem->setText( posName + 1, tempstr );
@@ -297,2 +320,3 @@ void MainWindow::slotEdit()
297 320
321// --- slotDelete -------------------------------------------------------------
298void MainWindow::slotDelete() 322void MainWindow::slotDelete()
@@ -314,5 +338,6 @@ void MainWindow::slotDelete()
314 338
339// --- slotConfigure ----------------------------------------------------------
315void MainWindow::slotConfigure() 340void MainWindow::slotConfigure()
316{ 341{
317 Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances ); 342 Configuration *cfgdlg = new Configuration( this, _cfg );
318 cfgdlg->showMaximized(); 343 cfgdlg->showMaximized();
@@ -320,13 +345,5 @@ void MainWindow::slotConfigure()
320 { 345 {
321 currencySymbol = cfgdlg->symbolEdit->text(); 346 // read data from config dialog & save it
322 showLocks = cfgdlg->lockCB->isChecked(); 347 cfgdlg->saveConfig( _cfg );
323 showBalances = cfgdlg->balCB->isChecked(); 348 writeConfig();
324
325 Config config( "checkbook" );
326 config.setGroup( "Config" );
327 config.writeEntry( "CurrencySymbol", currencySymbol );
328 config.writeEntry( "ShowLocks", showLocks );
329 config.writeEntry( "ShowBalances", showBalances );
330 config.write();
331
332 buildList(); 349 buildList();
@@ -335 +352,9 @@ void MainWindow::slotConfigure()
335} 352}
353
354
355// --- writeConfig --------------------------------------------------------------
356void MainWindow::writeConfig()
357{
358 Config config("checkbook");
359 _cfg.writeConfig( config );
360}