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 1241 2006-09-26 00:42:21Z 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 <QObject> 00032 #include <QHash> 00033 #include <QTreeWidget> 00034 #include <QHostAddress> 00035 #include <QKeyEvent> 00036 00037 #include "routerlistitem.h" 00038 00039 00040 class RouterListWidget : public QTreeWidget 00041 { 00042 Q_OBJECT 00043 00044 public: 00045 /** Columns in the list. */ 00046 enum Columns { 00047 StatusColumn = 0, /**< Status column, indicating bandwidth */ 00048 NameColumn = 1, /*< Router's name. */ 00049 00050 }; 00051 /** Column widths. */ 00052 enum ColumnWidths { 00053 StatusColumnWidth = 55 /**< Initial width of the status column. */ 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 /** Called when the user selects a router from the list. */ 00073 void routerSelected(RouterDescriptor rd); 00074 00075 public slots: 00076 /** Clears the list of router items. */ 00077 void clearRouters(); 00078 00079 private slots: 00080 /** Called when the user clicks on an item in the list. */ 00081 void onSelectionChanged(); 00082 00083 protected: 00084 /** Called when the user presses a key while the list has focus. */ 00085 void keyPressEvent(QKeyEvent *event); 00086 00087 private: 00088 /** Inserts a new item into the router list, maintaining the current order.*/ 00089 void insertSorted(RouterListItem *item); 00090 00091 /** Maps a server ID to that server's list item. */ 00092 QHash<QString,RouterListItem*> _idmap; 00093 }; 00094 00095 #endif 00096