summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index ce15e3e..c7ffa7c 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -148,97 +148,98 @@ MainWindow::~MainWindow()
148// --- buildList -------------------------------------------------------------- 148// --- buildList --------------------------------------------------------------
149void MainWindow::buildList() 149void MainWindow::buildList()
150{ 150{
151 if ( cbList ) 151 if ( cbList )
152 delete cbList; 152 delete cbList;
153 153
154 cbList = new QListView( this ); 154 cbList = new QListView( this );
155 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); 155 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
156 156
157 if ( _cfg.getShowLocks() ) 157 if ( _cfg.getShowLocks() )
158 { 158 {
159 cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); 159 cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
160 posName = 1; 160 posName = 1;
161 } 161 }
162 else 162 else
163 { 163 {
164 posName = 0; 164 posName = 0;
165 } 165 }
166 cbList->addColumn( tr( "Checkbook Name" ) ); 166 cbList->addColumn( tr( "Checkbook Name" ) );
167 if ( _cfg.getShowBalances() ) 167 if ( _cfg.getShowBalances() )
168 { 168 {
169 int colnum = cbList->addColumn( tr( "Balance" ) ); 169 int colnum = cbList->addColumn( tr( "Balance" ) );
170 cbList->setColumnAlignment( colnum, Qt::AlignRight ); 170 cbList->setColumnAlignment( colnum, Qt::AlignRight );
171 } 171 }
172 cbList->setAllColumnsShowFocus( TRUE ); 172 cbList->setAllColumnsShowFocus( TRUE );
173 cbList->setSorting( posName ); 173 cbList->setSorting( posName );
174 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); 174 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
175 connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), 175 connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ),
176 this, SLOT( slotEdit() ) ); 176 this, SLOT( slotEdit() ) );
177 setCentralWidget( cbList ); 177 setCentralWidget( cbList );
178 178
179 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) 179 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
180 { 180 {
181 addCheckbook( cb ); 181 addCheckbook( cb );
182 } 182 }
183} 183}
184 184
185void MainWindow::addCheckbook( CBInfo *cb ) 185void MainWindow::addCheckbook( CBInfo *cb )
186{ 186{
187 QListViewItem *lvi = new QListViewItem( cbList ); 187 QListViewItem *lvi = new QListViewItem( cbList );
188 if ( _cfg.getShowLocks() && !cb->password().isNull() ) 188 if ( _cfg.getShowLocks() && !cb->password().isNull() )
189 { 189 {
190 lvi->setPixmap( 0, lockIcon ); 190 lvi->setPixmap( 0, lockIcon );
191 } 191 }
192 lvi->setText( posName, cb->name() ); 192 lvi->setText( posName, cb->name() );
193 if ( _cfg.getShowBalances() ) 193 if ( _cfg.getShowBalances() )
194 { 194 {
195 QString balance; 195 QString balance;
196 balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); 196 balance.sprintf( "%.2f", cb->balance() );
197 balance.prepend( _cfg.getCurrencySymbol() );
197 lvi->setText( posName + 1, balance ); 198 lvi->setText( posName + 1, balance );
198 } 199 }
199} 200}
200 201
201void MainWindow::buildFilename( const QString &name ) 202void MainWindow::buildFilename( const QString &name )
202{ 203{
203 tempFilename = cbDir; 204 tempFilename = cbDir;
204 tempFilename.append( name ); 205 tempFilename.append( name );
205 tempFilename.append( ".qcb" ); 206 tempFilename.append( ".qcb" );
206} 207}
207 208
208void MainWindow::slotNew() 209void MainWindow::slotNew()
209{ 210{
210 CBInfo *cb = new CBInfo(); 211 CBInfo *cb = new CBInfo();
211 212
212 Checkbook *currcb = new Checkbook( this, cb, &_cfg ); 213 Checkbook *currcb = new Checkbook( this, cb, &_cfg );
213 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) 214 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
214 { 215 {
215 // Save new checkbook 216 // Save new checkbook
216 buildFilename( cb->name() ); 217 buildFilename( cb->name() );
217 _cfg.setLastBook( cb->name() ); 218 _cfg.setLastBook( cb->name() );
218 cb->setFilename( tempFilename ); 219 cb->setFilename( tempFilename );
219 cb->write(); 220 cb->write();
220 221
221 // Add to listbox 222 // Add to listbox
222 checkbooks->inSort( cb ); 223 checkbooks->inSort( cb );
223 addCheckbook( cb ); 224 addCheckbook( cb );
224 } 225 }
225 delete currcb; 226 delete currcb;
226} 227}
227 228
228// --- slotEdit --------------------------------------------------------------- 229// --- slotEdit ---------------------------------------------------------------
229void MainWindow::slotEdit() 230void MainWindow::slotEdit()
230{ 231{
231 // get name and open it 232 // get name and open it
232 QListViewItem *curritem = cbList->currentItem(); 233 QListViewItem *curritem = cbList->currentItem();
233 if ( !curritem ) 234 if ( !curritem )
234 return; 235 return;
235 openBook( curritem ); 236 openBook( curritem );
236} 237}
237 238
238 239
239// --- openBook --------------------------------------------------------------- 240// --- openBook ---------------------------------------------------------------
240void MainWindow::openBook(QListViewItem *curritem) 241void MainWindow::openBook(QListViewItem *curritem)
241{ 242{
242 // find book in List 243 // find book in List
243 QString currname=curritem->text(posName); 244 QString currname=curritem->text(posName);
244 CBInfo *cb = checkbooks->first(); 245 CBInfo *cb = checkbooks->first();
@@ -259,97 +260,98 @@ void MainWindow::openBook(QListViewItem *curritem)
259 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 260 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
260 if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) 261 if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
261 { 262 {
262 delete pw; 263 delete pw;
263 return; 264 return;
264 } 265 }
265 delete pw; 266 delete pw;
266 } 267 }
267 268
268 _cfg.setLastBook( currname ); 269 _cfg.setLastBook( currname );
269 Checkbook *currcb = new Checkbook( this, cb, &_cfg ); 270 Checkbook *currcb = new Checkbook( this, cb, &_cfg );
270 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) 271 if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
271 { 272 {
272 QString newname = cb->name(); 273 QString newname = cb->name();
273 if ( currname != newname ) 274 if ( currname != newname )
274 { 275 {
275 // Update name if changed 276 // Update name if changed
276 if( curritem ) { 277 if( curritem ) {
277 curritem->setText( posName, newname ); 278 curritem->setText( posName, newname );
278 cbList->sort(); 279 cbList->sort();
279 } 280 }
280 _cfg.setLastBook( newname ); 281 _cfg.setLastBook( newname );
281 282
282 // Remove old file 283 // Remove old file
283 QFile f( tempFilename ); 284 QFile f( tempFilename );
284 if ( f.exists() ) 285 if ( f.exists() )
285 f.remove(); 286 f.remove();
286 287
287 // Get new filename 288 // Get new filename
288 buildFilename( newname ); 289 buildFilename( newname );
289 cb->setFilename( tempFilename ); 290 cb->setFilename( tempFilename );
290 } 291 }
291 292
292 cb->write(); 293 cb->write();
293 294
294 // Update lock if changed 295 // Update lock if changed
295 if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) 296 if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
296 { 297 {
297 if ( !cb->password().isNull() ) 298 if ( !cb->password().isNull() )
298 curritem->setPixmap( 0, lockIcon ); 299 curritem->setPixmap( 0, lockIcon );
299 else 300 else
300 curritem->setPixmap( 0, nullIcon ); 301 curritem->setPixmap( 0, nullIcon );
301 } 302 }
302 303
303 // Update balance if changed 304 // Update balance if changed
304 if ( _cfg.getShowBalances() && cb->balance() != currbalance ) 305 if ( _cfg.getShowBalances() && cb->balance() != currbalance )
305 { 306 {
306 QString tempstr; 307 QString tempstr;
307 tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); 308 tempstr.sprintf( "%.2f", cb->balance() );
309 tempstr.prepend( _cfg.getCurrencySymbol() );
308 curritem->setText( posName + 1, tempstr ); 310 curritem->setText( posName + 1, tempstr );
309 } 311 }
310 312
311 // write config, if needed 313 // write config, if needed
312 if( _cfg.isDirty() ) { 314 if( _cfg.isDirty() ) {
313 Config config("checkbook"); 315 Config config("checkbook");
314 _cfg.writeConfig( config ); 316 _cfg.writeConfig( config );
315 } 317 }
316 } 318 }
317 delete currcb; 319 delete currcb;
318} 320}
319 321
320// --- slotDelete ------------------------------------------------------------- 322// --- slotDelete -------------------------------------------------------------
321void MainWindow::slotDelete() 323void MainWindow::slotDelete()
322{ 324{
323 QString currname = cbList->currentItem()->text( posName ); 325 QString currname = cbList->currentItem()->text( posName );
324 326
325 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) 327 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
326 { 328 {
327 buildFilename( currname ); 329 buildFilename( currname );
328 QFile f( tempFilename ); 330 QFile f( tempFilename );
329 if ( f.exists() ) 331 if ( f.exists() )
330 { 332 {
331 f.remove(); 333 f.remove();
332 } 334 }
333 335
334 delete cbList->currentItem(); 336 delete cbList->currentItem();
335 } 337 }
336} 338}
337 339
338// --- slotConfigure ---------------------------------------------------------- 340// --- slotConfigure ----------------------------------------------------------
339void MainWindow::slotConfigure() 341void MainWindow::slotConfigure()
340{ 342{
341 Configuration *cfgdlg = new Configuration( this, _cfg ); 343 Configuration *cfgdlg = new Configuration( this, _cfg );
342 if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted ) 344 if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted )
343 { 345 {
344 // read data from config dialog & save it 346 // read data from config dialog & save it
345 cfgdlg->saveConfig( _cfg ); 347 cfgdlg->saveConfig( _cfg );
346 writeConfig(); 348 writeConfig();
347 buildList(); 349 buildList();
348 } 350 }
349 delete cfgdlg; 351 delete cfgdlg;
350} 352}
351 353
352 354
353// --- writeConfig -------------------------------------------------------------- 355// --- writeConfig --------------------------------------------------------------
354void MainWindow::writeConfig() 356void MainWindow::writeConfig()
355{ 357{