Upstream tarball 20080522
[amule.git] / src / DownloadListCtrl.h
blob3ca9f1e5850be04c7549af721f6992ad0018d7fa
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 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 DOWNLOADLISTCTRL_H
27 #define DOWNLOADLISTCTRL_H
29 #include <map> // Needed for std::multimap
31 #include "Types.h" // Needed for uint8
32 #include "Constants.h" // Needed for DownloadItemType
33 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
36 class CPartFile;
37 class CUpDownClient;
38 class wxBitmap;
39 class wxRect;
40 class wxDC;
42 struct CtrlItem_Struct;
46 /**
47 * This class is responsible for representing the download queue.
49 * The CDownlodListCtrl class is responsible for drawing not only files being
50 * downloaded, but also sources assosiated with these. It is in many ways
51 * primary widget within the application, since it is here that users can
52 * inspect and manipulate their current downloads.
54 * Due to the fact that sources are one of the major sources of update-class,
55 * this class has been designed such that it does not need to recieve these
56 * unless sources in question are actually being displayed. Upon the initial
57 * showing of sources (when a file is expanded), a current list of that file's
58 * sources are requested. If the sources are hidden again, the class will
59 * discard all knowledge of their existance.
61 class CDownloadListCtrl : public CMuleListCtrl
63 public:
64 /**
65 * Constructor.
67 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
69 CDownloadListCtrl(
70 wxWindow *parent,
71 wxWindowID winid = -1,
72 const wxPoint &pos = wxDefaultPosition,
73 const wxSize &size = wxDefaultSize,
74 long style = wxLC_ICON,
75 const wxValidator& validator = wxDefaultValidator,
76 const wxString &name = wxT("downloadlistctrl") );
78 /**
79 * Destructor.
80 */
81 virtual ~CDownloadListCtrl();
84 /**
85 * Adds a file to the list, but it wont show unless it matches the current category.
87 * @param A valid pointer to a new partfile.
89 * Please note that duplicates wont be added.
91 void AddFile( CPartFile* file );
93 /**
94 * Adds a source belonging to the specified partfile.
96 * @param owner The owner of this specific source-entry, must be a valid pointer.
97 * @param source The client object to be added, must be a valid pointer.
98 * @param available If the source is a current source, or a A4AF source.
100 * Please note that the specified client will only be added to the list if it's
101 * owner is shown and has ShowSources set to true, otherwise the source will
102 * simply be ignored. Duplicates wont be added.
104 void AddSource( CPartFile* owner, CUpDownClient* source, DownloadItemType type );
108 * Removes a source from the list.
110 * @param source A pointer to the source to be removed.
111 * @param owner Either a specific file, or NULL to remove the source from all files.
113 void RemoveSource( const CUpDownClient* source, const CPartFile* owner );
116 * Removes the specified file from the list.
118 * @param file A valid pointer of the file to be removed.
120 * This function also removes any sources assosiated with the file.
122 void RemoveFile( CPartFile* file );
126 * Toggles showing of a file's sources on or off.
128 * @param file The file whoose sources should be shown/hidden.
129 * @param show Whenever or not to show sources.
131 void ShowSources( CPartFile* file, bool show );
134 * Shows or hides the sources of a specific file.
136 * @param file A valid pointer to the file to be shown/hidden.
137 * @param show Whenever or not to show the file.
139 * If the file is hidden, then its sources will also be hidden.
141 void ShowFile( CPartFile* file, bool show );
145 * Updates the state of the specified item, possibly causing a redrawing.
147 * @param toupdate The source or file to be updated.
149 * Calling this function with a file as the argument will ensure that the
150 * file is hidden/shown depending on its state and the currently selected
151 * category.
153 void UpdateItem(const void* toupdate);
157 * Returns the current category.
159 uint8 GetCategory() const;
162 * Changes the displayed category and updates the list of shown files.
164 * @param newCategory The new category to display.
166 void ChangeCategory( int newCategory );
170 * Clears all completed files from the list.
172 void ClearCompleted();
174 private:
176 * Updates the displayed number representing the ammount of files currently shown.
178 void ShowFilesCount( int diff );
182 * @see CMuleListCtrl::GetTTSText
184 virtual wxString GetTTSText(unsigned item) const;
188 * Overloaded function needed for custom drawing of items.
190 virtual void OnDrawItem( int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted );
193 * Draws a file item.
195 void DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, CtrlItem_Struct* item ) const;
198 * Draws a source item.
200 void DrawSourceItem( wxDC* dc, int nColumn, const wxRect& rect, CtrlItem_Struct* item ) const;
203 * Draws the status (chunk) bar for a file.
205 void DrawFileStatusBar( const CPartFile* file, wxDC* dc, const wxRect& rect, bool bFlat ) const;
208 * Draws the status (chunk) bar for a source.
210 void DrawSourceStatusBar( const CUpDownClient* source, wxDC* dc, const wxRect& rect, bool bFlat) const;
213 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
214 static int Compare( const CPartFile* file1, const CPartFile* file2, long lParamSort );
215 static int Compare( const CUpDownClient* client1, const CUpDownClient* client2, long lParamSort);
218 // Event-handlers for files
219 void OnCancelFile( wxCommandEvent& event );
220 void OnSetPriority( wxCommandEvent& event );
221 void OnSwapSources( wxCommandEvent& event );
222 void OnSetCategory( wxCommandEvent& event );
223 void OnSetStatus( wxCommandEvent& event );
224 void OnClearCompleted( wxCommandEvent& event );
225 void OnGetLink( wxCommandEvent& event );
226 void OnGetFeedback( wxCommandEvent& event );
227 void OnGetRazorStats( wxCommandEvent& event );
228 void OnViewFileInfo( wxCommandEvent& event );
229 void OnViewFileComments( wxCommandEvent& event );
230 void OnPreviewFile( wxCommandEvent& event );
232 // Event-handlers for sources
233 void OnSwapSource( wxCommandEvent& event );
234 void OnViewFiles( wxCommandEvent& event );
235 void OnAddFriend( wxCommandEvent& event );
236 void OnSendMessage( wxCommandEvent& event );
237 void OnViewClientInfo( wxCommandEvent& event );
239 // Misc event-handlers
240 void OnItemActivated( wxListEvent& event );
241 void OnMouseRightClick( wxListEvent& event );
242 void OnMouseMiddleClick( wxListEvent& event );
243 void OnKeyPressed( wxKeyEvent& event );
247 * Returns true if the given file should be shown in the specified category.
249 * @param file The file to be examined.
250 * @param newel The new category selection.
251 * @return True if the file should be shown, false otherwise.
253 bool ShowItemInCurrentCat( const CPartFile* file, int newsel ) const;
256 * Executes the user-selected preview command on the specified file.
258 * @file The file to be previewed.
260 void PreviewFile(CPartFile* file);
263 //! The type of list used to store items on the listctrl.
264 typedef std::multimap<const void*,CtrlItem_Struct*> ListItems;
265 //! Shortcut to the pair-type used on the list.
266 typedef ListItems::value_type ListItemsPair;
267 //! This pair is used when searching for equal-ranges.
268 typedef std::pair< ListItems::iterator, ListItems::iterator > ListIteratorPair;
270 //! This list contains everything shown on the list. Sources are only to
271 //! be found on this list if they are being displayed, whereas files can
272 //! always be found on this list, even if they are currently hidden.
273 ListItems m_ListItems;
276 //! Pointer to the current menu object, used to avoid multiple menus.
277 wxMenu* m_menu;
278 //! Pointer to a cached brush object.
279 wxBrush* m_hilightBrush;
280 //! Pointer to a cached brush object.
281 wxBrush* m_hilightUnfocusBrush;
284 //! The currently displayed category
285 uint8 m_category;
287 //! True if there are any completed files being displayed.
288 bool m_completedFiles;
290 //! The number of displayed files
291 int m_filecount;
293 DECLARE_EVENT_TABLE()
296 #endif
297 // File_checked_for_headers