[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r3249: Waste a portion of my life implementing a mostly useless fea (vidalia/trunk/src/vidalia/network)
Author: edmanm
Date: 2008-10-20 21:50:55 -0400 (Mon, 20 Oct 2008)
New Revision: 3249
Modified:
vidalia/trunk/src/vidalia/network/netviewer.cpp
vidalia/trunk/src/vidalia/network/netviewer.h
vidalia/trunk/src/vidalia/network/netviewer.ui
vidalia/trunk/src/vidalia/network/routerlistwidget.cpp
vidalia/trunk/src/vidalia/network/routerlistwidget.h
Log:
Waste a portion of my life implementing a mostly useless feature. Resolves
ticket #431.
Modified: vidalia/trunk/src/vidalia/network/netviewer.cpp
===================================================================
--- vidalia/trunk/src/vidalia/network/netviewer.cpp 2008-10-20 01:07:30 UTC (rev 3248)
+++ vidalia/trunk/src/vidalia/network/netviewer.cpp 2008-10-21 01:50:55 UTC (rev 3249)
@@ -90,8 +90,8 @@
/* Connect the necessary slots and signals */
connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(help()));
connect(ui.actionRefresh, SIGNAL(triggered()), this, SLOT(refresh()));
- connect(ui.treeRouterList, SIGNAL(routerSelected(RouterDescriptor)),
- this, SLOT(routerSelected(RouterDescriptor)));
+ connect(ui.treeRouterList, SIGNAL(routerSelected(QList<RouterDescriptor>)),
+ this, SLOT(routerSelected(QList<RouterDescriptor>)));
connect(ui.treeRouterList, SIGNAL(zoomToRouter(QString)),
_map, SLOT(zoomToRouter(QString)));
connect(ui.treeCircuitList, SIGNAL(circuitSelected(Circuit)),
@@ -408,14 +408,20 @@
ui.textRouterInfo->display(routers);
}
-/** Called when the user selects a router from the router list. */
+/** Called when the user selects one or more routers from the router list. */
void
-NetViewer::routerSelected(const RouterDescriptor &router)
+NetViewer::routerSelected(const QList<RouterDescriptor> &routers)
{
_map->deselectAll();
ui.textRouterInfo->clear();
- ui.textRouterInfo->display(router);
- _map->selectRouter(router.id());
+ ui.textRouterInfo->display(routers);
+
+ /* XXX: Ideally we would also be able to select multiple pinpoints on the
+ * map. But our current map sucks and you can't even tell when one is
+ * selected anyway. Worry about this when we actually get to Marble.
+ */
+ if (routers.size() == 1)
+ _map->selectRouter(routers[0].id());
}
/** If there are any IPs in the resolve queue, do the request now. */
Modified: vidalia/trunk/src/vidalia/network/netviewer.h
===================================================================
--- vidalia/trunk/src/vidalia/network/netviewer.h 2008-10-20 01:07:30 UTC (rev 3248)
+++ vidalia/trunk/src/vidalia/network/netviewer.h 2008-10-21 01:50:55 UTC (rev 3249)
@@ -66,8 +66,8 @@
void circuitSelected(const Circuit &circuit);
/** Called when an IP has been resolved to geographic information. */
void resolved(int id, const QList<GeoIp> &geoips);
- /** Called when the user selects a router in the list. */
- void routerSelected(const RouterDescriptor &router);
+ /** Called when the user selects one or more routers in the list. */
+ void routerSelected(const QList<RouterDescriptor> &routers);
/** Handles when we get connected to Tor network */
void onAuthenticated();
/** Handles when we get disconnected from Tor network */
Modified: vidalia/trunk/src/vidalia/network/netviewer.ui
===================================================================
--- vidalia/trunk/src/vidalia/network/netviewer.ui 2008-10-20 01:07:30 UTC (rev 3248)
+++ vidalia/trunk/src/vidalia/network/netviewer.ui 2008-10-21 01:50:55 UTC (rev 3249)
@@ -64,7 +64,7 @@
</size>
</property>
<property name="contextMenuPolicy" >
- <enum>Qt::CustomContextMenu</enum>
+ <enum>Qt::DefaultContextMenu</enum>
</property>
<property name="statusTip" >
<string/>
@@ -75,6 +75,9 @@
<property name="sortingEnabled" >
<bool>true</bool>
</property>
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
</widget>
<widget class="QSplitter" name="splitter3" >
<property name="sizePolicy" >
Modified: vidalia/trunk/src/vidalia/network/routerlistwidget.cpp
===================================================================
--- vidalia/trunk/src/vidalia/network/routerlistwidget.cpp 2008-10-20 01:07:30 UTC (rev 3248)
+++ vidalia/trunk/src/vidalia/network/routerlistwidget.cpp 2008-10-21 01:50:55 UTC (rev 3249)
@@ -15,11 +15,13 @@
*/
#include <QHeaderView>
+#include <QClipboard>
#include <vidalia.h>
#include "routerlistwidget.h"
#define IMG_ZOOM ":/images/22x22/page-zoom.png"
+#define IMG_COPY ":/images/22x22/edit-copy.png"
RouterListWidget::RouterListWidget(QWidget *parent)
@@ -53,26 +55,86 @@
* context menu will be displayed providing a list of actions, including
* zooming in on the server. */
void
-RouterListWidget::customContextMenuRequested(const QPoint &pos)
+RouterListWidget::contextMenuEvent(QContextMenuEvent *event)
{
- QMenu menu(this);
+ QAction *action;
+ QMenu *menu, *copyMenu;
+ QList<QTreeWidgetItem *> selected;
- /* Find out which (if any) router in the list is selected */
- RouterListItem *item = dynamic_cast<RouterListItem *>(itemAt(pos));
- if (!item)
+ selected = selectedItems();
+ if (! selected.size())
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());
+
+ menu = new QMenu();
+ copyMenu = menu->addMenu(QIcon(IMG_COPY), tr("Copy"));
+ action = copyMenu->addAction(tr("Nickname"));
+ connect(action, SIGNAL(triggered()), this, SLOT(copySelectedNicknames()));
+
+ action = copyMenu->addAction(tr("Fingerprint"));
+ connect(action, SIGNAL(triggered()), this, SLOT(copySelectedFingerprints()));
+
+ action = menu->addAction(QIcon(IMG_ZOOM), tr("Zoom to Relay"));
+ if (selected.size() > 1)
+ action->setEnabled(false);
+ else
+ connect(action, SIGNAL(triggered()), this, SLOT(zoomToSelectedRelay()));
+
+ menu->exec(event->globalPos());
+ delete menu;
}
+/** Copies the nicknames for all currently selected relays to the clipboard.
+ * Nicknames are formatted as a comma-delimited list, suitable for doing
+ * dumb things with your torrc. */
+void
+RouterListWidget::copySelectedNicknames()
+{
+ QString text;
+
+ foreach (QTreeWidgetItem *item, selectedItems()) {
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(item);
+ if (relay)
+ text.append(relay->name() + ",");
+ }
+ if (text.length()) {
+ text.remove(text.length()-1, 1);
+ vApp->clipboard()->setText(text);
+ }
+}
+
+/** Copies the fingerprints for all currently selected relays to the
+ * clipboard. Fingerprints are formatted as a comma-delimited list, suitable
+ * for doing dumb things with your torrc. */
+void
+RouterListWidget::copySelectedFingerprints()
+{
+ QString text;
+
+ foreach (QTreeWidgetItem *item, selectedItems()) {
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(item);
+ if (relay)
+ text.append("$" + relay->id() + ",");
+ }
+ if (text.length()) {
+ text.remove(text.length()-1, 1);
+ vApp->clipboard()->setText(text);
+ }
+}
+
+/** Emits a zoomToRouter() signal containing the fingerprint of the
+ * currently selected relay. */
+void
+RouterListWidget::zoomToSelectedRelay()
+{
+ QList<QTreeWidgetItem *> selected = selectedItems();
+ if (selected.size() != 1)
+ return;
+
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(selected[0]);
+ if (relay)
+ emit zoomToRouter(relay->id());
+}
+
/** Deselects all currently selected routers. */
void
RouterListWidget::deselectAll()
@@ -166,12 +228,14 @@
void
RouterListWidget::onSelectionChanged()
{
- RouterDescriptor rd;
- QList<QTreeWidgetItem *> items = selectedItems();
+ QList<RouterDescriptor> descriptors;
- if (items.count() > 0) {
- rd = ((RouterListItem *)items[0])->descriptor();
+ foreach (QTreeWidgetItem *item, selectedItems()) {
+ RouterListItem *relay = dynamic_cast<RouterListItem *>(item);
+ if (relay)
+ descriptors << relay->descriptor();
}
- emit routerSelected(rd);
+ if (descriptors.count() > 0)
+ emit routerSelected(descriptors);
}
Modified: vidalia/trunk/src/vidalia/network/routerlistwidget.h
===================================================================
--- vidalia/trunk/src/vidalia/network/routerlistwidget.h 2008-10-20 01:07:30 UTC (rev 3248)
+++ vidalia/trunk/src/vidalia/network/routerlistwidget.h 2008-10-21 01:50:55 UTC (rev 3249)
@@ -18,6 +18,7 @@
#define _ROUTERLISTWIDGET_H
#include <QHash>
+#include <QList>
#include <QMenu>
#include <QObject>
#include <QAction>
@@ -32,7 +33,7 @@
class RouterListWidget : public QTreeWidget
{
Q_OBJECT
-
+
public:
/** Columns in the list. */
enum Columns {
@@ -44,7 +45,7 @@
/** Default constructor. */
RouterListWidget(QWidget *parent = 0);
-
+
/** Adds a new descriptor the list. */
void addRouter(RouterDescriptor rd);
/** Finds the list item whose key ID matches <b>id</b>. Returns 0 if not
@@ -57,24 +58,35 @@
signals:
/** Emitted when the user selects a router from the list. */
- void routerSelected(RouterDescriptor rd);
+ void routerSelected(QList<RouterDescriptor> rd);
/** Emitted when the user selects a router to zoom in on. */
void zoomToRouter(QString id);
-
+
public slots:
/** Clears the list of router items. */
void clearRouters();
-
+
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);
+ /** Copies the nicknames for all currently selected relays to the clipboard.
+ * Nicknames are formatted as a comma-delimited list, suitable for doing
+ * dumb things with your torrc. */
+ void copySelectedNicknames();
+ /** Copies the fingerprints for all currently selected relays to the
+ * clipboard. Fingerprints are formatted as a comma-delimited list, suitable
+ * for doing dumb things with your torrc. */
+ void copySelectedFingerprints();
+ /** Emits a zoomToRouter() signal containing the fingerprint of the
+ * currently selected relay. */
+ void zoomToSelectedRelay();
protected:
/** Called when the user presses a key while the list has focus. */
void keyPressEvent(QKeyEvent *event);
+ /** Displays a context menu for the user when they right-click on the
+ * widget. */
+ virtual void contextMenuEvent(QContextMenuEvent *event);
private:
/** Maps a server ID to that server's list item. */