summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/cfg.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/cfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cfg.cpp15
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
@@ -34,35 +34,34 @@
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 --------------------------------------------------------------------
40Cfg::Cfg() 40Cfg::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.
53void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst) 54void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
54{ 55{
55qDebug( "%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 )
@@ -77,38 +76,42 @@ qDebug( "%s", sKey );
77void Cfg::readConfig(Config &config) 76void 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;
@@ -122,24 +125,27 @@ void Cfg::readConfig(Config &config)
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
140void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst) 146void 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++) {
@@ -157,34 +163,39 @@ void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst)
157void Cfg::writeConfig(Config &config) 163void 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 ----------------------------------------------------------
183QStringList Cfg::getCategories() 194QStringList 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 }