Diffstat (limited to 'noncore/apps/checkbook/cfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/cfg.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/noncore/apps/checkbook/cfg.cpp b/noncore/apps/checkbook/cfg.cpp index 1e0ec5c..0d5d9ed 100644 --- a/noncore/apps/checkbook/cfg.cpp +++ b/noncore/apps/checkbook/cfg.cpp | |||
@@ -22,181 +22,192 @@ | |||
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | 30 | ||
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
33 | #include <qwidget.h> | 33 | #include <qwidget.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | 36 | ||
37 | #include "cfg.h" | 37 | #include "cfg.h" |
38 | 38 | ||
39 | // --- Cfg -------------------------------------------------------------------- | 39 | // --- Cfg -------------------------------------------------------------------- |
40 | Cfg::Cfg() | 40 | Cfg::Cfg() |
41 | { | 41 | { |
42 | _currencySymbol="$"; | 42 | _currencySymbol="$"; |
43 | _showLocks=FALSE; | 43 | _showLocks=FALSE; |
44 | _showBalances=FALSE; | 44 | _showBalances=FALSE; |
45 | _pCategories=new CategoryList(); | 45 | _pCategories=new CategoryList(); |
46 | _bDirty=false; | ||
46 | } | 47 | } |
47 | 48 | ||
48 | // --- readStringList --------------------------------------------------------- | 49 | // --- readStringList --------------------------------------------------------- |
49 | // Reads the entries for the control from a configuration file and returns | 50 | // 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 | // 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 | // is assumed, that the group is already set. Key is used to enumerate the |
52 | // entries. | 53 | // entries. |
53 | void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) | 54 | void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) |
54 | { | 55 | { |
55 | qDebug( "%s", sKey ); | ||
56 | |||
57 | QString sEntry; | 56 | QString sEntry; |
58 | int iCount; | 57 | int iCount; |
59 | 58 | ||
60 | // read count of elements | 59 | // read count of elements |
61 | sEntry.sprintf("%s_Count", sKey); | 60 | sEntry.sprintf("%s_Count", sKey); |
62 | iCount=cfg.readNumEntry(sEntry, 0); | 61 | iCount=cfg.readNumEntry(sEntry, 0); |
63 | 62 | ||
64 | // read entries | 63 | // read entries |
65 | for(int i=1; i<=iCount; i++) { | 64 | for(int i=1; i<=iCount; i++) { |
66 | sEntry.sprintf("%s%d", sKey, i); | 65 | sEntry.sprintf("%s%d", sKey, i); |
67 | QString sType=cfg.readEntry(sEntry); | 66 | QString sType=cfg.readEntry(sEntry); |
68 | if( sType!=NULL ) | 67 | if( sType!=NULL ) |
69 | lst.append(sType); | 68 | lst.append(sType); |
70 | } | 69 | } |
71 | } | 70 | } |
72 | 71 | ||
73 | 72 | ||
74 | // --- readConfig ------------------------------------------------------------- | 73 | // --- readConfig ------------------------------------------------------------- |
75 | // Reads the member data from the given config file. It will also set the group | 74 | // Reads the member data from the given config file. It will also set the group |
76 | // "Config" | 75 | // "Config" |
77 | void Cfg::readConfig(Config &config) | 76 | void Cfg::readConfig(Config &config) |
78 | { | 77 | { |
79 | // set group | 78 | // set group |
80 | config.setGroup( "Config" ); | 79 | config.setGroup( "Config" ); |
81 | 80 | ||
82 | // read scalars | 81 | // read scalars |
83 | _currencySymbol = config.readEntry( "CurrencySymbol", "$" ); | 82 | _currencySymbol = config.readEntry( "CurrencySymbol", "$" ); |
84 | _showLocks = config.readBoolEntry( "ShowLocks", FALSE ); | 83 | _showLocks = config.readBoolEntry( "ShowLocks", FALSE ); |
85 | _showBalances = config.readBoolEntry( "ShowBalances", FALSE ); | 84 | _showBalances = config.readBoolEntry( "ShowBalances", FALSE ); |
86 | _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE ); | 85 | _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE ); |
87 | _sLastBook = config.readEntry("LastBook", ""); | 86 | _sLastBook = config.readEntry("LastBook", ""); |
88 | _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE ); | 87 | _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE ); |
88 | _bSavePayees = config.readBoolEntry( "SavePayees", FALSE ); | ||
89 | 89 | ||
90 | // Account types | 90 | // Account types |
91 | readStringList(config, "AccType", _AccountTypes); | 91 | readStringList(config, "AccType", _AccountTypes); |
92 | if( _AccountTypes.isEmpty() ) { | 92 | if( _AccountTypes.isEmpty() ) { |
93 | _AccountTypes+= (const char *)QWidget::tr("Savings"); | 93 | _AccountTypes+= (const char *)QWidget::tr("Savings"); |
94 | _AccountTypes+= (const char *)QWidget::tr("Checking"); | 94 | _AccountTypes+= (const char *)QWidget::tr("Checking"); |
95 | _AccountTypes+= (const char *)QWidget::tr("CD"); | 95 | _AccountTypes+= (const char *)QWidget::tr("CD"); |
96 | _AccountTypes+= (const char *)QWidget::tr("Money market"); | 96 | _AccountTypes+= (const char *)QWidget::tr("Money market"); |
97 | _AccountTypes+= (const char *)QWidget::tr("Mutual fund"); | 97 | _AccountTypes+= (const char *)QWidget::tr("Mutual fund"); |
98 | _AccountTypes+= (const char *)QWidget::tr("Other"); | 98 | _AccountTypes+= (const char *)QWidget::tr("Other"); |
99 | writeStringList(config, "AccType", _AccountTypes); | 99 | writeStringList(config, "AccType", _AccountTypes); |
100 | config.write(); | 100 | config.write(); |
101 | } | 101 | } |
102 | 102 | ||
103 | // Payees | ||
104 | readStringList(config, "Payee", _Payees); | ||
105 | |||
103 | // Read Categories | 106 | // Read Categories |
104 | QStringList lst; | 107 | QStringList lst; |
105 | readStringList(config, "Category", lst); | 108 | readStringList(config, "Category", lst); |
106 | if( lst.isEmpty() ) { | 109 | if( lst.isEmpty() ) { |
107 | QString type=QWidget::tr("Expense"); | 110 | QString type=QWidget::tr("Expense"); |
108 | lst += QWidget::tr( "Automobile" )+";"+type; | 111 | lst += QWidget::tr( "Automobile" )+";"+type; |
109 | lst += QWidget::tr( "Bills" )+";"+type; | 112 | lst += QWidget::tr( "Bills" )+";"+type; |
110 | lst += QWidget::tr( "CDs" )+";"+type; | 113 | lst += QWidget::tr( "CDs" )+";"+type; |
111 | lst += QWidget::tr( "Clothing" )+";"+type; | 114 | lst += QWidget::tr( "Clothing" )+";"+type; |
112 | lst += QWidget::tr( "Computer" )+";"+type; | 115 | lst += QWidget::tr( "Computer" )+";"+type; |
113 | lst += QWidget::tr( "DVDs" )+";"+type; | 116 | lst += QWidget::tr( "DVDs" )+";"+type; |
114 | lst += QWidget::tr( "Electronics" )+";"+type; | 117 | lst += QWidget::tr( "Electronics" )+";"+type; |
115 | lst += QWidget::tr( "Entertainment" )+";"+type; | 118 | lst += QWidget::tr( "Entertainment" )+";"+type; |
116 | lst += QWidget::tr( "Food" )+";"+type; | 119 | lst += QWidget::tr( "Food" )+";"+type; |
117 | lst += QWidget::tr( "Gasoline" )+";"+type; | 120 | lst += QWidget::tr( "Gasoline" )+";"+type; |
118 | lst += QWidget::tr( "Misc" )+";"+type; | 121 | lst += QWidget::tr( "Misc" )+";"+type; |
119 | lst += QWidget::tr( "Movies" )+";"+type; | 122 | lst += QWidget::tr( "Movies" )+";"+type; |
120 | lst += QWidget::tr( "Rent" )+";"+type; | 123 | lst += QWidget::tr( "Rent" )+";"+type; |
121 | lst += QWidget::tr( "Travel" )+";"+type; | 124 | lst += QWidget::tr( "Travel" )+";"+type; |
122 | 125 | ||
123 | type=QWidget::tr( "Income" ); | 126 | type=QWidget::tr( "Income" ); |
124 | lst += QWidget::tr( "Work" )+";"+type; | 127 | lst += QWidget::tr( "Work" )+";"+type; |
125 | lst += QWidget::tr( "Family Member" )+";"+type; | 128 | lst += QWidget::tr( "Family Member" )+";"+type; |
126 | lst += QWidget::tr( "Misc. Credit" )+";"+type; | 129 | lst += QWidget::tr( "Misc. Credit" )+";"+type; |
127 | 130 | ||
128 | setCategories(lst); | 131 | setCategories(lst); |
129 | writeStringList(config, "Category", lst); | 132 | writeStringList(config, "Category", lst); |
130 | config.write(); | 133 | config.write(); |
131 | } else { | 134 | } else { |
132 | setCategories(lst); | 135 | setCategories(lst); |
133 | } | 136 | } |
137 | |||
138 | // not dirty | ||
139 | _bDirty=false; | ||
134 | } | 140 | } |
135 | 141 | ||
136 | 142 | ||
137 | // --- writeStringList -------------------------------------------------------- | 143 | // --- writeStringList -------------------------------------------------------- |
138 | // Writes the entries in the control in a configuration file. It is assumed, | 144 | // 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 | 145 | // that the group is already set. Key is used to enumerate the entries |
140 | void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) | 146 | void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) |
141 | { | 147 | { |
142 | QString sEntry; | 148 | QString sEntry; |
143 | int iCount=0; | 149 | int iCount=0; |
144 | QStringList::Iterator itr; | 150 | QStringList::Iterator itr; |
145 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | 151 | for(itr=lst.begin(); itr!=lst.end(); itr++) { |
146 | sEntry.sprintf("%s%d", sKey, ++iCount); | 152 | sEntry.sprintf("%s%d", sKey, ++iCount); |
147 | cfg.writeEntry(sEntry, *itr ); | 153 | cfg.writeEntry(sEntry, *itr ); |
148 | } | 154 | } |
149 | sEntry.sprintf("%s_Count", sKey); | 155 | sEntry.sprintf("%s_Count", sKey); |
150 | cfg.writeEntry(sEntry, iCount); | 156 | cfg.writeEntry(sEntry, iCount); |
151 | } | 157 | } |
152 | 158 | ||
153 | 159 | ||
154 | // --- writeConfig ----------------------------------------------------------- | 160 | // --- writeConfig ----------------------------------------------------------- |
155 | // Writes all config data back to the config file. The group will be set to | 161 | // Writes all config data back to the config file. The group will be set to |
156 | // "Config" and the write be commited | 162 | // "Config" and the write be commited |
157 | void Cfg::writeConfig(Config &config) | 163 | void Cfg::writeConfig(Config &config) |
158 | { | 164 | { |
159 | // set the group | 165 | // set the group |
160 | config.setGroup( "Config" ); | 166 | config.setGroup( "Config" ); |
161 | 167 | ||
162 | // write scalars | 168 | // write scalars |
163 | config.writeEntry( "CurrencySymbol", _currencySymbol ); | 169 | config.writeEntry( "CurrencySymbol", _currencySymbol ); |
164 | config.writeEntry( "ShowLocks", _showLocks ); | 170 | config.writeEntry( "ShowLocks", _showLocks ); |
165 | config.writeEntry( "ShowBalances", _showBalances ); | 171 | config.writeEntry( "ShowBalances", _showBalances ); |
166 | config.writeEntry( "OpenLastBook", _openLastBook ); | 172 | config.writeEntry( "OpenLastBook", _openLastBook ); |
167 | config.writeEntry( "LastBook", _sLastBook ); | 173 | config.writeEntry( "LastBook", _sLastBook ); |
168 | config.writeEntry( "ShowLastTab", _showLastTab ); | 174 | config.writeEntry( "ShowLastTab", _showLastTab ); |
175 | config.writeEntry( "SavePayees", _bSavePayees ); | ||
169 | 176 | ||
170 | // write account types | 177 | // write account types |
171 | writeStringList(config, "AccType", _AccountTypes); | 178 | writeStringList(config, "AccType", _AccountTypes); |
172 | 179 | ||
180 | // write payees | ||
181 | writeStringList(config, "Payee", _Payees); | ||
182 | |||
173 | // write categories | 183 | // write categories |
174 | QStringList lst=getCategories(); | 184 | QStringList lst=getCategories(); |
175 | writeStringList(config, "Category", lst ); | 185 | writeStringList(config, "Category", lst ); |
176 | 186 | ||
177 | // commit write | 187 | // commit write |
178 | config.write(); | 188 | config.write(); |
189 | _bDirty=false; | ||
179 | } | 190 | } |
180 | 191 | ||
181 | 192 | ||
182 | // --- getCategories ---------------------------------------------------------- | 193 | // --- getCategories ---------------------------------------------------------- |
183 | QStringList Cfg::getCategories() | 194 | QStringList Cfg::getCategories() |
184 | { | 195 | { |
185 | QStringList ret; | 196 | QStringList ret; |
186 | for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) { | 197 | for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) { |
187 | QString sEntry; | 198 | QString sEntry; |
188 | sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) ); | 199 | sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) ); |
189 | ret.append(sEntry); | 200 | ret.append(sEntry); |
190 | } | 201 | } |
191 | return(ret); | 202 | return(ret); |
192 | } | 203 | } |
193 | 204 | ||
194 | 205 | ||
195 | // --- setCategories ---------------------------------------------------------- | 206 | // --- setCategories ---------------------------------------------------------- |
196 | void Cfg::setCategories(QStringList &lst) | 207 | void Cfg::setCategories(QStringList &lst) |
197 | { | 208 | { |
198 | _pCategories->clear(); | 209 | _pCategories->clear(); |
199 | QStringList::Iterator itr; | 210 | QStringList::Iterator itr; |
200 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | 211 | for(itr=lst.begin(); itr!=lst.end(); itr++) { |
201 | QStringList split=QStringList::split(";", *itr, true); | 212 | QStringList split=QStringList::split(";", *itr, true); |
202 | if( split.count()<2 ) continue; | 213 | if( split.count()<2 ) continue; |