]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
port Konqueror from KUrl to QUrl
[dolphin.git] / src / search / dolphinsearchbox.h
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINSEARCHBOX_H
21 #define DOLPHINSEARCHBOX_H
22
23 #include <KUrl>
24 #include <QWidget>
25
26 #include <config-baloo.h>
27
28 class DolphinFacetsWidget;
29 class KLineEdit;
30 class KSeparator;
31 class QToolButton;
32 class QScrollArea;
33 class QLabel;
34 class QVBoxLayout;
35
36 namespace Baloo {
37 class QueryBuilder;
38 class NaturalQueryParser;
39 }
40
41 /**
42 * @brief Input box for searching files with or without Baloo.
43 *
44 * The widget allows to specify:
45 * - Where to search: Everywhere or below the current directory
46 * - What to search: Filenames or content
47 *
48 * If Baloo is available and the current folder is indexed, further
49 * options are offered.
50 */
51 class DolphinSearchBox : public QWidget {
52 Q_OBJECT
53
54 public:
55 explicit DolphinSearchBox(QWidget* parent = 0);
56 virtual ~DolphinSearchBox();
57
58 /**
59 * Sets the text that should be used as input for
60 * searching.
61 */
62 void setText(const QString& text);
63
64 /**
65 * Returns the text that should be used as input
66 * for searching.
67 */
68 QString text() const;
69
70 /**
71 * Sets the current path that is used as root for
72 * searching files, if "From Here" has been selected.
73 */
74 void setSearchPath(const KUrl& url);
75 KUrl searchPath() const;
76
77 /** @return URL that will start the searching of files. */
78 KUrl urlForSearching() const;
79
80 /**
81 * Extracts information from the given search \a url to
82 * initialize the search box properly.
83 */
84 void fromSearchUrl(const KUrl& url);
85
86 /**
87 * Selects the whole text of the search box.
88 */
89 void selectAll();
90
91 /**
92 * Set the search box to the active mode, if \a active
93 * is true. The active mode is default. The inactive mode only differs
94 * visually from the active mode, no change of the behavior is given.
95 *
96 * Using the search box in the inactive mode is useful when having split views,
97 * where the inactive view is indicated by an search box visually.
98 */
99 void setActive(bool active);
100
101 /**
102 * @return True, if the search box is in the active mode.
103 * @see DolphinSearchBox::setActive()
104 */
105 bool isActive() const;
106
107 protected:
108 virtual bool event(QEvent* event);
109 virtual void showEvent(QShowEvent* event);
110 virtual void keyReleaseEvent(QKeyEvent* event);
111 virtual bool eventFilter(QObject* obj, QEvent* event);
112
113 signals:
114 /**
115 * Is emitted when a searching should be triggered.
116 */
117 void searchRequest();
118
119 /**
120 * Is emitted when the user has changed a character of
121 * the text that should be used as input for searching.
122 */
123 void searchTextChanged(const QString& text);
124
125 void returnPressed(const QString& text);
126
127 /**
128 * Emitted as soon as the search box should get closed.
129 */
130 void closeRequest();
131
132 /**
133 * Is emitted, if the searchbox has been activated by
134 * an user interaction
135 * @see DolphinSearchBox::setActive()
136 */
137 void activated();
138
139 private slots:
140 void emitSearchRequest();
141 void emitCloseRequest();
142 void slotConfigurationChanged();
143 void slotSearchTextChanged();
144 void slotReturnPressed();
145 void slotFacetsButtonToggled();
146 void slotFacetChanged();
147 void updateSearchInputParsing();
148
149 private:
150 void initButton(QToolButton* button);
151 void loadSettings();
152 void saveSettings();
153 void init();
154
155 /**
156 * @return URL that represents the Baloo query for starting the search.
157 */
158 KUrl balooUrlForSearching() const;
159
160 /**
161 * Extracts information from the given Baloo search \a url to
162 * initialize the search box properly.
163 */
164 void fromBalooSearchUrl(const KUrl& url);
165
166 void updateFacetsToggleButton();
167 private:
168 bool m_startedSearching;
169 bool m_active;
170
171 QVBoxLayout* m_topLayout;
172
173 QLabel* m_searchLabel;
174 #ifdef HAVE_BALOO
175 Baloo::QueryBuilder* m_searchInput;
176 QScopedPointer<Baloo::NaturalQueryParser> m_queryParser;
177 #else
178 KLineEdit* m_searchInput;
179 #endif
180 QScrollArea* m_optionsScrollArea;
181 QToolButton* m_fileNameButton;
182 QToolButton* m_contentButton;
183 KSeparator* m_separator;
184 QToolButton* m_fromHereButton;
185 QToolButton* m_everywhereButton;
186 QToolButton* m_facetsToggleButton;
187 DolphinFacetsWidget* m_facetsWidget;
188
189 KUrl m_searchPath;
190
191 QTimer* m_startSearchTimer;
192 };
193
194 #endif