debian: fix build-deps for focal
[amule.git] / src / SearchListCtrl.h
blob953a415a759ea544410083cc894543d496994bc7
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-2011 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.
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 SEARCHLISTCTRL_H
27 #define SEARCHLISTCTRL_H
30 #include <wx/colour.h> // Needed for wxColour
31 #include <wx/regex.h> // Needed for wxRegExp
33 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
36 class CSearchList;
37 class CSearchFile;
40 /**
41 * This class is used to display search results.
43 * Results on added to the list will be colored according to
44 * the number of sources and other parameters (see UpdateColor).
46 * To display results, first use the ShowResults function, which will display
47 * all current results with the specified id and afterwards you can use the
48 * AddResult function to add new results or the UpdateResult function to update
49 * already present results. Please note that it is not possible to add results
50 * with the AddResult function before calling ShowResults.
52 class CSearchListCtrl : public CMuleListCtrl
54 public:
55 /**
56 * Constructor.
58 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
60 CSearchListCtrl(
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("mulelistctrl") );
69 /**
70 * Destructor.
72 virtual ~CSearchListCtrl();
74 /**
75 * Adds ths specified file to the list.
77 * @param The new result to be shown.
79 * Please note that no duplicates checking is done, so the pointer should
80 * point to a new file in order to avoid problems. Also note that the result
81 * will be inserted sorted according to current sort-type, so there is no
82 * need to resort the list after adding new items.
84 void AddResult(CSearchFile* toshow);
86 /**
87 * Removes the specified file from the list.
89 void RemoveResult(CSearchFile* toshow);
91 /**
92 * Updates the specified source.
94 * @param The search result to be updated.
96 void UpdateResult(CSearchFile* toupdate);
98 /**
99 * Clears the list and inserts all results with the specified Id instead.
101 * @param nResult The ID of the results or Zero to simply reset the list.
103 void ShowResults( long ResultsId );
106 * Updates the colors of item at the specified index.
108 * @param index The zero-based index of the item.
110 * This function sets the color of the item based on the following:
111 * - Downloading files are marked in red.
112 * - Known (shared/completed) files are marked in green.
113 * - New files are marked in blue depending on the number of sources.
114 * - Canceled files are marked in magenta.
116 void UpdateItemColor(long index);
119 * Returns the current Search Id.
121 * @return The Search Id of the displayed results (set through ShowResults()).
123 wxUIntPtr GetSearchId();
126 * Sets the filter which decides which results should be shown.
128 * @param regExp A regular expression targeting the filenames.
129 * @param invert If true, invert the results of the filter-test.
130 * @param filterKnown Should files that are queued or known be filtered out.
132 * An invalid regExp will result in all results being displayed.
134 void SetFilter(const wxString& regExp, bool invert, bool filterKnown);
137 * Toggles the use of filtering on and off.
139 void EnableFiltering(bool enabled);
142 * Returns the number of items hidden due to filtering.
144 size_t GetHiddenItemCount() const;
147 * Attempts to download all selected items, updating color-scheme as needed.
149 * @param category The target category, or -1 to use the drop-down selection.
151 void DownloadSelected(int category = -1);
153 static wxString DetermineStatusPrintable(CSearchFile *toshow);
155 protected:
156 /// Return old column order.
157 wxString GetOldColumnOrder() const;
160 * Set the sort column
162 * @param column The column with which the list should be sorted.
163 * @param order The order in which to sort the column.
165 * Note that attempting to sort a column in an unsupported order
166 * is an illegal operation.
168 void SetSorting(unsigned column, unsigned order);
170 protected:
171 typedef std::list<CSearchFile*> ResultList;
173 //! List used to store results that are hidden due to matching the filter.
174 ResultList m_filteredOut;
176 //! The current filter reg-exp.
177 wxRegEx m_filter;
179 //! The text from which the filter is compiled.
180 wxString m_filterText;
182 //! Controls if shared/queued results should be shown.
183 bool m_filterKnown;
185 //! Controls if the result of filter-hits should be inverted
186 bool m_invert;
188 //! Specifies if filtering should be used
189 bool m_filterEnabled;
192 * Returns true if the filename is filtered.
194 bool IsFiltered(const CSearchFile* file);
197 * Sorter function used by wxListCtrl::SortItems function.
199 * @see CMuleListCtrl::SetSortFunc
200 * @see wxListCtrl::SortItems
202 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
204 /** @see CMuleListCtrl::AltSortAllowed */
205 virtual bool AltSortAllowed(unsigned column) const;
207 /** @see CMuleListCtrl::GetTTSText */
208 virtual wxString GetTTSText(unsigned item) const;
211 * Helper function which syncs two lists.
213 * @param src The source list.
214 * @param dst The list to be synced with the source list.
216 * This function syncronises the following settings of two lists:
217 * - Sort column
218 * - Sort direction
219 * - Column widths
221 * If either sort column or direction is changed, then the dst list will
222 * be resorted. This function is used to ensure that all results list act
223 * as one, while still allowing individual selection.
225 static void SyncLists( CSearchListCtrl* src, CSearchListCtrl* dst );
228 * Helper function which syncs all other lists against the specified one.
230 * @param src The list which all other lists should be synced against.
232 * This function just calls SyncLists() on all lists in s_lists, using
233 * the src argument as the src argument of the SyncLists function.
235 static void SyncOtherLists( CSearchListCtrl* src );
237 //! This list contains pointers to all current instances of CSearchListCtrl.
238 static std::list<CSearchListCtrl*> s_lists;
240 //! The ID of the search-results which the list is displaying or zero if unset.
241 wxUIntPtr m_nResultsID;
243 //! Custom drawing, needed to display children of search-results.
244 void OnDrawItem(int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted);
247 * Removes or adds child-entries for the given file.
249 void ShowChildren(CSearchFile* file, bool show);
252 * Event handler for right mouse clicks.
254 void OnRightClick( wxListEvent& event );
257 * Event handler for double-clicks or enter.
259 void OnItemActivated( wxListEvent& event );
262 * Event handler for left-clicks on the column headers.
264 * This eventhandler takes care of sync'ing all the other lists with this one.
266 void OnColumnLClick( wxListEvent& event );
269 * Event handler for resizing of the columns.
271 * This eventhandler takes care of sync'ing all the other lists with this one.
273 void OnColumnResize( wxListEvent& event );
276 * Event handler for get-url menu items.
278 void OnPopupGetUrl( wxCommandEvent& event );
281 * Event handler for Razorback 2 stats menu items.
283 void OnRazorStatsCheck( wxCommandEvent& event );
286 * Event handler for related search.
288 void OnRelatedSearch( wxCommandEvent& event );
291 * Event handler for "mark as known".
293 void OnMarkAsKnown( wxCommandEvent& event );
296 * Event handler for download-file(s) menu item.
298 void OnPopupDownload( wxCommandEvent& event );
300 DECLARE_EVENT_TABLE()
303 #endif // SEARCHLISTCTRL_H
304 // File_checked_for_headers