author | drw <drw> | 2002-11-30 22:51:39 (UTC) |
---|---|---|
committer | drw <drw> | 2002-11-30 22:51:39 (UTC) |
commit | 666313593479c03cdc88bd8fde926af181cb8423 (patch) (side-by-side diff) | |
tree | 79f5334d7ec7918146469d567466607ebaea28a8 /noncore/apps/checkbook/checkbook.cpp | |
parent | 2e2bbf823ba532f349ad9ca3dd84cf7f758f36b0 (diff) | |
download | opie-666313593479c03cdc88bd8fde926af181cb8423.zip opie-666313593479c03cdc88bd8fde926af181cb8423.tar.gz opie-666313593479c03cdc88bd8fde926af181cb8423.tar.bz2 |
Checkbook password protection
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 @@ -9,67 +9,69 @@ .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "checkbook.h" #include "transaction.h" #include "graph.h" #include "graphinfo.h" +#include "password.h" #include <opie/otabwidget.h> #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> +#include <qcheckbox.h> #include <qcombobox.h> #include <qfile.h> #include <qfontmetrics.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qwhatsthis.h> #include <qwidget.h> -Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, char symbol ) +Checkbook::Checkbook( QWidget *parent, const QString &n, const QString &fd, const QString &symbol ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { name = n; filename = fd; filename.append( name ); filename.append( ".qcb" ); filedir = fd; currencySymbol = symbol; currBalance = 0.0; if ( name != "" ) { QString tempstr = name; tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } else { setCaption( tr( "New checkbook" ) ); } // Setup layout to make everything pretty QVBoxLayout *layout = new QVBoxLayout( this ); @@ -95,114 +97,121 @@ Checkbook::~Checkbook() const QString &Checkbook::getName() { return( name ); } QWidget *Checkbook::initInfo() { QWidget *control = new QWidget( mainWidget ); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 2 ); layout->setMargin( 4 ); + // Password protection + passwordCB = new QCheckBox( tr( "Password protect" ), container ); + QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) ); + connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) ); + layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 ); + // Account name QLabel *label = new QLabel( tr( "Name:" ), container ); QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); - layout->addWidget( label, 0, 0 ); + layout->addWidget( label, 1, 0 ); nameEdit = new QLineEdit( container ); QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); connect( nameEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) ); - layout->addWidget( nameEdit, 0, 1 ); + layout->addWidget( nameEdit, 1, 1 ); // Type of account label = new QLabel( tr( "Type:" ), container ); QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); - layout->addWidget( label, 1, 0 ); + layout->addWidget( label, 2, 0 ); typeList = new QComboBox( container ); QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); typeList->insertItem( tr( "Savings" ) ); // 0 typeList->insertItem( tr( "Checking" ) ); // 1 typeList->insertItem( tr( "CD" ) ); // 2 typeList->insertItem( tr( "Money market" ) ); // 3 typeList->insertItem( tr( "Mutual fund" ) ); // 4 typeList->insertItem( tr( "Other" ) ); // 5 - layout->addWidget( typeList, 1, 1 ); + layout->addWidget( typeList, 2, 1 ); // Bank/institution name label = new QLabel( tr( "Bank:" ), container ); QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); - layout->addWidget( label, 2, 0 ); + layout->addWidget( label, 3, 0 ); bankEdit = new QLineEdit( container ); QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); - layout->addWidget( bankEdit, 2, 1 ); + layout->addWidget( bankEdit, 3, 1 ); // Account number label = new QLabel( tr( "Account number:" ), container ); QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); - layout->addWidget( label, 3, 0 ); + layout->addWidget( label, 4, 0 ); acctNumEdit = new QLineEdit( container ); QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); - layout->addWidget( acctNumEdit, 3, 1 ); + layout->addWidget( acctNumEdit, 4, 1 ); // PIN number label = new QLabel( tr( "PIN number:" ), container ); QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); - layout->addWidget( label, 4, 0 ); + layout->addWidget( label, 5, 0 ); pinNumEdit = new QLineEdit( container ); QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); - layout->addWidget( pinNumEdit, 4, 1 ); + layout->addWidget( pinNumEdit, 5, 1 ); // Starting balance label = new QLabel( tr( "Starting balance:" ), container ); QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); - layout->addWidget( label, 5, 0 ); + layout->addWidget( label, 6, 0 ); balanceEdit = new QLineEdit( container ); QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); connect( balanceEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotStartingBalanceChanged( const QString & ) ) ); - layout->addWidget( balanceEdit, 5, 1 ); + layout->addWidget( balanceEdit, 6, 1 ); // Notes label = new QLabel( tr( "Notes:" ), container ); QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); - layout->addWidget( label, 6, 0 ); + layout->addWidget( label, 7, 0 ); notesEdit = new QMultiLineEdit( container ); QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); - notesEdit->setMaximumHeight( 85 ); - layout->addMultiCellWidget( notesEdit, 7, 7, 0, 1 ); + notesEdit->setMinimumHeight( 25 ); + notesEdit->setMaximumHeight( 65 ); + layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); return control; } QWidget *Checkbook::initTransactions() { QWidget *control = new QWidget( mainWidget ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), control ); QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); tranTable = new QListView( control ); 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." ) ); tranTable->addColumn( tr( "Num" ) ); tranTable->addColumn( tr( "Date" ) ); //tranTable->addColumn( tr( "Cleared" ) ); tranTable->addColumn( tr( "Description" ) ); int colnum = tranTable->addColumn( tr( "Amount" ) ); @@ -245,93 +254,96 @@ QWidget *Checkbook::initCharts() graphWidget = new Graph( control ); QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); graphList = new QComboBox( control ); QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); graphList->insertItem( tr( "Account balance" ) ); graphList->insertItem( tr( "Withdrawals by category" ) ); graphList->insertItem( tr( "Deposits by category" ) ); layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); layout->addWidget( btn, 1, 2 ); return control; } void Checkbook::loadCheckbook() { transactions.clear(); - Config config(filename, Config::File); + Config config( filename, Config::File ); // Load info config.setGroup( "Account" ); + + password = config.readEntryCrypt( "Password", "" ); + passwordCB->setChecked( password != "" ); nameEdit->setText( name ); QString temptext = config.readEntry( "Type" ); int i = typeList->count(); while ( i > 0 ) { i--; typeList->setCurrentItem( i ); if ( typeList->currentText() == temptext ) { break; } } bankEdit->setText( config.readEntry( "Bank", "" ) ); acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) ); pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) ); balanceEdit->setText( config.readEntry( "Balance", "0.0" ) ); notesEdit->setText( config.readEntry( "Notes", "" ) ); bool ok; currBalance = balanceEdit->text().toFloat( &ok ); startBalance = currBalance; // Load transactions TranInfo *tran; QString trandesc = ""; float amount; QString stramount; for ( int i = 1; trandesc != QString::null; i++ ) { tran = new TranInfo( config, i ); trandesc = tran->desc(); if ( trandesc != QString::null ) { currBalance -= tran->fee(); amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } currBalance += amount; - stramount.sprintf( "%c%.2f", currencySymbol, amount ); + stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); // Add to transaction list transactions.inSort( tran ); // Add to transaction table ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), trandesc, stramount ); } else { delete tran; } } balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); highTranNum = transactions.count(); } void Checkbook::adjustBalance( float amount ) { currBalance += amount; balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); } @@ -339,157 +351,199 @@ TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, con { TranInfo *traninfo = transactions.first(); while ( traninfo ) { if ( traninfo->number() == checknum && traninfo->datestr() == date && traninfo->desc() == desc ) break; traninfo = transactions.next(); } return( traninfo ); } void Checkbook::accept() { QFile f( filename ); if ( f.exists() ) { f.remove(); } Config *config = new Config(filename, Config::File); // Save info config->setGroup( "Account" ); + config->writeEntryCrypt( "Password", password ); config->writeEntry( "Type", typeList->currentText() ); config->writeEntry( "Bank", bankEdit->text() ); config->writeEntryCrypt( "Number", acctNumEdit->text() ); config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); config->writeEntry( "Balance", balanceEdit->text() ); config->writeEntry( "Notes", notesEdit->text() ); // Save transactions int i = 1; for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) { tran->write( config, i ); i++; } config->write(); QDialog::accept(); } +void Checkbook::slotPasswordClicked() +{ + if ( password == "" && passwordCB->isChecked() ) + { + Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); + if ( pw->exec() != QDialog::Accepted ) + { + passwordCB->setChecked( FALSE ); + delete pw; + return; + } + password = pw->password; + delete pw; + + pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); + if ( pw->exec() != QDialog::Accepted || pw->password != password ) + { + passwordCB->setChecked( FALSE ); + password = ""; + } + + delete pw; + } + else if ( password != "" && !passwordCB->isChecked() ) + { + Password *pw = new Password( this, tr( "Enter password" ), + tr( "Please enter your password to confirm removal of password protection:" ) ); + if ( pw->exec() == QDialog::Accepted && pw->password == password ) + { + password = ""; + delete pw; + return; + } + else + { + passwordCB->setChecked( TRUE ); + } + + delete pw; + } +} + void Checkbook::slotNameChanged( const QString &newname ) { name = newname; filename = filedir; filename.append( newname ); filename.append( ".qcb" ); QString tempstr = name; tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { currBalance -= startBalance; bool ok; startBalance = newbalance.toFloat( &ok ); adjustBalance( startBalance ); } void Checkbook::slotNewTran() { highTranNum++; TranInfo *traninfo = new TranInfo( highTranNum ); Transaction *currtran = new Transaction( this, name, traninfo, currencySymbol ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } QString stramount; - stramount.sprintf( "%c%.2f", currencySymbol, amount ); + stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); // Add to transaction list transactions.inSort( traninfo ); // Add to transaction table ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), stramount ); adjustBalance( amount ); } else { highTranNum--; delete traninfo; } } void Checkbook::slotEditTran() { - bool ok; QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) { return; } TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); float origamt = traninfo->amount(); if ( traninfo->withdrawal() ) { origamt *= -1; } Transaction *currtran = new Transaction( this, name, traninfo, currencySymbol ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { curritem->setText( 1, traninfo->datestr() ); curritem->setText( 2, traninfo->desc() ); float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } adjustBalance( origamt * -1 ); adjustBalance( amount ); QString stramount; - stramount.sprintf( "%c%.2f", currencySymbol, amount ); + stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); curritem->setText( 3, stramount ); balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); delete currtran; } } void Checkbook::slotDeleteTran() { QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) { return; } TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete transaction" ), traninfo->desc() ) ) { float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; |