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 
00049 // This is a number indicating what configuration version
00050 // we're dealing with. Whenever new configuration options are
00051 // added that make it imperative for the user to take a
00052 // look at the configuration of KPilot (for example the
00053 // skipDB setting really needs user attention) we can change
00054 // (increase) this number.
00055 //
00056 //
00057 /* static */ const uint KPilotConfig::ConfigurationVersion = 443;
00058 
00059 /* static */ 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 /* static */ void KPilotConfig::updateConfigVersion()
00082 {
00083     FUNCTIONSETUP;
00084     KPilotSettings::setConfigVersion( ConfigurationVersion );
00085 }
00086 
00087 /* static */ 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 /* static */ 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 /* static */ 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 /* static */ 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     // Insert more recent additions here
00191 
00192 
00193     return s;
00194 }
00195 
00196 /* static */ 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     // Try to update conduit list
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     // Check if individual conduits have conflict settings?
00229 
00230     // Search for old conduit libraries.
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 /* static */ KPilotConfig::RunMode KPilotConfig::interactiveUpdate()
00295 {
00296     FUNCTIONSETUP;
00297 
00298     int res = 0;
00299     unsigned int fileVersion = KPilotSettings::configVersion();
00300     // FIXME better config handling -> Move the config entries using kconf_update
00301 
00302     // It's OK if we're already at the required level.
00303     if (fileVersion >= KPilotConfig::ConfigurationVersion)
00304     {
00305         return Normal;
00306     }
00307 
00308     if (0 == fileVersion) // No config file at all
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys