2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef GENERICCLIENTLISTCTRL_H
26 #define GENERICCLIENTLISTCTRL_H
28 #include <map> // Needed for std::multimap
29 #include <vector> // Needed for std::vector
32 #include "Types.h" // Needed for uint8
33 #include "Constants.h" // Needed for DownloadItemType
34 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
35 #include "amuleDlg.h" // Needed for CamuleDlg::DialogType
43 struct ClientCtrlItem_Struct
;
45 enum GenericColumnEnum
{
54 ColumnUserQueueRankLocal
,
55 ColumnUserQueueRankRemote
,
57 ColumnUserFileNameDownload
,
58 ColumnUserFileNameUpload
,
59 ColumnUserFileNameDownloadRemote
,
60 ColumnUserSharedFiles
,
64 struct CGenericClientListCtrlColumn
{
65 GenericColumnEnum cid
;
70 struct GenericColumnInfo
{
71 GenericColumnInfo(int n
, CGenericClientListCtrlColumn
* col
) : n_columns(n
), columns(col
) { };
73 CGenericClientListCtrlColumn
* columns
;
76 typedef std::vector
<CKnownFile
*> CKnownFileVector
;
79 * This class is responsible for representing clients in a generic way.
82 class CGenericClientListCtrl
: public CMuleListCtrl
88 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
90 CGenericClientListCtrl(
91 const wxString
& tablename
,
97 const wxValidator
& validator
,
98 const wxString
&name
);
103 virtual ~CGenericClientListCtrl();
106 * Initializes the control. We need a 2-stage initialization so the derived class members can be called.
108 void InitColumnData();
111 * Adds a source belonging to the specified file.
113 * @param owner The owner of this specific source-entry, must be a valid pointer.
114 * @param source The client object to be added, must be a valid pointer.
115 * @param type If the source is a current source, or a A4AF source.
117 * Please note that the specified client will only be added to the list if it's
118 * owner is shown, otherwise the source will simply be ignored.
119 * Duplicates wont be added.
121 void AddSource( CKnownFile
* owner
, const CClientRef
& source
, SourceItemType type
);
124 * Removes a source from the list.
126 * @param source ID of the source to be removed.
127 * @param owner Either a specific file, or NULL to remove the source from all files.
129 void RemoveSource( uint32 source
, const CKnownFile
* owner
);
132 * Shows the clients of specific files.
134 * @param file A valid, sorted vector of files whose clients will be shown.
136 * WARNING: The received vector *MUST* be odered with std::sort.
139 void ShowSources( const CKnownFileVector
& files
);
142 * Updates the state of the specified item, possibly causing a redrawing.
144 * @param toupdate ID of the client to be updated.
145 * @param type If the source is a current source, or a A4AF source.
148 void UpdateItem(uint32 toupdate
, SourceItemType type
);
150 void SetShowing( bool status
) { m_showing
= status
; }
151 bool GetShowing() const { return m_showing
; }
154 // The columns with their attributes; MUST be defined by the derived class.
155 GenericColumnInfo m_columndata
;
156 static int wxCALLBACK
SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
);
161 * Must be overriden by the derived class and return the dialog where this list is.
162 * @see CamuleDlg::DialogType
165 virtual CamuleDlg::DialogType
GetParentDialog() = 0;
168 * Updates the displayed number representing the amount of clients currently shown.
170 void ShowSourcesCount( int diff
);
173 * Overloaded function needed for custom drawing of items.
175 virtual void OnDrawItem( int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
);
178 * Draws a client item.
180 void DrawClientItem( wxDC
* dc
, int nColumn
, const wxRect
& rect
, ClientCtrlItem_Struct
* item
, int iTextOffset
, int iBitmapOffset
, int iBitmapXSize
) const;
183 * Draws the download status (chunk) bar for a client.
185 void DrawSourceStatusBar( const CClientRef
& source
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const;
188 * Draaws the file parts bar for a client.
190 void DrawStatusBar( const CClientRef
& client
, wxDC
* dc
, const wxRect
& rect1
) const;
193 * @see CMuleListCtrl::GetTTSText
196 virtual wxString
GetTTSText(unsigned) const { return wxEmptyString
; }
199 * Set "show sources" or "show peers" flag in Known File
201 virtual void SetShowSources(CKnownFile
*, bool) const = 0;
204 * Translate the CID to a unique string for saving column sizes
205 * @see CMuleListCtrl::InsertColumn
207 wxString
TranslateCIDToName(GenericColumnEnum cid
);
209 static int Compare( const CClientRef
& client1
, const CClientRef
& client2
, long lParamColumnSort
);
211 // Event-handlers for clients.
212 void OnSwapSource( wxCommandEvent
& event
);
213 void OnViewFiles( wxCommandEvent
& event
);
214 void OnAddFriend( wxCommandEvent
& event
);
215 void OnSetFriendslot( wxCommandEvent
& event
);
216 void OnSendMessage( wxCommandEvent
& event
);
217 void OnViewClientInfo( wxCommandEvent
& event
);
219 // Misc event-handlers
220 void OnItemActivated( wxListEvent
& event
);
221 void OnMouseRightClick( wxListEvent
& event
);
222 void OnMouseMiddleClick( wxListEvent
& event
);
223 void OnKeyPressed( wxKeyEvent
& event
);
225 //! The type of list used to store items on the listctrl. We use the unique ECID as key.
226 typedef std::multimap
<uint32
, ClientCtrlItem_Struct
*> ListItems
;
227 //! Shortcut to the pair-type used on the list.
228 typedef ListItems::value_type ListItemsPair
;
229 //! This pair is used when searching for equal-ranges.
230 typedef std::pair
< ListItems::iterator
, ListItems::iterator
> ListIteratorPair
;
232 //! This list contains everything shown on the list. Sources are only to
233 //! be found on this list if they are being displayed
234 ListItems m_ListItems
;
236 //! Pointer to the current menu object, used to avoid multiple menus.
238 //! Cached brush object.
239 wxBrush m_hilightBrush
;
240 //! Cached brush object.
241 wxBrush m_hilightUnfocusBrush
;
243 //! The number of displayed sources
246 //! The files being shown, if any.
247 CKnownFileVector m_knownfiles
;
249 DECLARE_EVENT_TABLE()
253 void RawAddSource(CKnownFile
* owner
, CClientRef source
, SourceItemType type
);
254 void RawRemoveSource( ListItems::iterator
& it
);
256 virtual bool IsShowingDownloadSources() const = 0;
260 // File_checked_for_headers