]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Next QUrl porting bug found: search include directories
[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 <QUrl>
24 #include <QWidget>
25
26 class DolphinFacetsWidget;
27 class QLineEdit;
28 class KSeparator;
29 class QToolButton;
30 class QScrollArea;
31 class QLabel;
32 class QVBoxLayout;
33
34 /**
35 * @brief Input box for searching files with or without Baloo.
36 *
37 * The widget allows to specify:
38 * - Where to search: Everywhere or below the current directory
39 * - What to search: Filenames or content
40 *
41 * If Baloo is available and the current folder is indexed, further
42 * options are offered.
43 */
44 class DolphinSearchBox : public QWidget {
45 Q_OBJECT
46
47 public:
48 explicit DolphinSearchBox(QWidget* parent = 0);
49 virtual ~DolphinSearchBox();
50
51 /**
52 * Sets the text that should be used as input for
53 * searching.
54 */
55 void setText(const QString& text);
56
57 /**
58 * Returns the text that should be used as input
59 * for searching.
60 */
61 QString text() const;
62
63 /**
64 * Sets the current path that is used as root for
65 * searching files, if "From Here" has been selected.
66 */
67 void setSearchPath(const QUrl& url);
68 QUrl searchPath() const;
69
70 /** @return URL that will start the searching of files. */
71 QUrl urlForSearching() const;
72
73 /**
74 * Extracts information from the given search \a url to
75 * initialize the search box properly.
76 */
77 void fromSearchUrl(const QUrl& url);
78
79 /**
80 * Selects the whole text of the search box.
81 */
82 void selectAll();
83
84 /**
85 * Set the search box to the active mode, if \a active
86 * is true. The active mode is default. The inactive mode only differs
87 * visually from the active mode, no change of the behavior is given.
88 *
89 * Using the search box in the inactive mode is useful when having split views,
90 * where the inactive view is indicated by an search box visually.
91 */
92 void setActive(bool active);
93
94 /**
95 * @return True, if the search box is in the active mode.
96 * @see DolphinSearchBox::setActive()
97 */
98 bool isActive() const;
99
100 protected:
101 virtual bool event(QEvent* event) Q_DECL_OVERRIDE;
102 virtual void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
103 virtual void keyReleaseEvent(QKeyEvent* event) Q_DECL_OVERRIDE;
104 virtual bool eventFilter(QObject* obj, QEvent* event) Q_DECL_OVERRIDE;
105
106 signals:
107 /**
108 * Is emitted when a searching should be triggered.
109 */
110 void searchRequest();
111
112 /**
113 * Is emitted when the user has changed a character of
114 * the text that should be used as input for searching.
115 */
116 void searchTextChanged(const QString& text);
117
118 void returnPressed();
119
120 /**
121 * Emitted as soon as the search box should get closed.
122 */
123 void closeRequest();
124
125 /**
126 * Is emitted, if the searchbox has been activated by
127 * an user interaction
128 * @see DolphinSearchBox::setActive()
129 */
130 void activated();
131
132 private slots:
133 void emitSearchRequest();
134 void emitCloseRequest();
135 void slotConfigurationChanged();
136 void slotSearchTextChanged(const QString& text);
137 void slotReturnPressed();
138 void slotFacetsButtonToggled();
139 void slotFacetChanged();
140
141 private:
142 void initButton(QToolButton* button);
143 void loadSettings();
144 void saveSettings();
145 void init();
146
147 /**
148 * @return URL that represents the Baloo query for starting the search.
149 */
150 QUrl balooUrlForSearching() const;
151
152 /**
153 * Extracts information from the given Baloo search \a url to
154 * initialize the search box properly.
155 */
156 void fromBalooSearchUrl(const QUrl& url);
157
158 void updateFacetsToggleButton();
159
160 private:
161 bool m_startedSearching;
162 bool m_active;
163
164 QVBoxLayout* m_topLayout;
165
166 QLabel* m_searchLabel;
167 QLineEdit* m_searchInput;
168 QScrollArea* m_optionsScrollArea;
169 QToolButton* m_fileNameButton;
170 QToolButton* m_contentButton;
171 KSeparator* m_separator;
172 QToolButton* m_fromHereButton;
173 QToolButton* m_everywhereButton;
174 QToolButton* m_facetsToggleButton;
175 DolphinFacetsWidget* m_facetsWidget;
176
177 QUrl m_searchPath;
178
179 QTimer* m_startSearchTimer;
180 };
181
182 #endif