[tor-commits] [vidalia/alpha] Add non hardcoded defaults handling

chiiph at torproject.org chiiph at torproject.org
Mon Mar 5 22:53:32 UTC 2012


commit cdc250c8159a25a9b4a7bb3e386c87f9fc6b4ca7
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Mon Mar 5 19:38:05 2012 -0300

    Add non hardcoded defaults handling
    
    Also removes temporary files that shouldn't have been there in the first
    place.
---
 src/vidalia/config/VSettings.cpp        |   11 +-
 src/vidalia/config/VSettings.h          |    7 +-
 src/vidalia/config/VidaliaSettings.cpp~ |  396 -------------------------------
 src/vidalia/config/VidaliaSettings.h~   |  163 -------------
 4 files changed, 16 insertions(+), 561 deletions(-)

diff --git a/src/vidalia/config/VSettings.cpp b/src/vidalia/config/VSettings.cpp
index ca8cdd4..020485b 100644
--- a/src/vidalia/config/VSettings.cpp
+++ b/src/vidalia/config/VSettings.cpp
@@ -20,16 +20,25 @@
 
 /** The file in which all settings will read and written. */
 #define SETTINGS_FILE (Vidalia::dataDirectory() + "/vidalia.conf")
+#define SETTINGS_DEFAULTS_FILE (Vidalia::dataDirectory() + "/vidalia.defaults.conf")
 
 
 /** Constructor */
 VSettings::VSettings(const QString settingsGroup)
 : QSettings(SETTINGS_FILE, QSettings::IniFormat)
 {
+  _defaultSettings = new QSettings(SETTINGS_DEFAULTS_FILE,
+                                   QSettings::IniFormat);
+
   if (!settingsGroup.isEmpty())
     beginGroup(settingsGroup);
 }
 
+VSettings::~VSettings()
+{
+  delete _defaultSettings;
+}
+
 /** Returns the location of Vidalia's configuration settings file. */
 QString
 VSettings::settingsFile()
@@ -70,7 +79,7 @@ VSettings::setValue(const QString &key, const QVariant &val)
 void
 VSettings::setDefault(const QString &key, const QVariant &val)
 {
-  _defaults.insert(key, val);
+  _defaults.insert(key, _defaultSettings->value(key, val));
 }
 
 /** Returns the default setting value associated with <b>key</b>. If
diff --git a/src/vidalia/config/VSettings.h b/src/vidalia/config/VSettings.h
index 50357fc..539f9a8 100644
--- a/src/vidalia/config/VSettings.h
+++ b/src/vidalia/config/VSettings.h
@@ -29,7 +29,9 @@ public:
    * set a prefix that will be prepended to keys specified to VSettings in
    * value() and setValue(). */
   VSettings(const QString group = QString());
-
+  /** Default destructor */
+  ~VSettings();
+  
   /** Returns the location of Vidalia's configuration settings file. */
   static QString settingsFile();
   /** Returns true if Vidalia's configuration settings file already exists. */
@@ -67,6 +69,9 @@ private:
 
   /** Stores values that last as long as Vidalia lives as a process */
   QMap<QString, QVariant> _volatileSettings;
+  
+  /** Defaults stored in a settings file */
+  QSettings *_defaultSettings;
 };
 
 #endif
diff --git a/src/vidalia/config/VidaliaSettings.cpp~ b/src/vidalia/config/VidaliaSettings.cpp~
deleted file mode 100644
index 6e468fa..0000000
--- a/src/vidalia/config/VidaliaSettings.cpp~
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
-**  including this file, may be copied, modified, propagated, or distributed 
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file VidaliaSettings.cpp
-** \brief General Vidalia settings, such as language and interface style
-*/
-
-#include "VidaliaSettings.h"
-#include "LanguageSupport.h"
-#include "Vidalia.h"
-#if defined(Q_WS_WIN)
-#include "win32.h"
-#endif
-
-#include <QDir>
-#include <QCoreApplication>
-#include <QStyleFactory>
-
-#define SETTING_LANGUAGE            "LanguageCode"
-#define SETTING_STYLE               "InterfaceStyle"
-#define SETTING_RUN_TOR_AT_START    "RunTorAtStart"
-#define SETTING_DATA_DIRECTORY      "DataDirectory"
-#define SETTING_SHOW_MAINWINDOW_AT_START  "ShowMainWindowAtStart"
-#define SETTING_BROWSER_EXECUTABLE  "BrowserExecutable"
-#define SETTING_BROWSER_DIRECTORY   "BrowserDirectory"
-#define SETTING_IM_EXECUTABLE       "IMExecutable"
-#define SETTING_RUN_PROXY_AT_START  "RunProxyAtStart"
-#define SETTING_PROXY_EXECUTABLE    "ProxyExecutable"
-#define SETTING_PROXY_EXECUTABLE_ARGUMENTS  "ProxyExecutableArguments"
-#define SETTING_CHECK_FOR_UPDATES   "CheckForUpdates"
-#define SETTING_LAST_UPDATE_CHECK   "LastUpdateCheck"
-#define SETTING_USE_LOCAL_GEOIP_DATABASE  "UseLocalGeoIpDatabase"
-#define SETTING_LOCAL_GEOIP_DATABASE "LocalGeoIpDatabase"
-#define SETTING_PLUGIN_PATH         "PluginPath"
-#define SETTING_SKIP_VERSION_CHECK  "SkipVersionCheck"
-
-#if defined(Q_OS_WIN32)
-#define STARTUP_REG_KEY        "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
-#define VIDALIA_REG_KEY        "Vidalia" 
-#endif
-
-#define SETTING_ICON_PREF	"IconPref"
-
-/** Default Constructor */
-VidaliaSettings::VidaliaSettings()
-{
-#if defined(Q_WS_MAC)
-  setDefault(SETTING_STYLE, "macintosh (aqua)");
-#else
-  static QStringList styles = QStyleFactory::keys();
-#if defined(Q_WS_WIN)
-  if (styles.contains("windowsvista", Qt::CaseInsensitive))
-    setDefault(SETTING_STYLE, "windowsvista");
-  else
-#endif
-  {
-    if (styles.contains("cleanlooks", Qt::CaseInsensitive))
-      setDefault(SETTING_STYLE, "cleanlooks");
-    else
-      setDefault(SETTING_STYLE, "plastique");
-  }
-#endif
-
-  setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode());
-  setDefault(SETTING_RUN_TOR_AT_START, true);
-  setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true);
-  setDefault(SETTING_BROWSER_EXECUTABLE, "");
-  setDefault(SETTING_IM_EXECUTABLE, "");
-  setDefault(SETTING_RUN_PROXY_AT_START, false);
-  setDefault(SETTING_PROXY_EXECUTABLE, "");
-  setDefault(SETTING_PROXY_EXECUTABLE_ARGUMENTS, QString());
-#if defined(Q_WS_WIN)
-  setDefault(SETTING_CHECK_FOR_UPDATES, true);
-#else
-  setDefault(SETTING_CHECK_FOR_UPDATES, false);
-#endif
-  setDefault(SETTING_LAST_UPDATE_CHECK, QDateTime());
-  setDefault(SETTING_USE_LOCAL_GEOIP_DATABASE, false);
-  setDefault(SETTING_LOCAL_GEOIP_DATABASE, "");
-
-  setDefault(SETTING_PLUGIN_PATH, vApp->dataDirectory());
-  setDefault(SETTING_ICON_PREF, Both);
-<<<<<<< HEAD
-  setDefault(SETTING_SKIP_VERSION_CHECK, false);
-=======
-  setDefault(SETTING_REMEMBER_SHUTDOWN, false);
->>>>>>> bug4577_remember
-}
-
-/** Gets the currently preferred language code for Vidalia. */
-QString
-VidaliaSettings::getLanguageCode()
-{
-  return value(SETTING_LANGUAGE).toString();
-}
-
-/** Sets the preferred language code. */
-void
-VidaliaSettings::setLanguageCode(QString languageCode)
-{
-  setValue(SETTING_LANGUAGE, languageCode);
-}
-
-/** Gets the interface style key (e.g., "windows", "motif", etc.) */
-QString
-VidaliaSettings::getInterfaceStyle()
-{
-  return value(SETTING_STYLE).toString();
-}
-
-/** Sets the interface style key. */
-void
-VidaliaSettings::setInterfaceStyle(QString styleKey)
-{
-  setValue(SETTING_STYLE, styleKey);
-}
-
-/** Returns true if Tor is to be run when Vidalia starts. */
-bool
-VidaliaSettings::runTorAtStart()
-{
-  return value(SETTING_RUN_TOR_AT_START).toBool();
-}
-
-/** If <b>run</b> is set to true, then Tor will be run when Vidalia starts. */
-void
-VidaliaSettings::setRunTorAtStart(bool run)
-{
-  setValue(SETTING_RUN_TOR_AT_START, run);
-}
-
-/** Returns true if Vidalia's main window should be visible when the
- * application starts. */
-bool
-VidaliaSettings::showMainWindowAtStart()
-{
-  return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
-}
-
-/** Sets whether to show Vidalia's main window when the application starts. */
-void
-VidaliaSettings::setShowMainWindowAtStart(bool show)
-{
-  setValue(SETTING_SHOW_MAINWINDOW_AT_START, show);
-}
-
-
-/** Returns true if Vidalia is set to run on system boot. */
-bool
-VidaliaSettings::runVidaliaOnBoot()
-{
-#if defined(Q_WS_WIN)
-  if (!win32_registry_get_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY).isEmpty()) {
-    return true;
-  } else {
-    return false;
-  }
-#else
-  /* Platforms other than windows aren't supported yet */
-  return false;
-#endif
-}
-
-/** If <b>run</b> is set to true, then Vidalia will run on system boot. */
-void
-VidaliaSettings::setRunVidaliaOnBoot(bool run)
-{
-#if defined(Q_WS_WIN)
-  if (run) {
-    win32_registry_set_key_value(STARTUP_REG_KEY, VIDALIA_REG_KEY,
-        QString("\"" +
-                QDir::convertSeparators(QCoreApplication::applicationFilePath())) +
-                "\"");
-  } else {
-    win32_registry_remove_key(STARTUP_REG_KEY, VIDALIA_REG_KEY);
-  }
-#else
-  /* Platforms othe rthan windows aren't supported yet */
-  Q_UNUSED(run);
-  return;
-#endif
-}
-
-/** If browserDirectory is empty, returns a fully-qualified path to
- * the web browser, including the executable name. If browserDirectory
- * is set, then returns the basename of the configured web browser */
-QString
-VidaliaSettings::getBrowserExecutable() const
-{
-  return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
-}
-
-/** Sets the location and name of the web browser executable to the given string.
- * If set to the empty string, the browser will not be started. */
-void
-VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
-{
-  setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
-}
-
-/** Returns a fully-qualified path to the web browser directory */
-QString
-VidaliaSettings::getBrowserDirectory() const
-{
-  return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
-}
-
-/** Sets the location and name of the web browser directory to the given string.
- * If set to the empty string, the browser will not be started. */
-void
-VidaliaSettings::setBrowserDirectory(const QString &browserDirectory)
-{
-  setValue(SETTING_BROWSER_DIRECTORY, browserDirectory);
-}
-
-/** Returns a fully-qualified path to the IM client, including the
- * executable name. */
-QString
-VidaliaSettings::getIMExecutable() const
-{
-  return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
-}
-
-/** Sets the location and name of the IM client executable to the given string.
- * If set to the empty string, the client will not be started. */
-void
-VidaliaSettings::setIMExecutable(const QString &IMExecutable)
-{
-  setValue(SETTING_IM_EXECUTABLE, IMExecutable);
-}
-
-/** Returns true if Vidalia should start a proxy application when it
- * starts. */
-bool
-VidaliaSettings::runProxyAtStart()
-{
-  return value(SETTING_RUN_PROXY_AT_START).toBool();
-}
-
-/** Set whether to run a proxy application when Vidalia starts. */
-void
-VidaliaSettings::setRunProxyAtStart(bool run)
-{
-  setValue(SETTING_RUN_PROXY_AT_START, run);
-}
-
-/** Returns a fully-qualified path to the proxy server, including the
- * executable name. */
-QString
-VidaliaSettings::getProxyExecutable() const
-{
-  return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
-}
-
-/** Sets the location and name of the proxy server executable to the given
- * string. If set to the empty string, the proxy will not be started. */
-void
-VidaliaSettings::setProxyExecutable(const QString &proxyExecutable)
-{
-  setValue(SETTING_PROXY_EXECUTABLE, proxyExecutable);
-}
-
-/** Returns a string containing additional command line arguments to be passed
- * to ProxyExecutable */
-QString
-VidaliaSettings::getProxyExecutableArguments() const
-{
-  return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
-}
-
-/** Sets the additional arguments to be passed to Proxy Executable */
-void
-VidaliaSettings::setProxyExecutableArguments(const QString
-                                             &proxyExecutableArguments)
-{
-  setValue(SETTING_PROXY_EXECUTABLE_ARGUMENTS, proxyExecutableArguments);
-}
-
-bool
-VidaliaSettings::isAutoUpdateEnabled() const
-{
-  return value(SETTING_CHECK_FOR_UPDATES).toBool();
-}
-
-void
-VidaliaSettings::setAutoUpdateEnabled(bool enabled)
-{
-  setValue(SETTING_CHECK_FOR_UPDATES, enabled);
-}
-
-QDateTime
-VidaliaSettings::lastCheckedForUpdates() const
-{
-  return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
-}
-
-void
-VidaliaSettings::setLastCheckedForUpdates(const QDateTime &checkedAt)
-{
-  setValue(SETTING_LAST_UPDATE_CHECK, checkedAt);
-}
-
-bool
-VidaliaSettings::useLocalGeoIpDatabase() const
-{
-  return value(SETTING_USE_LOCAL_GEOIP_DATABASE).toBool();
-}
-
-void
-VidaliaSettings::setUseLocalGeoIpDatabase(bool enabled)
-{
-  setValue(SETTING_USE_LOCAL_GEOIP_DATABASE, enabled);
-}
-
-QString
-VidaliaSettings::localGeoIpDatabase() const
-{
-  return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
-}
-
-void
-VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
-{
-  setValue(SETTING_LOCAL_GEOIP_DATABASE, databaseFile);
-}
-
-QString 
-VidaliaSettings::pluginPath() const
-{
-  return QDir::convertSeparators(value(SETTING_PLUGIN_PATH).toString());
-}
-
-void 
-VidaliaSettings::setPluginPath(const QString &path)
-{
-  setValue(SETTING_PLUGIN_PATH, path);
-}
-
-/** Get the icon preference */
-VidaliaSettings::IconPosition
-VidaliaSettings::getIconPref()
-{
-  return fromString(value(SETTING_ICON_PREF).toString());
-}
-
-/** Set the icon preference */
-void
-VidaliaSettings::setIconPref(const IconPosition iconPref)
-{
-  setValue(SETTING_ICON_PREF, toString(iconPref));
-}
-
-QString
-VidaliaSettings::toString(const IconPosition iconPref)
-{
-  switch(iconPref) {
-  case Dock: return "Dock";
-  case Tray: return "Tray";
-  default: return "Both";
-  }
-}
-
-VidaliaSettings::IconPosition
-VidaliaSettings::fromString(QString iconPref)
-{
-  if(iconPref == "Dock") return Dock;
-  if(iconPref == "Tray") return Tray;
-
-  return Both;
-}
-
-bool
-<<<<<<< HEAD
-VidaliaSettings::skipVersionCheck() const
-{
-  return value(SETTING_SKIP_VERSION_CHECK).toBool();
-=======
-VidaliaSettings::rememberShutdown()
-{
-  return value(SETTING_REMEMBER_SHUTDOWN).toBool();
-}
-
-void
-VidaliaSettings::setRememberShutdown(bool val)
-{
-  setValue(SETTING_REMEMBER_SHUTDOWN, val);
->>>>>>> bug4577_remember
-}
diff --git a/src/vidalia/config/VidaliaSettings.h~ b/src/vidalia/config/VidaliaSettings.h~
deleted file mode 100644
index 75c0b7a..0000000
--- a/src/vidalia/config/VidaliaSettings.h~
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
-**  including this file, may be copied, modified, propagated, or distributed 
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file VidaliaSettings.h
-** \brief General Vidalia settings, such as language and interface style
-*/
-
-#ifndef _VIDALIASETTINGS_H
-#define _VIDALIASETTINGS_H
-
-#include "VSettings.h"
-
-#include <QDateTime>
-
-/** Public setting keys */
-#define SETTING_REMEMBER_SHUTDOWN   "RememberShutdown"
-
-/** Handles saving and restoring Vidalia's settings, such as the
- * location of Tor, the control port, etc.
- *
- * NOTE: Qt 4.1 documentation states that constructing a QSettings object is
- * "very fast", so we shouldn't need to create a global instance of this
- * class.
- */
-class VidaliaSettings : public VSettings
-{
-  Q_OBJECT
-
-public:
-  enum IconPosition {
-    Tray,
-    Dock,
-    Both,
-  };
-
-  /** Default constructor. */
-  VidaliaSettings();
-
-  /** Gets the currently preferred language code for Vidalia. */
-  QString getLanguageCode();
-  /** Saves the preferred language code. */
-  void setLanguageCode(QString languageCode);
- 
-  /** Gets the interface style key (e.g., "windows", "motif", etc.) */
-  QString getInterfaceStyle();
-  /** Sets the interface style key. */
-  void setInterfaceStyle(QString styleKey);
-  
-  /** Returns true if Vidalia should start Tor when it starts. */
-  bool runTorAtStart();
-  /** Set whether to run Tor when Vidalia starts. */
-  void setRunTorAtStart(bool run);
-
-  /** Returns true if Vidalia's main window should be visible when the
-   * application starts. */
-  bool showMainWindowAtStart();
-  /** Sets whether to show Vidalia's main window when the application starts. */
-  void setShowMainWindowAtStart(bool show);
-  
-  /** Returns true if Vidalia should start on system boot. */
-  bool runVidaliaOnBoot();
-  /** Set whether to run Vidalia on system boot. */
-  void setRunVidaliaOnBoot(bool run);
-
-  /** If browserDirectory is empty, returns a fully-qualified path to
-   * the web browser, including the executable name. If browserDirectory
-   * is set, then returns the basename of the configured web browser */
-  QString getBrowserExecutable() const;
-  /** Sets the location and name of the web browser executable to the given
-   * string. If set to the empty string, the browser will not be started. */
-  void setBrowserExecutable(const QString &browserExecutable);
-
-  /** Returns a fully-qualified path to the web browser directory */
-  QString getBrowserDirectory() const;
-  /** Sets the location and name of the web browser directory to the given string.
-   * If set to the empty string, the browser will not be started. */
-  void setBrowserDirectory(const QString &browserDirectory);
-
-  /** Returns a fully-qualified path to the IM client, including the
-   * executable name. */
-  QString getIMExecutable() const;
-  /** Sets the location and name of the IM client executable to the given
-   * string. If set to the empty string, the client will not be started. */
-  void setIMExecutable(const QString &IMExecutable);
-
-  /** Returns true if Vidalia should start a proxy application when it
-   * starts. */
-  bool runProxyAtStart();
-  /** Set whether to run a proxy application when Vidalia starts. */
-  void setRunProxyAtStart(bool run);
-
-  /** Returns a fully-qualified path to the proxy server, including the
-   * executable name. */
-  QString getProxyExecutable() const;
-  /** Sets the location and name of the proxy server executable to the given
-   * string. If set to the empty string, the proxy will not be started. */
-  void setProxyExecutable(const QString &proxyExecutable);
-
-  /** Returns a list containing additional command line arguments to be
-   * passed to ProxyExecutable */
-  QString getProxyExecutableArguments() const;
-  /** Sets the additional arguments to be passed to Proxy Executable */
-  void setProxyExecutableArguments(const QString &proxyExecutableArguments);
-  
-  /** Returns true if Vidalia should automatically check for software updates.
-   */
-  bool isAutoUpdateEnabled() const;
-  /** Sets to <b>enabled</b> whether Vidalia should automatically check for
-   * software updates or not. */
-  void setAutoUpdateEnabled(bool enabled);
-
-  /** Returns the time at which Vidalia last checked for software updates. */
-  QDateTime lastCheckedForUpdates() const;
-  /** Sets to <b>checkedAt</b> the time at which Vidalia last checked for
-   * available software updates. */
-  void setLastCheckedForUpdates(const QDateTime &checkedAt);
-
-  /** Returns true if Vidalia is currently configured to use a local GeoIP
-   * database. */
-  bool useLocalGeoIpDatabase() const;
-  /** Enables or disables use of a local GeoIP database. */
-  void setUseLocalGeoIpDatabase(bool enabled);
-
-  /** Returns the file, if set, to be used as the local GeoIP database. */
-  QString localGeoIpDatabase() const;
-  /** Sets the file to use as a local GeoIP database. */
-  void setLocalGeoIpDatabase(const QString &databaseFile);
-
-  /** Returns the path where the plugins live */
-  QString pluginPath() const;
-  /** Sets the path where the plugins live */
-  void setPluginPath(const QString &path);
-
-  /** Get the icon preference */
-  IconPosition getIconPref();
-
-  /** Set the icon preference */
-  void setIconPref(const IconPosition iconPref);
-  QString toString(const IconPosition iconPref);
-  IconPosition fromString(QString iconPref);
-
-<<<<<<< HEAD
-  /** Returns true if Vidalia should skip the version check for tor */
-  bool skipVersionCheck() const;
-=======
-  /** Returns true if Vidalia should not ask if the user wants to shutdown 
-   *  tor gracefully */
-  bool rememberShutdown();
-  /** Sets RememberShutdown to val */
-  void setRememberShutdown(bool val);
->>>>>>> bug4577_remember
-};
-
-#endif
-





More information about the tor-commits mailing list