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
24 #include <KCompletion>
27 #include <KUrlNavigator>
29 #include <QElapsedTimer>
32 #include <views/dolphinview.h>
33 #include <config-dolphin.h>
35 #ifdef KF5Activities_FOUND
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 virtual ~DolphinViewContainer();
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 const DolphinStatusBar
* statusBar() const;
97 DolphinStatusBar
* statusBar();
99 const KUrlNavigator
* urlNavigator() const;
100 KUrlNavigator
* urlNavigator();
102 const DolphinView
* view() const;
106 * Shows the message \msg with the given type non-modal above
109 void showMessage(const QString
& msg
, MessageType type
);
112 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
116 /** Returns true, if the filter bar is visible. */
117 bool isFilterBarVisible() const;
120 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
121 * will be hidden and replaced by a line editor that allows to enter a search term.
123 void setSearchModeEnabled(bool enabled
);
124 bool isSearchModeEnabled() const;
127 * @return Text that should be used for the current URL when creating
130 QString
placesText() const;
134 * Sets the current active URL, where all actions are applied. The
135 * URL navigator is synchronized with this URL. The signals
136 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
138 * @see DolphinViewContainer::urlNavigator()
140 void setUrl(const QUrl
& url
);
143 * Popups the filter bar above the status bar if \a visible is true.
144 * It \a visible is true, it is assured that the filter bar gains
145 * the keyboard focus.
147 void setFilterBarVisible(bool visible
);
151 * Is emitted whenever the filter bar has changed its visibility state.
153 void showFilterBarChanged(bool shown
);
156 * Is emitted when the write state of the folder has been changed. The application
157 * should disable all actions like "Create New..." that depend on the write
160 void writeStateChanged(bool isFolderWritable
);
164 * Updates the number of items (= number of files + number of
165 * directories) in the statusbar. If files are selected, the number
166 * of selected files and the sum of the filesize is shown. The update
167 * is done asynchronously, as getting the sum of the
168 * filesizes can be an expensive operation.
169 * Unless a previous OperationCompletedMessage was set very shortly before
170 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
171 * Previous ErrorMessages however are always preserved.
173 void delayedStatusBarUpdate();
176 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
177 * updates the status bar synchronously.
179 void updateStatusBar();
181 void updateDirectoryLoadingProgress(int percent
);
183 void updateDirectorySortingProgress(int percent
);
186 * Updates the statusbar to show an undetermined progress with the correct
187 * context information whether a searching or a directory loading is done.
189 void slotDirectoryLoadingStarted();
192 * Assures that the viewport position is restored and updates the
193 * statusbar to reflect the current content.
195 void slotDirectoryLoadingCompleted();
198 * Updates the statusbar to show, that the directory loading has
201 void slotDirectoryLoadingCanceled();
204 * Is called if the URL set by DolphinView::setUrl() represents
205 * a file and not a directory. Takes care to activate the file.
207 void slotUrlIsFileError(const QUrl
& url
);
210 * Handles clicking on an item. If the item is a directory, the
211 * directory is opened in the view. If the item is a file, the file
212 * gets started by the corresponding application.
214 void slotItemActivated(const KFileItem
& item
);
217 * Handles activation of multiple files. The files get started by
218 * the corresponding applications.
220 void slotItemsActivated(const KFileItemList
& items
);
223 * Shows the information for the item \a item inside the statusbar. If the
224 * item is null, the default statusbar information is shown.
226 void showItemInfo(const KFileItem
& item
);
228 void closeFilterBar();
231 * Filters the currently shown items by \a nameFilter. All items
232 * which contain the given filter string will be shown.
234 void setNameFilter(const QString
& nameFilter
);
237 * Marks the view container as active
238 * (see DolphinViewContainer::setActive()).
243 * Is invoked if the signal urlAboutToBeChanged() from the DolphinView
244 * is emitted. Tries to save the view-state.
246 void slotViewUrlAboutToBeChanged(const QUrl
& url
);
249 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
250 * is emitted. Tries to save the view-state.
252 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl
& url
);
255 * Restores the current view to show \a url and assures
256 * that the root URL of the view is respected.
258 void slotUrlNavigatorLocationChanged(const QUrl
& url
);
261 * Is invoked when a redirection is done and changes the
262 * URL of the URL navigator to \a newUrl without triggering
263 * a reloading of the directory.
265 void redirect(const QUrl
& oldUrl
, const QUrl
& newUrl
);
267 /** Requests the focus for the view \a m_view. */
271 * Saves the currently used URL completion mode of
274 void saveUrlCompletionMode(KCompletion::CompletionMode completion
);
276 void slotHistoryChanged();
278 void slotReturnPressed();
281 * Gets the search URL from the searchbox and starts searching.
283 void startSearching();
284 void closeSearchBox();
287 * Stops the loading of a directory. Is connected with the "stopPressed" signal
288 * from the statusbar.
290 void stopDirectoryLoading();
292 void slotStatusBarZoomLevelChanged(int zoomLevel
);
295 * Slot that calls showMessage(msg, Error).
297 void showErrorMessage(const QString
& msg
);
301 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
303 bool isSearchUrl(const QUrl
& url
) const;
306 * Saves the state of the current view: contents position,
309 void saveViewState();
312 QVBoxLayout
* m_topLayout
;
313 KUrlNavigator
* m_urlNavigator
;
314 DolphinSearchBox
* m_searchBox
;
315 KMessageWidget
* m_messageWidget
;
319 FilterBar
* m_filterBar
;
321 DolphinStatusBar
* m_statusBar
;
322 QTimer
* m_statusBarTimer
; // Triggers a delayed update
323 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
324 bool m_autoGrabFocus
;
326 #ifdef KF5Activities_FOUND
328 KActivities::ResourceInstance
* m_activityResourceInstance
;
332 #endif // DOLPHINVIEWCONTAINER_H