commit 84b75ab02f6672434c6824e05b8b83b4040d8b58
Author: Boris Skegin <boris.skegin.de(a)gmail.com>
Date: Sun Apr 22 13:46:17 2012 +0200
Adds Settings frame to Network Map with optional Relay columns.
---
changes/bug2731 | 3 +
src/vidalia/network/NetViewer.cpp | 81 +++++++++++-
src/vidalia/network/NetViewer.h | 10 ++
src/vidalia/network/NetViewer.ui | 216 +++++++++++++++++++++++++++++-
src/vidalia/network/RouterListItem.cpp | 68 ++++++++++
src/vidalia/network/RouterListItem.h | 6 +-
src/vidalia/network/RouterListWidget.cpp | 10 +-
src/vidalia/network/RouterListWidget.h | 9 +-
8 files changed, 390 insertions(+), 13 deletions(-)
diff --git a/changes/bug2731 b/changes/bug2731
new file mode 100644
index 0000000..a7033ac
--- /dev/null
+++ b/changes/bug2731
@@ -0,0 +1,3 @@
+ New features:
+ o Adds Settings frame for Network Map with optional
+ columns for Relay panel. Resolves ticket 2731.
diff --git a/src/vidalia/network/NetViewer.cpp b/src/vidalia/network/NetViewer.cpp
index 9c2cd3b..f0868fe 100644
--- a/src/vidalia/network/NetViewer.cpp
+++ b/src/vidalia/network/NetViewer.cpp
@@ -51,6 +51,20 @@
#define DEFAULT_SPLITTER_MAP QByteArray()
#define DEFAULT_SPLITTER_ROUT QByteArray()
+/* Settings key for IP column */
+#define SETTING_IP_COLUMN "RelayPanel/ShowIPColumn"
+/* Settings key for Bandwidth column */
+#define SETTING_BW_COLUMN "RelayPanel/ShowBandwidthColumn"
+/* Settings key for Uptime column */
+#define SETTING_UPTIME_COLUMN "RelayPanel/ShowUptimeColumn"
+
+/* Default key value for IP column */
+#define DEFAULT_IP_COLUMN false
+/* Default key value for Bandwidth column */
+#define DEFAULT_BW_COLUMN false
+/* Default key value for Uptime column */
+#define DEFAULT_UPTIME_COLUMN false
+
/** Constructor. Loads settings from VidaliaSettings.
* \param parent The parent widget of this NetViewer object.\
*/
@@ -63,6 +77,8 @@ NetViewer::NetViewer(QWidget *parent)
ui.lblConsensus->setVisible(false);
ui.lblOffline->setVisible(false);
+ loadSettings();
+ ui.frmSettings->setVisible(false);
#if defined(Q_WS_MAC)
ui.actionHelp->setShortcut(QString("Ctrl+?"));
#endif
@@ -163,7 +179,10 @@ NetViewer::NetViewer(QWidget *parent)
ui.treeRouterList, SLOT(onRouterSearch(QString)));
connect(ui.treeRouterList, SIGNAL(displayRouterInfo(QString)),
this, SLOT(displayRouterInfo(QString)));
-
+ connect(ui.btnSaveSettings, SIGNAL(clicked()),
+ this, SLOT(saveSettings()));
+ connect(ui.btnCancelSettings, SIGNAL(clicked()),
+ this, SLOT(cancelChanges()));
setupGeoIpResolver();
QToolBar *tb = new QToolBar();
@@ -173,10 +192,11 @@ NetViewer::NetViewer(QWidget *parent)
tb->addAction(ui.actionZoomOut);
tb->addAction(ui.actionZoomToFit);
tb->addAction(ui.actionZoomFullScreen);
+ tb->addAction(ui.actionSettings);
tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
ui.horizontalLayout->addWidget(tb);
-
+
/* Restore the state of each splitter */
ui.spltMain->restoreState(getSetting(SETTING_SPLITTER_MAIN,
DEFAULT_SPLITTER_MAIN)
@@ -619,3 +639,60 @@ NetViewer::linkActivated(const QString &url)
{
emit helpRequested(url);
}
+
+/** Saves the Network Map settings and
+ * then hides the settings frame. */
+void
+NetViewer::saveSettings()
+{
+ ui.treeRouterList->setColumnHidden(RouterListWidget::IPnumberColumn,
+ !(ui.chkShowIP->isChecked()));
+ ui.treeRouterList->setColumnHidden(RouterListWidget::BandwidthColumn,
+ !(ui.chkShowBW->isChecked()));
+ ui.treeRouterList->setColumnHidden(RouterListWidget::UptimeColumn,
+ !(ui.chkShowUptime->isChecked()));
+ saveSetting(SETTING_IP_COLUMN, ui.chkShowIP->isChecked());
+ saveSetting(SETTING_BW_COLUMN, ui.chkShowBW->isChecked());
+ saveSetting(SETTING_UPTIME_COLUMN, ui.chkShowUptime->isChecked());
+}
+
+/** Simply restores the previously saved settings and hides the settings
+ * frame. */
+void
+NetViewer::cancelChanges()
+{
+ /* Hide the settings frame and reset toggle button */
+ ui.actionSettings->toggle();
+ /* Reload the settings */
+ loadSettings();
+}
+
+/** Loads the saved Network Map settings
+ * except Splitter settings. */
+void
+NetViewer::loadSettings()
+{
+ /* Add optional columns to Relay Panel if their setting values are
+ * true, otherwise use default values. */
+ ui.treeRouterList->setColumnHidden(RouterListWidget::IPnumberColumn,
+ !(getSetting(SETTING_IP_COLUMN,
+ DEFAULT_IP_COLUMN).
+ toBool()));
+ ui.chkShowIP->setChecked(getSetting(SETTING_IP_COLUMN,
+ DEFAULT_IP_COLUMN).
+ toBool());
+ ui.treeRouterList->setColumnHidden(RouterListWidget::BandwidthColumn,
+ !(getSetting(SETTING_BW_COLUMN,
+ DEFAULT_BW_COLUMN).
+ toBool()));
+ ui.chkShowBW->setChecked(getSetting(SETTING_BW_COLUMN,
+ DEFAULT_BW_COLUMN).
+ toBool());
+ ui.treeRouterList->setColumnHidden(RouterListWidget::UptimeColumn,
+ !(getSetting(SETTING_UPTIME_COLUMN,
+ DEFAULT_UPTIME_COLUMN).
+ toBool()));
+ ui.chkShowUptime->setChecked(getSetting(SETTING_UPTIME_COLUMN,
+ DEFAULT_UPTIME_COLUMN).
+ toBool());
+}
diff --git a/src/vidalia/network/NetViewer.h b/src/vidalia/network/NetViewer.h
index b4f4ec3..39a3de0 100644
--- a/src/vidalia/network/NetViewer.h
+++ b/src/vidalia/network/NetViewer.h
@@ -118,6 +118,16 @@ private slots:
/** Called when the user clicks on a QLabel containing a hyperlink. */
void linkActivated(const QString &url);
+ /** Saves the Network Map settings and
+ * then hides the settings frame. */
+ void saveSettings();
+ /** Loads the saved Network Map settings
+ * except Splitter settings. */
+ void loadSettings();
+ /** Simply restores the previously saved settings and hides the settings
+ * frame. */
+ void cancelChanges();
+
private:
/** */
void setupGeoIpResolver();
diff --git a/src/vidalia/network/NetViewer.ui b/src/vidalia/network/NetViewer.ui
index c4db045..7994fb9 100644
--- a/src/vidalia/network/NetViewer.ui
+++ b/src/vidalia/network/NetViewer.ui
@@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>740</width>
- <height>614</height>
+ <height>786</height>
</rect>
</property>
<property name="windowTitle">
<string>Network Map</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_10">
+ <layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QSplitter" name="spltMain">
<property name="orientation">
@@ -145,7 +145,7 @@
<bool>true</bool>
</property>
<property name="columnCount">
- <number>3</number>
+ <number>6</number>
</property>
<column>
<property name="text">
@@ -162,6 +162,21 @@
<string>Relay</string>
</property>
</column>
+ <column>
+ <property name="text">
+ <string>IP</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Bandwidth</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Uptime</string>
+ </property>
+ </column>
</widget>
</item>
</layout>
@@ -355,6 +370,164 @@
</widget>
</widget>
</item>
+ <item>
+ <widget class="QFrame" name="frmSettings">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>140</height>
+ </size>
+ </property>
+ <property name="contextMenuPolicy">
+ <enum>Qt::NoContextMenu</enum>
+ </property>
+ <property name="visible">
+ <bool>true</bool>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QGroupBox" name="grpRelayPanel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>400</width>
+ <height>110</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Add columns to Relay panel:</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="chkShowIP">
+ <property name="text">
+ <string>IP</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="chkShowBW">
+ <property name="text">
+ <string>Bandwidth</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="chkShowUptime">
+ <property name="text">
+ <string>Uptime</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_10">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetFixedSize</enum>
+ </property>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnSaveSettings">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>85</width>
+ <height>27</height>
+ </size>
+ </property>
+ <property name="contextMenuPolicy">
+ <enum>Qt::NoContextMenu</enum>
+ </property>
+ <property name="toolTip">
+ <string>Saves the current Network Map settings</string>
+ </property>
+ <property name="text">
+ <string>Save</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnCancelSettings">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>85</width>
+ <height>27</height>
+ </size>
+ </property>
+ <property name="contextMenuPolicy">
+ <enum>Qt::NoContextMenu</enum>
+ </property>
+ <property name="toolTip">
+ <string>Cancels changes made to settings</string>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
<action name="actionRefresh">
<property name="enabled">
@@ -485,6 +658,24 @@
<string>Ctrl+F</string>
</property>
</action>
+ <action name="actionSettings">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="icon">
+ <iconset resource="../res/vidalia.qrc">
+ <normaloff>:/images/32x32/preferences-other.png</normaloff>:/images/32x32/preferences-other.png</iconset>
+ </property>
+ <property name="text">
+ <string>Settings</string>
+ </property>
+ <property name="statusTip">
+ <string>Adjust Network Map Settings</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+T</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
@@ -506,5 +697,22 @@
<resources>
<include location="../res/vidalia.qrc"/>
</resources>
- <connections/>
+ <connections>
+ <connection>
+ <sender>actionSettings</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>frmSettings</receiver>
+ <slot>setVisible(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>-1</x>
+ <y>-1</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>264</x>
+ <y>424</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
</ui>
diff --git a/src/vidalia/network/RouterListItem.cpp b/src/vidalia/network/RouterListItem.cpp
index 480d5a8..08ce5f7 100644
--- a/src/vidalia/network/RouterListItem.cpp
+++ b/src/vidalia/network/RouterListItem.cpp
@@ -18,12 +18,16 @@
#include "TorSettings.h"
#include "Vidalia.h"
+#include "stringutil.h"
#include <QHeaderView>
#define STATUS_COLUMN (RouterListWidget::StatusColumn)
#define COUNTRY_COLUMN (RouterListWidget::CountryColumn)
#define NAME_COLUMN (RouterListWidget::NameColumn)
+#define IP_COLUMN (RouterListWidget::IPnumberColumn)
+#define BW_COLUMN (RouterListWidget::BandwidthColumn)
+#define UPTIME_COLUMN (RouterListWidget::UptimeColumn)
#define NONEXIT_COLOR (Qt::white)
#define EXIT_COLOR (QColor::fromRgb(169, 207, 84))
@@ -96,6 +100,20 @@ RouterListItem::update(const RouterDescriptor &rd)
/* Make the new information visible */
setIcon(STATUS_COLUMN, statusIcon);
setText(NAME_COLUMN, _rd->name());
+ setText(IP_COLUMN, _rd->ip().toString());
+ /* We show the observedBandwidth and not the minBandwidth as in
+ * RouterDescriptorView.cpp
+ */
+ setText(BW_COLUMN, string_format_bandwidth(_rd->observedBandwidth()));
+ /* Clf. quint64
+ * RouterInfoDialog::adjustUptime(quint64 uptime, const QDateTime &published)
+ */
+ QDateTime now = QDateTime::currentDateTime().toUTC();
+ if (now < _rd->published())
+ setText(UPTIME_COLUMN, string_format_uptime(_rd->uptime()));
+ else
+ setText(UPTIME_COLUMN, string_format_uptime(_rd->uptime() +
+ (now.toTime_t() - _rd->published().toTime_t())));
setToolTip(NAME_COLUMN, QString(_rd->name() + "\r\n" + _rd->platform()));
}
@@ -116,6 +134,27 @@ RouterListItem::setLocation(const GeoIpRecord &geoip)
_countryCode = geoip.countryCode();
}
+/** Convert IP numbers to quint64 for the comparison operator
+ * filling the dot separated groups with zeroes if necessary.
+ */
+quint64
+RouterListItem::iptoquint64(const RouterListItem *ListItem) const
+{
+ bool ok;
+ quint64 ipNumber;
+ QString ipString;
+ ipString = ListItem->descriptor().ip().toString();
+ QStringList ipList = ipString.split(".", QString::SkipEmptyParts);
+ ipString = "";
+ for (int i = ipList.size()-1; i >= 1; i--) {
+ ipList[i] = ipList[i].rightJustified(3, '0');
+ ipString.prepend(ipList[i]);
+ }
+ ipString.prepend(ipList[0]);
+ ipNumber = ipString.toULongLong(&ok, 10);
+ return(ipNumber);
+}
+
/** Overload the comparison operator. */
bool
RouterListItem::operator<(const QTreeWidgetItem &other) const
@@ -153,6 +192,35 @@ RouterListItem::operator<(const QTreeWidgetItem &other) const
return (a->_statusValue < b->_statusValue);
}
return (a->name().toLower() < b->name().toLower());
+ /* Compare IP numbers based on their quint64 values */
+ case RouterListWidget::IPnumberColumn:
+ if (a->descriptor().ip() == b->descriptor().ip()) {
+ if (order == Qt::AscendingOrder)
+ return (a->_statusValue > b->_statusValue);
+ else
+ return (a->_statusValue < b->_statusValue);
+ }
+ return (iptoquint64(a) < iptoquint64(b));
+ case RouterListWidget::BandwidthColumn:
+ /* Compare bandwidth in bytes */
+ if (a->descriptor().observedBandwidth() ==
+ b->descriptor().observedBandwidth()) {
+ if (order == Qt::AscendingOrder)
+ return (a->_statusValue > b->_statusValue);
+ else
+ return (a->_statusValue < b->_statusValue);
+ }
+ return (a->descriptor().observedBandwidth() <
+ b->descriptor().observedBandwidth());
+ case RouterListWidget::UptimeColumn:
+ /* Compare uptime in seconds */
+ if (a->descriptor().uptime() == b->descriptor().uptime()) {
+ if (order == Qt::AscendingOrder)
+ return (a->_statusValue > b->_statusValue);
+ else
+ return (a->_statusValue < b->_statusValue);
+ }
+ return (a->descriptor().uptime() < b->descriptor().uptime());
default:
break;
}
diff --git a/src/vidalia/network/RouterListItem.h b/src/vidalia/network/RouterListItem.h
index db98364..7f3f9f8 100644
--- a/src/vidalia/network/RouterListItem.h
+++ b/src/vidalia/network/RouterListItem.h
@@ -49,7 +49,10 @@ public:
void setLocation(const GeoIpRecord &geoip);
/** Returns the location information set for this router item. */
GeoIpRecord location() const { return _location; }
-
+ /** Convert IP numbers to quint64 for the comparison operator
+ * filling the dot separated groups with zeroes if necessary.
+ */
+ quint64 iptoquint64(const RouterListItem *ListItem) const;
/** Overload the comparison operator. */
virtual bool operator<(const QTreeWidgetItem &other) const;
@@ -82,4 +85,3 @@ private:
};
#endif
-
diff --git a/src/vidalia/network/RouterListWidget.cpp b/src/vidalia/network/RouterListWidget.cpp
index faa9a3e..eb0d74c 100644
--- a/src/vidalia/network/RouterListWidget.cpp
+++ b/src/vidalia/network/RouterListWidget.cpp
@@ -34,7 +34,10 @@ RouterListWidget::RouterListWidget(QWidget *parent)
/* Create and initialize columns */
setHeaderLabels(QStringList() << QString("")
<< QString("")
- << tr("Relay"));
+ << tr("Relay")
+ << tr("IP")
+ << tr("Bandwidth")
+ << tr("Uptime"));
/* Sort by descending server bandwidth */
sortItems(StatusColumn, Qt::DescendingOrder);
@@ -50,7 +53,10 @@ RouterListWidget::retranslateUi()
{
setHeaderLabels(QStringList() << QString("")
<< QString("")
- << tr("Relay"));
+ << tr("Relay")
+ << tr("IP")
+ << tr("Bandwidth")
+ << tr("Uptime"));
}
/** Called when the user requests a context menu for a router in the list. A
diff --git a/src/vidalia/network/RouterListWidget.h b/src/vidalia/network/RouterListWidget.h
index fddfaa9..6a3b7c1 100644
--- a/src/vidalia/network/RouterListWidget.h
+++ b/src/vidalia/network/RouterListWidget.h
@@ -37,9 +37,12 @@ class RouterListWidget : public QTreeWidget
public:
/** Columns in the list. */
enum Columns {
- StatusColumn = 0, /**< Status column, indicating bandwidth. */
- CountryColumn = 1, /**< Router's country flag. */
- NameColumn = 2, /**< Router's name. */
+ StatusColumn = 0, /**< Status column, indicating bandwidth. */
+ CountryColumn = 1, /**< Router's country flag. */
+ NameColumn = 2, /**< Router's name. */
+ IPnumberColumn = 3, /**< Router's IP. */
+ BandwidthColumn = 4, /**< Router's Bandwidth. */
+ UptimeColumn = 5, /**< Router's Uptime. */
};
/** Default constructor. */