kpilot Library API Documentation

kpilotConfig.cc

00001 /* kpilotConfig.cc                      KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is all of KPilot's config-handling stuff.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
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 // This is a number indicating what configuration version
00063 // we're dealing with. Whenever new configuration options are
00064 // added that make it imperative for the user to take a
00065 // look at the configuration of KPilot (for example the
00066 // skipDB setting really needs user attention) we can change
00067 // (increase) this number.
00068 //
00069 //
00070 /* static */ const int KPilotConfig::ConfigurationVersion = 403;
00071 
00072 /* static */ int KPilotConfig::getConfigVersion(KConfig * config)
00073 {
00074         FUNCTIONSETUP;
00075 
00076         if (!config)
00077                 return 0;
00078         else
00079                 return getConfigVersion(*config);
00080         /* NOTREACHED */
00081         (void) kpilotconfig_id;
00082 }
00083 
00084 /* static */ 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 /* static */ void KPilotConfig::updateConfigVersion()
00108 {
00109         FUNCTIONSETUP;
00110 
00111         KPilotConfigSettings & config = getConfig();
00112         config.setVersion(ConfigurationVersion);
00113 }
00114 
00115 /* static */ 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 /* static */ int KPilotConfig::getDebugLevel(KPilotConfigSettings &)
00127 {
00128         return 0;
00129 }
00130 
00131 /* static */ int KPilotConfig::getDebugLevel(bool)
00132 {
00133         return 0;
00134 }
00135 #else
00136 /* static */ 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 /* static */ 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 /* static */ 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 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:43 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001