]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Make UrlNavigators in the toolbar the only option
[dolphin.git] / src / dolphinviewcontainer.h
1 /*
2 * SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINVIEWCONTAINER_H
8 #define DOLPHINVIEWCONTAINER_H
9
10 #include "config-kactivities.h"
11 #include "dolphinurlnavigator.h"
12 #include "views/dolphinview.h"
13
14 #include <KFileItem>
15 #include <KIO/Job>
16 #include <KUrlNavigator>
17
18 #include <QElapsedTimer>
19 #include <QPushButton>
20 #include <QWidget>
21
22 #ifdef HAVE_KACTIVITIES
23 namespace KActivities {
24 class ResourceInstance;
25 }
26 #endif
27
28 class FilterBar;
29 class KMessageWidget;
30 class QUrl;
31 class KUrlNavigator;
32 class DolphinSearchBox;
33 class DolphinStatusBar;
34
35 /**
36 * @short Represents a view for the directory content
37 * including the navigation bar, filter bar and status bar.
38 *
39 * View modes for icons, compact and details are supported. Currently
40 * Dolphin allows to have up to two views inside the main window.
41 *
42 * @see DolphinView
43 * @see FilterBar
44 * @see KUrlNavigator
45 * @see DolphinStatusBar
46 */
47 class DolphinViewContainer : public QWidget
48 {
49 Q_OBJECT
50
51 public:
52 enum MessageType
53 {
54 Information,
55 Warning,
56 Error
57 };
58
59 DolphinViewContainer(const QUrl& url, QWidget* parent);
60 ~DolphinViewContainer() override;
61
62 /**
63 * Returns the current active URL, where all actions are applied.
64 * The URL navigator is synchronized with this URL.
65 */
66 QUrl url() const;
67
68 /**
69 * If \a active is true, the view container will marked as active. The active
70 * view container is defined as view where all actions are applied to.
71 */
72 void setActive(bool active);
73 bool isActive() const;
74
75 /**
76 * If \a grab is set to true, the container automatically grabs the focus
77 * as soon as the URL has been changed. Per default the grabbing
78 * of the focus is enabled.
79 */
80 void setAutoGrabFocus(bool grab);
81 bool autoGrabFocus() const;
82
83 QString currentSearchText() const;
84
85 const DolphinStatusBar* statusBar() const;
86 DolphinStatusBar* statusBar();
87
88 /**
89 * @return An UrlNavigator that is controlling this view
90 * or nullptr if there is none.
91 * @see connectUrlNavigator()
92 * @see disconnectUrlNavigator()
93 *
94 * Use urlNavigatorInternalWithHistory() if you want to access the history.
95 * @see urlNavigatorInternalWithHistory()
96 */
97 const DolphinUrlNavigator *urlNavigator() const;
98 /**
99 * @return An UrlNavigator that is controlling this view
100 * or nullptr if there is none.
101 * @see connectUrlNavigator()
102 * @see disconnectUrlNavigator()
103 *
104 * Use urlNavigatorInternalWithHistory() if you want to access the history.
105 * @see urlNavigatorInternalWithHistory()
106 */
107 DolphinUrlNavigator *urlNavigator();
108
109 /**
110 * @return An UrlNavigator that contains this view's history.
111 * Use urlNavigator() instead when not accessing the history.
112 */
113 const DolphinUrlNavigator *urlNavigatorInternalWithHistory() const;
114 /**
115 * @return An UrlNavigator that contains this view's history.
116 * Use urlNavigator() instead when not accessing the history.
117 */
118 DolphinUrlNavigator *urlNavigatorInternalWithHistory();
119
120 const DolphinView* view() const;
121 DolphinView* view();
122
123 /**
124 * @param urlNavigator The UrlNavigator that is supposed to control
125 * this view.
126 */
127 void connectUrlNavigator(DolphinUrlNavigator *urlNavigator);
128
129 /**
130 * Disconnects the navigator that is currently controling the view.
131 * This method completely reverses connectUrlNavigator().
132 */
133 void disconnectUrlNavigator();
134
135 /**
136 * Shows the message \msg with the given type non-modal above
137 * the view-content.
138 */
139 void showMessage(const QString& msg, MessageType type);
140
141 /**
142 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
143 */
144 void readSettings();
145
146 /** Returns true, if the filter bar is visible. */
147 bool isFilterBarVisible() const;
148
149
150 /** Returns true if the search mode is enabled. */
151 bool isSearchModeEnabled() const;
152
153 /**
154 * @return Text that should be used for the current URL when creating
155 * a new place.
156 */
157 QString placesText() const;
158
159 /**
160 * Reload the view of this container. This will also hide messages in a messagewidget.
161 */
162 void reload();
163
164 /**
165 * @return Returns a Caption suitable for display in the window title.
166 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
167 * If it's false, it calls caption().
168 */
169 QString captionWindowTitle() const;
170
171 /**
172 * @return Returns a Caption suitable for display to the user. It is
173 * calculated depending on settings, if a search is active and other
174 * factors.
175 */
176 QString caption() const;
177
178 public slots:
179 /**
180 * Sets the current active URL, where all actions are applied. The
181 * URL navigator is synchronized with this URL. The signals
182 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
183 * are emitted.
184 * @see DolphinViewContainer::urlNavigator()
185 */
186 void setUrl(const QUrl& url);
187
188 /**
189 * Popups the filter bar above the status bar if \a visible is true.
190 * It \a visible is true, it is assured that the filter bar gains
191 * the keyboard focus.
192 */
193 void setFilterBarVisible(bool visible);
194
195 /**
196 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
197 * will be hidden and replaced by a line editor that allows to enter a search term.
198 */
199 void setSearchModeEnabled(bool enabled);
200
201 signals:
202 /**
203 * Is emitted whenever the filter bar has changed its visibility state.
204 */
205 void showFilterBarChanged(bool shown);
206 /**
207 * Is emitted whenever the search mode has changed its state.
208 */
209 void searchModeEnabledChanged(bool enabled);
210
211 /**
212 * Is emitted when the write state of the folder has been changed. The application
213 * should disable all actions like "Create New..." that depend on the write
214 * state.
215 */
216 void writeStateChanged(bool isFolderWritable);
217
218 private slots:
219 /**
220 * Updates the number of items (= number of files + number of
221 * directories) in the statusbar. If files are selected, the number
222 * of selected files and the sum of the filesize is shown. The update
223 * is done asynchronously, as getting the sum of the
224 * filesizes can be an expensive operation.
225 * Unless a previous OperationCompletedMessage was set very shortly before
226 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
227 * Previous ErrorMessages however are always preserved.
228 */
229 void delayedStatusBarUpdate();
230
231 /**
232 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
233 * updates the status bar synchronously.
234 */
235 void updateStatusBar();
236
237 void updateDirectoryLoadingProgress(int percent);
238
239 void updateDirectorySortingProgress(int percent);
240
241 /**
242 * Updates the statusbar to show an undetermined progress with the correct
243 * context information whether a searching or a directory loading is done.
244 */
245 void slotDirectoryLoadingStarted();
246
247 /**
248 * Assures that the viewport position is restored and updates the
249 * statusbar to reflect the current content.
250 */
251 void slotDirectoryLoadingCompleted();
252
253 /**
254 * Updates the statusbar to show, that the directory loading has
255 * been canceled.
256 */
257 void slotDirectoryLoadingCanceled();
258
259 /**
260 * Is called if the URL set by DolphinView::setUrl() represents
261 * a file and not a directory. Takes care to activate the file.
262 */
263 void slotUrlIsFileError(const QUrl& url);
264
265 /**
266 * Handles clicking on an item. If the item is a directory, the
267 * directory is opened in the view. If the item is a file, the file
268 * gets started by the corresponding application.
269 */
270 void slotItemActivated(const KFileItem& item);
271
272 /**
273 * Handles activation of multiple files. The files get started by
274 * the corresponding applications.
275 */
276 void slotItemsActivated(const KFileItemList& items);
277
278 /**
279 * Shows the information for the item \a item inside the statusbar. If the
280 * item is null, the default statusbar information is shown.
281 */
282 void showItemInfo(const KFileItem& item);
283
284 void closeFilterBar();
285
286 /**
287 * Filters the currently shown items by \a nameFilter. All items
288 * which contain the given filter string will be shown.
289 */
290 void setNameFilter(const QString& nameFilter);
291
292 /**
293 * Marks the view container as active
294 * (see DolphinViewContainer::setActive()).
295 */
296 void activate();
297
298 /**
299 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
300 * is emitted. Tries to save the view-state.
301 */
302 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl& url);
303
304 /**
305 * Restores the current view to show \a url and assures
306 * that the root URL of the view is respected.
307 */
308 void slotUrlNavigatorLocationChanged(const QUrl& url);
309
310 /**
311 * @see KUrlNavigator::urlSelectionRequested
312 */
313 void slotUrlSelectionRequested(const QUrl& url);
314
315 /**
316 * Is invoked when a redirection is done and changes the
317 * URL of the URL navigator to \a newUrl without triggering
318 * a reloading of the directory.
319 */
320 void redirect(const QUrl& oldUrl, const QUrl& newUrl);
321
322 /** Requests the focus for the view \a m_view. */
323 void requestFocus();
324
325 /**
326 * Gets the search URL from the searchbox and starts searching.
327 */
328 void startSearching();
329 void closeSearchBox();
330
331 /**
332 * Stops the loading of a directory. Is connected with the "stopPressed" signal
333 * from the statusbar.
334 */
335 void stopDirectoryLoading();
336
337 void slotStatusBarZoomLevelChanged(int zoomLevel);
338
339 /**
340 * Slot that calls showMessage(msg, Error).
341 */
342 void showErrorMessage(const QString& msg);
343
344 private:
345 /**
346 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
347 */
348 bool isSearchUrl(const QUrl& url) const;
349
350 /**
351 * Saves the state of the current view: contents position,
352 * root URL, ...
353 */
354 void saveViewState();
355
356 /**
357 * Restores the state of the current view iff the URL navigator contains a
358 * non-empty location state.
359 */
360 void tryRestoreViewState();
361
362 private:
363 QVBoxLayout* m_topLayout;
364
365 /**
366 * The internal UrlNavigator which is never visible to the user.
367 * m_urlNavigator is used even when another UrlNavigator is controlling
368 * the view to keep track of this object's history.
369 */
370 std::unique_ptr<DolphinUrlNavigator> m_urlNavigator;
371
372 /**
373 * The UrlNavigator that is currently connected to the view.
374 * This is a nullptr if no UrlNavigator is connected.
375 * Otherwise it's one of the UrlNavigators visible in the toolbar.
376 */
377 QPointer<DolphinUrlNavigator> m_urlNavigatorConnected;
378 DolphinSearchBox* m_searchBox;
379 bool m_searchModeEnabled;
380 KMessageWidget* m_messageWidget;
381
382 DolphinView* m_view;
383
384 FilterBar* m_filterBar;
385
386 DolphinStatusBar* m_statusBar;
387 QTimer* m_statusBarTimer; // Triggers a delayed update
388 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
389 bool m_autoGrabFocus;
390 /**
391 * The visual state to be applied to the next UrlNavigator that gets
392 * connected to this ViewContainer.
393 */
394 std::unique_ptr<DolphinUrlNavigator::VisualState> m_urlNavigatorVisualState;
395
396 #ifdef HAVE_KACTIVITIES
397 private:
398 KActivities::ResourceInstance * m_activityResourceInstance;
399 #endif
400 };
401
402 #endif // DOLPHINVIEWCONTAINER_H