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