summaryrefslogtreecommitdiff
authordrw <drw>2003-03-08 22:35:47 (UTC)
committer drw <drw>2003-03-08 22:35:47 (UTC)
commit984291364aaedd4a6e0c50add833d30d7223c3e4 (patch) (unidiff)
tree09f950cd405131f1d63bb2f1ed7abd72563103cf
parent71b6f7c1ced665b062e7546bb8c7196a32deea03 (diff)
downloadopie-984291364aaedd4a6e0c50add833d30d7223c3e4.zip
opie-984291364aaedd4a6e0c50add833d30d7223c3e4.tar.gz
opie-984291364aaedd4a6e0c50add833d30d7223c3e4.tar.bz2
Use inline pic
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index cabd231..ab1ceef 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -1,338 +1,338 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> 4             .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
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 34
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/global.h> 36#include <qpe/global.h>
37#include <qpe/qpeapplication.h> 37#include <qpe/qpeapplication.h>
38#include <qpe/qpemenubar.h> 38#include <qpe/qpemenubar.h>
39#include <qpe/qpemessagebox.h> 39#include <qpe/qpemessagebox.h>
40#include <qpe/qpetoolbar.h> 40#include <qpe/qpetoolbar.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42 42
43#include <qaction.h> 43#include <qaction.h>
44#include <qcheckbox.h> 44#include <qcheckbox.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qlistview.h> 47#include <qlistview.h>
48#include <qpopupmenu.h> 48#include <qpopupmenu.h>
49#include <qstring.h> 49#include <qstring.h>
50#include <qwhatsthis.h> 50#include <qwhatsthis.h>
51 51
52MainWindow::MainWindow() 52MainWindow::MainWindow()
53 : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) 53 : QMainWindow( 0x0, 0x0, WStyle_ContextHelp )
54{ 54{
55 setCaption( tr( "Checkbook" ) ); 55 setCaption( tr( "Checkbook" ) );
56 56
57 cbDir = Global::applicationFileName( "checkbook", "" ); 57 cbDir = Global::applicationFileName( "checkbook", "" );
58 lockIcon = Resource::loadPixmap( "locked" ); 58 lockIcon = Resource::loadPixmap( "locked" );
59 59
60 // Load configuration options 60 // Load configuration options
61 Config config( "checkbook" ); 61 Config config( "checkbook" );
62 config.setGroup( "Config" ); 62 config.setGroup( "Config" );
63 currencySymbol = config.readEntry( "CurrencySymbol", "$" ); 63 currencySymbol = config.readEntry( "CurrencySymbol", "$" );
64 showLocks = config.readBoolEntry( "ShowLocks", FALSE ); 64 showLocks = config.readBoolEntry( "ShowLocks", FALSE );
65 showBalances = config.readBoolEntry( "ShowBalances", FALSE ); 65 showBalances = config.readBoolEntry( "ShowBalances", FALSE );
66 66
67 // Build menu and tool bars 67 // Build menu and tool bars
68 setToolBarsMovable( FALSE ); 68 setToolBarsMovable( FALSE );
69 69
70 QPEToolBar *bar = new QPEToolBar( this ); 70 QPEToolBar *bar = new QPEToolBar( this );
71 bar->setHorizontalStretchable( TRUE ); 71 bar->setHorizontalStretchable( TRUE );
72 QPEMenuBar *mb = new QPEMenuBar( bar ); 72 QPEMenuBar *mb = new QPEMenuBar( bar );
73 mb->setMargin( 0 ); 73 mb->setMargin( 0 );
74 QPopupMenu *popup = new QPopupMenu( this ); 74 QPopupMenu *popup = new QPopupMenu( this );
75 75
76 bar = new QPEToolBar( this ); 76 bar = new QPEToolBar( this );
77 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 77 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
78 a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); 78 a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) );
79 connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); 79 connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) );
80 a->addTo( popup ); 80 a->addTo( popup );
81 a->addTo( bar ); 81 a->addTo( bar );
82 82
83 actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 83 actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
84 0, this, 0 ); 84 0, this, 0 );
85 actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); 85 actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) );
86 connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); 86 connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) );
87 actionOpen->addTo( popup ); 87 actionOpen->addTo( popup );
88 actionOpen->addTo( bar ); 88 actionOpen->addTo( bar );
89 89
90 actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 90 actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
91 0, this, 0 ); 91 0, this, 0 );
92 actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); 92 actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) );
93 connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); 93 connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) );
94 actionDelete->addTo( popup ); 94 actionDelete->addTo( popup );
95 actionDelete->addTo( bar ); 95 actionDelete->addTo( bar );
96 96
97 popup->insertSeparator(); 97 popup->insertSeparator();
98 98
99 a = new QAction( tr( "Configure" ), Resource::loadPixmap( "checkbook/config" ), QString::null, 0, this, 0 ); 99 a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 );
100 a->setWhatsThis( tr( "Click here to configure this app." ) ); 100 a->setWhatsThis( tr( "Click here to configure this app." ) );
101 connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); 101 connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) );
102 a->addTo( popup ); 102 a->addTo( popup );
103 a->addTo( bar ); 103 a->addTo( bar );
104 104
105 mb->insertItem( tr( "Checkbook" ), popup ); 105 mb->insertItem( tr( "Checkbook" ), popup );
106 106
107 // Load Checkbook selection list 107 // Load Checkbook selection list
108 checkbooks = new CBInfoList(); 108 checkbooks = new CBInfoList();
109 109
110 QDir checkdir( cbDir ); 110 QDir checkdir( cbDir );
111 if (checkdir.exists() == true) 111 if (checkdir.exists() == true)
112 { 112 {
113 QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, 113 QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
114 QDir::Time ); 114 QDir::Time );
115 CBInfo *cb = 0x0; 115 CBInfo *cb = 0x0;
116 QString filename; 116 QString filename;
117 117
118 for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) 118 for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ )
119 { 119 {
120 filename = cbDir; 120 filename = cbDir;
121 filename.append( (*it) ); 121 filename.append( (*it) );
122 122
123 cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); 123 cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename );
124 checkbooks->inSort( cb ); 124 checkbooks->inSort( cb );
125 } 125 }
126 } 126 }
127 127
128 // Build Checkbook selection list control 128 // Build Checkbook selection list control
129 cbList = 0x0; 129 cbList = 0x0;
130 buildList(); 130 buildList();
131} 131}
132 132
133MainWindow::~MainWindow() 133MainWindow::~MainWindow()
134{ 134{
135 //config.write(); 135 //config.write();
136} 136}
137 137
138void MainWindow::buildList() 138void MainWindow::buildList()
139{ 139{
140 if ( cbList ) 140 if ( cbList )
141 { 141 {
142 delete cbList; 142 delete cbList;
143 } 143 }
144 144
145 cbList = new QListView( this ); 145 cbList = new QListView( this );
146 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); 146 QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) );
147 147
148 if ( showLocks ) 148 if ( showLocks )
149 { 149 {
150 cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); 150 cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 );
151 posName = 1; 151 posName = 1;
152 } 152 }
153 else 153 else
154 { 154 {
155 posName = 0; 155 posName = 0;
156 } 156 }
157 cbList->addColumn( tr( "Checkbook Name" ) ); 157 cbList->addColumn( tr( "Checkbook Name" ) );
158 if ( showBalances ) 158 if ( showBalances )
159 { 159 {
160 int colnum = cbList->addColumn( tr( "Balance" ) ); 160 int colnum = cbList->addColumn( tr( "Balance" ) );
161 cbList->setColumnAlignment( colnum, Qt::AlignRight ); 161 cbList->setColumnAlignment( colnum, Qt::AlignRight );
162 } 162 }
163 cbList->setAllColumnsShowFocus( TRUE ); 163 cbList->setAllColumnsShowFocus( TRUE );
164 cbList->setSorting( posName ); 164 cbList->setSorting( posName );
165 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); 165 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
166 connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), 166 connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
167 this, SLOT( slotEdit() ) ); 167 this, SLOT( slotEdit() ) );
168 setCentralWidget( cbList ); 168 setCentralWidget( cbList );
169 169
170 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) 170 for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() )
171 { 171 {
172 addCheckbook( cb ); 172 addCheckbook( cb );
173 } 173 }
174} 174}
175 175
176void MainWindow::addCheckbook( CBInfo *cb ) 176void MainWindow::addCheckbook( CBInfo *cb )
177{ 177{
178 QListViewItem *lvi = new QListViewItem( cbList ); 178 QListViewItem *lvi = new QListViewItem( cbList );
179 if ( showLocks && !cb->password().isNull() ) 179 if ( showLocks && !cb->password().isNull() )
180 { 180 {
181 lvi->setPixmap( 0, lockIcon ); 181 lvi->setPixmap( 0, lockIcon );
182 } 182 }
183 lvi->setText( posName, cb->name() ); 183 lvi->setText( posName, cb->name() );
184 if ( showBalances ) 184 if ( showBalances )
185 { 185 {
186 QString balance; 186 QString balance;
187 balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); 187 balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
188 lvi->setText( posName + 1, balance ); 188 lvi->setText( posName + 1, balance );
189 } 189 }
190} 190}
191 191
192void MainWindow::buildFilename( const QString &name ) 192void MainWindow::buildFilename( const QString &name )
193{ 193{
194 tempFilename = cbDir; 194 tempFilename = cbDir;
195 tempFilename.append( name ); 195 tempFilename.append( name );
196 tempFilename.append( ".qcb" ); 196 tempFilename.append( ".qcb" );
197} 197}
198 198
199void MainWindow::slotNew() 199void MainWindow::slotNew()
200{ 200{
201 CBInfo *cb = new CBInfo(); 201 CBInfo *cb = new CBInfo();
202 202
203 Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); 203 Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
204 currcb->showMaximized(); 204 currcb->showMaximized();
205 if ( currcb->exec() == QDialog::Accepted ) 205 if ( currcb->exec() == QDialog::Accepted )
206 { 206 {
207 // Save new checkbook 207 // Save new checkbook
208 buildFilename( cb->name() ); 208 buildFilename( cb->name() );
209 cb->setFilename( tempFilename ); 209 cb->setFilename( tempFilename );
210 cb->write(); 210 cb->write();
211 211
212 // Add to listbox 212 // Add to listbox
213 checkbooks->inSort( cb ); 213 checkbooks->inSort( cb );
214 addCheckbook( cb ); 214 addCheckbook( cb );
215 } 215 }
216 delete currcb; 216 delete currcb;
217} 217}
218 218
219void MainWindow::slotEdit() 219void MainWindow::slotEdit()
220{ 220{
221 221
222 QListViewItem *curritem = cbList->currentItem(); 222 QListViewItem *curritem = cbList->currentItem();
223 if ( !curritem ) 223 if ( !curritem )
224 { 224 {
225 return; 225 return;
226 } 226 }
227 QString currname = curritem->text( posName ); 227 QString currname = curritem->text( posName );
228 228
229 CBInfo *cb = checkbooks->first(); 229 CBInfo *cb = checkbooks->first();
230 while ( cb ) 230 while ( cb )
231 { 231 {
232 if ( cb->name() == currname ) 232 if ( cb->name() == currname )
233 break; 233 break;
234 cb = checkbooks->next(); 234 cb = checkbooks->next();
235 } 235 }
236 if ( !cb ) 236 if ( !cb )
237 { 237 {
238 return; 238 return;
239 } 239 }
240 240
241 buildFilename( currname ); 241 buildFilename( currname );
242 float currbalance = cb->balance(); 242 float currbalance = cb->balance();
243 bool currlock = !cb->password().isNull(); 243 bool currlock = !cb->password().isNull();
244 244
245 if ( currlock ) 245 if ( currlock )
246 { 246 {
247 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); 247 Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
248 if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) 248 if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
249 { 249 {
250 delete pw; 250 delete pw;
251 return; 251 return;
252 } 252 }
253 delete pw; 253 delete pw;
254 } 254 }
255 255
256 Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); 256 Checkbook *currcb = new Checkbook( this, cb, currencySymbol );
257 currcb->showMaximized(); 257 currcb->showMaximized();
258 if ( currcb->exec() == QDialog::Accepted ) 258 if ( currcb->exec() == QDialog::Accepted )
259 { 259 {
260 QString newname = cb->name(); 260 QString newname = cb->name();
261 if ( currname != newname ) 261 if ( currname != newname )
262 { 262 {
263 // Update name if changed 263 // Update name if changed
264 curritem->setText( posName, newname ); 264 curritem->setText( posName, newname );
265 cbList->sort(); 265 cbList->sort();
266 266
267 // Remove old file 267 // Remove old file
268 QFile f( tempFilename ); 268 QFile f( tempFilename );
269 if ( f.exists() ) 269 if ( f.exists() )
270 { 270 {
271 f.remove(); 271 f.remove();
272 } 272 }
273 273
274 // Get new filename 274 // Get new filename
275 buildFilename( newname ); 275 buildFilename( newname );
276 cb->setFilename( tempFilename ); 276 cb->setFilename( tempFilename );
277 } 277 }
278 278
279 cb->write(); 279 cb->write();
280 280
281 // Update lock if changed 281 // Update lock if changed
282 if ( showLocks && !cb->password().isNull() != currlock ) 282 if ( showLocks && !cb->password().isNull() != currlock )
283 { 283 {
284 if ( !cb->password().isNull() ) 284 if ( !cb->password().isNull() )
285 curritem->setPixmap( 0, lockIcon ); 285 curritem->setPixmap( 0, lockIcon );
286 else 286 else
287 curritem->setPixmap( 0, nullIcon ); 287 curritem->setPixmap( 0, nullIcon );
288 } 288 }
289 289
290 // Update balance if changed 290 // Update balance if changed
291 if ( showBalances && cb->balance() != currbalance ) 291 if ( showBalances && cb->balance() != currbalance )
292 { 292 {
293 QString tempstr; 293 QString tempstr;
294 tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); 294 tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() );
295 curritem->setText( posName + 1, tempstr ); 295 curritem->setText( posName + 1, tempstr );
296 } 296 }
297 } 297 }
298 delete currcb; 298 delete currcb;
299} 299}
300 300
301void MainWindow::slotDelete() 301void MainWindow::slotDelete()
302{ 302{
303 QString currname = cbList->currentItem()->text( posName ); 303 QString currname = cbList->currentItem()->text( posName );
304 304
305 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) 305 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
306 { 306 {
307 buildFilename( currname ); 307 buildFilename( currname );
308 QFile f( tempFilename ); 308 QFile f( tempFilename );
309 if ( f.exists() ) 309 if ( f.exists() )
310 { 310 {
311 f.remove(); 311 f.remove();
312 } 312 }
313 313
314 delete cbList->currentItem(); 314 delete cbList->currentItem();
315 } 315 }
316} 316}
317 317
318void MainWindow::slotConfigure() 318void MainWindow::slotConfigure()
319{ 319{
320 Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances ); 320 Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances );
321 cfgdlg->showMaximized(); 321 cfgdlg->showMaximized();
322 if ( cfgdlg->exec() == QDialog::Accepted ) 322 if ( cfgdlg->exec() == QDialog::Accepted )
323 { 323 {
324 currencySymbol = cfgdlg->symbolEdit->text(); 324 currencySymbol = cfgdlg->symbolEdit->text();
325 showLocks = cfgdlg->lockCB->isChecked(); 325 showLocks = cfgdlg->lockCB->isChecked();
326 showBalances = cfgdlg->balCB->isChecked(); 326 showBalances = cfgdlg->balCB->isChecked();
327 327
328 Config config( "checkbook" ); 328 Config config( "checkbook" );
329 config.setGroup( "Config" ); 329 config.setGroup( "Config" );
330 config.writeEntry( "CurrencySymbol", currencySymbol ); 330 config.writeEntry( "CurrencySymbol", currencySymbol );
331 config.writeEntry( "ShowLocks", showLocks ); 331 config.writeEntry( "ShowLocks", showLocks );
332 config.writeEntry( "ShowBalances", showBalances ); 332 config.writeEntry( "ShowBalances", showBalances );
333 config.write(); 333 config.write();
334 334
335 buildList(); 335 buildList();
336 } 336 }
337 delete cfgdlg; 337 delete cfgdlg;
338} 338}