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.cpp230
1 files changed, 188 insertions, 42 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index 2c0abf1..68c6aee 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -27,6 +27,8 @@
27*/ 27*/
28 28
29#include "mainwindow.h" 29#include "mainwindow.h"
30#include "cbinfo.h"
31#include "configuration.h"
30#include "password.h" 32#include "password.h"
31#include "checkbook.h" 33#include "checkbook.h"
32 34
@@ -39,8 +41,10 @@
39#include <qpe/resource.h> 41#include <qpe/resource.h>
40 42
41#include <qaction.h> 43#include <qaction.h>
44#include <qcheckbox.h>
42#include <qdir.h> 45#include <qdir.h>
43#include <qlistbox.h> 46#include <qlineedit.h>
47#include <qlistview.h>
44#include <qpopupmenu.h> 48#include <qpopupmenu.h>
45#include <qstring.h> 49#include <qstring.h>
46#include <qwhatsthis.h> 50#include <qwhatsthis.h>
@@ -51,6 +55,14 @@ MainWindow::MainWindow()
51 setCaption( tr( "Checkbook" ) ); 55 setCaption( tr( "Checkbook" ) );
52 56
53 cbDir = Global::applicationFileName( "checkbook", "" ); 57 cbDir = Global::applicationFileName( "checkbook", "" );
58 lockIcon = Resource::loadPixmap( "locked" );
59
60 // Load configuration options
61 Config config( "checkbook" );
62 config.setGroup( "Config" );
63 currencySymbol = config.readEntry( "CurrencySymbol", "$" );
64 showLocks = config.readBoolEntry( "ShowLocks", FALSE );
65 showBalances = config.readBoolEntry( "ShowBalances", FALSE );
54 66
55 // Build menu and tool bars 67 // Build menu and tool bars
56 setToolBarsMovable( FALSE ); 68 setToolBarsMovable( FALSE );
@@ -82,65 +94,152 @@ MainWindow::MainWindow()
82 actionDelete->addTo( popup ); 94 actionDelete->addTo( popup );
83 actionDelete->addTo( bar ); 95 actionDelete->addTo( bar );
84 96
85 mb->insertItem( tr( "Checkbook" ), popup ); 97 popup->insertSeparator();
86 98
87 // Build Checkbook selection list control 99 a = new QAction( tr( "Configure" ), Resource::loadPixmap( "checkbook/config" ), QString::null, 0, this, 0 );
88 cbList = new QListBox( this ); 100 a->setWhatsThis( tr( "Click here to configure this app." ) );
89 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); 101 connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) );
90 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); 102 a->addTo( popup );
91 connect( cbList, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint & ) ), 103 a->addTo( bar );
92 this, SLOT( slotEdit() ) ); 104
93 setCentralWidget( cbList ); 105 mb->insertItem( tr( "Checkbook" ), popup );
94 106
95 // Load Checkbook selection list 107 // Load Checkbook selection list
108 checkbooks = new CBInfoList();
109
96 QDir checkdir( cbDir ); 110 QDir checkdir( cbDir );
97 if (checkdir.exists() == true) 111 if (checkdir.exists() == true)
98 { 112 {
99 QStringList checkbooks = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, 113 QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
100 QDir::Time ); 114 QDir::Time );
101 for ( QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++ ) 115 CBInfo *cb = 0x0;
116 QString filename;
117
118 for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ )
102 { 119 {
103 (*it) = (*it).remove( (*it).find('.'), (*it).length() ); 120 filename = cbDir;
121 filename.append( (*it) );
122
123 cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename );
124 checkbooks->inSort( cb );
104 } 125 }
105 cbList->insertStringList( checkbooks );
106 } 126 }
107 cbList->sort();
108 cbList->setSelected( 0, TRUE );
109 127
110 currencySymbol = "$"; 128 // Build Checkbook selection list control
129 cbList = 0x0;
130 buildList();
111} 131}
112 132
113MainWindow::~MainWindow() 133MainWindow::~MainWindow()
114{ 134{
135 //config.write();
136}
137
138void MainWindow::buildList()
139{
140 if ( cbList )
141 {
142 delete cbList;
143 }
144
145 cbList = new QListView( this );
146 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
147
148 if ( showLocks )
149 {
150 cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
151 posName = 1;
152 }
153 else
154 {
155 posName = 0;
156 }
157 cbList->addColumn( tr( "Checkbook Name" ) );
158 if ( showBalances )
159 {
160 int colnum = cbList->addColumn( tr( "Balance" ) );
161 cbList->setColumnAlignment( colnum, Qt::AlignRight );
162 }
163 cbList->setAllColumnsShowFocus( TRUE );
164 cbList->setSorting( posName );
165 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
166 connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
167 this, SLOT( slotEdit() ) );
168 setCentralWidget( cbList );
169
170 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
171 {
172 addCheckbook( cb );
173 }
174}
175
176void MainWindow::addCheckbook( CBInfo *cb )
177{
178 QListViewItem *lvi = new QListViewItem( cbList );
179 if ( showLocks && !cb->password().isNull() )
180 {
181 lvi->setPixmap( 0, lockIcon );
182 }
183 lvi->setText( posName, cb->name() );
184 if ( showBalances )
185 {
186 QString balance;
187 balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
188 lvi->setText( posName + 1, balance );
189 }
190}
191
192void MainWindow::buildFilename( const QString &name )
193{
194 tempFilename = cbDir;
195 tempFilename.append( name );
196 tempFilename.append( ".qcb" );
115} 197}
116 198
117void MainWindow::slotNew() 199void MainWindow::slotNew()
118{ 200{
119 Checkbook *currcb = new Checkbook( this, "", cbDir, currencySymbol ); 201 CBInfo *cb = new CBInfo();
202
203 Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
120 currcb->showMaximized(); 204 currcb->showMaximized();
121 if ( currcb->exec() == QDialog::Accepted ) 205 if ( currcb->exec() == QDialog::Accepted )
122 { 206 {
123 cbList->insertItem( currcb->getName() ); 207 checkbooks->inSort( cb );
124 cbList->sort(); 208 addCheckbook( cb );
125 delete currcb;
126 } 209 }
210 delete currcb;
127} 211}
128 212
129void MainWindow::slotEdit() 213void MainWindow::slotEdit()
130{ 214{
131 QString currname = cbList->currentText(); 215
132 216 QListViewItem *curritem = cbList->currentItem();
133 QString tempstr = cbDir; 217 if ( !curritem )
134 tempstr.append( currname ); 218 {
135 tempstr.append( ".qcb" ); 219 return;
136 220 }
137 Config config( tempstr, Config::File ); 221 QString currname = curritem->text( posName );
138 config.setGroup( "Account" ); 222
139 QString password = config.readEntryCrypt( "Password", "" ); 223 CBInfo *cb = checkbooks->first();
140 if ( password != "" ) 224 while ( cb )
225 {
226 if ( cb->name() == currname )
227 break;
228 cb = checkbooks->next();
229 }
230 if ( !cb )
231 {
232 return;
233 }
234
235 buildFilename( currname );
236 float currbalance = cb->balance();
237 bool currlock = !cb->password().isNull();
238
239 if ( currlock )
141 { 240 {
142 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 241 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
143 if ( pw->exec() != QDialog::Accepted || pw->password != password ) 242 if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
144 { 243 {
145 delete pw; 244 delete pw;
146 return; 245 return;
@@ -148,39 +247,86 @@ void MainWindow::slotEdit()
148 delete pw; 247 delete pw;
149 } 248 }
150 249
151 Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol ); 250 Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
152 currcb->showMaximized(); 251 currcb->showMaximized();
153 if ( currcb->exec() == QDialog::Accepted ) 252 if ( currcb->exec() == QDialog::Accepted )
154 { 253 {
155 QString newname = currcb->getName(); 254 QString newname = cb->name();
156 if ( currname != newname ) 255 if ( currname != newname )
157 { 256 {
158 cbList->changeItem( newname, cbList->currentItem() ); 257 // Update name if changed
258 curritem->setText( posName, newname );
159 cbList->sort(); 259 cbList->sort();
160 260
161 QFile f( tempstr ); 261 // Remove old file
262 QFile f( tempFilename );
162 if ( f.exists() ) 263 if ( f.exists() )
163 { 264 {
164 f.remove(); 265 f.remove();
165 } 266 }
267
268 // Get new filename
269 buildFilename( newname );
270 cb->setFilename( tempFilename );
271 }
272
273 cb->write();
274
275 // Update lock if changed
276 if ( showLocks && !cb->password().isNull() != currlock )
277 {
278 if ( !cb->password().isNull() )
279 curritem->setPixmap( 0, lockIcon );
280 else
281 curritem->setPixmap( 0, nullIcon );
282 }
283
284 // Update balance if changed
285 if ( showBalances && cb->balance() != currbalance )
286 {
287 QString tempstr;
288 tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
289 curritem->setText( posName + 1, tempstr );
166 } 290 }
167 delete currcb;
168 } 291 }
292 delete currcb;
169} 293}
170 294
171void MainWindow::slotDelete() 295void MainWindow::slotDelete()
172{ 296{
173 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), cbList->currentText() ) ) 297 QString currname = cbList->currentItem()->text( posName );
298
299 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
174 { 300 {
175 QString tempstr = cbDir; 301 buildFilename( currname );
176 tempstr.append( cbList->currentText() ); 302 QFile f( tempFilename );
177 tempstr.append( ".qcb" );
178 QFile f( tempstr );
179 if ( f.exists() ) 303 if ( f.exists() )
180 { 304 {
181 f.remove(); 305 f.remove();
182 } 306 }
183 307
184 cbList->removeItem( cbList->currentItem() ); 308 delete cbList->currentItem();
309 }
310}
311
312void MainWindow::slotConfigure()
313{
314 Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances );
315 cfgdlg->showMaximized();
316 if ( cfgdlg->exec() == QDialog::Accepted )
317 {
318 currencySymbol = cfgdlg->symbolEdit->text();
319 showLocks = cfgdlg->lockCB->isChecked();
320 showBalances = cfgdlg->balCB->isChecked();
321
322 Config config( "checkbook" );
323 config.setGroup( "Config" );
324 config.writeEntry( "CurrencySymbol", currencySymbol );
325 config.writeEntry( "ShowLocks", showLocks );
326 config.writeEntry( "ShowBalances", showBalances );
327 config.write();
328
329 buildList();
185 } 330 }
331 delete cfgdlg;
186} 332}