]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Fix search-UI issues in combination with the new places entries
[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 <QList>
25 #include <QWidget>
26
27 class DolphinFacetsWidget;
28 class KLineEdit;
29 class KSeparator;
30 class QToolButton;
31 class QScrollArea;
32 class QLabel;
33 class QVBoxLayout;
34
35 /**
36 * @brief Input box for searching files with or without Nepomuk.
37 *
38 * The widget allows to specify:
39 * - Where to search: Everywhere or below the current directory
40 * - What to search: Filenames or content
41 *
42 * If Nepomuk is available and the current folder is indexed, further
43 * options are offered.
44 */
45 class DolphinSearchBox : public QWidget {
46 Q_OBJECT
47
48 public:
49 enum SearchContext {
50 SearchFileName,
51 SearchContent
52 };
53
54 enum SearchLocation {
55 SearchFromHere,
56 SearchEverywhere
57 };
58
59 explicit DolphinSearchBox(QWidget* parent = 0);
60 virtual ~DolphinSearchBox();
61
62 /**
63 * Sets the text that should be used as input for
64 * searching.
65 */
66 void setText(const QString& text);
67
68 /**
69 * Returns the text that should be used as input
70 * for searching.
71 */
72 QString text() const;
73
74 /**
75 * Sets the current path that is used as root for
76 * searching files, if "From Here" has been selected.
77 */
78 void setSearchPath(const KUrl& url);
79 KUrl searchPath() const;
80
81 /** @return URL that will start the searching of files. */
82 KUrl urlForSearching() const;
83
84 /**
85 * Selects the whole text of the search box.
86 */
87 void selectAll();
88
89 /**
90 * @param readOnly If set to true the searchbox cannot be modified
91 * by the user and acts as visual indicator for
92 * an externally triggered search query.
93 * @param query If readOnly is true this URL will be used
94 * to show a human readable information about the
95 * query.
96 */
97 void setReadOnly(bool readOnly, const KUrl& query = KUrl());
98 bool isReadOnly() const;
99
100 protected:
101 virtual bool event(QEvent* event);
102 virtual void showEvent(QShowEvent* event);
103 virtual void keyReleaseEvent(QKeyEvent* event);
104
105 signals:
106 /**
107 * Is emitted when a searching should be triggered
108 * and provides the text that should be used as input
109 * for searching.
110 */
111 void search(const QString& text);
112
113 /**
114 * Is emitted when the user has changed a character of
115 * the text that should be used as input for searching.
116 */
117 void searchTextChanged(const QString& text);
118
119 void returnPressed(const QString& text);
120
121 /**
122 * Is emitted if the search location has been changed by the user.
123 */
124 void searchLocationChanged(SearchLocation location);
125
126 /**
127 * Is emitted if the search context has been changed by the user.
128 */
129 void searchContextChanged(SearchContext context);
130
131 /**
132 * Emitted as soon as the search box should get closed.
133 */
134 void closeRequest();
135
136 private slots:
137 void emitSearchSignal();
138 void slotSearchLocationChanged();
139 void slotSearchContextChanged();
140 void slotConfigurationChanged();
141 void slotSearchTextChanged(const QString& text);
142 void slotReturnPressed(const QString& text);
143 void slotFacetsButtonToggled();
144
145 private:
146 void initButton(QToolButton* button);
147 void loadSettings();
148 void saveSettings();
149 void init();
150
151 /**
152 * @return URL that represents the Nepomuk query for starting the search.
153 */
154 KUrl nepomukUrlForSearching() const;
155
156 void applyReadOnlyState();
157
158 void updateFacetsToggleButtonIcon();
159
160 private:
161 bool m_startedSearching;
162 bool m_readOnly;
163
164 QVBoxLayout* m_topLayout;
165
166 QLabel* m_searchLabel;
167 KLineEdit* 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 KUrl m_searchPath;
178 KUrl m_readOnlyQuery;
179
180 QTimer* m_startSearchTimer;
181 };
182
183 #endif