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-kactivities.h"
11 #include "dolphinurlnavigator.h"
12 #include "views/dolphinview.h"
16 #include <KUrlNavigator>
18 #include <QElapsedTimer>
19 #include <QPushButton>
22 #ifdef HAVE_KACTIVITIES
23 namespace KActivities
{
24 class ResourceInstance
;
32 class DolphinSearchBox
;
33 class DolphinStatusBar
;
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
59 DolphinViewContainer(const QUrl
& url
, QWidget
* parent
);
60 ~DolphinViewContainer() override
;
63 * Returns the current active URL, where all actions are applied.
64 * The URL navigator is synchronized with this URL.
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.
72 void setActive(bool active
);
73 bool isActive() const;
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.
80 void setAutoGrabFocus(bool grab
);
81 bool autoGrabFocus() const;
83 QString
currentSearchText() const;
85 const DolphinStatusBar
* statusBar() const;
86 DolphinStatusBar
* statusBar();
89 * @return An UrlNavigator that is controlling this view
90 * or nullptr if there is none.
91 * @see connectUrlNavigator()
92 * @see disconnectUrlNavigator()
94 * Use urlNavigatorInternalWithHistory() if you want to access the history.
95 * @see urlNavigatorInternalWithHistory()
97 const DolphinUrlNavigator
*urlNavigator() const;
99 * @return An UrlNavigator that is controlling this view
100 * or nullptr if there is none.
101 * @see connectUrlNavigator()
102 * @see disconnectUrlNavigator()
104 * Use urlNavigatorInternalWithHistory() if you want to access the history.
105 * @see urlNavigatorInternalWithHistory()
107 DolphinUrlNavigator
*urlNavigator();
110 * @return An UrlNavigator that contains this view's history.
111 * Use urlNavigator() instead when not accessing the history.
113 const DolphinUrlNavigator
*urlNavigatorInternalWithHistory() const;
115 * @return An UrlNavigator that contains this view's history.
116 * Use urlNavigator() instead when not accessing the history.
118 DolphinUrlNavigator
*urlNavigatorInternalWithHistory();
120 const DolphinView
* view() const;
124 * @param urlNavigator The UrlNavigator that is supposed to control
127 void connectUrlNavigator(DolphinUrlNavigator
*urlNavigator
);
130 * Disconnects the navigator that is currently controling the view.
131 * This method completely reverses connectUrlNavigator().
133 void disconnectUrlNavigator();
136 * Shows the message \msg with the given type non-modal above
139 void showMessage(const QString
& msg
, MessageType type
);
142 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
146 /** Returns true, if the filter bar is visible. */
147 bool isFilterBarVisible() const;
150 /** Returns true if the search mode is enabled. */
151 bool isSearchModeEnabled() const;
154 * @return Text that should be used for the current URL when creating
157 QString
placesText() const;
160 * Reload the view of this container. This will also hide messages in a messagewidget.
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().
169 QString
captionWindowTitle() const;
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
176 QString
caption() const;
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()
184 * @see DolphinViewContainer::urlNavigator()
186 void setUrl(const QUrl
& url
);
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.
193 void setFilterBarVisible(bool visible
);
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.
199 void setSearchModeEnabled(bool enabled
);
203 * Is emitted whenever the filter bar has changed its visibility state.
205 void showFilterBarChanged(bool shown
);
207 * Is emitted whenever the search mode has changed its state.
209 void searchModeEnabledChanged(bool enabled
);
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
216 void writeStateChanged(bool isFolderWritable
);
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.
229 void delayedStatusBarUpdate();
232 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
233 * updates the status bar synchronously.
235 void updateStatusBar();
237 void updateDirectoryLoadingProgress(int percent
);
239 void updateDirectorySortingProgress(int percent
);
242 * Updates the statusbar to show an undetermined progress with the correct
243 * context information whether a searching or a directory loading is done.
245 void slotDirectoryLoadingStarted();
248 * Assures that the viewport position is restored and updates the
249 * statusbar to reflect the current content.
251 void slotDirectoryLoadingCompleted();
254 * Updates the statusbar to show, that the directory loading has
257 void slotDirectoryLoadingCanceled();
260 * Is called if the URL set by DolphinView::setUrl() represents
261 * a file and not a directory. Takes care to activate the file.
263 void slotUrlIsFileError(const QUrl
& url
);
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.
270 void slotItemActivated(const KFileItem
& item
);
273 * Handles activation of multiple files. The files get started by
274 * the corresponding applications.
276 void slotItemsActivated(const KFileItemList
& items
);
279 * Shows the information for the item \a item inside the statusbar. If the
280 * item is null, the default statusbar information is shown.
282 void showItemInfo(const KFileItem
& item
);
284 void closeFilterBar();
287 * Filters the currently shown items by \a nameFilter. All items
288 * which contain the given filter string will be shown.
290 void setNameFilter(const QString
& nameFilter
);
293 * Marks the view container as active
294 * (see DolphinViewContainer::setActive()).
299 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
300 * is emitted. Tries to save the view-state.
302 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
& url
);
305 * Restores the current view to show \a url and assures
306 * that the root URL of the view is respected.
308 void slotUrlNavigatorLocationChanged(const QUrl
& url
);
311 * @see KUrlNavigator::urlSelectionRequested
313 void slotUrlSelectionRequested(const QUrl
& url
);
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.
320 void redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
);
322 /** Requests the focus for the view \a m_view. */
326 * Gets the search URL from the searchbox and starts searching.
328 void startSearching();
329 void closeSearchBox();
332 * Stops the loading of a directory. Is connected with the "stopPressed" signal
333 * from the statusbar.
335 void stopDirectoryLoading();
337 void slotStatusBarZoomLevelChanged(int zoomLevel
);
340 * Slot that calls showMessage(msg, Error).
342 void showErrorMessage(const QString
& msg
);
346 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
348 bool isSearchUrl(const QUrl
& url
) const;
351 * Saves the state of the current view: contents position,
354 void saveViewState();
357 * Restores the state of the current view iff the URL navigator contains a
358 * non-empty location state.
360 void tryRestoreViewState();
363 QVBoxLayout
* m_topLayout
;
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.
370 std::unique_ptr
<DolphinUrlNavigator
> m_urlNavigator
;
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.
377 QPointer
<DolphinUrlNavigator
> m_urlNavigatorConnected
;
378 DolphinSearchBox
* m_searchBox
;
379 bool m_searchModeEnabled
;
380 KMessageWidget
* m_messageWidget
;
384 FilterBar
* m_filterBar
;
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
;
391 * The visual state to be applied to the next UrlNavigator that gets
392 * connected to this ViewContainer.
394 std::unique_ptr
<DolphinUrlNavigator::VisualState
> m_urlNavigatorVisualState
;
396 #ifdef HAVE_KACTIVITIES
398 KActivities::ResourceInstance
* m_activityResourceInstance
;
402 #endif // DOLPHINVIEWCONTAINER_H