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.
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 SEARCHDLG_H
27 #define SEARCHDLG_H
28 
29 #include <wx/panel.h>		// Needed for wxPanel
30 #include <wx/notebook.h>	// needed for wxBookCtrlEvent in wx 2.8
31 
32 #include "Types.h"		// Needed for uint16 and uint32
33 
34 
35 class CMuleNotebook;
36 class CSearchListCtrl;
37 class CMuleNotebookEvent;
38 class wxListEvent;
39 class wxSpinEvent;
40 class wxGauge;
41 class CSearchFile;
42 
43 
44 /**
45  * This class represents the Search Dialog, which takes care of
46  * enabling the user to search and to display results in a readable
47  * manner.
48  */
49 class CSearchDlg : public wxPanel
50 {
51 public:
52 	/**
53 	 * Constructor.
54 	 *
55 	 * @param pParent The parent widget passed to the wxPanel constructor.
56 	 */
57 	CSearchDlg(wxWindow* pParent);
58 
59 	/**
60 	 * Destructor.
61 	 */
62 	~CSearchDlg();
63 
64 
65 	/**
66 	 * Adds the provided result to the right result-list.
67 	 *
68 	 * Please note that there is no duplicates checking, so the files should
69 	 * indeed be a new result.
70 	 */
71 	void AddResult(CSearchFile* toadd);
72 
73 	/**
74 	 * Updates a changed result.
75 	 *
76 	 * @param A pointer to the updated CSearchFile.
77 	 *
78 	 * This function will update the source-count and color of the result, and
79 	 * if needed, it will also move the result so that the current sorting
80 	 * is maintained.
81 	 */
82 	void UpdateResult(CSearchFile* toupdate);
83 
84 	/**
85 	 * Checks if a result-page with the specified heading exists.
86 	 *
87 	 * @param searchString The heading to look for.
88 	 */
89 	bool		CheckTabNameExists(const wxString& searchString);
90 
91 	/**
92 	 * Creates a new tab and displays the specified results.
93 	 *
94 	 * @param searchString This will be the heading of the new page.
95 	 * @param nSearchID The results with this searchId will be displayed.
96 	 */
97 	void		CreateNewTab(const wxString& searchString, wxUIntPtr nSearchID);
98 
99 
100 	/**
101 	 * Call this function to signify that the local search is over.
102 	 */
103 	void		LocalSearchEnd();
104 
105 
106 	/**
107 	 * Call this function to signify that the kad search is over.
108 	 */
109 	void		KadSearchEnd(uint32 id);
110 
111 
112 	/**
113 	 * This function updates the category list according to existing categories.
114 	 */
115 	void		UpdateCatChoice();
116 
117 
118 	/**
119 	 * This function displays the the hit-count in the heading for the specified page.
120 	 *
121 	 * @param page The page to have its heading updated.
122 	 */
123 	void		UpdateHitCount(CSearchListCtrl* page);
124 
125 	/**
126 	 * Helper function which resets the controls.
127 	 */
128 	void		ResetControls();
129 
130 	// Event handler and helper function
131 	void		OnBnClickedDownload(wxCommandEvent& ev);
132 
133 	CSearchListCtrl* GetSearchList( wxUIntPtr id );
134 
135 	void	UpdateProgress(uint32 new_value);
136 
137 	void	StartNewSearch();
138 
139 	void FixSearchTypes();
140 
141 private:
142 	// Event handlers
143 	void		OnFieldChanged(wxEvent& evt);
144 
145 	void		OnListItemSelected(wxListEvent& ev);
146 	void		OnBnClickedReset(wxCommandEvent& ev);
147 	void		OnBnClickedClear(wxCommandEvent& ev);
148 	void		OnExtendedSearchChange(wxCommandEvent& ev);
149 	void		OnFilterCheckChange(wxCommandEvent& ev);
150 	void		OnFilteringChange(wxCommandEvent& ev);
151 
152 	void		OnSearchClosing(wxBookCtrlEvent& evt);
153 
154 	void		OnBnClickedStart(wxCommandEvent& evt);
155 	void		OnBnClickedStop(wxCommandEvent& evt);
156 
157 
158 	/**
159 	 * Event-handler for page-chages which takes care of enabling/disabling the download button.
160 	 */
161 	void		OnSearchPageChanged(wxBookCtrlEvent& evt);
162 
163 	uint32		m_last_search_time;
164 
165 	wxGauge*	m_progressbar;
166 
167 	CMuleNotebook*	m_notebook;
168 
169 	wxArrayString m_searchchoices;
170 
171 	DECLARE_EVENT_TABLE()
172 };
173 
174 #endif
175 // File_checked_for_headers
176