commit d2ba7d6b2d3a429f66571039dd2d56154aba6ffb Author: Thibault Vataire vatairethibault@no-log.org Date: Thu Jun 16 20:30:41 2011 +0200
Improve search in the routers list by adding a search field --- src/vidalia/network/NetViewer.cpp | 12 ++++ src/vidalia/network/NetViewer.h | 3 + src/vidalia/network/NetViewer.ui | 91 +++++++++++++++++++++--------- src/vidalia/network/RouterListWidget.cpp | 34 +++++++++++ src/vidalia/network/RouterListWidget.h | 5 ++ 5 files changed, 118 insertions(+), 27 deletions(-)
diff --git a/src/vidalia/network/NetViewer.cpp b/src/vidalia/network/NetViewer.cpp index 405fd35..0e0a161 100644 --- a/src/vidalia/network/NetViewer.cpp +++ b/src/vidalia/network/NetViewer.cpp @@ -128,6 +128,10 @@ NetViewer::NetViewer(QWidget *parent) _torControl, SLOT(closeCircuit(CircuitId))); connect(ui.treeCircuitList, SIGNAL(closeStream(StreamId)), _torControl, SLOT(closeStream(StreamId))); + connect(ui.lineRouterSearch, SIGNAL(returnPressed()), + this, SLOT(onRouterSearch())); + connect(ui.lineRouterSearch, SIGNAL(textChanged(QString)), + ui.treeRouterList, SLOT(onRouterSearch(QString)));
setupGeoIpResolver();
@@ -246,6 +250,14 @@ NetViewer::clear() ui.textRouterInfo->clear(); }
+/** Called when the search of a router is triggered by the signal + * returnPressed from the search field. */ +void +NetViewer::onRouterSearch() +{ + ui.treeRouterList->searchNextRouter(ui.lineRouterSearch->text()); +} + /** Loads a list of all current address mappings. */ void NetViewer::loadAddressMap() diff --git a/src/vidalia/network/NetViewer.h b/src/vidalia/network/NetViewer.h index 3c0a675..b1c40be 100644 --- a/src/vidalia/network/NetViewer.h +++ b/src/vidalia/network/NetViewer.h @@ -101,6 +101,9 @@ private slots: /** Called when the user clicks "Full Screen" or presses Escape on the map. * Toggles the map between normal and a full screen viewing modes. */ void toggleFullScreen(); + /** Called when the search of a router is triggered by the signal + * returnPressed from the search field. */ + void onRouterSearch();
private: /** */ diff --git a/src/vidalia/network/NetViewer.ui b/src/vidalia/network/NetViewer.ui index 863907b..11fd0a2 100644 --- a/src/vidalia/network/NetViewer.ui +++ b/src/vidalia/network/NetViewer.ui @@ -28,9 +28,9 @@ <property name="childrenCollapsible"> <bool>false</bool> </property> - <widget class="RouterListWidget" name="treeRouterList"> + <widget class="QSplitter" name="splitter4"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>1</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -42,38 +42,75 @@ </size> </property> <property name="contextMenuPolicy"> - <enum>Qt::DefaultContextMenu</enum> - </property> - <property name="statusTip"> - <string/> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - <property name="indentation"> - <number>0</number> + <enum>Qt::NoContextMenu</enum> </property> - <property name="sortingEnabled"> - <bool>true</bool> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <property name="columnCount"> - <number>3</number> + <property name="childrenCollapsible"> + <bool>false</bool> </property> - <column> - <property name="text"> - <string/> + <widget class="QLineEdit" name="lineRouterSearch"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>30</height> + </size> </property> - </column> - <column> - <property name="text"> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>30</height> + </size> + </property> + </widget> + <widget class="RouterListWidget" name="treeRouterList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>175</width> + <height>0</height> + </size> + </property> + <property name="contextMenuPolicy"> + <enum>Qt::DefaultContextMenu</enum> + </property> + <property name="statusTip"> <string/> </property> - </column> - <column> - <property name="text"> - <string>Relay</string> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + <property name="indentation"> + <number>0</number> </property> - </column> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <property name="columnCount"> + <number>3</number> + </property> + <column> + <property name="text"> + <string/> + </property> + </column> + <column> + <property name="text"> + <string/> + </property> + </column> + <column> + <property name="text"> + <string>Relay</string> + </property> + </column> + </widget> </widget> <widget class="QSplitter" name="splitter3"> <property name="sizePolicy"> diff --git a/src/vidalia/network/RouterListWidget.cpp b/src/vidalia/network/RouterListWidget.cpp index e35bc22..851a5ea 100644 --- a/src/vidalia/network/RouterListWidget.cpp +++ b/src/vidalia/network/RouterListWidget.cpp @@ -152,6 +152,40 @@ RouterListWidget::clearRouters() setStatusTip(tr("%1 relays online").arg(0)); }
+/** Called when the search of a router is triggered by the signal + * textChanged from the search field. */ +void +RouterListWidget::onRouterSearch(const QString routerNickname) +{ + if (!currentIndex().data().toString().toLower().startsWith(routerNickname.toLower())) + { + searchNextRouter(routerNickname); + } else { + /* If item at currentIndex() isn't visible, make it visible. */ + scrollToItem(itemFromIndex(currentIndex())); + } +} + +/** Selects the following router whose name starts by routerNickname. */ +void +RouterListWidget::searchNextRouter(const QString routerNickname) +{ + /* currentIndex().row() = -1 if no item is selected. */ + int startIndex = currentIndex().row() + 1; + /* Search for a router whose name start with routerNickname. Case-insensitive search. */ + QModelIndexList qmIndList = model()->match(model()->index(startIndex, NameColumn), + Qt::DisplayRole, + QVariant(routerNickname), + 1, + (Qt::MatchStartsWith | Qt::MatchWrap)); + if (qmIndList.count() > 0) { + setCurrentIndex(qmIndList.at(0)); + /* If item at currentIndex() was already selected but not visible, + * make it visible. */ + scrollToItem(itemFromIndex(currentIndex())); + } +} + /** Called when the user selects a router from the list. This will search the * list for a router whose names starts with the key pressed. */ void diff --git a/src/vidalia/network/RouterListWidget.h b/src/vidalia/network/RouterListWidget.h index 04d7263..95b471e 100644 --- a/src/vidalia/network/RouterListWidget.h +++ b/src/vidalia/network/RouterListWidget.h @@ -54,6 +54,8 @@ public: void deselectAll(); /** Called when the user changes the UI translation. */ void retranslateUi(); + /** Selects the following router whose name starts by routerNickname. */ + void searchNextRouter(const QString routerNickname);
signals: /** Emitted when the user selects a router from the list. */ @@ -64,6 +66,9 @@ signals: public slots: /** Clears the list of router items. */ void clearRouters(); + /** Called when the search of a router is triggered by the signal + * textChanged from the search field. */ + void onRouterSearch(const QString routerNickname);
private slots: /** Called when the user clicks on an item in the list. */
tor-commits@lists.torproject.org