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

[vidalia-svn] r2091: Fix a bug in the network map that would cause the user to so (in trunk: . src/gui/network)



Author: edmanm
Date: 2007-10-25 00:27:52 -0400 (Thu, 25 Oct 2007)
New Revision: 2091

Modified:
   trunk/
   trunk/CHANGELOG
   trunk/src/gui/network/circuitlistwidget.cpp
   trunk/src/gui/network/circuitlistwidget.h
   trunk/src/gui/network/netviewer.ui
   trunk/src/gui/network/routerlistwidget.cpp
   trunk/src/gui/network/routerlistwidget.h
Log:
 r2240@lysithea:  edmanm | 2007-10-25 00:27:45 -0400
 Fix a bug in the network map that would cause the user to sometimes be
 unable to select a circuit or server after clicking and dragging the
 mouse in one of the lists (Ticket #269). Also take this opportunity to save a
 little bit of memory by creating the context menus on demand and cleaning up
 when they're closed, instead of allocating them on startup and cleaning up
 only on exit.



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

Modified: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/CHANGELOG	2007-10-25 04:27:52 UTC (rev 2091)
@@ -13,6 +13,9 @@
     like the 'Network' and 'Server' settings pages in the future.
   o If we prompt the user to enter a control password and they enter one,
     don't keep trying to use our randomly generated password.
+  o Fix a bug in the network map that would cause the user to sometimes be
+    unable to select a circuit or server after clicking and dragging the mouse
+    in one of the lists. (Ticket #269)
   o Stop leaking memory for pretty much every circuit we plotted on the network
     map. Found by Roger Dingledine and his Valgrind.
   o Stop leaking memory if TorMapWidget::addRouter() is called for a router

Modified: trunk/src/gui/network/circuitlistwidget.cpp
===================================================================
--- trunk/src/gui/network/circuitlistwidget.cpp	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/src/gui/network/circuitlistwidget.cpp	2007-10-25 04:27:52 UTC (rev 2091)
@@ -49,54 +49,59 @@
   /* Find out when a circuit has been selected */
   connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
           this, SLOT(onSelectionChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
-
-  /* Set up the circuit item context menu */
-  _circuitContextMenu = new QMenu(this);
-  _zoomCircuitAct = new QAction(QIcon(IMG_ZOOM), tr("Zoom to Circuit"), this);
-  _closeCircuitAct = new QAction(QIcon(IMG_CLOSE), tr("Close Circuit"), this);
-  _circuitContextMenu->addAction(_zoomCircuitAct);
-  _circuitContextMenu->addSeparator();
-  _circuitContextMenu->addAction(_closeCircuitAct);
-  /* Set up the stream item context menu */
-  _streamContextMenu = new QMenu(this);
-  _closeStreamAct = new QAction(QIcon(IMG_CLOSE), tr("Close Stream"), this);
-  _streamContextMenu->addAction(_closeStreamAct);
+  connect(this, SIGNAL(customContextMenuRequested(QPoint)),
+          this, SLOT(customContextMenuRequested(QPoint)));
 }
 
-/** Called when the user presses and releases a mouse button. If the event
- * indicates a right-click and a circuit or stream is selected, an appropriate
- * context menu will be displayed. */
+/** Called when the user requests a context menu on a circuit or stream in the
+ * list and displays a context menu appropriate for whichever type of item is
+ * currently selected. */
 void
-CircuitListWidget::mouseReleaseEvent(QMouseEvent *e)
+CircuitListWidget::customContextMenuRequested(const QPoint &pos)
 {
-  if (e->button() == Qt::RightButton) {
-    /* Find out which item was right-clicked */
-    QTreeWidgetItem *item = itemAt(e->pos());
-    if (!item) {
+  QMenu menu(this);
+
+  /* Find out which item was right-clicked */
+  QTreeWidgetItem *item = itemAt(pos);
+  if (!item)
+    return;
+    
+  if (!item->parent()) {
+    /* A circuit was selected */
+    CircuitItem *circuitItem = dynamic_cast<CircuitItem *>(item);
+    if (!circuitItem)
       return;
-    }
-    
-    QPoint pos = e->globalPos();
-    if (!item->parent()) {
-      /* Circuit was right-clicked */
-      Circuit circ   = ((CircuitItem *)item)->circuit();
-      quint64 circid = circ.id();
-      _zoomCircuitAct->setEnabled((circ.status() == Circuit::Built));
+
+    /* Set up the circuit context menu */
+    QAction *zoomAct  = new QAction(QIcon(IMG_ZOOM),tr("Zoom to Circuit"),this);
+    QAction *closeAct = new QAction(QIcon(IMG_CLOSE), tr("Close Circuit"),this);
+    zoomAct->setEnabled(circuitItem->circuit().status() == Circuit::Built);
+    menu.addAction(zoomAct);
+    menu.addSeparator();
+    menu.addAction(closeAct);
       
-      QAction* action = _circuitContextMenu->exec(pos);
-      if (action == _closeCircuitAct) {
-        emit closeCircuit(circid);
-      } else if (action == _zoomCircuitAct) {
-        emit zoomToCircuit(circid);
-      }
-    } else {
-      /* Stream was right-clicked */
-      quint64 streamid = ((StreamItem *)item)->id();
-      QAction* action = _streamContextMenu->exec(pos);
-      if (action == _closeStreamAct) {
-        emit closeStream(streamid);
-      }
-    }
+    /* Display the context menu and find out which (if any) action was
+     * selected */
+    QAction* action = menu.exec(mapToGlobal(pos));
+    if (action == closeAct)
+      emit closeCircuit(circuitItem->id());
+    else if (action == zoomAct)
+      emit zoomToCircuit(circuitItem->id());
+  } else {
+    /* A stream was selected */
+    StreamItem *streamItem = dynamic_cast<StreamItem *>(item);
+    if (!streamItem)
+      return;
+ 
+    /* Set up the stream context menu */
+    QAction *closeAct = new QAction(QIcon(IMG_ZOOM), tr("Close Stream"), this);
+    menu.addAction(closeAct);
+
+    /* Display the context menu and find out which (if any) action was
+     * selected */
+    QAction* action = menu.exec(mapToGlobal(pos));
+    if (action == closeAct)
+      emit closeStream(streamItem->id());
   }
 }
 

Modified: trunk/src/gui/network/circuitlistwidget.h
===================================================================
--- trunk/src/gui/network/circuitlistwidget.h	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/src/gui/network/circuitlistwidget.h	2007-10-25 04:27:52 UTC (rev 2091)
@@ -77,10 +77,6 @@
   /** Clears all circuits and streams from the list. */
   void clearCircuits();
 
-protected:
-  /** Called when the user presses and releases a mouse button. */ 
-  virtual void mouseReleaseEvent(QMouseEvent *e);
-
 private slots:
   /** Removes the first circuit scheduled to be removed.*/
   void removeCircuit(); 
@@ -88,7 +84,11 @@
   void removeStream();
   /** Called when the current item selectio has changed. */
   void onSelectionChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev);
-  
+  /** Called when the user requests a context menu on a circuit or stream in
+   * the list and displays a context menu appropriate for whichever type of
+   * item is currently selected. */
+  void customContextMenuRequested(const QPoint &pos);
+
 private:
   /** Removes the given circuit item and all streams on that circuit. */
   void removeCircuit(CircuitItem *circuit);
@@ -103,13 +103,6 @@
   /** Schedules a stream to be removed after the given timeout. */
   void scheduleStreamRemoval(StreamItem *stream, int delay);
 
-  /* Circuit and stream context menus and items */
-  QMenu* _circuitContextMenu; /**< Context menu for circuit items. */
-  QAction* _closeCircuitAct;  /**< Closes a circuit. */
-  QAction* _zoomCircuitAct;   /**< Zoom to a circuit. */
-  QMenu* _streamContextMenu;  /**< Context menu for stream items. */
-  QAction* _closeStreamAct;   /**< Closes a stream. */
-
   /** List of circuit items to be removed. */
   QList<CircuitItem *> _circuitRemovalList;
   /** List of stream items to be removed. */

Modified: trunk/src/gui/network/netviewer.ui
===================================================================
--- trunk/src/gui/network/netviewer.ui	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/src/gui/network/netviewer.ui	2007-10-25 04:27:52 UTC (rev 2091)
@@ -64,7 +64,7 @@
         </size>
        </property>
        <property name="contextMenuPolicy" >
-        <enum>Qt::NoContextMenu</enum>
+        <enum>Qt::CustomContextMenu</enum>
        </property>
        <property name="statusTip" >
         <string/>
@@ -171,7 +171,7 @@
           </size>
          </property>
          <property name="contextMenuPolicy" >
-          <enum>Qt::NoContextMenu</enum>
+          <enum>Qt::CustomContextMenu</enum>
          </property>
          <property name="statusTip" >
           <string/>

Modified: trunk/src/gui/network/routerlistwidget.cpp
===================================================================
--- trunk/src/gui/network/routerlistwidget.cpp	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/src/gui/network/routerlistwidget.cpp	2007-10-25 04:27:52 UTC (rev 2091)
@@ -49,34 +49,32 @@
   /* Find out when the selected item has changed. */
   connect(this, SIGNAL(itemSelectionChanged()), 
           this, SLOT(onSelectionChanged()));
-
-  /* Set up the router item context menu */
-  _routerContextMenu = new QMenu(this);
-  _zoomToRouterAct = new QAction(QIcon(IMG_ZOOM), tr("Zoom to Relay"), this);
-  _routerContextMenu->addAction(_zoomToRouterAct);
+  connect(this, SIGNAL(customContextMenuRequested(QPoint)),
+          this, SLOT(customContextMenuRequested(QPoint)));
 }
 
-/** Called when the user presses and releases a mouse button. If the event
- * indicates a right-click on a router item, a context menu will be displayed
- * providing a list of actions, including zooming in on the server. */
+/** Called when the user requests a context menu for a router in the list. A
+ * context menu will be displayed providing a list of actions, including
+ * zooming in on the server. */
 void
-RouterListWidget::mouseReleaseEvent(QMouseEvent *e)
+RouterListWidget::customContextMenuRequested(const QPoint &pos)
 {
-  if (e->button() == Qt::RightButton) {
-    /* Find out which server was right-clicked */
-    RouterListItem *item = (RouterListItem *)itemAt(e->pos());
-    if (!item) {
-      return;
-    }
+  QMenu menu(this);
 
-    /* Display a context menu for this router item */
-    QPoint pos = e->globalPos();
-    QAction *action = _routerContextMenu->exec(pos);
-    if (action == _zoomToRouterAct) {
-      /* Zoom in on this router */
-      emit zoomToRouter(item->id());
-    }
-  }
+  /* Find out which (if any) router in the list is selected */
+  RouterListItem *item = dynamic_cast<RouterListItem *>(itemAt(pos));
+  if (!item)
+    return;
+  
+  /* Set up the context menu */
+  QAction *zoomAction =
+    new QAction(QIcon(IMG_ZOOM), tr("Zoom to Relay"), &menu);
+  menu.addAction(zoomAction);
+  
+  /* Display the menu and find out which (if any) action was selected */
+  QAction *action = menu.exec(mapToGlobal(pos));
+  if (action == zoomAction)
+    emit zoomToRouter(item->id());
 }
 
 /** Deselects all currently selected routers. */

Modified: trunk/src/gui/network/routerlistwidget.h
===================================================================
--- trunk/src/gui/network/routerlistwidget.h	2007-10-25 02:28:25 UTC (rev 2090)
+++ trunk/src/gui/network/routerlistwidget.h	2007-10-25 04:27:52 UTC (rev 2091)
@@ -78,13 +78,12 @@
   /** Clears the list of router items. */
   void clearRouters();
  
-protected:
-  /** Called when the user presses and releases a moust button. */
-  virtual void mouseReleaseEvent(QMouseEvent *e);
-  
 private slots:
   /** Called when the user clicks on an item in the list. */
   void onSelectionChanged();
+  /** Called when the user requests a context menu for some router in the
+   * list. */  
+  void customContextMenuRequested(const QPoint &pos);
 
 protected:
   /** Called when the user presses a key while the list has focus. */
@@ -96,10 +95,6 @@
 
   /** Maps a server ID to that server's list item. */
   QHash<QString,RouterListItem*> _idmap;
-  
-  /** Router item context menu and items. */
-  QMenu* _routerContextMenu; /**< Context menu for router items. */
-  QAction* _zoomToRouterAct; /**< Zooms in on the selected router. */
   quint32  _onlineRouterCount; /**< Number of online routers. */
 };