]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Fix visibility- and enabled-issues for the filter-panel
[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 explicit 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 /**
68 * Selects the whole text of the search box.
69 */
70 void selectAll();
71
72 protected:
73 virtual bool event(QEvent* event);
74 virtual void showEvent(QShowEvent* event);
75 virtual void keyReleaseEvent(QKeyEvent* event);
76
77 signals:
78 /**
79 * Is emitted when a searching should be triggered
80 * and provides the text that should be used as input
81 * for searching.
82 */
83 void search(const QString& text);
84
85 /**
86 * Is emitted when the user has changed a character of
87 * the text that should be used as input for searching.
88 */
89 void searchTextChanged(const QString& text);
90
91 void returnPressed(const QString& text);
92
93 /**
94 * Emitted as soon as the search box should get closed.
95 */
96 void closeRequest();
97
98 private slots:
99 void emitSearchSignal();
100 void slotConfigurationChanged();
101 void slotSearchTextChanged(const QString& text);
102 void slotReturnPressed(const QString& text);
103
104 private:
105 void initButton(QPushButton* button);
106 void loadSettings();
107 void saveSettings();
108 void init();
109
110 /**
111 * @return URL that represents the Nepomuk query for starting the search.
112 */
113 KUrl nepomukUrlForSearching() const;
114
115 private:
116 bool m_startedSearching;
117 bool m_nepomukActivated;
118
119 QVBoxLayout* m_topLayout;
120
121 KLineEdit* m_searchInput;
122 QPushButton* m_fileNameButton;
123 QPushButton* m_contentButton;
124 KSeparator* m_separator;
125 QPushButton* m_fromHereButton;
126 QPushButton* m_everywhereButton;
127
128 KUrl m_searchPath;
129
130 QTimer* m_startSearchTimer;
131 };
132
133 #endif