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 #include <kstddirs.h>
00038 #include <kconfig.h>
00039 #include <ksimpleconfig.h>
00040 #include <kcmdlineargs.h>
00041 #include <kmessagebox.h>
00042 #include <kglobalsettings.h>
00043
00044 #include "kpilotConfig.h"
00045
00046 static const char kpilotconfig_id[] =
00047 "$Id: kpilotConfig.cc,v 1.28 2003/07/27 20:35:19 mueller Exp $";
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 const int KPilotConfig::ConfigurationVersion = 440;
00058
00059 int KPilotConfig::getConfigVersion(KConfig * config)
00060 {
00061 FUNCTIONSETUP;
00062
00063 if (!config)
00064 return 0;
00065 else
00066 return getConfigVersion(*config);
00067
00068 (void) kpilotconfig_id;
00069 }
00070
00071 int KPilotConfig::getConfigVersion(KConfig & config)
00072 {
00073 FUNCTIONSETUP;
00074
00075 config.setGroup(QString::null);
00076 int version = config.readNumEntry("Configured", 0);
00077
00078 if (version < ConfigurationVersion)
00079 {
00080 kdWarning() << k_funcinfo <<
00081 ": Config file has old version " << version << endl;
00082 }
00083 else
00084 {
00085 #ifdef DEBUG
00086 DEBUGDB << fname
00087 << ": Config file has version " << version << endl;
00088 #endif
00089 }
00090
00091 return version;
00092 }
00093
00094 void KPilotConfig::updateConfigVersion()
00095 {
00096 FUNCTIONSETUP;
00097
00098 KPilotConfigSettings & config = getConfig();
00099 config.setVersion(ConfigurationVersion);
00100 }
00101
00102 QString KPilotConfig::getDefaultDBPath()
00103 {
00104 FUNCTIONSETUP;
00105 QString lastUser = getConfig().getUser();
00106 QString dbsubpath = CSL1("kpilot/DBBackup/");
00107 QString defaultDBPath = KGlobal::dirs()->
00108 saveLocation("data", dbsubpath + lastUser + CSL1("/"));
00109 return defaultDBPath;
00110 }
00111
00112 int KPilotConfig::getDebugLevel(KCmdLineArgs *p)
00113 {
00114 FUNCTIONSETUP;
00115
00116 if (p)
00117 {
00118 if (p->isSet("debug"))
00119 {
00120 debug_level = p->getOption("debug").toInt();
00121 }
00122 }
00123
00124 return debug_level;
00125 }
00126
00127 static KPilotConfigSettings *theconfig = 0L;
00128
00129 KPilotConfigSettings & KPilotConfig::getConfig()
00130 {
00131 FUNCTIONSETUP;
00132
00133 if (theconfig)
00134 {
00135 return *theconfig;
00136 }
00137
00144 QString existingConfig =
00145 KGlobal::dirs()->findResource("config", CSL1("kpilotrc"));
00146
00147
00148 if (existingConfig.isNull())
00149 {
00150 #ifdef DEBUG
00151 DEBUGDB << fname << ": Making a new config file" << endl;
00152 #endif
00153 KSimpleConfig *c = new KSimpleConfig(CSL1("kpilotrc"), false);
00154
00155 c->writeEntry("Configured", ConfigurationVersion);
00156 c->writeEntry("NextUniqueID", 61440);
00157 c->sync();
00158 delete c;
00159
00160 theconfig = new KPilotConfigSettings(CSL1("kpilotrc"));
00161 }
00162 else
00163 {
00164 #ifdef DEBUG
00165 DEBUGDB << fname
00166 << ": Re-using existing config file "
00167 << existingConfig << endl;
00168 #endif
00169
00170 theconfig = new KPilotConfigSettings(existingConfig);
00171 }
00172
00173 if (theconfig == 0L)
00174 {
00175 kdWarning() << k_funcinfo
00176 << ": No configuration was found." << endl;
00177 }
00178
00179 return *theconfig;
00180 }
00181
00182 static QFont *thefont = 0L;
00183
00184 const QFont & KPilotConfig::fixed()
00185 {
00186 FUNCTIONSETUP;
00187
00188 if (!thefont)
00189 thefont = new QFont(KGlobalSettings::fixedFont());
00190
00191 return *thefont;
00192 }
00193
00194 KPilotConfigSettings::KPilotConfigSettings(const QString & f, bool b) :
00195 KSimpleConfig(f, b)
00196 {
00197 FUNCTIONSETUP;
00198 }
00199
00200 KPilotConfigSettings::~KPilotConfigSettings()
00201 {
00202 FUNCTIONSETUP;
00203 }
00204
00205 #define IntProperty_(a,key,defl,m) \
00206 int KPilotConfigSettings::get##a() const { \
00207 int i = readNumEntry(key,defl); \
00208 if ((i<0) || (i>m)) i=0; \
00209 return i; } \
00210 void KPilotConfigSettings::set##a(int i) { \
00211 if ((i<0) || (i>m)) i=0; writeEntry(key,i); }
00212
00213 IntProperty_(PilotSpeed, "PilotSpeed", 0, 4)
00214 IntProperty_(SyncType, "SyncType", 0, 4)
00215 IntProperty_(ConflictResolution, "ConflictResolution", 0,5)
00216 IntProperty_(AddressDisplayMode, "AddressDisplay", 0, 1)
00217 IntProperty_(Version, "Configured", 0, 100000)
00218 IntProperty_(Debug, "Debug", 0, 1023)
00219
00220 #define BoolProperty_(a,key,defl) \
00221 bool KPilotConfigSettings::get##a() const { \
00222 bool b = readBoolEntry(key,defl); return b; } \
00223 void KPilotConfigSettings::set##a(bool b) { \
00224 writeEntry(key,b); }
00225
00226 BoolProperty_(StartDaemonAtLogin, "StartDaemonAtLogin", true)
00227 BoolProperty_(DockDaemon, "DockDaemon", true)
00228 BoolProperty_(KillDaemonOnExit, "StopDaemonAtExit", false)
00229 BoolProperty_(QuitAfterSync, "QuitAfterSync", false)
00230 BoolProperty_(FullSyncOnPCChange, "FullSyncOnPCChange", true)
00231
00232
00233 BoolProperty_(ShowSecrets, "ShowSecrets", false)
00234 BoolProperty_(UseKeyField, "UseKeyField", false)
00235 BoolProperty_(InternalEditors, "InternalEditorsWritable", true)
00236
00237
00238 #define StringProperty_(a,key,defl) \
00239 QString KPilotConfigSettings::get##a() const { \
00240 QString s = readEntry(key,defl); return s; } \
00241 void KPilotConfigSettings::set##a(const QString &s) { \
00242 writeEntry(key,s); }
00243
00244
00245 StringProperty_(PilotDevice, "PilotDevice", CSL1("/dev/pilot"))
00246 StringProperty_(Encoding, "Encoding", QString::null)
00247
00248 StringProperty_(User, "UserName", QString::null)
00249 StringProperty_(BackupOnly, "BackupForSync", CSL1("Arng,PmDB,lnch"))
00250 StringProperty_(Skip, "SkipSync", CSL1("AvGo"))
00251
00252
00253 KPilotConfigSettings & KPilotConfigSettings::setAddressGroup()
00254 {
00255 FUNCTIONSETUP;
00256 setGroup("Address Widget");
00257 return *this;
00258 }
00259
00260 KPilotConfigSettings & KPilotConfigSettings::setConduitGroup()
00261 {
00262 FUNCTIONSETUP;
00263 setGroup("Conduit Names");
00264 return *this;
00265 }
00266
00267 KPilotConfigSettings & KPilotConfigSettings::setDatabaseGroup()
00268 {
00269 FUNCTIONSETUP;
00270 setGroup("Database Names");
00271 return *this;
00272 }
00273
00274 QStringList KPilotConfigSettings::getInstalledConduits()
00275 {
00276 FUNCTIONSETUP;
00277 KConfigGroupSaver cgs(this,"Conduit Names");
00278 return readListEntry("InstalledConduits");
00279 }
00280
00281 void KPilotConfigSettings::setInstalledConduits(const QStringList & l)
00282 {
00283 FUNCTIONSETUP;
00284 KConfigGroupSaver cgs(this,"Conduit Names");
00285 writeEntry("InstalledConduits", l);
00286 }
00287
00288 QStringList KPilotConfigSettings::getDirtyDatabases()
00289 {
00290 FUNCTIONSETUP;
00291 KConfigGroupSaver cgs(this,"Internal Editors");
00292 return readListEntry("Changed Databases");
00293 }
00294
00295 void KPilotConfigSettings::setDirtyDatabases(const QStringList &l)
00296 {
00297 FUNCTIONSETUP;
00298 KConfigGroupSaver cgs(this,"Internal Editors");
00299 writeEntry("Changed Databases", l);
00300 }
00301
00302 void KPilotConfigSettings::addDirtyDatabase(QString db)
00303 {
00304 FUNCTIONSETUP;
00305 QStringList l(getDirtyDatabases());
00306 if (!l.contains(db))
00307 {
00308 l.append(db);
00309 setDirtyDatabases(l);
00310 }
00311 }
00312
00313
00314 QStringList KPilotConfigSettings::getAppBlockChangedDatabases()
00315 {
00316 FUNCTIONSETUP;
00317 KConfigGroupSaver cgs(this,"Internal Editors");
00318 return readListEntry("AppBlock Changed");
00319 }
00320
00321 void KPilotConfigSettings::setAppBlockChangedDatabases(const QStringList &l)
00322 {
00323 FUNCTIONSETUP;
00324 KConfigGroupSaver cgs(this,"Internal Editors");
00325 writeEntry("AppBlock Changed", l);
00326 }
00327
00328 void KPilotConfigSettings::addAppBlockChangedDatabase(QString db)
00329 {
00330 QStringList l(getAppBlockChangedDatabases());
00331 if (!l.contains(db))
00332 {
00333 l.append(db);
00334 setAppBlockChangedDatabases(l);
00335 }
00336 }
00337
00338
00339 QStringList KPilotConfigSettings::getFlagsChangedDatabases()
00340 {
00341 FUNCTIONSETUP;
00342 KConfigGroupSaver cgs(this,"Internal Editors");
00343 return readListEntry("Flags Changed");
00344 }
00345
00346 void KPilotConfigSettings::setFlagsChangedDatabases(const QStringList &l)
00347 {
00348 FUNCTIONSETUP;
00349 KConfigGroupSaver cgs(this,"Internal Editors");
00350 writeEntry("Flags Changed", l);
00351 }
00352
00353 void KPilotConfigSettings::addFlagsChangedDatabase(QString db)
00354 {
00355 QStringList l(getFlagsChangedDatabases());
00356 if (!l.contains(db))
00357 {
00358 l.append(db);
00359 setFlagsChangedDatabases(l);
00360 }
00361 }
00362
00363
00364 void KPilotConfigSettings::setDatabaseConduit(const QString & database,
00365 const QString & conduit)
00366 {
00367 FUNCTIONSETUP;
00368 setDatabaseGroup();
00369 writeEntry(database, conduit);
00370 }
00371
00372
00373 QString KPilotConfig::versionDetails(int fileversion, bool run)
00374 {
00375 FUNCTIONSETUP;
00376 QString s = CSL1("<qt><p>");
00377 s = i18n("The configuration file is outdated.");
00378 s += ' ';
00379 s += i18n("The configuration file has version %1, while KPilot "
00380 "needs version %2.").arg(fileversion).arg(ConfigurationVersion);
00381 if (run)
00382 {
00383 s += ' ';
00384 s += i18n("Please run KPilot and check the configuration carefully "
00385 "to update the file.");
00386 }
00387 s += CSL1("</p><p>");
00388 s += i18n("Important changes to watch for are:");
00389 s += ' ';
00390 if (fileversion < 440)
00391 {
00392 s += i18n("Renamed conduits, Kroupware and file installer have "
00393 "been made conduits as well.");
00394 s += ' ';
00395 s += i18n("Conflict resolution is now a global setting.");
00396 }
00397
00398
00399
00400 return s;
00401 }
00402
00403 void KPilotConfig::sorryVersionOutdated(int fileversion)
00404 {
00405 FUNCTIONSETUP;
00406 KMessageBox::detailedSorry(0L,
00407 i18n("The configuration file for KPilot is out-of "
00408 "date. Please run KPilot to update it."),
00409 KPilotConfig::versionDetails(fileversion,true),
00410 i18n("Configuration File Out-of Date"));
00411 }
00412
00413
00414 void KPilotConfig::interactiveUpdate()
00415 {
00416 FUNCTIONSETUP;
00417 KPilotConfigSettings &c = KPilotConfig::getConfig();
00418 int fileversion = c.getVersion();
00419 int res = 0;
00420
00421 res = KMessageBox::warningContinueCancel(0L,
00422 i18n("The configuration file for KPilot is out-of "
00423 "date. KPilot can update some parts of the "
00424 "configuration automatically. Do you wish to "
00425 "continue?"),
00426 i18n("Configuration File Out-of Date"));
00427 if (res!=KMessageBox::Continue) return;
00428
00429
00430 {
00431 QStringList conduits( c.getInstalledConduits() );
00432 c.resetGroup();
00433 bool useKroupware = c.readBoolEntry("SyncWithKMail",false);
00434 bool installFiles = c.readBoolEntry("SyncFiles",true);
00435 if (useKroupware) conduits.append( CSL1("internal_kroupware") );
00436 if (installFiles) conduits.append( CSL1("internal_fileinstall") );
00437 c.deleteEntry("SyncWithKMail");
00438 c.deleteEntry("SyncFiles");
00439 c.setInstalledConduits(conduits);
00440 c.sync();
00441 if (useKroupware || installFiles)
00442 KMessageBox::information(0L,
00443 i18n("The settings for Kroupware syncing with KMail "
00444 "and the file installer have been moved to the "
00445 "conduits configuration. Check the installed "
00446 "conduits list."),
00447 i18n("Settings Updated"));
00448
00449 }
00450
00451
00452
00453
00454 {
00455 QStringList foundlibs ;
00456 static const char *oldconduits[] = { "null", "address", "doc",
00457 "knotes", "sysinfo", "time", "todo", "vcal", 0L } ;
00458 const char **s = oldconduits;
00459 while (*s)
00460 {
00461 QString libname = CSL1("kde3/lib%1conduit.so").arg(*s);
00462 QString foundlib = ::locate("lib",libname);
00463 if (!foundlib.isEmpty())
00464 {
00465 foundlibs.append(foundlib);
00466 }
00467 s++;
00468 }
00469
00470 if (!foundlibs.isEmpty())
00471 KMessageBox::informationList(0L,
00472 i18n("<qt>The following old conduits were found on "
00473 "your system. It is a good idea to remove "
00474 "them and the associated <tt>.la</tt> "
00475 "and <tt>.so.0</tt> files.</qt>"),
00476 foundlibs,
00477 i18n("Old Conduits Found"));
00478 }
00479
00480 KPilotConfig::updateConfigVersion();
00481 c.sync();
00482 }