]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Always support a moving animation in case of the details view
[dolphin.git] / src / dolphinviewcontainer.h
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef DOLPHINVIEWCONTAINER_H
21 #define DOLPHINVIEWCONTAINER_H
22
23 #include <KFileItem>
24 #include <KFileItemDelegate>
25 #include <KGlobalSettings>
26 #include <KIO/Job>
27
28 #include <KUrlNavigator>
29
30 #include <QElapsedTimer>
31 #include <QWidget>
32
33 #include <views/dolphinview.h>
34
35 class FilterBar;
36 class KMessageWidget;
37 class KUrl;
38 class KUrlNavigator;
39 class DolphinSearchBox;
40 class DolphinStatusBar;
41
42 /**
43 * @short Represents a view for the directory content
44 * including the navigation bar, filter bar and status bar.
45 *
46 * View modes for icons, compact and details are supported. Currently
47 * Dolphin allows to have up to two views inside the main window.
48 *
49 * @see DolphinView
50 * @see FilterBar
51 * @see KUrlNavigator
52 * @see DolphinStatusBar
53 */
54 class DolphinViewContainer : public QWidget
55 {
56 Q_OBJECT
57
58 public:
59 enum MessageType
60 {
61 Information,
62 Warning,
63 Error
64 };
65
66 DolphinViewContainer(const KUrl& url, QWidget* parent);
67 virtual ~DolphinViewContainer();
68
69 /**
70 * Returns the current active URL, where all actions are applied.
71 * The URL navigator is synchronized with this URL.
72 */
73 KUrl url() const;
74
75 /**
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.
78 */
79 void setActive(bool active);
80 bool isActive() const;
81
82 /**
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.
86 */
87 void setAutoGrabFocus(bool grab);
88 bool autoGrabFocus() const;
89
90 const DolphinStatusBar* statusBar() const;
91 DolphinStatusBar* statusBar();
92
93 const KUrlNavigator* urlNavigator() const;
94 KUrlNavigator* urlNavigator();
95
96 const DolphinView* view() const;
97 DolphinView* view();
98
99 /**
100 * Shows the message \msg with the given type non-modal above
101 * the view-content.
102 */
103 void showMessage(const QString& msg, MessageType type);
104
105 /**
106 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
107 */
108 void readSettings();
109
110 /** Returns true, if the filter bar is visible. */
111 bool isFilterBarVisible() const;
112
113 /**
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.
116 */
117 void setSearchModeEnabled(bool enabled);
118 bool isSearchModeEnabled() const;
119
120 /**
121 * @return Text that should be used for the current URL when creating
122 * a new place.
123 */
124 QString placesText() const;
125
126 public slots:
127 /**
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()
131 * are emitted.
132 * @see DolphinViewContainer::urlNavigator()
133 */
134 void setUrl(const KUrl& url);
135
136 /**
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.
140 */
141 void setFilterBarVisible(bool visible);
142
143 signals:
144 /**
145 * Is emitted whenever the filter bar has changed its visibility state.
146 */
147 void showFilterBarChanged(bool shown);
148
149 /**
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
152 * state.
153 */
154 void writeStateChanged(bool isFolderWritable);
155
156 private slots:
157 /**
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.
166 */
167 void delayedStatusBarUpdate();
168
169 /**
170 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
171 * updates the status bar synchronously.
172 */
173 void updateStatusBar();
174
175 void updateDirectoryLoadingProgress(int percent);
176
177 void updateDirectorySortingProgress(int percent);
178
179 /**
180 * Updates the statusbar to show an undetermined progress with the correct
181 * context information whether a searching or a directory loading is done.
182 */
183 void slotDirectoryLoadingStarted();
184
185 /**
186 * Assures that the viewport position is restored and updates the
187 * statusbar to reflect the current content.
188 */
189 void slotDirectoryLoadingCompleted();
190
191 /**
192 * Handles clicking on an item. If the item is a directory, the
193 * directory is opened in the view. If the item is a file, the file
194 * gets started by the corresponding application.
195 */
196 void slotItemActivated(const KFileItem& item);
197
198 /**
199 * Shows the information for the item \a item inside the statusbar. If the
200 * item is null, the default statusbar information is shown.
201 */
202 void showItemInfo(const KFileItem& item);
203
204 void closeFilterBar();
205
206 /**
207 * Filters the currently shown items by \a nameFilter. All items
208 * which contain the given filter string will be shown.
209 */
210 void setNameFilter(const QString& nameFilter);
211
212 /**
213 * Marks the view container as active
214 * (see DolphinViewContainer::setActive()).
215 */
216 void activate();
217
218 /**
219 * Is invoked if the signal urlAboutToBeChanged() from the DolphinView
220 * is emitted. Tries to save the view-state.
221 */
222 void slotViewUrlAboutToBeChanged(const KUrl& url);
223
224 /**
225 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
226 * is emitted. Tries to save the view-state.
227 */
228 void slotUrlNavigatorLocationAboutToBeChanged(const KUrl& url);
229
230 /**
231 * Restores the current view to show \a url and assures
232 * that the root URL of the view is respected.
233 */
234 void slotUrlNavigatorLocationChanged(const KUrl& url);
235
236 /**
237 * Is connected with the URL navigator and drops the URLs
238 * above the destination \a destination.
239 */
240 void dropUrls(const KUrl& destination, QDropEvent* event);
241
242 /**
243 * Is invoked when a redirection is done and changes the
244 * URL of the URL navigator to \a newUrl without triggering
245 * a reloading of the directory.
246 */
247 void redirect(const KUrl& oldUrl, const KUrl& newUrl);
248
249 /** Requests the focus for the view \a m_view. */
250 void requestFocus();
251
252 /**
253 * Saves the currently used URL completion mode of
254 * the URL navigator.
255 */
256 void saveUrlCompletionMode(KGlobalSettings::Completion completion);
257
258 void slotHistoryChanged();
259
260 /**
261 * Gets the search URL from the searchbox and starts searching.
262 */
263 void startSearching();
264 void closeSearchBox();
265
266 /**
267 * Stops the loading of a directory. Is connected with the "stopPressed" signal
268 * from the statusbar.
269 */
270 void stopDirectoryLoading();
271
272 void slotStatusBarZoomLevelChanged(int zoomLevel);
273
274 /**
275 * Slot that calls showMessage(msg, Error).
276 */
277 void showErrorMessage(const QString& msg);
278
279 private:
280 /**
281 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
282 */
283 bool isSearchUrl(const KUrl& url) const;
284
285 /**
286 * Saves the state of the current view: contents position,
287 * root URL, ...
288 */
289 void saveViewState();
290
291 private:
292 QVBoxLayout* m_topLayout;
293 KUrlNavigator* m_urlNavigator;
294 DolphinSearchBox* m_searchBox;
295 KMessageWidget* m_messageWidget;
296
297 DolphinView* m_view;
298
299 FilterBar* m_filterBar;
300
301 DolphinStatusBar* m_statusBar;
302 QTimer* m_statusBarTimer; // Triggers a delayed update
303 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
304 bool m_autoGrabFocus;
305 };
306
307 #endif // DOLPHINVIEWCONTAINER_H