]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Merge remote-tracking branch 'origin/KDE/4.9'
[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 protected:
91 virtual bool event(QEvent* event);
92 virtual void showEvent(QShowEvent* event);
93 virtual void keyReleaseEvent(QKeyEvent* event);
94
95 signals:
96 /**
97 * Is emitted when a searching should be triggered.
98 */
99 void searchRequest();
100
101 /**
102 * Is emitted when the user has changed a character of
103 * the text that should be used as input for searching.
104 */
105 void searchTextChanged(const QString& text);
106
107 void returnPressed(const QString& text);
108
109 /**
110 * Emitted as soon as the search box should get closed.
111 */
112 void closeRequest();
113
114 private slots:
115 void emitSearchRequest();
116 void emitCloseRequest();
117 void slotConfigurationChanged();
118 void slotSearchTextChanged(const QString& text);
119 void slotReturnPressed(const QString& text);
120 void slotFacetsButtonToggled();
121 void slotFacetChanged();
122
123 private:
124 void initButton(QToolButton* button);
125 void loadSettings();
126 void saveSettings();
127 void init();
128
129 /**
130 * @return URL that represents the Nepomuk query for starting the search.
131 */
132 KUrl nepomukUrlForSearching() const;
133
134 void applyReadOnlyState();
135
136 void updateFacetsToggleButton();
137 private:
138 bool m_startedSearching;
139 bool m_readOnly;
140
141 QVBoxLayout* m_topLayout;
142
143 QLabel* m_searchLabel;
144 KLineEdit* m_searchInput;
145 QScrollArea* m_optionsScrollArea;
146 QToolButton* m_fileNameButton;
147 QToolButton* m_contentButton;
148 KSeparator* m_separator;
149 QToolButton* m_fromHereButton;
150 QToolButton* m_everywhereButton;
151 QToolButton* m_facetsToggleButton;
152 DolphinFacetsWidget* m_facetsWidget;
153
154 KUrl m_searchPath;
155 KUrl m_readOnlyQuery;
156
157 QTimer* m_startSearchTimer;
158 };
159
160 #endif