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