00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030
00031 #include <qwidget.h>
00032 #include <qpe/config.h>
00033
00034 #include "cfg.h"
00035
00036
00037 Cfg::Cfg()
00038 {
00039 _currencySymbol="$";
00040 _useSmallFont=TRUE;
00041 _showLocks=FALSE;
00042 _showBalances=FALSE;
00043 _pCategories=new CategoryList();
00044 _bDirty=false;
00045 }
00046
00047
00048
00049
00050
00051
00052 void Cfg::readStringList(Config &cfg, const char *sKey, QStringList &lst)
00053 {
00054 QString sEntry;
00055 int iCount;
00056
00057
00058 sEntry.sprintf("%s_Count", sKey);
00059 iCount=cfg.readNumEntry(sEntry, 0);
00060
00061
00062 for(int i=1; i<=iCount; i++) {
00063 sEntry.sprintf("%s%d", sKey, i);
00064 QString sType=cfg.readEntry(sEntry);
00065 if( sType!=NULL )
00066 lst.append(sType);
00067 }
00068 }
00069
00070
00071
00072
00073
00074 void Cfg::readConfig(Config &config)
00075 {
00076
00077 config.setGroup( "Config" );
00078
00079
00080 _currencySymbol = config.readEntry( "CurrencySymbol", "$" );
00081 _useSmallFont = config.readBoolEntry( "UseSmallFont", TRUE );
00082 _showLocks = config.readBoolEntry( "ShowLocks", FALSE );
00083 _showBalances = config.readBoolEntry( "ShowBalances", FALSE );
00084 _openLastBook = config.readBoolEntry( "OpenLastBook", FALSE );
00085 _sLastBook = config.readEntry("LastBook", "");
00086 _showLastTab = config.readBoolEntry( "ShowLastTab", FALSE );
00087 _bSavePayees = config.readBoolEntry( "SavePayees", FALSE );
00088
00089
00090 readStringList(config, "AccType", _AccountTypes);
00091 if( _AccountTypes.isEmpty() ) {
00092 _AccountTypes+= (const char *)QWidget::tr("Savings");
00093 _AccountTypes+= (const char *)QWidget::tr("Checking");
00094 _AccountTypes+= (const char *)QWidget::tr("CD");
00095 _AccountTypes+= (const char *)QWidget::tr("Money market");
00096 _AccountTypes+= (const char *)QWidget::tr("Mutual fund");
00097 _AccountTypes+= (const char *)QWidget::tr("Other");
00098 writeStringList(config, "AccType", _AccountTypes);
00099 config.write();
00100 }
00101
00102
00103 readStringList(config, "Payee", _Payees);
00104
00105
00106 QStringList lst;
00107 readStringList(config, "Category", lst);
00108 if( lst.isEmpty() ) {
00109 QString type=QWidget::tr("Expense");
00110 lst += QWidget::tr( "Automobile" )+";"+type;
00111 lst += QWidget::tr( "Bills" )+";"+type;
00112 lst += QWidget::tr( "CDs" )+";"+type;
00113 lst += QWidget::tr( "Clothing" )+";"+type;
00114 lst += QWidget::tr( "Computer" )+";"+type;
00115 lst += QWidget::tr( "DVDs" )+";"+type;
00116 lst += QWidget::tr( "Electronics" )+";"+type;
00117 lst += QWidget::tr( "Entertainment" )+";"+type;
00118 lst += QWidget::tr( "Food" )+";"+type;
00119 lst += QWidget::tr( "Gasoline" )+";"+type;
00120 lst += QWidget::tr( "Misc" )+";"+type;
00121 lst += QWidget::tr( "Movies" )+";"+type;
00122 lst += QWidget::tr( "Rent" )+";"+type;
00123 lst += QWidget::tr( "Travel" )+";"+type;
00124
00125 type=QWidget::tr( "Income" );
00126 lst += QWidget::tr( "Work" )+";"+type;
00127 lst += QWidget::tr( "Family Member" )+";"+type;
00128 lst += QWidget::tr( "Misc. Credit" )+";"+type;
00129
00130 setCategories(lst);
00131 writeStringList(config, "Category", lst);
00132 config.write();
00133 } else {
00134 setCategories(lst);
00135 }
00136
00137
00138 _bDirty=false;
00139 }
00140
00141
00142
00143
00144
00145 void Cfg::writeStringList(Config &cfg, const char *sKey, QStringList &lst)
00146 {
00147 QString sEntry;
00148 int iCount=0;
00149 QStringList::Iterator itr;
00150 for(itr=lst.begin(); itr!=lst.end(); itr++) {
00151 sEntry.sprintf("%s%d", sKey, ++iCount);
00152 cfg.writeEntry(sEntry, *itr );
00153 }
00154 sEntry.sprintf("%s_Count", sKey);
00155 cfg.writeEntry(sEntry, iCount);
00156 }
00157
00158
00159
00160
00161
00162 void Cfg::writeConfig(Config &config)
00163 {
00164
00165 config.setGroup( "Config" );
00166
00167
00168 config.writeEntry( "CurrencySymbol", _currencySymbol );
00169 config.writeEntry( "UseSmallFont", _useSmallFont );
00170 config.writeEntry( "ShowLocks", _showLocks );
00171 config.writeEntry( "ShowBalances", _showBalances );
00172 config.writeEntry( "OpenLastBook", _openLastBook );
00173 config.writeEntry( "LastBook", _sLastBook );
00174 config.writeEntry( "ShowLastTab", _showLastTab );
00175 config.writeEntry( "SavePayees", _bSavePayees );
00176
00177
00178 writeStringList(config, "AccType", _AccountTypes);
00179
00180
00181 writeStringList(config, "Payee", _Payees);
00182
00183
00184 QStringList lst=getCategories();
00185 writeStringList(config, "Category", lst );
00186
00187
00188 config.write();
00189 _bDirty=false;
00190 }
00191
00192
00193
00194 QStringList Cfg::getCategories()
00195 {
00196 QStringList ret;
00197 for(Category *itr=_pCategories->first(); itr; itr=_pCategories->next() ) {
00198 QString sEntry;
00199 sEntry.sprintf("%s;%s", (const char *)itr->getName(), (const char *)(itr->isIncome() ? QWidget::tr("Income") : QWidget::tr("Expense")) );
00200 ret.append(sEntry);
00201 }
00202 return(ret);
00203 }
00204
00205
00206
00207 void Cfg::setCategories(QStringList &lst)
00208 {
00209 _pCategories->clear();
00210 QStringList::Iterator itr;
00211 for(itr=lst.begin(); itr!=lst.end(); itr++) {
00212 QStringList split=QStringList::split(";", *itr, true);
00213 if( split.count()<2 ) continue;
00214 bool bIncome= (split[1]==QWidget::tr("Income"));
00215 _pCategories->append( new Category(split[0], bIncome) );
00216 }
00217 }
00218
00219
00220
00221 CategoryList::CategoryList() : QList<Category>()
00222 {
00223 setAutoDelete(true);
00224 }