2 * SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef DOLPHINVIEWCONTAINER_H
8 #define DOLPHINVIEWCONTAINER_H
10 #include "config-dolphin.h"
11 #include "dolphinurlnavigator.h"
12 #include "selectionmode/bottombar.h"
13 #include "views/dolphinview.h"
17 #include <KUrlNavigator>
19 #include <QElapsedTimer>
20 #include <QPushButton>
28 class DolphinSearchBox
;
29 class DolphinStatusBar
;
30 namespace SelectionMode
36 * @short Represents a view for the directory content
37 * including the navigation bar, filter bar and status bar.
39 * View modes for icons, compact and details are supported. Currently
40 * Dolphin allows to have up to two views inside the main window.
45 * @see DolphinStatusBar
47 class DolphinViewContainer
: public QWidget
52 enum MessageType
{ Information
, Warning
, Error
};
54 DolphinViewContainer(const QUrl
&url
, QWidget
*parent
);
55 ~DolphinViewContainer() override
;
58 * Returns the current active URL, where all actions are applied.
59 * The URL navigator is synchronized with this URL.
62 KFileItem
rootItem() const;
65 * If \a active is true, the view container will marked as active. The active
66 * view container is defined as view where all actions are applied to.
68 void setActive(bool active
);
69 bool isActive() const;
72 * If \a grab is set to true, the container automatically grabs the focus
73 * as soon as the URL has been changed. Per default the grabbing
74 * of the focus is enabled.
76 void setAutoGrabFocus(bool grab
);
77 bool autoGrabFocus() const;
79 QString
currentSearchText() const;
81 const DolphinStatusBar
*statusBar() const;
82 DolphinStatusBar
*statusBar();
85 * @return An UrlNavigator that is controlling this view
86 * or nullptr if there is none.
87 * @see connectUrlNavigator()
88 * @see disconnectUrlNavigator()
90 * Use urlNavigatorInternalWithHistory() if you want to access the history.
91 * @see urlNavigatorInternalWithHistory()
93 const DolphinUrlNavigator
*urlNavigator() const;
95 * @return An UrlNavigator that is controlling this view
96 * or nullptr if there is none.
97 * @see connectUrlNavigator()
98 * @see disconnectUrlNavigator()
100 * Use urlNavigatorInternalWithHistory() if you want to access the history.
101 * @see urlNavigatorInternalWithHistory()
103 DolphinUrlNavigator
*urlNavigator();
106 * @return An UrlNavigator that contains this view's history.
107 * Use urlNavigator() instead when not accessing the history.
109 const DolphinUrlNavigator
*urlNavigatorInternalWithHistory() const;
111 * @return An UrlNavigator that contains this view's history.
112 * Use urlNavigator() instead when not accessing the history.
114 DolphinUrlNavigator
*urlNavigatorInternalWithHistory();
116 const DolphinView
*view() const;
120 * @param urlNavigator The UrlNavigator that is supposed to control
123 void connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
);
126 * Disconnects the navigator that is currently controlling the view.
127 * This method completely reverses connectUrlNavigator().
129 void disconnectUrlNavigator();
132 * Sets a selection mode that is useful for quick and easy selecting or deselecting of files.
133 * This method is the central authority about enabling or disabling selection mode:
134 * All other classes that want to enable or disable selection mode should trigger a call of this method.
136 * This method sets the selection mode for the view of this viewContainer and sets the visibility of the
137 * selection mode top and bottom bar which also belong to this viewContainer.
139 * @param enabled Whether to enable or disable selection mode.
140 * @param actionCollection The collection of actions from which the actions on the bottom bar are retrieved.
141 * @param bottomBarContents The contents the bar is supposed to show after this call.
143 void setSelectionModeEnabled(bool enabled
,
144 KActionCollection
*actionCollection
= nullptr,
145 SelectionMode::BottomBar::Contents bottomBarContents
= SelectionMode::BottomBar::Contents::GeneralContents
);
146 /** @see setSelectionModeEnabled() */
147 bool isSelectionModeEnabled() const;
150 * Shows the message \msg with the given type non-modal above
153 void showMessage(const QString
&msg
, MessageType type
);
156 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
160 /** Returns true, if the filter bar is visible. */
161 bool isFilterBarVisible() const;
163 /** Returns true if the search mode is enabled. */
164 bool isSearchModeEnabled() const;
167 * @return Text that should be used for the current URL when creating
170 QString
placesText() const;
173 * Reload the view of this container. This will also hide messages in a messagewidget.
178 * @return Returns a Caption suitable for display in the window title.
179 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
180 * If it's false, it calls caption().
182 QString
captionWindowTitle() const;
185 * @return Returns a Caption suitable for display to the user. It is
186 * calculated depending on settings, if a search is active and other
189 QString
caption() const;
192 * Disable/enable the behavior of "select child when moving to parent folder"
193 * offered by KUrlNavigator.
195 * See KUrlNavigator::urlSelectionRequested
197 void disableUrlNavigatorSelectionRequests();
198 void enableUrlNavigatorSelectionRequests();
199 void clearFilterBar();
203 * Sets the current active URL, where all actions are applied. The
204 * URL navigator is synchronized with this URL. The signals
205 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
207 * @see DolphinViewContainer::urlNavigator()
209 void setUrl(const QUrl
&url
);
212 * Popups the filter bar above the status bar if \a visible is true.
213 * It \a visible is true, it is assured that the filter bar gains
214 * the keyboard focus.
216 void setFilterBarVisible(bool visible
);
219 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
220 * will be hidden and replaced by a line editor that allows to enter a search term.
222 void setSearchModeEnabled(bool enabled
);
224 /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
225 void slotSplitTabDisabled();
229 * Is emitted whenever the filter bar has changed its visibility state.
231 void showFilterBarChanged(bool shown
);
233 * Is emitted whenever the search mode has changed its state.
235 void searchModeEnabledChanged(bool enabled
);
237 void selectionModeChanged(bool enabled
);
240 * Is emitted when the write state of the folder has been changed. The application
241 * should disable all actions like "Create New..." that depend on the write
244 void writeStateChanged(bool isFolderWritable
);
247 * Is emitted when the Caption has been changed.
248 * @see DolphinViewContainer::caption()
250 void captionChanged();
253 * Is emitted if a new tab should be opened in the background for the URL \a url.
255 void tabRequested(const QUrl
&url
);
258 * Is emitted if a new tab should be opened for the URL \a url and set as active.
260 void activeTabRequested(const QUrl
&url
);
264 * Updates the number of items (= number of files + number of
265 * directories) in the statusbar. If files are selected, the number
266 * of selected files and the sum of the filesize is shown. The update
267 * is done asynchronously, as getting the sum of the
268 * filesizes can be an expensive operation.
269 * Unless a previous OperationCompletedMessage was set very shortly before
270 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
271 * Previous ErrorMessages however are always preserved.
273 void delayedStatusBarUpdate();
276 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
277 * updates the status bar synchronously.
279 void updateStatusBar();
281 void updateDirectoryLoadingProgress(int percent
);
283 void updateDirectorySortingProgress(int percent
);
286 * Updates the statusbar to show an undetermined progress with the correct
287 * context information whether a searching or a directory loading is done.
289 void slotDirectoryLoadingStarted();
292 * Assures that the viewport position is restored and updates the
293 * statusbar to reflect the current content.
295 void slotDirectoryLoadingCompleted();
298 * Updates the statusbar to show, that the directory loading has
301 void slotDirectoryLoadingCanceled();
304 * Is called if the URL set by DolphinView::setUrl() represents
305 * a file and not a directory. Takes care to activate the file.
307 void slotUrlIsFileError(const QUrl
&url
);
310 * Handles clicking on an item. If the item is a directory, the
311 * directory is opened in the view. If the item is a file, the file
312 * gets started by the corresponding application.
314 void slotItemActivated(const KFileItem
&item
);
317 * Handles activation of multiple files. The files get started by
318 * the corresponding applications.
320 void slotItemsActivated(const KFileItemList
&items
);
323 * Handles middle click of file. It opens the file passed using the second application associated with the file's mimetype.
325 void slotfileMiddleClickActivated(const KFileItem
&item
);
328 * Shows the information for the item \a item inside the statusbar. If the
329 * item is null, the default statusbar information is shown.
331 void showItemInfo(const KFileItem
&item
);
333 void closeFilterBar();
336 * Filters the currently shown items by \a nameFilter. All items
337 * which contain the given filter string will be shown.
339 void setNameFilter(const QString
&nameFilter
);
342 * Marks the view container as active
343 * (see DolphinViewContainer::setActive()).
348 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
349 * is emitted. Tries to save the view-state.
351 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&url
);
354 * Restores the current view to show \a url and assures
355 * that the root URL of the view is respected.
357 void slotUrlNavigatorLocationChanged(const QUrl
&url
);
360 * @see KUrlNavigator::urlSelectionRequested
362 void slotUrlSelectionRequested(const QUrl
&url
);
365 * Is invoked when a redirection is done and changes the
366 * URL of the URL navigator to \a newUrl without triggering
367 * a reloading of the directory.
369 void redirect(const QUrl
&oldUrl
, const QUrl
&newUrl
);
371 /** Requests the focus for the view \a m_view. */
375 * Gets the search URL from the searchbox and starts searching.
377 void startSearching();
378 void openSearchBox();
379 void closeSearchBox();
382 * Stops the loading of a directory. Is connected with the "stopPressed" signal
383 * from the statusbar.
385 void stopDirectoryLoading();
387 void slotStatusBarZoomLevelChanged(int zoomLevel
);
390 * Slot that calls showMessage(msg, Error).
392 void showErrorMessage(const QString
&msg
);
395 * Is invoked when a KFilePlacesModel has been changed
396 * @see DolphinPlacesModelSingleton::instance().placesModel()
398 void slotPlacesModelChanged();
400 void slotHiddenFilesShownChanged(bool showHiddenFiles
);
401 void slotSortHiddenLastChanged(bool hiddenLast
);
402 void slotCurrentDirectoryRemoved();
404 void slotOpenUrlFinished(KJob
*job
);
408 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
410 bool isSearchUrl(const QUrl
&url
) const;
413 * Saves the state of the current view: contents position,
416 void saveViewState();
419 * Restores the state of the current view iff the URL navigator contains a
420 * non-empty location state.
422 void tryRestoreViewState();
425 * @return Path of nearest existing ancestor directory.
427 QString
getNearestExistingAncestorOfPath(const QString
&path
) const;
430 QGridLayout
*m_topLayout
;
433 * The internal UrlNavigator which is never visible to the user.
434 * m_urlNavigator is used even when another UrlNavigator is controlling
435 * the view to keep track of this object's history.
437 std::unique_ptr
<DolphinUrlNavigator
> m_urlNavigator
;
440 * The UrlNavigator that is currently connected to the view.
441 * This is a nullptr if no UrlNavigator is connected.
442 * Otherwise it's one of the UrlNavigators visible in the toolbar.
444 QPointer
<DolphinUrlNavigator
> m_urlNavigatorConnected
;
446 DolphinSearchBox
*m_searchBox
;
447 bool m_searchModeEnabled
;
449 KMessageWidget
*m_messageWidget
;
451 /// A bar shown at the top of the view to signify that selection mode is currently active.
452 SelectionMode::TopBar
*m_selectionModeTopBar
;
456 FilterBar
*m_filterBar
;
458 /// A bar shown at the bottom of the view whose contents depend on what the user is currently doing.
459 SelectionMode::BottomBar
*m_selectionModeBottomBar
;
461 DolphinStatusBar
*m_statusBar
;
462 QTimer
*m_statusBarTimer
; // Triggers a delayed update
463 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
464 bool m_autoGrabFocus
;
466 * The visual state to be applied to the next UrlNavigator that gets
467 * connected to this ViewContainer.
469 std::unique_ptr
<DolphinUrlNavigator::VisualState
> m_urlNavigatorVisualState
;
472 #endif // DOLPHINVIEWCONTAINER_H