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 "views/dolphinview.h"
13 #include <KCompletion>
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();
88 const KUrlNavigator
* urlNavigator() const;
89 KUrlNavigator
* urlNavigator();
91 const DolphinView
* view() const;
95 * Shows the message \msg with the given type non-modal above
98 void showMessage(const QString
& msg
, MessageType type
);
101 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
105 /** Returns true, if the filter bar is visible. */
106 bool isFilterBarVisible() const;
109 /** Returns true if the search mode is enabled. */
110 bool isSearchModeEnabled() const;
113 * @return Text that should be used for the current URL when creating
116 QString
placesText() const;
119 * Reload the view of this container. This will also hide messages in a messagewidget.
124 * @return Returns a Caption suitable for display in the window title.
125 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
126 * If it's false, it calls caption().
128 QString
captionWindowTitle() const;
131 * @return Returns a Caption suitable for display to the user. It is
132 * calculated depending on settings, if a search is active and other
135 QString
caption() const;
139 * Sets the current active URL, where all actions are applied. The
140 * URL navigator is synchronized with this URL. The signals
141 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
143 * @see DolphinViewContainer::urlNavigator()
145 void setUrl(const QUrl
& url
);
148 * Popups the filter bar above the status bar if \a visible is true.
149 * It \a visible is true, it is assured that the filter bar gains
150 * the keyboard focus.
152 void setFilterBarVisible(bool visible
);
155 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
156 * will be hidden and replaced by a line editor that allows to enter a search term.
158 void setSearchModeEnabled(bool enabled
);
162 * Is emitted whenever the filter bar has changed its visibility state.
164 void showFilterBarChanged(bool shown
);
166 * Is emitted whenever the search mode has changed its state.
168 void searchModeEnabledChanged(bool enabled
);
171 * Is emitted when the write state of the folder has been changed. The application
172 * should disable all actions like "Create New..." that depend on the write
175 void writeStateChanged(bool isFolderWritable
);
179 * Updates the number of items (= number of files + number of
180 * directories) in the statusbar. If files are selected, the number
181 * of selected files and the sum of the filesize is shown. The update
182 * is done asynchronously, as getting the sum of the
183 * filesizes can be an expensive operation.
184 * Unless a previous OperationCompletedMessage was set very shortly before
185 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
186 * Previous ErrorMessages however are always preserved.
188 void delayedStatusBarUpdate();
191 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
192 * updates the status bar synchronously.
194 void updateStatusBar();
196 void updateDirectoryLoadingProgress(int percent
);
198 void updateDirectorySortingProgress(int percent
);
201 * Updates the statusbar to show an undetermined progress with the correct
202 * context information whether a searching or a directory loading is done.
204 void slotDirectoryLoadingStarted();
207 * Assures that the viewport position is restored and updates the
208 * statusbar to reflect the current content.
210 void slotDirectoryLoadingCompleted();
213 * Updates the statusbar to show, that the directory loading has
216 void slotDirectoryLoadingCanceled();
219 * Is called if the URL set by DolphinView::setUrl() represents
220 * a file and not a directory. Takes care to activate the file.
222 void slotUrlIsFileError(const QUrl
& url
);
225 * Handles clicking on an item. If the item is a directory, the
226 * directory is opened in the view. If the item is a file, the file
227 * gets started by the corresponding application.
229 void slotItemActivated(const KFileItem
& item
);
232 * Handles activation of multiple files. The files get started by
233 * the corresponding applications.
235 void slotItemsActivated(const KFileItemList
& items
);
238 * Shows the information for the item \a item inside the statusbar. If the
239 * item is null, the default statusbar information is shown.
241 void showItemInfo(const KFileItem
& item
);
243 void closeFilterBar();
246 * Filters the currently shown items by \a nameFilter. All items
247 * which contain the given filter string will be shown.
249 void setNameFilter(const QString
& nameFilter
);
252 * Marks the view container as active
253 * (see DolphinViewContainer::setActive()).
258 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
259 * is emitted. Tries to save the view-state.
261 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
& url
);
264 * Restores the current view to show \a url and assures
265 * that the root URL of the view is respected.
267 void slotUrlNavigatorLocationChanged(const QUrl
& url
);
270 * @see KUrlNavigator::urlSelectionRequested
272 void slotUrlSelectionRequested(const QUrl
& url
);
275 * Is invoked when a redirection is done and changes the
276 * URL of the URL navigator to \a newUrl without triggering
277 * a reloading of the directory.
279 void redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
);
281 /** Requests the focus for the view \a m_view. */
285 * Saves the currently used URL completion mode of
288 void saveUrlCompletionMode(KCompletion::CompletionMode completion
);
290 void slotReturnPressed();
293 * Gets the search URL from the searchbox and starts searching.
295 void startSearching();
296 void closeSearchBox();
299 * Stops the loading of a directory. Is connected with the "stopPressed" signal
300 * from the statusbar.
302 void stopDirectoryLoading();
304 void slotStatusBarZoomLevelChanged(int zoomLevel
);
307 * Slot that calls showMessage(msg, Error).
309 void showErrorMessage(const QString
& msg
);
313 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
315 bool isSearchUrl(const QUrl
& url
) const;
318 * Saves the state of the current view: contents position,
321 void saveViewState();
324 * Restores the state of the current view iff the URL navigator contains a
325 * non-empty location state.
327 void tryRestoreViewState();
330 QVBoxLayout
* m_topLayout
;
331 QWidget
* m_navigatorWidget
;
332 KUrlNavigator
* m_urlNavigator
;
333 QPushButton
* m_emptyTrashButton
;
334 DolphinSearchBox
* m_searchBox
;
335 bool m_searchModeEnabled
;
336 KMessageWidget
* m_messageWidget
;
340 FilterBar
* m_filterBar
;
342 DolphinStatusBar
* m_statusBar
;
343 QTimer
* m_statusBarTimer
; // Triggers a delayed update
344 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
345 bool m_autoGrabFocus
;
347 #ifdef HAVE_KACTIVITIES
349 KActivities::ResourceInstance
* m_activityResourceInstance
;
353 #endif // DOLPHINVIEWCONTAINER_H