1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
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 ***************************************************************************/
21 #ifndef DOLPHINVIEWCONTAINER_H
22 #define DOLPHINVIEWCONTAINER_H
24 #include <kfileitem.h>
25 #include <kfileitemdelegate.h>
26 #include <kglobalsettings.h>
29 #include <kurlnavigator.h>
31 #include <QElapsedTimer>
34 #include <views/dolphinview.h>
40 class DolphinDirLister
;
41 class DolphinSearchBox
;
42 class DolphinSortFilterProxyModel
;
43 class DolphinStatusBar
;
46 * @short Represents a view for the directory content
47 * including the navigation bar, filter bar and status bar.
49 * View modes for icons, details and columns are supported. Currently
50 * Dolphin allows to have up to two views inside the main window.
55 * @see DolphinStatusBar
57 class DolphinViewContainer
: public QWidget
62 DolphinViewContainer(const KUrl
& url
, QWidget
* parent
);
63 virtual ~DolphinViewContainer();
66 * Returns the current active URL, where all actions are applied.
67 * The URL navigator is synchronized with this URL.
72 * If \a active is true, the view container will marked as active. The active
73 * view container is defined as view where all actions are applied to.
75 void setActive(bool active
);
76 bool isActive() const;
78 const DolphinStatusBar
* statusBar() const;
79 DolphinStatusBar
* statusBar();
81 const KUrlNavigator
* urlNavigator() const;
82 KUrlNavigator
* urlNavigator();
84 const DolphinView
* view() const;
88 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
92 /** Returns true, if the filter bar is visible. */
93 bool isFilterBarVisible() const;
96 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
97 * will be hidden and replaced by a line editor that allows to enter a search term.
99 void setSearchModeEnabled(bool enabled
);
100 bool isSearchModeEnabled() const;
104 * Sets the current active URL, where all actions are applied. The
105 * URL navigator is synchronized with this URL. The signals
106 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
108 * @see DolphinViewContainer::urlNavigator()
110 void setUrl(const KUrl
& url
);
113 * Popups the filter bar above the status bar if \a visible is true.
115 void setFilterBarVisible(bool visible
);
119 * Is emitted whenever the filter bar has changed its visibility state.
121 void showFilterBarChanged(bool shown
);
124 * Is emitted when the write state of the folder has been changed. The application
125 * should disable all actions like "Create New..." that depend on the write
128 void writeStateChanged(bool isFolderWritable
);
131 * Is emitted if the search mode has been enabled or disabled.
132 * (see DolphinViewContainer::setSearchModeEnabled() and
133 * DolphinViewContainer::isSearchModeEnabled())
135 void searchModeChanged(bool enabled
);
139 * Updates the number of items (= number of files + number of
140 * directories) in the statusbar. If files are selected, the number
141 * of selected files and the sum of the filesize is shown. The update
142 * is done asynchronously, as getting the sum of the
143 * filesizes can be an expensive operation.
145 void delayedStatusBarUpdate();
148 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
149 * updates the status bar synchronously.
151 void updateStatusBar();
153 void initializeProgress();
155 void updateProgress(int percent
);
158 * Assures that the viewport position is restored and updates the
159 * statusbar to reflect the current content.
161 void slotDirListerCompleted();
164 * Handles clicking on an item. If the item is a directory, the
165 * directory is opened in the view. If the item is a file, the file
166 * gets started by the corresponding application.
168 void slotItemTriggered(const KFileItem
& item
);
171 * Opens a the file \a url by opening the corresponding application.
172 * Is connected with the signal urlIsFile() from DolphinDirLister and will
173 * get invoked if the user manually has entered a file into the URL navigator.
175 void openFile(const KUrl
& url
);
178 * Shows the information for the item \a item inside the statusbar. If the
179 * item is null, the default statusbar information is shown.
181 void showItemInfo(const KFileItem
& item
);
183 /** Shows the information \a msg inside the statusbar. */
184 void showInfoMessage(const QString
& msg
);
186 /** Shows the error message \a msg inside the statusbar. */
187 void showErrorMessage(const QString
& msg
);
189 /** Shows the "operation completed" message \a msg inside the statusbar. */
190 void showOperationCompletedMessage(const QString
& msg
);
192 void closeFilterBar();
195 * Filters the currently shown items by \a nameFilter. All items
196 * which contain the given filter string will be shown.
198 void setNameFilter(const QString
& nameFilter
);
201 * Marks the view container as active
202 * (see DolphinViewContainer::setActive()).
207 * Saves the state of the current view: contents position,
210 void saveViewState();
213 * Restores the current view to show \a url and assures
214 * that the root URL of the view is respected.
216 void slotUrlNavigatorLocationChanged(const KUrl
& url
);
219 * Is connected with the URL navigator and drops the URLs
220 * above the destination \a destination.
222 void dropUrls(const KUrl
& destination
, QDropEvent
* event
);
225 * Is invoked when a redirection is done and changes the
226 * URL of the URL navigator to \a newUrl without triggering
227 * a reloading of the directory.
229 void redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
);
231 /** Requests the focus for the view \a m_view. */
235 * Saves the currently used URL completion mode of
238 void saveUrlCompletionMode(KGlobalSettings::Completion completion
);
240 void slotHistoryChanged();
243 * Gets the search URL from the searchbox and starts searching.
244 * @param text Text the user has entered into the searchbox.
246 void startSearching(const QString
& text
);
247 void closeSearchBox();
251 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
253 bool isSearchUrl(const KUrl
& url
) const;
256 bool m_isFolderWritable
;
258 QVBoxLayout
* m_topLayout
;
259 KUrlNavigator
* m_urlNavigator
;
260 DolphinSearchBox
* m_searchBox
;
264 FilterBar
* m_filterBar
;
266 DolphinStatusBar
* m_statusBar
;
267 QTimer
* m_statusBarTimer
; // Triggers a delayed update
268 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
270 DolphinModel
* m_dolphinModel
;
271 DolphinDirLister
* m_dirLister
;
272 DolphinSortFilterProxyModel
* m_proxyModel
;
275 inline const DolphinStatusBar
* DolphinViewContainer::statusBar() const
280 inline DolphinStatusBar
* DolphinViewContainer::statusBar()
285 inline const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
287 return m_urlNavigator
;
290 inline KUrlNavigator
* DolphinViewContainer::urlNavigator()
292 return m_urlNavigator
;
295 inline const DolphinView
* DolphinViewContainer::view() const
300 inline DolphinView
* DolphinViewContainer::view()
305 #endif // DOLPHINVIEWCONTAINER_H