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.4.1 2004/03/26 22:47:02 adridg 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 QStringList KPilotConfigSettings::getNoBackupDatabases()
00314 {
00315 FUNCTIONSETUP;
00316 KConfigGroupSaver cgs(this,"");
00317 return readListEntry("BackupForSync");
00318 }
00319
00320
00321 QStringList KPilotConfigSettings::getAppBlockChangedDatabases()
00322 {
00323 FUNCTIONSETUP;
00324 KConfigGroupSaver cgs(this,"Internal Editors");
00325 return readListEntry("AppBlock Changed");
00326 }
00327
00328 void KPilotConfigSettings::setAppBlockChangedDatabases(const QStringList &l)
00329 {
00330 FUNCTIONSETUP;
00331 KConfigGroupSaver cgs(this,"Internal Editors");
00332 writeEntry("AppBlock Changed", l);
00333 }
00334
00335 void KPilotConfigSettings::addAppBlockChangedDatabase(QString db)
00336 {
00337 QStringList l(getAppBlockChangedDatabases());
00338 if (!l.contains(db))
00339 {
00340 l.append(db);
00341 setAppBlockChangedDatabases(l);
00342 }
00343 }
00344
00345
00346 QStringList KPilotConfigSettings::getFlagsChangedDatabases()
00347 {
00348 FUNCTIONSETUP;
00349 KConfigGroupSaver cgs(this,"Internal Editors");
00350 return readListEntry("Flags Changed");
00351 }
00352
00353 void KPilotConfigSettings::setFlagsChangedDatabases(const QStringList &l)
00354 {
00355 FUNCTIONSETUP;
00356 KConfigGroupSaver cgs(this,"Internal Editors");
00357 writeEntry("Flags Changed", l);
00358 }
00359
00360 void KPilotConfigSettings::addFlagsChangedDatabase(QString db)
00361 {
00362 QStringList l(getFlagsChangedDatabases());
00363 if (!l.contains(db))
00364 {
00365 l.append(db);
00366 setFlagsChangedDatabases(l);
00367 }
00368 }
00369
00370
00371 void KPilotConfigSettings::setDatabaseConduit(const QString & database,
00372 const QString & conduit)
00373 {
00374 FUNCTIONSETUP;
00375 setDatabaseGroup();
00376 writeEntry(database, conduit);
00377 }
00378
00379
00380 QString KPilotConfig::versionDetails(int fileversion, bool run)
00381 {
00382 FUNCTIONSETUP;
00383 QString s = CSL1("<qt><p>");
00384 s = i18n("The configuration file is outdated.");
00385 s += ' ';
00386 s += i18n("The configuration file has version %1, while KPilot "
00387 "needs version %2.").arg(fileversion).arg(ConfigurationVersion);
00388 if (run)
00389 {
00390 s += ' ';
00391 s += i18n("Please run KPilot and check the configuration carefully "
00392 "to update the file.");
00393 }
00394 s += CSL1("</p><p>");
00395 s += i18n("Important changes to watch for are:");
00396 s += ' ';
00397 if (fileversion < 440)
00398 {
00399 s += i18n("Renamed conduits, Kroupware and file installer have "
00400 "been made conduits as well.");
00401 s += ' ';
00402 s += i18n("Conflict resolution is now a global setting.");
00403 }
00404
00405
00406
00407 return s;
00408 }
00409
00410 void KPilotConfig::sorryVersionOutdated(int fileversion)
00411 {
00412 FUNCTIONSETUP;
00413 KMessageBox::detailedSorry(0L,
00414 i18n("The configuration file for KPilot is out-of "
00415 "date. Please run KPilot to update it."),
00416 KPilotConfig::versionDetails(fileversion,true),
00417 i18n("Configuration File Out-of Date"));
00418 }
00419
00420
00421 void KPilotConfig::interactiveUpdate()
00422 {
00423 FUNCTIONSETUP;
00424 KPilotConfigSettings &c = KPilotConfig::getConfig();
00425 int fileversion = c.getVersion();
00426 int res = 0;
00427
00428 res = KMessageBox::warningContinueCancel(0L,
00429 i18n("The configuration file for KPilot is out-of "
00430 "date. KPilot can update some parts of the "
00431 "configuration automatically. Do you wish to "
00432 "continue?"),
00433 i18n("Configuration File Out-of Date"));
00434 if (res!=KMessageBox::Continue) return;
00435
00436
00437 {
00438 QStringList conduits( c.getInstalledConduits() );
00439 c.resetGroup();
00440 bool useKroupware = c.readBoolEntry("SyncWithKMail",false);
00441 bool installFiles = c.readBoolEntry("SyncFiles",true);
00442 if (useKroupware) conduits.append( CSL1("internal_kroupware") );
00443 if (installFiles) conduits.append( CSL1("internal_fileinstall") );
00444 c.deleteEntry("SyncWithKMail");
00445 c.deleteEntry("SyncFiles");
00446 c.setInstalledConduits(conduits);
00447 c.sync();
00448 if (useKroupware || installFiles)
00449 KMessageBox::information(0L,
00450 i18n("The settings for Kroupware syncing with KMail "
00451 "and the file installer have been moved to the "
00452 "conduits configuration. Check the installed "
00453 "conduits list."),
00454 i18n("Settings Updated"));
00455
00456 }
00457
00458
00459
00460
00461 {
00462 QStringList foundlibs ;
00463 static const char *oldconduits[] = { "null", "address", "doc",
00464 "knotes", "sysinfo", "time", "todo", "vcal", 0L } ;
00465 const char **s = oldconduits;
00466 while (*s)
00467 {
00468 QString libname = CSL1("kde3/lib%1conduit.so").arg(*s);
00469 QString foundlib = ::locate("lib",libname);
00470 if (!foundlib.isEmpty())
00471 {
00472 foundlibs.append(foundlib);
00473 }
00474 s++;
00475 }
00476
00477 if (!foundlibs.isEmpty())
00478 KMessageBox::informationList(0L,
00479 i18n("<qt>The following old conduits were found on "
00480 "your system. It is a good idea to remove "
00481 "them and the associated <tt>.la</tt> "
00482 "and <tt>.so.0</tt> files.</qt>"),
00483 foundlibs,
00484 i18n("Old Conduits Found"));
00485 }
00486
00487 KPilotConfig::updateConfigVersion();
00488 c.sync();
00489 }