Vidalia 0.3.1
VidaliaSettings.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file VidaliaSettings.cpp
13** \brief General Vidalia settings, such as language and interface style
14*/
15
16#include "VidaliaSettings.h"
17#include "LanguageSupport.h"
18#include "Vidalia.h"
19#if defined(Q_WS_WIN)
20#include "win32.h"
21#endif
22
23#include <QDir>
24#include <QCoreApplication>
25#include <QStyleFactory>
26
27#define SETTING_LANGUAGE "LanguageCode"
28#define SETTING_STYLE "InterfaceStyle"
29#define SETTING_RUN_TOR_AT_START "RunTorAtStart"
30#define SETTING_DATA_DIRECTORY "DataDirectory"
31#define SETTING_SHOW_MAINWINDOW_AT_START "ShowMainWindowAtStart"
32#define SETTING_BROWSER_EXECUTABLE "BrowserExecutable"
33#define SETTING_BROWSER_DIRECTORY "BrowserDirectory"
34#define SETTING_IM_EXECUTABLE "IMExecutable"
35#define SETTING_RUN_PROXY_AT_START "RunProxyAtStart"
36#define SETTING_PROXY_EXECUTABLE "ProxyExecutable"
37#define SETTING_PROXY_EXECUTABLE_ARGUMENTS "ProxyExecutableArguments"
38#define SETTING_CHECK_FOR_UPDATES "CheckForUpdates"
39#define SETTING_LAST_UPDATE_CHECK "LastUpdateCheck"
40#define SETTING_USE_LOCAL_GEOIP_DATABASE "UseLocalGeoIpDatabase"
41#define SETTING_LOCAL_GEOIP_DATABASE "LocalGeoIpDatabase"
42#define SETTING_PLUGIN_PATH "PluginPath"
43#define SETTING_SKIP_VERSION_CHECK "SkipVersionCheck"
44
45#if defined(Q_OS_WIN32)
46#define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
47#define VIDALIA_REG_KEY "Vidalia"
48#endif
49
50#define SETTING_ICON_PREF "IconPref"
51
52/** Default Constructor */
54{
55#if defined(Q_WS_MAC)
56 setDefault(SETTING_STYLE, "macintosh (aqua)");
57#else
58 static QStringList styles = QStyleFactory::keys();
59#if defined(Q_WS_WIN)
60 if (styles.contains("windowsvista", Qt::CaseInsensitive))
61 setDefault(SETTING_STYLE, "windowsvista");
62 else
63#endif
64 {
65 if (styles.contains("cleanlooks", Qt::CaseInsensitive))
66 setDefault(SETTING_STYLE, "cleanlooks");
67 else
68 setDefault(SETTING_STYLE, "plastique");
69 }
70#endif
71
80#if defined(Q_WS_WIN)
82#else
84#endif
88
89 setDefault(SETTING_PLUGIN_PATH, vApp->dataDirectory());
93}
94
95/** Gets the currently preferred language code for Vidalia. */
96QString
98{
99 return value(SETTING_LANGUAGE).toString();
100}
101
102/** Sets the preferred language code. */
103void
105{
106 setValue(SETTING_LANGUAGE, languageCode);
107}
108
109/** Gets the interface style key (e.g., "windows", "motif", etc.) */
110QString
112{
113 return value(SETTING_STYLE).toString();
114}
115
116/** Sets the interface style key. */
117void
119{
120 setValue(SETTING_STYLE, styleKey);
121}
122
123/** Returns true if Tor is to be run when Vidalia starts. */
124bool
126{
127 return value(SETTING_RUN_TOR_AT_START).toBool();
128}
129
130/** If <b>run</b> is set to true, then Tor will be run when Vidalia starts. */
131void
133{
135}
136
137/** Returns true if Vidalia's main window should be visible when the
138 * application starts. */
139bool
141{
143}
144
145/** Sets whether to show Vidalia's main window when the application starts. */
146void
148{
150}
151
152
153/** Returns true if Vidalia is set to run on system boot. */
154bool
156{
157#if defined(Q_WS_WIN)
158 if (!win32_registry_get_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY).isEmpty()) {
159 return true;
160 } else {
161 return false;
162 }
163#else
164 /* Platforms other than windows aren't supported yet */
165 return false;
166#endif
167}
168
169/** If <b>run</b> is set to true, then Vidalia will run on system boot. */
170void
172{
173#if defined(Q_WS_WIN)
174 if (run) {
175 win32_registry_set_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY,
176 QString("\"" +
177 QDir::convertSeparators(QCoreApplication::applicationFilePath())) +
178 "\"");
179 } else {
180 win32_registry_remove_key(STARTUP_REG_KEY, VIDALIA_REG_KEY);
181 }
182#else
183 /* Platforms othe rthan windows aren't supported yet */
184 Q_UNUSED(run);
185 return;
186#endif
187}
188
189/** If browserDirectory is empty, returns a fully-qualified path to
190 * the web browser, including the executable name. If browserDirectory
191 * is set, then returns the basename of the configured web browser */
192QString
194{
195 return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
196}
197
198/** Sets the location and name of the web browser executable to the given string.
199 * If set to the empty string, the browser will not be started. */
200void
201VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
202{
203 setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
204}
205
206/** Returns a fully-qualified path to the web browser directory */
207QString
209{
210 return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
211}
212
213/** Sets the location and name of the web browser directory to the given string.
214 * If set to the empty string, the browser will not be started. */
215void
216VidaliaSettings::setBrowserDirectory(const QString &browserDirectory)
217{
218 setValue(SETTING_BROWSER_DIRECTORY, browserDirectory);
219}
220
221/** Returns a fully-qualified path to the IM client, including the
222 * executable name. */
223QString
225{
226 return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
227}
228
229/** Sets the location and name of the IM client executable to the given string.
230 * If set to the empty string, the client will not be started. */
231void
232VidaliaSettings::setIMExecutable(const QString &IMExecutable)
233{
234 setValue(SETTING_IM_EXECUTABLE, IMExecutable);
235}
236
237/** Returns true if Vidalia should start a proxy application when it
238 * starts. */
239bool
241{
242 return value(SETTING_RUN_PROXY_AT_START).toBool();
243}
244
245/** Set whether to run a proxy application when Vidalia starts. */
246void
248{
250}
251
252/** Returns a fully-qualified path to the proxy server, including the
253 * executable name. */
254QString
256{
257 return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
258}
259
260/** Sets the location and name of the proxy server executable to the given
261 * string. If set to the empty string, the proxy will not be started. */
262void
263VidaliaSettings::setProxyExecutable(const QString &proxyExecutable)
264{
265 setValue(SETTING_PROXY_EXECUTABLE, proxyExecutable);
266}
267
268/** Returns a string containing additional command line arguments to be passed
269 * to ProxyExecutable */
270QString
272{
273 return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
274}
275
276/** Sets the additional arguments to be passed to Proxy Executable */
277void
279 &proxyExecutableArguments)
280{
281 setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
282}
283
284bool
286{
287 return value(SETTING_CHECK_FOR_UPDATES).toBool();
288}
289
290void
292{
294}
295
296QDateTime
298{
299 return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
300}
301
302void
304{
306}
307
308bool
310{
312}
313
314void
316{
318}
319
320QString
322{
323 return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
324}
325
326void
327VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
328{
330}
331
332QString
334{
335 return QDir::convertSeparators(value(SETTING_PLUGIN_PATH).toString());
336}
337
338void
340{
342}
343
344/** Get the icon preference */
347{
349}
350
351/** Set the icon preference */
352void
354{
356}
357
358QString
360{
361 switch(iconPref) {
362 case Dock: return "Dock";
363 case Tray: return "Tray";
364 default: return "Both";
365 }
366}
367
370{
371 if(iconPref == "Dock") return Dock;
372 if(iconPref == "Tray") return Tray;
373
374 return Both;
375}
376
377bool
379{
380 return value(SETTING_SKIP_VERSION_CHECK).toBool();
381}
382
383bool
385{
386 return value(SETTING_REMEMBER_SHUTDOWN).toBool();
387}
388
389void
391{
393}
#define vApp
Definition: Vidalia.h:37
#define SETTING_SHOW_MAINWINDOW_AT_START
#define SETTING_SKIP_VERSION_CHECK
#define SETTING_PROXY_EXECUTABLE
#define SETTING_BROWSER_EXECUTABLE
#define SETTING_LOCAL_GEOIP_DATABASE
#define SETTING_RUN_PROXY_AT_START
#define SETTING_LANGUAGE
#define SETTING_RUN_TOR_AT_START
#define SETTING_STYLE
#define SETTING_CHECK_FOR_UPDATES
#define SETTING_PLUGIN_PATH
#define SETTING_PROXY_EXECUTABLE_ARGUMENTS
#define SETTING_ICON_PREF
#define SETTING_BROWSER_DIRECTORY
#define SETTING_IM_EXECUTABLE
#define SETTING_LAST_UPDATE_CHECK
#define SETTING_USE_LOCAL_GEOIP_DATABASE
#define SETTING_REMEMBER_SHUTDOWN
static QString defaultLanguageCode()
virtual void setValue(const QString &key, const QVariant &val)
Definition: VSettings.cpp:61
virtual QVariant value(const QString &key, const QVariant &defaultVal=QVariant()) const
Definition: VSettings.cpp:53
void setDefault(const QString &key, const QVariant &val)
Definition: VSettings.cpp:71
void setBrowserDirectory(const QString &browserDirectory)
void setBrowserExecutable(const QString &browserExecutable)
bool skipVersionCheck() const
void setRunProxyAtStart(bool run)
QString getProxyExecutable() const
IconPosition fromString(QString iconPref)
void setInterfaceStyle(QString styleKey)
void setLastCheckedForUpdates(const QDateTime &checkedAt)
QString getBrowserExecutable() const
bool useLocalGeoIpDatabase() const
QString getIMExecutable() const
IconPosition getIconPref()
QString getBrowserDirectory() const
void setIconPref(const IconPosition iconPref)
QString localGeoIpDatabase() const
void setIMExecutable(const QString &IMExecutable)
void setAutoUpdateEnabled(bool enabled)
void setLocalGeoIpDatabase(const QString &databaseFile)
void setLanguageCode(QString languageCode)
QString getInterfaceStyle()
QString getLanguageCode()
QString pluginPath() const
void setRememberShutdown(bool val)
void setUseLocalGeoIpDatabase(bool enabled)
QString getProxyExecutableArguments() const
QDateTime lastCheckedForUpdates() const
QString toString(const IconPosition iconPref)
void setShowMainWindowAtStart(bool show)
void setProxyExecutable(const QString &proxyExecutable)
void setRunVidaliaOnBoot(bool run)
void setRunTorAtStart(bool run)
void setPluginPath(const QString &path)
bool isAutoUpdateEnabled() const
void setProxyExecutableArguments(const QString &proxyExecutableArguments)
void win32_registry_remove_key(QString keyLocation, QString keyName)
Definition: win32.cpp:146
void win32_registry_set_key_value(QString keyLocation, QString keyName, QString keyValue)
Definition: win32.cpp:119
QString win32_registry_get_key_value(QString keyLocation, QString keyName)
Definition: win32.cpp:95