kpilot/kpilot

kpilotConfig.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This is all of KPilot's config-handling stuff.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
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 static const char kpilotconfig_id[] =
00049     "$Id: kpilotConfig.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00050 
00051 // This is a number indicating what configuration version
00052 // we're dealing with. Whenever new configuration options are
00053 // added that make it imperative for the user to take a
00054 // look at the configuration of KPilot (for example the
00055 // skipDB setting really needs user attention) we can change
00056 // (increase) this number.
00057 //
00058 //
00059 /* static */ const uint KPilotConfig::ConfigurationVersion = 443;
00060 
00061 /* static */ int KPilotConfig::getConfigVersion()
00062 {
00063     FUNCTIONSETUP;
00064 
00065     uint version = KPilotSettings::configVersion();
00066 
00067     if (version < ConfigurationVersion)
00068     {
00069         kdWarning() << k_funcinfo <<
00070             ": Config file has old version " << version << endl;
00071     }
00072     else
00073     {
00074 #ifdef DEBUG
00075         DEBUGDB << fname
00076             << ": Config file has version " << version << endl;
00077 #endif
00078     }
00079 
00080     return version;
00081 }
00082 
00083 /* static */ void KPilotConfig::updateConfigVersion()
00084 {
00085     FUNCTIONSETUP;
00086     KPilotSettings::setConfigVersion( ConfigurationVersion );
00087 }
00088 
00089 /* static */ QString KPilotConfig::getDefaultDBPath()
00090 {
00091     FUNCTIONSETUP;
00092     QString lastUser = KPilotSettings::userName();
00093     QString dbsubpath = CSL1("kpilot/DBBackup/");
00094     QString defaultDBPath = KGlobal::dirs()->
00095         saveLocation("data", dbsubpath + lastUser + CSL1("/"));
00096     return defaultDBPath;
00097 }
00098 
00099 /* static */ int KPilotConfig::getDebugLevel(KCmdLineArgs *p)
00100 {
00101     FUNCTIONSETUP;
00102 
00103     if (p)
00104     {
00105         if (p->isSet("debug"))
00106         {
00107             debug_level = p->getOption("debug").toInt();
00108         }
00109     }
00110 
00111     return debug_level;
00112 }
00113 
00114 static QFont *thefont = 0L;
00115 
00116 /* static */ const QFont & KPilotConfig::fixed()
00117 {
00118     FUNCTIONSETUP;
00119 
00120     if (!thefont)
00121         thefont = new QFont(KGlobalSettings::fixedFont());
00122 
00123     return *thefont;
00124 }
00125 
00126 
00127 void KPilotConfig::addDirtyDatabase(QString db)
00128 {
00129     FUNCTIONSETUP;
00130     QStringList l(KPilotSettings::dirtyDatabases());
00131     if (!l.contains(db))
00132     {
00133         l.append(db);
00134         KPilotSettings::setDirtyDatabases(l);
00135     }
00136 }
00137 
00138 
00139 void KPilotConfig::addAppBlockChangedDatabase(QString db)
00140 {
00141     QStringList l(KPilotSettings::appBlockChangedDatabases());
00142     if (!l.contains(db))
00143     {
00144         l.append(db);
00145         KPilotSettings::setAppBlockChangedDatabases(l);
00146     }
00147 }
00148 
00149 void KPilotConfig::addFlagsChangedDatabase(QString db)
00150 {
00151     QStringList l(KPilotSettings::flagsChangedDatabases());
00152     if (!l.contains(db))
00153     {
00154         l.append(db);
00155         KPilotSettings::setFlagsChangedDatabases(l);
00156     }
00157 }
00158 
00159 
00160 
00161 
00162 /* static */ QString KPilotConfig::versionDetails(int fileversion, bool run)
00163 {
00164     FUNCTIONSETUP;
00165     QString s = CSL1("<qt><p>");
00166     s += i18n("The configuration file is outdated.");
00167     s += ' ';
00168     s += i18n("The configuration file has version %1, while KPilot "
00169         "needs version %2.").arg(fileversion).arg(ConfigurationVersion);
00170     if (run)
00171     {
00172         s += ' ';
00173         s += i18n("Please run KPilot and check the configuration carefully "
00174             "to update the file.");
00175     }
00176     s += CSL1("</p><p>");
00177     s += i18n("Important changes to watch for are:");
00178     s += ' ';
00179     if (fileversion < 440)
00180     {
00181         s += i18n("Renamed conduits, Kroupware and file installer have "
00182             "been made conduits as well.");
00183         s += ' ';
00184         s += i18n("Conflict resolution is now a global setting.");
00185         s += ' ';
00186     }
00187     if (fileversion < 443)
00188     {
00189         s += i18n("Changed format of no-backup databases.");
00190         s += ' ';
00191     }
00192     // Insert more recent additions here
00193 
00194 
00195     return s;
00196 }
00197 
00198 /* static */ void KPilotConfig::sorryVersionOutdated(int fileversion)
00199 {
00200     FUNCTIONSETUP;
00201     KMessageBox::detailedSorry(0L,
00202         i18n("The configuration file for KPilot is out-of "
00203             "date. Please run KPilot to update it."),
00204         KPilotConfig::versionDetails(fileversion,true),
00205         i18n("Configuration File Out-of Date"));
00206 }
00207 
00208 static void update440()
00209 {
00210     // Try to update conduit list
00211     {
00212     QStringList conduits( KPilotSettings::installedConduits() );
00213     KConfig*c = KPilotSettings::self()->config();
00215     c->setGroup( QString::null );
00216     bool installFiles = c->readBoolEntry("SyncFiles",true);
00217     if (installFiles) conduits.append( CSL1("internal_fileinstall") );
00218     c->deleteEntry("SyncFiles");
00219     KPilotSettings::setInstalledConduits(conduits);
00220     c->sync();
00221     if (installFiles)
00222         KMessageBox::information(0L,
00223             i18n("The settings for the file installer have been moved to the "
00224                 "conduits configuration. Check the installed "
00225                 "conduits list."),
00226             i18n("Settings Updated"));
00227 
00228     }
00229 
00230     // Check if individual conduits have conflict settings?
00231 
00232     // Search for old conduit libraries.
00233     {
00234     QStringList foundlibs ;
00235     static const char *oldconduits[] = { "null", "address", "doc",
00236         "knotes", "sysinfo", "time", "todo", "vcal", 0L } ;
00237     const char **s = oldconduits;
00238     while (*s)
00239     {
00240         QString libname = CSL1("kde3/lib%1conduit.so").arg(QString::fromLatin1(*s));
00241         QString foundlib = ::locate("lib",libname);
00242         if (!foundlib.isEmpty())
00243         {
00244             foundlibs.append(foundlib);
00245         }
00246         s++;
00247     }
00248 
00249     if (!foundlibs.isEmpty())
00250         KMessageBox::informationList(0L,
00251             i18n("<qt>The following old conduits were found on "
00252                 "your system. It is a good idea to remove "
00253                 "them and the associated <tt>.la</tt> "
00254                 "and <tt>.so.0</tt> files.</qt>"),
00255             foundlibs,
00256             i18n("Old Conduits Found"));
00257     }
00258 }
00259 
00260 static void update443()
00261 {
00262     FUNCTIONSETUP;
00263 
00264     QStringList skip = KPilotSettings::skipBackupDB();
00265     QStringList fixSkip;
00266     bool fixedSome = false;
00267 #ifdef DEBUG
00268     DEBUGKPILOT << fname << ": Skip databases are: "
00269         << skip.join(CSL1(",")) << endl;
00270 #endif
00271 
00272     for (QStringList::const_iterator i = skip.begin(); i!=skip.end(); ++i)
00273     {
00274         if ((*i).length()==4)
00275         {
00276             fixSkip.append(CSL1("[%1]").arg(*i));
00277             fixedSome = true;
00278         }
00279         else
00280         {
00281             fixSkip.append(*i);
00282         }
00283     }
00284 
00285     if (fixedSome)
00286     {
00287         KMessageBox::informationList(0L,
00288             i18n("<qt>The no backup databases listed in your configuration file "
00289                 "have been adjusted to the new format. Database creator IDs "
00290                 "have been changed to use square brackets []."),
00291             fixSkip,
00292             i18n("No Backup Databases Updated"));
00293     }
00294 }
00295 
00296 /* static */ KPilotConfig::RunMode KPilotConfig::interactiveUpdate()
00297 {
00298     FUNCTIONSETUP;
00299 
00300     int res = 0;
00301     unsigned int fileVersion = KPilotSettings::configVersion();
00302     // FIXME better config handling -> Move the config entries using kconf_update
00303 
00304     // It's OK if we're already at the required level.
00305     if (fileVersion >= KPilotConfig::ConfigurationVersion)
00306     {
00307         return Normal;
00308     }
00309 
00310     if (0 == fileVersion) // No config file at all
00311     {
00312         res = KMessageBox::questionYesNoCancel(0L,
00313             i18n("KPilot is not configured for use. You may use "
00314                 "the configuration wizard or the normal configure dialog "
00315                 "to configure KPilot."),
00316             i18n("Not Configured"),
00317             i18n("Use &Wizard"),
00318             i18n("Use &Dialog"));
00319         if (res == KMessageBox::Yes) return WizardAndContinue;
00320         if (res == KMessageBox::No) return ConfigureAndContinue;
00321 
00322         return Cancel;
00323     }
00324 
00325     res = KMessageBox::warningContinueCancel(0L,
00326         i18n("The configuration file for KPilot is out-of "
00327             "date. KPilot can update some parts of the "
00328             "configuration automatically. Do you wish to "
00329             "continue?"),
00330         i18n("Configuration File Out-of Date"));
00331     if (res!=KMessageBox::Continue) return Cancel;
00332 
00333 #ifdef DEBUG
00334     DEBUGKPILOT << fname << ": Updating from "
00335         << fileVersion << " to " << ConfigurationVersion << endl;
00336 #endif
00337 
00338     if (fileVersion < 440) update440();
00339     if (fileVersion < 443) update443();
00340 
00341     KPilotConfig::updateConfigVersion();
00342     KPilotSettings::writeConfig();
00343     return ConfigureAndContinue;
00344 }
00345 
00346 void KPilotConfig::sync()
00347 {
00348     KPilotSettings::self()->config()->sync();
00349 }
KDE Home | KDE Accessibility Home | Description of Access Keys