]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
[dolphin] Add an action to toggle the searchbar
[dolphin.git] / src / dolphinviewcontainer.h
1 /***************************************************************************
2 * Copyright (C) 2007 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 DOLPHINVIEWCONTAINER_H
21 #define DOLPHINVIEWCONTAINER_H
22
23 #include "config-kactivities.h"
24 #include "views/dolphinview.h"
25
26 #include <KCompletion>
27 #include <KFileItem>
28 #include <KIO/Job>
29 #include <KUrlNavigator>
30
31 #include <QElapsedTimer>
32 #include <QPushButton>
33 #include <QWidget>
34
35 #ifdef HAVE_KACTIVITIES
36 namespace KActivities {
37 class ResourceInstance;
38 }
39 #endif
40
41 class FilterBar;
42 class KMessageWidget;
43 class QUrl;
44 class KUrlNavigator;
45 class DolphinSearchBox;
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, compact and details 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 enum MessageType
66 {
67 Information,
68 Warning,
69 Error
70 };
71
72 DolphinViewContainer(const QUrl& url, QWidget* parent);
73 ~DolphinViewContainer() override;
74
75 /**
76 * Returns the current active URL, where all actions are applied.
77 * The URL navigator is synchronized with this URL.
78 */
79 QUrl url() const;
80
81 /**
82 * If \a active is true, the view container will marked as active. The active
83 * view container is defined as view where all actions are applied to.
84 */
85 void setActive(bool active);
86 bool isActive() const;
87
88 /**
89 * If \a grab is set to true, the container automatically grabs the focus
90 * as soon as the URL has been changed. Per default the grabbing
91 * of the focus is enabled.
92 */
93 void setAutoGrabFocus(bool grab);
94 bool autoGrabFocus() const;
95
96 QString currentSearchText() const;
97
98 const DolphinStatusBar* statusBar() const;
99 DolphinStatusBar* statusBar();
100
101 const KUrlNavigator* urlNavigator() const;
102 KUrlNavigator* urlNavigator();
103
104 const DolphinView* view() const;
105 DolphinView* view();
106
107 /**
108 * Shows the message \msg with the given type non-modal above
109 * the view-content.
110 */
111 void showMessage(const QString& msg, MessageType type);
112
113 /**
114 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
115 */
116 void readSettings();
117
118 /** Returns true, if the filter bar is visible. */
119 bool isFilterBarVisible() const;
120
121
122 /** Returns true if the search mode is enabled. */
123 bool isSearchModeEnabled() const;
124
125 /**
126 * @return Text that should be used for the current URL when creating
127 * a new place.
128 */
129 QString placesText() const;
130
131 /**
132 * Reload the view of this container. This will also hide messages in a messagewidget.
133 */
134 void reload();
135
136 /**
137 * @return Returns a Caption suitable for display to the user. It is
138 * calculated depending on settings, if a search is active and other
139 * factors.
140 */
141 QString caption() const;
142
143 public slots:
144 /**
145 * Sets the current active URL, where all actions are applied. The
146 * URL navigator is synchronized with this URL. The signals
147 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
148 * are emitted.
149 * @see DolphinViewContainer::urlNavigator()
150 */
151 void setUrl(const QUrl& url);
152
153 /**
154 * Popups the filter bar above the status bar if \a visible is true.
155 * It \a visible is true, it is assured that the filter bar gains
156 * the keyboard focus.
157 */
158 void setFilterBarVisible(bool visible);
159
160 /**
161 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
162 * will be hidden and replaced by a line editor that allows to enter a search term.
163 */
164 void setSearchModeEnabled(bool enabled);
165
166 signals:
167 /**
168 * Is emitted whenever the filter bar has changed its visibility state.
169 */
170 void showFilterBarChanged(bool shown);
171 /**
172 * Is emitted whenever the search mode has changed its state.
173 */
174 void searchModeEnabledChanged(bool enabled);
175
176 /**
177 * Is emitted when the write state of the folder has been changed. The application
178 * should disable all actions like "Create New..." that depend on the write
179 * state.
180 */
181 void writeStateChanged(bool isFolderWritable);
182
183 private slots:
184 /**
185 * Updates the number of items (= number of files + number of
186 * directories) in the statusbar. If files are selected, the number
187 * of selected files and the sum of the filesize is shown. The update
188 * is done asynchronously, as getting the sum of the
189 * filesizes can be an expensive operation.
190 * Unless a previous OperationCompletedMessage was set very shortly before
191 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
192 * Previous ErrorMessages however are always preserved.
193 */
194 void delayedStatusBarUpdate();
195
196 /**
197 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
198 * updates the status bar synchronously.
199 */
200 void updateStatusBar();
201
202 void updateDirectoryLoadingProgress(int percent);
203
204 void updateDirectorySortingProgress(int percent);
205
206 /**
207 * Updates the statusbar to show an undetermined progress with the correct
208 * context information whether a searching or a directory loading is done.
209 */
210 void slotDirectoryLoadingStarted();
211
212 /**
213 * Assures that the viewport position is restored and updates the
214 * statusbar to reflect the current content.
215 */
216 void slotDirectoryLoadingCompleted();
217
218 /**
219 * Updates the statusbar to show, that the directory loading has
220 * been canceled.
221 */
222 void slotDirectoryLoadingCanceled();
223
224 /**
225 * Is called if the URL set by DolphinView::setUrl() represents
226 * a file and not a directory. Takes care to activate the file.
227 */
228 void slotUrlIsFileError(const QUrl& url);
229
230 /**
231 * Handles clicking on an item. If the item is a directory, the
232 * directory is opened in the view. If the item is a file, the file
233 * gets started by the corresponding application.
234 */
235 void slotItemActivated(const KFileItem& item);
236
237 /**
238 * Handles activation of multiple files. The files get started by
239 * the corresponding applications.
240 */
241 void slotItemsActivated(const KFileItemList& items);
242
243 /**
244 * Shows the information for the item \a item inside the statusbar. If the
245 * item is null, the default statusbar information is shown.
246 */
247 void showItemInfo(const KFileItem& item);
248
249 void closeFilterBar();
250
251 /**
252 * Filters the currently shown items by \a nameFilter. All items
253 * which contain the given filter string will be shown.
254 */
255 void setNameFilter(const QString& nameFilter);
256
257 /**
258 * Marks the view container as active
259 * (see DolphinViewContainer::setActive()).
260 */
261 void activate();
262
263 /**
264 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
265 * is emitted. Tries to save the view-state.
266 */
267 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl& url);
268
269 /**
270 * Restores the current view to show \a url and assures
271 * that the root URL of the view is respected.
272 */
273 void slotUrlNavigatorLocationChanged(const QUrl& url);
274
275 /**
276 * @see KUrlNavigator::urlSelectionRequested
277 */
278 void slotUrlSelectionRequested(const QUrl& url);
279
280 /**
281 * Is invoked when a redirection is done and changes the
282 * URL of the URL navigator to \a newUrl without triggering
283 * a reloading of the directory.
284 */
285 void redirect(const QUrl& oldUrl, const QUrl& newUrl);
286
287 /** Requests the focus for the view \a m_view. */
288 void requestFocus();
289
290 /**
291 * Saves the currently used URL completion mode of
292 * the URL navigator.
293 */
294 void saveUrlCompletionMode(KCompletion::CompletionMode completion);
295
296 void slotReturnPressed();
297
298 /**
299 * Gets the search URL from the searchbox and starts searching.
300 */
301 void startSearching();
302 void closeSearchBox();
303
304 /**
305 * Stops the loading of a directory. Is connected with the "stopPressed" signal
306 * from the statusbar.
307 */
308 void stopDirectoryLoading();
309
310 void slotStatusBarZoomLevelChanged(int zoomLevel);
311
312 /**
313 * Slot that calls showMessage(msg, Error).
314 */
315 void showErrorMessage(const QString& msg);
316
317 private:
318 /**
319 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
320 */
321 bool isSearchUrl(const QUrl& url) const;
322
323 /**
324 * Saves the state of the current view: contents position,
325 * root URL, ...
326 */
327 void saveViewState();
328
329 /**
330 * Restores the state of the current view iff the URL navigator contains a
331 * non-empty location state.
332 */
333 void tryRestoreViewState();
334
335 private:
336 QVBoxLayout* m_topLayout;
337 QWidget* m_navigatorWidget;
338 KUrlNavigator* m_urlNavigator;
339 QPushButton* m_emptyTrashButton;
340 DolphinSearchBox* m_searchBox;
341 bool m_searchModeEnabled;
342 KMessageWidget* m_messageWidget;
343
344 DolphinView* m_view;
345
346 FilterBar* m_filterBar;
347
348 DolphinStatusBar* m_statusBar;
349 QTimer* m_statusBarTimer; // Triggers a delayed update
350 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
351 bool m_autoGrabFocus;
352
353 #ifdef HAVE_KACTIVITIES
354 private:
355 KActivities::ResourceInstance * m_activityResourceInstance;
356 #endif
357 };
358
359 #endif // DOLPHINVIEWCONTAINER_H