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. */
96 QString
98 {
99  return value(SETTING_LANGUAGE).toString();
100 }
101 
102 /** Sets the preferred language code. */
103 void
104 VidaliaSettings::setLanguageCode(QString languageCode)
105 {
106  setValue(SETTING_LANGUAGE, languageCode);
107 }
108 
109 /** Gets the interface style key (e.g., "windows", "motif", etc.) */
110 QString
112 {
113  return value(SETTING_STYLE).toString();
114 }
115 
116 /** Sets the interface style key. */
117 void
119 {
120  setValue(SETTING_STYLE, styleKey);
121 }
122 
123 /** Returns true if Tor is to be run when Vidalia starts. */
124 bool
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. */
131 void
133 {
135 }
136 
137 /** Returns true if Vidalia's main window should be visible when the
138  * application starts. */
139 bool
141 {
142  return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
143 }
144 
145 /** Sets whether to show Vidalia's main window when the application starts. */
146 void
148 {
150 }
151 
152 
153 /** Returns true if Vidalia is set to run on system boot. */
154 bool
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. */
170 void
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 */
192 QString
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. */
200 void
201 VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
202 {
203  setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
204 }
205 
206 /** Returns a fully-qualified path to the web browser directory */
207 QString
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. */
215 void
216 VidaliaSettings::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. */
223 QString
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. */
231 void
232 VidaliaSettings::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. */
239 bool
241 {
242  return value(SETTING_RUN_PROXY_AT_START).toBool();
243 }
244 
245 /** Set whether to run a proxy application when Vidalia starts. */
246 void
248 {
250 }
251 
252 /** Returns a fully-qualified path to the proxy server, including the
253  * executable name. */
254 QString
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. */
262 void
263 VidaliaSettings::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 */
270 QString
272 {
273  return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
274 }
275 
276 /** Sets the additional arguments to be passed to Proxy Executable */
277 void
279  &proxyExecutableArguments)
280 {
281  setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
282 }
283 
284 bool
286 {
287  return value(SETTING_CHECK_FOR_UPDATES).toBool();
288 }
289 
290 void
292 {
294 }
295 
296 QDateTime
298 {
299  return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
300 }
301 
302 void
303 VidaliaSettings::setLastCheckedForUpdates(const QDateTime &checkedAt)
304 {
306 }
307 
308 bool
310 {
311  return value(SETTING_USE_LOCAL_GEOIP_DATABASE).toBool();
312 }
313 
314 void
316 {
318 }
319 
320 QString
322 {
323  return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
324 }
325 
326 void
327 VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
328 {
329  setValue(SETTING_LOCAL_GEOIP_DATABASE, databaseFile);
330 }
331 
332 QString
334 {
335  return QDir::convertSeparators(value(SETTING_PLUGIN_PATH).toString());
336 }
337 
338 void
339 VidaliaSettings::setPluginPath(const QString &path)
340 {
342 }
343 
344 /** Get the icon preference */
347 {
349 }
350 
351 /** Set the icon preference */
352 void
354 {
355  setValue(SETTING_ICON_PREF, toString(iconPref));
356 }
357 
358 QString
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 
377 bool
379 {
380  return value(SETTING_SKIP_VERSION_CHECK).toBool();
381 }
382 
383 bool
385 {
386  return value(SETTING_REMEMBER_SHUTDOWN).toBool();
387 }
388 
389 void
391 {
393 }