]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Don't offer the "Search everywhere" option for non-local URLs.
[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 KSeparator;
30 class QFormLayout;
31 class QPushButton;
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 a searching should be triggered
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 void returnPressed(const QString& text);
87
88 /**
89 * Emitted as soon as the search box should get closed.
90 */
91 void closeRequest();
92
93 private slots:
94 void emitSearchSignal();
95 void slotConfigurationChanged();
96 void slotSearchTextChanged(const QString& text);
97 void slotReturnPressed(const QString& text);
98
99 private:
100 void initButton(QPushButton* button);
101 void loadSettings();
102 void saveSettings();
103 void init();
104
105 /**
106 * @return True, if the complete directory tree specified by m_searchPath
107 * is indexed by Strigi.
108 */
109 bool isSearchPathIndexed() const;
110
111 /**
112 * @return URL that represents the Nepomuk query for starting the search.
113 */
114 KUrl nepomukUrlForSearching() const;
115
116 private:
117 bool m_startedSearching;
118 bool m_nepomukActivated;
119
120 QVBoxLayout* m_topLayout;
121
122 KLineEdit* m_searchInput;
123 QPushButton* m_fileNameButton;
124 QPushButton* m_contentButton;
125 KSeparator* m_separator;
126 QPushButton* m_fromHereButton;
127 QPushButton* m_everywhereButton;
128
129 KUrl m_searchPath;
130
131 QTimer* m_startSearchTimer;
132 };
133
134 #endif