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