]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
GIT_SILENT Sync po/docbooks with svn
[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
22 /**
23 * @brief Input box for searching files with or without Baloo.
24 *
25 * The widget allows to specify:
26 * - Where to search: Everywhere or below the current directory
27 * - What to search: Filenames or content
28 *
29 * If Baloo is available and the current folder is indexed, further
30 * options are offered.
31 */
32 class DolphinSearchBox : public QWidget
33 {
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 when the search box should be opened.
115 */
116 void openRequest();
117
118 /**
119 * Is emitted, if the searchbox has been activated by
120 * an user interaction
121 * @see DolphinSearchBox::setActive()
122 */
123 void activated();
124 void focusViewRequest();
125
126 private Q_SLOTS:
127 void emitSearchRequest();
128 void emitCloseRequest();
129 void slotConfigurationChanged();
130 void slotSearchTextChanged(const QString &text);
131 void slotReturnPressed();
132 void slotFacetChanged();
133 void slotSearchSaved();
134
135 private:
136 void initButton(QToolButton *button);
137 void loadSettings();
138 void saveSettings();
139 void init();
140
141 /**
142 * @return URL that represents the Baloo query for starting the search.
143 */
144 QUrl balooUrlForSearching() const;
145
146 /**
147 * Sets the searchbox UI with the parameters established by the \a query
148 */
149 void updateFromQuery(const DolphinQuery &query);
150
151 void updateFacetsVisible();
152
153 bool isIndexingEnabled() const;
154
155 private:
156 QString queryTitle(const QString &text) const;
157
158 bool m_startedSearching;
159 bool m_active;
160
161 QVBoxLayout *m_topLayout;
162
163 QLineEdit *m_searchInput;
164 QAction *m_saveSearchAction;
165 QScrollArea *m_optionsScrollArea;
166 QToolButton *m_fileNameButton;
167 QToolButton *m_contentButton;
168 KSeparator *m_separator;
169 QToolButton *m_fromHereButton;
170 QToolButton *m_everywhereButton;
171 DolphinFacetsWidget *m_facetsWidget;
172
173 QUrl m_searchPath;
174
175 QTimer *m_startSearchTimer;
176 };
177
178 #endif