Changeset 2091

Show
Ignore:
Timestamp:
10/25/07 00:27:52 (10 months ago)
Author:
edmanm
Message:

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.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG

    r2090 r2091  
    1414  o If we prompt the user to enter a control password and they enter one, 
    1515    don't keep trying to use our randomly generated password. 
     16  o Fix a bug in the network map that would cause the user to sometimes be 
     17    unable to select a circuit or server after clicking and dragging the mouse 
     18    in one of the lists. (Ticket #269) 
    1619  o Stop leaking memory for pretty much every circuit we plotted on the network 
    1720    map. Found by Roger Dingledine and his Valgrind. 
  • trunk/src/gui/network/circuitlistwidget.cpp

    r1627 r2091  
    5050  connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), 
    5151          this, SLOT(onSelectionChanged(QTreeWidgetItem*,QTreeWidgetItem*))); 
    52  
    53   /* Set up the circuit item context menu */ 
    54   _circuitContextMenu = new QMenu(this); 
    55   _zoomCircuitAct = new QAction(QIcon(IMG_ZOOM), tr("Zoom to Circuit"), this); 
    56   _closeCircuitAct = new QAction(QIcon(IMG_CLOSE), tr("Close Circuit"), this); 
    57   _circuitContextMenu->addAction(_zoomCircuitAct); 
    58   _circuitContextMenu->addSeparator(); 
    59   _circuitContextMenu->addAction(_closeCircuitAct); 
    60   /* Set up the stream item context menu */ 
    61   _streamContextMenu = new QMenu(this); 
    62   _closeStreamAct = new QAction(QIcon(IMG_CLOSE), tr("Close Stream"), this); 
    63   _streamContextMenu->addAction(_closeStreamAct); 
    64 } 
    65  
    66 /** Called when the user presses and releases a mouse button. If the event 
    67  * indicates a right-click and a circuit or stream is selected, an appropriate 
    68  * context menu will be displayed. */ 
    69 void 
    70 CircuitListWidget::mouseReleaseEvent(QMouseEvent *e) 
    71 { 
    72   if (e->button() == Qt::RightButton) { 
    73     /* Find out which item was right-clicked */ 
    74     QTreeWidgetItem *item = itemAt(e->pos()); 
    75     if (!item) { 
     52  connect(this, SIGNAL(customContextMenuRequested(QPoint)), 
     53          this, SLOT(customContextMenuRequested(QPoint))); 
     54} 
     55 
     56/** Called when the user requests a context menu on a circuit or stream in the 
     57 * list and displays a context menu appropriate for whichever type of item is 
     58 * currently selected. */ 
     59void 
     60CircuitListWidget::customContextMenuRequested(const QPoint &pos) 
     61{ 
     62  QMenu menu(this); 
     63 
     64  /* Find out which item was right-clicked */ 
     65  QTreeWidgetItem *item = itemAt(pos); 
     66  if (!item) 
     67    return; 
     68     
     69  if (!item->parent()) { 
     70    /* A circuit was selected */ 
     71    CircuitItem *circuitItem = dynamic_cast<CircuitItem *>(item); 
     72    if (!circuitItem) 
    7673      return; 
    77     } 
    78      
    79     QPoint pos = e->globalPos(); 
    80     if (!item->parent()) { 
    81       /* Circuit was right-clicked */ 
    82       Circuit circ   = ((CircuitItem *)item)->circuit(); 
    83       quint64 circid = circ.id(); 
    84       _zoomCircuitAct->setEnabled((circ.status() == Circuit::Built)); 
     74 
     75    /* Set up the circuit context menu */ 
     76    QAction *zoomAct  = new QAction(QIcon(IMG_ZOOM),tr("Zoom to Circuit"),this); 
     77    QAction *closeAct = new QAction(QIcon(IMG_CLOSE), tr("Close Circuit"),this); 
     78    zoomAct->setEnabled(circuitItem->circuit().status() == Circuit::Built); 
     79    menu.addAction(zoomAct); 
     80    menu.addSeparator(); 
     81    menu.addAction(closeAct); 
    8582       
    86       QAction* action = _circuitContextMenu->exec(pos); 
    87       if (action == _closeCircuitAct) { 
    88         emit closeCircuit(circid); 
    89       } else if (action == _zoomCircuitAct) { 
    90         emit zoomToCircuit(circid); 
    91       } 
    92     } else { 
    93       /* Stream was right-clicked */ 
    94       quint64 streamid = ((StreamItem *)item)->id(); 
    95       QAction* action = _streamContextMenu->exec(pos); 
    96       if (action == _closeStreamAct) { 
    97         emit closeStream(streamid); 
    98       } 
    99     } 
     83    /* Display the context menu and find out which (if any) action was 
     84     * selected */ 
     85    QAction* action = menu.exec(mapToGlobal(pos)); 
     86    if (action == closeAct) 
     87      emit closeCircuit(circuitItem->id()); 
     88    else if (action == zoomAct) 
     89      emit zoomToCircuit(circuitItem->id()); 
     90  } else { 
     91    /* A stream was selected */ 
     92    StreamItem *streamItem = dynamic_cast<StreamItem *>(item); 
     93    if (!streamItem) 
     94      return; 
     95  
     96    /* Set up the stream context menu */ 
     97    QAction *closeAct = new QAction(QIcon(IMG_ZOOM), tr("Close Stream"), this); 
     98    menu.addAction(closeAct); 
     99 
     100    /* Display the context menu and find out which (if any) action was 
     101     * selected */ 
     102    QAction* action = menu.exec(mapToGlobal(pos)); 
     103    if (action == closeAct) 
     104      emit closeStream(streamItem->id()); 
    100105  } 
    101106} 
  • trunk/src/gui/network/circuitlistwidget.h

    r1641 r2091  
    7878  void clearCircuits(); 
    7979 
    80 protected: 
    81   /** Called when the user presses and releases a mouse button. */  
    82   virtual void mouseReleaseEvent(QMouseEvent *e); 
    83  
    8480private slots: 
    8581  /** Removes the first circuit scheduled to be removed.*/ 
     
    8985  /** Called when the current item selectio has changed. */ 
    9086  void onSelectionChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev); 
    91    
     87  /** Called when the user requests a context menu on a circuit or stream in 
     88   * the list and displays a context menu appropriate for whichever type of 
     89   * item is currently selected. */ 
     90  void customContextMenuRequested(const QPoint &pos); 
     91 
    9292private: 
    9393  /** Removes the given circuit item and all streams on that circuit. */ 
     
    104104  void scheduleStreamRemoval(StreamItem *stream, int delay); 
    105105 
    106   /* Circuit and stream context menus and items */ 
    107   QMenu* _circuitContextMenu; /**< Context menu for circuit items. */ 
    108   QAction* _closeCircuitAct;  /**< Closes a circuit. */ 
    109   QAction* _zoomCircuitAct;   /**< Zoom to a circuit. */ 
    110   QMenu* _streamContextMenu;  /**< Context menu for stream items. */ 
    111   QAction* _closeStreamAct;   /**< Closes a stream. */ 
    112  
    113106  /** List of circuit items to be removed. */ 
    114107  QList<CircuitItem *> _circuitRemovalList; 
  • trunk/src/gui/network/netviewer.ui

    r2073 r2091  
    6565       </property> 
    6666       <property name="contextMenuPolicy" > 
    67         <enum>Qt::NoContextMenu</enum> 
     67        <enum>Qt::CustomContextMenu</enum> 
    6868       </property> 
    6969       <property name="statusTip" > 
     
    172172         </property> 
    173173         <property name="contextMenuPolicy" > 
    174           <enum>Qt::NoContextMenu</enum> 
     174          <enum>Qt::CustomContextMenu</enum> 
    175175         </property> 
    176176         <property name="statusTip" > 
  • trunk/src/gui/network/routerlistwidget.cpp

    r2057 r2091  
    5050  connect(this, SIGNAL(itemSelectionChanged()),  
    5151          this, SLOT(onSelectionChanged())); 
    52  
    53   /* Set up the router item context menu */ 
    54   _routerContextMenu = new QMenu(this); 
    55   _zoomToRouterAct = new QAction(QIcon(IMG_ZOOM), tr("Zoom to Relay"), this); 
    56   _routerContextMenu->addAction(_zoomToRouterAct); 
    57 } 
    58  
    59 /** Called when the user presses and releases a mouse button. If the event 
    60  * indicates a right-click on a router item, a context menu will be displayed 
    61  * providing a list of actions, including zooming in on the server. */ 
    62 void 
    63 RouterListWidget::mouseReleaseEvent(QMouseEvent *e) 
    64 { 
    65   if (e->button() == Qt::RightButton) { 
    66     /* Find out which server was right-clicked */ 
    67     RouterListItem *item = (RouterListItem *)itemAt(e->pos()); 
    68     if (!item) { 
    69       return; 
    70     } 
    71  
    72     /* Display a context menu for this router item */ 
    73     QPoint pos = e->globalPos(); 
    74     QAction *action = _routerContextMenu->exec(pos); 
    75     if (action == _zoomToRouterAct) { 
    76       /* Zoom in on this router */ 
    77       emit zoomToRouter(item->id()); 
    78     } 
    79   } 
     52  connect(this, SIGNAL(customContextMenuRequested(QPoint)), 
     53          this, SLOT(customContextMenuRequested(QPoint))); 
     54} 
     55 
     56/** Called when the user requests a context menu for a router in the list. A 
     57 * context menu will be displayed providing a list of actions, including 
     58 * zooming in on the server. */ 
     59void 
     60RouterListWidget::customContextMenuRequested(const QPoint &pos) 
     61{ 
     62  QMenu menu(this); 
     63 
     64  /* Find out which (if any) router in the list is selected */ 
     65  RouterListItem *item = dynamic_cast<RouterListItem *>(itemAt(pos)); 
     66  if (!item) 
     67    return; 
     68   
     69  /* Set up the context menu */ 
     70  QAction *zoomAction = 
     71    new QAction(QIcon(IMG_ZOOM), tr("Zoom to Relay"), &menu); 
     72  menu.addAction(zoomAction); 
     73   
     74  /* Display the menu and find out which (if any) action was selected */ 
     75  QAction *action = menu.exec(mapToGlobal(pos)); 
     76  if (action == zoomAction) 
     77    emit zoomToRouter(item->id()); 
    8078} 
    8179 
  • trunk/src/gui/network/routerlistwidget.h

    r1638 r2091  
    7979  void clearRouters(); 
    8080  
    81 protected: 
    82   /** Called when the user presses and releases a moust button. */ 
    83   virtual void mouseReleaseEvent(QMouseEvent *e); 
    84    
    8581private slots: 
    8682  /** Called when the user clicks on an item in the list. */ 
    8783  void onSelectionChanged(); 
     84  /** Called when the user requests a context menu for some router in the 
     85   * list. */   
     86  void customContextMenuRequested(const QPoint &pos); 
    8887 
    8988protected: 
     
    9796  /** Maps a server ID to that server's list item. */ 
    9897  QHash<QString,RouterListItem*> _idmap; 
    99    
    100   /** Router item context menu and items. */ 
    101   QMenu* _routerContextMenu; /**< Context menu for router items. */ 
    102   QAction* _zoomToRouterAct; /**< Zooms in on the selected router. */ 
    10398  quint32  _onlineRouterCount; /**< Number of online routers. */ 
    10499};