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>
24 namespace KActivities
{
25 class ResourceInstance
;
34 class DolphinSearchBox
;
35 class DolphinStatusBar
;
36 namespace SelectionMode
{
41 * @short Represents a view for the directory content
42 * including the navigation bar, filter bar and status bar.
44 * View modes for icons, compact and details are supported. Currently
45 * Dolphin allows to have up to two views inside the main window.
50 * @see DolphinStatusBar
52 class DolphinViewContainer
: public QWidget
64 DolphinViewContainer(const QUrl
& url
, QWidget
* parent
);
65 ~DolphinViewContainer() override
;
68 * Returns the current active URL, where all actions are applied.
69 * The URL navigator is synchronized with this URL.
74 * If \a active is true, the view container will marked as active. The active
75 * view container is defined as view where all actions are applied to.
77 void setActive(bool active
);
78 bool isActive() const;
81 * If \a grab is set to true, the container automatically grabs the focus
82 * as soon as the URL has been changed. Per default the grabbing
83 * of the focus is enabled.
85 void setAutoGrabFocus(bool grab
);
86 bool autoGrabFocus() const;
88 QString
currentSearchText() const;
90 const DolphinStatusBar
* statusBar() const;
91 DolphinStatusBar
* statusBar();
94 * @return An UrlNavigator that is controlling this view
95 * or nullptr if there is none.
96 * @see connectUrlNavigator()
97 * @see disconnectUrlNavigator()
99 * Use urlNavigatorInternalWithHistory() if you want to access the history.
100 * @see urlNavigatorInternalWithHistory()
102 const DolphinUrlNavigator
*urlNavigator() const;
104 * @return An UrlNavigator that is controlling this view
105 * or nullptr if there is none.
106 * @see connectUrlNavigator()
107 * @see disconnectUrlNavigator()
109 * Use urlNavigatorInternalWithHistory() if you want to access the history.
110 * @see urlNavigatorInternalWithHistory()
112 DolphinUrlNavigator
*urlNavigator();
115 * @return An UrlNavigator that contains this view's history.
116 * Use urlNavigator() instead when not accessing the history.
118 const DolphinUrlNavigator
*urlNavigatorInternalWithHistory() const;
120 * @return An UrlNavigator that contains this view's history.
121 * Use urlNavigator() instead when not accessing the history.
123 DolphinUrlNavigator
*urlNavigatorInternalWithHistory();
125 const DolphinView
* view() const;
129 * @param urlNavigator The UrlNavigator that is supposed to control
132 void connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
);
135 * Disconnects the navigator that is currently controlling the view.
136 * This method completely reverses connectUrlNavigator().
138 void disconnectUrlNavigator();
140 void setSelectionModeEnabled(bool enabled
, KActionCollection
*actionCollection
= nullptr, SelectionMode::BottomBar::Contents bottomBarContents
= SelectionMode::BottomBar::Contents::GeneralContents
);
141 bool isSelectionModeEnabled() const;
144 * Shows the message \msg with the given type non-modal above
147 void showMessage(const QString
& msg
, MessageType type
);
150 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
154 /** Returns true, if the filter bar is visible. */
155 bool isFilterBarVisible() const;
158 /** Returns true if the search mode is enabled. */
159 bool isSearchModeEnabled() const;
162 * @return Text that should be used for the current URL when creating
165 QString
placesText() const;
168 * Reload the view of this container. This will also hide messages in a messagewidget.
173 * @return Returns a Caption suitable for display in the window title.
174 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
175 * If it's false, it calls caption().
177 QString
captionWindowTitle() const;
180 * @return Returns a Caption suitable for display to the user. It is
181 * calculated depending on settings, if a search is active and other
184 QString
caption() const;
187 * Disable/enable the behavior of "select child when moving to parent folder"
188 * offered by KUrlNavigator.
190 * See KUrlNavigator::urlSelectionRequested
192 void disableUrlNavigatorSelectionRequests();
193 void enableUrlNavigatorSelectionRequests();
197 * Sets the current active URL, where all actions are applied. The
198 * URL navigator is synchronized with this URL. The signals
199 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
201 * @see DolphinViewContainer::urlNavigator()
203 void setUrl(const QUrl
& url
);
206 * Popups the filter bar above the status bar if \a visible is true.
207 * It \a visible is true, it is assured that the filter bar gains
208 * the keyboard focus.
210 void setFilterBarVisible(bool visible
);
213 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
214 * will be hidden and replaced by a line editor that allows to enter a search term.
216 void setSearchModeEnabled(bool enabled
);
218 /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
219 void slotSplitTabDisabled();
223 * Is emitted whenever the filter bar has changed its visibility state.
225 void showFilterBarChanged(bool shown
);
227 * Is emitted whenever the search mode has changed its state.
229 void searchModeEnabledChanged(bool enabled
);
231 void selectionModeChanged(bool enabled
);
234 * Is emitted when the write state of the folder has been changed. The application
235 * should disable all actions like "Create New..." that depend on the write
238 void writeStateChanged(bool isFolderWritable
);
241 * Is emitted when the Caption has been changed.
242 * @see DolphinViewContainer::caption()
244 void captionChanged();
247 * Is emitted if a new tab should be opened in the background for the URL \a url.
249 void tabRequested(const QUrl
&url
);
252 * Is emitted if a new tab should be opened for the URL \a url and set as active.
254 void activeTabRequested(const QUrl
&url
);
258 * Updates the number of items (= number of files + number of
259 * directories) in the statusbar. If files are selected, the number
260 * of selected files and the sum of the filesize is shown. The update
261 * is done asynchronously, as getting the sum of the
262 * filesizes can be an expensive operation.
263 * Unless a previous OperationCompletedMessage was set very shortly before
264 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
265 * Previous ErrorMessages however are always preserved.
267 void delayedStatusBarUpdate();
270 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
271 * updates the status bar synchronously.
273 void updateStatusBar();
275 void updateDirectoryLoadingProgress(int percent
);
277 void updateDirectorySortingProgress(int percent
);
280 * Updates the statusbar to show an undetermined progress with the correct
281 * context information whether a searching or a directory loading is done.
283 void slotDirectoryLoadingStarted();
286 * Assures that the viewport position is restored and updates the
287 * statusbar to reflect the current content.
289 void slotDirectoryLoadingCompleted();
292 * Updates the statusbar to show, that the directory loading has
295 void slotDirectoryLoadingCanceled();
298 * Is called if the URL set by DolphinView::setUrl() represents
299 * a file and not a directory. Takes care to activate the file.
301 void slotUrlIsFileError(const QUrl
& url
);
304 * Handles clicking on an item. If the item is a directory, the
305 * directory is opened in the view. If the item is a file, the file
306 * gets started by the corresponding application.
308 void slotItemActivated(const KFileItem
&item
);
311 * Handles activation of multiple files. The files get started by
312 * the corresponding applications.
314 void slotItemsActivated(const KFileItemList
& items
);
317 * Shows the information for the item \a item inside the statusbar. If the
318 * item is null, the default statusbar information is shown.
320 void showItemInfo(const KFileItem
& item
);
322 void closeFilterBar();
325 * Filters the currently shown items by \a nameFilter. All items
326 * which contain the given filter string will be shown.
328 void setNameFilter(const QString
& nameFilter
);
331 * Marks the view container as active
332 * (see DolphinViewContainer::setActive()).
337 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
338 * is emitted. Tries to save the view-state.
340 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
& url
);
343 * Restores the current view to show \a url and assures
344 * that the root URL of the view is respected.
346 void slotUrlNavigatorLocationChanged(const QUrl
& url
);
349 * @see KUrlNavigator::urlSelectionRequested
351 void slotUrlSelectionRequested(const QUrl
& url
);
354 * Is invoked when a redirection is done and changes the
355 * URL of the URL navigator to \a newUrl without triggering
356 * a reloading of the directory.
358 void redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
);
360 /** Requests the focus for the view \a m_view. */
364 * Gets the search URL from the searchbox and starts searching.
366 void startSearching();
367 void closeSearchBox();
370 * Stops the loading of a directory. Is connected with the "stopPressed" signal
371 * from the statusbar.
373 void stopDirectoryLoading();
375 void slotStatusBarZoomLevelChanged(int zoomLevel
);
378 * Slot that calls showMessage(msg, Error).
380 void showErrorMessage(const QString
& msg
);
383 * Is invoked when a KFilePlacesModel has been changed
384 * @see DolphinPlacesModelSingleton::instance().placesModel()
386 void slotPlacesModelChanged();
388 void slotHiddenFilesShownChanged(bool showHiddenFiles
);
389 void slotSortHiddenLastChanged(bool hiddenLast
);
391 void slotOpenUrlFinished(KJob
* job
);
395 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
397 bool isSearchUrl(const QUrl
& url
) const;
400 * Saves the state of the current view: contents position,
403 void saveViewState();
406 * Restores the state of the current view iff the URL navigator contains a
407 * non-empty location state.
409 void tryRestoreViewState();
412 QGridLayout
*m_topLayout
;
415 * The internal UrlNavigator which is never visible to the user.
416 * m_urlNavigator is used even when another UrlNavigator is controlling
417 * the view to keep track of this object's history.
419 std::unique_ptr
<DolphinUrlNavigator
> m_urlNavigator
;
422 * The UrlNavigator that is currently connected to the view.
423 * This is a nullptr if no UrlNavigator is connected.
424 * Otherwise it's one of the UrlNavigators visible in the toolbar.
426 QPointer
<DolphinUrlNavigator
> m_urlNavigatorConnected
;
428 DolphinSearchBox
* m_searchBox
;
429 bool m_searchModeEnabled
;
431 KMessageWidget
* m_messageWidget
;
433 /// A bar shown at the top of the view to signify that selection mode is currently active.
434 SelectionMode::TopBar
*m_selectionModeTopBar
;
438 FilterBar
* m_filterBar
;
440 /// A bar shown at the bottom of the view whose contents depend on what the user is currently doing.
441 SelectionMode::BottomBar
*m_selectionModeBottomBar
;
443 DolphinStatusBar
* m_statusBar
;
444 QTimer
* m_statusBarTimer
; // Triggers a delayed update
445 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
446 bool m_autoGrabFocus
;
448 * The visual state to be applied to the next UrlNavigator that gets
449 * connected to this ViewContainer.
451 std::unique_ptr
<DolphinUrlNavigator::VisualState
> m_urlNavigatorVisualState
;
455 KActivities::ResourceInstance
* m_activityResourceInstance
;
459 #endif // DOLPHINVIEWCONTAINER_H