[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [vidalia/master] Add {Default, }{Plugin, Profile}Directory settings



commit e36785b3bc90fd33eed45e5ca6d334780d5fab30
Author: Tomás Touceda <chiiph@xxxxxxxxxxxxxx>
Date:   Thu Mar 22 19:54:20 2012 -0300

    Add {Default,}{Plugin,Profile}Directory settings
    
    If defined relative, make Vidalia's binary path the start point.
---
 src/vidalia/MainWindow.cpp             |   54 +++++++++++++++++++---------
 src/vidalia/config/VidaliaSettings.cpp |   61 ++++++++++++++++++++++++++++++-
 src/vidalia/config/VidaliaSettings.h   |   10 +++++
 3 files changed, 106 insertions(+), 19 deletions(-)

diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index e45919d..e116269 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -624,31 +624,43 @@ MainWindow::launchBrowserFromDirectory()
 {
   VidaliaSettings settings;
 
+  /** Directory for the browser */
   QString browserDirectory = settings.getBrowserDirectory();
-  QString browserDirectoryFilename = settings.getBrowserExecutable();
+  if(QDir(browserDirectory).isRelative())
+    browserDirectory = QDir::toNativeSeparators(QCoreApplication::applicationDirPath()
+                                                + "/" + browserDirectory);
 
-  _browserProcess->setEnvironment(updateBrowserEnv());
+  /** Relative path to the browser executable from the browserDirectory */
+  QString browserExecutable = QDir::toNativeSeparators(browserDirectory + "/" + settings.getBrowserExecutable());
 
-  /* The browser is in <browserDirectory>/App/Firefox/<browserDirectoryFilename> */
-  QString browserExecutable =
-    QDir::toNativeSeparators(browserDirectory + "/App/Firefox/" + browserDirectoryFilename);
-  /* The profile is in <browserDirectory>/Data/profile */
-  QString profileDir =
-    QDir::toNativeSeparators(browserDirectory + "/Data/profile");
+  /** Relative path to profile from the browserDirectory */
+  QString profileDirectory = QDir::toNativeSeparators(settings.getProfileDirectory());
+  /** Default profile to copy from */
+  QString defaultProfileDirectory = QDir::toNativeSeparators(settings.getDefaultProfileDirectory());
+
+  /** Relative path to the plugins directory from the browserDirectory */
+  QString pluginsDirectory = QDir::toNativeSeparators(settings.getPluginsDirectory());
+  /** Relative path to the default plugins directory from the browserDirectory */
+  QString defaultPluginsDirectory = QDir::toNativeSeparators(settings.getDefaultPluginsDirectory());
+
+  QString profileDir = browserDirectory + "/" + profileDirectory;
+
+  _browserProcess->setEnvironment(updateBrowserEnv());
 
-  /* Copy the profile directory if it's not already there */
   QDir browserDirObj = QDir(browserDirectory);
 
   /* Copy the profile directory if it's not already there */
-  if (!browserDirObj.exists("Data/profile")) {
-    browserDirObj.mkdir("Data/profile");
-    copy_dir(browserDirectory + "/App/DefaultData/profile", browserDirectory + "/Data/profile");
+  if (!browserDirObj.exists(profileDirectory)) {
+    browserDirObj.mkdir(profileDirectory);
+    copy_dir(browserDirectory + "/" + defaultProfileDirectory,
+             browserDirectory + "/" + profileDirectory);
   }
 
-  /* Copy the plugins directory if it's not already there */
-  if (!browserDirObj.exists("Data/plugins")) {
-    browserDirObj.mkdir("Data/plugins");
-    copy_dir(browserDirectory + "/App/DefaultData/plugins", browserDirectory + "/Data/plugins");
+  /* Copy the pluginss directory if it's not already there */
+  if (!browserDirObj.exists(pluginsDirectory)) {
+    browserDirObj.mkdir(pluginsDirectory);
+    copy_dir(browserDirectory + "/" + defaultPluginsDirectory,
+             browserDirectory + "/" + pluginsDirectory);
   }
 
   /* Build the command line arguments */
@@ -1054,6 +1066,8 @@ MainWindow::start()
   }
 
   QString torrc = settings.getTorrc();
+  if(QDir(QFileInfo(torrc).filePath()).isRelative())
+    torrc = QCoreApplication::applicationDirPath() + "/" + torrc;
 
   if(settings.bootstrap()) {
     QString boottorrc = settings.bootstrapFrom();
@@ -1075,6 +1089,9 @@ MainWindow::start()
 
   /* Specify Tor's data directory, if different from the default */
   QString dataDirectory = settings.getDataDirectory();
+  if(QDir(dataDirectory).isRelative())
+    dataDirectory = QCoreApplication::applicationDirPath() + "/" + dataDirectory;
+
   QString expDataDirectory = expand_filename(dataDirectory);
   if (!dataDirectory.isEmpty())
     args << "DataDirectory" << expDataDirectory;
@@ -1129,7 +1146,10 @@ MainWindow::start()
    * start. */
   _isIntentionalExit = true;
   /* Kick off the Tor process */
-  _torControl->start(settings.getExecutable(), args);
+  QString torExecutable = settings.getExecutable();
+  if(QDir(QFileInfo(torExecutable).filePath()).isRelative())
+    torExecutable = QCoreApplication::applicationDirPath() + "/" + torExecutable;
+  _torControl->start(torExecutable, args);
 }
 
 /** Called when the user changes a setting that needs Tor restarting */
diff --git a/src/vidalia/config/VidaliaSettings.cpp b/src/vidalia/config/VidaliaSettings.cpp
index 7273f10..7d317dc 100644
--- a/src/vidalia/config/VidaliaSettings.cpp
+++ b/src/vidalia/config/VidaliaSettings.cpp
@@ -29,8 +29,12 @@
 #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_BROWSER_EXECUTABLE        "BrowserExecutable"
+#define SETTING_BROWSER_DIRECTORY         "BrowserDirectory"
+#define SETTING_PROFILE_DIRECTORY          "ProfileDirectory"
+#define SETTING_DEFAULT_PROFILE_DIRECTORY  "DefaultProfileDirectory"
+#define SETTING_PLUGINS_DIRECTORY          "PluginsDirectory"
+#define SETTING_DEFAULT_PLUGINS_DIRECTORY  "DefaultPluginsDirectory"
 #define SETTING_IM_EXECUTABLE       "IMExecutable"
 #define SETTING_RUN_PROXY_AT_START  "RunProxyAtStart"
 #define SETTING_PROXY_EXECUTABLE    "ProxyExecutable"
@@ -86,6 +90,11 @@ VidaliaSettings::VidaliaSettings()
   setDefault(SETTING_LOCAL_GEOIP_DATABASE, "");
   setDefault(SETTING_ICON_PREF, Both);
   setDefault(SETTING_SKIP_VERSION_CHECK, false);
+
+  setDefault(SETTING_PROFILE_DIRECTORY, "");
+  setDefault(SETTING_DEFAULT_PROFILE_DIRECTORY, "");
+  setDefault(SETTING_PLUGINS_DIRECTORY, "");
+  setDefault(SETTING_DEFAULT_PLUGINS_DIRECTORY, "");
 }
 
 /** Gets the currently preferred language code for Vidalia. */
@@ -363,3 +372,51 @@ VidaliaSettings::skipVersionCheck() const
 {
   return value(SETTING_SKIP_VERSION_CHECK).toBool();
 }
+
+QString
+VidaliaSettings::getDefaultProfileDirectory() const
+{
+  return QDir::convertSeparators(value(SETTING_DEFAULT_PROFILE_DIRECTORY).toString());
+}
+
+void
+VidaliaSettings::setDefaultProfileDirectory(const QString &dir)
+{
+  setValue(SETTING_DEFAULT_PROFILE_DIRECTORY, dir);
+}
+
+QString
+VidaliaSettings::getProfileDirectory() const
+{
+  return QDir::convertSeparators(value(SETTING_PROFILE_DIRECTORY).toString());
+}
+
+void
+VidaliaSettings::setProfileDirectory(const QString &dir)
+{
+  setValue(SETTING_PROFILE_DIRECTORY, dir);
+}
+
+QString
+VidaliaSettings::getPluginsDirectory() const
+{
+  return QDir::convertSeparators(value(SETTING_PLUGINS_DIRECTORY).toString());
+}
+
+void
+VidaliaSettings::setPluginsDirectory(const QString &dir)
+{
+  setValue(SETTING_PLUGINS_DIRECTORY, dir);
+}
+
+QString
+VidaliaSettings::getDefaultPluginsDirectory() const
+{
+  return QDir::convertSeparators(value(SETTING_DEFAULT_PLUGINS_DIRECTORY).toString());
+}
+
+void
+VidaliaSettings::setDefaultPluginsDirectory(const QString &dir)
+{
+  setValue(SETTING_DEFAULT_PLUGINS_DIRECTORY, dir);
+}
diff --git a/src/vidalia/config/VidaliaSettings.h b/src/vidalia/config/VidaliaSettings.h
index b378d9b..6967740 100644
--- a/src/vidalia/config/VidaliaSettings.h
+++ b/src/vidalia/config/VidaliaSettings.h
@@ -82,6 +82,16 @@ public:
    * If set to the empty string, the browser will not be started. */
   void setBrowserDirectory(const QString &browserDirectory);
 
+  /** Browser directories */
+  QString getDefaultProfileDirectory() const;
+  void setDefaultProfileDirectory(const QString &dir);
+  QString getProfileDirectory() const;
+  void setProfileDirectory(const QString &dir);
+  QString getPluginsDirectory() const;
+  void setPluginsDirectory(const QString &dir);
+  QString getDefaultPluginsDirectory() const;
+  void setDefaultPluginsDirectory(const QString &dir);
+
   /** Returns a fully-qualified path to the IM client, including the
    * executable name. */
   QString getIMExecutable() const;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits