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 * Forwards to DolphinStatusBar::showProgress(). Only exception: The button to cancel the task is hidden.
189 * @see DolphinStatusBar::showProgress().
191 void showProgress(const QString
¤tlyRunningTaskTitle
, int progressPercent
);
194 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
198 /** @returns true, if the filter bar is visible.
199 * false, if it is hidden or currently animating towards a hidden state. */
200 bool isFilterBarVisible() const;
203 * @return Text that should be used for the current URL when creating
206 QString
placesText() const;
209 * Reload the view of this container. This will also hide messages in a messagewidget.
214 * @return Returns a Caption suitable for display in the window title.
215 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
216 * If it's false, it calls caption().
218 QString
captionWindowTitle() const;
221 * @return Returns a Caption suitable for display to the user. It is
222 * calculated depending on settings, if a search is active and other
225 QString
caption() const;
228 * Disable/enable the behavior of "select child when moving to parent folder"
229 * offered by KUrlNavigator.
231 * See KUrlNavigator::urlSelectionRequested
233 void disableUrlNavigatorSelectionRequests();
234 void enableUrlNavigatorSelectionRequests();
235 void clearFilterBar();
239 * Sets the current active URL, where all actions are applied. The
240 * URL navigator is synchronized with this URL. The signals
241 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
243 * @see DolphinViewContainer::urlNavigator()
245 void setUrl(const QUrl
&url
);
248 * Popups the filter bar above the status bar if \a visible is true.
249 * It \a visible is true, it is assured that the filter bar gains
250 * the keyboard focus.
252 void setFilterBarVisible(bool visible
);
254 /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
255 void slotSplitTabDisabled();
259 * Is emitted whenever the filter bar has changed its visibility state.
261 void showFilterBarChanged(bool shown
);
263 * 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
264 * this signal is emitted because typically the showing and hiding is animated.
265 * @param visible The visibility state the search bar is going to end up at.
267 * @see setSearchBarVisible().
268 * @see isSearchBarVisible().
270 void searchBarVisibilityChanged(bool visible
);
272 void selectionModeChanged(bool enabled
);
275 * Is emitted when the write state of the folder has been changed. The application
276 * should disable all actions like "Create New..." that depend on the write
279 void writeStateChanged(bool isFolderWritable
);
282 * Is emitted when the Caption has been changed.
283 * @see DolphinViewContainer::caption()
285 void captionChanged();
288 * Is emitted if a new tab should be opened in the background for the URL \a url.
290 void tabRequested(const QUrl
&url
);
293 * Is emitted if a new tab should be opened for the URL \a url and set as active.
295 void activeTabRequested(const QUrl
&url
);
299 * Updates the number of items (= number of files + number of
300 * directories) in the statusbar. If files are selected, the number
301 * of selected files and the sum of the filesize is shown. The update
302 * is done asynchronously, as getting the sum of the
303 * filesizes can be an expensive operation.
304 * Unless a previous OperationCompletedMessage was set very shortly before
305 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
306 * Previous ErrorMessages however are always preserved.
308 void delayedStatusBarUpdate();
311 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
312 * updates the status bar synchronously.
314 void updateStatusBar();
317 * Updates the statusbar to show an undetermined progress with the correct
318 * context information whether a searching or a directory loading is done.
320 void slotDirectoryLoadingStarted();
323 * Assures that the viewport position is restored and updates the
324 * statusbar to reflect the current content.
326 void slotDirectoryLoadingCompleted();
329 * Updates the statusbar to show, that the directory loading has
332 void slotDirectoryLoadingCanceled();
335 * Is called if the URL set by DolphinView::setUrl() represents
336 * a file and not a directory. Takes care to activate the file.
338 void slotUrlIsFileError(const QUrl
&url
);
341 * Handles clicking on an item. If the item is a directory, the
342 * directory is opened in the view. If the item is a file, the file
343 * gets started by the corresponding application.
345 void slotItemActivated(const KFileItem
&item
);
348 * Handles activation of multiple files. The files get started by
349 * the corresponding applications.
351 void slotItemsActivated(const KFileItemList
&items
);
354 * Handles middle click of file. It opens the file passed using the second application associated with the file's mimetype.
356 void slotfileMiddleClickActivated(const KFileItem
&item
);
359 * Shows the information for the item \a item inside the statusbar. If the
360 * item is null, the default statusbar information is shown.
362 void showItemInfo(const KFileItem
&item
);
364 void closeFilterBar();
367 * Filters the currently shown items by \a nameFilter. All items
368 * which contain the given filter string will be shown.
370 void setNameFilter(const QString
&nameFilter
);
373 * Marks the view container as active
374 * (see DolphinViewContainer::setActive()).
379 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
380 * is emitted. Tries to save the view-state.
382 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
&url
);
385 * Restores the current view to show \a url and assures
386 * that the root URL of the view is respected.
388 void slotUrlNavigatorLocationChanged(const QUrl
&url
);
391 * @see KUrlNavigator::urlSelectionRequested
393 void slotUrlSelectionRequested(const QUrl
&url
);
396 * Is invoked when a redirection is done and changes the
397 * URL of the URL navigator to \a newUrl without triggering
398 * a reloading of the directory.
400 void redirect(const QUrl
&oldUrl
, const QUrl
&newUrl
);
402 /** Requests the focus for the view \a m_view. */
406 * Stops the loading of a directory. Is connected with the "stopPressed" signal
407 * from the statusbar.
409 void stopDirectoryLoading();
411 void slotStatusBarZoomLevelChanged(int zoomLevel
);
414 * Creates and shows an error message based on \p message and \p kioErrorCode.
416 void slotErrorMessageFromView(const QString
&message
, const int kioErrorCode
);
419 * Slot that calls showMessage(message, KMessageWidget::Error).
421 void showErrorMessage(const QString
&message
);
424 * Is invoked when a KFilePlacesModel has been changed
425 * @see DolphinPlacesModelSingleton::instance().placesModel()
427 void slotPlacesModelChanged();
429 void slotHiddenFilesShownChanged(bool showHiddenFiles
);
430 void slotSortHiddenLastChanged(bool hiddenLast
);
431 void slotCurrentDirectoryRemoved();
433 void slotOpenUrlFinished(KJob
*job
);
437 * Saves the state of the current view: contents position,
440 void saveViewState();
443 * Restores the state of the current view iff the URL navigator contains a
444 * non-empty location state.
446 void tryRestoreViewState();
449 * @return Path of nearest existing ancestor directory.
451 QString
getNearestExistingAncestorOfPath(const QString
&path
) const;
454 * Update the geometry of statusbar depending on what mode it is using.
456 void updateStatusBarGeometry();
459 * @return Preferred geometry of the small statusbar.
461 QRect
preferredSmallStatusBarGeometry();
464 * Check if a folder can be created at url.
465 * This method supports only local URLs.
467 bool isFolderCreatable(QUrl url
);
470 bool eventFilter(QObject
*object
, QEvent
*event
) override
;
473 QGridLayout
*m_topLayout
;
476 * The internal UrlNavigator which is never visible to the user.
477 * m_urlNavigator is used even when another UrlNavigator is controlling
478 * the view to keep track of this object's history.
480 std::unique_ptr
<DolphinUrlNavigator
> m_urlNavigator
;
483 * The UrlNavigator that is currently connected to the view.
484 * This is a nullptr if no UrlNavigator is connected.
485 * Otherwise it's one of the UrlNavigators visible in the toolbar.
487 QPointer
<DolphinUrlNavigator
> m_urlNavigatorConnected
;
489 Search::Bar
*m_searchBar
;
490 bool m_searchModeEnabled
;
492 /// A bar shown at the top of the view to signify that the view is currently viewed and acted on with elevated privileges.
493 Admin::Bar
*m_adminBar
;
494 /// An action to switch to the admin protocol. This variable will always be nullptr unless kio-admin was installed. @see Admin::WorkerIntegration.
495 QAction
*m_authorizeToEnterFolderAction
;
496 /// An action to create new folder in case user enters a nonexistent URL in the location bar.
497 QAction
*m_createFolderAction
;
499 KMessageWidget
*m_messageWidget
;
501 /// A bar shown at the top of the view to signify that selection mode is currently active.
502 SelectionMode::TopBar
*m_selectionModeTopBar
;
506 FilterBar
*m_filterBar
;
508 /// A bar shown at the bottom of the view whose contents depend on what the user is currently doing.
509 SelectionMode::BottomBar
*m_selectionModeBottomBar
;
511 DolphinStatusBar
*m_statusBar
;
512 QTimer
*m_statusBarTimer
; // Triggers a delayed update
513 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
514 bool m_grabFocusOnUrlChange
;
516 * The visual state to be applied to the next UrlNavigator that gets
517 * connected to this ViewContainer.
519 std::unique_ptr
<DolphinUrlNavigator::VisualState
> m_urlNavigatorVisualState
;
522 #endif // DOLPHINVIEWCONTAINER_H