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