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

[vidalia-svn] r1987: Make ConfigDialog responsible for deciding when to apply the (in trunk: . src/gui/config)



Author: edmanm
Date: 2007-10-09 23:39:31 -0400 (Tue, 09 Oct 2007)
New Revision: 1987

Modified:
   trunk/
   trunk/src/gui/config/configdialog.cpp
   trunk/src/gui/config/configdialog.h
Log:
 r2019@lysithea:  edmanm | 2007-10-09 23:31:52 -0400
 Make ConfigDialog responsible for deciding when to apply the changes to Tor,
 instead of each individual setting page. Also let ConfigDialog be responsible
 for SAVECONFing, instead of the individual settings classes, so we don't try
 to SAVECONF after each page.



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

Modified: trunk/src/gui/config/configdialog.cpp
===================================================================
--- trunk/src/gui/config/configdialog.cpp	2007-10-10 03:39:19 UTC (rev 1986)
+++ trunk/src/gui/config/configdialog.cpp	2007-10-10 03:39:31 UTC (rev 1987)
@@ -27,6 +27,8 @@
 
 #include <gui/common/vmessagebox.h>
 #include <util/html.h>
+#include <serversettings.h>
+#include <networksettings.h>
 #include <vidalia.h>
 
 #include "configdialog.h"
@@ -148,7 +150,8 @@
   }
 }
 
-/** Saves changes made to settings. */
+/** Saves changes made to settings. If Tor is running and Vidalia is
+ * connected, we will also attempt to apply the changes to Tor. */
 void
 ConfigDialog::saveChanges()
 {
@@ -171,7 +174,10 @@
       return;
     }
   }
-  QMainWindow::close();
+  if (Vidalia::torControl()->isConnected())
+    applyChanges();
+  else
+    close();
 }
 
 /** Called after Vidalia has authenticated to Tor and applies any changes 68
@@ -180,7 +186,8 @@
 ConfigDialog::applyChanges()
 {
   QString errmsg;
-  
+  bool appliedChanges = false;
+
   foreach (ConfigPage *page, ui.stackPages->pages()) {
     if (!page->changedSinceLastApply())
       continue;
@@ -194,14 +201,35 @@
                   VMessageBox::ShowSettings|VMessageBox::Default,
                   VMessageBox::Cancel|VMessageBox::Escape);
       if (ret == VMessageBox::ShowSettings) {
+        /* Show the user the page with the bad settings */
         showWindow();
         ui.stackPages->setCurrentPage(page);
-        break;
+      } else {
+        /* The user clicked 'Cancel', so revert the failed settings */
+        page->revert();
+        close();
       }
+      return;
     }
+    appliedChanges = true;
   }
+  if (appliedChanges)
+    saveConf();      
+  close();
 }
 
+/** Sends Tor a SAVECONF to write its configuration to disk. If the SAVECONF
+ * is successful, then all settings are considered to be applied. */
+void
+ConfigDialog::saveConf()
+{
+  TorControl *tc = Vidalia::torControl();
+  if (tc->saveConf()) {
+    ServerSettings(tc).setChanged(false);
+    NetworkSettings(tc).setChanged(false);
+  }
+}
+
 /** 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-10 03:39:19 UTC (rev 1986)
+++ trunk/src/gui/config/configdialog.h	2007-10-10 03:39:31 UTC (rev 1987)
@@ -64,11 +64,17 @@
   void showWindow(Page page = General);
 
 private slots:
+  /** Called when user clicks "Save Settings". Saves their settings to
+   * Vidalia's configuration file. */
+  void saveChanges();
   /** 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();
+  /** Sends Tor a SAVECONF to write its configuration to disk. If the
+   * SAVECONF is successful, then all settings are considered to be
+   * applied. */
+  void saveConf();
+  
   /** Called when user clicks "Help" */
   void help();