[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1283: Right-clicking on a circuit or stream item pops up a context (in trunk/src/gui: network res res/16x16)
Author: edmanm
Date: 2006-10-04 15:43:54 -0400 (Wed, 04 Oct 2006)
New Revision: 1283
Added:
trunk/src/gui/res/16x16/network-offline.png
Modified:
trunk/src/gui/network/circuitlistwidget.cpp
trunk/src/gui/network/circuitlistwidget.h
trunk/src/gui/network/netviewer.cpp
trunk/src/gui/network/netviewer.h
trunk/src/gui/res/vidalia_common.qrc
Log:
Right-clicking on a circuit or stream item pops up a context menu that lets
you close that circuit or stream. (part of Ticket #176, minus the pony)
Modified: trunk/src/gui/network/circuitlistwidget.cpp
===================================================================
--- trunk/src/gui/network/circuitlistwidget.cpp 2006-10-04 19:41:48 UTC (rev 1282)
+++ trunk/src/gui/network/circuitlistwidget.cpp 2006-10-04 19:43:54 UTC (rev 1283)
@@ -25,10 +25,13 @@
* \brief Collection of Tor circuits as CircuitItems
*/
+#include <QPoint>
#include <QTimer>
#include "circuitlistwidget.h"
+#define IMG_CLOSE ":/images/16x16/network-offline.png"
+
#define CLOSED_CIRCUIT_REMOVE_DELAY 3000
#define FAILED_CIRCUIT_REMOVE_DELAY 5000
#define CLOSED_STREAM_REMOVE_DELAY 3000
@@ -45,8 +48,49 @@
/* 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);
+ _closeCircuitAct = new QAction(QIcon(IMG_CLOSE), tr("Close Circuit"), this);
+ _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);
}
+/** 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. */
+void
+CircuitListWidget::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->button() == Qt::RightButton) {
+ /* Find out which item was right-clicked */
+ QTreeWidgetItem *item = itemAt(e->pos());
+ if (!item) {
+ return;
+ }
+
+ QPoint pos = e->globalPos();
+ if (!item->parent()) {
+ /* Circuit was right-clicked */
+ quint64 circid = ((CircuitItem *)item)->id();
+ QAction* action = _circuitContextMenu->exec(pos);
+ if (action == _closeCircuitAct) {
+ emit closeCircuit(circid);
+ }
+ } else {
+ /* Stream was right-clicked */
+ quint64 streamid = ((StreamItem *)item)->id();
+ QAction* action = _streamContextMenu->exec(pos);
+ if (action == _closeStreamAct) {
+ emit closeStream(streamid);
+ }
+ }
+ }
+}
+
/** Adds a circuit to the list. If the circuit already exists in the list, the
* status and path will be updated. */
void
Modified: trunk/src/gui/network/circuitlistwidget.h
===================================================================
--- trunk/src/gui/network/circuitlistwidget.h 2006-10-04 19:41:48 UTC (rev 1282)
+++ trunk/src/gui/network/circuitlistwidget.h 2006-10-04 19:43:54 UTC (rev 1283)
@@ -30,6 +30,9 @@
#include <QTreeWidget>
#include <QList>
+#include <QMenu>
+#include <QAction>
+#include <QMouseEvent>
#include "circuititem.h"
#include "streamitem.h"
@@ -56,10 +59,6 @@
/** Adds a stream to the list. If the stream already exists in the list, the
* status and path will be updated. */
void addStream(Stream stream);
- /** Removes the given circuit item and all streams on that circuit. */
- void removeCircuit(CircuitItem *circuit);
- /** Removes the given stream item. */
- void removeStream(StreamItem *stream);
/** Returns a list of circuits currently in the widget. */
QList<Circuit> circuits();
@@ -68,20 +67,32 @@
void circuitSelected(Circuit circuit);
/** Emitted when a circuit is removed from the list. */
void circuitRemoved(quint64 circid);
+ /** Emitted when the user selects a circuit to be closed. */
+ void closeCircuit(quint64 circid);
+ /** Emitted when the user selects a stream to be closed. */
+ void closeStream(quint64 streamid);
public slots:
/** 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 circuit with the given ID and any streams on this circuit.*/
+ /** Removes the first circuit scheduled to be removed.*/
void removeCircuit();
- /** Removes the stream with the given ID. */
+ /** Removes the first stream scheduled to be removed. */
void removeStream();
/** Called when the current item selectio has changed. */
void onSelectionChanged(QTreeWidgetItem *cur, QTreeWidgetItem *prev);
-
+
private:
+ /** Removes the given circuit item and all streams on that circuit. */
+ void removeCircuit(CircuitItem *circuit);
+ /** Removes the given stream item. */
+ void removeStream(StreamItem *stream);
/** Finds the circuit with the given ID. */
CircuitItem* findCircuitItem(quint64 circid);
/** Finds the stream with the given ID. */
@@ -91,6 +102,12 @@
/** 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. */
+ 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.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp 2006-10-04 19:41:48 UTC (rev 1282)
+++ trunk/src/gui/network/netviewer.cpp 2006-10-04 19:43:54 UTC (rev 1283)
@@ -101,6 +101,10 @@
this, SLOT(circuitSelected(Circuit)));
connect(ui.treeCircuitList, SIGNAL(circuitRemoved(quint64)),
_map, SLOT(removeCircuit(quint64)));
+ connect(ui.treeCircuitList, SIGNAL(closeCircuit(quint64)),
+ this, SLOT(closeCircuit(quint64)));
+ connect(ui.treeCircuitList, SIGNAL(closeStream(quint64)),
+ this, SLOT(closeStream(quint64)));
/* Respond to changes in the status of the control connection */
connect(_torControl, SIGNAL(connected(bool)), ui.actionRefresh, SLOT(setEnabled(bool)));
@@ -222,6 +226,20 @@
_map->addCircuit(circuit.id(), circIds.hops());
}
+/** Asks Tor to close the circuit with the id <b>circid</b>. */
+void
+NetViewer::closeCircuit(quint64 circid)
+{
+ _torControl->closeCircuit(circid);
+}
+
+/** Asks Tor to close the stream with the id <b>streamid</b>. */
+void
+NetViewer::closeStream(quint64 streamid)
+{
+ _torControl->closeStream(streamid);
+}
+
/** Called when the user selects the "Help" action from the toolbar. */
void
NetViewer::help()
Modified: trunk/src/gui/network/netviewer.h
===================================================================
--- trunk/src/gui/network/netviewer.h 2006-10-04 19:41:48 UTC (rev 1282)
+++ trunk/src/gui/network/netviewer.h 2006-10-04 19:43:54 UTC (rev 1283)
@@ -68,6 +68,10 @@
void refresh();
/** Called when the user selects a circuit on the circuit list */
void circuitSelected(Circuit circuit);
+ /** Called when the user selects a circuit to be closed. */
+ void closeCircuit(quint64 circid);
+ /** Called when the user selects a stream to be closed. */
+ void closeStream(quint64 streamid);
/** Called when an IP has been resolved to geographic information. */
void resolved(int id, QList<GeoIp> geoips);
/** Called when the user selects a router in the list. */
Added: trunk/src/gui/res/16x16/network-offline.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/gui/res/16x16/network-offline.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/src/gui/res/vidalia_common.qrc
===================================================================
--- trunk/src/gui/res/vidalia_common.qrc 2006-10-04 19:41:48 UTC (rev 1282)
+++ trunk/src/gui/res/vidalia_common.qrc 2006-10-04 19:43:54 UTC (rev 1283)
@@ -17,6 +17,7 @@
<file>16x16/msg-info.png</file>
<file>16x16/msg-notice.png</file>
<file>16x16/msg-warn.png</file>
+ <file>16x16/network-offline.png</file>
<file>16x16/preferences-system.png</file>
<file>16x16/system-users.png</file>
<file>16x16/tor-logo.png</file>