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 <KMessageWidget>
18 #include <KUrlNavigator>
20 #include <QElapsedTimer>
21 #include <QPushButton>
24 #include <initializer_list>
38 class DolphinStatusBar
;
40 namespace SelectionMode
46 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
48 bool isSearchUrl(const QUrl
&url
);
51 * @short Represents a view for the directory content
52 * including the navigation bar, filter bar and status bar.
54 * View modes for icons, compact and details are supported. Currently
55 * Dolphin allows to have up to two views inside the main window.
60 * @see DolphinStatusBar
62 class DolphinViewContainer
: public QWidget
67 DolphinViewContainer(const QUrl
&url
, QWidget
*parent
);
68 ~DolphinViewContainer() override
;
71 * Returns the current active URL, where all actions are applied.
72 * The URL navigator is synchronized with this URL.
75 KFileItem
rootItem() const;
78 * If \a active is true, the view container will marked as active. The active
79 * view container is defined as view where all actions are applied to.
81 void setActive(bool active
);
82 bool isActive() const;
85 * If \a grab is set to true, the container automatically grabs the focus
86 * as soon as the URL has been changed. Per default the grabbing
87 * of the focus is enabled.
89 void setGrabFocusOnUrlChange(bool grabFocus
);
91 const DolphinStatusBar
*statusBar() const;
92 DolphinStatusBar
*statusBar();
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 const DolphinUrlNavigator
*urlNavigator() const;
105 * @return An UrlNavigator that is controlling this view
106 * or nullptr if there is none.
107 * @see connectUrlNavigator()
108 * @see disconnectUrlNavigator()
110 * Use urlNavigatorInternalWithHistory() if you want to access the history.
111 * @see urlNavigatorInternalWithHistory()
113 DolphinUrlNavigator
*urlNavigator();
116 * @return An UrlNavigator that contains this view's history.
117 * Use urlNavigator() instead when not accessing the history.
119 const DolphinUrlNavigator
*urlNavigatorInternalWithHistory() const;
121 * @return An UrlNavigator that contains this view's history.
122 * Use urlNavigator() instead when not accessing the history.
124 DolphinUrlNavigator
*urlNavigatorInternalWithHistory();
126 const DolphinView
*view() const;
130 * @param urlNavigator The UrlNavigator that is supposed to control
133 void connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
);
136 * Disconnects the navigator that is currently controlling the view.
137 * This method completely reverses connectUrlNavigator().
139 void disconnectUrlNavigator();
142 * Sets the visibility of this objects search configuration user interface. This search bar is the primary interface in Dolphin to search for files and
145 * The signal searchBarVisibilityChanged will be emitted when the new visibility state is different from the old.
147 * Typically an animation will play when the search bar is shown or hidden, so the visibility of the bar will not necessarily match @p visible when this
148 * method returns. Instead use isSearchBarVisible(), which will always communicate the visibility state the search bar is heading to.
151 * @see isSearchBarVisible().
153 void setSearchBarVisible(bool visible
);
155 /** @returns true if the search bar is visible while not being in the process to hide itself. */
156 bool isSearchBarVisible() const;
159 * Moves keyboard focus to the search bar. The search term is fully selected to allow easy replacing.
161 void setFocusToSearchBar();
164 * Sets a selection mode that is useful for quick and easy selecting or deselecting of files.
165 * This method is the central authority about enabling or disabling selection mode:
166 * All other classes that want to enable or disable selection mode should trigger a call of this method.
168 * This method sets the selection mode for the view of this viewContainer and sets the visibility of the
169 * selection mode top and bottom bar which also belong to this viewContainer.
171 * @param enabled Whether to enable or disable selection mode.
172 * @param actionCollection The collection of actions from which the actions on the bottom bar are retrieved.
173 * @param bottomBarContents The contents the bar is supposed to show after this call.
175 void setSelectionModeEnabled(bool enabled
,
176 KActionCollection
*actionCollection
= nullptr,
177 SelectionMode::BottomBar::Contents bottomBarContents
= SelectionMode::BottomBar::Contents::GeneralContents
);
178 /** @see setSelectionModeEnabled() */
179 bool isSelectionModeEnabled() const;
182 * Shows the message \message with the given type \messageType non-modal above the view-content.
183 * \buttonActions defines actions which the user can trigger as a response to this message. They are presented as buttons below the \message.
185 void showMessage(const QString
&message
, KMessageWidget::MessageType messageType
, std::initializer_list
<QAction
*> buttonActions
= {});
188 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
192 /** @returns true, if the filter bar is visible.
193 * false, if it is hidden or currently animating towards a hidden state. */
194 bool isFilterBarVisible() const;
197 * @return Text that should be used for the current URL when creating
200 QString
placesText() const;
203 * Reload the view of this container. This will also hide messages in a messagewidget.
208 * @return Returns a Caption suitable for display in the window title.
209 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
210 * If it's false, it calls caption().
212 QString
captionWindowTitle() const;
215 * @return Returns a Caption suitable for display to the user. It is
216 * calculated depending on settings, if a search is active and other
219 QString
caption() const;
222 * Disable/enable the behavior of "select child when moving to parent folder"
223 * offered by KUrlNavigator.
225 * See KUrlNavigator::urlSelectionRequested
227 void disableUrlNavigatorSelectionRequests();
228 void enableUrlNavigatorSelectionRequests();
229 void clearFilterBar();
233 * Sets the current active URL, where all actions are applied. The
234 * URL navigator is synchronized with this URL. The signals
235 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
237 * @see DolphinViewContainer::urlNavigator()
239 void setUrl(const QUrl
&url
);
242 * Popups the filter bar above the status bar if \a visible is true.
243 * It \a visible is true, it is assured that the filter bar gains
244 * the keyboard focus.
246 void setFilterBarVisible(bool visible
);
248 /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
249 void slotSplitTabDisabled();
253 * Is emitted whenever the filter bar has changed its visibility state.
255 void showFilterBarChanged(bool shown
);
257 * Is emitted whenever a change to the search bar's visibility is invoked. The visibility change might not have actually already taken effect by the time
258 * this signal is emitted because typically the showing and hiding is animated.
259 * @param visible The visibility state the search bar is going to end up at.
261 * @see setSearchBarVisible().
262 * @see isSearchBarVisible().
264 void searchBarVisibilityChanged(bool visible
);
266 void selectionModeChanged(bool enabled
);
269 * Is emitted when the write state of the folder has been changed. The application
270 * should disable all actions like "Create New..." that depend on the write
273 void writeStateChanged(bool isFolderWritable
);
276 * Is emitted when the Caption has been changed.
277 * @see DolphinViewContainer::caption()
279 void captionChanged();
282 * Is emitted if a new tab should be opened in the background for the URL \a url.
284 void tabRequested(const QUrl
&url
);
287 * Is emitted if a new tab should be opened for the URL \a url and set as active.
289 void activeTabRequested(const QUrl
&url
);
293 * Updates the number of items (= number of files + number of
294 * directories) in the statusbar. If files are selected, the number
295 * of selected files and the sum of the filesize is shown. The update
296 * is done asynchronously, as getting the sum of the
297 * filesizes can be an expensive operation.
298 * Unless a previous OperationCompletedMessage was set very shortly before
299 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
300 * Previous ErrorMessages however are always preserved.
302 void delayedStatusBarUpdate();
305 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
306 * updates the status bar synchronously.
308 void updateStatusBar();
311 * Updates the statusbar to show an undetermined progress with the correct
312 * context information whether a searching or a directory loading is done.
314 void slotDirectoryLoadingStarted();
317 * Assures that the viewport position is restored and updates the
318 * statusbar to reflect the current content.
320 void slotDirectoryLoadingCompleted();
323 * Updates the statusbar to show, that the directory loading has
326 void slotDirectoryLoadingCanceled();
329 * Is called if the URL set by DolphinView::setUrl() represents
330 * a file and not a directory. Takes care to activate the file.
332 void slotUrlIsFileError(const QUrl
&url
);
335 * Handles clicking on an item. If the item is a directory, the
336 * directory is opened in the view. If the item is a file, the file
337 * gets started by the corresponding application.
339 void slotItemActivated(const KFileItem
&item
);
342 * Handles activation of multiple files. The files get started by
343 * the corresponding applications.
345 void slotItemsActivated(const KFileItemList
&items
);
348 * Handles middle click of file. It opens the file passed using the second application associated with the file's mimetype.
350 void slotfileMiddleClickActivated(const KFileItem
&item
);
353 * Shows the information for the item \a item inside the statusbar. If the
354 * item is null, the default statusbar information is shown.
356 void showItemInfo(const KFileItem
&item
);
358 void closeFilterBar();
361 * Filters the currently shown items by \a nameFilter. All items
362 * which contain the given filter string will be shown.
364 void setNameFilter(const QString
&nameFilter
);
367 * Marks the view container as active
368 * (see DolphinViewContainer::setActive()).
373 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
374 * is emitted. Tries to save the view-state.
376 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&url
);
379 * Restores the current view to show \a url and assures
380 * that the root URL of the view is respected.
382 void slotUrlNavigatorLocationChanged(const QUrl
&url
);
385 * @see KUrlNavigator::urlSelectionRequested
387 void slotUrlSelectionRequested(const QUrl
&url
);
390 * Is invoked when a redirection is done and changes the
391 * URL of the URL navigator to \a newUrl without triggering
392 * a reloading of the directory.
394 void redirect(const QUrl
&oldUrl
, const QUrl
&newUrl
);
396 /** Requests the focus for the view \a m_view. */
400 * Stops the loading of a directory. Is connected with the "stopPressed" signal
401 * from the statusbar.
403 void stopDirectoryLoading();
405 void slotStatusBarZoomLevelChanged(int zoomLevel
);
408 * Creates and shows an error message based on \p message and \p kioErrorCode.
410 void slotErrorMessageFromView(const QString
&message
, const int kioErrorCode
);
413 * Slot that calls showMessage(message, KMessageWidget::Error).
415 void showErrorMessage(const QString
&message
);
418 * Is invoked when a KFilePlacesModel has been changed
419 * @see DolphinPlacesModelSingleton::instance().placesModel()
421 void slotPlacesModelChanged();
423 void slotHiddenFilesShownChanged(bool showHiddenFiles
);
424 void slotSortHiddenLastChanged(bool hiddenLast
);
425 void slotCurrentDirectoryRemoved();
427 void slotOpenUrlFinished(KJob
*job
);
431 * Saves the state of the current view: contents position,
434 void saveViewState();
437 * Restores the state of the current view iff the URL navigator contains a
438 * non-empty location state.
440 void tryRestoreViewState();
443 * @return Path of nearest existing ancestor directory.
445 QString
getNearestExistingAncestorOfPath(const QString
&path
) const;
448 * Update the geometry of statusbar depending on what mode it is using.
450 void updateStatusBarGeometry();
453 * @return Preferred geometry of the small statusbar.
455 QRect
preferredSmallStatusBarGeometry();
458 bool eventFilter(QObject
*object
, QEvent
*event
) override
;
461 QGridLayout
*m_topLayout
;
464 * The internal UrlNavigator which is never visible to the user.
465 * m_urlNavigator is used even when another UrlNavigator is controlling
466 * the view to keep track of this object's history.
468 std::unique_ptr
<DolphinUrlNavigator
> m_urlNavigator
;
471 * The UrlNavigator that is currently connected to the view.
472 * This is a nullptr if no UrlNavigator is connected.
473 * Otherwise it's one of the UrlNavigators visible in the toolbar.
475 QPointer
<DolphinUrlNavigator
> m_urlNavigatorConnected
;
477 Search::Bar
*m_searchBar
;
478 bool m_searchModeEnabled
;
480 /// A bar shown at the top of the view to signify that the view is currently viewed and acted on with elevated privileges.
481 Admin::Bar
*m_adminBar
;
482 /// An action to switch to the admin protocol. This variable will always be nullptr unless kio-admin was installed. @see Admin::WorkerIntegration.
483 QAction
*m_authorizeToEnterFolderAction
;
485 KMessageWidget
*m_messageWidget
;
487 /// A bar shown at the top of the view to signify that selection mode is currently active.
488 SelectionMode::TopBar
*m_selectionModeTopBar
;
492 FilterBar
*m_filterBar
;
494 /// A bar shown at the bottom of the view whose contents depend on what the user is currently doing.
495 SelectionMode::BottomBar
*m_selectionModeBottomBar
;
497 DolphinStatusBar
*m_statusBar
;
498 QTimer
*m_statusBarTimer
; // Triggers a delayed update
499 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
500 bool m_grabFocusOnUrlChange
;
502 * The visual state to be applied to the next UrlNavigator that gets
503 * connected to this ViewContainer.
505 std::unique_ptr
<DolphinUrlNavigator::VisualState
> m_urlNavigatorVisualState
;
508 #endif // DOLPHINVIEWCONTAINER_H