00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file routerlistwidget.h 00024 * \version $Id: routerlistwidget.h 1638 2007-02-16 21:51:40Z edmanm $ 00025 * \brief Displays a list of Tor servers and their status 00026 */ 00027 00028 #ifndef _ROUTERLISTWIDGET_H 00029 #define _ROUTERLISTWIDGET_H 00030 00031 #include <QHash> 00032 #include <QMenu> 00033 #include <QObject> 00034 #include <QAction> 00035 #include <QKeyEvent> 00036 #include <QTreeWidget> 00037 #include <QHostAddress> 00038 #include <QMouseEvent> 00039 00040 #include "routerlistitem.h" 00041 00042 00043 class RouterListWidget : public QTreeWidget 00044 { 00045 Q_OBJECT 00046 00047 public: 00048 /** Columns in the list. */ 00049 enum Columns { 00050 StatusColumn = 0, /**< Status column, indicating bandwidth. */ 00051 CountryColumn = 1, /**< Router's country flag. */ 00052 NameColumn = 2, /**< Router's name. */ 00053 00054 }; 00055 00056 /** Default constructor. */ 00057 RouterListWidget(QWidget *parent = 0); 00058 00059 /** Adds a new descriptor the list. */ 00060 void addRouter(RouterDescriptor rd); 00061 /** Finds the list item whose router nickname matches <b>name</b>. If more 00062 * than one router exists with given name, the first match will be 00063 * returned. Returns 0 if not found. */ 00064 RouterListItem* findRouterByName(QString name); 00065 /** Finds the list item whose key ID matches <b>id</b>. Returns 0 if not 00066 * found. */ 00067 RouterListItem* findRouterById(QString id); 00068 /** Deselects all currently selected routers. */ 00069 void deselectAll(); 00070 00071 signals: 00072 /** Emitted when the user selects a router from the list. */ 00073 void routerSelected(RouterDescriptor rd); 00074 /** Emitted when the user selects a router to zoom in on. */ 00075 void zoomToRouter(QString id); 00076 00077 public slots: 00078 /** Clears the list of router items. */ 00079 void clearRouters(); 00080 00081 protected: 00082 /** Called when the user presses and releases a moust button. */ 00083 virtual void mouseReleaseEvent(QMouseEvent *e); 00084 00085 private slots: 00086 /** Called when the user clicks on an item in the list. */ 00087 void onSelectionChanged(); 00088 00089 protected: 00090 /** Called when the user presses a key while the list has focus. */ 00091 void keyPressEvent(QKeyEvent *event); 00092 00093 private: 00094 /** Inserts a new item into the router list, maintaining the current order.*/ 00095 void insertSorted(RouterListItem *item); 00096 00097 /** Maps a server ID to that server's list item. */ 00098 QHash<QString,RouterListItem*> _idmap; 00099 00100 /** Router item context menu and items. */ 00101 QMenu* _routerContextMenu; /**< Context menu for router items. */ 00102 QAction* _zoomToRouterAct; /**< Zooms in on the selected router. */ 00103 quint32 _onlineRouterCount; /**< Number of online routers. */ 00104 }; 00105 00106 #endif 00107