Upstream tarball 9882
[amule.git] / src / ServerListCtrl.h
blob0de2f29bc7edc0d427ed2a02c56d85c548b0f2e8
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 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.
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.
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
26 #ifndef SERVERLISTCTRL_H
27 #define SERVERLISTCTRL_H
29 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
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
45 class CServer;
46 class CServerList;
47 class wxListEvent;
48 class wxCommandEvent;
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.
56 class CServerListCtrl : public CMuleListCtrl
58 public:
59 /**
60 * Constructor.
62 * @see CMuleListCtrl::CMuleListCtrl
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") );
73 /**
74 * Destructor.
76 virtual ~CServerListCtrl();
79 /**
80 * Adds a server to the list.
82 * @param A pointer to the new server.
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.
88 void AddServer( CServer* toadd );
90 /**
91 * Removes a server from the displayed list.
93 void RemoveServer(CServer* server);
95 /**
96 * Removes all servers with the specified state.
98 * @param state All items with this state will be removed, default being all.
100 void RemoveAllServers(int state = wxLIST_STATE_DONTCARE);
104 * Updates the displayed information on a server.
106 * @param server The server to be updated.
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.
115 void RefreshServer( CServer* server );
118 * Sets the highlighting of the specified server.
120 * @param server The server to have its highlighting set.
121 * @param highlight The new highlighting state.
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.
127 void HighlightServer( const CServer* server, bool highlight );
130 * Marks the specified server as static or not.
132 * @param The server to be marked or unmarked as static.
133 * @param The new static state.
135 * Other than setting the static setting of the specified server, it
136 * also adds or removes the server from the static-list file.
138 bool SetStaticServer( CServer* server, bool isStatic );
142 * This function updates the server-count in the server-wnd.
144 void ShowServerCount();
146 protected:
147 /// Return old column order.
148 wxString GetOldColumnOrder() const;
150 private:
153 * Event-handler for handling item activation (connect).
155 void OnItemActivated( wxListEvent& event );
158 * Event-handler for displaying the popup-menu.
160 void OnItemRightClicked( wxListEvent& event );
163 * Event-handler for priority changes.
165 void OnPriorityChange( wxCommandEvent& event );
168 * Event-handler for static changes.
170 void OnStaticChange( wxCommandEvent& event );
173 * Event-handler for server connections.
175 void OnConnectToServer( wxCommandEvent& event );
178 * Event-handler for copying server-urls to the clipboard.
180 void OnGetED2kURL( wxCommandEvent& event );
183 * Event-handler for server removal.
185 void OnRemoveServers( wxCommandEvent& event );
188 * Event-handler for deleting servers when the delete-key is pressed.
190 void OnKeyPressed( wxKeyEvent& event );
193 * Sorter function.
195 * @see wxListCtrl::SortItems
197 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
200 //! Used to keep track of the last high-lighted item.
201 wxUIntPtr m_connected;
204 DECLARE_EVENT_TABLE()
207 #endif
208 // File_checked_for_headers