Vidalia 0.2.10

VidaliaSettings.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file VidaliaSettings.cpp
00013 ** \version $Id: VidaliaSettings.cpp 4375 2010-08-05 20:09:44Z edmanm $
00014 ** \brief General Vidalia settings, such as language and interface style
00015 */
00016 
00017 #include "VidaliaSettings.h"
00018 #include "LanguageSupport.h"
00019 #include "Vidalia.h"
00020 #if defined(Q_WS_WIN)
00021 #include "win32.h"
00022 #endif
00023 
00024 #include <QDir>
00025 #include <QCoreApplication>
00026 #include <QStyleFactory>
00027 
00028 #define SETTING_LANGUAGE            "LanguageCode"
00029 #define SETTING_STYLE               "InterfaceStyle"
00030 #define SETTING_RUN_TOR_AT_START    "RunTorAtStart"
00031 #define SETTING_DATA_DIRECTORY      "DataDirectory"
00032 #define SETTING_SHOW_MAINWINDOW_AT_START  "ShowMainWindowAtStart"
00033 #define SETTING_BROWSER_EXECUTABLE  "BrowserExecutable"
00034 #define SETTING_BROWSER_DIRECTORY   "BrowserDirectory"
00035 #define SETTING_IM_EXECUTABLE       "IMExecutable"
00036 #define SETTING_RUN_PROXY_AT_START  "RunProxyAtStart"
00037 #define SETTING_PROXY_EXECUTABLE    "ProxyExecutable"
00038 #define SETTING_PROXY_EXECUTABLE_ARGUMENTS  "ProxyExecutableArguments"
00039 #define SETTING_CHECK_FOR_UPDATES   "CheckForUpdates"
00040 #define SETTING_LAST_UPDATE_CHECK   "LastUpdateCheck"
00041 #define SETTING_USE_LOCAL_GEOIP_DATABASE  "UseLocalGeoIpDatabase"
00042 #define SETTING_LOCAL_GEOIP_DATABASE "LocalGeoIpDatabase"
00043 
00044 #if defined(Q_OS_WIN32)
00045 #define STARTUP_REG_KEY        "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
00046 #define VIDALIA_REG_KEY        "Vidalia" 
00047 #endif
00048 
00049 
00050 /** Default Constructor */
00051 VidaliaSettings::VidaliaSettings()
00052 {
00053 #if defined(Q_WS_MAC)
00054   setDefault(SETTING_STYLE, "macintosh (aqua)");
00055 #else
00056   static QStringList styles = QStyleFactory::keys();
00057 #if defined(Q_WS_WIN)
00058   if (styles.contains("windowsvista", Qt::CaseInsensitive))
00059     setDefault(SETTING_STYLE, "windowsvista");
00060   else
00061 #endif
00062   {
00063     if (styles.contains("cleanlooks", Qt::CaseInsensitive))
00064       setDefault(SETTING_STYLE, "cleanlooks");
00065     else
00066       setDefault(SETTING_STYLE, "plastique");
00067   }
00068 #endif
00069 
00070   setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode());
00071   setDefault(SETTING_RUN_TOR_AT_START, true);
00072   setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true);
00073   setDefault(SETTING_BROWSER_EXECUTABLE, "");
00074   setDefault(SETTING_IM_EXECUTABLE, "");
00075   setDefault(SETTING_RUN_PROXY_AT_START, false);
00076   setDefault(SETTING_PROXY_EXECUTABLE, "");
00077   setDefault(SETTING_PROXY_EXECUTABLE_ARGUMENTS, QString());
00078 #if defined(Q_WS_WIN)
00079   setDefault(SETTING_CHECK_FOR_UPDATES, true);
00080 #else
00081   setDefault(SETTING_CHECK_FOR_UPDATES, false);
00082 #endif
00083   setDefault(SETTING_LAST_UPDATE_CHECK, QDateTime());
00084   setDefault(SETTING_USE_LOCAL_GEOIP_DATABASE, false);
00085   setDefault(SETTING_LOCAL_GEOIP_DATABASE, "");
00086 }
00087 
00088 /** Gets the currently preferred language code for Vidalia. */
00089 QString
00090 VidaliaSettings::getLanguageCode()
00091 {
00092   return value(SETTING_LANGUAGE).toString();
00093 }
00094 
00095 /** Sets the preferred language code. */
00096 void
00097 VidaliaSettings::setLanguageCode(QString languageCode)
00098 {
00099   setValue(SETTING_LANGUAGE, languageCode);
00100 }
00101 
00102 /** Gets the interface style key (e.g., "windows", "motif", etc.) */
00103 QString
00104 VidaliaSettings::getInterfaceStyle()
00105 {
00106   return value(SETTING_STYLE).toString();
00107 }
00108 
00109 /** Sets the interface style key. */
00110 void
00111 VidaliaSettings::setInterfaceStyle(QString styleKey)
00112 {
00113   setValue(SETTING_STYLE, styleKey);
00114 }
00115 
00116 /** Returns true if Tor is to be run when Vidalia starts. */
00117 bool
00118 VidaliaSettings::runTorAtStart()
00119 {
00120   return value(SETTING_RUN_TOR_AT_START).toBool();
00121 }
00122 
00123 /** If <b>run</b> is set to true, then Tor will be run when Vidalia starts. */
00124 void
00125 VidaliaSettings::setRunTorAtStart(bool run)
00126 {
00127   setValue(SETTING_RUN_TOR_AT_START, run);
00128 }
00129 
00130 /** Returns true if Vidalia's main window should be visible when the
00131  * application starts. */
00132 bool
00133 VidaliaSettings::showMainWindowAtStart()
00134 {
00135   return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
00136 }
00137 
00138 /** Sets whether to show Vidalia's main window when the application starts. */
00139 void
00140 VidaliaSettings::setShowMainWindowAtStart(bool show)
00141 {
00142   setValue(SETTING_SHOW_MAINWINDOW_AT_START, show);
00143 }
00144 
00145 
00146 /** Returns true if Vidalia is set to run on system boot. */
00147 bool
00148 VidaliaSettings::runVidaliaOnBoot()
00149 {
00150 #if defined(Q_WS_WIN)
00151   if (!win32_registry_get_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY).isEmpty()) {
00152     return true;
00153   } else {
00154     return false;
00155   }
00156 #else
00157   /* Platforms other than windows aren't supported yet */
00158   return false;
00159 #endif
00160 }
00161 
00162 /** If <b>run</b> is set to true, then Vidalia will run on system boot. */
00163 void
00164 VidaliaSettings::setRunVidaliaOnBoot(bool run)
00165 {
00166 #if defined(Q_WS_WIN)
00167   if (run) {
00168     win32_registry_set_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY,
00169         QString("\"" +
00170                 QDir::convertSeparators(QCoreApplication::applicationFilePath())) +
00171                 "\"");
00172   } else {
00173     win32_registry_remove_key(STARTUP_REG_KEY, VIDALIA_REG_KEY);
00174   }
00175 #else
00176   /* Platforms othe rthan windows aren't supported yet */
00177   Q_UNUSED(run);
00178   return;
00179 #endif
00180 }
00181 
00182 /** If browserDirectory is empty, returns a fully-qualified path to
00183  * the web browser, including the executable name. If browserDirectory
00184  * is set, then returns the basename of the configured web browser */
00185 QString
00186 VidaliaSettings::getBrowserExecutable() const
00187 {
00188   return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
00189 }
00190 
00191 /** Sets the location and name of the web browser executable to the given string.
00192  * If set to the empty string, the browser will not be started. */
00193 void
00194 VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
00195 {
00196   setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
00197 }
00198 
00199 /** Returns a fully-qualified path to the web browser directory */
00200 QString
00201 VidaliaSettings::getBrowserDirectory() const
00202 {
00203   return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
00204 }
00205 
00206 /** Sets the location and name of the web browser directory to the given string.
00207  * If set to the empty string, the browser will not be started. */
00208 void
00209 VidaliaSettings::setBrowserDirectory(const QString &browserDirectory)
00210 {
00211   setValue(SETTING_BROWSER_DIRECTORY, browserDirectory);
00212 }
00213 
00214 /** Returns a fully-qualified path to the IM client, including the
00215  * executable name. */
00216 QString
00217 VidaliaSettings::getIMExecutable() const
00218 {
00219   return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
00220 }
00221 
00222 /** Sets the location and name of the IM client executable to the given string.
00223  * If set to the empty string, the client will not be started. */
00224 void
00225 VidaliaSettings::setIMExecutable(const QString &IMExecutable)
00226 {
00227   setValue(SETTING_IM_EXECUTABLE, IMExecutable);
00228 }
00229 
00230 /** Returns true if Vidalia should start a proxy application when it
00231  * starts. */
00232 bool
00233 VidaliaSettings::runProxyAtStart()
00234 {
00235   return value(SETTING_RUN_PROXY_AT_START).toBool();
00236 }
00237 
00238 /** Set whether to run a proxy application when Vidalia starts. */
00239 void
00240 VidaliaSettings::setRunProxyAtStart(bool run)
00241 {
00242   setValue(SETTING_RUN_PROXY_AT_START, run);
00243 }
00244 
00245 /** Returns a fully-qualified path to the proxy server, including the
00246  * executable name. */
00247 QString
00248 VidaliaSettings::getProxyExecutable() const
00249 {
00250   return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
00251 }
00252 
00253 /** Sets the location and name of the proxy server executable to the given
00254  * string. If set to the empty string, the proxy will not be started. */
00255 void
00256 VidaliaSettings::setProxyExecutable(const QString &proxyExecutable)
00257 {
00258   setValue(SETTING_PROXY_EXECUTABLE, proxyExecutable);
00259 }
00260 
00261 /** Returns a string containing additional command line arguments to be passed
00262  * to ProxyExecutable */
00263 QString
00264 VidaliaSettings::getProxyExecutableArguments() const
00265 {
00266   return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
00267 }
00268 
00269 /** Sets the additional arguments to be passed to Proxy Executable */
00270 void
00271 VidaliaSettings::setProxyExecutableArguments(const QString
00272                                              &proxyExecutableArguments)
00273 {
00274   setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
00275 }
00276 
00277 bool
00278 VidaliaSettings::isAutoUpdateEnabled() const
00279 {
00280   return value(SETTING_CHECK_FOR_UPDATES).toBool();
00281 }
00282 
00283 void
00284 VidaliaSettings::setAutoUpdateEnabled(bool enabled)
00285 {
00286   setValue(SETTING_CHECK_FOR_UPDATES, enabled);
00287 }
00288 
00289 QDateTime
00290 VidaliaSettings::lastCheckedForUpdates() const
00291 {
00292   return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
00293 }
00294 
00295 void
00296 VidaliaSettings::setLastCheckedForUpdates(const QDateTime &checkedAt)
00297 {
00298   setValue(SETTING_LAST_UPDATE_CHECK, checkedAt);
00299 }
00300 
00301 bool
00302 VidaliaSettings::useLocalGeoIpDatabase() const
00303 {
00304   return value(SETTING_USE_LOCAL_GEOIP_DATABASE).toBool();
00305 }
00306 
00307 void
00308 VidaliaSettings::setUseLocalGeoIpDatabase(bool enabled)
00309 {
00310   setValue(SETTING_USE_LOCAL_GEOIP_DATABASE, enabled);
00311 }
00312 
00313 QString
00314 VidaliaSettings::localGeoIpDatabase() const
00315 {
00316   return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
00317 }
00318 
00319 void
00320 VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
00321 {
00322   setValue(SETTING_LOCAL_GEOIP_DATABASE, databaseFile);
00323 }
00324