kpilot/kpilot
kpilotConfig.cc00001
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
00030 #include "options.h"
00031
00032 #include <stdlib.h>
00033
00034 #include <qlineedit.h>
00035 #include <qcombobox.h>
00036 #include <qcheckbox.h>
00037
00038 #include <kstandarddirs.h>
00039 #include <kconfig.h>
00040 #include <ksimpleconfig.h>
00041 #include <kcmdlineargs.h>
00042 #include <kmessagebox.h>
00043 #include <kglobalsettings.h>
00044
00045 #include "kpilotSettings.h"
00046 #include "kpilotConfig.h"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 const uint KPilotConfig::ConfigurationVersion = 443;
00058
00059 int KPilotConfig::getConfigVersion()
00060 {
00061 FUNCTIONSETUP;
00062
00063 uint version = KPilotSettings::configVersion();
00064
00065 if (version < ConfigurationVersion)
00066 {
00067 kdWarning() << k_funcinfo <<
00068 ": Config file has old version " << version << endl;
00069 }
00070 else
00071 {
00072 #ifdef DEBUG
00073 DEBUGDB << fname
00074 << ": Config file has version " << version << endl;
00075 #endif
00076 }
00077
00078 return version;
00079 }
00080
00081 void KPilotConfig::updateConfigVersion()
00082 {
00083 FUNCTIONSETUP;
00084 KPilotSettings::setConfigVersion( ConfigurationVersion );
00085 }
00086
00087 QString KPilotConfig::getDefaultDBPath()
00088 {
00089 FUNCTIONSETUP;
00090 QString lastUser = KPilotSettings::userName();
00091 QString dbsubpath = CSL1("kpilot/DBBackup/");
00092 QString defaultDBPath = KGlobal::dirs()->
00093 saveLocation("data", dbsubpath + lastUser + CSL1("/"));
00094 return defaultDBPath;
00095 }
00096
00097 int KPilotConfig::getDebugLevel(KCmdLineArgs *p)
00098 {
00099 FUNCTIONSETUP;
00100
00101 if (p)
00102 {
00103 if (p->isSet("debug"))
00104 {
00105 debug_level = p->getOption("debug").toInt();
00106 }
00107 }
00108
00109 return debug_level;
00110 }
00111
00112 static QFont *thefont = 0L;
00113
00114 const QFont & KPilotConfig::fixed()
00115 {
00116 FUNCTIONSETUP;
00117
00118 if (!thefont)
00119 thefont = new QFont(KGlobalSettings::fixedFont());
00120
00121 return *thefont;
00122 }
00123
00124
00125 void KPilotConfig::addDirtyDatabase(QString db)
00126 {
00127 FUNCTIONSETUP;
00128 QStringList l(KPilotSettings::dirtyDatabases());
00129 if (!l.contains(db))
00130 {
00131 l.append(db);
00132 KPilotSettings::setDirtyDatabases(l);
00133 }
00134 }
00135
00136
00137 void KPilotConfig::addAppBlockChangedDatabase(QString db)
00138 {
00139 QStringList l(KPilotSettings::appBlockChangedDatabases());
00140 if (!l.contains(db))
00141 {
00142 l.append(db);
00143 KPilotSettings::setAppBlockChangedDatabases(l);
00144 }
00145 }
00146
00147 void KPilotConfig::addFlagsChangedDatabase(QString db)
00148 {
00149 QStringList l(KPilotSettings::flagsChangedDatabases());
00150 if (!l.contains(db))
00151 {
00152 l.append(db);
00153 KPilotSettings::setFlagsChangedDatabases(l);
00154 }
00155 }
00156
00157
00158
00159
00160 QString KPilotConfig::versionDetails(int fileversion, bool run)
00161 {
00162 FUNCTIONSETUP;
00163 QString s = CSL1("<qt><p>");
00164 s += i18n("The configuration file is outdated.");
00165 s += ' ';
00166 s += i18n("The configuration file has version %1, while KPilot "
00167 "needs version %2.").arg(fileversion).arg(ConfigurationVersion);
00168 if (run)
00169 {
00170 s += ' ';
00171 s += i18n("Please run KPilot and check the configuration carefully "
00172 "to update the file.");
00173 }
00174 s += CSL1("</p><p>");
00175 s += i18n("Important changes to watch for are:");
00176 s += ' ';
00177 if (fileversion < 440)
00178 {
00179 s += i18n("Renamed conduits, Kroupware and file installer have "
00180 "been made conduits as well.");
00181 s += ' ';
00182 s += i18n("Conflict resolution is now a global setting.");
00183 s += ' ';
00184 }
00185 if (fileversion < 443)
00186 {
00187 s += i18n("Changed format of no-backup databases.");
00188 s += ' ';
00189 }
00190
00191
00192
00193 return s;
00194 }
00195
00196 void KPilotConfig::sorryVersionOutdated(int fileversion)
00197 {
00198 FUNCTIONSETUP;
00199 KMessageBox::detailedSorry(0L,
00200 i18n("The configuration file for KPilot is out-of "
00201 "date. Please run KPilot to update it."),
00202 KPilotConfig::versionDetails(fileversion,true),
00203 i18n("Configuration File Out-of Date"));
00204 }
00205
00206 static void update440()
00207 {
00208
00209 {
00210 QStringList conduits( KPilotSettings::installedConduits() );
00211 KConfig*c = KPilotSettings::self()->config();
00213 c->setGroup( QString::null );
00214 bool installFiles = c->readBoolEntry("SyncFiles",true);
00215 if (installFiles) conduits.append( CSL1("internal_fileinstall") );
00216 c->deleteEntry("SyncFiles");
00217 KPilotSettings::setInstalledConduits(conduits);
00218 c->sync();
00219 if (installFiles)
00220 KMessageBox::information(0L,
00221 i18n("The settings for the file installer have been moved to the "
00222 "conduits configuration. Check the installed "
00223 "conduits list."),
00224 i18n("Settings Updated"));
00225
00226 }
00227
00228
00229
00230
00231 {
00232 QStringList foundlibs ;
00233 static const char *oldconduits[] = { "null", "address", "doc",
00234 "knotes", "sysinfo", "time", "todo", "vcal", 0L } ;
00235 const char **s = oldconduits;
00236 while (*s)
00237 {
00238 QString libname = CSL1("kde3/lib%1conduit.so").arg(QString::fromLatin1(*s));
00239 QString foundlib = ::locate("lib",libname);
00240 if (!foundlib.isEmpty())
00241 {
00242 foundlibs.append(foundlib);
00243 }
00244 s++;
00245 }
00246
00247 if (!foundlibs.isEmpty())
00248 KMessageBox::informationList(0L,
00249 i18n("<qt>The following old conduits were found on "
00250 "your system. It is a good idea to remove "
00251 "them and the associated <tt>.la</tt> "
00252 "and <tt>.so.0</tt> files.</qt>"),
00253 foundlibs,
00254 i18n("Old Conduits Found"));
00255 }
00256 }
00257
00258 static void update443()
00259 {
00260 FUNCTIONSETUP;
00261
00262 QStringList skip = KPilotSettings::skipBackupDB();
00263 QStringList fixSkip;
00264 bool fixedSome = false;
00265 #ifdef DEBUG
00266 DEBUGKPILOT << fname << ": Skip databases are: "
00267 << skip.join(CSL1(",")) << endl;
00268 #endif
00269
00270 for (QStringList::const_iterator i = skip.begin(); i!=skip.end(); ++i)
00271 {
00272 if ((*i).length()==4)
00273 {
00274 fixSkip.append(CSL1("[%1]").arg(*i));
00275 fixedSome = true;
00276 }
00277 else
00278 {
00279 fixSkip.append(*i);
00280 }
00281 }
00282
00283 if (fixedSome)
00284 {
00285 KMessageBox::informationList(0L,
00286 i18n("<qt>The no backup databases listed in your configuration file "
00287 "have been adjusted to the new format. Database creator IDs "
00288 "have been changed to use square brackets []."),
00289 fixSkip,
00290 i18n("No Backup Databases Updated"));
00291 }
00292 }
00293
00294 KPilotConfig::RunMode KPilotConfig::interactiveUpdate()
00295 {
00296 FUNCTIONSETUP;
00297
00298 int res = 0;
00299 unsigned int fileVersion = KPilotSettings::configVersion();
00300
00301
00302
00303 if (fileVersion >= KPilotConfig::ConfigurationVersion)
00304 {
00305 return Normal;
00306 }
00307
00308 if (0 == fileVersion)
00309 {
00310 res = KMessageBox::questionYesNoCancel(0L,
00311 i18n("KPilot is not configured for use. You may use "
00312 "the configuration wizard or the normal configure dialog "
00313 "to configure KPilot."),
00314 i18n("Not Configured"),
00315 i18n("Use &Wizard"),
00316 i18n("Use &Dialog"));
00317 if (res == KMessageBox::Yes) return WizardAndContinue;
00318 if (res == KMessageBox::No) return ConfigureAndContinue;
00319
00320 return Cancel;
00321 }
00322
00323 res = KMessageBox::warningContinueCancel(0L,
00324 i18n("The configuration file for KPilot is out-of "
00325 "date. KPilot can update some parts of the "
00326 "configuration automatically. Do you wish to "
00327 "continue?"),
00328 i18n("Configuration File Out-of Date"));
00329 if (res!=KMessageBox::Continue) return Cancel;
00330
00331 #ifdef DEBUG
00332 DEBUGKPILOT << fname << ": Updating from "
00333 << fileVersion << " to " << ConfigurationVersion << endl;
00334 #endif
00335
00336 if (fileVersion < 440) update440();
00337 if (fileVersion < 443) update443();
00338
00339 KPilotConfig::updateConfigVersion();
00340 KPilotSettings::writeConfig();
00341 return ConfigureAndContinue;
00342 }
00343
00344 void KPilotConfig::sync()
00345 {
00346 KPilotSettings::self()->config()->sync();
00347 }
|