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 <KFileItemDelegate>
25 #include <KGlobalSettings>
28 #include <KUrlNavigator>
30 #include <QElapsedTimer>
33 #include <views/dolphinview.h>
39 class DolphinSearchBox
;
40 class DolphinStatusBar
;
43 * @short Represents a view for the directory content
44 * including the navigation bar, filter bar and status bar.
46 * View modes for icons, compact and details are supported. Currently
47 * Dolphin allows to have up to two views inside the main window.
52 * @see DolphinStatusBar
54 class DolphinViewContainer
: public QWidget
66 DolphinViewContainer(const KUrl
& url
, QWidget
* parent
);
67 virtual ~DolphinViewContainer();
70 * Returns the current active URL, where all actions are applied.
71 * The URL navigator is synchronized with this URL.
76 * If \a active is true, the view container will marked as active. The active
77 * view container is defined as view where all actions are applied to.
79 void setActive(bool active
);
80 bool isActive() const;
83 * If \a grab is set to true, the container automatically grabs the focus
84 * as soon as the URL has been changed. Per default the grabbing
85 * of the focus is enabled.
87 void setAutoGrabFocus(bool grab
);
88 bool autoGrabFocus() const;
90 const DolphinStatusBar
* statusBar() const;
91 DolphinStatusBar
* statusBar();
93 const KUrlNavigator
* urlNavigator() const;
94 KUrlNavigator
* urlNavigator();
96 const DolphinView
* view() const;
100 * Shows the message \msg with the given type non-modal above
103 void showMessage(const QString
& msg
, MessageType type
);
106 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
110 /** Returns true, if the filter bar is visible. */
111 bool isFilterBarVisible() const;
114 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
115 * will be hidden and replaced by a line editor that allows to enter a search term.
117 void setSearchModeEnabled(bool enabled
);
118 bool isSearchModeEnabled() const;
121 * @return Text that should be used for the current URL when creating
124 QString
placesText() const;
128 * Sets the current active URL, where all actions are applied. The
129 * URL navigator is synchronized with this URL. The signals
130 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
132 * @see DolphinViewContainer::urlNavigator()
134 void setUrl(const KUrl
& url
);
137 * Popups the filter bar above the status bar if \a visible is true.
138 * It \a visible is true, it is assured that the filter bar gains
139 * the keyboard focus.
141 void setFilterBarVisible(bool visible
);
145 * Is emitted whenever the filter bar has changed its visibility state.
147 void showFilterBarChanged(bool shown
);
150 * Is emitted when the write state of the folder has been changed. The application
151 * should disable all actions like "Create New..." that depend on the write
154 void writeStateChanged(bool isFolderWritable
);
158 * Updates the number of items (= number of files + number of
159 * directories) in the statusbar. If files are selected, the number
160 * of selected files and the sum of the filesize is shown. The update
161 * is done asynchronously, as getting the sum of the
162 * filesizes can be an expensive operation.
163 * Unless a previous OperationCompletedMessage was set very shortly before
164 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
165 * Previous ErrorMessages however are always preserved.
167 void delayedStatusBarUpdate();
170 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
171 * updates the status bar synchronously.
173 void updateStatusBar();
175 void updateDirectoryLoadingProgress(int percent
);
177 void updateDirectorySortingProgress(int percent
);
180 * Updates the statusbar to show an undetermined progress with the correct
181 * context information whether a searching or a directory loading is done.
183 void slotDirectoryLoadingStarted();
186 * Assures that the viewport position is restored and updates the
187 * statusbar to reflect the current content.
189 void slotDirectoryLoadingCompleted();
192 * Is called if the URL set by DolphinView::setUrl() represents
193 * a file and not a directory. Takes care to activate the file.
195 void slotUrlIsFileError(const KUrl
& url
);
198 * Handles clicking on an item. If the item is a directory, the
199 * directory is opened in the view. If the item is a file, the file
200 * gets started by the corresponding application.
202 void slotItemActivated(const KFileItem
& item
);
205 * Shows the information for the item \a item inside the statusbar. If the
206 * item is null, the default statusbar information is shown.
208 void showItemInfo(const KFileItem
& item
);
210 void closeFilterBar();
213 * Filters the currently shown items by \a nameFilter. All items
214 * which contain the given filter string will be shown.
216 void setNameFilter(const QString
& nameFilter
);
219 * Marks the view container as active
220 * (see DolphinViewContainer::setActive()).
225 * Is invoked if the signal urlAboutToBeChanged() from the DolphinView
226 * is emitted. Tries to save the view-state.
228 void slotViewUrlAboutToBeChanged(const KUrl
& url
);
231 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
232 * is emitted. Tries to save the view-state.
234 void slotUrlNavigatorLocationAboutToBeChanged(const KUrl
& url
);
237 * Restores the current view to show \a url and assures
238 * that the root URL of the view is respected.
240 void slotUrlNavigatorLocationChanged(const KUrl
& url
);
243 * Is connected with the URL navigator and drops the URLs
244 * above the destination \a destination.
246 void dropUrls(const KUrl
& destination
, QDropEvent
* event
);
249 * Is invoked when a redirection is done and changes the
250 * URL of the URL navigator to \a newUrl without triggering
251 * a reloading of the directory.
253 void redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
);
255 /** Requests the focus for the view \a m_view. */
259 * Saves the currently used URL completion mode of
262 void saveUrlCompletionMode(KGlobalSettings::Completion completion
);
264 void slotHistoryChanged();
267 * Gets the search URL from the searchbox and starts searching.
269 void startSearching();
270 void closeSearchBox();
273 * Stops the loading of a directory. Is connected with the "stopPressed" signal
274 * from the statusbar.
276 void stopDirectoryLoading();
278 void slotStatusBarZoomLevelChanged(int zoomLevel
);
281 * Slot that calls showMessage(msg, Error).
283 void showErrorMessage(const QString
& msg
);
287 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
289 bool isSearchUrl(const KUrl
& url
) const;
292 * Saves the state of the current view: contents position,
295 void saveViewState();
298 QVBoxLayout
* m_topLayout
;
299 KUrlNavigator
* m_urlNavigator
;
300 DolphinSearchBox
* m_searchBox
;
301 KMessageWidget
* m_messageWidget
;
305 FilterBar
* m_filterBar
;
307 DolphinStatusBar
* m_statusBar
;
308 QTimer
* m_statusBarTimer
; // Triggers a delayed update
309 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
310 bool m_autoGrabFocus
;
313 #endif // DOLPHINVIEWCONTAINER_H