No reason to drop requests of already downloading clients if the upload queue is...
[amule.git] / src / DownloadListCtrl.h
blobaadea9159f1882c70e3e2757a2a106024b612bd0
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
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
37 class CPartFile;
38 class CUpDownClient;
39 class wxBitmap;
40 class wxRect;
41 class wxDC;
43 struct FileCtrlItem_Struct;
45 /**
46 * This class is responsible for representing the download queue.
48 * The CDownlodListCtrl class is responsible for drawing files being downloaded.
49 * It is in many ways primary widget within the application, since it is here that
50 * users can inspect and manipulate their current downloads.
53 class CDownloadListCtrl : public CMuleListCtrl
55 public:
56 /**
57 * Constructor.
59 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
61 CDownloadListCtrl(
62 wxWindow *parent,
63 wxWindowID winid = -1,
64 const wxPoint &pos = wxDefaultPosition,
65 const wxSize &size = wxDefaultSize,
66 long style = wxLC_ICON,
67 const wxValidator& validator = wxDefaultValidator,
68 const wxString &name = wxT("downloadlistctrl") );
70 /**
71 * Destructor.
72 */
73 virtual ~CDownloadListCtrl();
76 /**
77 * Adds a file to the list, but it wont show unless it matches the current category.
79 * @param A valid pointer to a new partfile.
81 * Please note that duplicates wont be added.
83 void AddFile( CPartFile* file );
85 /**
86 * Removes the specified file from the list.
88 * @param file A valid pointer of the file to be removed.
90 * This function also removes any sources assosiated with the file.
92 void RemoveFile( CPartFile* file );
94 /**
95 * Shows or hides the sources of a specific file.
97 * @param file A valid pointer to the file to be shown/hidden.
98 * @param show Whenever or not to show the file.
100 * If the file is hidden, then its sources will also be hidden.
102 void ShowFile( CPartFile* file, bool show );
106 * Updates the state of the specified item, possibly causing a redrawing.
108 * @param toupdate The source or file to be updated.
110 * Calling this function with a file as the argument will ensure that the
111 * file is hidden/shown depending on its state and the currently selected
112 * category.
114 void UpdateItem(const void* toupdate);
117 * Returns the current category.
119 uint8 GetCategory() const;
122 * Changes the displayed category and updates the list of shown files.
124 * @param newCategory The new category to display.
126 void ChangeCategory( int newCategory );
130 * Clears all completed files from the list.
132 void ClearCompleted();
134 protected:
135 /// Return old column order.
136 wxString GetOldColumnOrder() const;
138 private:
140 * Updates the displayed number representing the amount of files currently shown.
142 void ShowFilesCount( int diff );
146 * @see CMuleListCtrl::GetTTSText
148 virtual wxString GetTTSText(unsigned item) const;
152 * Overloaded function needed for custom drawing of items.
154 virtual void OnDrawItem( int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted );
157 * Draws a file item.
159 void DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, FileCtrlItem_Struct* item ) const;
162 * Draws the status (chunk) bar for a file.
164 void DrawFileStatusBar( const CPartFile* file, wxDC* dc, const wxRect& rect, bool bFlat ) const;
166 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
167 static int Compare( const CPartFile* file1, const CPartFile* file2, long lParamSort );
169 // Event-handlers for files
170 void OnCancelFile( wxCommandEvent& event );
171 void OnSetPriority( wxCommandEvent& event );
172 void OnSwapSources( wxCommandEvent& event );
173 void OnSetCategory( wxCommandEvent& event );
174 void OnSetStatus( wxCommandEvent& event );
175 void OnClearCompleted( wxCommandEvent& event );
176 void OnGetLink( wxCommandEvent& event );
177 void OnGetFeedback( wxCommandEvent& event );
178 void OnViewFileInfo( wxCommandEvent& event );
179 void OnViewFileComments( wxCommandEvent& event );
180 void OnPreviewFile( wxCommandEvent& event );
182 // Misc event-handlers
183 void OnItemActivated( wxListEvent& event );
184 void OnMouseRightClick( wxListEvent& event );
185 void OnMouseMiddleClick( wxListEvent& event );
186 void OnKeyPressed( wxKeyEvent& event );
187 void OnItemSelectionChanged( wxListEvent& event );
190 * Returns true if the given file should be shown in the specified category.
192 * @param file The file to be examined.
193 * @param newel The new category selection.
194 * @return True if the file should be shown, false otherwise.
196 bool ShowItemInCurrentCat( const CPartFile* file, int newsel ) const;
199 * Executes the user-selected preview command on the specified file.
201 * @file The file to be previewed.
203 void PreviewFile(CPartFile* file);
206 //! The type of list used to store items on the listctrl.
207 typedef std::multimap<const void*,FileCtrlItem_Struct*> ListItems;
208 //! Shortcut to the pair-type used on the list.
209 typedef ListItems::value_type ListItemsPair;
210 //! This pair is used when searching for equal-ranges.
211 typedef std::pair< ListItems::iterator, ListItems::iterator > ListIteratorPair;
213 //! This list contains everything shown on the list. Sources are only to
214 //! be found on this list if they are being displayed, whereas files can
215 //! always be found on this list, even if they are currently hidden.
216 ListItems m_ListItems;
219 //! Pointer to the current menu object, used to avoid multiple menus.
220 wxMenu* m_menu;
221 //! Cached brush object.
222 wxBrush m_hilightBrush;
223 //! Cached brush object.
224 wxBrush m_hilightUnfocusBrush;
226 //! The currently displayed category
227 uint8 m_category;
229 //! True if there are any completed files being displayed.
230 bool m_completedFiles;
232 //! The number of displayed files
233 int m_filecount;
235 DECLARE_EVENT_TABLE()
239 #endif
240 // File_checked_for_headers