Updated Russian documentation by Morse.
[amule.git] / src / GenericClientListCtrl.h
blob24993a95a491267c9b09d6ff3e2cceeb88ea57e2
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 //
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
8 // respective authors.
9 //
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.
19 //
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
30 #include <wx/brush.h>
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
37 class CPartFile;
38 class CClientRef;
39 class wxBitmap;
40 class wxRect;
41 class wxDC;
43 struct ClientCtrlItem_Struct;
45 enum GenericColumnEnum {
46 ColumnUserName = 0,
47 ColumnUserDownloaded,
48 ColumnUserUploaded,
49 ColumnUserSpeedDown,
50 ColumnUserSpeedUp,
51 ColumnUserProgress,
52 ColumnUserAvailable,
53 ColumnUserVersion,
54 ColumnUserQueueRankLocal,
55 ColumnUserQueueRankRemote,
56 ColumnUserOrigin,
57 ColumnUserFileNameDownload,
58 ColumnUserFileNameUpload,
59 ColumnUserFileNameDownloadRemote,
60 ColumnInvalid
63 struct CGenericClientListCtrlColumn {
64 GenericColumnEnum cid;
65 wxString title;
66 int width;
69 struct GenericColumnInfo {
70 GenericColumnInfo(int n, CGenericClientListCtrlColumn* col) : n_columns(n), columns(col) { };
71 int n_columns;
72 CGenericClientListCtrlColumn* columns;
75 typedef std::vector<CKnownFile*> CKnownFileVector;
77 /**
78 * This class is responsible for representing clients in a generic way.
81 class CGenericClientListCtrl : public CMuleListCtrl
83 public:
84 /**
85 * Constructor.
87 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
89 CGenericClientListCtrl(
90 const wxString& tablename,
91 wxWindow *parent,
92 wxWindowID winid,
93 const wxPoint &pos,
94 const wxSize &size,
95 long style,
96 const wxValidator& validator,
97 const wxString &name);
99 /**
100 * Destructor.
102 virtual ~CGenericClientListCtrl();
105 * Initializes the control. We need a 2-stage initialization so the derived class members can be called.
107 void InitColumnData();
110 * Adds a source belonging to the specified file.
112 * @param owner The owner of this specific source-entry, must be a valid pointer.
113 * @param source The client object to be added, must be a valid pointer.
114 * @param type If the source is a current source, or a A4AF source.
116 * Please note that the specified client will only be added to the list if it's
117 * owner is shown, otherwise the source will simply be ignored.
118 * Duplicates wont be added.
120 void AddSource( CKnownFile* owner, const CClientRef& source, SourceItemType type );
123 * Removes a source from the list.
125 * @param source ID of the source to be removed.
126 * @param owner Either a specific file, or NULL to remove the source from all files.
128 void RemoveSource( uint32 source, const CKnownFile* owner );
131 * Shows the clients of specific files.
133 * @param file A valid, sorted vector of files whose clients will be shown.
135 * WARNING: The received vector *MUST* be odered with std::sort.
138 void ShowSources( const CKnownFileVector& files );
141 * Updates the state of the specified item, possibly causing a redrawing.
143 * @param toupdate ID of the client to be updated.
144 * @param type If the source is a current source, or a A4AF source.
147 void UpdateItem(uint32 toupdate, SourceItemType type);
149 void SetShowing( bool status ) { m_showing = status; }
150 bool GetShowing() const { return m_showing; }
152 protected:
153 // The columns with their attributes; MUST be defined by the derived class.
154 GenericColumnInfo m_columndata;
155 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
157 private:
160 * Must be overriden by the derived class and return the dialog where this list is.
161 * @see CamuleDlg::DialogType
164 virtual CamuleDlg::DialogType GetParentDialog() = 0;
167 * Updates the displayed number representing the amount of clients currently shown.
169 void ShowSourcesCount( int diff );
172 * Overloaded function needed for custom drawing of items.
174 virtual void OnDrawItem( int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted );
177 * Draws a client item.
179 void DrawClientItem( wxDC* dc, int nColumn, const wxRect& rect, ClientCtrlItem_Struct* item, int iTextOffset, int iBitmapOffset, int iBitmapXSize ) const;
182 * Draws the download status (chunk) bar for a client.
184 void DrawSourceStatusBar( const CClientRef& source, wxDC* dc, const wxRect& rect, bool bFlat) const;
187 * Draaws the file parts bar for a client.
189 void DrawStatusBar( const CClientRef& client, wxDC* dc, const wxRect& rect1 ) const;
192 * @see CMuleListCtrl::GetTTSText
193 * Just a dummy
195 virtual wxString GetTTSText(unsigned) const { return wxEmptyString; }
198 * Set "show sources" or "show peers" flag in Known File
200 virtual void SetShowSources(CKnownFile *, bool) const = 0;
203 * Translate the CID to a unique string for saving column sizes
204 * @see CMuleListCtrl::InsertColumn
206 wxString TranslateCIDToName(GenericColumnEnum cid);
208 static int Compare( const CClientRef& client1, const CClientRef& client2, long lParamColumnSort);
210 // Event-handlers for clients.
211 void OnSwapSource( wxCommandEvent& event );
212 void OnViewFiles( wxCommandEvent& event );
213 void OnAddFriend( wxCommandEvent& event );
214 void OnSetFriendslot( wxCommandEvent& event );
215 void OnSendMessage( wxCommandEvent& event );
216 void OnViewClientInfo( wxCommandEvent& event );
218 // Misc event-handlers
219 void OnItemActivated( wxListEvent& event );
220 void OnMouseRightClick( wxListEvent& event );
221 void OnMouseMiddleClick( wxListEvent& event );
222 void OnKeyPressed( wxKeyEvent& event );
224 //! The type of list used to store items on the listctrl. We use the unique ECID as key.
225 typedef std::multimap<uint32, ClientCtrlItem_Struct*> ListItems;
226 //! Shortcut to the pair-type used on the list.
227 typedef ListItems::value_type ListItemsPair;
228 //! This pair is used when searching for equal-ranges.
229 typedef std::pair< ListItems::iterator, ListItems::iterator > ListIteratorPair;
231 //! This list contains everything shown on the list. Sources are only to
232 //! be found on this list if they are being displayed
233 ListItems m_ListItems;
235 //! Pointer to the current menu object, used to avoid multiple menus.
236 wxMenu* m_menu;
237 //! Cached brush object.
238 wxBrush m_hilightBrush;
239 //! Cached brush object.
240 wxBrush m_hilightUnfocusBrush;
242 //! The number of displayed sources
243 int m_clientcount;
245 //! The files being shown, if any.
246 CKnownFileVector m_knownfiles;
248 DECLARE_EVENT_TABLE()
250 bool m_showing;
252 void RawAddSource(CKnownFile* owner, CClientRef source, SourceItemType type);
253 void RawRemoveSource( ListItems::iterator& it );
255 virtual bool IsShowingDownloadSources() const = 0;
258 #endif
259 // File_checked_for_headers