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

[vidalia-svn] r1612: Add a "Cancel" button to the message box that asks server op (in trunk: . src/gui)



Author: edmanm
Date: 2007-01-26 22:55:43 -0500 (Fri, 26 Jan 2007)
New Revision: 1612

Modified:
   trunk/
   trunk/src/gui/mainwindow.cpp
   trunk/src/gui/mainwindow.h
Log:
 r1624@adrastea:  edmanm | 2007-01-26 22:52:55 -0500
 Add a "Cancel" button to the message box that asks server operators if they
 want to delay server shutdown or kill Tor right away. (Ticket #222)



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /vidalia/local/trunk [r1624] on 54b3572a-7227-0410-958f-53ecd705b71a

Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp	2007-01-25 03:24:21 UTC (rev 1611)
+++ trunk/src/gui/mainwindow.cpp	2007-01-27 03:55:43 UTC (rev 1612)
@@ -171,15 +171,11 @@
      * shutdown. If we do, then close Vidalia only when Tor stops. Otherwise,
      * kill Tor and bail now. */
     ServerSettings settings(_torControl);
-    if (_torControl->isConnected() && settings.isServerEnabled() 
-                                   && !_delayedShutdownStarted) {
-      if (delayServerShutdown()) {
-        /* Close when Tor stops */
-        connect(_torControl, SIGNAL(stopped()), this, SLOT(shutdown()));
-        _delayedShutdownStarted = _torControl->signal(TorSignal::Shutdown);
-        updateTrayIcon(IMG_TOR_STOPPING, tr("Tor is stopping"));
-        return;
-      }
+    if (_torControl->isConnected() && settings.isServerEnabled()) {
+      connect(_torControl, SIGNAL(stopped()), this, SLOT(shutdown()));
+      if (!stop())
+        disconnect(_torControl, SIGNAL(stopped()), this, SLOT(shutdown()));
+      return;
     }
   }
   /* Shut down Tor (if necessary) and exit Vidalia */
@@ -424,49 +420,45 @@
   }
 }
 
-/** Gives users the option of shutting down a server gracefully, giving
- * clients time to find a new circuit. Returns true if the timed server
- * shutdown was initiated successfully or false if we want to terminate
- * forcefully. */
-bool
-MainWindow::delayServerShutdown()
-{
-  /* Ask the user if they want to shutdown nicely. */
-  int response = VMessageBox::question(this, tr("Server is Enabled"),
-                  tr("You are currently running a Tor server. "
-                       "Terminating your server will interrupt any "
-                       "open connections from clients.\n\n"
-                       "Would you like to shutdown gracefully and "
-                       "give clients time to find a new server?"),
-                  VMessageBox::Yes, VMessageBox::No);
-
-  return (response == VMessageBox::Yes);
-}
-
 /** Disconnects the control socket and stops the Tor process. */
-void 
+bool
 MainWindow::stop()
 {
   ServerSettings server(_torControl);
   QString errmsg;
-  bool shutdown;
+  bool rc, delayShutdown = false;
   
   /* If we're running a server, give users the option of terminating
    * gracefully so clients have time to find new servers. */
-  if (server.isServerEnabled() && !_delayedShutdownStarted
-                               && delayServerShutdown()) {
-    /* Delayed server shutdown was started successfully. */
-    shutdown = _torControl->signal(TorSignal::Shutdown);
-    _delayedShutdownStarted = shutdown;
+  if (server.isServerEnabled() && !_delayedShutdownStarted) {
+    /* Ask the user if they want to shutdown nicely. */
+    int response = VMessageBox::question(this, tr("Server is Enabled"),
+                     tr("You are currently running a Tor server. "
+                        "Terminating your server will interrupt any "
+                        "open connections from clients.\n\n"
+                        "Would you like to shutdown gracefully and "
+                        "give clients time to find a new server?"),
+                        VMessageBox::Yes|VMessageBox::Default, 
+                        VMessageBox::No, 
+                        VMessageBox::Cancel|VMessageBox::Escape);
+    if (response == VMessageBox::Yes)
+      delayShutdown = true;
+    else if (response == VMessageBox::Cancel)
+      return false;
+  }
+
+  if (delayShutdown) {
+    /* Start a delayed shutdown */
+    rc = _torControl->signal(TorSignal::Shutdown, &errmsg);
+    _delayedShutdownStarted = rc;
   } else {
-    /* Terminate the Tor process immediately */
+    /* We want Tor to stop now, regardless of whether we're a server. */
     _isIntentionalExit = true;
-    if ((shutdown = _torControl->stop(&errmsg)) == true) {
+    if ((rc = _torControl->stop(&errmsg)) == true)
       _stopAct->setEnabled(false);
-    }
   }
-
-  if (shutdown) {
+  
+  if (rc) {
     /* Indicate that Tor is about to shut down */
     updateTrayIcon(IMG_TOR_STOPPING, tr("Tor is stopping"));
   } else {
@@ -480,10 +472,10 @@
       /* Show some troubleshooting help */
       Vidalia::help("troubleshooting.stop");
     }
-    
     /* Tor is still running since stopping failed */
     _isIntentionalExit = false;
   }
+  return rc;
 }
 
 /** Slot: Called when the Tor process has exited. It will adjust the tray

Modified: trunk/src/gui/mainwindow.h
===================================================================
--- trunk/src/gui/mainwindow.h	2007-01-25 03:24:21 UTC (rev 1611)
+++ trunk/src/gui/mainwindow.h	2007-01-27 03:55:43 UTC (rev 1612)
@@ -72,7 +72,7 @@
   /** Called when the Tor process has successfully started. */
   void started();
   /** Called when the user selects "Stop" form the menu. */
-  void stop();
+  bool stop();
   /** Called when the Tor process has exited, either expectedly or not. */
   void stopped(int errorCode, QProcess::ExitStatus exitStatus);
   /** Called when the control socket has connected to Tor. */
@@ -101,14 +101,12 @@
   void createMenuBar();
   /** Sets the tray icon's image and tooltip. */
   void updateTrayIcon(QString iconFile, QString tooltip = QString());
-  /** Starts a graceful, delayed server shutdown */
-  bool delayServerShutdown();
 
   /* Used to determine if the Tor process exiting was intentional or not */
   bool _isIntentionalExit;
   /** Tracks whether we started a delayed server shutdown. */
   bool _delayedShutdownStarted;
-  
+ 
   /** An AboutDialog object, used to display version information. */
   AboutDialog* _aboutDialog;
   /** A MessageLog object which handles logging Tor messages */