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

[vidalia-svn] r1966: Move the logic for applying modified settings to Tor after i (in trunk: . src/gui src/gui/config)



Author: edmanm
Date: 2007-10-02 23:34:40 -0400 (Tue, 02 Oct 2007)
New Revision: 1966

Modified:
   trunk/
   trunk/src/gui/config/configdialog.cpp
   trunk/src/gui/config/configdialog.h
   trunk/src/gui/config/serverpage.cpp
   trunk/src/gui/config/serverpage.h
   trunk/src/gui/mainwindow.cpp
   trunk/src/gui/mainwindow.h
Log:
 r1999@lysithea:  edmanm | 2007-10-02 23:33:43 -0400
 Move the logic for applying modified settings to Tor after it has started out
 from MainWindow and into ConfigDialog. At the moment this only affects server
 settings, but it will make more sense once we also have to worry about
 modified network and hidden service settings.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /local/vidalia/trunk [r1999] on dc66be73-d13e-47ba-a267-8dc7cda68c65

Modified: trunk/src/gui/config/configdialog.cpp
===================================================================
--- trunk/src/gui/config/configdialog.cpp	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/config/configdialog.cpp	2007-10-03 03:34:40 UTC (rev 1966)
@@ -26,6 +26,7 @@
  */
 
 #include <gui/common/vmessagebox.h>
+#include <util/html.h>
 #include <vidalia.h>
 
 #include "configdialog.h"
@@ -49,6 +50,9 @@
 
   /* Invoke the Qt Designer generated QObject setup routine */
   ui.setupUi(this);
+  
+  connect(Vidalia::torControl(), SIGNAL(authenticated()),
+                           this, SLOT(applyChanges()));
 
   /* Create the config pages and actions */
   QActionGroup *grp = new QActionGroup(this);
@@ -158,7 +162,9 @@
       
       /* Show the user what went wrong */
       VMessageBox::warning(this, 
-        tr("Error Saving Configuration"), errmsg,
+        tr("Error Saving Settings"), 
+        p(tr("Vidalia was unable to save your %1 settings.")
+             .arg(page->title())) + p(errmsg),
         VMessageBox::Ok);
 
       /* Don't process the rest of the pages */
@@ -168,6 +174,34 @@
   QMainWindow::close();
 }
 
+/** Called after Vidalia has authenticated to Tor and applies any changes 68
+ * made since the last time they were applied. */
+void
+ConfigDialog::applyChanges()
+{
+  QString errmsg;
+  
+  foreach (ConfigPage *page, ui.stackPages->pages()) {
+    if (!page->changedSinceLastApply())
+      continue;
+    if (!page->apply(errmsg)) {
+      /* Failed to apply the changes to Tor */
+      int ret = VMessageBox::warning(this,
+                  tr("Error Applying Settings"),
+                  p(tr("Vidalia was unable to apply your %1 settings "
+                       "to Tor.").arg(page->title()))
+                    + p(errmsg),
+                  VMessageBox::ShowSettings|VMessageBox::Default,
+                  VMessageBox::Cancel|VMessageBox::Escape);
+      if (ret == VMessageBox::ShowSettings) {
+        showWindow();
+        ui.stackPages->setCurrentPage(page);
+        break;
+      }
+    }
+  }
+}
+
 /** Shows help information about the configuration dialog. */
 void
 ConfigDialog::help()

Modified: trunk/src/gui/config/configdialog.h
===================================================================
--- trunk/src/gui/config/configdialog.h	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/config/configdialog.h	2007-10-03 03:34:40 UTC (rev 1966)
@@ -64,6 +64,9 @@
   void showWindow(Page page = General);
 
 private slots:
+  /** Called after Vidalia has authenticated to Tor and applies any changes
+   * made since the last time they were applied. */
+  void applyChanges();
   /** Called when user clicks "Save Settings" */
   void saveChanges();
   /** Called when user clicks "Help" */
@@ -76,7 +79,7 @@
   QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
   /** Adds a new action to the toolbar. */
   void addAction(QAction *action, const char *slot = 0);
-
+  
   /** Qt Designer generated object */
   Ui::ConfigDialog ui;
 };

Modified: trunk/src/gui/config/serverpage.cpp
===================================================================
--- trunk/src/gui/config/serverpage.cpp	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/config/serverpage.cpp	2007-10-03 03:34:40 UTC (rev 1966)
@@ -73,7 +73,7 @@
 
 /** Constructor */
 ServerPage::ServerPage(QWidget *parent)
-: ConfigPage(parent)
+: ConfigPage(parent, tr("Server"))
 {
   /* Invoke the Qt Designer generated object setup routine */
   ui.setupUi(this);
@@ -143,15 +143,31 @@
 
   /* If we're connected to Tor and we've changed the server settings, attempt
    * to apply the new settings now. */
-  if (_torControl->isConnected() && _settings->changedSinceLastApply()) {
-    if (!_settings->apply(&errmsg)) {
+  if (_torControl->isConnected() && changedSinceLastApply())
+    if (!apply(errmsg)) {
       _settings->revert();
       return false;
     }
-  }
   return true;
 }
 
+/** Returns true if the user has changed their server settings since the
+ * last time they were applied to Tor. */
+bool
+ServerPage::changedSinceLastApply()
+{
+  return _settings->changedSinceLastApply();
+}
+
+/** Applies the server configuration settings to Tor. Returns true if the
+ * settings were applied successfully. Otherwise, <b>errmsg</b> is
+ * set and false is returned. */
+bool
+ServerPage::apply(QString &errmsg)
+{
+  return _settings->apply(&errmsg);
+}
+
 /** Loads previously saved settings */
 void
 ServerPage::load()

Modified: trunk/src/gui/config/serverpage.h
===================================================================
--- trunk/src/gui/config/serverpage.h	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/config/serverpage.h	2007-10-03 03:34:40 UTC (rev 1966)
@@ -52,6 +52,13 @@
   bool save(QString &errmsg);
   /** Loads the settings for this page */
   void load();
+  /** Applies the server configuration settings to Tor. Returns true if the
+   * settings were applied successfully. Otherwise, <b>errmsg</b> is set and
+   * false is returned. */
+  bool apply(QString &errmsg);
+  /** Returns true if the user has changed their server settings since the
+   * last time they were applied to Tor. */
+  bool changedSinceLastApply();
 
 private slots:
   /** Called when the user clicks the bandwidth help button */

Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/mainwindow.cpp	2007-10-03 03:34:40 UTC (rev 1966)
@@ -114,10 +114,11 @@
   ui.setupUi(this);
 
   /* Create all the dialogs of which we only want one instance */
-  _messageLog = new MessageLog();
+  _messageLog     = new MessageLog();
   _bandwidthGraph = new BandwidthGraph();
-  _netViewer = new NetViewer();
-  
+  _netViewer      = new NetViewer();
+  _configDialog   = new ConfigDialog();
+
   /* Create the actions that will go in the tray menu */
   createActions();
   /* Creates a tray icon with a context menu and adds it to the system's
@@ -127,7 +128,7 @@
   _status = Unset;
   updateTorStatus(Stopped);
   
-  /* Create a new TorControl object, used to communicate with and manipulate Tor */
+  /* Create a new TorControl object, used to communicate with Tor */
   _torControl = Vidalia::torControl(); 
   connect(_torControl, SIGNAL(started()), this, SLOT(started()));
   connect(_torControl, SIGNAL(startFailed(QString)),
@@ -810,33 +811,12 @@
   ui.lblNewIdentity->setEnabled(true);
 
   /* Register for any pertinent asynchronous events. */
-  if (!_torControl->setEvents(&errmsg))
+  if (!_torControl->setEvents(&errmsg)) {
     VMessageBox::warning(this, tr("Error Registering for Events"),
       p(tr("Vidalia was unable to register for Tor events. "
            "Many of Vidalia's features may be unavailable."))
          + p(errmsg),
       VMessageBox::Ok);
-  
-  /* If the user changed some of the server's settings while Tor wasn't 
-   * running, then we better let Tor know about the changes now. */
-  if (serverSettings.changedSinceLastApply()) {
-    if (!serverSettings.apply(&errmsg)) {
-      int ret = VMessageBox::warning(this, 
-                  tr("Error Applying Server Settings"),
-                  p(tr("Vidalia was unable to apply your server's settings."))
-                    + p(errmsg),
-                  VMessageBox::Ok|VMessageBox::Escape, 
-                  VMessageBox::ShowSettings|VMessageBox::Default,
-                  VMessageBox::ShowLog);
-
-      if (ret == VMessageBox::ShowSettings) {
-        /* Show the config dialog with the server page already shown. */
-        showConfigDialog(ConfigDialog::Server);
-      } else if (ret == VMessageBox::ShowLog) {
-        /* Show the message log. */
-        _messageLog->showWindow(); 
-      }
-    }
   }
 }
 
@@ -950,10 +930,7 @@
 void
 MainWindow::showConfigDialog(ConfigDialog::Page page)
 {
-  static ConfigDialog *configDialog = 0;
-  if (!configDialog)
-    configDialog = new ConfigDialog(this);
-  configDialog->showWindow(page);
+  _configDialog->showWindow(page);
 }
 
 /** Displays the Configuration dialog, set to the Server page. */

Modified: trunk/src/gui/mainwindow.h
===================================================================
--- trunk/src/gui/mainwindow.h	2007-10-03 03:34:32 UTC (rev 1965)
+++ trunk/src/gui/mainwindow.h	2007-10-03 03:34:40 UTC (rev 1966)
@@ -163,6 +163,8 @@
   BandwidthGraph* _bandwidthGraph;
   /** A NetViewer object which displays the Tor network graphically */
   NetViewer* _netViewer;
+  /** A ConfigDialog object which lets the user configure Tor and Vidalia */
+  ConfigDialog* _configDialog;
   /** A TorControl object that handles communication with Tor */
   TorControl* _torControl;