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 @@ | |||
32 | #include "password.h" | 32 | #include "password.h" |
33 | #include "checkbook.h" | 33 | #include "checkbook.h" |
34 | #include "listedit.h" | ||
34 | 35 | ||
35 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
@@ -47,6 +48,7 @@ | |||
47 | #include <qwhatsthis.h> | 48 | #include <qwhatsthis.h> |
48 | 49 | ||
49 | MainWindow::MainWindow() | 50 | |
50 | : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) | 51 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) |
52 | : QMainWindow( parent, name, fl || WStyle_ContextHelp ) | ||
51 | { | 53 | { |
52 | setCaption( tr( "Checkbook" ) ); | 54 | setCaption( tr( "Checkbook" ) ); |
@@ -57,8 +59,7 @@ MainWindow::MainWindow() | |||
57 | // Load configuration options | 59 | // Load configuration options |
58 | Config config( "checkbook" ); | 60 | Config config( "checkbook" ); |
59 | config.setGroup( "Config" ); | 61 | qDebug( "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 | ||
64 | // Build menu and tool bars | 65 | // Build menu and tool bars |
@@ -126,22 +127,38 @@ MainWindow::MainWindow() | |||
126 | cbList = 0x0; | 127 | cbList = 0x0; |
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 ------------------------------------------------------------ | ||
130 | MainWindow::~MainWindow() | 147 | MainWindow::~MainWindow() |
131 | { | 148 | { |
132 | //config.write(); | 149 | writeConfig(); |
133 | } | 150 | } |
134 | 151 | ||
152 | |||
153 | // --- buildList -------------------------------------------------------------- | ||
135 | void MainWindow::buildList() | 154 | void MainWindow::buildList() |
136 | { | 155 | { |
137 | if ( cbList ) | 156 | if ( cbList ) |
138 | { | 157 | delete cbList; |
139 | delete cbList; | ||
140 | } | ||
141 | 158 | ||
142 | cbList = new QListView( this ); | 159 | cbList = new QListView( this ); |
143 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); | 160 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); |
144 | 161 | ||
145 | if ( showLocks ) | 162 | if ( _cfg.getShowLocks() ) |
146 | { | 163 | { |
147 | cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); | 164 | cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); |
@@ -153,5 +170,5 @@ void MainWindow::buildList() | |||
153 | } | 170 | } |
154 | cbList->addColumn( tr( "Checkbook Name" ) ); | 171 | cbList->addColumn( tr( "Checkbook Name" ) ); |
155 | if ( showBalances ) | 172 | if ( _cfg.getShowBalances() ) |
156 | { | 173 | { |
157 | int colnum = cbList->addColumn( tr( "Balance" ) ); | 174 | int colnum = cbList->addColumn( tr( "Balance" ) ); |
@@ -174,13 +191,13 @@ void MainWindow::addCheckbook( CBInfo *cb ) | |||
174 | { | 191 | { |
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 | { |
178 | lvi->setPixmap( 0, lockIcon ); | 195 | lvi->setPixmap( 0, lockIcon ); |
179 | } | 196 | } |
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 ); |
186 | } | 203 | } |
@@ -198,5 +215,5 @@ void MainWindow::slotNew() | |||
198 | CBInfo *cb = new CBInfo(); | 215 | CBInfo *cb = new CBInfo(); |
199 | 216 | ||
200 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); | 217 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
201 | currcb->showMaximized(); | 218 | currcb->showMaximized(); |
202 | if ( currcb->exec() == QDialog::Accepted ) | 219 | if ( currcb->exec() == QDialog::Accepted ) |
@@ -204,4 +221,5 @@ void MainWindow::slotNew() | |||
204 | // Save new checkbook | 221 | // Save new checkbook |
205 | buildFilename( cb->name() ); | 222 | buildFilename( cb->name() ); |
223 | _cfg.setLastBook( cb->name() ); | ||
206 | cb->setFilename( tempFilename ); | 224 | cb->setFilename( tempFilename ); |
207 | cb->write(); | 225 | cb->write(); |
@@ -214,26 +232,29 @@ void MainWindow::slotNew() | |||
214 | } | 232 | } |
215 | 233 | ||
234 | // --- slotEdit --------------------------------------------------------------- | ||
216 | void MainWindow::slotEdit() | 235 | void 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 | { | 246 | void 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 ) |
230 | break; | 253 | break; |
231 | cb = checkbooks->next(); | 254 | cb = checkbooks->next(); |
232 | } | 255 | } |
233 | if ( !cb ) | 256 | if ( !cb ) return; |
234 | { | ||
235 | return; | ||
236 | } | ||
237 | 257 | ||
258 | // | ||
238 | buildFilename( currname ); | 259 | buildFilename( currname ); |
239 | float currbalance = cb->balance(); | 260 | float currbalance = cb->balance(); |
@@ -251,5 +272,6 @@ void MainWindow::slotEdit() | |||
251 | } | 272 | } |
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(); |
255 | if ( currcb->exec() == QDialog::Accepted ) | 277 | if ( currcb->exec() == QDialog::Accepted ) |
@@ -259,13 +281,14 @@ void MainWindow::slotEdit() | |||
259 | { | 281 | { |
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 | ||
264 | // Remove old file | 289 | // Remove old file |
265 | QFile f( tempFilename ); | 290 | QFile f( tempFilename ); |
266 | if ( f.exists() ) | 291 | if ( f.exists() ) |
267 | { | ||
268 | f.remove(); | 292 | f.remove(); |
269 | } | ||
270 | 293 | ||
271 | // Get new filename | 294 | // Get new filename |
@@ -277,5 +300,5 @@ void MainWindow::slotEdit() | |||
277 | 300 | ||
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 | { |
281 | if ( !cb->password().isNull() ) | 304 | if ( !cb->password().isNull() ) |
@@ -286,8 +309,8 @@ void MainWindow::slotEdit() | |||
286 | 309 | ||
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 ); |
293 | } | 316 | } |
@@ -296,4 +319,5 @@ void MainWindow::slotEdit() | |||
296 | } | 319 | } |
297 | 320 | ||
321 | // --- slotDelete ------------------------------------------------------------- | ||
298 | void MainWindow::slotDelete() | 322 | void MainWindow::slotDelete() |
299 | { | 323 | { |
@@ -313,23 +337,24 @@ void MainWindow::slotDelete() | |||
313 | } | 337 | } |
314 | 338 | ||
339 | // --- slotConfigure ---------------------------------------------------------- | ||
315 | void MainWindow::slotConfigure() | 340 | void 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(); |
319 | if ( cfgdlg->exec() == QDialog::Accepted ) | 344 | if ( cfgdlg->exec() == QDialog::Accepted ) |
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(); |
333 | } | 350 | } |
334 | delete cfgdlg; | 351 | delete cfgdlg; |
335 | } | 352 | } |
353 | |||
354 | |||
355 | // --- writeConfig -------------------------------------------------------------- | ||
356 | void MainWindow::writeConfig() | ||
357 | { | ||
358 | Config config("checkbook"); | ||
359 | _cfg.writeConfig( config ); | ||
360 | } | ||