]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Unify the search interface for non-indexed and indexed folders
[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.h>
24 #include <QList>
25 #include <QWidget>
26
27 class AbstractSearchFilterWidget;
28 class KLineEdit;
29 class QFormLayout;
30 class QPushButton;
31 class QToolButton;
32 class QVBoxLayout;
33
34 /**
35 * @brief Input box for searching files with or without Nepomuk.
36 *
37 * The widget allows to specify:
38 * - Where to search: Everywhere or below the current directory
39 * - What to search: Filenames or content
40 *
41 * If Nepomuk is available and the current folder is indexed, further
42 * options are offered.
43 */
44 class DolphinSearchBox : public QWidget {
45 Q_OBJECT
46
47 public:
48 DolphinSearchBox(QWidget* parent = 0);
49 virtual ~DolphinSearchBox();
50
51 /**
52 * Returns the text that should be used as input
53 * for searching.
54 */
55 QString text() const;
56
57 /**
58 * Sets the current path that is used as root for
59 * searching files, if "From Here" has been selected.
60 */
61 void setSearchPath(const KUrl& url);
62 KUrl searchPath() const;
63
64 /** @return URL that will start the searching of files. */
65 KUrl urlForSearching() const;
66
67 protected:
68 virtual bool event(QEvent* event);
69 virtual void showEvent(QShowEvent* event);
70 virtual void keyReleaseEvent(QKeyEvent* event);
71
72 signals:
73 /**
74 * Is emitted when the user pressed Return or Enter
75 * and provides the text that should be used as input
76 * for searching.
77 */
78 void search(const QString& text);
79
80 /**
81 * Is emitted when the user has changed a character of
82 * the text that should be used as input for searching.
83 */
84 void searchTextChanged(const QString& text);
85
86 /**
87 * Emitted as soon as the search box should get closed.
88 */
89 void closeRequest();
90
91 private slots:
92 void emitSearchSignal();
93 void slotConfigurationChanged();
94 void setFilterWidgetsVisible(bool visible);
95
96 private:
97 void initButton(QPushButton* button);
98 void loadSettings();
99 void saveSettings();
100 void init();
101
102 /**
103 * @return True, if the complete directory tree specified by m_searchPath
104 * is indexed by Strigi.
105 */
106 bool isSearchPathIndexed() const;
107
108 /**
109 * @return URL that represents the Nepomuk query for starting the search.
110 */
111 KUrl nepomukUrlForSearching() const;
112
113 private:
114 bool m_startedSearching;
115 bool m_nepomukActivated;
116
117 QVBoxLayout* m_topLayout;
118
119 KLineEdit* m_searchInput;
120 QPushButton* m_fromHereButton;
121 QPushButton* m_everywhereButton;
122 QPushButton* m_fileNameButton;
123 QPushButton* m_contentButton;
124
125 QToolButton* m_filterButton;
126 QFormLayout* m_filterWidgetsLayout;
127 QList<AbstractSearchFilterWidget*> m_filterWidgets;
128
129 KUrl m_searchPath;
130 };
131
132 #endif