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 4132 2009-09-24 02:28:18Z 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 
00042 #if defined(Q_OS_WIN32)
00043 #define STARTUP_REG_KEY        "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
00044 #define VIDALIA_REG_KEY        "Vidalia" 
00045 #endif
00046 
00047 
00048 /** Default Constructor */
00049 VidaliaSettings::VidaliaSettings()
00050 {
00051 #if defined(Q_WS_MAC)
00052   setDefault(SETTING_STYLE, "macintosh (aqua)");
00053 #else
00054   static QStringList styles = QStyleFactory::keys();
00055 #if defined(Q_WS_WIN)
00056   if (styles.contains("windowsvista", Qt::CaseInsensitive))
00057     setDefault(SETTING_STYLE, "windowsvista");
00058   else
00059 #endif
00060   {
00061     if (styles.contains("cleanlooks", Qt::CaseInsensitive))
00062       setDefault(SETTING_STYLE, "cleanlooks");
00063     else
00064       setDefault(SETTING_STYLE, "plastique");
00065   }
00066 #endif
00067 
00068   setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode());
00069   setDefault(SETTING_RUN_TOR_AT_START, true);
00070   setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true);
00071   setDefault(SETTING_BROWSER_EXECUTABLE, "");
00072   setDefault(SETTING_IM_EXECUTABLE, "");
00073   setDefault(SETTING_RUN_PROXY_AT_START, false);
00074   setDefault(SETTING_PROXY_EXECUTABLE, "");
00075   setDefault(SETTING_PROXY_EXECUTABLE_ARGUMENTS, QString());
00076 #if defined(Q_WS_WIN)
00077   setDefault(SETTING_CHECK_FOR_UPDATES, true);
00078 #else
00079   setDefault(SETTING_CHECK_FOR_UPDATES, false);
00080 #endif
00081   setDefault(SETTING_LAST_UPDATE_CHECK, QDateTime());
00082 }
00083 
00084 /** Gets the currently preferred language code for Vidalia. */
00085 QString
00086 VidaliaSettings::getLanguageCode()
00087 {
00088   return value(SETTING_LANGUAGE).toString();
00089 }
00090 
00091 /** Sets the preferred language code. */
00092 void
00093 VidaliaSettings::setLanguageCode(QString languageCode)
00094 {
00095   setValue(SETTING_LANGUAGE, languageCode);
00096 }
00097 
00098 /** Gets the interface style key (e.g., "windows", "motif", etc.) */
00099 QString
00100 VidaliaSettings::getInterfaceStyle()
00101 {
00102   return value(SETTING_STYLE).toString();
00103 }
00104 
00105 /** Sets the interface style key. */
00106 void
00107 VidaliaSettings::setInterfaceStyle(QString styleKey)
00108 {
00109   setValue(SETTING_STYLE, styleKey);
00110 }
00111 
00112 /** Returns true if Tor is to be run when Vidalia starts. */
00113 bool
00114 VidaliaSettings::runTorAtStart()
00115 {
00116   return value(SETTING_RUN_TOR_AT_START).toBool();
00117 }
00118 
00119 /** If <b>run</b> is set to true, then Tor will be run when Vidalia starts. */
00120 void
00121 VidaliaSettings::setRunTorAtStart(bool run)
00122 {
00123   setValue(SETTING_RUN_TOR_AT_START, run);
00124 }
00125 
00126 /** Returns true if Vidalia's main window should be visible when the
00127  * application starts. */
00128 bool
00129 VidaliaSettings::showMainWindowAtStart()
00130 {
00131   return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
00132 }
00133 
00134 /** Sets whether to show Vidalia's main window when the application starts. */
00135 void
00136 VidaliaSettings::setShowMainWindowAtStart(bool show)
00137 {
00138   setValue(SETTING_SHOW_MAINWINDOW_AT_START, show);
00139 }
00140 
00141 
00142 /** Returns true if Vidalia is set to run on system boot. */
00143 bool
00144 VidaliaSettings::runVidaliaOnBoot()
00145 {
00146 #if defined(Q_WS_WIN)
00147   if (!win32_registry_get_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY).isEmpty()) {
00148     return true;
00149   } else {
00150     return false;
00151   }
00152 #else
00153   /* Platforms other than windows aren't supported yet */
00154   return false;
00155 #endif
00156 }
00157 
00158 /** If <b>run</b> is set to true, then Vidalia will run on system boot. */
00159 void
00160 VidaliaSettings::setRunVidaliaOnBoot(bool run)
00161 {
00162 #if defined(Q_WS_WIN)
00163   if (run) {
00164     win32_registry_set_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY,
00165         QString("\"" +
00166                 QDir::convertSeparators(QCoreApplication::applicationFilePath())) +
00167                 "\"");
00168   } else {
00169     win32_registry_remove_key(STARTUP_REG_KEY, VIDALIA_REG_KEY);
00170   }
00171 #else
00172   /* Platforms othe rthan windows aren't supported yet */
00173   Q_UNUSED(run);
00174   return;
00175 #endif
00176 }
00177 
00178 /** If browserDirectory is empty, returns a fully-qualified path to
00179  * the web browser, including the executable name. If browserDirectory
00180  * is set, then returns the basename of the configured web browser */
00181 QString
00182 VidaliaSettings::getBrowserExecutable() const
00183 {
00184   return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
00185 }
00186 
00187 /** Sets the location and name of the web browser executable to the given string.
00188  * If set to the empty string, the browser will not be started. */
00189 void
00190 VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
00191 {
00192   setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
00193 }
00194 
00195 /** Returns a fully-qualified path to the web browser directory */
00196 QString
00197 VidaliaSettings::getBrowserDirectory() const
00198 {
00199   return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
00200 }
00201 
00202 /** Sets the location and name of the web browser directory to the given string.
00203  * If set to the empty string, the browser will not be started. */
00204 void
00205 VidaliaSettings::setBrowserDirectory(const QString &browserDirectory)
00206 {
00207   setValue(SETTING_BROWSER_DIRECTORY, browserDirectory);
00208 }
00209 
00210 /** Returns a fully-qualified path to the IM client, including the
00211  * executable name. */
00212 QString
00213 VidaliaSettings::getIMExecutable() const
00214 {
00215   return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
00216 }
00217 
00218 /** Sets the location and name of the IM client executable to the given string.
00219  * If set to the empty string, the client will not be started. */
00220 void
00221 VidaliaSettings::setIMExecutable(const QString &IMExecutable)
00222 {
00223   setValue(SETTING_IM_EXECUTABLE, IMExecutable);
00224 }
00225 
00226 /** Returns true if Vidalia should start a proxy application when it
00227  * starts. */
00228 bool
00229 VidaliaSettings::runProxyAtStart()
00230 {
00231   return value(SETTING_RUN_PROXY_AT_START).toBool();
00232 }
00233 
00234 /** Set whether to run a proxy application when Vidalia starts. */
00235 void
00236 VidaliaSettings::setRunProxyAtStart(bool run)
00237 {
00238   setValue(SETTING_RUN_PROXY_AT_START, run);
00239 }
00240 
00241 /** Returns a fully-qualified path to the proxy server, including the
00242  * executable name. */
00243 QString
00244 VidaliaSettings::getProxyExecutable() const
00245 {
00246   return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
00247 }
00248 
00249 /** Sets the location and name of the proxy server executable to the given
00250  * string. If set to the empty string, the proxy will not be started. */
00251 void
00252 VidaliaSettings::setProxyExecutable(const QString &proxyExecutable)
00253 {
00254   setValue(SETTING_PROXY_EXECUTABLE, proxyExecutable);
00255 }
00256 
00257 /** Returns a string containing additional command line arguments to be passed
00258  * to ProxyExecutable */
00259 QString
00260 VidaliaSettings::getProxyExecutableArguments() const
00261 {
00262   return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
00263 }
00264 
00265 /** Sets the additional arguments to be passed to Proxy Executable */
00266 void
00267 VidaliaSettings::setProxyExecutableArguments(const QString
00268                                              &proxyExecutableArguments)
00269 {
00270   setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
00271 }
00272 
00273 bool
00274 VidaliaSettings::isAutoUpdateEnabled() const
00275 {
00276   return value(SETTING_CHECK_FOR_UPDATES).toBool();
00277 }
00278 
00279 void
00280 VidaliaSettings::setAutoUpdateEnabled(bool enabled)
00281 {
00282   setValue(SETTING_CHECK_FOR_UPDATES, enabled);
00283 }
00284 
00285 QDateTime
00286 VidaliaSettings::lastCheckedForUpdates() const
00287 {
00288   return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
00289 }
00290 
00291 void
00292 VidaliaSettings::setLastCheckedForUpdates(const QDateTime &checkedAt)
00293 {
00294   setValue(SETTING_LAST_UPDATE_CHECK, checkedAt);
00295 }
00296 

Generated on Mon Aug 30 19:10:00 2010 for Vidalia by  doxygen 1.5.9