2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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
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.
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 DOWNLOADLISTCTRL_H
27 #define DOWNLOADLISTCTRL_H
29 #include <map> // Needed for std::multimap
32 #include "Types.h" // Needed for uint8
33 #include "Constants.h" // Needed for DownloadItemType
34 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
43 struct CtrlItem_Struct
;
48 * This class is responsible for representing the download queue.
50 * The CDownlodListCtrl class is responsible for drawing not only files being
51 * downloaded, but also sources assosiated with these. It is in many ways
52 * primary widget within the application, since it is here that users can
53 * inspect and manipulate their current downloads.
55 * Due to the fact that sources are one of the major sources of update-class,
56 * this class has been designed such that it does not need to recieve these
57 * unless sources in question are actually being displayed. Upon the initial
58 * showing of sources (when a file is expanded), a current list of that file's
59 * sources are requested. If the sources are hidden again, the class will
60 * discard all knowledge of their existance.
62 class CDownloadListCtrl
: public CMuleListCtrl
68 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
72 wxWindowID winid
= -1,
73 const wxPoint
&pos
= wxDefaultPosition
,
74 const wxSize
&size
= wxDefaultSize
,
75 long style
= wxLC_ICON
,
76 const wxValidator
& validator
= wxDefaultValidator
,
77 const wxString
&name
= wxT("downloadlistctrl") );
82 virtual ~CDownloadListCtrl();
86 * Adds a file to the list, but it wont show unless it matches the current category.
88 * @param A valid pointer to a new partfile.
90 * Please note that duplicates wont be added.
92 void AddFile( CPartFile
* file
);
95 * Adds a source belonging to the specified partfile.
97 * @param owner The owner of this specific source-entry, must be a valid pointer.
98 * @param source The client object to be added, must be a valid pointer.
99 * @param available If the source is a current source, or a A4AF source.
101 * Please note that the specified client will only be added to the list if it's
102 * owner is shown and has ShowSources set to true, otherwise the source will
103 * simply be ignored. Duplicates wont be added.
105 void AddSource( CPartFile
* owner
, CUpDownClient
* source
, DownloadItemType type
);
109 * Removes a source from the list.
111 * @param source A pointer to the source to be removed.
112 * @param owner Either a specific file, or NULL to remove the source from all files.
114 void RemoveSource( const CUpDownClient
* source
, const CPartFile
* owner
);
117 * Removes the specified file from the list.
119 * @param file A valid pointer of the file to be removed.
121 * This function also removes any sources assosiated with the file.
123 void RemoveFile( CPartFile
* file
);
127 * Toggles showing of a file's sources on or off.
129 * @param file The file whoose sources should be shown/hidden.
130 * @param show Whenever or not to show sources.
132 void ShowSources( CPartFile
* file
, bool show
);
135 * Shows or hides the sources of a specific file.
137 * @param file A valid pointer to the file to be shown/hidden.
138 * @param show Whenever or not to show the file.
140 * If the file is hidden, then its sources will also be hidden.
142 void ShowFile( CPartFile
* file
, bool show
);
146 * Updates the state of the specified item, possibly causing a redrawing.
148 * @param toupdate The source or file to be updated.
150 * Calling this function with a file as the argument will ensure that the
151 * file is hidden/shown depending on its state and the currently selected
154 void UpdateItem(const void* toupdate
);
158 * Returns the current category.
160 uint8
GetCategory() const;
163 * Changes the displayed category and updates the list of shown files.
165 * @param newCategory The new category to display.
167 void ChangeCategory( int newCategory
);
171 * Clears all completed files from the list.
173 void ClearCompleted();
176 /// Return old column order.
177 wxString
GetOldColumnOrder() const;
181 * Updates the displayed number representing the amount of files currently shown.
183 void ShowFilesCount( int diff
);
187 * @see CMuleListCtrl::GetTTSText
189 virtual wxString
GetTTSText(unsigned item
) const;
193 * Overloaded function needed for custom drawing of items.
195 virtual void OnDrawItem( int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
);
200 void DrawFileItem( wxDC
* dc
, int nColumn
, const wxRect
& rect
, CtrlItem_Struct
* item
) const;
203 * Draws a source item.
205 void DrawSourceItem( wxDC
* dc
, int nColumn
, const wxRect
& rect
, CtrlItem_Struct
* item
) const;
208 * Draws the status (chunk) bar for a file.
210 void DrawFileStatusBar( const CPartFile
* file
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const;
213 * Draws the status (chunk) bar for a source.
215 void DrawSourceStatusBar( const CUpDownClient
* source
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const;
218 static int wxCALLBACK
SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
);
219 static int Compare( const CPartFile
* file1
, const CPartFile
* file2
, long lParamSort
);
220 static int Compare( const CUpDownClient
* client1
, const CUpDownClient
* client2
, long lParamSort
);
223 // Event-handlers for files
224 void OnCancelFile( wxCommandEvent
& event
);
225 void OnSetPriority( wxCommandEvent
& event
);
226 void OnSwapSources( wxCommandEvent
& event
);
227 void OnSetCategory( wxCommandEvent
& event
);
228 void OnSetStatus( wxCommandEvent
& event
);
229 void OnClearCompleted( wxCommandEvent
& event
);
230 void OnGetLink( wxCommandEvent
& event
);
231 void OnGetFeedback( wxCommandEvent
& event
);
232 void OnGetRazorStats( wxCommandEvent
& event
);
233 void OnViewFileInfo( wxCommandEvent
& event
);
234 void OnViewFileComments( wxCommandEvent
& event
);
235 void OnPreviewFile( wxCommandEvent
& event
);
237 // Event-handlers for sources
238 void OnSwapSource( wxCommandEvent
& event
);
239 void OnViewFiles( wxCommandEvent
& event
);
240 void OnAddFriend( wxCommandEvent
& event
);
241 void OnSendMessage( wxCommandEvent
& event
);
242 void OnViewClientInfo( wxCommandEvent
& event
);
244 // Misc event-handlers
245 void OnItemActivated( wxListEvent
& event
);
246 void OnMouseRightClick( wxListEvent
& event
);
247 void OnMouseMiddleClick( wxListEvent
& event
);
248 void OnKeyPressed( wxKeyEvent
& event
);
252 * Returns true if the given file should be shown in the specified category.
254 * @param file The file to be examined.
255 * @param newel The new category selection.
256 * @return True if the file should be shown, false otherwise.
258 bool ShowItemInCurrentCat( const CPartFile
* file
, int newsel
) const;
261 * Executes the user-selected preview command on the specified file.
263 * @file The file to be previewed.
265 void PreviewFile(CPartFile
* file
);
268 //! The type of list used to store items on the listctrl.
269 typedef std::multimap
<const void*,CtrlItem_Struct
*> ListItems
;
270 //! Shortcut to the pair-type used on the list.
271 typedef ListItems::value_type ListItemsPair
;
272 //! This pair is used when searching for equal-ranges.
273 typedef std::pair
< ListItems::iterator
, ListItems::iterator
> ListIteratorPair
;
275 //! This list contains everything shown on the list. Sources are only to
276 //! be found on this list if they are being displayed, whereas files can
277 //! always be found on this list, even if they are currently hidden.
278 ListItems m_ListItems
;
281 //! Pointer to the current menu object, used to avoid multiple menus.
283 //! Cached brush object.
284 wxBrush m_hilightBrush
;
285 //! Cached brush object.
286 wxBrush m_hilightUnfocusBrush
;
289 //! The currently displayed category
292 //! True if there are any completed files being displayed.
293 bool m_completedFiles
;
295 //! The number of displayed files
298 DECLARE_EVENT_TABLE()
312 ColumnLastSeenComplete
,
314 ColumnNumberOfColumns
319 // File_checked_for_headers