author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (unidiff) | |
tree | 46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook | |
parent | f0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff) | |
download | opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2 |
merge noncore/apps/* except
- advancedfm (ljp, please...)
- odict (tille, please...)
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 90 | ||||
-rw-r--r-- | noncore/apps/checkbook/cbinfo.h | 20 | ||||
-rw-r--r-- | noncore/apps/checkbook/cfg.cpp | 213 | ||||
-rw-r--r-- | noncore/apps/checkbook/cfg.h | 120 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 206 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.h | 28 | ||||
-rw-r--r-- | noncore/apps/checkbook/checkbook.pro | 10 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.cpp | 105 | ||||
-rw-r--r-- | noncore/apps/checkbook/configuration.h | 18 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 340 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.h | 78 | ||||
-rw-r--r-- | noncore/apps/checkbook/main.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 109 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.h | 15 | ||||
-rw-r--r-- | noncore/apps/checkbook/tabledef.cpp | 76 | ||||
-rw-r--r-- | noncore/apps/checkbook/tabledef.h | 99 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.cpp | 48 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.h | 15 | ||||
-rw-r--r-- | noncore/apps/checkbook/transaction.cpp | 34 | ||||
-rw-r--r-- | noncore/apps/checkbook/transaction.h | 6 |
20 files changed, 1436 insertions, 208 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp index 9fdc6b2..36dde04 100644 --- a/noncore/apps/checkbook/cbinfo.cpp +++ b/noncore/apps/checkbook/cbinfo.cpp | |||
@@ -35,2 +35,3 @@ | |||
35 | 35 | ||
36 | // --- CBInfo ----------------------------------------------------------------- | ||
36 | CBInfo::CBInfo() | 37 | CBInfo::CBInfo() |
@@ -46,2 +47,5 @@ CBInfo::CBInfo() | |||
46 | sb = 0.0; | 47 | sb = 0.0; |
48 | _sLastTab=""; | ||
49 | _first=-1; | ||
50 | _last=-1; | ||
47 | 51 | ||
@@ -50,2 +54,4 @@ CBInfo::CBInfo() | |||
50 | 54 | ||
55 | |||
56 | // --- CBInfo ----------------------------------------------------------------- | ||
51 | CBInfo::CBInfo( const QString &name, const QString &filename ) | 57 | CBInfo::CBInfo( const QString &name, const QString &filename ) |
@@ -64,2 +70,5 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) | |||
64 | nt = config.readEntry( "Notes", "" ); | 70 | nt = config.readEntry( "Notes", "" ); |
71 | _sLastTab = config.readEntry("LastTab", ""); | ||
72 | _first=config.readNumEntry("First", -1); | ||
73 | _sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") ); | ||
65 | 74 | ||
@@ -71,2 +80,3 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) | |||
71 | 80 | ||
81 | // --- balance ---------------------------------------------------------------- | ||
72 | float CBInfo::balance() | 82 | float CBInfo::balance() |
@@ -77,2 +87,3 @@ float CBInfo::balance() | |||
77 | 87 | ||
88 | // --- write ------------------------------------------------------------------ | ||
78 | void CBInfo::write() | 89 | void CBInfo::write() |
@@ -81,5 +92,3 @@ void CBInfo::write() | |||
81 | if ( f.exists() ) | 92 | if ( f.exists() ) |
82 | { | ||
83 | f.remove(); | 93 | f.remove(); |
84 | } | ||
85 | 94 | ||
@@ -87,3 +96,20 @@ void CBInfo::write() | |||
87 | 96 | ||
97 | |||
98 | // fix transaction numbers | ||
99 | _first=-1; | ||
100 | TranInfo *prev=NULL; | ||
101 | for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { | ||
102 | if( _first<0 ) _first=tran->id(); | ||
103 | if( prev ) prev->setNext( tran->id() ); | ||
104 | tran->setNext(-1); | ||
105 | prev=tran; | ||
106 | } | ||
107 | |||
108 | // Save transactions | ||
109 | for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { | ||
110 | tran->write(config); | ||
111 | } | ||
112 | |||
88 | // Save info | 113 | // Save info |
114 | if( _first<0 && _last>=0 ) _first=_last; | ||
89 | config->setGroup( "Account" ); | 115 | config->setGroup( "Account" ); |
@@ -95,2 +121,3 @@ void CBInfo::write() | |||
95 | config->writeEntry( "Notes", nt ); | 121 | config->writeEntry( "Notes", nt ); |
122 | config->writeEntry( "LastTab", _sLastTab ); | ||
96 | QString balstr; | 123 | QString balstr; |
@@ -98,12 +125,6 @@ void CBInfo::write() | |||
98 | config->writeEntry( "Balance", balstr ); | 125 | config->writeEntry( "Balance", balstr ); |
126 | config->writeEntry( "First", _first ); | ||
127 | config->writeEntry( "SortOrder", _sSortOrder ); | ||
99 | 128 | ||
100 | // Save transactions | ||
101 | int i = 1; | ||
102 | for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) | ||
103 | { | ||
104 | tran->write( config, i ); | ||
105 | i++; | ||
106 | } | ||
107 | config->write(); | 129 | config->write(); |
108 | |||
109 | delete config; | 130 | delete config; |
@@ -111,12 +132,14 @@ void CBInfo::write() | |||
111 | 132 | ||
112 | TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, | 133 | |
113 | const QString &desc ) | 134 | // --- findTransaction -------------------------------------------------------- |
114 | { | 135 | TranInfo *CBInfo::findTransaction( const QString &sId ) |
115 | TranInfo *traninfo = tl->first(); | ||
116 | while ( traninfo ) | ||
117 | { | 136 | { |
118 | if ( traninfo->number() == checknum && traninfo->datestr() == date && | 137 | bool bOk; |
119 | traninfo->desc() == desc ) | 138 | int id=sId.toInt( &bOk ); |
139 | if( !bOk ) | ||
140 | return(false); | ||
141 | TranInfo *traninfo; | ||
142 | for(traninfo=tl->first(); traninfo; traninfo=tl->next()) { | ||
143 | if( traninfo->id() == id ) | ||
120 | break; | 144 | break; |
121 | traninfo = tl->next(); | ||
122 | } | 145 | } |
@@ -127,3 +150,3 @@ void CBInfo::addTransaction( TranInfo *tran ) | |||
127 | { | 150 | { |
128 | tl->inSort( tran ); | 151 | tl->append( tran ); |
129 | calcBalance(); | 152 | calcBalance(); |
@@ -133,3 +156,3 @@ void CBInfo::removeTransaction( TranInfo *tran ) | |||
133 | { | 156 | { |
134 | tl->remove( tran ); | 157 | tl->removeRef( tran ); |
135 | delete tran; | 158 | delete tran; |
@@ -138,2 +161,5 @@ void CBInfo::removeTransaction( TranInfo *tran ) | |||
138 | 161 | ||
162 | |||
163 | // --- loadTransactions ------------------------------------------------------- | ||
164 | // Reads the transactions. Either the old way 1-n or as linked list. | ||
139 | void CBInfo::loadTransactions() | 165 | void CBInfo::loadTransactions() |
@@ -146,15 +172,18 @@ void CBInfo::loadTransactions() | |||
146 | Config config( fn, Config::File ); | 172 | Config config( fn, Config::File ); |
147 | 173 | int i=_first; | |
148 | for ( int i = 1; trandesc != QString::null; i++ ) | 174 | bool bOld=false; |
149 | { | 175 | if( i==-1 ) { |
176 | i=1; | ||
177 | bOld=true; | ||
178 | } | ||
179 | while( i>=0 ) { | ||
180 | _last=i; | ||
150 | tran = new TranInfo( config, i ); | 181 | tran = new TranInfo( config, i ); |
151 | trandesc = tran->desc(); | 182 | trandesc = tran->desc(); |
152 | if ( trandesc != QString::null ) | 183 | if( trandesc==QString::null ) { |
153 | { | ||
154 | tl->inSort( tran ); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | delete tran; | 184 | delete tran; |
185 | break; | ||
159 | } | 186 | } |
187 | tl->append(tran); | ||
188 | i= bOld ? i+1 : tran->getNext(); | ||
160 | } | 189 | } |
@@ -164,2 +193,4 @@ void CBInfo::loadTransactions() | |||
164 | 193 | ||
194 | |||
195 | // --- calcBalance ------------------------------------------------------------ | ||
165 | void CBInfo::calcBalance() | 196 | void CBInfo::calcBalance() |
@@ -182,2 +213,3 @@ void CBInfo::calcBalance() | |||
182 | 213 | ||
214 | |||
183 | int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) | 215 | int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) |
diff --git a/noncore/apps/checkbook/cbinfo.h b/noncore/apps/checkbook/cbinfo.h index 5e65db2..0b5b818 100644 --- a/noncore/apps/checkbook/cbinfo.h +++ b/noncore/apps/checkbook/cbinfo.h | |||
@@ -31,2 +31,3 @@ | |||
31 | 31 | ||
32 | #include <qwidget.h> | ||
32 | #include <qlist.h> | 33 | #include <qlist.h> |
@@ -65,6 +66,8 @@ class CBInfo | |||
65 | 66 | ||
67 | // write | ||
66 | void write(); | 68 | void write(); |
67 | 69 | ||
70 | // transactions | ||
68 | TranInfoList *transactions() const { return tl; } | 71 | TranInfoList *transactions() const { return tl; } |
69 | TranInfo *findTransaction( const QString &, const QString &, const QString & ); | 72 | TranInfo *findTransaction( const QString & ); |
70 | void addTransaction( TranInfo * ); | 73 | void addTransaction( TranInfo * ); |
@@ -72,2 +75,13 @@ class CBInfo | |||
72 | 75 | ||
76 | // lastTab | ||
77 | void setLastTab(const QString &sLastTab) { _sLastTab=sLastTab; } | ||
78 | QString &getLastTab() { return(_sLastTab); } | ||
79 | |||
80 | // getNextNumber | ||
81 | int getNextNumber() { return( ++_last ); } | ||
82 | |||
83 | // sortOrder | ||
84 | void setSortOrder(const QString &sSortOrder) { _sSortOrder=sSortOrder; } | ||
85 | QString &getSortOrder() { return(_sSortOrder); } | ||
86 | |||
73 | private: | 87 | private: |
@@ -83,2 +97,6 @@ class CBInfo | |||
83 | float b; | 97 | float b; |
98 | QString _sLastTab; | ||
99 | int _first; | ||
100 | int _last; | ||
101 | QString _sSortOrder; | ||
84 | 102 | ||
diff --git a/noncore/apps/checkbook/cfg.cpp b/noncore/apps/checkbook/cfg.cpp new file mode 100644 index 0000000..1e0ec5c --- a/dev/null +++ b/noncore/apps/checkbook/cfg.cpp | |||
@@ -0,0 +1,213 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <stdio.h> | ||
30 | |||
31 | #include <qstring.h> | ||
32 | #include <qstringlist.h> | ||
33 | #include <qwidget.h> | ||
34 | #include <qpe/resource.h> | ||
35 | #include <qpe/config.h> | ||
36 | |||
37 | #include "cfg.h" | ||
38 | |||
39 | // --- Cfg -------------------------------------------------------------------- | ||
40 | Cfg::Cfg() | ||
41 | { | ||
42 | _currencySymbol="$"; | ||
43 | _showLocks=FALSE; | ||
44 | _showBalances=FALSE; | ||
45 | _pCategories=new CategoryList(); | ||
46 | } | ||
47 | |||
48 | // --- readStringList --------------------------------------------------------- | ||
49 | // Reads the entries for the control from a configuration file and returns | ||
50 | // them in a StringList. Later this list can be used to create the control. It | ||
51 | // is assumed, that the group is already set. Key is used to enumerate the | ||
52 | // entries. | ||
53 | void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) | ||
54 | { | ||
55 | qDebug( "%s", sKey ); | ||
56 | |||
57 | QString sEntry; | ||
58 | int iCount; | ||
59 | |||
60 | // read count of elements | ||
61 | sEntry.sprintf("%s_Count", sKey); | ||
62 | iCount=cfg.readNumEntry(sEntry, 0); | ||
63 | |||
64 | // read entries | ||
65 | for(int i=1; i<=iCount; i++) { | ||
66 | sEntry.sprintf("%s%d", sKey, i); | ||
67 | QString sType=cfg.readEntry(sEntry); | ||
68 | if( sType!=NULL ) | ||
69 | lst.append(sType); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | // --- readConfig ------------------------------------------------------------- | ||
75 | // Reads the member data from the given config file. It will also set the group | ||
76 | // "Config" | ||
77 | void Cfg::readConfig(Config &config) | ||
78 | { | ||
79 | // set group | ||
80 | config.setGroup( "Config" ); | ||
81 | |||
82 | // read scalars | ||
83 | _currencySymbol = config.readEntry( "CurrencySymbol", "$" ); | ||
84 | _showLocks = config.readBoolEntry( "ShowLocks", FALSE ); | ||
85 | _showBalances = config.readBoolEntry( "ShowBalances", FALSE ); | ||
86 | _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE ); | ||
87 | _sLastBook = config.readEntry("LastBook", ""); | ||
88 | _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE ); | ||
89 | |||
90 | // Account types | ||
91 | readStringList(config, "AccType", _AccountTypes); | ||
92 | if( _AccountTypes.isEmpty() ) { | ||
93 | _AccountTypes+= (const char *)QWidget::tr("Savings"); | ||
94 | _AccountTypes+= (const char *)QWidget::tr("Checking"); | ||
95 | _AccountTypes+= (const char *)QWidget::tr("CD"); | ||
96 | _AccountTypes+= (const char *)QWidget::tr("Money market"); | ||
97 | _AccountTypes+= (const char *)QWidget::tr("Mutual fund"); | ||
98 | _AccountTypes+= (const char *)QWidget::tr("Other"); | ||
99 | writeStringList(config, "AccType", _AccountTypes); | ||
100 | config.write(); | ||
101 | } | ||
102 | |||
103 | // Read Categories | ||
104 | QStringList lst; | ||
105 | readStringList(config, "Category", lst); | ||
106 | if( lst.isEmpty() ) { | ||
107 | QString type=QWidget::tr("Expense"); | ||
108 | lst += QWidget::tr( "Automobile" )+";"+type; | ||
109 | lst += QWidget::tr( "Bills" )+";"+type; | ||
110 | lst += QWidget::tr( "CDs" )+";"+type; | ||
111 | lst += QWidget::tr( "Clothing" )+";"+type; | ||
112 | lst += QWidget::tr( "Computer" )+";"+type; | ||
113 | lst += QWidget::tr( "DVDs" )+";"+type; | ||
114 | lst += QWidget::tr( "Electronics" )+";"+type; | ||
115 | lst += QWidget::tr( "Entertainment" )+";"+type; | ||
116 | lst += QWidget::tr( "Food" )+";"+type; | ||
117 | lst += QWidget::tr( "Gasoline" )+";"+type; | ||
118 | lst += QWidget::tr( "Misc" )+";"+type; | ||
119 | lst += QWidget::tr( "Movies" )+";"+type; | ||
120 | lst += QWidget::tr( "Rent" )+";"+type; | ||
121 | lst += QWidget::tr( "Travel" )+";"+type; | ||
122 | |||
123 | type=QWidget::tr( "Income" ); | ||
124 | lst += QWidget::tr( "Work" )+";"+type; | ||
125 | lst += QWidget::tr( "Family Member" )+";"+type; | ||
126 | lst += QWidget::tr( "Misc. Credit" )+";"+type; | ||
127 | |||
128 | setCategories(lst); | ||
129 | writeStringList(config, "Category", lst); | ||
130 | config.write(); | ||
131 | } else { | ||
132 | setCategories(lst); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | |||
137 | // --- writeStringList -------------------------------------------------------- | ||
138 | // Writes the entries in the control in a configuration file. It is assumed, | ||
139 | // that the group is already set. Key is used to enumerate the entries | ||
140 | void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) | ||
141 | { | ||
142 | QString sEntry; | ||
143 | int iCount=0; | ||
144 | QStringList::Iterator itr; | ||
145 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | ||
146 | sEntry.sprintf("%s%d", sKey, ++iCount); | ||
147 | cfg.writeEntry(sEntry, *itr ); | ||
148 | } | ||
149 | sEntry.sprintf("%s_Count", sKey); | ||
150 | cfg.writeEntry(sEntry, iCount); | ||
151 | } | ||
152 | |||
153 | |||
154 | // --- writeConfig ----------------------------------------------------------- | ||
155 | // Writes all config data back to the config file. The group will be set to | ||
156 | // "Config" and the write be commited | ||
157 | void Cfg::writeConfig(Config &config) | ||
158 | { | ||
159 | // set the group | ||
160 | config.setGroup( "Config" ); | ||
161 | |||
162 | // write scalars | ||
163 | config.writeEntry( "CurrencySymbol", _currencySymbol ); | ||
164 | config.writeEntry( "ShowLocks", _showLocks ); | ||
165 | config.writeEntry( "ShowBalances", _showBalances ); | ||
166 | config.writeEntry( "OpenLastBook", _openLastBook ); | ||
167 | config.writeEntry( "LastBook", _sLastBook ); | ||
168 | config.writeEntry( "ShowLastTab", _showLastTab ); | ||
169 | |||
170 | // write account types | ||
171 | writeStringList(config, "AccType", _AccountTypes); | ||
172 | |||
173 | // write categories | ||
174 | QStringList lst=getCategories(); | ||
175 | writeStringList(config, "Category", lst ); | ||
176 | |||
177 | // commit write | ||
178 | config.write(); | ||
179 | } | ||
180 | |||
181 | |||
182 | // --- getCategories ---------------------------------------------------------- | ||
183 | QStringList Cfg::getCategories() | ||
184 | { | ||
185 | QStringList ret; | ||
186 | for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) { | ||
187 | QString sEntry; | ||
188 | sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) ); | ||
189 | ret.append(sEntry); | ||
190 | } | ||
191 | return(ret); | ||
192 | } | ||
193 | |||
194 | |||
195 | // --- setCategories ---------------------------------------------------------- | ||
196 | void Cfg::setCategories(QStringList &lst) | ||
197 | { | ||
198 | _pCategories->clear(); | ||
199 | QStringList::Iterator itr; | ||
200 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | ||
201 | QStringList split=QStringList::split(";", *itr, true); | ||
202 | if( split.count()<2 ) continue; | ||
203 | bool bIncome= (split[1]==QWidget::tr("Income")); | ||
204 | _pCategories->append( new Category(split[0], bIncome) ); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | |||
209 | // --- CategoryList ------------------------------------------------------------ | ||
210 | CategoryList::CategoryList() : QList<Category>() | ||
211 | { | ||
212 | setAutoDelete(true); | ||
213 | } | ||
diff --git a/noncore/apps/checkbook/cfg.h b/noncore/apps/checkbook/cfg.h new file mode 100644 index 0000000..2b69368 --- a/dev/null +++ b/noncore/apps/checkbook/cfg.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef CFG_H | ||
30 | #define CFG_H | ||
31 | |||
32 | #include <qstring.h> | ||
33 | #include <qlist.h> | ||
34 | #include <qstringlist.h> | ||
35 | class Config; | ||
36 | |||
37 | // --- Category --------------------------------------------------------------- | ||
38 | class Category | ||
39 | { | ||
40 | public: | ||
41 | // --- Constructor: | ||
42 | Category(QString &sName, bool bIncome=false) { _sName=sName; _bIncome=bIncome; } | ||
43 | |||
44 | // members | ||
45 | QString &getName() { return(_sName); } | ||
46 | bool isIncome() { return(_bIncome); } | ||
47 | void setName(QString &sName) { _sName=sName; } | ||
48 | void setIncome(bool bIncome) { _bIncome=bIncome; } | ||
49 | |||
50 | private: | ||
51 | QString _sName; | ||
52 | bool _bIncome; | ||
53 | }; | ||
54 | |||
55 | class CategoryList : public QList<Category> | ||
56 | { | ||
57 | public: | ||
58 | // --- Constructor | ||
59 | CategoryList(); | ||
60 | }; | ||
61 | |||
62 | |||
63 | // --- Cfg -------------------------------------------------------------------- | ||
64 | class Cfg | ||
65 | { | ||
66 | public: | ||
67 | // --- Constructor | ||
68 | Cfg(); | ||
69 | |||
70 | // --- members | ||
71 | bool getShowLocks() { return(_showLocks); } | ||
72 | void setShowLocks(bool n) { _showLocks=n; } | ||
73 | bool getShowBalances() { return(_showBalances); } | ||
74 | void setShowBalances(bool n) { _showBalances=n; } | ||
75 | QString &getCurrencySymbol() { return(_currencySymbol); } | ||
76 | void setCurrencySymbol(QString n) {_currencySymbol= n; } | ||
77 | void setCurrencySymbol(const char *n) { _currencySymbol=n; } | ||
78 | QStringList &getAccountTypes() { return(_AccountTypes); } | ||
79 | |||
80 | // --- Categories | ||
81 | QStringList getCategories(); | ||
82 | void setCategories(QStringList &lst); | ||
83 | CategoryList *getCategoryList() { return(_pCategories); } | ||
84 | |||
85 | // --- last book | ||
86 | void setOpenLastBook(bool openLastBook) { _openLastBook=openLastBook; } | ||
87 | bool isOpenLastBook() { return(_openLastBook); } | ||
88 | void setLastBook(const QString &lastBook) { _sLastBook=lastBook; } | ||
89 | QString &getLastBook() { return(_sLastBook); } | ||
90 | |||
91 | // --- last tab | ||
92 | void setShowLastTab(bool showLastTab) { _showLastTab=showLastTab; } | ||
93 | bool isShowLastTab() { return(_showLastTab); } | ||
94 | |||
95 | // --- reads data from config file | ||
96 | void readConfig(Config &cfg); | ||
97 | |||
98 | // --- writes data to config file | ||
99 | void writeConfig(Config &cfg); | ||
100 | |||
101 | // --- reads list from config file | ||
102 | static void readStringList(Config &cfg, const char *sKey, QStringList &lst); | ||
103 | |||
104 | // --- writes list in configuration file | ||
105 | static void writeStringList(Config &cfg, const char *sKey, QStringList &lst); | ||
106 | |||
107 | |||
108 | |||
109 | private: | ||
110 | QString _currencySymbol; | ||
111 | bool _showLocks; | ||
112 | bool _showBalances; | ||
113 | bool _openLastBook; | ||
114 | bool _showLastTab; | ||
115 | QString _sLastBook; | ||
116 | QStringList _AccountTypes; | ||
117 | CategoryList *_pCategories; | ||
118 | }; | ||
119 | |||
120 | #endif | ||
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 653ee4a..c53e889 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -35,2 +35,4 @@ | |||
35 | #include "password.h" | 35 | #include "password.h" |
36 | #include "mainwindow.h" | ||
37 | #include "cfg.h" | ||
36 | 38 | ||
@@ -50,3 +52,11 @@ | |||
50 | 52 | ||
51 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | 53 | #define COL_ID 0 |
54 | #define COL_NUM 1 | ||
55 | #define COL_DATE 2 | ||
56 | #define COL_DESC 3 | ||
57 | #define COL_AMOUNT 4 | ||
58 | #define COL_BAL 5 | ||
59 | |||
60 | // --- Checkbook -------------------------------------------------------------- | ||
61 | Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) | ||
52 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 62 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
@@ -54,4 +64,5 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | |||
54 | info = i; | 64 | info = i; |
55 | currencySymbol = symbol; | 65 | _pCfg=cfg; |
56 | 66 | ||
67 | // Title bar | ||
57 | if ( info->name() != "" ) | 68 | if ( info->name() != "" ) |
@@ -68,2 +79,3 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | |||
68 | 79 | ||
80 | |||
69 | // Setup layout to make everything pretty | 81 | // Setup layout to make everything pretty |
@@ -76,3 +88,2 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | |||
76 | layout->addWidget( mainWidget ); | 88 | layout->addWidget( mainWidget ); |
77 | |||
78 | mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); | 89 | mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); |
@@ -80,3 +91,7 @@ Checkbook::Checkbook( QWidget *parent, CBInfo *i, const QString &symbol ) | |||
80 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); | 91 | mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); |
92 | if( _pCfg->isShowLastTab() ) | ||
93 | mainWidget->setCurrentTab( info->getLastTab() ); | ||
94 | else | ||
81 | mainWidget->setCurrentTab( tr( "Info" ) ); | 95 | mainWidget->setCurrentTab( tr( "Info" ) ); |
96 | connect( mainWidget, SIGNAL( currentChanged(QWidget *) ), this, SLOT( slotTab(QWidget *) ) ); | ||
82 | 97 | ||
@@ -90,5 +105,6 @@ Checkbook::~Checkbook() | |||
90 | 105 | ||
106 | // --- initInfo --------------------------------------------------------------- | ||
91 | QWidget *Checkbook::initInfo() | 107 | QWidget *Checkbook::initInfo() |
92 | { | 108 | { |
93 | QWidget *control = new QWidget( mainWidget ); | 109 | QWidget *control = new QWidget( mainWidget, tr("Info") ); |
94 | 110 | ||
@@ -130,8 +146,3 @@ QWidget *Checkbook::initInfo() | |||
130 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); | 146 | QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); |
131 | typeList->insertItem( tr( "Savings" ) ); // 0 | 147 | typeList->insertStringList( _pCfg->getAccountTypes() ); |
132 | typeList->insertItem( tr( "Checking" ) ); // 1 | ||
133 | typeList->insertItem( tr( "CD" ) ); // 2 | ||
134 | typeList->insertItem( tr( "Money market" ) );// 3 | ||
135 | typeList->insertItem( tr( "Mutual fund" ) );// 4 | ||
136 | typeList->insertItem( tr( "Other" ) ); // 5 | ||
137 | layout->addWidget( typeList, 2, 1 ); | 148 | layout->addWidget( typeList, 2, 1 ); |
@@ -185,5 +196,7 @@ QWidget *Checkbook::initInfo() | |||
185 | 196 | ||
197 | |||
198 | // --- initTransactions ------------------------------------------------------- | ||
186 | QWidget *Checkbook::initTransactions() | 199 | QWidget *Checkbook::initTransactions() |
187 | { | 200 | { |
188 | QWidget *control = new QWidget( mainWidget ); | 201 | QWidget *control = new QWidget( mainWidget, tr("Transactions") ); |
189 | 202 | ||
@@ -193,9 +206,22 @@ QWidget *Checkbook::initTransactions() | |||
193 | 206 | ||
194 | balanceLabel = new QLabel( tr( "Current balance: %10.00" ).arg( currencySymbol ), | 207 | // Sort selector |
195 | control ); | 208 | QLabel *label = new QLabel( tr( "Sort by:" ), control ); |
196 | QWhatsThis::add( balanceLabel, tr( "This area shows the current balance in this checkbook." ) ); | 209 | QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); |
197 | layout->addMultiCellWidget( balanceLabel, 0, 0, 0, 2 ); | 210 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); |
198 | 211 | _cbSortType=new QComboBox( control ); | |
212 | _cbSortType->insertItem( tr("Entry Order") ); | ||
213 | _cbSortType->insertItem( tr("Date") ); | ||
214 | _cbSortType->insertItem( tr("Number") ); | ||
215 | layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); | ||
216 | connect( _cbSortType, SIGNAL( activated(const QString &) ), this, SLOT( slotSortChanged( const QString & ) ) ); | ||
217 | |||
218 | // Table | ||
199 | tranTable = new QListView( control ); | 219 | tranTable = new QListView( control ); |
220 | QFont fnt(QPEApplication::font()); | ||
221 | fnt.setPointSize( fnt.pointSize()-1 ); | ||
222 | tranTable->setFont( fnt ); | ||
200 | 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." ) ); | 223 | 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 | tranTable->addColumn( tr( "Id" ) ); | ||
225 | tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); | ||
226 | tranTable->setColumnWidth( COL_ID, 0); | ||
201 | tranTable->addColumn( tr( "Num" ) ); | 227 | tranTable->addColumn( tr( "Num" ) ); |
@@ -204,6 +230,8 @@ QWidget *Checkbook::initTransactions() | |||
204 | tranTable->addColumn( tr( "Description" ) ); | 230 | tranTable->addColumn( tr( "Description" ) ); |
205 | int colnum = tranTable->addColumn( tr( "Amount" ) ); | 231 | int column = tranTable->addColumn( tr( "Amount" ) ); |
206 | tranTable->setColumnAlignment( colnum, Qt::AlignRight ); | 232 | tranTable->setColumnAlignment( column, Qt::AlignRight ); |
233 | column=tranTable->addColumn( tr("Balance") ); | ||
234 | tranTable->setColumnAlignment( column, Qt::AlignRight ); | ||
207 | tranTable->setAllColumnsShowFocus( TRUE ); | 235 | tranTable->setAllColumnsShowFocus( TRUE ); |
208 | tranTable->setSorting( 1 ); | 236 | tranTable->setSorting( -1 ); |
209 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); | 237 | layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); |
@@ -212,3 +240,5 @@ QWidget *Checkbook::initTransactions() | |||
212 | this, SLOT( slotEditTran() ) ); | 240 | this, SLOT( slotEditTran() ) ); |
241 | _sortCol=COL_ID; | ||
213 | 242 | ||
243 | // Buttons | ||
214 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); | 244 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); |
@@ -231,2 +261,4 @@ QWidget *Checkbook::initTransactions() | |||
231 | 261 | ||
262 | |||
263 | // --- initCharts ------------------------------------------------------------- | ||
232 | QWidget *Checkbook::initCharts() | 264 | QWidget *Checkbook::initCharts() |
@@ -235,3 +267,3 @@ QWidget *Checkbook::initCharts() | |||
235 | 267 | ||
236 | QWidget *control = new QWidget( mainWidget ); | 268 | QWidget *control = new QWidget( mainWidget, tr("Charts") ); |
237 | 269 | ||
@@ -261,2 +293,3 @@ QWidget *Checkbook::initCharts() | |||
261 | 293 | ||
294 | // --- loadCheckbook ---------------------------------------------------------- | ||
262 | void Checkbook::loadCheckbook() | 295 | void Checkbook::loadCheckbook() |
@@ -283,2 +316,6 @@ void Checkbook::loadCheckbook() | |||
283 | } | 316 | } |
317 | if( i<=0 ) { | ||
318 | typeList->insertItem( temptext, 0 ); | ||
319 | typeList->setCurrentItem(0); | ||
320 | } | ||
284 | bankEdit->setText( info->bank() ); | 321 | bankEdit->setText( info->bank() ); |
@@ -293,3 +330,2 @@ void Checkbook::loadCheckbook() | |||
293 | QString stramount; | 330 | QString stramount; |
294 | |||
295 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) | 331 | for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) |
@@ -301,29 +337,49 @@ void Checkbook::loadCheckbook() | |||
301 | } | 337 | } |
302 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 338 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
303 | ( void ) new CBListItem( tranTable, tran->number(), tran->datestr(), tran->desc(), stramount ); | 339 | ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->number(), tran->datestr(), tran->desc(), stramount ); |
304 | } | 340 | } |
305 | 341 | ||
306 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); | 342 | // set sort order |
343 | bool bOk=false; | ||
344 | for(int i=0; i<_cbSortType->count(); i++) { | ||
345 | if( _cbSortType->text(i)==info->getSortOrder() ) { | ||
346 | _cbSortType->setCurrentItem(i); | ||
347 | slotSortChanged( info->getSortOrder() ); | ||
348 | bOk=true; | ||
349 | break; | ||
350 | } | ||
351 | } | ||
352 | if( !bOk ) { | ||
353 | _cbSortType->setCurrentItem(0); | ||
354 | slotSortChanged( _cbSortType->currentText() ); | ||
355 | } | ||
307 | 356 | ||
308 | highTranNum = tranList->count(); | 357 | // calc running balance |
358 | adjustBalance(); | ||
309 | } | 359 | } |
310 | 360 | ||
361 | // --- adjustBalance ---------------------------------------------------------- | ||
311 | void Checkbook::adjustBalance() | 362 | void Checkbook::adjustBalance() |
312 | { | 363 | { |
313 | balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( info->balance(), 0, 'f', 2 ) ); | 364 | // update running balance in register |
365 | QString sRunning; | ||
366 | float bal=info->startingBalance(); | ||
367 | for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { | ||
368 | TranInfo *tran=item->getTranInfo(); | ||
369 | bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); | ||
370 | sRunning.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal ); | ||
371 | item->setText( COL_BAL, sRunning); | ||
372 | } | ||
314 | } | 373 | } |
315 | 374 | ||
316 | TranInfo *Checkbook::findTran( const QString &checknum, const QString &date, const QString &desc ) | 375 | // --- resort ----------------------------------------------------------------- |
317 | { | 376 | void Checkbook::resort() |
318 | TranInfo *traninfo = tranList->first(); | ||
319 | while ( traninfo ) | ||
320 | { | 377 | { |
321 | if ( traninfo->number() == checknum && traninfo->datestr() == date && | 378 | tranTable->setSorting(_sortCol); |
322 | traninfo->desc() == desc ) | 379 | tranTable->sort(); |
323 | break; | 380 | tranTable->setSorting(-1); |
324 | traninfo = tranList->next(); | ||
325 | } | ||
326 | return( traninfo ); | ||
327 | } | 381 | } |
328 | 382 | ||
383 | |||
384 | // --- accept ----------------------------------------------------------------- | ||
329 | void Checkbook::accept() | 385 | void Checkbook::accept() |
@@ -400,2 +456,4 @@ void Checkbook::slotNameChanged( const QString &newname ) | |||
400 | 456 | ||
457 | |||
458 | // ---slotStartingBalanceChanged ---------------------------------------------- | ||
401 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | 459 | void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) |
@@ -407,6 +465,8 @@ void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) | |||
407 | 465 | ||
466 | |||
408 | void Checkbook::slotNewTran() | 467 | void Checkbook::slotNewTran() |
409 | { | 468 | { |
410 | highTranNum++; | 469 | TranInfo *traninfo = new TranInfo( info->getNextNumber() ); |
411 | TranInfo *traninfo = new TranInfo( highTranNum ); | 470 | if( !_dLastNew.isNull() ) |
471 | traninfo->setDate(_dLastNew); | ||
412 | 472 | ||
@@ -414,3 +474,3 @@ void Checkbook::slotNewTran() | |||
414 | traninfo, | 474 | traninfo, |
415 | currencySymbol ); | 475 | _pCfg ); |
416 | currtran->showMaximized(); | 476 | currtran->showMaximized(); |
@@ -424,14 +484,12 @@ void Checkbook::slotNewTran() | |||
424 | QString stramount; | 484 | QString stramount; |
425 | 485 | amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount(); | |
426 | amount = traninfo->amount(); | 486 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
427 | if ( traninfo->withdrawal() ) | 487 | ( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), |
428 | { | 488 | traninfo->number(), traninfo->datestr(), traninfo->desc(), |
429 | amount *= -1; | ||
430 | } | ||
431 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | ||
432 | |||
433 | ( void ) new CBListItem( tranTable, traninfo->number(), traninfo->datestr(), traninfo->desc(), | ||
434 | stramount ); | 489 | stramount ); |
435 | 490 | resort(); | |
436 | adjustBalance(); | 491 | adjustBalance(); |
492 | |||
493 | // save last date | ||
494 | _dLastNew = traninfo->date(); | ||
437 | } | 495 | } |
@@ -439,3 +497,2 @@ void Checkbook::slotNewTran() | |||
439 | { | 497 | { |
440 | highTranNum--; | ||
441 | delete traninfo; | 498 | delete traninfo; |
@@ -448,8 +505,5 @@ void Checkbook::slotEditTran() | |||
448 | if ( !curritem ) | 505 | if ( !curritem ) |
449 | { | ||
450 | return; | 506 | return; |
451 | } | ||
452 | 507 | ||
453 | TranInfo *traninfo = info->findTransaction( curritem->text( 0 ), curritem->text( 1 ), | 508 | TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) ); |
454 | curritem->text( 2 ) ); | ||
455 | 509 | ||
@@ -457,3 +511,3 @@ void Checkbook::slotEditTran() | |||
457 | traninfo, | 511 | traninfo, |
458 | currencySymbol ); | 512 | _pCfg ); |
459 | currtran->showMaximized(); | 513 | currtran->showMaximized(); |
@@ -461,5 +515,5 @@ void Checkbook::slotEditTran() | |||
461 | { | 515 | { |
462 | curritem->setText( 0, traninfo->number() ); | 516 | curritem->setText( COL_NUM, traninfo->number() ); |
463 | curritem->setText( 1, traninfo->datestr() ); | 517 | curritem->setText( COL_DATE, traninfo->datestr() ); |
464 | curritem->setText( 2, traninfo->desc() ); | 518 | curritem->setText( COL_DESC, traninfo->desc() ); |
465 | 519 | ||
@@ -471,5 +525,5 @@ void Checkbook::slotEditTran() | |||
471 | QString stramount; | 525 | QString stramount; |
472 | stramount.sprintf( "%s%.2f", currencySymbol.latin1(), amount ); | 526 | stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount ); |
473 | curritem->setText( 3, stramount ); | 527 | curritem->setText( COL_AMOUNT, stramount ); |
474 | 528 | resort(); | |
475 | adjustBalance(); | 529 | adjustBalance(); |
@@ -484,7 +538,5 @@ void Checkbook::slotDeleteTran() | |||
484 | if ( !curritem ) | 538 | if ( !curritem ) |
485 | { | ||
486 | return; | 539 | return; |
487 | } | ||
488 | 540 | ||
489 | TranInfo *traninfo = findTran( curritem->text( 0 ), curritem->text( 1 ), curritem->text( 2 ) ); | 541 | TranInfo *traninfo = info->findTransaction( curritem->text(COL_ID) ); |
490 | 542 | ||
@@ -591,3 +643,3 @@ void Checkbook::drawCategoryChart( bool withdrawals ) | |||
591 | 643 | ||
592 | CBListItem::CBListItem( QListView *parent, QString label1, QString label2, | 644 | CBListItem::CBListItem( TranInfo *pTran, QListView *parent, QString label1, QString label2, |
593 | QString label3, QString label4, QString label5, QString label6, QString label7, | 645 | QString label3, QString label4, QString label5, QString label6, QString label7, |
@@ -596,2 +648,3 @@ CBListItem::CBListItem( QListView *parent, QString label1, QString label2, | |||
596 | { | 648 | { |
649 | _pTran=pTran; | ||
597 | m_known = FALSE; | 650 | m_known = FALSE; |
@@ -654 +707,24 @@ bool CBListItem::isAltBackground() | |||
654 | } | 707 | } |
708 | |||
709 | |||
710 | // --- slotTab ---------------------------------------------------------------- | ||
711 | void Checkbook::slotTab(QWidget *tab) | ||
712 | { | ||
713 | if( !tab || !info ) return; | ||
714 | info->setLastTab( tab->name() ); | ||
715 | } | ||
716 | |||
717 | |||
718 | // --- slotSortChanged --------------------------------------------------------- | ||
719 | void Checkbook::slotSortChanged( const QString &selc ) | ||
720 | { | ||
721 | if( selc==tr("Entry Order") ) { | ||
722 | _sortCol=COL_ID; | ||
723 | } else if( selc==tr("Number") ) { | ||
724 | _sortCol=COL_NUM; | ||
725 | } else if( selc==tr("Date") ) { | ||
726 | _sortCol=COL_DATE; | ||
727 | } | ||
728 | info->setSortOrder( selc ); | ||
729 | resort(); | ||
730 | } | ||
diff --git a/noncore/apps/checkbook/checkbook.h b/noncore/apps/checkbook/checkbook.h index 4a5011b..1b6a2d3 100644 --- a/noncore/apps/checkbook/checkbook.h +++ b/noncore/apps/checkbook/checkbook.h | |||
@@ -31,2 +31,3 @@ | |||
31 | 31 | ||
32 | #include <qdatetime.h> | ||
32 | #include <qdialog.h> | 33 | #include <qdialog.h> |
@@ -48,3 +49,6 @@ class TranInfo; | |||
48 | class TranInfoList; | 49 | class TranInfoList; |
50 | class Cfg; | ||
49 | 51 | ||
52 | |||
53 | // --- Checkbook -------------------------------------------------------------- | ||
50 | class Checkbook : public QDialog | 54 | class Checkbook : public QDialog |
@@ -54,5 +58,8 @@ class Checkbook : public QDialog | |||
54 | public: | 58 | public: |
55 | Checkbook( QWidget * = 0x0, CBInfo * = 0x0, const QString & = "$" ); | 59 | Checkbook( QWidget *, CBInfo *, Cfg *cfg ); |
56 | ~Checkbook(); | 60 | ~Checkbook(); |
57 | 61 | ||
62 | // resort | ||
63 | void resort(); | ||
64 | |||
58 | private: | 65 | private: |
@@ -60,4 +67,3 @@ class Checkbook : public QDialog | |||
60 | TranInfoList *tranList; | 67 | TranInfoList *tranList; |
61 | QString currencySymbol; | 68 | Cfg *_pCfg; |
62 | int highTranNum; | ||
63 | 69 | ||
@@ -66,3 +72,2 @@ class Checkbook : public QDialog | |||
66 | void adjustBalance(); | 72 | void adjustBalance(); |
67 | TranInfo *findTran( const QString &, const QString &, const QString & ); | ||
68 | 73 | ||
@@ -78,2 +83,3 @@ class Checkbook : public QDialog | |||
78 | QMultiLineEdit *notesEdit; | 83 | QMultiLineEdit *notesEdit; |
84 | int _sortCol; | ||
79 | 85 | ||
@@ -82,3 +88,4 @@ class Checkbook : public QDialog | |||
82 | QListView *tranTable; | 88 | QListView *tranTable; |
83 | QLabel *balanceLabel; | 89 | QComboBox *_cbSortType; |
90 | QDate _dLastNew; | ||
84 | 91 | ||
@@ -93,4 +100,6 @@ class Checkbook : public QDialog | |||
93 | 100 | ||
101 | |||
94 | protected slots: | 102 | protected slots: |
95 | void accept(); | 103 | void accept(); |
104 | void slotTab(QWidget *tab); | ||
96 | 105 | ||
@@ -104,4 +113,6 @@ class Checkbook : public QDialog | |||
104 | void slotDrawGraph(); | 113 | void slotDrawGraph(); |
114 | void slotSortChanged( const QString & ); | ||
105 | }; | 115 | }; |
106 | 116 | ||
117 | // --- CBListItem ------------------------------------------------------------- | ||
107 | class CBListItem : public QListViewItem | 118 | class CBListItem : public QListViewItem |
@@ -111,3 +122,3 @@ class CBListItem : public QListViewItem | |||
111 | public: | 122 | public: |
112 | CBListItem( QListView *, QString = QString::null, QString = QString::null, | 123 | CBListItem( TranInfo *, QListView *, QString = QString::null, QString = QString::null, |
113 | QString = QString::null, QString = QString::null, QString = QString::null, | 124 | QString = QString::null, QString = QString::null, QString = QString::null, |
@@ -117,3 +128,7 @@ class CBListItem : public QListViewItem | |||
117 | 128 | ||
129 | // --- members | ||
130 | TranInfo *getTranInfo() { return(_pTran); } | ||
131 | |||
118 | private: | 132 | private: |
133 | TranInfo *_pTran; | ||
119 | QListView *owner; | 134 | QListView *owner; |
@@ -125,2 +140,3 @@ class CBListItem : public QListViewItem | |||
125 | 140 | ||
141 | |||
126 | #endif | 142 | #endif |
diff --git a/noncore/apps/checkbook/checkbook.pro b/noncore/apps/checkbook/checkbook.pro index 9a16a56..c574aff 100644 --- a/noncore/apps/checkbook/checkbook.pro +++ b/noncore/apps/checkbook/checkbook.pro | |||
@@ -1,3 +1,2 @@ | |||
1 | TEMPLATE = app | 1 | CONFIG = qt warn_on release quick-app |
2 | CONFIG = qt warn_on release | ||
3 | HEADERS = mainwindow.h \ | 2 | HEADERS = mainwindow.h \ |
@@ -10,2 +9,5 @@ HEADERS = mainwindow.h \ | |||
10 | transaction.h \ | 9 | transaction.h \ |
10 | tabledef.h \ | ||
11 | listedit.h \ | ||
12 | cfg.h \ | ||
11 | graph.h | 13 | graph.h |
@@ -20,2 +22,5 @@ SOURCES = main.cpp \ | |||
20 | transaction.cpp \ | 22 | transaction.cpp \ |
23 | tabledef.cpp \ | ||
24 | listedit.cpp \ | ||
25 | cfg.cpp \ | ||
21 | graph.cpp | 26 | graph.cpp |
@@ -25,3 +30,2 @@ LIBS += -lqpe -lopie | |||
25 | TARGET = checkbook | 30 | TARGET = checkbook |
26 | DESTDIR = $(OPIEDIR)/bin | ||
27 | 31 | ||
diff --git a/noncore/apps/checkbook/configuration.cpp b/noncore/apps/checkbook/configuration.cpp index 7731cf3..3f5662d 100644 --- a/noncore/apps/checkbook/configuration.cpp +++ b/noncore/apps/checkbook/configuration.cpp | |||
@@ -29,2 +29,5 @@ | |||
29 | #include "configuration.h" | 29 | #include "configuration.h" |
30 | #include "mainwindow.h" | ||
31 | #include "listedit.h" | ||
32 | #include "tabledef.h" | ||
30 | 33 | ||
@@ -35,4 +38,8 @@ | |||
35 | #include <qwhatsthis.h> | 38 | #include <qwhatsthis.h> |
39 | #include <qlistview.h> | ||
40 | #include <qpushbutton.h> | ||
41 | #include <qtabwidget.h> | ||
42 | #include <qpe/resource.h> | ||
36 | 43 | ||
37 | Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool sb ) | 44 | Configuration::Configuration( QWidget *parent, Cfg &cfg ) |
38 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 45 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
@@ -41,2 +48,43 @@ Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool | |||
41 | 48 | ||
49 | // Setup layout to make everything pretty | ||
50 | QVBoxLayout *layout = new QVBoxLayout( this ); | ||
51 | layout->setMargin( 2 ); | ||
52 | layout->setSpacing( 4 ); | ||
53 | |||
54 | // Setup tabs for all info | ||
55 | _mainWidget = new QTabWidget( this ); | ||
56 | layout->addWidget( _mainWidget ); | ||
57 | |||
58 | // Settings tab | ||
59 | _mainWidget->addTab( initSettings(cfg), tr( "&Settings" ) ); | ||
60 | |||
61 | // Account Types tab | ||
62 | ColumnDef *d; | ||
63 | _listEditTypes=new ListEdit(_mainWidget, "TYPES" ); | ||
64 | d=new ColumnDef( tr("Type"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Account Type")); | ||
65 | _listEditTypes->addColumnDef( d ); | ||
66 | _listEditTypes->addData( cfg.getAccountTypes() ); | ||
67 | _mainWidget->addTab( _listEditTypes, tr( "&Account Types" ) ); | ||
68 | |||
69 | // Categories tab | ||
70 | _listEditCategories=new ListEdit(_mainWidget, "CATEGORIES" ); | ||
71 | _listEditCategories->addColumnDef( new ColumnDef( tr("Category"), (ColumnDef::ColumnType)(ColumnDef::typeString | ColumnDef::typeUnique), tr("New Category")) ); | ||
72 | d=new ColumnDef( tr("Type"), ColumnDef::typeList, tr("Expense") ); | ||
73 | d->addColumnValue( tr("Expense") ); | ||
74 | d->addColumnValue( tr("Income") ); | ||
75 | _listEditCategories->addColumnDef( d ); | ||
76 | QStringList lst=cfg.getCategories(); | ||
77 | _listEditCategories->addData( lst ); | ||
78 | _mainWidget->addTab( _listEditCategories, tr( "&Categories" ) ); | ||
79 | } | ||
80 | |||
81 | Configuration::~Configuration() | ||
82 | { | ||
83 | } | ||
84 | |||
85 | // ---- initSettings ---------------------------------------------------------- | ||
86 | QWidget *Configuration::initSettings(Cfg &cfg) | ||
87 | { | ||
88 | QWidget *control = new QWidget( _mainWidget ); | ||
89 | |||
42 | QFontMetrics fm = fontMetrics(); | 90 | QFontMetrics fm = fontMetrics(); |
@@ -44,3 +92,13 @@ Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool | |||
44 | 92 | ||
45 | QGridLayout *layout = new QGridLayout( this ); | 93 | QVBoxLayout *vb = new QVBoxLayout( control ); |
94 | |||
95 | QScrollView *sv = new QScrollView( control ); | ||
96 | vb->addWidget( sv, 0, 0 ); | ||
97 | sv->setResizePolicy( QScrollView::AutoOneFit ); | ||
98 | sv->setFrameStyle( QFrame::NoFrame ); | ||
99 | |||
100 | QWidget *container = new QWidget( sv->viewport() ); | ||
101 | sv->addChild( container ); | ||
102 | |||
103 | QGridLayout *layout = new QGridLayout( container ); | ||
46 | layout->setSpacing( 4 ); | 104 | layout->setSpacing( 4 ); |
@@ -48,3 +106,3 @@ Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool | |||
48 | 106 | ||
49 | QLabel *label = new QLabel( tr( "Enter currency symbol:" ), this ); | 107 | QLabel *label = new QLabel( tr( "Enter currency symbol:" ), container ); |
50 | QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) ); | 108 | QWhatsThis::add( label, tr( "Enter your local currency symbol here." ) ); |
@@ -53,3 +111,3 @@ Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool | |||
53 | 111 | ||
54 | symbolEdit = new QLineEdit( cs, this ); | 112 | symbolEdit = new QLineEdit( cfg.getCurrencySymbol(), container ); |
55 | QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) ); | 113 | QWhatsThis::add( symbolEdit, tr( "Enter your local currency symbol here." ) ); |
@@ -59,16 +117,45 @@ Configuration::Configuration( QWidget *parent, const QString &cs, bool sl, bool | |||
59 | 117 | ||
60 | lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), this ); | 118 | lockCB = new QCheckBox( tr( "Show whether checkbook is password\nprotected" ), container ); |
61 | QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) ); | 119 | QWhatsThis::add( lockCB, tr( "Click here to select whether or not the main window will display that the checkbook is protected with a password." ) ); |
62 | lockCB->setChecked( sl ); | 120 | lockCB->setChecked( cfg.getShowLocks() ); |
63 | layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 ); | 121 | layout->addMultiCellWidget( lockCB, 1, 1, 0, 1 ); |
64 | 122 | ||
65 | balCB = new QCheckBox( tr( "Show checkbook balances" ), this ); | 123 | balCB = new QCheckBox( tr( "Show checkbook balances" ), container ); |
66 | QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) ); | 124 | QWhatsThis::add( balCB, tr( "Click here to select whether or not the main window will display the current balance for each checkbook." ) ); |
67 | balCB->setMaximumHeight( fh + 5 ); | 125 | balCB->setMaximumHeight( fh + 5 ); |
68 | balCB->setChecked( sb ); | 126 | balCB->setChecked( cfg.getShowBalances() ); |
69 | layout->addMultiCellWidget( balCB, 2, 2, 0, 1 ); | 127 | layout->addMultiCellWidget( balCB, 2, 2, 0, 1 ); |
128 | |||
129 | openLastBookCB = new QCheckBox( tr("Open last checkbook" ), container ); | ||
130 | QWhatsThis::add( openLastBookCB, tr("Click here to select whether the last open checkbook will be opened at startup.") ); | ||
131 | openLastBookCB->setMaximumHeight(fh+5); | ||
132 | openLastBookCB->setChecked( cfg.isOpenLastBook() ); | ||
133 | layout->addMultiCellWidget( openLastBookCB, 3, 3, 0, 1 ); | ||
134 | |||
135 | lastTabCB = new QCheckBox( tr("Show last checkbook tab" ), container ); | ||
136 | QWhatsThis::add( lastTabCB, tr("Click here to select whether the last tab in a checkbook should be displayed.") ); | ||
137 | lastTabCB->setMaximumHeight(fh+5); | ||
138 | lastTabCB->setChecked( cfg.isShowLastTab() ); | ||
139 | layout->addMultiCellWidget( lastTabCB, 4, 4, 0, 1 ); | ||
140 | |||
141 | return(control); | ||
70 | } | 142 | } |
71 | 143 | ||
72 | Configuration::~Configuration() | 144 | // --- saveConfig ------------------------------------------------------------- |
145 | void Configuration::saveConfig(Cfg &cfg) | ||
73 | { | 146 | { |
147 | // Settings | ||
148 | cfg.setCurrencySymbol( symbolEdit->text() ); | ||
149 | cfg.setShowLocks( lockCB->isChecked() ); | ||
150 | cfg.setShowBalances( balCB->isChecked() ); | ||
151 | cfg.setOpenLastBook( openLastBookCB->isChecked() ); | ||
152 | cfg.setShowLastTab( lastTabCB->isChecked() ); | ||
153 | |||
154 | // Typelist | ||
155 | _listEditTypes->storeInList( cfg.getAccountTypes() ); | ||
156 | |||
157 | // Category list | ||
158 | QStringList lst; | ||
159 | _listEditCategories->storeInList( lst ); | ||
160 | cfg.setCategories( lst ); | ||
74 | } | 161 | } |
diff --git a/noncore/apps/checkbook/configuration.h b/noncore/apps/checkbook/configuration.h index 9a8de02..5893502 100644 --- a/noncore/apps/checkbook/configuration.h +++ b/noncore/apps/checkbook/configuration.h | |||
@@ -32,2 +32,3 @@ | |||
32 | #include <qdialog.h> | 32 | #include <qdialog.h> |
33 | #include "cfg.h" | ||
33 | 34 | ||
@@ -36,2 +37,4 @@ class QLineEdit; | |||
36 | class QString; | 37 | class QString; |
38 | class QTabWidget; | ||
39 | class ListEdit; | ||
37 | 40 | ||
@@ -42,3 +45,4 @@ class Configuration : public QDialog | |||
42 | public: | 45 | public: |
43 | Configuration( QWidget * = 0x0, const QString & = "$", bool = FALSE, bool = FALSE ); | 46 | // Constructor |
47 | Configuration( QWidget *, Cfg &cfg); | ||
44 | ~Configuration(); | 48 | ~Configuration(); |
@@ -48,2 +52,14 @@ class Configuration : public QDialog | |||
48 | QCheckBox *balCB; | 52 | QCheckBox *balCB; |
53 | QCheckBox *openLastBookCB; | ||
54 | QCheckBox *lastTabCB; | ||
55 | QTabWidget *_mainWidget; | ||
56 | ListEdit *_listEditTypes; | ||
57 | ListEdit *_listEditCategories; | ||
58 | |||
59 | // saves settings in config struct | ||
60 | void saveConfig(Cfg &cfg); | ||
61 | |||
62 | protected: | ||
63 | // creates settings tap from configuration | ||
64 | QWidget *initSettings(Cfg &cfg); | ||
49 | }; | 65 | }; |
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp new file mode 100644 index 0000000..99a6531 --- a/dev/null +++ b/noncore/apps/checkbook/listedit.cpp | |||
@@ -0,0 +1,340 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "listedit.h" | ||
30 | #include <qlayout.h> | ||
31 | #include <qlineedit.h> | ||
32 | #include <qlistview.h> | ||
33 | #include <qwidgetstack.h> | ||
34 | #include <qcombobox.h> | ||
35 | #include <qpushbutton.h> | ||
36 | #include <qpe/resource.h> | ||
37 | |||
38 | |||
39 | // --- ListEdit --------------------------------------------------------------- | ||
40 | ListEdit::ListEdit( QWidget *parent, const char *sName ) | ||
41 | : QWidget(parent, sName), TableDef(sName) | ||
42 | { | ||
43 | // get font height | ||
44 | int fh = fontMetrics().height(); | ||
45 | |||
46 | // create layout | ||
47 | QGridLayout *layout=new QGridLayout(this); | ||
48 | layout->setSpacing( 2 ); | ||
49 | layout->setMargin( 4 ); | ||
50 | |||
51 | // type table | ||
52 | _typeTable = new QListView( this ); | ||
53 | ColumnDef *def=first(); | ||
54 | while( def ) { | ||
55 | _typeTable->addColumn( def->getName() ); | ||
56 | def=next(); | ||
57 | } | ||
58 | connect( _typeTable, SIGNAL( clicked(QListViewItem *, const QPoint &, int) ), this, SLOT( slotClick(QListViewItem *, const QPoint &, int ) ) ); | ||
59 | layout->addMultiCellWidget(_typeTable, 0,4,0,4); | ||
60 | _currentItem=NULL; | ||
61 | |||
62 | // edit field | ||
63 | _stack=new QWidgetStack( this ); | ||
64 | _stack->setMaximumHeight(fh+5); | ||
65 | layout->addMultiCellWidget(_stack, 5,5,0,2); | ||
66 | _typeEdit = new QLineEdit( _stack ); | ||
67 | _stack->raiseWidget(_typeEdit ); | ||
68 | connect( _typeEdit, SIGNAL( textChanged(const QString &) ), this, SLOT( slotEditChanged(const QString &) ) ); | ||
69 | |||
70 | // combo box | ||
71 | _box=new QComboBox( _stack ); | ||
72 | connect( _box, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) ); | ||
73 | |||
74 | |||
75 | // add button | ||
76 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/add" ), tr( "Add" ), this ); | ||
77 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); | ||
78 | layout->addWidget( btn, 5, 3 ); | ||
79 | |||
80 | // delete button | ||
81 | btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this ); | ||
82 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); | ||
83 | layout->addWidget( btn, 5, 4 ); | ||
84 | } | ||
85 | |||
86 | // --- ~ListEdit -------------------------------------------------------------- | ||
87 | ListEdit::~ListEdit() | ||
88 | { | ||
89 | } | ||
90 | |||
91 | |||
92 | // --- slotEditTypeChanged ---------------------------------------------------- | ||
93 | void ListEdit::slotEditChanged(const QString &str) | ||
94 | { | ||
95 | if( !_currentItem || _currentColumn<0 ) return; | ||
96 | _currentItem->setText(_currentColumn, str); | ||
97 | } | ||
98 | |||
99 | // --- slotAddType ------------------------------------------------------------ | ||
100 | void ListEdit::slotAdd() | ||
101 | { | ||
102 | // construct new row | ||
103 | QString args[8]; | ||
104 | ColumnDef *pCol=this->first(); | ||
105 | int i=0; | ||
106 | while( pCol && i<8 ) { | ||
107 | args[i++]=pCol->getNewValue(); | ||
108 | pCol=this->next(); | ||
109 | } | ||
110 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); | ||
111 | |||
112 | // fix uniques | ||
113 | fixTypes(); | ||
114 | |||
115 | // display col 0 of new value | ||
116 | QPoint pnt; | ||
117 | slotClick(_currentItem, pnt, 0); | ||
118 | _typeTable->setSelected( _currentItem, true ); | ||
119 | } | ||
120 | |||
121 | // --- slotDel ------------------------------------------------------------- | ||
122 | void ListEdit::slotDel() | ||
123 | { | ||
124 | if( !_currentItem ) return; | ||
125 | delete _currentItem; | ||
126 | _currentItem=NULL; | ||
127 | _typeEdit->setText(""); | ||
128 | _stack->raiseWidget(_typeEdit); | ||
129 | } | ||
130 | |||
131 | |||
132 | // --- fixTypes ---------------------------------------------------------------- | ||
133 | // Makes sure all entries have a unique name and empty entries are replaced | ||
134 | // by a generic string. The first version performs the operation on a particular | ||
135 | // column, whereas the 2nd does it for all unique columns. | ||
136 | class ColMap { | ||
137 | public: | ||
138 | ColMap(QString sValue, QListViewItem *pEntry) { | ||
139 | _sValue=sValue; | ||
140 | _pEntry=pEntry; | ||
141 | } | ||
142 | QString &getValue() { return(_sValue); } | ||
143 | QListViewItem *getItem() { return(_pEntry); } | ||
144 | |||
145 | protected: | ||
146 | QString _sValue; | ||
147 | QListViewItem *_pEntry; | ||
148 | }; | ||
149 | |||
150 | class ColList : public QList<QString> | ||
151 | { | ||
152 | public: | ||
153 | ColList() : QList<QString>() { } | ||
154 | |||
155 | protected: | ||
156 | int compareItems(QCollection::Item, QCollection::Item); | ||
157 | }; | ||
158 | |||
159 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { | ||
160 | return( ((QString *)i1)->compare(*(QString *)i2) ); | ||
161 | } | ||
162 | |||
163 | void ListEdit::fixTypes(int iColumn) | ||
164 | { | ||
165 | // get column def | ||
166 | ColumnDef *pDef=this->at(iColumn); | ||
167 | |||
168 | // create map of entries | ||
169 | if( !_typeTable->childCount() ) return; | ||
170 | ColMap **colMap=new (ColMap *)[_typeTable->childCount()]; | ||
171 | QListViewItem *cur=_typeTable->firstChild(); | ||
172 | ColList lst; | ||
173 | for(int i=0; i<_typeTable->childCount(); i++) { | ||
174 | colMap[i]=new ColMap(cur->text(iColumn), cur); | ||
175 | lst.append( &(colMap[i]->getValue()) ); | ||
176 | cur=cur->nextSibling(); | ||
177 | } | ||
178 | |||
179 | // fix empty entries | ||
180 | int i=0; | ||
181 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { | ||
182 | *ptr=ptr->stripWhiteSpace(); | ||
183 | if( ptr->isEmpty() ) { | ||
184 | i++; | ||
185 | if( i==1 ) *ptr=pDef->getNewValue(); | ||
186 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | // fix dups | ||
191 | lst.sort(); | ||
192 | QString repl; | ||
193 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { | ||
194 | QString *current=lst.at(iCur); | ||
195 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { | ||
196 | if( *current!=*lst.at(iNext) ) continue; | ||
197 | for(int i=2; ; i++) { | ||
198 | repl.sprintf("%s %d", (const char *)*current, i); | ||
199 | bool bDup=false; | ||
200 | uint iChk=iNext+1; | ||
201 | while( iChk<lst.count() ) { | ||
202 | QString *chk=lst.at(iChk); | ||
203 | if( !chk->startsWith(*current) ) break; | ||
204 | if( *chk==repl ) { | ||
205 | bDup=true; | ||
206 | break; | ||
207 | } | ||
208 | iChk++; | ||
209 | } | ||
210 | if( !bDup ) { | ||
211 | *lst.at(iNext)=repl; | ||
212 | break; | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | lst.sort(); | ||
218 | |||
219 | // copy back clean up col map | ||
220 | for(int i=0; i<_typeTable->childCount(); i++) { | ||
221 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); | ||
222 | delete colMap[i]; | ||
223 | } | ||
224 | delete colMap; | ||
225 | } | ||
226 | |||
227 | void ListEdit::fixTypes() | ||
228 | { | ||
229 | int i; | ||
230 | ColumnDef *pDef; | ||
231 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | ||
232 | if( pDef->hasFlag(ColumnDef::typeUnique) ) | ||
233 | fixTypes(i); | ||
234 | } | ||
235 | _typeTable->sort(); | ||
236 | } | ||
237 | |||
238 | |||
239 | // --- storeInList ------------------------------------------------------------ | ||
240 | void ListEdit::storeInList(QStringList &lst) | ||
241 | { | ||
242 | // delete old content | ||
243 | lst.clear(); | ||
244 | |||
245 | // add new one | ||
246 | fixTypes(); | ||
247 | QListViewItem *itm=_typeTable->firstChild(); | ||
248 | while( itm ) { | ||
249 | int i=0; | ||
250 | QString sAdd; | ||
251 | ColumnDef *pDef; | ||
252 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | ||
253 | if( i>=1 ) sAdd+=";"; | ||
254 | sAdd += itm->text(i); | ||
255 | } | ||
256 | lst.append( sAdd ); | ||
257 | itm=itm->nextSibling(); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | |||
262 | // --- slotClicked ------------------------------------------------------------ | ||
263 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) | ||
264 | { | ||
265 | (void)pnt; // get rid of unused warning; | ||
266 | |||
267 | // save values | ||
268 | _currentItem=itm; | ||
269 | _currentColumn=col; | ||
270 | if( itm==NULL ) { | ||
271 | _typeEdit->setText(""); | ||
272 | _stack->raiseWidget(_typeEdit); | ||
273 | return; | ||
274 | } | ||
275 | |||
276 | // display value | ||
277 | if( _currentColumn<0 ) _currentColumn=0; | ||
278 | ColumnDef *pDef=this->at(_currentColumn); | ||
279 | if( pDef->isType(ColumnDef::typeString) ) { | ||
280 | _typeEdit->setText( _currentItem->text(_currentColumn) ); | ||
281 | _stack->raiseWidget(_typeEdit); | ||
282 | } else if( pDef->isType(ColumnDef::typeList) ){ | ||
283 | _box->clear(); | ||
284 | _box->insertStringList( pDef->getValueList() ); | ||
285 | QStringList::Iterator itr; | ||
286 | int i=0; | ||
287 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { | ||
288 | if( (*itr)==_currentItem->text(_currentColumn) ) { | ||
289 | _box->setCurrentItem(i); | ||
290 | i=-1; | ||
291 | break; | ||
292 | } | ||
293 | i++; | ||
294 | } | ||
295 | if( i>=0 ) { | ||
296 | _box->insertItem( _currentItem->text(_currentColumn) ); | ||
297 | _box->setCurrentItem(i); | ||
298 | } | ||
299 | _stack->raiseWidget(_box); | ||
300 | } else { | ||
301 | qDebug( "Unsupported column type for column %s", (const char *)pDef->getName() ); | ||
302 | _typeEdit->setText(""); | ||
303 | _stack->raiseWidget(_typeEdit); | ||
304 | } | ||
305 | } | ||
306 | |||
307 | |||
308 | // --- addColumnDef ----------------------------------------------------------- | ||
309 | void ListEdit::addColumnDef(ColumnDef *pDef) | ||
310 | { | ||
311 | _typeTable->addColumn( pDef->getName() ); | ||
312 | _vColumns.append(pDef); | ||
313 | } | ||
314 | |||
315 | // --- addData ---------------------------------------------------------------- | ||
316 | void ListEdit::addData(QStringList &lst) | ||
317 | { | ||
318 | // run through list | ||
319 | QStringList::Iterator itr; | ||
320 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | ||
321 | QStringList split=QStringList::split(";", *itr, true); | ||
322 | QStringList::Iterator entry; | ||
323 | QString args[8]; | ||
324 | int i=0; | ||
325 | for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { | ||
326 | args[i]= (*entry); | ||
327 | } | ||
328 | while(i<8) { | ||
329 | args[i++]=""; | ||
330 | } | ||
331 | new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | // --- slotActivated ---------------------------------------------------------- | ||
336 | void ListEdit::slotActivated(const QString &str) | ||
337 | { | ||
338 | if( _currentItem==NULL || _currentColumn<0 ) return; | ||
339 | _currentItem->setText(_currentColumn, str); | ||
340 | } | ||
diff --git a/noncore/apps/checkbook/listedit.h b/noncore/apps/checkbook/listedit.h new file mode 100644 index 0000000..d2135ea --- a/dev/null +++ b/noncore/apps/checkbook/listedit.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef LISTEDIT_H | ||
30 | #define LISTEDIT_H | ||
31 | |||
32 | #include <qwidget.h> | ||
33 | #include "tabledef.h" | ||
34 | class QListView; | ||
35 | class QLineEdit; | ||
36 | class QListViewItem; | ||
37 | class QPoint; | ||
38 | class QWidgetStack; | ||
39 | class QComboBox; | ||
40 | |||
41 | class ListEdit : public QWidget, public TableDef | ||
42 | { | ||
43 | Q_OBJECT | ||
44 | |||
45 | public: | ||
46 | ListEdit( QWidget *, const char *sName); | ||
47 | virtual ~ListEdit(); | ||
48 | |||
49 | QListView *_typeTable; | ||
50 | QLineEdit *_typeEdit; | ||
51 | QWidgetStack *_stack; | ||
52 | QComboBox *_box; | ||
53 | QListViewItem *_currentItem; | ||
54 | int _currentColumn; | ||
55 | |||
56 | // resolves dups and empty entries | ||
57 | void fixTypes(); | ||
58 | void fixTypes(int iColumn); | ||
59 | |||
60 | // stores content in string list | ||
61 | void storeInList(QStringList &lst); | ||
62 | |||
63 | // adds a column definition | ||
64 | virtual void addColumnDef(ColumnDef *pDef); | ||
65 | |||
66 | // adds data to table | ||
67 | void addData(QStringList &lst); | ||
68 | |||
69 | |||
70 | public slots: | ||
71 | void slotClick(QListViewItem *, const QPoint &pnt, int col); | ||
72 | void slotEditChanged(const QString &); | ||
73 | void slotAdd(); | ||
74 | void slotDel(); | ||
75 | void slotActivated(const QString &); | ||
76 | }; | ||
77 | |||
78 | #endif | ||
diff --git a/noncore/apps/checkbook/main.cpp b/noncore/apps/checkbook/main.cpp index abfa633..dcaab4a 100644 --- a/noncore/apps/checkbook/main.cpp +++ b/noncore/apps/checkbook/main.cpp | |||
@@ -28,15 +28,7 @@ | |||
28 | 28 | ||
29 | #include "mainwindow.h" | ||
30 | |||
31 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <opie/oapplicationfactory.h> | ||
32 | 31 | ||
33 | int main(int argc, char **argv) | 32 | #include "mainwindow.h" |
34 | { | ||
35 | QPEApplication app(argc, argv); | ||
36 | |||
37 | MainWindow *cb = new MainWindow(); | ||
38 | app.setMainWidget(cb); | ||
39 | cb->showMaximized(); | ||
40 | 33 | ||
41 | return app.exec(); | 34 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) |
42 | } | ||
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 6d1d7b9..8d64cad 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp | |||
@@ -33,2 +33,3 @@ | |||
33 | #include "checkbook.h" | 33 | #include "checkbook.h" |
34 | #include "listedit.h" | ||
34 | 35 | ||
@@ -48,4 +49,5 @@ | |||
48 | 49 | ||
49 | MainWindow::MainWindow() | 50 | |
50 | : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) | 51 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) |
52 | : QMainWindow( parent, name, fl || WStyle_ContextHelp ) | ||
51 | { | 53 | { |
@@ -58,6 +60,5 @@ MainWindow::MainWindow() | |||
58 | Config config( "checkbook" ); | 60 | Config config( "checkbook" ); |
59 | config.setGroup( "Config" ); | 61 | qDebug( "Reading config" ); |
60 | currencySymbol = config.readEntry( "CurrencySymbol", "$" ); | 62 | _cfg.readConfig( config ); |
61 | showLocks = config.readBoolEntry( "ShowLocks", FALSE ); | 63 | |
62 | showBalances = config.readBoolEntry( "ShowBalances", FALSE ); | ||
63 | 64 | ||
@@ -127,9 +128,27 @@ MainWindow::MainWindow() | |||
127 | buildList(); | 128 | buildList(); |
129 | |||
130 | // open last book? | ||
131 | if( _cfg.isOpenLastBook() ) { | ||
132 | this->show(); | ||
133 | this->showMaximized(); | ||
134 | QListViewItem *itm=cbList->firstChild(); | ||
135 | while( itm ) { | ||
136 | if( itm->text(posName)==_cfg.getLastBook() ) { | ||
137 | openBook( itm ); | ||
138 | break; | ||
128 | } | 139 | } |
140 | itm=itm->nextSibling(); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
129 | 145 | ||
146 | // --- ~MainWindow ------------------------------------------------------------ | ||
130 | MainWindow::~MainWindow() | 147 | MainWindow::~MainWindow() |
131 | { | 148 | { |
132 | //config.write(); | 149 | writeConfig(); |
133 | } | 150 | } |
134 | 151 | ||
152 | |||
153 | // --- buildList -------------------------------------------------------------- | ||
135 | void MainWindow::buildList() | 154 | void MainWindow::buildList() |
@@ -137,5 +156,3 @@ void MainWindow::buildList() | |||
137 | if ( cbList ) | 156 | if ( cbList ) |
138 | { | ||
139 | delete cbList; | 157 | delete cbList; |
140 | } | ||
141 | 158 | ||
@@ -144,3 +161,3 @@ void MainWindow::buildList() | |||
144 | 161 | ||
145 | if ( showLocks ) | 162 | if ( _cfg.getShowLocks() ) |
146 | { | 163 | { |
@@ -154,3 +171,3 @@ void MainWindow::buildList() | |||
154 | cbList->addColumn( tr( "Checkbook Name" ) ); | 171 | cbList->addColumn( tr( "Checkbook Name" ) ); |
155 | if ( showBalances ) | 172 | if ( _cfg.getShowBalances() ) |
156 | { | 173 | { |
@@ -175,3 +192,3 @@ void MainWindow::addCheckbook( CBInfo *cb ) | |||
175 | QListViewItem *lvi = new QListViewItem( cbList ); | 192 | QListViewItem *lvi = new QListViewItem( cbList ); |
176 | if ( showLocks && !cb->password().isNull() ) | 193 | if ( _cfg.getShowLocks() && !cb->password().isNull() ) |
177 | { | 194 | { |
@@ -180,6 +197,6 @@ void MainWindow::addCheckbook( CBInfo *cb ) | |||
180 | lvi->setText( posName, cb->name() ); | 197 | lvi->setText( posName, cb->name() ); |
181 | if ( showBalances ) | 198 | if ( _cfg.getShowBalances() ) |
182 | { | 199 | { |
183 | QString balance; | 200 | QString balance; |
184 | balance.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); | 201 | balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); |
185 | lvi->setText( posName + 1, balance ); | 202 | lvi->setText( posName + 1, balance ); |
@@ -199,3 +216,3 @@ void MainWindow::slotNew() | |||
199 | 216 | ||
200 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); | 217 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
201 | currcb->showMaximized(); | 218 | currcb->showMaximized(); |
@@ -205,2 +222,3 @@ void MainWindow::slotNew() | |||
205 | buildFilename( cb->name() ); | 222 | buildFilename( cb->name() ); |
223 | _cfg.setLastBook( cb->name() ); | ||
206 | cb->setFilename( tempFilename ); | 224 | cb->setFilename( tempFilename ); |
@@ -215,15 +233,20 @@ void MainWindow::slotNew() | |||
215 | 233 | ||
234 | // --- slotEdit --------------------------------------------------------------- | ||
216 | void MainWindow::slotEdit() | 235 | void MainWindow::slotEdit() |
217 | { | 236 | { |
218 | 237 | // get name and open it | |
219 | QListViewItem *curritem = cbList->currentItem(); | 238 | QListViewItem *curritem = cbList->currentItem(); |
220 | if ( !curritem ) | 239 | if ( !curritem ) |
221 | { | ||
222 | return; | 240 | return; |
241 | openBook( curritem ); | ||
223 | } | 242 | } |
224 | QString currname = curritem->text( posName ); | ||
225 | 243 | ||
226 | CBInfo *cb = checkbooks->first(); | 244 | |
227 | while ( cb ) | 245 | // --- openBook --------------------------------------------------------------- |
246 | void MainWindow::openBook(QListViewItem *curritem) | ||
228 | { | 247 | { |
248 | // find book in List | ||
249 | QString currname=curritem->text(posName); | ||
250 | CBInfo *cb = checkbooks->first(); | ||
251 | while ( cb ) { | ||
229 | if ( cb->name() == currname ) | 252 | if ( cb->name() == currname ) |
@@ -232,7 +255,5 @@ void MainWindow::slotEdit() | |||
232 | } | 255 | } |
233 | if ( !cb ) | 256 | if ( !cb ) return; |
234 | { | ||
235 | return; | ||
236 | } | ||
237 | 257 | ||
258 | // | ||
238 | buildFilename( currname ); | 259 | buildFilename( currname ); |
@@ -252,3 +273,4 @@ void MainWindow::slotEdit() | |||
252 | 273 | ||
253 | Checkbook *currcb = new Checkbook( this, cb, currencySymbol ); | 274 | _cfg.setLastBook( currname ); |
275 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | ||
254 | currcb->showMaximized(); | 276 | currcb->showMaximized(); |
@@ -260,4 +282,7 @@ void MainWindow::slotEdit() | |||
260 | // Update name if changed | 282 | // Update name if changed |
283 | if( curritem ) { | ||
261 | curritem->setText( posName, newname ); | 284 | curritem->setText( posName, newname ); |
262 | cbList->sort(); | 285 | cbList->sort(); |
286 | } | ||
287 | _cfg.setLastBook( newname ); | ||
263 | 288 | ||
@@ -266,5 +291,3 @@ void MainWindow::slotEdit() | |||
266 | if ( f.exists() ) | 291 | if ( f.exists() ) |
267 | { | ||
268 | f.remove(); | 292 | f.remove(); |
269 | } | ||
270 | 293 | ||
@@ -278,3 +301,3 @@ void MainWindow::slotEdit() | |||
278 | // Update lock if changed | 301 | // Update lock if changed |
279 | if ( showLocks && !cb->password().isNull() != currlock ) | 302 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) |
280 | { | 303 | { |
@@ -287,6 +310,6 @@ void MainWindow::slotEdit() | |||
287 | // Update balance if changed | 310 | // Update balance if changed |
288 | if ( showBalances && cb->balance() != currbalance ) | 311 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) |
289 | { | 312 | { |
290 | QString tempstr; | 313 | QString tempstr; |
291 | tempstr.sprintf( "%s%.2f", currencySymbol.latin1(), cb->balance() ); | 314 | tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); |
292 | curritem->setText( posName + 1, tempstr ); | 315 | curritem->setText( posName + 1, tempstr ); |
@@ -297,2 +320,3 @@ void MainWindow::slotEdit() | |||
297 | 320 | ||
321 | // --- slotDelete ------------------------------------------------------------- | ||
298 | void MainWindow::slotDelete() | 322 | void MainWindow::slotDelete() |
@@ -314,5 +338,6 @@ void MainWindow::slotDelete() | |||
314 | 338 | ||
339 | // --- slotConfigure ---------------------------------------------------------- | ||
315 | void MainWindow::slotConfigure() | 340 | void MainWindow::slotConfigure() |
316 | { | 341 | { |
317 | Configuration *cfgdlg = new Configuration( this, currencySymbol, showLocks, showBalances ); | 342 | Configuration *cfgdlg = new Configuration( this, _cfg ); |
318 | cfgdlg->showMaximized(); | 343 | cfgdlg->showMaximized(); |
@@ -320,13 +345,5 @@ void MainWindow::slotConfigure() | |||
320 | { | 345 | { |
321 | currencySymbol = cfgdlg->symbolEdit->text(); | 346 | // read data from config dialog & save it |
322 | showLocks = cfgdlg->lockCB->isChecked(); | 347 | cfgdlg->saveConfig( _cfg ); |
323 | showBalances = cfgdlg->balCB->isChecked(); | 348 | writeConfig(); |
324 | |||
325 | Config config( "checkbook" ); | ||
326 | config.setGroup( "Config" ); | ||
327 | config.writeEntry( "CurrencySymbol", currencySymbol ); | ||
328 | config.writeEntry( "ShowLocks", showLocks ); | ||
329 | config.writeEntry( "ShowBalances", showBalances ); | ||
330 | config.write(); | ||
331 | |||
332 | buildList(); | 349 | buildList(); |
@@ -335 +352,9 @@ void MainWindow::slotConfigure() | |||
335 | } | 352 | } |
353 | |||
354 | |||
355 | // --- writeConfig -------------------------------------------------------------- | ||
356 | void MainWindow::writeConfig() | ||
357 | { | ||
358 | Config config("checkbook"); | ||
359 | _cfg.writeConfig( config ); | ||
360 | } | ||
diff --git a/noncore/apps/checkbook/mainwindow.h b/noncore/apps/checkbook/mainwindow.h index 2bc70b3..6275f94 100644 --- a/noncore/apps/checkbook/mainwindow.h +++ b/noncore/apps/checkbook/mainwindow.h | |||
@@ -33,2 +33,3 @@ | |||
33 | #include <qpixmap.h> | 33 | #include <qpixmap.h> |
34 | #include "cfg.h" | ||
34 | 35 | ||
@@ -39,2 +40,3 @@ class QListView; | |||
39 | class QString; | 40 | class QString; |
41 | class QListViewItem; | ||
40 | 42 | ||
@@ -45,4 +47,11 @@ class MainWindow : public QMainWindow | |||
45 | public: | 47 | public: |
46 | MainWindow(); | 48 | MainWindow(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
47 | ~MainWindow(); | 49 | ~MainWindow(); |
50 | static QString appName() { return QString::fromLatin1("checkbook"); }; | ||
51 | |||
52 | // safe config | ||
53 | void writeConfig(); | ||
54 | |||
55 | // open a check book | ||
56 | void openBook(QListViewItem *curr); | ||
48 | 57 | ||
@@ -54,5 +63,3 @@ class MainWindow : public QMainWindow | |||
54 | 63 | ||
55 | QString currencySymbol; | 64 | Cfg _cfg; |
56 | bool showLocks; | ||
57 | bool showBalances; | ||
58 | int posName; | 65 | int posName; |
diff --git a/noncore/apps/checkbook/tabledef.cpp b/noncore/apps/checkbook/tabledef.cpp new file mode 100644 index 0000000..13edded --- a/dev/null +++ b/noncore/apps/checkbook/tabledef.cpp | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "tabledef.h" | ||
30 | |||
31 | #include <qstring.h> | ||
32 | #include <qpe/resource.h> | ||
33 | |||
34 | // --- ColumnDef -------------------------------------------------------------- | ||
35 | ColumnDef::ColumnDef(const char *sName, ColumnType type, const char *sNewValue) | ||
36 | { | ||
37 | _sName=sName; | ||
38 | _type=type; | ||
39 | _sNewValue=sNewValue; | ||
40 | } | ||
41 | |||
42 | |||
43 | // --- addColumnValue --------------------------------------------------------- | ||
44 | void ColumnDef::addColumnValue(const QString &sValue) | ||
45 | { | ||
46 | if( (_type & 0x00ffffff) !=typeList ) | ||
47 | qDebug("Column %s is not a list", (const char *)_sName); | ||
48 | else | ||
49 | _valueList.append(sValue); | ||
50 | } | ||
51 | void ColumnDef::addColumnValue(const char *sValue) | ||
52 | { | ||
53 | if( (_type & 0x00ffffff)!=typeList ) | ||
54 | qDebug("Column %s is not a list", (const char *)_sName); | ||
55 | else | ||
56 | _valueList.append(sValue); | ||
57 | } | ||
58 | |||
59 | // --- TableDef --------------------------------------------------------------- | ||
60 | TableDef::TableDef(const char *sName) | ||
61 | { | ||
62 | _sName=sName; | ||
63 | _vColumns.setAutoDelete(TRUE); | ||
64 | } | ||
65 | |||
66 | |||
67 | // --- ~TableDef -------------------------------------------------------------- | ||
68 | TableDef::~TableDef() | ||
69 | { | ||
70 | } | ||
71 | |||
72 | // --- addColumnDef ----------------------------------------------------------- | ||
73 | void TableDef::addColumnDef(ColumnDef *pDef) | ||
74 | { | ||
75 | _vColumns.append(pDef); | ||
76 | } | ||
diff --git a/noncore/apps/checkbook/tabledef.h b/noncore/apps/checkbook/tabledef.h new file mode 100644 index 0000000..5891ad7 --- a/dev/null +++ b/noncore/apps/checkbook/tabledef.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #ifndef TABLEDEF_H | ||
30 | #define TABLEDEF_H | ||
31 | |||
32 | #include <qstring.h> | ||
33 | #include <qstringlist.h> | ||
34 | #include <qlist.h> | ||
35 | |||
36 | |||
37 | |||
38 | // --- ColumnDef ------------------------------------------------------------- | ||
39 | class ColumnDef | ||
40 | { | ||
41 | public: | ||
42 | enum ColumnType { | ||
43 | typeString=0x1, | ||
44 | typeList=0x2, | ||
45 | typeUnique=0x80000000 | ||
46 | }; | ||
47 | |||
48 | // Constructor | ||
49 | ColumnDef(const char *sName, ColumnType type, const char *sNewValue); | ||
50 | |||
51 | // add column value | ||
52 | void addColumnValue(const QString &Value); | ||
53 | void addColumnValue(const char *sValue); | ||
54 | |||
55 | // member functions | ||
56 | const QString getName() { return(_sName); } | ||
57 | const QString getNewValue() { return(_sNewValue); } | ||
58 | |||
59 | // test for type | ||
60 | int isType(ColumnType x) { return( (_type & 0x00ffffff)==x ); } | ||
61 | int hasFlag(ColumnType x) { return( (_type & x) ); } | ||
62 | |||
63 | // get value list | ||
64 | QStringList &getValueList() { return(_valueList); } | ||
65 | |||
66 | private: | ||
67 | QString _sName; | ||
68 | QString _sNewValue; | ||
69 | enum ColumnType _type; | ||
70 | QStringList _valueList; | ||
71 | }; | ||
72 | |||
73 | typedef QList<ColumnDef> ColumnDefList; | ||
74 | |||
75 | |||
76 | // --- TableDef --------------------------------------------------------------- | ||
77 | class TableDef | ||
78 | { | ||
79 | public: | ||
80 | // Constructor & Destructor | ||
81 | TableDef(const char *sName); | ||
82 | virtual ~TableDef(); | ||
83 | |||
84 | // adds a column definition | ||
85 | virtual void addColumnDef(ColumnDef *pDef); | ||
86 | |||
87 | // movement operators | ||
88 | ColumnDef *first() { return(_vColumns.first() ); } | ||
89 | ColumnDef *last() { return(_vColumns.last() ); } | ||
90 | ColumnDef *next() { return(_vColumns.next() ); } | ||
91 | ColumnDef *prev() { return(_vColumns.prev() ); } | ||
92 | ColumnDef *at(int i) { return(_vColumns.at(i)); } | ||
93 | |||
94 | protected: | ||
95 | QString _sName; | ||
96 | ColumnDefList _vColumns; | ||
97 | }; | ||
98 | |||
99 | #endif | ||
diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp index 65c190c..d880bb4 100644 --- a/noncore/apps/checkbook/traninfo.cpp +++ b/noncore/apps/checkbook/traninfo.cpp | |||
@@ -36,3 +36,3 @@ TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdra | |||
36 | const QString &type, const QString &category, float amount, | 36 | const QString &type, const QString &category, float amount, |
37 | float fee, const QString &number, const QString ¬es ) | 37 | float fee, const QString &number, const QString ¬es, int next ) |
38 | { | 38 | { |
@@ -48,2 +48,3 @@ TranInfo::TranInfo( int id, const QString &desc, const QDate &date, bool withdra | |||
48 | n = notes; | 48 | n = notes; |
49 | _next=next; | ||
49 | } | 50 | } |
@@ -118,2 +119,5 @@ TranInfo::TranInfo( Config config, int entry ) | |||
118 | n = config.readEntry( "Comments", "" ); | 119 | n = config.readEntry( "Comments", "" ); |
120 | |||
121 | // next | ||
122 | _next = config.readNumEntry("Next", -1); | ||
119 | } | 123 | } |
@@ -121,14 +125,15 @@ TranInfo::TranInfo( Config config, int entry ) | |||
121 | 125 | ||
126 | // --- datestr ---------------------------------------------------------------- | ||
122 | const QString &TranInfo::datestr() | 127 | const QString &TranInfo::datestr() |
123 | { | 128 | { |
124 | tempstr = QString::number( td.year() ); | 129 | int y=td.year(); |
125 | tempstr.append( '/' ); | 130 | y= y>=2000 && y<=2099 ? y-2000 : y; |
126 | int tempfield = td.month(); | 131 | tempstr.sprintf( "%02d/%02d/%02d", y ,td.month(), td.day() ); |
127 | if ( tempfield < 10 ) tempstr.append( '0' ); | 132 | return( tempstr ); |
128 | tempstr.append( QString::number( tempfield ) ); | 133 | } |
129 | tempstr.append( '/' ); | ||
130 | tempfield = td.day(); | ||
131 | if ( tempfield < 10 ) tempstr.append( '0' ); | ||
132 | tempstr.append( QString::number( tempfield ) ); | ||
133 | 134 | ||
135 | // --- getIdStr --------------------------------------------------------------- | ||
136 | const QString &TranInfo::getIdStr() | ||
137 | { | ||
138 | tempstr.sprintf("%04d", i); | ||
134 | return( tempstr ); | 139 | return( tempstr ); |
@@ -136,5 +141,6 @@ const QString &TranInfo::datestr() | |||
136 | 141 | ||
137 | void TranInfo::write( Config *config, int entry ) | 142 | // --- write ------------------------------------------------------------------ |
143 | void TranInfo::write( Config *config ) | ||
138 | { | 144 | { |
139 | config->setGroup( QString::number( entry ) ); | 145 | config->setGroup( QString::number( id() ) ); |
140 | 146 | ||
@@ -172,6 +178,7 @@ void TranInfo::write( Config *config, int entry ) | |||
172 | config->writeEntry( "CheckNumber", cn ); | 178 | config->writeEntry( "CheckNumber", cn ); |
173 | |||
174 | config->writeEntry( "Comments", n ); | 179 | config->writeEntry( "Comments", n ); |
180 | config->writeEntry( "Next", _next ); | ||
175 | } | 181 | } |
176 | 182 | ||
183 | |||
177 | int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) | 184 | int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) |
@@ -190 +197,16 @@ int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 | |||
190 | } | 197 | } |
198 | |||
199 | // --- toString --------------------------------------------------------------- | ||
200 | QString TranInfo::toString() | ||
201 | { | ||
202 | QString ret; | ||
203 | ret.sprintf("(%4d) %10s %4s %-10s %5.2f %5.2f", | ||
204 | id(), | ||
205 | (const char *)datestr(), | ||
206 | (const char *)number(), | ||
207 | (const char *)desc(), | ||
208 | (withdrawal() ? -1 : 1) * amount(), | ||
209 | fee() | ||
210 | ); | ||
211 | return(ret); | ||
212 | } | ||
diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h index f6c5cae..0abdc61 100644 --- a/noncore/apps/checkbook/traninfo.h +++ b/noncore/apps/checkbook/traninfo.h | |||
@@ -42,6 +42,9 @@ class TranInfo | |||
42 | float = 0.0, float = 0.0, | 42 | float = 0.0, float = 0.0, |
43 | const QString & = 0x0, const QString & = 0x0 ); | 43 | const QString & = 0x0, const QString & = 0x0, int =-1 ); |
44 | TranInfo( Config, int ); | 44 | TranInfo( Config, int ); |
45 | 45 | ||
46 | // getters | ||
46 | int id() const { return i; } | 47 | int id() const { return i; } |
48 | const QString &getIdStr(); | ||
49 | |||
47 | const QString &desc() const { return d; } | 50 | const QString &desc() const { return d; } |
@@ -56,3 +59,5 @@ class TranInfo | |||
56 | const QString ¬es() const { return n; } | 59 | const QString ¬es() const { return n; } |
60 | int getNext() { return(_next); } | ||
57 | 61 | ||
62 | // setters | ||
58 | void setDesc( const QString &desc ) { d = desc; } | 63 | void setDesc( const QString &desc ) { d = desc; } |
@@ -66,4 +71,9 @@ class TranInfo | |||
66 | void setNotes( const QString ¬es ) { n = notes; } | 71 | void setNotes( const QString ¬es ) { n = notes; } |
72 | void setNext(int next) { _next=next; } | ||
73 | |||
74 | // write | ||
75 | void write( Config * ); | ||
67 | 76 | ||
68 | void write( Config *, int ); | 77 | // toString |
78 | QString toString(); | ||
69 | 79 | ||
@@ -80,2 +90,3 @@ class TranInfo | |||
80 | QString n; | 90 | QString n; |
91 | int _next; | ||
81 | }; | 92 | }; |
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp index c94b989..138d0e6 100644 --- a/noncore/apps/checkbook/transaction.cpp +++ b/noncore/apps/checkbook/transaction.cpp | |||
@@ -30,2 +30,3 @@ | |||
30 | #include "traninfo.h" | 30 | #include "traninfo.h" |
31 | #include "cfg.h" | ||
31 | 32 | ||
@@ -43,3 +44,3 @@ | |||
43 | Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, | 44 | Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, |
44 | const QString &symbol ) | 45 | Cfg *pCfg ) |
45 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) | 46 | : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) |
@@ -51,3 +52,3 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
51 | tran = info; | 52 | tran = info; |
52 | currencySymbol = symbol; | 53 | _pCfg=pCfg; |
53 | 54 | ||
@@ -232,17 +233,9 @@ void Transaction::slotWithdrawalClicked() | |||
232 | catList->clear(); | 233 | catList->clear(); |
233 | catList->insertItem( tr( "Automobile" ) ); | 234 | CategoryList *pCatList=_pCfg->getCategoryList(); |
234 | catList->insertItem( tr( "Bills" ) ); | 235 | for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) { |
235 | catList->insertItem( tr( "CDs" ) ); | 236 | if( !pCat->isIncome() ) |
236 | catList->insertItem( tr( "Clothing" ) ); | 237 | catList->insertItem( pCat->getName() ); |
237 | catList->insertItem( tr( "Computer" ) ); | 238 | } |
238 | catList->insertItem( tr( "DVDs" ) ); | ||
239 | catList->insertItem( tr( "Electronics" ) ); | ||
240 | catList->insertItem( tr( "Entertainment" ) ); | ||
241 | catList->insertItem( tr( "Food" ) ); | ||
242 | catList->insertItem( tr( "Gasoline" ) ); | ||
243 | catList->insertItem( tr( "Misc" ) ); | ||
244 | catList->insertItem( tr( "Movies" ) ); | ||
245 | catList->insertItem( tr( "Rent" ) ); | ||
246 | catList->insertItem( tr( "Travel" ) ); | ||
247 | catList->setCurrentItem( 0 ); | 239 | catList->setCurrentItem( 0 ); |
240 | |||
248 | typeList->clear(); | 241 | typeList->clear(); |
@@ -257,6 +250,9 @@ void Transaction::slotDepositClicked() | |||
257 | catList->clear(); | 250 | catList->clear(); |
258 | catList->insertItem( tr( "Work" ) ); | 251 | CategoryList *pCatList=_pCfg->getCategoryList(); |
259 | catList->insertItem( tr( "Family Member" ) ); | 252 | for(Category *pCat=pCatList->first(); pCat; pCat=pCatList->next()) { |
260 | catList->insertItem( tr( "Misc. Credit" ) ); | 253 | if( pCat->isIncome() ) |
254 | catList->insertItem( pCat->getName() ); | ||
255 | } | ||
261 | catList->setCurrentItem( 0 ); | 256 | catList->setCurrentItem( 0 ); |
257 | |||
262 | typeList->clear(); | 258 | typeList->clear(); |
diff --git a/noncore/apps/checkbook/transaction.h b/noncore/apps/checkbook/transaction.h index 000aee7..fbe9cd3 100644 --- a/noncore/apps/checkbook/transaction.h +++ b/noncore/apps/checkbook/transaction.h | |||
@@ -42,2 +42,3 @@ class QWidget; | |||
42 | class TranInfo; | 42 | class TranInfo; |
43 | class Cfg; | ||
43 | 44 | ||
@@ -48,4 +49,3 @@ class Transaction : public QDialog | |||
48 | public: | 49 | public: |
49 | Transaction( QWidget * = 0x0, const QString & = 0x0, TranInfo * = 0x0, | 50 | Transaction( QWidget *, const QString &, TranInfo *, Cfg *); |
50 | const QString & = "$" ); | ||
51 | ~Transaction(); | 51 | ~Transaction(); |
@@ -55,3 +55,3 @@ class Transaction : public QDialog | |||
55 | 55 | ||
56 | QString currencySymbol; | 56 | Cfg *_pCfg; |
57 | 57 | ||