author | zecke <zecke> | 2004-10-26 21:28:59 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-10-26 21:28:59 (UTC) |
commit | ae5855babec6e46802be89ee408d26a2cbbb1981 (patch) (unidiff) | |
tree | 6aab434ceb2831741b997b93f053e1843c3d59ec | |
parent | c95aeb8fd283fe9d2f220209e696726120857257 (diff) | |
download | opie-ae5855babec6e46802be89ee408d26a2cbbb1981.zip opie-ae5855babec6e46802be89ee408d26a2cbbb1981.tar.gz opie-ae5855babec6e46802be89ee408d26a2cbbb1981.tar.bz2 |
-Remove usage of latin1() as a possible fix to #1471
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 18 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 6 |
2 files changed, 17 insertions, 7 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 706d970..44d3764 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -145,592 +145,600 @@ QWidget *Checkbook::initInfo() | |||
145 | layout->addWidget( label, 2, 0 ); | 145 | layout->addWidget( label, 2, 0 ); |
146 | typeList = new QComboBox( container ); | 146 | typeList = new QComboBox( container ); |
147 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); | 147 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); |
148 | typeList->insertStringList( _pCfg->getAccountTypes() ); | 148 | typeList->insertStringList( _pCfg->getAccountTypes() ); |
149 | layout->addWidget( typeList, 2, 1 ); | 149 | layout->addWidget( typeList, 2, 1 ); |
150 | 150 | ||
151 | // Bank/institution name | 151 | // Bank/institution name |
152 | label = new QLabel( tr( "Bank:" ), container ); | 152 | label = new QLabel( tr( "Bank:" ), container ); |
153 | QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); | 153 | QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); |
154 | layout->addWidget( label, 3, 0 ); | 154 | layout->addWidget( label, 3, 0 ); |
155 | bankEdit = new QLineEdit( container ); | 155 | bankEdit = new QLineEdit( container ); |
156 | QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); | 156 | QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); |
157 | layout->addWidget( bankEdit, 3, 1 ); | 157 | layout->addWidget( bankEdit, 3, 1 ); |
158 | 158 | ||
159 | // Account number | 159 | // Account number |
160 | label = new QLabel( tr( "Account number:" ), container ); | 160 | label = new QLabel( tr( "Account number:" ), container ); |
161 | QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); | 161 | QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); |
162 | layout->addWidget( label, 4, 0 ); | 162 | layout->addWidget( label, 4, 0 ); |
163 | acctNumEdit = new QLineEdit( container ); | 163 | acctNumEdit = new QLineEdit( container ); |
164 | QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); | 164 | QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); |
165 | layout->addWidget( acctNumEdit, 4, 1 ); | 165 | layout->addWidget( acctNumEdit, 4, 1 ); |
166 | 166 | ||
167 | // PIN number | 167 | // PIN number |
168 | label = new QLabel( tr( "PIN number:" ), container ); | 168 | label = new QLabel( tr( "PIN number:" ), container ); |
169 | QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); | 169 | QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); |
170 | layout->addWidget( label, 5, 0 ); | 170 | layout->addWidget( label, 5, 0 ); |
171 | pinNumEdit = new QLineEdit( container ); | 171 | pinNumEdit = new QLineEdit( container ); |
172 | QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); | 172 | QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); |
173 | layout->addWidget( pinNumEdit, 5, 1 ); | 173 | layout->addWidget( pinNumEdit, 5, 1 ); |
174 | 174 | ||
175 | // Starting balance | 175 | // Starting balance |
176 | label = new QLabel( tr( "Starting balance:" ), container ); | 176 | label = new QLabel( tr( "Starting balance:" ), container ); |
177 | QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); | 177 | QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); |
178 | layout->addWidget( label, 6, 0 ); | 178 | layout->addWidget( label, 6, 0 ); |
179 | balanceEdit = new QLineEdit( container ); | 179 | balanceEdit = new QLineEdit( container ); |
180 | QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); | 180 | QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); |
181 | connect( balanceEdit, SIGNAL( textChanged(const QString&) ), | 181 | connect( balanceEdit, SIGNAL( textChanged(const QString&) ), |
182 | this, SLOT( slotStartingBalanceChanged(const QString&) ) ); | 182 | this, SLOT( slotStartingBalanceChanged(const QString&) ) ); |
183 | layout->addWidget( balanceEdit, 6, 1 ); | 183 | layout->addWidget( balanceEdit, 6, 1 ); |
184 | 184 | ||
185 | // Notes | 185 | // Notes |
186 | label = new QLabel( tr( "Notes:" ), container ); | 186 | label = new QLabel( tr( "Notes:" ), container ); |
187 | QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); | 187 | QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); |
188 | layout->addWidget( label, 7, 0 ); | 188 | layout->addWidget( label, 7, 0 ); |
189 | notesEdit = new QMultiLineEdit( container ); | 189 | notesEdit = new QMultiLineEdit( container ); |
190 | QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); | 190 | QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); |
191 | notesEdit->setMinimumHeight( 25 ); | 191 | notesEdit->setMinimumHeight( 25 ); |
192 | notesEdit->setMaximumHeight( 65 ); | 192 | notesEdit->setMaximumHeight( 65 ); |
193 | layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); | 193 | layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); |
194 | 194 | ||
195 | return control; | 195 | return control; |
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
199 | // --- initTransactions ------------------------------------------------------- | 199 | // --- initTransactions ------------------------------------------------------- |
200 | QWidget *Checkbook::initTransactions() | 200 | QWidget *Checkbook::initTransactions() |
201 | { | 201 | { |
202 | QWidget *control = new QWidget( mainWidget, tr("Transactions") ); | 202 | QWidget *control = new QWidget( mainWidget, tr("Transactions") ); |
203 | 203 | ||
204 | QGridLayout *layout = new QGridLayout( control ); | 204 | QGridLayout *layout = new QGridLayout( control ); |
205 | layout->setSpacing( 2 ); | 205 | layout->setSpacing( 2 ); |
206 | layout->setMargin( 4 ); | 206 | layout->setMargin( 4 ); |
207 | 207 | ||
208 | // Sort selector | 208 | // Sort selector |
209 | QLabel *label = new QLabel( tr( "Sort by:" ), control ); | 209 | QLabel *label = new QLabel( tr( "Sort by:" ), control ); |
210 | QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); | 210 | QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); |
211 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); | 211 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); |
212 | _cbSortType=new QComboBox( control ); | 212 | _cbSortType=new QComboBox( control ); |
213 | _cbSortType->insertItem( tr("Entry Order") ); | 213 | _cbSortType->insertItem( tr("Entry Order") ); |
214 | _cbSortType->insertItem( tr("Date") ); | 214 | _cbSortType->insertItem( tr("Date") ); |
215 | _cbSortType->insertItem( tr("Number") ); | 215 | _cbSortType->insertItem( tr("Number") ); |
216 | layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); | 216 | layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); |
217 | connect( _cbSortType, SIGNAL( activated(const QString&) ), this, SLOT( slotSortChanged(const QString&) ) ); | 217 | connect( _cbSortType, SIGNAL( activated(const QString&) ), this, SLOT( slotSortChanged(const QString&) ) ); |
218 | 218 | ||
219 | // Table | 219 | // Table |
220 | tranTable = new QListView( control ); | 220 | tranTable = new QListView( control ); |
221 | QFont fnt(QPEApplication::font()); | 221 | QFont fnt(QPEApplication::font()); |
222 | fnt.setPointSize( fnt.pointSize()-1 ); | 222 | fnt.setPointSize( fnt.pointSize()-1 ); |
223 | tranTable->setFont( fnt ); | 223 | tranTable->setFont( fnt ); |
224 | QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); | 224 | QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); |
225 | tranTable->addColumn( tr( "Id" ) ); | 225 | tranTable->addColumn( tr( "Id" ) ); |
226 | tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); | 226 | tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); |
227 | tranTable->setColumnWidth( COL_ID, 0); | 227 | tranTable->setColumnWidth( COL_ID, 0); |
228 | tranTable->addColumn( tr( "SortDate" ) ); | 228 | tranTable->addColumn( tr( "SortDate" ) ); |
229 | tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual ); | 229 | tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual ); |
230 | tranTable->setColumnWidth( COL_SORTDATE, 0); | 230 | tranTable->setColumnWidth( COL_SORTDATE, 0); |
231 | tranTable->addColumn( tr( "Num" ) ); | 231 | tranTable->addColumn( tr( "Num" ) ); |
232 | tranTable->addColumn( tr( "Date" ) ); | 232 | tranTable->addColumn( tr( "Date" ) ); |
233 | //tranTable->addColumn( tr( "Cleared" ) ); | 233 | //tranTable->addColumn( tr( "Cleared" ) ); |
234 | tranTable->addColumn( tr( "Description" ) ); | 234 | tranTable->addColumn( tr( "Description" ) ); |
235 | int column = tranTable->addColumn( tr( "Amount" ) ); | 235 | int column = tranTable->addColumn( tr( "Amount" ) ); |
236 | tranTable->setColumnAlignment( column, Qt::AlignRight ); | 236 | tranTable->setColumnAlignment( column, Qt::AlignRight ); |
237 | column=tranTable->addColumn( tr("Balance") ); | 237 | column=tranTable->addColumn( tr("Balance") ); |
238 | tranTable->setColumnAlignment( column, Qt::AlignRight ); | 238 | tranTable->setColumnAlignment( column, Qt::AlignRight ); |
239 | tranTable->setAllColumnsShowFocus( TRUE ); | 239 | tranTable->setAllColumnsShowFocus( TRUE ); |
240 | tranTable->setSorting( -1 ); | 240 | tranTable->setSorting( -1 ); |
241 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); | 241 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); |
242 | QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); | 242 | QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); |
243 | connect( tranTable, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), | 243 | connect( tranTable, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), |
244 | this, SLOT( slotMenuTran(QListViewItem*,const QPoint&) ) ); | 244 | this, SLOT( slotMenuTran(QListViewItem*,const QPoint&) ) ); |
245 | connect( tranTable, SIGNAL( doubleClicked(QListViewItem*) ), | 245 | connect( tranTable, SIGNAL( doubleClicked(QListViewItem*) ), |
246 | this, SLOT( slotEditTran() ) ); | 246 | this, SLOT( slotEditTran() ) ); |
247 | _sortCol=COL_ID; | 247 | _sortCol=COL_ID; |
248 | 248 | ||
249 | // Buttons | 249 | // Buttons |
250 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); | 250 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); |
251 | QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); | 251 | QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); |
252 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); | 252 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); |
253 | layout->addWidget( btn, 2, 0 ); | 253 | layout->addWidget( btn, 2, 0 ); |
254 | 254 | ||
255 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); | 255 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); |
256 | QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); | 256 | QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); |
257 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); | 257 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); |
258 | layout->addWidget( btn, 2, 1 ); | 258 | layout->addWidget( btn, 2, 1 ); |
259 | 259 | ||
260 | btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); | 260 | btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); |
261 | QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); | 261 | QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); |
262 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); | 262 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); |
263 | layout->addWidget( btn, 2, 2 ); | 263 | layout->addWidget( btn, 2, 2 ); |
264 | 264 | ||
265 | return( control ); | 265 | return( control ); |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | // --- initCharts ------------------------------------------------------------- | 269 | // --- initCharts ------------------------------------------------------------- |
270 | QWidget *Checkbook::initCharts() | 270 | QWidget *Checkbook::initCharts() |
271 | { | 271 | { |
272 | graphInfo = 0x0; | 272 | graphInfo = 0x0; |
273 | 273 | ||
274 | QWidget *control = new QWidget( mainWidget, tr("Charts") ); | 274 | QWidget *control = new QWidget( mainWidget, tr("Charts") ); |
275 | 275 | ||
276 | QGridLayout *layout = new QGridLayout( control ); | 276 | QGridLayout *layout = new QGridLayout( control ); |
277 | layout->setSpacing( 2 ); | 277 | layout->setSpacing( 2 ); |
278 | layout->setMargin( 4 ); | 278 | layout->setMargin( 4 ); |
279 | 279 | ||
280 | graphWidget = new Graph( control ); | 280 | graphWidget = new Graph( control ); |
281 | QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); | 281 | QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); |
282 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); | 282 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); |
283 | 283 | ||
284 | graphList = new QComboBox( control ); | 284 | graphList = new QComboBox( control ); |
285 | QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); | 285 | QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); |
286 | graphList->insertItem( tr( "Account balance" ) ); | 286 | graphList->insertItem( tr( "Account balance" ) ); |
287 | graphList->insertItem( tr( "Withdrawals by category" ) ); | 287 | graphList->insertItem( tr( "Withdrawals by category" ) ); |
288 | graphList->insertItem( tr( "Deposits by category" ) ); | 288 | graphList->insertItem( tr( "Deposits by category" ) ); |
289 | 289 | ||
290 | layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); | 290 | layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); |
291 | 291 | ||
292 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); | 292 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); |
293 | QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); | 293 | QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); |
294 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); | 294 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); |
295 | layout->addWidget( btn, 1, 2 ); | 295 | layout->addWidget( btn, 1, 2 ); |
296 | 296 | ||
297 | return control; | 297 | return control; |
298 | } | 298 | } |
299 | 299 | ||
300 | // --- loadCheckbook ---------------------------------------------------------- | 300 | // --- loadCheckbook ---------------------------------------------------------- |
301 | void Checkbook::loadCheckbook() | 301 | void Checkbook::loadCheckbook() |
302 | { | 302 | { |
303 | if ( !info ) | 303 | if ( !info ) |
304 | { | 304 | { |
305 | return; | 305 | return; |
306 | } | 306 | } |
307 | 307 | ||
308 | tranList = info->transactions(); | 308 | tranList = info->transactions(); |
309 | 309 | ||
310 | passwordCB->setChecked( !info->password().isNull() ); | 310 | passwordCB->setChecked( !info->password().isNull() ); |
311 | nameEdit->setText( info->name() ); | 311 | nameEdit->setText( info->name() ); |
312 | QString temptext = info->type(); | 312 | QString temptext = info->type(); |
313 | int i = typeList->count(); | 313 | int i = typeList->count(); |
314 | while ( i > 0 ) | 314 | while ( i > 0 ) |
315 | { | 315 | { |
316 | i--; | 316 | i--; |
317 | typeList->setCurrentItem( i ); | 317 | typeList->setCurrentItem( i ); |
318 | if ( typeList->currentText() == temptext ) | 318 | if ( typeList->currentText() == temptext ) |
319 | { | 319 | { |
320 | break; | 320 | break; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | if( i<=0 ) { | 323 | if( i<=0 ) { |
324 | typeList->insertItem( temptext, 0 ); | 324 | typeList->insertItem( temptext, 0 ); |
325 | typeList->setCurrentItem(0); | 325 | typeList->setCurrentItem(0); |
326 | } | 326 | } |
327 | bankEdit->setText( info->bank() ); | 327 | bankEdit->setText( info->bank() ); |
328 | acctNumEdit->setText( info->account() ); | 328 | acctNumEdit->setText( info->account() ); |
329 | pinNumEdit->setText( info->pin() ); | 329 | pinNumEdit->setText( info->pin() ); |
330 | temptext.setNum( info->startingBalance(), 'f', 2 ); | 330 | temptext.setNum( info->startingBalance(), 'f', 2 ); |
331 | balanceEdit->setText( temptext ); | 331 | balanceEdit->setText( temptext ); |
332 | notesEdit->setText( info->notes() ); | 332 | notesEdit->setText( info->notes() ); |
333 | 333 | ||
334 | // Load transactions | 334 | // Load transactions |
335 | float amount; | 335 | float amount; |
336 | QString stramount; | 336 | QString stramount; |
337 | QString symbol = _pCfg->getCurrencySymbol(); | ||
337 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) | 338 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) |
338 | { | 339 | { |
339 | amount = tran->amount(); | 340 | amount = tran->amount(); |
340 | if ( tran->withdrawal() ) | 341 | if ( tran->withdrawal() ) |
341 | { | 342 | { |
342 | amount *= -1; | 343 | amount *= -1; |
343 | } | 344 | } |
344 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); | 345 | stramount.sprintf( "%.2f", amount ); |
346 | stramount.prepend( symbol ); | ||
345 | ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount ); | 347 | ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount ); |
346 | } | 348 | } |
347 | 349 | ||
348 | // set sort order | 350 | // set sort order |
349 | bool bOk=false; | 351 | bool bOk=false; |
350 | for(int i=0; i<_cbSortType->count(); i++) { | 352 | for(int i=0; i<_cbSortType->count(); i++) { |
351 | if( _cbSortType->text(i)==info->getSortOrder() ) { | 353 | if( _cbSortType->text(i)==info->getSortOrder() ) { |
352 | _cbSortType->setCurrentItem(i); | 354 | _cbSortType->setCurrentItem(i); |
353 | slotSortChanged( info->getSortOrder() ); | 355 | slotSortChanged( info->getSortOrder() ); |
354 | bOk=true; | 356 | bOk=true; |
355 | break; | 357 | break; |
356 | } | 358 | } |
357 | } | 359 | } |
358 | if( !bOk ) { | 360 | if( !bOk ) { |
359 | _cbSortType->setCurrentItem(0); | 361 | _cbSortType->setCurrentItem(0); |
360 | slotSortChanged( _cbSortType->currentText() ); | 362 | slotSortChanged( _cbSortType->currentText() ); |
361 | } | 363 | } |
362 | 364 | ||
363 | // calc running balance | 365 | // calc running balance |
364 | adjustBalance(); | 366 | adjustBalance(); |
365 | } | 367 | } |
366 | 368 | ||
367 | 369 | ||
368 | // --- adjustBalance ---------------------------------------------------------- | 370 | // --- adjustBalance ---------------------------------------------------------- |
369 | void Checkbook::adjustBalance() | 371 | void Checkbook::adjustBalance() |
370 | { | 372 | { |
371 | // update running balance in register | 373 | // update running balance in register |
372 | QString sRunning; | 374 | QString sRunning; |
375 | QString symbol = _pCfg->getCurrencySymbol(); | ||
373 | float bal=info->startingBalance(); | 376 | float bal=info->startingBalance(); |
377 | |||
374 | for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { | 378 | for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { |
375 | TranInfo *tran=item->getTranInfo(); | 379 | TranInfo *tran=item->getTranInfo(); |
376 | bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); | 380 | bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); |
377 | sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); | 381 | sRunning.sprintf( "%.2f", bal ); |
382 | sRunning.prepend(symbol); | ||
378 | item->setText( COL_BAL, sRunning); | 383 | item->setText( COL_BAL, sRunning); |
379 | } | 384 | } |
380 | } | 385 | } |
381 | 386 | ||
382 | // --- resort ----------------------------------------------------------------- | 387 | // --- resort ----------------------------------------------------------------- |
383 | void Checkbook::resort() | 388 | void Checkbook::resort() |
384 | { | 389 | { |
385 | tranTable->setSorting(_sortCol); | 390 | tranTable->setSorting(_sortCol); |
386 | tranTable->sort(); | 391 | tranTable->sort(); |
387 | tranTable->setSorting(-1); | 392 | tranTable->setSorting(-1); |
388 | } | 393 | } |
389 | 394 | ||
390 | 395 | ||
391 | // --- accept ----------------------------------------------------------------- | 396 | // --- accept ----------------------------------------------------------------- |
392 | void Checkbook::accept() | 397 | void Checkbook::accept() |
393 | { | 398 | { |
394 | info->setName( nameEdit->text() ); | 399 | info->setName( nameEdit->text() ); |
395 | info->setType( typeList->currentText() ); | 400 | info->setType( typeList->currentText() ); |
396 | info->setBank( bankEdit->text() ); | 401 | info->setBank( bankEdit->text() ); |
397 | info->setAccount( acctNumEdit->text() ); | 402 | info->setAccount( acctNumEdit->text() ); |
398 | info->setPin( pinNumEdit->text() ); | 403 | info->setPin( pinNumEdit->text() ); |
399 | bool ok; | 404 | bool ok; |
400 | info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); | 405 | info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); |
401 | info->setNotes( notesEdit->text() ); | 406 | info->setNotes( notesEdit->text() ); |
402 | 407 | ||
403 | QDialog::accept(); | 408 | QDialog::accept(); |
404 | } | 409 | } |
405 | 410 | ||
406 | // --- slotPasswordClicked ---------------------------------------------------- | 411 | // --- slotPasswordClicked ---------------------------------------------------- |
407 | void Checkbook::slotPasswordClicked() | 412 | void Checkbook::slotPasswordClicked() |
408 | { | 413 | { |
409 | if ( info->password().isNull() && passwordCB->isChecked() ) | 414 | if ( info->password().isNull() && passwordCB->isChecked() ) |
410 | { | 415 | { |
411 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 416 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
412 | if ( pw->exec() != QDialog::Accepted ) | 417 | if ( pw->exec() != QDialog::Accepted ) |
413 | { | 418 | { |
414 | passwordCB->setChecked( FALSE ); | 419 | passwordCB->setChecked( FALSE ); |
415 | delete pw; | 420 | delete pw; |
416 | return; | 421 | return; |
417 | } | 422 | } |
418 | info->setPassword( pw->password ); | 423 | info->setPassword( pw->password ); |
419 | delete pw; | 424 | delete pw; |
420 | 425 | ||
421 | pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); | 426 | pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); |
422 | if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) | 427 | if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) |
423 | { | 428 | { |
424 | passwordCB->setChecked( FALSE ); | 429 | passwordCB->setChecked( FALSE ); |
425 | info->setPassword( QString::null ); | 430 | info->setPassword( QString::null ); |
426 | } | 431 | } |
427 | 432 | ||
428 | delete pw; | 433 | delete pw; |
429 | } | 434 | } |
430 | else if ( !info->password().isNull() && !passwordCB->isChecked() ) | 435 | else if ( !info->password().isNull() && !passwordCB->isChecked() ) |
431 | { | 436 | { |
432 | Password *pw = new Password( this, tr( "Enter password" ), | 437 | Password *pw = new Password( this, tr( "Enter password" ), |
433 | tr( "Please enter your password to confirm removal of password protection:" ) ); | 438 | tr( "Please enter your password to confirm removal of password protection:" ) ); |
434 | if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) | 439 | if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) |
435 | { | 440 | { |
436 | info->setPassword( QString::null ); | 441 | info->setPassword( QString::null ); |
437 | delete pw; | 442 | delete pw; |
438 | return; | 443 | return; |
439 | } | 444 | } |
440 | else | 445 | else |
441 | { | 446 | { |
442 | passwordCB->setChecked( TRUE ); | 447 | passwordCB->setChecked( TRUE ); |
443 | } | 448 | } |
444 | 449 | ||
445 | delete pw; | 450 | delete pw; |
446 | } | 451 | } |
447 | } | 452 | } |
448 | 453 | ||
449 | void Checkbook::slotNameChanged( const QString &newname ) | 454 | void Checkbook::slotNameChanged( const QString &newname ) |
450 | { | 455 | { |
451 | info->setName( newname ); | 456 | info->setName( newname ); |
452 | 457 | ||
453 | // TODO - need filedir | 458 | // TODO - need filedir |
454 | // QString namestr = filedir; | 459 | // QString namestr = filedir; |
455 | // namestr.append( newname ); | 460 | // namestr.append( newname ); |
456 | // namestr.append( ".qcb" ); | 461 | // namestr.append( ".qcb" ); |
457 | // info->setFilename( namestr ); | 462 | // info->setFilename( namestr ); |
458 | 463 | ||
459 | QString namestr = newname; | 464 | QString namestr = newname; |
460 | namestr.append( " - " ); | 465 | namestr.append( " - " ); |
461 | namestr.append( tr( "Checkbook" ) ); | 466 | namestr.append( tr( "Checkbook" ) ); |
462 | setCaption( namestr ); | 467 | setCaption( namestr ); |
463 | } | 468 | } |
464 | 469 | ||
465 | 470 | ||
466 | // ---slotStartingBalanceChanged ---------------------------------------------- | 471 | // ---slotStartingBalanceChanged ---------------------------------------------- |
467 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | 472 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) |
468 | { | 473 | { |
469 | bool ok; | 474 | bool ok; |
470 | info->setStartingBalance( newbalance.toFloat( &ok ) ); | 475 | info->setStartingBalance( newbalance.toFloat( &ok ) ); |
471 | adjustBalance(); | 476 | adjustBalance(); |
472 | } | 477 | } |
473 | 478 | ||
474 | 479 | ||
475 | // --- slotNewTran ------------------------------------------------------------ | 480 | // --- slotNewTran ------------------------------------------------------------ |
476 | void Checkbook::slotNewTran() | 481 | void Checkbook::slotNewTran() |
477 | { | 482 | { |
478 | TranInfo *traninfo = new TranInfo( info->getNextNumber() ); | 483 | TranInfo *traninfo = new TranInfo( info->getNextNumber() ); |
479 | if( !_dLastNew.isNull() ) | 484 | if( !_dLastNew.isNull() ) |
480 | traninfo->setDate(_dLastNew); | 485 | traninfo->setDate(_dLastNew); |
481 | 486 | ||
482 | Transaction *currtran = new Transaction( this, true, info->name(), | 487 | Transaction *currtran = new Transaction( this, true, info->name(), |
483 | traninfo, | 488 | traninfo, |
484 | _pCfg ); | 489 | _pCfg ); |
490 | QString symbol = _pCfg->getCurrencySymbol(); | ||
485 | if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) | 491 | if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) |
486 | { | 492 | { |
487 | // Add to transaction list | 493 | // Add to transaction list |
488 | info->addTransaction( traninfo ); | 494 | info->addTransaction( traninfo ); |
489 | 495 | ||
490 | // Add to transaction table | 496 | // Add to transaction table |
491 | float amount; | 497 | float amount; |
492 | QString stramount; | 498 | QString stramount; |
493 | amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); | 499 | amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); |
494 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); | 500 | stramount.sprintf( "%.2f", amount ); |
501 | stramount.prepend(symbol); | ||
495 | ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false), | 502 | ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false), |
496 | traninfo->number(), traninfo->datestr(true), traninfo->desc(), | 503 | traninfo->number(), traninfo->datestr(true), traninfo->desc(), |
497 | stramount ); | 504 | stramount ); |
498 | resort(); | 505 | resort(); |
499 | adjustBalance(); | 506 | adjustBalance(); |
500 | 507 | ||
501 | // save last date | 508 | // save last date |
502 | _dLastNew = traninfo->date(); | 509 | _dLastNew = traninfo->date(); |
503 | 510 | ||
504 | // save description in list of payees, if not in there | 511 | // save description in list of payees, if not in there |
505 | QStringList *pLst=&_pCfg->getPayees(); | 512 | QStringList *pLst=&_pCfg->getPayees(); |
506 | if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { | 513 | if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { |
507 | pLst->append( traninfo->desc() ); | 514 | pLst->append( traninfo->desc() ); |
508 | pLst->sort(); | 515 | pLst->sort(); |
509 | _pCfg->setDirty(true); | 516 | _pCfg->setDirty(true); |
510 | } | 517 | } |
511 | } | 518 | } |
512 | else | 519 | else |
513 | { | 520 | { |
514 | delete traninfo; | 521 | delete traninfo; |
515 | } | 522 | } |
516 | } | 523 | } |
517 | 524 | ||
518 | 525 | ||
519 | // --- slotEditTran ----------------------------------------------------------- | 526 | // --- slotEditTran ----------------------------------------------------------- |
520 | void Checkbook::slotEditTran() | 527 | void Checkbook::slotEditTran() |
521 | { | 528 | { |
522 | QListViewItem *curritem = tranTable->currentItem(); | 529 | QListViewItem *curritem = tranTable->currentItem(); |
523 | if ( !curritem ) | 530 | if ( !curritem ) |
524 | return; | 531 | return; |
525 | 532 | ||
526 | TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); | 533 | TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); |
527 | 534 | ||
528 | Transaction *currtran = new Transaction( this, false, info->name(), | 535 | Transaction *currtran = new Transaction( this, false, info->name(), |
529 | traninfo, | 536 | traninfo, |
530 | _pCfg ); | 537 | _pCfg ); |
531 | if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) | 538 | if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted ) |
532 | { | 539 | { |
533 | curritem->setText( COL_NUM, traninfo->number() ); | 540 | curritem->setText( COL_NUM, traninfo->number() ); |
534 | curritem->setText( COL_SORTDATE, traninfo->datestr(false) ); | 541 | curritem->setText( COL_SORTDATE, traninfo->datestr(false) ); |
535 | curritem->setText( COL_DATE, traninfo->datestr(true) ); | 542 | curritem->setText( COL_DATE, traninfo->datestr(true) ); |
536 | curritem->setText( COL_DESC, traninfo->desc() ); | 543 | curritem->setText( COL_DESC, traninfo->desc() ); |
537 | 544 | ||
538 | float amount = traninfo->amount(); | 545 | float amount = traninfo->amount(); |
539 | if ( traninfo->withdrawal() ) | 546 | if ( traninfo->withdrawal() ) |
540 | { | 547 | { |
541 | amount *= -1; | 548 | amount *= -1; |
542 | } | 549 | } |
543 | QString stramount; | 550 | QString stramount; |
544 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); | 551 | stramount.sprintf( "%.2f", amount ); |
552 | stramount.prepend( _pCfg->getCurrencySymbol() ); | ||
545 | curritem->setText( COL_AMOUNT, stramount ); | 553 | curritem->setText( COL_AMOUNT, stramount ); |
546 | resort(); | 554 | resort(); |
547 | adjustBalance(); | 555 | adjustBalance(); |
548 | 556 | ||
549 | // save description in list of payees, if not in there | 557 | // save description in list of payees, if not in there |
550 | QStringList *pLst=&_pCfg->getPayees(); | 558 | QStringList *pLst=&_pCfg->getPayees(); |
551 | if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { | 559 | if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) { |
552 | pLst->append( traninfo->desc() ); | 560 | pLst->append( traninfo->desc() ); |
553 | pLst->sort(); | 561 | pLst->sort(); |
554 | _pCfg->setDirty(true); | 562 | _pCfg->setDirty(true); |
555 | } | 563 | } |
556 | } | 564 | } |
557 | 565 | ||
558 | delete currtran; | 566 | delete currtran; |
559 | } | 567 | } |
560 | 568 | ||
561 | // --- slotMenuTran ----------------------------------------------------------- | 569 | // --- slotMenuTran ----------------------------------------------------------- |
562 | void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt) | 570 | void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt) |
563 | { | 571 | { |
564 | // active item? | 572 | // active item? |
565 | if( !item ) | 573 | if( !item ) |
566 | return; | 574 | return; |
567 | 575 | ||
568 | // Display menu | 576 | // Display menu |
569 | QPopupMenu m; | 577 | QPopupMenu m; |
570 | m.insertItem( QWidget::tr( "Edit" ), 1 ); | 578 | m.insertItem( QWidget::tr( "Edit" ), 1 ); |
571 | m.insertItem( QWidget::tr( "New" ), 2 ); | 579 | m.insertItem( QWidget::tr( "New" ), 2 ); |
572 | m.insertItem( QWidget::tr( "Delete" ), 3 ); | 580 | m.insertItem( QWidget::tr( "Delete" ), 3 ); |
573 | int r = m.exec( pnt ); | 581 | int r = m.exec( pnt ); |
574 | switch(r) { | 582 | switch(r) { |
575 | case 1: | 583 | case 1: |
576 | slotEditTran(); | 584 | slotEditTran(); |
577 | break; | 585 | break; |
578 | case 2: | 586 | case 2: |
579 | slotNewTran(); | 587 | slotNewTran(); |
580 | break; | 588 | break; |
581 | case 3: | 589 | case 3: |
582 | slotDeleteTran(); | 590 | slotDeleteTran(); |
583 | break; | 591 | break; |
584 | } | 592 | } |
585 | } | 593 | } |
586 | 594 | ||
587 | 595 | ||
588 | // --- slotDeleteTran --------------------------------------------------------- | 596 | // --- slotDeleteTran --------------------------------------------------------- |
589 | void Checkbook::slotDeleteTran() | 597 | void Checkbook::slotDeleteTran() |
590 | { | 598 | { |
591 | QListViewItem *curritem = tranTable->currentItem(); | 599 | QListViewItem *curritem = tranTable->currentItem(); |
592 | if ( !curritem ) | 600 | if ( !curritem ) |
593 | return; | 601 | return; |
594 | 602 | ||
595 | TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); | 603 | TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); |
596 | 604 | ||
597 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) | 605 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) |
598 | { | 606 | { |
599 | info->removeTransaction( traninfo ); | 607 | info->removeTransaction( traninfo ); |
600 | delete curritem; | 608 | delete curritem; |
601 | adjustBalance(); | 609 | adjustBalance(); |
602 | } | 610 | } |
603 | } | 611 | } |
604 | 612 | ||
605 | void Checkbook::slotDrawGraph() | 613 | void Checkbook::slotDrawGraph() |
606 | { | 614 | { |
607 | if ( graphInfo ) | 615 | if ( graphInfo ) |
608 | { | 616 | { |
609 | delete graphInfo; | 617 | delete graphInfo; |
610 | } | 618 | } |
611 | 619 | ||
612 | switch ( graphList->currentItem() ) | 620 | switch ( graphList->currentItem() ) |
613 | { | 621 | { |
614 | case 0 : drawBalanceChart(); | 622 | case 0 : drawBalanceChart(); |
615 | break; | 623 | break; |
616 | case 1 : drawCategoryChart( TRUE ); | 624 | case 1 : drawCategoryChart( TRUE ); |
617 | break; | 625 | break; |
618 | case 2 : drawCategoryChart( FALSE ); | 626 | case 2 : drawCategoryChart( FALSE ); |
619 | break; | 627 | break; |
620 | }; | 628 | }; |
621 | 629 | ||
622 | graphWidget->setGraphInfo( graphInfo ); | 630 | graphWidget->setGraphInfo( graphInfo ); |
623 | graphWidget->drawGraph( TRUE ); | 631 | graphWidget->drawGraph( TRUE ); |
624 | } | 632 | } |
625 | 633 | ||
626 | void Checkbook::drawBalanceChart() | 634 | void Checkbook::drawBalanceChart() |
627 | { | 635 | { |
628 | DataPointList *list = new DataPointList(); | 636 | DataPointList *list = new DataPointList(); |
629 | 637 | ||
630 | float balance = info->startingBalance(); | 638 | float balance = info->startingBalance(); |
631 | float amount; | 639 | float amount; |
632 | QString label; | 640 | QString label; |
633 | int i = 0; | 641 | int i = 0; |
634 | int count = tranList->count(); | 642 | int count = tranList->count(); |
635 | 643 | ||
636 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) | 644 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) |
637 | { | 645 | { |
638 | i++; | 646 | i++; |
639 | balance -= tran->fee(); | 647 | balance -= tran->fee(); |
640 | amount = tran->amount(); | 648 | amount = tran->amount(); |
641 | if ( tran->withdrawal() ) | 649 | if ( tran->withdrawal() ) |
642 | { | 650 | { |
643 | amount *= -1; | 651 | amount *= -1; |
644 | } | 652 | } |
645 | balance += amount; | 653 | balance += amount; |
646 | if ( i == 1 || i == count / 2 || i == count ) | 654 | if ( i == 1 || i == count / 2 || i == count ) |
647 | { | 655 | { |
648 | label = tran->datestr(true); | 656 | label = tran->datestr(true); |
649 | } | 657 | } |
650 | else | 658 | else |
651 | { | 659 | { |
652 | label = ""; | 660 | label = ""; |
653 | } | 661 | } |
654 | list->append( new DataPointInfo( label, balance ) ); | 662 | list->append( new DataPointInfo( label, balance ) ); |
655 | } | 663 | } |
656 | 664 | ||
657 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); | 665 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); |
658 | } | 666 | } |
659 | 667 | ||
660 | void Checkbook::drawCategoryChart( bool withdrawals ) | 668 | void Checkbook::drawCategoryChart( bool withdrawals ) |
661 | { | 669 | { |
662 | DataPointList *list = new DataPointList(); | 670 | DataPointList *list = new DataPointList(); |
663 | 671 | ||
664 | TranInfo *tran = tranList->first(); | 672 | TranInfo *tran = tranList->first(); |
665 | if ( tran && tran->withdrawal() == withdrawals ) | 673 | if ( tran && tran->withdrawal() == withdrawals ) |
666 | { | 674 | { |
667 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | 675 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); |
668 | } | 676 | } |
669 | tran = tranList->next(); | 677 | tran = tranList->next(); |
670 | 678 | ||
671 | DataPointInfo *cat; | 679 | DataPointInfo *cat; |
672 | for ( ; tran; tran = tranList->next() ) | 680 | for ( ; tran; tran = tranList->next() ) |
673 | { | 681 | { |
674 | if ( tran->withdrawal() == withdrawals ) | 682 | if ( tran->withdrawal() == withdrawals ) |
675 | { | 683 | { |
676 | // Find category in list | 684 | // Find category in list |
677 | for ( cat = list->first(); cat; cat = list->next() ) | 685 | for ( cat = list->first(); cat; cat = list->next() ) |
678 | { | 686 | { |
679 | if ( cat->label() == tran->category() ) | 687 | if ( cat->label() == tran->category() ) |
680 | { | 688 | { |
681 | break; | 689 | break; |
682 | } | 690 | } |
683 | } | 691 | } |
684 | if ( cat && cat->label() == tran->category() ) | 692 | if ( cat && cat->label() == tran->category() ) |
685 | { // Found category, add to transaction to category total | 693 | { // Found category, add to transaction to category total |
686 | cat->addToValue( tran->amount() ); | 694 | cat->addToValue( tran->amount() ); |
687 | } | 695 | } |
688 | else | 696 | else |
689 | { // Didn't find category, add category to list | 697 | { // Didn't find category, add category to list |
690 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | 698 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); |
691 | } | 699 | } |
692 | } | 700 | } |
693 | } | 701 | } |
694 | 702 | ||
695 | graphInfo = new GraphInfo( GraphInfo::PieChart, list ); | 703 | graphInfo = new GraphInfo( GraphInfo::PieChart, list ); |
696 | } | 704 | } |
697 | 705 | ||
698 | CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2, | 706 | CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2, |
699 | QString label3, QString label4, QString label5, QString label6, QString label7, | 707 | QString label3, QString label4, QString label5, QString label6, QString label7, |
700 | QString label8 ) | 708 | QString label8 ) |
701 | : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) | 709 | : QListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) |
702 | { | 710 | { |
703 | _pTran=pTran; | 711 | _pTran=pTran; |
704 | m_known = FALSE; | 712 | m_known = FALSE; |
705 | owner = parent; | 713 | owner = parent; |
706 | } | 714 | } |
707 | 715 | ||
708 | void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) | 716 | void CBListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) |
709 | { | 717 | { |
710 | QColorGroup _cg = cg; | 718 | QColorGroup _cg = cg; |
711 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 719 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
712 | if ( pm && !pm->isNull() ) | 720 | if ( pm && !pm->isNull() ) |
713 | { | 721 | { |
714 | _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) ); | 722 | _cg.setBrush( QColorGroup::Base, QBrush( cg.base(), *pm ) ); |
715 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 723 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
716 | } | 724 | } |
717 | else if ( isAltBackground() ) | 725 | else if ( isAltBackground() ) |
718 | _cg.setColor(QColorGroup::Base, cg.background() ); | 726 | _cg.setColor(QColorGroup::Base, cg.background() ); |
719 | 727 | ||
720 | QListViewItem::paintCell(p, _cg, column, width, align); | 728 | QListViewItem::paintCell(p, _cg, column, width, align); |
721 | } | 729 | } |
722 | 730 | ||
723 | // --- CBListItem::isAltBackground -------------------------------------------- | 731 | // --- CBListItem::isAltBackground -------------------------------------------- |
724 | bool CBListItem::isAltBackground() | 732 | bool CBListItem::isAltBackground() |
725 | { | 733 | { |
726 | QListView *lv = static_cast<QListView *>( listView() ); | 734 | QListView *lv = static_cast<QListView *>( listView() ); |
727 | if ( lv ) | 735 | if ( lv ) |
728 | { | 736 | { |
729 | CBListItem *above = 0; | 737 | CBListItem *above = 0; |
730 | above = (CBListItem *)( itemAbove() ); | 738 | above = (CBListItem *)( itemAbove() ); |
731 | m_known = above ? above->m_known : true; | 739 | m_known = above ? above->m_known : true; |
732 | if ( m_known ) | 740 | if ( m_known ) |
733 | { | 741 | { |
734 | m_odd = above ? !above->m_odd : false; | 742 | m_odd = above ? !above->m_odd : false; |
735 | } | 743 | } |
736 | else | 744 | else |
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 | |||
@@ -4,355 +4,357 @@ | |||
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/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | #include <qpe/qpemessagebox.h> | 37 | #include <qpe/qpemessagebox.h> |
38 | #include <qtoolbar.h> | 38 | #include <qtoolbar.h> |
39 | #include <qpe/resource.h> | 39 | #include <qpe/resource.h> |
40 | 40 | ||
41 | #include <qmenubar.h> | 41 | #include <qmenubar.h> |
42 | #include <qaction.h> | 42 | #include <qaction.h> |
43 | #include <qdir.h> | 43 | #include <qdir.h> |
44 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
45 | 45 | ||
46 | 46 | ||
47 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ ) | 47 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ ) |
48 | : QMainWindow( parent, name, WStyle_ContextHelp ) | 48 | : QMainWindow( parent, name, WStyle_ContextHelp ) |
49 | { | 49 | { |
50 | setCaption( tr( "Checkbook" ) ); | 50 | setCaption( tr( "Checkbook" ) ); |
51 | 51 | ||
52 | cbDir = Global::applicationFileName( "checkbook", "" ); | 52 | cbDir = Global::applicationFileName( "checkbook", "" ); |
53 | lockIcon = Resource::loadPixmap( "locked" ); | 53 | lockIcon = Resource::loadPixmap( "locked" ); |
54 | 54 | ||
55 | // Load configuration options | 55 | // Load configuration options |
56 | Config config( "checkbook" ); | 56 | Config config( "checkbook" ); |
57 | _cfg.readConfig( config ); | 57 | _cfg.readConfig( config ); |
58 | 58 | ||
59 | 59 | ||
60 | // Build menu and tool bars | 60 | // Build menu and tool bars |
61 | setToolBarsMovable( FALSE ); | 61 | setToolBarsMovable( FALSE ); |
62 | 62 | ||
63 | QToolBar *bar = new QToolBar( this ); | 63 | QToolBar *bar = new QToolBar( this ); |
64 | bar->setHorizontalStretchable( TRUE ); | 64 | bar->setHorizontalStretchable( TRUE ); |
65 | QMenuBar *mb = new QMenuBar( bar ); | 65 | QMenuBar *mb = new QMenuBar( bar ); |
66 | mb->setMargin( 0 ); | 66 | mb->setMargin( 0 ); |
67 | QPopupMenu *popup = new QPopupMenu( this ); | 67 | QPopupMenu *popup = new QPopupMenu( this ); |
68 | 68 | ||
69 | bar = new QToolBar( this ); | 69 | bar = new QToolBar( this ); |
70 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 70 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
71 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); | 71 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); |
72 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); | 72 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); |
73 | a->addTo( popup ); | 73 | a->addTo( popup ); |
74 | a->addTo( bar ); | 74 | a->addTo( bar ); |
75 | 75 | ||
76 | actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 76 | actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
77 | 0, this, 0 ); | 77 | 0, this, 0 ); |
78 | 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." ) ); | 78 | 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." ) ); |
79 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); | 79 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); |
80 | actionOpen->addTo( popup ); | 80 | actionOpen->addTo( popup ); |
81 | actionOpen->addTo( bar ); | 81 | actionOpen->addTo( bar ); |
82 | 82 | ||
83 | actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 83 | actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
84 | 0, this, 0 ); | 84 | 0, this, 0 ); |
85 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); | 85 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); |
86 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); | 86 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); |
87 | actionDelete->addTo( popup ); | 87 | actionDelete->addTo( popup ); |
88 | actionDelete->addTo( bar ); | 88 | actionDelete->addTo( bar ); |
89 | 89 | ||
90 | popup->insertSeparator(); | 90 | popup->insertSeparator(); |
91 | 91 | ||
92 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); | 92 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); |
93 | a->setWhatsThis( tr( "Click here to configure this app." ) ); | 93 | a->setWhatsThis( tr( "Click here to configure this app." ) ); |
94 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); | 94 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); |
95 | a->addTo( popup ); | 95 | a->addTo( popup ); |
96 | a->addTo( bar ); | 96 | a->addTo( bar ); |
97 | 97 | ||
98 | mb->insertItem( tr( "Checkbook" ), popup ); | 98 | mb->insertItem( tr( "Checkbook" ), popup ); |
99 | 99 | ||
100 | // Load Checkbook selection list | 100 | // Load Checkbook selection list |
101 | checkbooks = new CBInfoList(); | 101 | checkbooks = new CBInfoList(); |
102 | 102 | ||
103 | QDir checkdir( cbDir ); | 103 | QDir checkdir( cbDir ); |
104 | if (checkdir.exists() == true) | 104 | if (checkdir.exists() == true) |
105 | { | 105 | { |
106 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, | 106 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, |
107 | QDir::Time ); | 107 | QDir::Time ); |
108 | CBInfo *cb = 0x0; | 108 | CBInfo *cb = 0x0; |
109 | QString filename; | 109 | QString filename; |
110 | 110 | ||
111 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) | 111 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) |
112 | { | 112 | { |
113 | filename = cbDir; | 113 | filename = cbDir; |
114 | filename.append( (*it) ); | 114 | filename.append( (*it) ); |
115 | 115 | ||
116 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); | 116 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); |
117 | checkbooks->inSort( cb ); | 117 | checkbooks->inSort( cb ); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | // Build Checkbook selection list control | 121 | // Build Checkbook selection list control |
122 | cbList = 0x0; | 122 | cbList = 0x0; |
123 | buildList(); | 123 | buildList(); |
124 | 124 | ||
125 | // open last book? | 125 | // open last book? |
126 | if( _cfg.isOpenLastBook() ) { | 126 | if( _cfg.isOpenLastBook() ) { |
127 | this->show(); | 127 | this->show(); |
128 | this->showMaximized(); | 128 | this->showMaximized(); |
129 | QListViewItem *itm=cbList->firstChild(); | 129 | QListViewItem *itm=cbList->firstChild(); |
130 | while( itm ) { | 130 | while( itm ) { |
131 | if( itm->text(posName)==_cfg.getLastBook() ) { | 131 | if( itm->text(posName)==_cfg.getLastBook() ) { |
132 | openBook( itm ); | 132 | openBook( itm ); |
133 | break; | 133 | break; |
134 | } | 134 | } |
135 | itm=itm->nextSibling(); | 135 | itm=itm->nextSibling(); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | // --- ~MainWindow ------------------------------------------------------------ | 141 | // --- ~MainWindow ------------------------------------------------------------ |
142 | MainWindow::~MainWindow() | 142 | MainWindow::~MainWindow() |
143 | { | 143 | { |
144 | writeConfig(); | 144 | writeConfig(); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | // --- buildList -------------------------------------------------------------- | 148 | // --- buildList -------------------------------------------------------------- |
149 | void MainWindow::buildList() | 149 | void 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 | ||
185 | void MainWindow::addCheckbook( CBInfo *cb ) | 185 | void 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 | ||
201 | void MainWindow::buildFilename( const QString &name ) | 202 | void 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 | ||
208 | void MainWindow::slotNew() | 209 | void 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 --------------------------------------------------------------- |
229 | void MainWindow::slotEdit() | 230 | void 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 --------------------------------------------------------------- |
240 | void MainWindow::openBook(QListViewItem *curritem) | 241 | void 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(); |
245 | while ( cb ) { | 246 | while ( cb ) { |
246 | if ( cb->name() == currname ) | 247 | if ( cb->name() == currname ) |
247 | break; | 248 | break; |
248 | cb = checkbooks->next(); | 249 | cb = checkbooks->next(); |
249 | } | 250 | } |
250 | if ( !cb ) return; | 251 | if ( !cb ) return; |
251 | 252 | ||
252 | // | 253 | // |
253 | buildFilename( currname ); | 254 | buildFilename( currname ); |
254 | float currbalance = cb->balance(); | 255 | float currbalance = cb->balance(); |
255 | bool currlock = !cb->password().isNull(); | 256 | bool currlock = !cb->password().isNull(); |
256 | 257 | ||
257 | if ( currlock ) | 258 | if ( currlock ) |
258 | { | 259 | { |
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 ------------------------------------------------------------- |
321 | void MainWindow::slotDelete() | 323 | void 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 ---------------------------------------------------------- |
339 | void MainWindow::slotConfigure() | 341 | void 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 -------------------------------------------------------------- |
354 | void MainWindow::writeConfig() | 356 | void MainWindow::writeConfig() |
355 | { | 357 | { |
356 | Config config("checkbook"); | 358 | Config config("checkbook"); |
357 | _cfg.writeConfig( config ); | 359 | _cfg.writeConfig( config ); |
358 | } | 360 | } |