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 | |||
@@ -28,12 +28,13 @@ | |||
28 | 28 | ||
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "cbinfo.h" | 30 | #include "cbinfo.h" |
31 | #include "configuration.h" | 31 | #include "configuration.h" |
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> |
36 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
37 | #include <qpe/qpeapplication.h> | 38 | #include <qpe/qpeapplication.h> |
38 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
39 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
@@ -43,26 +44,26 @@ | |||
43 | #include <qaction.h> | 44 | #include <qaction.h> |
44 | #include <qcheckbox.h> | 45 | #include <qcheckbox.h> |
45 | #include <qdir.h> | 46 | #include <qdir.h> |
46 | #include <qlineedit.h> | 47 | #include <qlineedit.h> |
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" ) ); |
53 | 55 | ||
54 | cbDir = Global::applicationFileName( "checkbook", "" ); | 56 | cbDir = Global::applicationFileName( "checkbook", "" ); |
55 | lockIcon = Resource::loadPixmap( "locked" ); | 57 | lockIcon = Resource::loadPixmap( "locked" ); |
56 | 58 | ||
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 |
65 | setToolBarsMovable( FALSE ); | 66 | setToolBarsMovable( FALSE ); |
66 | 67 | ||
67 | QPEToolBar *bar = new QPEToolBar( this ); | 68 | QPEToolBar *bar = new QPEToolBar( this ); |
68 | bar->setHorizontalStretchable( TRUE ); | 69 | bar->setHorizontalStretchable( TRUE ); |
@@ -122,40 +123,56 @@ MainWindow::MainWindow() | |||
122 | } | 123 | } |
123 | } | 124 | } |
124 | 125 | ||
125 | // Build Checkbook selection list control | 126 | // Build Checkbook selection list control |
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 ); |
148 | posName = 1; | 165 | posName = 1; |
149 | } | 166 | } |
150 | else | 167 | else |
151 | { | 168 | { |
152 | posName = 0; | 169 | posName = 0; |
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" ) ); |
158 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); | 175 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); |
159 | } | 176 | } |
160 | cbList->setAllColumnsShowFocus( TRUE ); | 177 | cbList->setAllColumnsShowFocus( TRUE ); |
161 | cbList->setSorting( posName ); | 178 | cbList->setSorting( posName ); |
@@ -170,21 +187,21 @@ void MainWindow::buildList() | |||
170 | } | 187 | } |
171 | } | 188 | } |
172 | 189 | ||
173 | void MainWindow::addCheckbook( CBInfo *cb ) | 190 | 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 | } |
187 | } | 204 | } |
188 | 205 | ||
189 | void MainWindow::buildFilename( const QString &name ) | 206 | void MainWindow::buildFilename( const QString &name ) |
190 | { | 207 | { |
@@ -194,50 +211,54 @@ void MainWindow::buildFilename( const QString &name ) | |||
194 | } | 211 | } |
195 | 212 | ||
196 | void MainWindow::slotNew() | 213 | void MainWindow::slotNew() |
197 | { | 214 | { |
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 ) |
203 | { | 220 | { |
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(); |
208 | 226 | ||
209 | // Add to listbox | 227 | // Add to listbox |
210 | checkbooks->inSort( cb ); | 228 | checkbooks->inSort( cb ); |
211 | addCheckbook( cb ); | 229 | addCheckbook( cb ); |
212 | } | 230 | } |
213 | delete currcb; | 231 | delete currcb; |
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(); |
240 | bool currlock = !cb->password().isNull(); | 261 | bool currlock = !cb->password().isNull(); |
241 | 262 | ||
242 | if ( currlock ) | 263 | if ( currlock ) |
243 | { | 264 | { |
@@ -247,57 +268,60 @@ void MainWindow::slotEdit() | |||
247 | delete pw; | 268 | delete pw; |
248 | return; | 269 | return; |
249 | } | 270 | } |
250 | delete pw; | 271 | delete pw; |
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 ) |
256 | { | 278 | { |
257 | QString newname = cb->name(); | 279 | QString newname = cb->name(); |
258 | if ( currname != newname ) | 280 | if ( currname != newname ) |
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 |
272 | buildFilename( newname ); | 295 | buildFilename( newname ); |
273 | cb->setFilename( tempFilename ); | 296 | cb->setFilename( tempFilename ); |
274 | } | 297 | } |
275 | 298 | ||
276 | cb->write(); | 299 | cb->write(); |
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() ) |
282 | curritem->setPixmap( 0, lockIcon ); | 305 | curritem->setPixmap( 0, lockIcon ); |
283 | else | 306 | else |
284 | curritem->setPixmap( 0, nullIcon ); | 307 | curritem->setPixmap( 0, nullIcon ); |
285 | } | 308 | } |
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 | } |
294 | } | 317 | } |
295 | delete currcb; | 318 | delete currcb; |
296 | } | 319 | } |
297 | 320 | ||
321 | // --- slotDelete ------------------------------------------------------------- | ||
298 | void MainWindow::slotDelete() | 322 | void MainWindow::slotDelete() |
299 | { | 323 | { |
300 | QString currname = cbList->currentItem()->text( posName ); | 324 | QString currname = cbList->currentItem()->text( posName ); |
301 | 325 | ||
302 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) | 326 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) |
303 | { | 327 | { |
@@ -309,27 +333,28 @@ void MainWindow::slotDelete() | |||
309 | } | 333 | } |
310 | 334 | ||
311 | delete cbList->currentItem(); | 335 | delete cbList->currentItem(); |
312 | } | 336 | } |
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 | } | ||