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

Generated on 2 Sep 2009 for Vidalia by  doxygen 1.6.1