Vidalia  0.2.21
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_PROFILE_DIRECTORY "ProfileDirectory"
35 #define SETTING_DEFAULT_PROFILE_DIRECTORY "DefaultProfileDirectory"
36 #define SETTING_PLUGINS_DIRECTORY "PluginsDirectory"
37 #define SETTING_DEFAULT_PLUGINS_DIRECTORY "DefaultPluginsDirectory"
38 #define SETTING_IM_EXECUTABLE "IMExecutable"
39 #define SETTING_RUN_PROXY_AT_START "RunProxyAtStart"
40 #define SETTING_PROXY_EXECUTABLE "ProxyExecutable"
41 #define SETTING_PROXY_EXECUTABLE_ARGUMENTS "ProxyExecutableArguments"
42 #define SETTING_CHECK_FOR_UPDATES "CheckForUpdates"
43 #define SETTING_LAST_UPDATE_CHECK "LastUpdateCheck"
44 #define SETTING_USE_LOCAL_GEOIP_DATABASE "UseLocalGeoIpDatabase"
45 #define SETTING_LOCAL_GEOIP_DATABASE "LocalGeoIpDatabase"
46 #define SETTING_SKIP_VERSION_CHECK "SkipVersionCheck"
47 
48 #if defined(Q_OS_WIN32)
49 #define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
50 #define VIDALIA_REG_KEY "Vidalia"
51 #endif
52 
53 #define SETTING_ICON_PREF "IconDisplayPreference"
54 
55 /** Default Constructor */
57 {
58 #if defined(Q_WS_MAC)
59  setDefault(SETTING_STYLE, "macintosh (aqua)");
60 #else
61  static QStringList styles = QStyleFactory::keys();
62 #if defined(Q_WS_WIN)
63  if (styles.contains("windowsvista", Qt::CaseInsensitive))
64  setDefault(SETTING_STYLE, "windowsvista");
65  else
66 #endif
67  {
68  if (styles.contains("cleanlooks", Qt::CaseInsensitive))
69  setDefault(SETTING_STYLE, "cleanlooks");
70  else
71  setDefault(SETTING_STYLE, "plastique");
72  }
73 #endif
74 
83 #if defined(Q_WS_WIN)
85 #else
87 #endif
93 
98 }
99 
100 /** Gets the currently preferred language code for Vidalia. */
101 QString
103 {
104  return value(SETTING_LANGUAGE).toString();
105 }
106 
107 /** Sets the preferred language code. */
108 void
109 VidaliaSettings::setLanguageCode(QString languageCode)
110 {
111  setValue(SETTING_LANGUAGE, languageCode);
112 }
113 
114 /** Gets the interface style key (e.g., "windows", "motif", etc.) */
115 QString
117 {
118  return value(SETTING_STYLE).toString();
119 }
120 
121 /** Sets the interface style key. */
122 void
124 {
125  setValue(SETTING_STYLE, styleKey);
126 }
127 
128 /** Returns true if Tor is to be run when Vidalia starts. */
129 bool
131 {
132  return value(SETTING_RUN_TOR_AT_START).toBool();
133 }
134 
135 /** If <b>run</b> is set to true, then Tor will be run when Vidalia starts. */
136 void
138 {
140 }
141 
142 /** Returns true if Vidalia's main window should be visible when the
143  * application starts. */
144 bool
146 {
147  return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
148 }
149 
150 /** Sets whether to show Vidalia's main window when the application starts. */
151 void
153 {
155 }
156 
157 
158 /** Returns true if Vidalia is set to run on system boot. */
159 bool
161 {
162 #if defined(Q_WS_WIN)
163  if (!win32_registry_get_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY).isEmpty()) {
164  return true;
165  } else {
166  return false;
167  }
168 #else
169  /* Platforms other than windows aren't supported yet */
170  return false;
171 #endif
172 }
173 
174 /** If <b>run</b> is set to true, then Vidalia will run on system boot. */
175 void
177 {
178 #if defined(Q_WS_WIN)
179  if (run) {
180  win32_registry_set_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY,
181  QString("\"" +
182  QDir::convertSeparators(QCoreApplication::applicationFilePath())) +
183  "\"");
184  } else {
185  win32_registry_remove_key(STARTUP_REG_KEY, VIDALIA_REG_KEY);
186  }
187 #else
188  /* Platforms othe rthan windows aren't supported yet */
189  Q_UNUSED(run);
190  return;
191 #endif
192 }
193 
194 /** If browserDirectory is empty, returns a fully-qualified path to
195  * the web browser, including the executable name. If browserDirectory
196  * is set, then returns the basename of the configured web browser */
197 QString
199 {
200  return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
201 }
202 
203 /** Sets the location and name of the web browser executable to the given string.
204  * If set to the empty string, the browser will not be started. */
205 void
206 VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
207 {
208  setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
209 }
210 
211 /** Returns a fully-qualified path to the web browser directory */
212 QString
214 {
215  return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
216 }
217 
218 /** Sets the location and name of the web browser directory to the given string.
219  * If set to the empty string, the browser will not be started. */
220 void
221 VidaliaSettings::setBrowserDirectory(const QString &browserDirectory)
222 {
223  setValue(SETTING_BROWSER_DIRECTORY, browserDirectory);
224 }
225 
226 /** Returns a fully-qualified path to the IM client, including the
227  * executable name. */
228 QString
230 {
231  return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
232 }
233 
234 /** Sets the location and name of the IM client executable to the given string.
235  * If set to the empty string, the client will not be started. */
236 void
237 VidaliaSettings::setIMExecutable(const QString &IMExecutable)
238 {
239  setValue(SETTING_IM_EXECUTABLE, IMExecutable);
240 }
241 
242 /** Returns true if Vidalia should start a proxy application when it
243  * starts. */
244 bool
246 {
247  return value(SETTING_RUN_PROXY_AT_START).toBool();
248 }
249 
250 /** Set whether to run a proxy application when Vidalia starts. */
251 void
253 {
255 }
256 
257 /** Returns a fully-qualified path to the proxy server, including the
258  * executable name. */
259 QString
261 {
262  return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
263 }
264 
265 /** Sets the location and name of the proxy server executable to the given
266  * string. If set to the empty string, the proxy will not be started. */
267 void
268 VidaliaSettings::setProxyExecutable(const QString &proxyExecutable)
269 {
270  setValue(SETTING_PROXY_EXECUTABLE, proxyExecutable);
271 }
272 
273 /** Returns a string containing additional command line arguments to be passed
274  * to ProxyExecutable */
275 QString
277 {
278  return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
279 }
280 
281 /** Sets the additional arguments to be passed to Proxy Executable */
282 void
284  &proxyExecutableArguments)
285 {
286  setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
287 }
288 
289 bool
291 {
292  return value(SETTING_CHECK_FOR_UPDATES).toBool();
293 }
294 
295 void
297 {
299 }
300 
301 QDateTime
303 {
304  return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
305 }
306 
307 void
308 VidaliaSettings::setLastCheckedForUpdates(const QDateTime &checkedAt)
309 {
311 }
312 
313 bool
315 {
316  return value(SETTING_USE_LOCAL_GEOIP_DATABASE).toBool();
317 }
318 
319 void
321 {
323 }
324 
325 QString
327 {
328  return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
329 }
330 
331 void
332 VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
333 {
334  setValue(SETTING_LOCAL_GEOIP_DATABASE, databaseFile);
335 }
336 
337 /** Get the icon preference */
340 {
342 }
343 
344 /** Set the icon preference */
345 void
347 {
348  setValue(SETTING_ICON_PREF, toString(iconPref));
349 }
350 
351 QString
353 {
354  switch(iconPref) {
355  case Dock: return "Dock";
356  case Tray: return "Tray";
357  default: return "Both";
358  }
359 }
360 
363 {
364  if(iconPref == "Dock") return Dock;
365  if(iconPref == "Tray") return Tray;
366 
367  return Both;
368 }
369 
370 bool
372 {
373  return value(SETTING_SKIP_VERSION_CHECK).toBool();
374 }
375 
376 QString
378 {
379  return QDir::convertSeparators(value(SETTING_DEFAULT_PROFILE_DIRECTORY).toString());
380 }
381 
382 void
384 {
386 }
387 
388 QString
390 {
391  return QDir::convertSeparators(value(SETTING_PROFILE_DIRECTORY).toString());
392 }
393 
394 void
396 {
398 }
399 
400 QString
402 {
403  return QDir::convertSeparators(value(SETTING_PLUGINS_DIRECTORY).toString());
404 }
405 
406 void
408 {
410 }
411 
412 QString
414 {
415  return QDir::convertSeparators(value(SETTING_DEFAULT_PLUGINS_DIRECTORY).toString());
416 }
417 
418 void
420 {
422 }