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