summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/cfg.cpp
authormickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
committer mickeyl <mickeyl>2003-10-27 19:51:32 (UTC)
commit951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (unidiff)
tree46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/cfg.cpp
parentf0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff)
downloadopie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip
opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz
opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2
merge noncore/apps/* except
- advancedfm (ljp, please...) - odict (tille, please...)
Diffstat (limited to 'noncore/apps/checkbook/cfg.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/cfg.cpp213
1 files changed, 213 insertions, 0 deletions
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 --------------------------------------------------------------------
40Cfg::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.
53void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
54{
55qDebug( "%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"
77void 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
140void 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
157void 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 ----------------------------------------------------------
183QStringList 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 ----------------------------------------------------------
196void 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 ------------------------------------------------------------
210CategoryList::CategoryList() : QList<Category>()
211{
212 setAutoDelete(true);
213}