Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 09b0b46..5a6d607 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "transaction.h" | 30 | #include "transaction.h" |
31 | #include "graph.h" | 31 | #include "graph.h" |
32 | #include "graphinfo.h" | 32 | #include "graphinfo.h" |
33 | #include "password.h" | ||
33 | 34 | ||
34 | #include <opie/otabwidget.h> | 35 | #include <opie/otabwidget.h> |
35 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
@@ -37,6 +38,7 @@ | |||
37 | #include <qpe/qpemessagebox.h> | 38 | #include <qpe/qpemessagebox.h> |
38 | #include <qpe/resource.h> | 39 | #include <qpe/resource.h> |
39 | 40 | ||
41 | #include <qcheckbox.h> | ||
40 | #include <qcombobox.h> | 42 | #include <qcombobox.h> |
41 | #include <qfile.h> | 43 | #include <qfile.h> |
42 | #include <qfontmetrics.h> | 44 | #include <qfontmetrics.h> |
@@ -48,7 +50,7 @@ | |||
48 | #include <qwhatsthis.h> | 50 | #include <qwhatsthis.h> |
49 | #include <qwidget.h> | 51 | #include <qwidget.h> |
50 | 52 | ||
51 | Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) | 53 | Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol ) |
52 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 54 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
53 | { | 55 | { |
54 | name = n; | 56 | name = n; |
@@ -116,20 +118,26 @@ QWidget *Checkbook::initInfo() | |||
116 | layout->setSpacing( 2 ); | 118 | layout->setSpacing( 2 ); |
117 | layout->setMargin( 4 ); | 119 | layout->setMargin( 4 ); |
118 | 120 | ||
121 | // Password protection | ||
122 | passwordCB = new QCheckBox( tr( "Password protect" ), container ); | ||
123 | QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) ); | ||
124 | connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) ); | ||
125 | layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 ); | ||
126 | |||
119 | // Account name | 127 | // Account name |
120 | QLabel *label = new QLabel( tr( "Name:" ), container ); | 128 | QLabel *label = new QLabel( tr( "Name:" ), container ); |
121 | QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); | 129 | QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); |
122 | layout->addWidget( label, 0, 0 ); | 130 | layout->addWidget( label, 1, 0 ); |
123 | nameEdit = new QLineEdit( container ); | 131 | nameEdit = new QLineEdit( container ); |
124 | QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); | 132 | QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); |
125 | connect( nameEdit, SIGNAL( textChanged( const QString & ) ), | 133 | connect( nameEdit, SIGNAL( textChanged( const QString & ) ), |
126 | this, SLOT( slotNameChanged( const QString & ) ) ); | 134 | this, SLOT( slotNameChanged( const QString & ) ) ); |
127 | layout->addWidget( nameEdit, 0, 1 ); | 135 | layout->addWidget( nameEdit, 1, 1 ); |
128 | 136 | ||
129 | // Type of account | 137 | // Type of account |
130 | label = new QLabel( tr( "Type:" ), container ); | 138 | label = new QLabel( tr( "Type:" ), container ); |
131 | QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); | 139 | QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); |
132 | layout->addWidget( label, 1, 0 ); | 140 | layout->addWidget( label, 2, 0 ); |
133 | typeList = new QComboBox( container ); | 141 | typeList = new QComboBox( container ); |
134 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); | 142 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); |
135 | typeList->insertItem( tr( "Savings" ) ); // 0 | 143 | typeList->insertItem( tr( "Savings" ) ); // 0 |
@@ -138,50 +146,51 @@ QWidget *Checkbook::initInfo() | |||
138 | typeList->insertItem( tr( "Money market" ) );// 3 | 146 | typeList->insertItem( tr( "Money market" ) );// 3 |
139 | typeList->insertItem( tr( "Mutual fund" ) );// 4 | 147 | typeList->insertItem( tr( "Mutual fund" ) );// 4 |
140 | typeList->insertItem( tr( "Other" ) ); // 5 | 148 | typeList->insertItem( tr( "Other" ) ); // 5 |
141 | layout->addWidget( typeList, 1, 1 ); | 149 | layout->addWidget( typeList, 2, 1 ); |
142 | 150 | ||
143 | // Bank/institution name | 151 | // Bank/institution name |
144 | label = new QLabel( tr( "Bank:" ), container ); | 152 | label = new QLabel( tr( "Bank:" ), container ); |
145 | 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." ) ); |
146 | layout->addWidget( label, 2, 0 ); | 154 | layout->addWidget( label, 3, 0 ); |
147 | bankEdit = new QLineEdit( container ); | 155 | bankEdit = new QLineEdit( container ); |
148 | 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." ) ); |
149 | layout->addWidget( bankEdit, 2, 1 ); | 157 | layout->addWidget( bankEdit, 3, 1 ); |
150 | 158 | ||
151 | // Account number | 159 | // Account number |
152 | label = new QLabel( tr( "Account number:" ), container ); | 160 | label = new QLabel( tr( "Account number:" ), container ); |
153 | QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); | 161 | QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); |
154 | layout->addWidget( label, 3, 0 ); | 162 | layout->addWidget( label, 4, 0 ); |
155 | acctNumEdit = new QLineEdit( container ); | 163 | acctNumEdit = new QLineEdit( container ); |
156 | QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); | 164 | QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); |
157 | layout->addWidget( acctNumEdit, 3, 1 ); | 165 | layout->addWidget( acctNumEdit, 4, 1 ); |
158 | 166 | ||
159 | // PIN number | 167 | // PIN number |
160 | label = new QLabel( tr( "PIN number:" ), container ); | 168 | label = new QLabel( tr( "PIN number:" ), container ); |
161 | QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); | 169 | QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); |
162 | layout->addWidget( label, 4, 0 ); | 170 | layout->addWidget( label, 5, 0 ); |
163 | pinNumEdit = new QLineEdit( container ); | 171 | pinNumEdit = new QLineEdit( container ); |
164 | QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); | 172 | QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); |
165 | layout->addWidget( pinNumEdit, 4, 1 ); | 173 | layout->addWidget( pinNumEdit, 5, 1 ); |
166 | 174 | ||
167 | // Starting balance | 175 | // Starting balance |
168 | label = new QLabel( tr( "Starting balance:" ), container ); | 176 | label = new QLabel( tr( "Starting balance:" ), container ); |
169 | 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." ) ); |
170 | layout->addWidget( label, 5, 0 ); | 178 | layout->addWidget( label, 6, 0 ); |
171 | balanceEdit = new QLineEdit( container ); | 179 | balanceEdit = new QLineEdit( container ); |
172 | 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." ) ); |
173 | connect( balanceEdit, SIGNAL( textChanged( const QString & ) ), | 181 | connect( balanceEdit, SIGNAL( textChanged( const QString & ) ), |
174 | this, SLOT( slotStartingBalanceChanged( const QString & ) ) ); | 182 | this, SLOT( slotStartingBalanceChanged( const QString & ) ) ); |
175 | layout->addWidget( balanceEdit, 5, 1 ); | 183 | layout->addWidget( balanceEdit, 6, 1 ); |
176 | 184 | ||
177 | // Notes | 185 | // Notes |
178 | label = new QLabel( tr( "Notes:" ), container ); | 186 | label = new QLabel( tr( "Notes:" ), container ); |
179 | 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." ) ); |
180 | layout->addWidget( label, 6, 0 ); | 188 | layout->addWidget( label, 7, 0 ); |
181 | notesEdit = new QMultiLineEdit( container ); | 189 | notesEdit = new QMultiLineEdit( container ); |
182 | 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." ) ); |
183 | notesEdit->setMaximumHeight( 85 ); | 191 | notesEdit->setMinimumHeight( 25 ); |
184 | layout->addMultiCellWidget( notesEdit, 7, 7, 0, 1 ); | 192 | notesEdit->setMaximumHeight( 65 ); |
193 | layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); | ||
185 | 194 | ||
186 | return control; | 195 | return control; |
187 | } | 196 | } |
@@ -266,10 +275,13 @@ void Checkbook::loadCheckbook() | |||
266 | { | 275 | { |
267 | transactions.clear(); | 276 | transactions.clear(); |
268 | 277 | ||
269 | Config config(filename, Config::File); | 278 | Config config( filename, Config::File ); |
270 | 279 | ||
271 | // Load info | 280 | // Load info |
272 | config.setGroup( "Account" ); | 281 | config.setGroup( "Account" ); |
282 | |||
283 | password = config.readEntryCrypt( "Password", "" ); | ||
284 | passwordCB->setChecked( password != "" ); | ||
273 | nameEdit->setText( name ); | 285 | nameEdit->setText( name ); |
274 | QString temptext = config.readEntry( "Type" ); | 286 | QString temptext = config.readEntry( "Type" ); |
275 | int i = typeList->count(); | 287 | int i = typeList->count(); |
@@ -310,7 +322,7 @@ void Checkbook::loadCheckbook() | |||
310 | amount *= -1; | 322 | amount *= -1; |
311 | } | 323 | } |
312 | currBalance += amount; | 324 | currBalance += amount; |
313 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 325 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); |
314 | 326 | ||
315 | // Add to transaction list | 327 | // Add to transaction list |
316 | transactions.inSort( tran ); | 328 | transactions.inSort( tran ); |
@@ -360,6 +372,7 @@ void Checkbook::accept() | |||
360 | 372 | ||
361 | // Save info | 373 | // Save info |
362 | config->setGroup( "Account" ); | 374 | config->setGroup( "Account" ); |
375 | config->writeEntryCrypt( "Password", password ); | ||
363 | config->writeEntry( "Type", typeList->currentText() ); | 376 | config->writeEntry( "Type", typeList->currentText() ); |
364 | config->writeEntry( "Bank", bankEdit->text() ); | 377 | config->writeEntry( "Bank", bankEdit->text() ); |
365 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); | 378 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); |
@@ -379,6 +392,48 @@ void Checkbook::accept() | |||
379 | QDialog::accept(); | 392 | QDialog::accept(); |
380 | } | 393 | } |
381 | 394 | ||
395 | void Checkbook::slotPasswordClicked() | ||
396 | { | ||
397 | if ( password == "" && passwordCB->isChecked() ) | ||
398 | { | ||
399 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | ||
400 | if ( pw->exec() != QDialog::Accepted ) | ||
401 | { | ||
402 | passwordCB->setChecked( FALSE ); | ||
403 | delete pw; | ||
404 | return; | ||
405 | } | ||
406 | password = pw->password; | ||
407 | delete pw; | ||
408 | |||
409 | pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); | ||
410 | if ( pw->exec() != QDialog::Accepted || pw->password != password ) | ||
411 | { | ||
412 | passwordCB->setChecked( FALSE ); | ||
413 | password = ""; | ||
414 | } | ||
415 | |||
416 | delete pw; | ||
417 | } | ||
418 | else if ( password != "" && !passwordCB->isChecked() ) | ||
419 | { | ||
420 | Password *pw = new Password( this, tr( "Enter password" ), | ||
421 | tr( "Please enter your password to confirm removal of password protection:" ) ); | ||
422 | if ( pw->exec() == QDialog::Accepted && pw->password == password ) | ||
423 | { | ||
424 | password = ""; | ||
425 | delete pw; | ||
426 | return; | ||
427 | } | ||
428 | else | ||
429 | { | ||
430 | passwordCB->setChecked( TRUE ); | ||
431 | } | ||
432 | |||
433 | delete pw; | ||
434 | } | ||
435 | } | ||
436 | |||
382 | void Checkbook::slotNameChanged( const QString &newname ) | 437 | void Checkbook::slotNameChanged( const QString &newname ) |
383 | { | 438 | { |
384 | name = newname; | 439 | name = newname; |
@@ -416,7 +471,7 @@ void Checkbook::slotNewTran() | |||
416 | amount *= -1; | 471 | amount *= -1; |
417 | } | 472 | } |
418 | QString stramount; | 473 | QString stramount; |
419 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 474 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); |
420 | 475 | ||
421 | // Add to transaction list | 476 | // Add to transaction list |
422 | transactions.inSort( traninfo ); | 477 | transactions.inSort( traninfo ); |
@@ -436,7 +491,6 @@ void Checkbook::slotNewTran() | |||
436 | 491 | ||
437 | void Checkbook::slotEditTran() | 492 | void Checkbook::slotEditTran() |
438 | { | 493 | { |
439 | bool ok; | ||
440 | QListViewItem *curritem = tranTable->currentItem(); | 494 | QListViewItem *curritem = tranTable->currentItem(); |
441 | if ( !curritem ) | 495 | if ( !curritem ) |
442 | { | 496 | { |
@@ -468,7 +522,7 @@ void Checkbook::slotEditTran() | |||
468 | adjustBalance( origamt * -1 ); | 522 | adjustBalance( origamt * -1 ); |
469 | adjustBalance( amount ); | 523 | adjustBalance( amount ); |
470 | QString stramount; | 524 | QString stramount; |
471 | stramount.sprintf( "%c%.2f", currencySymbol, amount ); | 525 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); |
472 | curritem->setText( 3, stramount ); | 526 | curritem->setText( 3, stramount ); |
473 | 527 | ||
474 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); | 528 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); |