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