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

Generated on Wed Nov 26 21:03:58 2008 for Vidalia by  doxygen 1.5.6