]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Unify the search interface for non-indexed and indexed folders
[dolphin.git] / src / dolphinviewcontainer.h
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
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
21 #ifndef DOLPHINVIEWCONTAINER_H
22 #define DOLPHINVIEWCONTAINER_H
23
24 #include "dolphinview.h"
25
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
28 #include <kglobalsettings.h>
29 #include <kio/job.h>
30
31 #include <kurlnavigator.h>
32
33 #include <QtGui/QKeyEvent>
34 #include <QtCore/QLinkedList>
35 #include <QtGui/QListView>
36 #include <QtGui/QBoxLayout>
37 #include <QtGui/QWidget>
38
39 class FilterBar;
40 class KUrl;
41 class DolphinModel;
42 class KUrlNavigator;
43 class DolphinDirLister;
44 class DolphinSearchBox;
45 class DolphinSortFilterProxyModel;
46 class DolphinStatusBar;
47
48 /**
49 * @short Represents a view for the directory content
50 * including the navigation bar, filter bar and status bar.
51 *
52 * View modes for icons, details and columns are supported. Currently
53 * Dolphin allows to have up to two views inside the main window.
54 *
55 * @see DolphinView
56 * @see FilterBar
57 * @see KUrlNavigator
58 * @see DolphinStatusBar
59 */
60 class DolphinViewContainer : public QWidget
61 {
62 Q_OBJECT
63
64 public:
65 DolphinViewContainer(const KUrl& url, QWidget* parent);
66 virtual ~DolphinViewContainer();
67
68 /**
69 * Returns the current active URL, where all actions are applied.
70 * The URL navigator is synchronized with this URL.
71 */
72 KUrl url() const;
73
74 /**
75 * If \a active is true, the view container will marked as active. The active
76 * view container is defined as view where all actions are applied to.
77 */
78 void setActive(bool active);
79 bool isActive() const;
80
81 const DolphinStatusBar* statusBar() const;
82 DolphinStatusBar* statusBar();
83
84 const KUrlNavigator* urlNavigator() const;
85 KUrlNavigator* urlNavigator();
86
87 const DolphinView* view() const;
88 DolphinView* view();
89
90 /**
91 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
92 */
93 void refresh();
94
95 /** Returns true, if the filter bar is visible. */
96 bool isFilterBarVisible() const;
97
98 /**
99 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
100 * will be hidden and replaced by a line editor that allows to enter a search term.
101 */
102 void setSearchModeEnabled(bool enabled);
103 bool isSearchModeEnabled() const;
104
105 public slots:
106 /**
107 * Sets the current active URL, where all actions are applied. The
108 * URL navigator is synchronized with this URL. The signals
109 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
110 * are emitted.
111 * @see DolphinViewContainer::urlNavigator()
112 */
113 void setUrl(const KUrl& url);
114
115 /**
116 * Popups the filter bar above the status bar if \a show is true.
117 */
118 void showFilterBar(bool show);
119
120 signals:
121 /**
122 * Is emitted whenever the filter bar has changed its visibility state.
123 */
124 void showFilterBarChanged(bool shown);
125
126 /**
127 * Is emitted when the write state of the folder has been changed. The application
128 * should disable all actions like "Create New..." that depend on the write
129 * state.
130 */
131 void writeStateChanged(bool isFolderWritable);
132
133 private slots:
134 /**
135 * Updates the number of items (= number of files + number of
136 * directories) in the statusbar. If files are selected, the number
137 * of selected files and the sum of the filesize is shown. The update
138 * is done asynchronously, as getting the sum of the
139 * filesizes can be an expensive operation.
140 */
141 void delayedStatusBarUpdate();
142
143 /**
144 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
145 * updates the status bar synchronously.
146 */
147 void updateStatusBar();
148
149 void initializeProgress();
150
151 void updateProgress(int percent);
152
153 /**
154 * Assures that the viewport position is restored and updates the
155 * statusbar to reflect the current content.
156 */
157 void slotDirListerCompleted();
158
159 /**
160 * Handles clicking on an item. If the item is a directory, the
161 * directory is opened in the view. If the item is a file, the file
162 * gets started by the corresponding application.
163 */
164 void slotItemTriggered(const KFileItem& item);
165
166 /**
167 * Opens a the file \a url by opening the corresponding application.
168 * Is connected with the signal urlIsFile() from DolphinDirLister and will
169 * get invoked if the user manually has entered a file into the URL navigator.
170 */
171 void openFile(const KUrl& url);
172
173 /**
174 * Shows the information for the item \a item inside the statusbar. If the
175 * item is null, the default statusbar information is shown.
176 */
177 void showItemInfo(const KFileItem& item);
178
179 /** Shows the information \a msg inside the statusbar. */
180 void showInfoMessage(const QString& msg);
181
182 /** Shows the error message \a msg inside the statusbar. */
183 void showErrorMessage(const QString& msg);
184
185 /** Shows the "operation completed" message \a msg inside the statusbar. */
186 void showOperationCompletedMessage(const QString& msg);
187
188 void closeFilterBar();
189
190 /**
191 * Filters the currently shown items by \a nameFilter. All items
192 * which contain the given filter string will be shown.
193 */
194 void setNameFilter(const QString& nameFilter);
195
196 /**
197 * Marks the view container as active
198 * (see DolphinViewContainer::setActive()).
199 */
200 void activate();
201
202 /**
203 * Saves the state of the current view: contents position,
204 * root URL, ...
205 */
206 void saveViewState();
207
208 /**
209 * Restores the current view to show \a url and assures
210 * that the root URL of the view is respected.
211 */
212 void slotUrlNavigatorLocationChanged(const KUrl& url);
213
214 /**
215 * Is connected with the URL navigator and drops the URLs
216 * above the destination \a destination.
217 */
218 void dropUrls(const KUrl& destination, QDropEvent* event);
219
220 /**
221 * Is invoked when a redirection is done and changes the
222 * URL of the URL navigator to \a newUrl without triggering
223 * a reloading of the directory.
224 */
225 void redirect(const KUrl& oldUrl, const KUrl& newUrl);
226
227 /** Requests the focus for the view \a m_view. */
228 void requestFocus();
229
230 /**
231 * Saves the currently used URL completion mode of
232 * the URL navigator.
233 */
234 void saveUrlCompletionMode(KGlobalSettings::Completion completion);
235
236 void slotHistoryChanged();
237
238 /**
239 * Gets the search URL from the searchbox and starts searching.
240 * @param text Text the user has entered into the searchbox.
241 */
242 void startSearching(const QString& text);
243 void closeSearchBox();
244
245 private:
246 bool isSearchUrl(const KUrl& url) const;
247
248 private:
249 bool m_isFolderWritable;
250
251 QVBoxLayout* m_topLayout;
252 KUrlNavigator* m_urlNavigator;
253 DolphinSearchBox* m_searchBox;
254
255 DolphinView* m_view;
256
257 FilterBar* m_filterBar;
258
259 DolphinStatusBar* m_statusBar;
260 QTimer* m_statusBarTimer;
261
262 DolphinModel* m_dolphinModel;
263 DolphinDirLister* m_dirLister;
264 DolphinSortFilterProxyModel* m_proxyModel;
265 };
266
267 inline const DolphinStatusBar* DolphinViewContainer::statusBar() const
268 {
269 return m_statusBar;
270 }
271
272 inline DolphinStatusBar* DolphinViewContainer::statusBar()
273 {
274 return m_statusBar;
275 }
276
277 inline const KUrlNavigator* DolphinViewContainer::urlNavigator() const
278 {
279 return m_urlNavigator;
280 }
281
282 inline KUrlNavigator* DolphinViewContainer::urlNavigator()
283 {
284 return m_urlNavigator;
285 }
286
287 inline const DolphinView* DolphinViewContainer::view() const
288 {
289 return m_view;
290 }
291
292 inline DolphinView* DolphinViewContainer::view()
293 {
294 return m_view;
295 }
296
297 #endif // DOLPHINVIEWCONTAINER_H