-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 96 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.h | 9 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.pro | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 26 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.h | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/password.cpp | 99 | ||||
-rw-r--r-- | noncore/apps/checkbook/password.h | 55 | ||||
-rw-r--r-- | noncore/apps/checkbook/transaction.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/transaction.h | 4 |
9 files changed, 264 insertions, 31 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 @@ -27,31 +27,33 @@ */ #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" ); @@ -113,78 +115,85 @@ QWidget *Checkbook::initInfo() 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() { @@ -263,16 +272,19 @@ QWidget *Checkbook::initCharts() } 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--; @@ -307,13 +319,13 @@ void Checkbook::loadCheckbook() 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 ); @@ -357,12 +369,13 @@ void Checkbook::accept() } 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() ); @@ -376,12 +389,54 @@ void Checkbook::accept() } 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" ); @@ -413,13 +468,13 @@ void Checkbook::slotNewTran() 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(), @@ -433,13 +488,12 @@ void Checkbook::slotNewTran() delete traninfo; } } void Checkbook::slotEditTran() { - bool ok; QListViewItem *curritem = tranTable->currentItem(); if ( !curritem ) { return; } @@ -465,13 +519,13 @@ void Checkbook::slotEditTran() { 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; } diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h index 0260b43..27658ff 100644 --- a/noncore/apps/checkbook/checkbook.h +++ b/noncore/apps/checkbook/checkbook.h @@ -35,44 +35,48 @@ #include <qlistview.h> class OTabWidget; class Graph; class GraphInfo; +class QCheckBox; class QComboBox; class QLabel; class QLineEdit; class QListView; class QMultiLineEdit; class QString; class Checkbook : public QDialog { Q_OBJECT public: - Checkbook( QWidget * = 0x0, const QString & = 0x0, const QString & = 0x0, char = '$' ); + Checkbook( QWidget * = 0x0, const QString & = 0x0, const QString & = 0x0, + const QString & = "$" ); ~Checkbook(); const QString &getName(); private: TranInfoList transactions; QString name; QString filename; QString filedir; - char currencySymbol; + QString currencySymbol; + QString password; int highTranNum; OTabWidget *mainWidget; void loadCheckbook(); void adjustBalance( float ); TranInfo *findTran( const QString &, const QString &, const QString & ); // Info tab QWidget *initInfo(); + QCheckBox *passwordCB; QLineEdit *nameEdit; QComboBox *typeList; QLineEdit *bankEdit; QLineEdit *acctNumEdit; QLineEdit *pinNumEdit; QLineEdit *balanceEdit; @@ -95,12 +99,13 @@ class Checkbook : public QDialog void drawCategoryChart( bool = TRUE ); protected slots: void accept(); private slots: + void slotPasswordClicked(); void slotNameChanged( const QString & ); void slotStartingBalanceChanged( const QString & ); void slotNewTran(); void slotEditTran(); void slotDeleteTran(); void slotDrawGraph(); diff --git a/noncore/apps/checkbook/checkbook.pro b/noncore/apps/checkbook/checkbook.pro index bd69939..53b5ff4 100644 --- a/noncore/apps/checkbook/checkbook.pro +++ b/noncore/apps/checkbook/checkbook.pro @@ -1,18 +1,20 @@ TEMPLATE = app CONFIG = qt warn_on release HEADERS = mainwindow.h \ traninfo.h \ graphinfo.h \ + password.h \ checkbook.h \ transaction.h \ graph.h SOURCES = main.cpp \ mainwindow.cpp \ traninfo.cpp \ graphinfo.cpp \ + password.cpp \ checkbook.cpp \ transaction.cpp \ graph.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopie diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 567b8ad..2c0abf1 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp @@ -24,14 +24,16 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mainwindow.h" +#include "password.h" #include "checkbook.h" +#include <qpe/config.h> #include <qpe/global.h> #include <qpe/qpeapplication.h> #include <qpe/qpemenubar.h> #include <qpe/qpemessagebox.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> @@ -102,13 +104,13 @@ MainWindow::MainWindow() } cbList->insertStringList( checkbooks ); } cbList->sort(); cbList->setSelected( 0, TRUE ); - currencySymbol = '$'; + currencySymbol = "$"; } MainWindow::~MainWindow() { } @@ -124,25 +126,41 @@ void MainWindow::slotNew() } } void MainWindow::slotEdit() { QString currname = cbList->currentText(); + + QString tempstr = cbDir; + tempstr.append( currname ); + tempstr.append( ".qcb" ); + + Config config( tempstr, Config::File ); + config.setGroup( "Account" ); + QString password = config.readEntryCrypt( "Password", "" ); + if ( password != "" ) + { + Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); + if ( pw->exec() != QDialog::Accepted || pw->password != password ) + { + delete pw; + return; + } + delete pw; + } + Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol ); currcb->showMaximized(); if ( currcb->exec() == QDialog::Accepted ) { QString newname = currcb->getName(); if ( currname != newname ) { cbList->changeItem( newname, cbList->currentItem() ); cbList->sort(); - QString tempstr = cbDir; - tempstr.append( currname ); - tempstr.append( ".qcb" ); QFile f( tempstr ); if ( f.exists() ) { f.remove(); } } diff --git a/noncore/apps/checkbook/mainwindow.h b/noncore/apps/checkbook/mainwindow.h index 1b460fa..11a3343 100644 --- a/noncore/apps/checkbook/mainwindow.h +++ b/noncore/apps/checkbook/mainwindow.h @@ -46,13 +46,13 @@ class MainWindow : public QMainWindow private: QListBox *cbList; QString cbDir; QAction *actionOpen; QAction *actionDelete; - char currencySymbol; + QString currencySymbol; private slots: void slotNew(); void slotEdit(); void slotDelete(); }; diff --git a/noncore/apps/checkbook/password.cpp b/noncore/apps/checkbook/password.cpp new file mode 100644 index 0000000..82020d5 --- a/dev/null +++ b/noncore/apps/checkbook/password.cpp @@ -0,0 +1,99 @@ +/* + This file is part of the OPIE Project + =. + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= + _;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="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 "password.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qpixmap.h> +#include <qpushbutton.h> +#include <qwidget.h> + +static const char* const showhideimage_data[] = { +"16 16 2 1", +". c None", +"# c #000000", +"................", +"...#...###...##.", +"..#.#..#..#.##..", +"..###..###.##...", +".#...#.#..##....", +".#...#.#.##.....", +"........##.#..#.", +"..##...##...##..", +".#..#.###...##..", +".#...##..#.#..#.", +".#..##..........", +".#.##.#..#.#..#.", +"..##...##...##..", +".##....##...##..", +".#....#..#.#..#.", +"................"}; + +Password::Password( QWidget *parent, const char *caption, const char *prompt ) + : QDialog( parent, 0x0, TRUE, 0x0 ) +{ + setCaption( caption ); + + QGridLayout *layout = new QGridLayout( this ); + layout->setSpacing( 2 ); + layout->setMargin( 4 ); + + QLabel *label = new QLabel( prompt, this ); + label->setAlignment( AlignLeft | AlignTop | WordBreak ); + layout->addMultiCellWidget( label, 0, 0, 0, 1 ); + + pw = new QLineEdit( this ); + pw->setEchoMode( QLineEdit::Password ); + layout->addWidget( pw, 1, 0 ); + + QPixmap *pic = new QPixmap( ( const char** ) showhideimage_data ); + QPushButton *btn = new QPushButton( ( QIconSet ) *pic, QString::null, this ); + btn->setMaximumSize( pic->width() + 10, pic->height() + 10 ); + btn->setToggleButton( TRUE ); + connect( btn, SIGNAL( toggled( bool ) ), this, SLOT( slotTogglePassword( bool ) ) ); + layout->addWidget( btn, 1, 1 ); + + password == ""; +} + +Password::~Password() +{ +} + +void Password::accept() +{ + password = pw->text(); + QDialog::accept(); +} + +void Password::slotTogglePassword( bool showPW ) +{ + showPW ? pw->setEchoMode( QLineEdit::Normal ) : pw->setEchoMode( QLineEdit::Password ); +} diff --git a/noncore/apps/checkbook/password.h b/noncore/apps/checkbook/password.h new file mode 100644 index 0000000..87d64d9 --- a/dev/null +++ b/noncore/apps/checkbook/password.h @@ -0,0 +1,55 @@ +/* + This file is part of the OPIE Project + =. + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= + _;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="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. + +*/ + +#ifndef PASSWORD_H +#define PASSWORD_H + +#include <qdialog.h> + +class QLineEdit; +class QWidget; + +class Password : public QDialog +{ + Q_OBJECT + + public: + Password( QWidget *, const char *, const char * ); + ~Password(); + + QString password; + + private: + QLineEdit *pw; + + protected slots: + void accept(); + void slotTogglePassword( bool ); +}; + +#endif diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp index 122c8d6..17be669 100644 --- a/noncore/apps/checkbook/transaction.cpp +++ b/noncore/apps/checkbook/transaction.cpp @@ -43,13 +43,13 @@ #include <qradiobutton.h> #include <qscrollview.h> #include <qstring.h> #include <qwhatsthis.h> Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, - char symbol ) + const QString &symbol ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { QString tempstr = tr( "Transaction for " ); tempstr.append( acctname ); setCaption( tempstr ); diff --git a/noncore/apps/checkbook/transaction.h b/noncore/apps/checkbook/transaction.h index 89ca8e4..000aee7 100644 --- a/noncore/apps/checkbook/transaction.h +++ b/noncore/apps/checkbook/transaction.h @@ -44,19 +44,19 @@ class TranInfo; class Transaction : public QDialog { Q_OBJECT public: Transaction( QWidget * = 0x0, const QString & = 0x0, TranInfo * = 0x0, - char = '$' ); + const QString & = "$" ); ~Transaction(); private: TranInfo *tran; - char currencySymbol; + QString currencySymbol; QRadioButton *withBtn; QRadioButton *depBtn; QPushButton *dateBtn; DateBookMonth *datePicker; QLineEdit *numEdit; |