1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef DOLPHINVIEWCONTAINER_H
21 #define DOLPHINVIEWCONTAINER_H
23 #include "config-kactivities.h"
24 #include "views/dolphinview.h"
26 #include <KCompletion>
29 #include <KUrlNavigator>
31 #include <QElapsedTimer>
32 #include <QPushButton>
35 #ifdef HAVE_KACTIVITIES
36 namespace KActivities
{
37 class ResourceInstance
;
45 class DolphinSearchBox
;
46 class DolphinStatusBar
;
49 * @short Represents a view for the directory content
50 * including the navigation bar, filter bar and status bar.
52 * View modes for icons, compact and details are supported. Currently
53 * Dolphin allows to have up to two views inside the main window.
58 * @see DolphinStatusBar
60 class DolphinViewContainer
: public QWidget
72 DolphinViewContainer(const QUrl
& url
, QWidget
* parent
);
73 ~DolphinViewContainer() override
;
76 * Returns the current active URL, where all actions are applied.
77 * The URL navigator is synchronized with this URL.
82 * If \a active is true, the view container will marked as active. The active
83 * view container is defined as view where all actions are applied to.
85 void setActive(bool active
);
86 bool isActive() const;
89 * If \a grab is set to true, the container automatically grabs the focus
90 * as soon as the URL has been changed. Per default the grabbing
91 * of the focus is enabled.
93 void setAutoGrabFocus(bool grab
);
94 bool autoGrabFocus() const;
96 QString
currentSearchText() const;
98 const DolphinStatusBar
* statusBar() const;
99 DolphinStatusBar
* statusBar();
101 const KUrlNavigator
* urlNavigator() const;
102 KUrlNavigator
* urlNavigator();
104 const DolphinView
* view() const;
108 * Shows the message \msg with the given type non-modal above
111 void showMessage(const QString
& msg
, MessageType type
);
114 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
118 /** Returns true, if the filter bar is visible. */
119 bool isFilterBarVisible() const;
122 /** Returns true if the search mode is enabled. */
123 bool isSearchModeEnabled() const;
126 * @return Text that should be used for the current URL when creating
129 QString
placesText() const;
132 * Reload the view of this container. This will also hide messages in a messagewidget.
137 * @return Returns a Caption suitable for display to the user. It is
138 * calculated depending on settings, if a search is active and other
141 QString
caption() const;
145 * Sets the current active URL, where all actions are applied. The
146 * URL navigator is synchronized with this URL. The signals
147 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
149 * @see DolphinViewContainer::urlNavigator()
151 void setUrl(const QUrl
& url
);
154 * Popups the filter bar above the status bar if \a visible is true.
155 * It \a visible is true, it is assured that the filter bar gains
156 * the keyboard focus.
158 void setFilterBarVisible(bool visible
);
161 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
162 * will be hidden and replaced by a line editor that allows to enter a search term.
164 void setSearchModeEnabled(bool enabled
);
168 * Is emitted whenever the filter bar has changed its visibility state.
170 void showFilterBarChanged(bool shown
);
172 * Is emitted whenever the search mode has changed its state.
174 void searchModeEnabledChanged(bool enabled
);
177 * Is emitted when the write state of the folder has been changed. The application
178 * should disable all actions like "Create New..." that depend on the write
181 void writeStateChanged(bool isFolderWritable
);
185 * Updates the number of items (= number of files + number of
186 * directories) in the statusbar. If files are selected, the number
187 * of selected files and the sum of the filesize is shown. The update
188 * is done asynchronously, as getting the sum of the
189 * filesizes can be an expensive operation.
190 * Unless a previous OperationCompletedMessage was set very shortly before
191 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
192 * Previous ErrorMessages however are always preserved.
194 void delayedStatusBarUpdate();
197 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
198 * updates the status bar synchronously.
200 void updateStatusBar();
202 void updateDirectoryLoadingProgress(int percent
);
204 void updateDirectorySortingProgress(int percent
);
207 * Updates the statusbar to show an undetermined progress with the correct
208 * context information whether a searching or a directory loading is done.
210 void slotDirectoryLoadingStarted();
213 * Assures that the viewport position is restored and updates the
214 * statusbar to reflect the current content.
216 void slotDirectoryLoadingCompleted();
219 * Updates the statusbar to show, that the directory loading has
222 void slotDirectoryLoadingCanceled();
225 * Is called if the URL set by DolphinView::setUrl() represents
226 * a file and not a directory. Takes care to activate the file.
228 void slotUrlIsFileError(const QUrl
& url
);
231 * Handles clicking on an item. If the item is a directory, the
232 * directory is opened in the view. If the item is a file, the file
233 * gets started by the corresponding application.
235 void slotItemActivated(const KFileItem
& item
);
238 * Handles activation of multiple files. The files get started by
239 * the corresponding applications.
241 void slotItemsActivated(const KFileItemList
& items
);
244 * Shows the information for the item \a item inside the statusbar. If the
245 * item is null, the default statusbar information is shown.
247 void showItemInfo(const KFileItem
& item
);
249 void closeFilterBar();
252 * Filters the currently shown items by \a nameFilter. All items
253 * which contain the given filter string will be shown.
255 void setNameFilter(const QString
& nameFilter
);
258 * Marks the view container as active
259 * (see DolphinViewContainer::setActive()).
264 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
265 * is emitted. Tries to save the view-state.
267 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
& url
);
270 * Restores the current view to show \a url and assures
271 * that the root URL of the view is respected.
273 void slotUrlNavigatorLocationChanged(const QUrl
& url
);
276 * @see KUrlNavigator::urlSelectionRequested
278 void slotUrlSelectionRequested(const QUrl
& url
);
281 * Is invoked when a redirection is done and changes the
282 * URL of the URL navigator to \a newUrl without triggering
283 * a reloading of the directory.
285 void redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
);
287 /** Requests the focus for the view \a m_view. */
291 * Saves the currently used URL completion mode of
294 void saveUrlCompletionMode(KCompletion::CompletionMode completion
);
296 void slotReturnPressed();
299 * Gets the search URL from the searchbox and starts searching.
301 void startSearching();
302 void closeSearchBox();
305 * Stops the loading of a directory. Is connected with the "stopPressed" signal
306 * from the statusbar.
308 void stopDirectoryLoading();
310 void slotStatusBarZoomLevelChanged(int zoomLevel
);
313 * Slot that calls showMessage(msg, Error).
315 void showErrorMessage(const QString
& msg
);
319 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
321 bool isSearchUrl(const QUrl
& url
) const;
324 * Saves the state of the current view: contents position,
327 void saveViewState();
330 * Restores the state of the current view iff the URL navigator contains a
331 * non-empty location state.
333 void tryRestoreViewState();
336 QVBoxLayout
* m_topLayout
;
337 QWidget
* m_navigatorWidget
;
338 KUrlNavigator
* m_urlNavigator
;
339 QPushButton
* m_emptyTrashButton
;
340 DolphinSearchBox
* m_searchBox
;
341 bool m_searchModeEnabled
;
342 KMessageWidget
* m_messageWidget
;
346 FilterBar
* m_filterBar
;
348 DolphinStatusBar
* m_statusBar
;
349 QTimer
* m_statusBarTimer
; // Triggers a delayed update
350 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
351 bool m_autoGrabFocus
;
353 #ifdef HAVE_KACTIVITIES
355 KActivities::ResourceInstance
* m_activityResourceInstance
;
359 #endif // DOLPHINVIEWCONTAINER_H