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 // 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. 10 // 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. 15 // 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 24 // 25 26 #ifndef DOWNLOADLISTCTRL_H 27 #define DOWNLOADLISTCTRL_H 28 29 #include <map> // Needed for std::multimap 30 #include <wx/brush.h> 31 32 #include "Types.h" // Needed for uint8 33 #include "Constants.h" // Needed for DownloadItemType 34 #include "MuleListCtrl.h" // Needed for CMuleListCtrl 35 36 37 class CPartFile; 38 class wxBitmap; 39 class wxRect; 40 class wxDC; 41 42 struct FileCtrlItem_Struct; 43 44 /** 45 * This class is responsible for representing the download queue. 46 * 47 * The CDownlodListCtrl class is responsible for drawing files being downloaded. 48 * It is in many ways primary widget within the application, since it is here that 49 * users can inspect and manipulate their current downloads. 50 * 51 */ 52 class CDownloadListCtrl : public CMuleListCtrl 53 { 54 public: 55 /** 56 * Constructor. 57 * 58 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters. 59 */ 60 CDownloadListCtrl( 61 wxWindow *parent, 62 wxWindowID winid = -1, 63 const wxPoint &pos = wxDefaultPosition, 64 const wxSize &size = wxDefaultSize, 65 long style = wxLC_ICON, 66 const wxValidator& validator = wxDefaultValidator, 67 const wxString &name = wxT("downloadlistctrl") ); 68 69 /** 70 * Destructor. 71 */ 72 virtual ~CDownloadListCtrl(); 73 74 75 /** 76 * Adds a file to the list, but it wont show unless it matches the current category. 77 * 78 * @param A valid pointer to a new partfile. 79 * 80 * Please note that duplicates wont be added. 81 */ 82 void AddFile( CPartFile* file ); 83 84 /** 85 * Removes the specified file from the list. 86 * 87 * @param file A valid pointer of the file to be removed. 88 * 89 * This function also removes any sources assosiated with the file. 90 */ 91 void RemoveFile( CPartFile* file ); 92 93 /** 94 * Shows or hides the sources of a specific file. 95 * 96 * @param file A valid pointer to the file to be shown/hidden. 97 * @param show Whenever or not to show the file. 98 * 99 * If the file is hidden, then its sources will also be hidden. 100 */ 101 void ShowFile( CPartFile* file, bool show ); 102 103 104 /** 105 * Updates the state of the specified item, possibly causing a redrawing. 106 * 107 * @param toupdate The source or file to be updated. 108 * 109 * Calling this function with a file as the argument will ensure that the 110 * file is hidden/shown depending on its state and the currently selected 111 * category. 112 */ 113 void UpdateItem(const void* toupdate); 114 115 /** 116 * Returns the current category. 117 */ 118 uint8 GetCategory() const; 119 120 /** 121 * Changes the displayed category and updates the list of shown files. 122 * 123 * @param newCategory The new category to display. 124 */ 125 void ChangeCategory( int newCategory ); 126 127 128 /** 129 * Clears all completed files from the list. 130 */ 131 void ClearCompleted(); 132 133 /** 134 * Perform client update when item selection has changed. 135 */ 136 void DoItemSelectionChanged(); 137 138 protected: 139 /// Return old column order. 140 wxString GetOldColumnOrder() const; 141 142 private: 143 /** 144 * Updates the displayed number representing the amount of files currently shown. 145 */ 146 void ShowFilesCount( int diff ); 147 148 149 /** 150 * @see CMuleListCtrl::GetTTSText 151 */ 152 virtual wxString GetTTSText(unsigned item) const; 153 154 155 /** 156 * Overloaded function needed for custom drawing of items. 157 */ 158 virtual void OnDrawItem( int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted ); 159 160 /** 161 * Draws a file item. 162 */ 163 void DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, FileCtrlItem_Struct* item ) const; 164 165 /** 166 * Draws the status (chunk) bar for a file. 167 */ 168 void DrawFileStatusBar( const CPartFile* file, wxDC* dc, const wxRect& rect, bool bFlat ) const; 169 170 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData); 171 static int Compare( const CPartFile* file1, const CPartFile* file2, long lParamSort ); 172 173 // Event-handlers for files 174 void OnCancelFile( wxCommandEvent& event ); 175 void OnSetPriority( wxCommandEvent& event ); 176 void OnSwapSources( wxCommandEvent& event ); 177 void OnSetCategory( wxCommandEvent& event ); 178 void OnSetStatus( wxCommandEvent& event ); 179 void OnClearCompleted( wxCommandEvent& event ); 180 void OnGetLink( wxCommandEvent& event ); 181 void OnGetFeedback( wxCommandEvent& event ); 182 void OnViewFileInfo( wxCommandEvent& event ); 183 void OnViewFileComments( wxCommandEvent& event ); 184 void OnPreviewFile( wxCommandEvent& event ); 185 186 // Misc event-handlers 187 void OnItemActivated( wxListEvent& event ); 188 void OnMouseRightClick( wxListEvent& event ); 189 void OnMouseMiddleClick( wxListEvent& event ); 190 void OnKeyPressed( wxKeyEvent& event ); 191 void OnItemSelectionChanged( wxListEvent& event ); 192 193 /** 194 * Executes the user-selected preview command on the specified file. 195 * 196 * @file The file to be previewed. 197 */ 198 void PreviewFile(CPartFile* file); 199 200 /** 201 * Show file detail dialog for item at index 202 */ 203 void ShowFileDetailDialog(long index); 204 205 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; 212 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; 217 218 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; 225 226 //! The currently displayed category 227 uint8 m_category; 228 229 //! Flag if change of item selection is pending 230 bool m_ItemSelectionChangePending; 231 232 //! The number of displayed files 233 int m_filecount; 234 235 DECLARE_EVENT_TABLE() 236 237 }; 238 239 #endif 240 // File_checked_for_headers 241