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

[vidalia-svn] r1328: Add a virtual showWindow() method to VidaliaWindow so we're (in trunk/src: . gui gui/about gui/bwgraph gui/common gui/config gui/help/browser)



Author: edmanm
Date: 2006-10-12 22:42:54 -0400 (Thu, 12 Oct 2006)
New Revision: 1328

Modified:
   trunk/src/gui/about/aboutdialog.cpp
   trunk/src/gui/about/aboutdialog.h
   trunk/src/gui/bwgraph/bwgraph.cpp
   trunk/src/gui/bwgraph/bwgraph.h
   trunk/src/gui/common/vidaliawindow.cpp
   trunk/src/gui/common/vidaliawindow.h
   trunk/src/gui/config/configdialog.cpp
   trunk/src/gui/config/configdialog.h
   trunk/src/gui/help/browser/helpbrowser.cpp
   trunk/src/gui/help/browser/helpbrowser.h
   trunk/src/gui/mainwindow.cpp
   trunk/src/gui/mainwindow.h
   trunk/src/vidalia.cpp
Log:
Add a virtual showWindow() method to VidaliaWindow so we're not overriding
non-virtual QMainWindow::show(). Also create all main windows (bandwidth
graph, message log, etc.) without a parent so they aren't brought into focus
just because one of the other dialogs is. Reported by DJHasis.


Modified: trunk/src/gui/about/aboutdialog.cpp
===================================================================
--- trunk/src/gui/about/aboutdialog.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/about/aboutdialog.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -65,7 +65,7 @@
 
 /** Displays the About dialog window **/
 void
-AboutDialog::show()
+AboutDialog::showWindow()
 {
   /* Access the TorControl object to retrieve version */
   if (_torControl->isRunning()) {
@@ -77,6 +77,6 @@
   } else {
     ui.lblTorVersion->setText(tr("<Not Running>"));
   }
-  VidaliaWindow::show();
+  VidaliaWindow::showWindow();
 }
 

Modified: trunk/src/gui/about/aboutdialog.h
===================================================================
--- trunk/src/gui/about/aboutdialog.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/about/aboutdialog.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -40,9 +40,11 @@
 public:
   /** Default constructor **/
   AboutDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
-  /** Overriden QWidget.show() **/
-  void show();
 
+public slots:
+  /** Overriden VidaliaWindow::showWindow() */
+  void showWindow();
+
 private:
   /** Loads the license file */
   void loadLicense();

Modified: trunk/src/gui/bwgraph/bwgraph.cpp
===================================================================
--- trunk/src/gui/bwgraph/bwgraph.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/bwgraph/bwgraph.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -256,11 +256,11 @@
 
 /** Overloads the default show() slot so we can set opacity. */
 void
-BandwidthGraph::show()
+BandwidthGraph::showWindow()
 {
   /* Load saved settings */
   loadSettings();
   /* Show the window */
-  VidaliaWindow::show();
+  VidaliaWindow::showWindow();
 }
 

Modified: trunk/src/gui/bwgraph/bwgraph.h
===================================================================
--- trunk/src/gui/bwgraph/bwgraph.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/bwgraph/bwgraph.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -51,7 +51,7 @@
 
 public slots:
   /** Overloaded QWidget.show */
-  void show();
+  void showWindow();
 
 protected:
   /** Called to deliver a bandwidth update event from Tor. */

Modified: trunk/src/gui/common/vidaliawindow.cpp
===================================================================
--- trunk/src/gui/common/vidaliawindow.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/common/vidaliawindow.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -32,9 +32,7 @@
 #include <QKeySequence>
 #include "vidaliawindow.h"
 
-#include <QtDebug>
 
-
 /** Default constructor. */
 VidaliaWindow::VidaliaWindow(QString name, QWidget *parent, Qt::WFlags flags)
  : QMainWindow(parent, flags)
@@ -101,40 +99,38 @@
   _settings->setValue(key, value);
 }
 
-/** Overloaded QWidget::close() method. Saves the window state and closes the
- * window. Returns true if the window was closed. */
-bool
-VidaliaWindow::close()
-{
-  saveWindowState();
-  return QMainWindow::close();
-}
-
-/** Overloaded QWidget::show() */
+/** Overloaded QWidget::setVisible(). If this window is already visible and
+ * <b>visible</b> is true, this window will be brought to the top and given 
+ * focus. If <b>visible</b> is false, then the window state will be saved and
+ * this window will be hidden. */
 void
-VidaliaWindow::show()
+VidaliaWindow::setVisible(bool visible)
 {
-  /* If this is the first time this window is shown, restore its window
-   * position and size. */
-  if (!_previouslyShown) {
+  if (visible) {
+    /* If this is the first time this window is shown, restore its window
+     * position and size. */
+    if (!_previouslyShown) {
 #if !defined (Q_WS_WIN)
-    /* Use the standard palette on non-Windows, overriding whatever was 
-     * specified in the .ui file for this dialog. */
-    setPalette(QPalette());
+      /* Use the standard palette on non-Windows, overriding whatever was 
+       * specified in the .ui file for this dialog. */
+      setPalette(QPalette());
 #endif
     
-    restoreWindowState();
-    _previouslyShown = true;
-  }
+      restoreWindowState();
+      _previouslyShown = true;
+    }
 
-  /* Bring the window to the top, if it's already open. Otherwise, make the
-   * window visible. */
-  if (!this->isVisible()) {
-    QMainWindow::show();
+    /* Bring the window to the top, if it's already open. Otherwise, make the
+     * window visible. */
+    if (isVisible()) {
+      activateWindow();
+      setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
+      raise();
+    }
   } else {
-    activateWindow();
-    setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
-    raise();
+    /* Save the last size and position of this window. */
+    saveWindowState();
   }
+  QMainWindow::setVisible(visible);
 }
 

Modified: trunk/src/gui/common/vidaliawindow.h
===================================================================
--- trunk/src/gui/common/vidaliawindow.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/common/vidaliawindow.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -59,11 +59,11 @@
   void saveSetting(QString name, QVariant value);
 
 public slots:
-  /** Overloaded QWidget::close() method. Saves the window state and closes
-   * the window. Returns true if the window was closed. */
-  bool close();
-  /** Overloaded QWidget::show(). */
-  void show();
+  /** Shows or hides this window. */
+  virtual void setVisible(bool visible);
+  /** Show this window. This method really just exists for subclasses to 
+   * override, since QMainWindow::show() is non-virtual. */
+  virtual void showWindow() { QMainWindow::show(); }
 
 private:
   QString _name;  /**< Name associated with this window. */

Modified: trunk/src/gui/config/configdialog.cpp
===================================================================
--- trunk/src/gui/config/configdialog.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/config/configdialog.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -115,23 +115,14 @@
   connect(action, SIGNAL(triggered()), this, slot);
 }
 
-/** Overloads the default show so we can load settings */
+/** Shows the config dialog with focus set to the given page. */
 void
-ConfigDialog::show()
+ConfigDialog::showWindow(Page page)
 {
   /* Load saved settings */
   loadSettings();
-  /* Show the window */
-  VidaliaWindow::show();
-}
-
-/** Shows the config dialog with focus set to the given page. */
-void
-ConfigDialog::show(Page page)
-{
   /* Show the dialog. */
-  show();
-
+  VidaliaWindow::showWindow();
   /* Set the focus to the specified page. */
   ui.stackPages->setCurrentIndex((int)page);
 }

Modified: trunk/src/gui/config/configdialog.h
===================================================================
--- trunk/src/gui/config/configdialog.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/config/configdialog.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -57,10 +57,8 @@
   ConfigDialog(QWidget *parent = 0);
 
 public slots:
-  /** Called when this dialog is to be displayed */
-  void show();
   /** Shows the config dialog with focus set to the given page. */
-  void show(Page page);
+  void showWindow(Page page = General);
 
 private slots:
   /** Called when user clicks "Save Settings" */

Modified: trunk/src/gui/help/browser/helpbrowser.cpp
===================================================================
--- trunk/src/gui/help/browser/helpbrowser.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/help/browser/helpbrowser.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -423,11 +423,11 @@
 
 /** Overrides the default show method */
 void
-HelpBrowser::show(QString topic)
+HelpBrowser::showWindow(QString topic)
 {
   
   /* Bring the window to the top */
-  VidaliaWindow::show();
+  VidaliaWindow::showWindow();
 
   /* If a topic was specified, then go ahead and display it. */
   if (!topic.isEmpty()) {

Modified: trunk/src/gui/help/browser/helpbrowser.h
===================================================================
--- trunk/src/gui/help/browser/helpbrowser.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/help/browser/helpbrowser.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -50,7 +50,7 @@
  
 public slots:
   /** Overrides the default QWidget::show() */
-  void show(QString topic = QString());
+  void showWindow(QString topic = QString());
   
 private slots:
   /** Called when the user clicks "Find Next" */

Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/mainwindow.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -79,6 +79,13 @@
   /* Set Vidalia's application icon */
   setWindowIcon(QIcon(IMG_APP_ICON));
 
+  /* Create all the dialogs of which we only want one instance */
+  _aboutDialog = new AboutDialog();
+  _messageLog = new MessageLog();
+  _bandwidthGraph = new BandwidthGraph();
+  _netViewer = new NetViewer();
+  _configDialog = new ConfigDialog();
+  
   /* Create the actions that will go in the tray menu */
   createActions();
   
@@ -101,15 +108,6 @@
   connect(_torControl, SIGNAL(connectFailed(QString)), 
                  this,   SLOT(connectFailed(QString)));
 
-  /* Create a new MessageLog object so messages can be logged when not shown */
-  _messageLog = new MessageLog();
-  
-  /* Create a new BandwidthGraph object so we can monitor bandwidth usage */
-  _bandwidthGraph = new BandwidthGraph(this);
-
-  /* Create a new NetViewer object so we can monitor the network */
-  _netViewer = new NetViewer();
-
   /* Put an icon in the system tray to indicate the status of Tor */
   _trayIcon = new TrayIcon(IMG_TOR_STOPPED,
                            tr("Tor is Stopped"), _trayMenu);
@@ -179,27 +177,32 @@
   connect(_stopAct, SIGNAL(triggered()), this, SLOT(stop()));
   _stopAct->setEnabled(false);
 
-  _configAct = new QAction(QIcon(IMG_CONFIG), tr("Settings"), this);
-  connect(_configAct, SIGNAL(triggered()), this, SLOT(showConfig()));
-  
-  _aboutAct = new QAction(QIcon(IMG_ABOUT), tr("About"), this);
-  connect(_aboutAct, SIGNAL(triggered()), this, SLOT(showAbout()));
-  
   _exitAct = new QAction(QIcon(IMG_EXIT), tr("Exit"), this);
   connect(_exitAct, SIGNAL(triggered()), this, SLOT(close()));
 
   _bandwidthAct = new QAction(QIcon(IMG_BWGRAPH), tr("Bandwidth Graph"), this);
-  connect(_bandwidthAct, SIGNAL(triggered()), this, SLOT(showBandwidthGraph()));
+  connect(_bandwidthAct, SIGNAL(triggered()), 
+          _bandwidthGraph, SLOT(showWindow()));
 
   _messageAct = new QAction(QIcon(IMG_MESSAGELOG), tr("Message Log"), this);
-  connect(_messageAct, SIGNAL(triggered()), this, SLOT(showMessageLog()));
+  connect(_messageAct, SIGNAL(triggered()),
+          _messageLog, SLOT(showWindow()));
 
-  _helpAct = new QAction(QIcon(IMG_HELP), tr("Help"), this);
-  connect(_helpAct, SIGNAL(triggered()), vApp, SLOT(help()));
-
   _networkAct = new QAction(QIcon(IMG_NETWORK), tr("Network Map"), this);
-  connect(_networkAct, SIGNAL(triggered()), this, SLOT(showNetwork()));
+  connect(_networkAct, SIGNAL(triggered()), 
+          _netViewer, SLOT(showWindow()));
+  
+  _configAct = new QAction(QIcon(IMG_CONFIG), tr("Settings"), this);
+  connect(_configAct, SIGNAL(triggered()), 
+          _configDialog, SLOT(showWindow()));
+  
+  _aboutAct = new QAction(QIcon(IMG_ABOUT), tr("About"), this);
+  connect(_aboutAct, SIGNAL(triggered()), 
+          _aboutDialog, SLOT(showWindow()));
 
+  _helpAct = new QAction(QIcon(IMG_HELP), tr("Help"), this);
+  connect(_helpAct, SIGNAL(triggered()), vApp, SLOT(help()));
+  
   _newIdentityAct = new QAction(QIcon(IMG_IDENTITY), tr("New Identity"), this);
   _newIdentityAct->setEnabled(false);
   connect(_newIdentityAct, SIGNAL(triggered()), this, SLOT(newIdentity()));
@@ -315,7 +318,7 @@
     /* Show the settings dialog so the user can make sure they're pointing to
      * the correct Tor. */
      ConfigDialog* configDialog = new ConfigDialog(this);
-     configDialog->show(ConfigDialog::General);
+     configDialog->showWindow(ConfigDialog::General);
   } else if (response == VMessageBox::Help) {
     /* Show troubleshooting information about starting Tor */
     Vidalia::help("troubleshooting.start");
@@ -454,7 +457,7 @@
                      "about what happened to Tor before it exited."),
                   VMessageBox::Ok, VMessageBox::ShowLog, VMessageBox::Help);
       if (ret == VMessageBox::ShowLog) {
-        showMessageLog();  
+        _messageLog->showWindow();  
       } else if (ret == VMessageBox::Help) {
         Vidalia::help("troubleshooting.torexited");
       }
@@ -485,11 +488,10 @@
 
       if (ret == VMessageBox::ShowSettings) {
         /* Show the config dialog with the server page already shown. */
-        ConfigDialog* configDialog = new ConfigDialog(this);
-        configDialog->show(ConfigDialog::Server);
+        _configDialog->showWindow(ConfigDialog::Server);
       } else if (ret == VMessageBox::ShowLog) {
         /* Show the message log. */
-        showMessageLog(); 
+        _messageLog->showWindow(); 
       }
     }
   }
@@ -502,48 +504,6 @@
   _newIdentityAct->setEnabled(false);
 }
 
-/** Creates an instance of AboutDialog and shows it. If the About dialog is
- * already displayed, the existing instance will be brought to the foreground. */
-void 
-MainWindow::showAbout()
-{
-  static AboutDialog* aboutDialog = new AboutDialog(this);
-  aboutDialog->show();
-}
-
-/** Shows Message Log. If the message log is already displayed, the existing
- * instance will be brought to the foreground. */
-void
-MainWindow::showMessageLog()
-{
-  _messageLog->show();
-}
-
-/** Shows Bandwidth Graph. If the bandwidth graph is already displayed, the
- * existing instance will be brought to the foreground. */
-void
-MainWindow::showBandwidthGraph()
-{
-  _bandwidthGraph->show();
-}
-
-/** Shows Configuration dialog. If the config dialog is already displayed, the
- * existing instance will be brought to the foreground. */
-void
-MainWindow::showConfig()
-{
-  static ConfigDialog* configDialog = new ConfigDialog(this);
-  configDialog->show();
-}
-
-/** Shows the View Network dialog. If the View Network dialog is already
- *  displayed, the existing instance will be brought to the foreground. */
-void
-MainWindow::showNetwork()
-{
-  _netViewer->show();  
-}
-
 /** Called when the user selects the "New Identity" action from the menu. */
 void
 MainWindow::newIdentity()

Modified: trunk/src/gui/mainwindow.h
===================================================================
--- trunk/src/gui/mainwindow.h	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/gui/mainwindow.h	2006-10-13 02:42:54 UTC (rev 1328)
@@ -72,16 +72,6 @@
   void connectFailed(QString errmsg);
   /** Called when the control socket has been disconnected. */
   void disconnected();
-  /** Called when the user selects "About" from the menu. */
-  void showAbout();
-  /** Called when the user selects "Message Log" from the menu. */
-  void showMessageLog();
-  /** Called when the user selects "Bandwidth Graph" from the menu. */
-  void showBandwidthGraph();
-  /** Called when the user selects "Configuration" from the menu. */
-  void showConfig();
-  /** Called when the user selects "View Network" from the menu */
-  void showNetwork();
   /** Called when the user selects the "New Identity" action from the menu. */
   void newIdentity();
 
@@ -97,14 +87,18 @@
   
   /* Used to determine if the Tor process exiting was intentional or not */
   bool _isIntentionalExit;
+  
+  /** An AboutDialog object, used to display version information. */
+  AboutDialog* _aboutDialog;
   /** A MessageLog object which handles logging Tor messages */
   MessageLog* _messageLog;
   /** A BandwidthGraph object which handles monitoring Tor bandwidth usage */
   BandwidthGraph* _bandwidthGraph;
-  /** A HelpBrowser object which handles displaying help files */
-  HelpBrowser* _helpBrowser;
   /** A NetViewer object which displays the Tor network graphically */
   NetViewer* _netViewer;
+  /** A ConfigDialog object used to configure Tor and Vidalia's settings. */
+  ConfigDialog* _configDialog;
+  
   /** A TorControl object that handles communication with Tor */
   TorControl* _torControl;
   /** Instance of a tray icon that will appear in the system tray */

Modified: trunk/src/vidalia.cpp
===================================================================
--- trunk/src/vidalia.cpp	2006-10-12 23:27:14 UTC (rev 1327)
+++ trunk/src/vidalia.cpp	2006-10-13 02:42:54 UTC (rev 1328)
@@ -227,7 +227,7 @@
 void
 Vidalia::help(QString topic)
 {
-  _help->show(topic);
+  _help->showWindow(topic);
 }
 
 /** Returns the directory Vidalia uses for its data files. */