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 "options.h"
00030
00031 #include <stdlib.h>
00032
00033 #include <qlineedit.h>
00034 #include <qcombobox.h>
00035 #include <qcheckbox.h>
00036
00037 #ifndef _KLOCALE_H
00038 #include <klocale.h>
00039 #endif
00040 #ifndef _KGLOBAL_H
00041 #include <kglobal.h>
00042 #endif
00043 #ifndef _KSTDDIRS_H
00044 #include <kstddirs.h>
00045 #endif
00046 #ifndef _KCONFIG_H
00047 #include <kconfig.h>
00048 #endif
00049 #include <ksimpleconfig.h>
00050
00051 #ifdef DEBUG
00052 #include <kcmdlineargs.h>
00053 #endif
00054
00055 #ifndef _KPILOT_KPILOTCONFIG_H
00056 #include "kpilotConfig.h"
00057 #endif
00058
00059 static const char *kpilotconfig_id =
00060 "$Id: kpilotConfig.cc,v 1.12.6.6 2003/03/20 21:08:27 adridg Exp $";
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 const int KPilotConfig::ConfigurationVersion = 403;
00071
00072 int KPilotConfig::getConfigVersion(KConfig * config)
00073 {
00074 FUNCTIONSETUP;
00075
00076 if (!config)
00077 return 0;
00078 else
00079 return getConfigVersion(*config);
00080
00081 (void) kpilotconfig_id;
00082 }
00083
00084 int KPilotConfig::getConfigVersion(KConfig & config)
00085 {
00086 FUNCTIONSETUP;
00087
00088 config.setGroup(QString::null);
00089 int version = config.readNumEntry("Configured", 0);
00090
00091 if (version < ConfigurationVersion)
00092 {
00093 kdWarning() << k_funcinfo <<
00094 ": Config file has old version " << version << endl;
00095 }
00096 else
00097 {
00098 #ifdef DEBUG
00099 DEBUGDB << fname
00100 << ": Config file has version " << version << endl;
00101 #endif
00102 }
00103
00104 return version;
00105 }
00106
00107 void KPilotConfig::updateConfigVersion()
00108 {
00109 FUNCTIONSETUP;
00110
00111 KPilotConfigSettings & config = getConfig();
00112 config.setVersion(ConfigurationVersion);
00113 }
00114
00115 QString KPilotConfig::getDefaultDBPath()
00116 {
00117 FUNCTIONSETUP;
00118 QString lastUser = getConfig().getUser();
00119 QString dbsubpath = CSL1("kpilot/DBBackup/");
00120 QString defaultDBPath = KGlobal::dirs()->
00121 saveLocation("data", dbsubpath + lastUser + CSL1("/"));
00122 return defaultDBPath;
00123 }
00124
00125 #ifndef DEBUG
00126 int KPilotConfig::getDebugLevel(KPilotConfigSettings &)
00127 {
00128 return 0;
00129 }
00130
00131 int KPilotConfig::getDebugLevel(bool)
00132 {
00133 return 0;
00134 }
00135 #else
00136 int KPilotConfig::getDebugLevel(KPilotConfigSettings & c)
00137 {
00138 FUNCTIONSETUP;
00139
00140 int d = c.getDebug();
00141
00142 debug_level |= d;
00143
00144 if (debug_level)
00145 {
00146 DEBUGKPILOT << fname
00147 << ": Debug level set to " << debug_level << endl;
00148 }
00149
00150 return debug_level;
00151 }
00152
00153 int KPilotConfig::getDebugLevel(bool useDebugId)
00154 {
00155 FUNCTIONSETUP;
00156
00157 KCmdLineArgs *p = KCmdLineArgs::parsedArgs(useDebugId ? "debug" : 0L);
00158
00159 if (p)
00160 {
00161 if (p->isSet("debug"))
00162 {
00163 debug_level = atoi(p->getOption("debug"));
00164 }
00165 }
00166
00167 getDebugLevel(getConfig());
00168
00169 return debug_level;
00170 }
00171 #endif
00172
00173 static KPilotConfigSettings *theconfig = 0L;
00174
00175 KPilotConfigSettings & KPilotConfig::getConfig()
00176 {
00177 FUNCTIONSETUP;
00178
00179 if (theconfig)
00180 {
00181 return *theconfig;
00182 }
00183
00190 QString existingConfig =
00191 KGlobal::dirs()->findResource("config", CSL1("kpilotrc"));
00192
00193
00194 if (existingConfig.isNull())
00195 {
00196 #ifdef DEBUG
00197 DEBUGDB << fname << ": Making a new config file" << endl;
00198 #endif
00199 KSimpleConfig *c = new KSimpleConfig(CSL1("kpilotrc"), false);
00200
00201 c->writeEntry("Configured", ConfigurationVersion);
00202 c->writeEntry("NextUniqueID", 61440);
00203 c->sync();
00204 delete c;
00205
00206 theconfig = new KPilotConfigSettings(CSL1("kpilotrc"));
00207 }
00208 else
00209 {
00210 #ifdef DEBUG
00211 DEBUGDB << fname
00212 << ": Re-using existing config file "
00213 << existingConfig << endl;
00214 #endif
00215
00216 theconfig = new KPilotConfigSettings(existingConfig);
00217 }
00218
00219 if (theconfig == 0L)
00220 {
00221 kdWarning() << k_funcinfo
00222 << ": No configuration was found." << endl;
00223 }
00224
00225 return *theconfig;
00226 }
00227
00228 static QFont *thefont = 0L;
00229
00230 const QFont & KPilotConfig::fixed()
00231 {
00232 FUNCTIONSETUP;
00233
00234 if (thefont)
00235 {
00236 return *thefont;
00237 }
00238
00239 KConfig KDEGlobalConfig(QString::null);
00240
00241 KDEGlobalConfig.setGroup("General");
00242 QString s = KDEGlobalConfig.readEntry("fixed");
00243
00244 #ifdef DEBUG
00245 DEBUGKPILOT << fname << ": Creating font " << s << endl;
00246 #endif
00247
00248 thefont = new QFont(KDEGlobalConfig.readFontEntry("fixed"));
00249
00250 if (!thefont)
00251 {
00252 kdError() << k_funcinfo
00253 << ": **\n"
00254 << ": ** No font was created! (Expect crash now)\n"
00255 << ": **" << endl;
00256 }
00257
00258 return *thefont;
00259 }
00260
00261 KPilotConfigSettings::KPilotConfigSettings(const QString & f, bool b) :
00262 KSimpleConfig(f, b)
00263 {
00264 FUNCTIONSETUP;
00265 }
00266
00267 KPilotConfigSettings::~KPilotConfigSettings()
00268 {
00269 FUNCTIONSETUP;
00270 }
00271
00272
00273
00274 #define IntProperty_(a,key,defl,m) \
00275 int KPilotConfigSettings::get##a(QComboBox *p) const { \
00276 int i = readNumEntry(key,defl); \
00277 if ((i<0) || (i>m)) i=0; \
00278 if (p) p->setCurrentItem(i); \
00279 return i; } \
00280 void KPilotConfigSettings::set##a(QComboBox *p) { \
00281 set##a(p->currentItem()); } \
00282 void KPilotConfigSettings::set##a(int i) { \
00283 if ((i<0) || (i>m)) i=0; writeEntry(key,i); }
00284
00285 IntProperty_(PilotType, "PilotType", 0, 3)
00286 IntProperty_(PilotSpeed, "PilotSpeed", 0, 4)
00287 IntProperty_(AddressDisplayMode, "AddressDisplay", 0, 1)
00288 IntProperty_(Version, "Configured", 0, 100000)
00289 IntProperty_(Debug, "Debug", 0, 1023)
00290
00291 #define BoolProperty_(a,key,defl) \
00292 bool KPilotConfigSettings::get##a(QCheckBox *p) const { \
00293 bool b = readBoolEntry(key,defl); if (p) p->setChecked(b); return b; } \
00294 void KPilotConfigSettings::set##a(QCheckBox *p) { \
00295 set##a(p->isChecked()); } \
00296 void KPilotConfigSettings::set##a(bool b) { \
00297 writeEntry(key,b); }
00298 BoolProperty_(DockDaemon, "DockDaemon", true)
00299
00300 BoolProperty_(KillDaemonOnExit, "StopDaemonAtExit", false)
00301 BoolProperty_(StartDaemonAtLogin, "StartDaemonAtLogin", true)
00302 BoolProperty_(ShowSecrets, "ShowSecrets", false)
00303 BoolProperty_(SyncFiles, "SyncFiles", true)
00304 BoolProperty_(SyncWithKMail, "SyncWithKMail", false)
00305 BoolProperty_(UseKeyField, "UseKeyField", false)
00306
00307
00308 #define StringProperty_(a,key,defl) \
00309 QString KPilotConfigSettings::get##a(QLineEdit *p) const { \
00310 QString s = readEntry(key,defl); if (p) p->setText(s); return s; } \
00311 void KPilotConfigSettings::set##a(QLineEdit *p) { \
00312 set##a(p->text()); } \
00313 void KPilotConfigSettings::set##a(const QString &s) { \
00314 writeEntry(key,s); }
00315
00316
00317 StringProperty_(PilotDevice, "PilotDevice", CSL1("/dev/pilot"))
00318 StringProperty_(Encoding, "Encoding", QString::null)
00319 IntProperty_(EncodingDD,"EncodingDD",0,7)
00320
00321 StringProperty_(User, "UserName", QString::null)
00322 StringProperty_(BackupOnly, "BackupForSync", CSL1("Arng,PmDB,lnch"))
00323 StringProperty_(Skip, "SkipSync", CSL1("AvGo"))
00324
00325
00326 KPilotConfigSettings & KPilotConfigSettings::setAddressGroup()
00327 {
00328 FUNCTIONSETUP;
00329 setGroup("Address Widget");
00330 return *this;
00331 }
00332
00333 KPilotConfigSettings & KPilotConfigSettings::setConduitGroup()
00334 {
00335 FUNCTIONSETUP;
00336 setGroup("Conduit Names");
00337 return *this;
00338 }
00339
00340 KPilotConfigSettings & KPilotConfigSettings::setDatabaseGroup()
00341 {
00342 FUNCTIONSETUP;
00343 setGroup("Database Names");
00344 return *this;
00345 }
00346
00347 QStringList KPilotConfigSettings::getInstalledConduits()
00348 {
00349 FUNCTIONSETUP;
00350 KConfigGroupSaver cgs(this,"Conduit Names");
00351 return readListEntry("InstalledConduits");
00352 }
00353
00354 void KPilotConfigSettings::setInstalledConduits(const QStringList & l)
00355 {
00356 FUNCTIONSETUP;
00357 KConfigGroupSaver cgs(this,"Conduit Names");
00358 writeEntry("InstalledConduits", l);
00359 }
00360
00361 void KPilotConfigSettings::setDatabaseConduit(const QString & database,
00362 const QString & conduit)
00363 {
00364 FUNCTIONSETUP;
00365 setDatabaseGroup();
00366 writeEntry(database, conduit);
00367 }
00368
00369