]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Merge remote-tracking branch 'origin/KDE/4.11'
[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 explicit DolphinSearchBox(QWidget* parent = 0);
50 virtual ~DolphinSearchBox();
51
52 /**
53 * Sets the text that should be used as input for
54 * searching.
55 */
56 void setText(const QString& text);
57
58 /**
59 * Returns the text that should be used as input
60 * for searching.
61 */
62 QString text() const;
63
64 /**
65 * Sets the current path that is used as root for
66 * searching files, if "From Here" has been selected.
67 */
68 void setSearchPath(const KUrl& url);
69 KUrl searchPath() const;
70
71 /** @return URL that will start the searching of files. */
72 KUrl urlForSearching() const;
73
74 /**
75 * Selects the whole text of the search box.
76 */
77 void selectAll();
78
79 /**
80 * @param readOnly If set to true the searchbox cannot be modified
81 * by the user and acts as visual indicator for
82 * an externally triggered search query.
83 * @param query If readOnly is true this URL will be used
84 * to show a human readable information about the
85 * query.
86 */
87 void setReadOnly(bool readOnly, const KUrl& query = KUrl());
88 bool isReadOnly() const;
89
90 /**
91 * Set the search box to the active mode, if \a active
92 * is true. The active mode is default. The inactive mode only differs
93 * visually from the active mode, no change of the behavior is given.
94 *
95 * Using the search box in the inactive mode is useful when having split views,
96 * where the inactive view is indicated by an search box visually.
97 */
98 void setActive(bool active);
99
100 /**
101 * @return True, if the search box is in the active mode.
102 * @see DolphinSearchBox::setActive()
103 */
104 bool isActive() const;
105
106 protected:
107 virtual bool event(QEvent* event);
108 virtual void showEvent(QShowEvent* event);
109 virtual void keyReleaseEvent(QKeyEvent* event);
110 virtual bool eventFilter(QObject* obj, QEvent* event);
111
112 signals:
113 /**
114 * Is emitted when a searching should be triggered.
115 */
116 void searchRequest();
117
118 /**
119 * Is emitted when the user has changed a character of
120 * the text that should be used as input for searching.
121 */
122 void searchTextChanged(const QString& text);
123
124 void returnPressed(const QString& text);
125
126 /**
127 * Emitted as soon as the search box should get closed.
128 */
129 void closeRequest();
130
131 /**
132 * Is emitted, if the searchbox has been activated by
133 * an user interaction
134 * @see DolphinSearchBox::setActive()
135 */
136 void activated();
137
138 private slots:
139 void emitSearchRequest();
140 void emitCloseRequest();
141 void slotConfigurationChanged();
142 void slotSearchTextChanged(const QString& text);
143 void slotReturnPressed(const QString& text);
144 void slotFacetsButtonToggled();
145 void slotFacetChanged();
146
147 private:
148 void initButton(QToolButton* button);
149 void loadSettings();
150 void saveSettings();
151 void init();
152
153 /**
154 * @return URL that represents the Nepomuk query for starting the search.
155 */
156 KUrl nepomukUrlForSearching() const;
157
158 void applyReadOnlyState();
159
160 void updateFacetsToggleButton();
161 private:
162 bool m_startedSearching;
163 bool m_readOnly;
164 bool m_active;
165
166 QVBoxLayout* m_topLayout;
167
168 QLabel* m_searchLabel;
169 KLineEdit* m_searchInput;
170 QScrollArea* m_optionsScrollArea;
171 QToolButton* m_fileNameButton;
172 QToolButton* m_contentButton;
173 KSeparator* m_separator;
174 QToolButton* m_fromHereButton;
175 QToolButton* m_everywhereButton;
176 QToolButton* m_facetsToggleButton;
177 DolphinFacetsWidget* m_facetsWidget;
178
179 KUrl m_searchPath;
180 KUrl m_readOnlyQuery;
181
182 QTimer* m_startSearchTimer;
183 };
184
185 #endif