1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net ) 6// 7// Any parts of this program derived from the xMule, lMule or eMule project, 8// or contributed by third-party developers are copyrighted by their 9// respective authors. 10// 11// This program is free software; you can redistribute it and/or modify 12// it under the terms of the GNU General Public License as published by 13// the Free Software Foundation; either version 2 of the License, or 14// (at your option) any later version. 15// 16// This program is distributed in the hope that it will be useful, 17// but WITHOUT ANY WARRANTY; without even the implied warranty of 18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19// GNU General Public License for more details. 20// 21// You should have received a copy of the GNU General Public License 22// along with this program; if not, write to the Free Software 23// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 24// 25 26#ifndef SERVERLISTCTRL_H 27#define SERVERLISTCTRL_H 28 29#include "MuleListCtrl.h" // Needed for CMuleListCtrl 30 31#define COLUMN_SERVER_NAME 0 32#define COLUMN_SERVER_ADDR 1 33#define COLUMN_SERVER_PORT 2 34#define COLUMN_SERVER_DESC 3 35#define COLUMN_SERVER_PING 4 36#define COLUMN_SERVER_USERS 5 37#define COLUMN_SERVER_FILES 6 38#define COLUMN_SERVER_PRIO 7 39#define COLUMN_SERVER_FAILS 8 40#define COLUMN_SERVER_STATIC 9 41#define COLUMN_SERVER_VERSION 10 42#define COLUMN_SERVER_TCPFLAGS 11 43#define COLUMN_SERVER_UDPFLAGS 12 44 45class CServer; 46class CServerList; 47class wxListEvent; 48class wxCommandEvent; 49 50 51/** 52 * The CServerListCtrl is used to display the list of servers which the user 53 * can connect to and which we request sources from. It is a permanently sorted 54 * list in that it always ensure that the items are sorted in the correct order. 55 */ 56class CServerListCtrl : public CMuleListCtrl 57{ 58public: 59 /** 60 * Constructor. 61 * 62 * @see CMuleListCtrl::CMuleListCtrl 63 */ 64 CServerListCtrl( 65 wxWindow *parent, 66 wxWindowID winid = -1, 67 const wxPoint &pos = wxDefaultPosition, 68 const wxSize &size = wxDefaultSize, 69 long style = wxLC_ICON, 70 const wxValidator& validator = wxDefaultValidator, 71 const wxString &name = wxT("mulelistctrl") ); 72 73 /** 74 * Destructor. 75 */ 76 virtual ~CServerListCtrl(); 77 78 79 /** 80 * Adds a server to the list. 81 * 82 * @param A pointer to the new server. 83 * 84 * Internally this function calls RefreshServer and ShowServerCount, with 85 * the result that it is legal to add servers already in the list, though 86 * not recommended. 87 */ 88 void AddServer( CServer* toadd ); 89 90 /** 91 * Removes a server from the displayed list. 92 */ 93 void RemoveServer(CServer* server); 94 95 /** 96 * Removes all servers with the specified state. 97 * 98 * @param state All items with this state will be removed, default being all. 99 */ 100 void RemoveAllServers(int state = wxLIST_STATE_DONTCARE); 101 102 103 /** 104 * Updates the displayed information on a server. 105 * 106 * @param server The server to be updated. 107 * 108 * This function will not only update the displayed information, it will also 109 * reposition the item should it be nescecarry to enforce the current sorting. 110 * Also note that this function does not require that the server actually is 111 * on the list already, since AddServer makes use of it, but this should 112 * generally be avoided, since it will result in the server-count getting 113 * skewed until the next AddServer call. 114 */ 115 void RefreshServer( CServer* server ); 116 117 /** 118 * Sets the highlighting of the specified server. 119 * 120 * @param server The server to have its highlighting set. 121 * @param highlight The new highlighting state. 122 * 123 * Please note that only _one_ item is allowed to be highlighted at any 124 * one time, so calling this function while another item is already 125 * highlighted will result in the old item not being highlighted any more. 126 */ 127 void HighlightServer( const CServer* server, bool highlight ); 128 129 130 131 /** 132 * This function updates the server-count in the server-wnd. 133 */ 134 void ShowServerCount(); 135 136protected: 137 /// Return old column order. 138 wxString GetOldColumnOrder() const; 139 140private: 141 142 /** 143 * Event-handler for handling item activation (connect). 144 */ 145 void OnItemActivated( wxListEvent& event ); 146 147 /** 148 * Event-handler for displaying the popup-menu. 149 */ 150 void OnItemRightClicked( wxListEvent& event ); 151 152 /** 153 * Event-handler for priority changes. 154 */ 155 void OnPriorityChange( wxCommandEvent& event ); 156 157 /** 158 * Event-handler for static changes. 159 */ 160 void OnStaticChange( wxCommandEvent& event ); 161 162 /** 163 * Event-handler for server connections. 164 */ 165 void OnConnectToServer( wxCommandEvent& event ); 166 167 /** 168 * Event-handler for copying server-urls to the clipboard. 169 */ 170 void OnGetED2kURL( wxCommandEvent& event ); 171 172 /** 173 * Event-handler for server removal. 174 */ 175 void OnRemoveServers( wxCommandEvent& event ); 176 177 /** 178 * Event-handler for deleting servers when the delete-key is pressed. 179 */ 180 void OnKeyPressed( wxKeyEvent& event ); 181 182 /** 183 * Sorter function. 184 * 185 * @see wxListCtrl::SortItems 186 */ 187 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData); 188 189 190 //! Used to keep track of the last high-lighted item. 191 const CServer* m_connected; 192 193 194 DECLARE_EVENT_TABLE() 195}; 196 197#endif 198// File_checked_for_headers 199