]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
KFileItemModel: interface cleanups
[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 KUrl;
37 class KUrlNavigator;
38 class DolphinSearchBox;
39 class DolphinStatusBar;
40
41 /**
42 * @short Represents a view for the directory content
43 * including the navigation bar, filter bar and status bar.
44 *
45 * View modes for icons, compact and details are supported. Currently
46 * Dolphin allows to have up to two views inside the main window.
47 *
48 * @see DolphinView
49 * @see FilterBar
50 * @see KUrlNavigator
51 * @see DolphinStatusBar
52 */
53 class DolphinViewContainer : public QWidget
54 {
55 Q_OBJECT
56
57 public:
58 DolphinViewContainer(const KUrl& url, QWidget* parent);
59 virtual ~DolphinViewContainer();
60
61 /**
62 * Returns the current active URL, where all actions are applied.
63 * The URL navigator is synchronized with this URL.
64 */
65 KUrl url() const;
66
67 /**
68 * If \a active is true, the view container will marked as active. The active
69 * view container is defined as view where all actions are applied to.
70 */
71 void setActive(bool active);
72 bool isActive() const;
73
74 const DolphinStatusBar* statusBar() const;
75 DolphinStatusBar* statusBar();
76
77 const KUrlNavigator* urlNavigator() const;
78 KUrlNavigator* urlNavigator();
79
80 const DolphinView* view() const;
81 DolphinView* view();
82
83 const DolphinSearchBox* searchBox() const;
84 DolphinSearchBox* searchBox();
85
86 /**
87 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
88 */
89 void readSettings();
90
91 /** Returns true, if the filter bar is visible. */
92 bool isFilterBarVisible() const;
93
94 /**
95 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
96 * will be hidden and replaced by a line editor that allows to enter a search term.
97 */
98 void setSearchModeEnabled(bool enabled);
99 bool isSearchModeEnabled() const;
100
101 public slots:
102 /**
103 * Sets the current active URL, where all actions are applied. The
104 * URL navigator is synchronized with this URL. The signals
105 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
106 * are emitted.
107 * @see DolphinViewContainer::urlNavigator()
108 */
109 void setUrl(const KUrl& url);
110
111 /**
112 * Popups the filter bar above the status bar if \a visible is true.
113 * It \a visible is true, it is assured that the filter bar gains
114 * the keyboard focus.
115 */
116 void setFilterBarVisible(bool visible);
117
118 signals:
119 /**
120 * Is emitted whenever the filter bar has changed its visibility state.
121 */
122 void showFilterBarChanged(bool shown);
123
124 /**
125 * Is emitted when the write state of the folder has been changed. The application
126 * should disable all actions like "Create New..." that depend on the write
127 * state.
128 */
129 void writeStateChanged(bool isFolderWritable);
130
131 /**
132 * Is emitted if the search mode has been enabled or disabled.
133 * (see DolphinViewContainer::setSearchModeEnabled() and
134 * DolphinViewContainer::isSearchModeEnabled())
135 */
136 void searchModeChanged(bool enabled);
137
138 private slots:
139 /**
140 * Updates the number of items (= number of files + number of
141 * directories) in the statusbar. If files are selected, the number
142 * of selected files and the sum of the filesize is shown. The update
143 * is done asynchronously, as getting the sum of the
144 * filesizes can be an expensive operation.
145 * Unless a previous OperationCompletedMessage was set very shortly before
146 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
147 * Previous ErrorMessages however are always preserved.
148 */
149 void delayedStatusBarUpdate();
150
151 /**
152 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
153 * updates the status bar synchronously.
154 */
155 void updateStatusBar();
156
157 void updateDirectoryLoadingProgress(int percent);
158
159 void updateDirectorySortingProgress(int percent);
160
161 /**
162 * Updates the statusbar to show an undetermined progress with the correct
163 * context information whether a searching or a directory loading is done.
164 */
165 void slotDirectoryLoadingStarted();
166
167 /**
168 * Assures that the viewport position is restored and updates the
169 * statusbar to reflect the current content.
170 */
171 void slotDirectoryLoadingCompleted();
172
173 /**
174 * Handles clicking on an item. If the item is a directory, the
175 * directory is opened in the view. If the item is a file, the file
176 * gets started by the corresponding application.
177 */
178 void slotItemActivated(const KFileItem& item);
179
180 /**
181 * Shows the information for the item \a item inside the statusbar. If the
182 * item is null, the default statusbar information is shown.
183 */
184 void showItemInfo(const KFileItem& item);
185
186 /** Shows the information \a msg inside the statusbar. */
187 void showInfoMessage(const QString& msg);
188
189 /** Shows the error message \a msg inside the statusbar. */
190 void showErrorMessage(const QString& msg);
191
192 /** Shows the "operation completed" message \a msg inside the statusbar. */
193 void showOperationCompletedMessage(const QString& msg);
194
195 void closeFilterBar();
196
197 /**
198 * Filters the currently shown items by \a nameFilter. All items
199 * which contain the given filter string will be shown.
200 */
201 void setNameFilter(const QString& nameFilter);
202
203 /**
204 * Marks the view container as active
205 * (see DolphinViewContainer::setActive()).
206 */
207 void activate();
208
209 /**
210 * Is invoked if the signal urlAboutToBeChanged() from the DolphinView
211 * is emitted. Tries to save the view-state.
212 */
213 void slotViewUrlAboutToBeChanged(const KUrl& url);
214
215 /**
216 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
217 * is emitted. Tries to save the view-state.
218 */
219 void slotUrlNavigatorLocationAboutToBeChanged(const KUrl& url);
220
221 /**
222 * Restores the current view to show \a url and assures
223 * that the root URL of the view is respected.
224 */
225 void slotUrlNavigatorLocationChanged(const KUrl& url);
226
227 /**
228 * Is connected with the URL navigator and drops the URLs
229 * above the destination \a destination.
230 */
231 void dropUrls(const KUrl& destination, QDropEvent* event);
232
233 /**
234 * Is invoked when a redirection is done and changes the
235 * URL of the URL navigator to \a newUrl without triggering
236 * a reloading of the directory.
237 */
238 void redirect(const KUrl& oldUrl, const KUrl& newUrl);
239
240 /** Requests the focus for the view \a m_view. */
241 void requestFocus();
242
243 /**
244 * Saves the currently used URL completion mode of
245 * the URL navigator.
246 */
247 void saveUrlCompletionMode(KGlobalSettings::Completion completion);
248
249 void slotHistoryChanged();
250
251 /**
252 * Gets the search URL from the searchbox and starts searching.
253 * @param text Text the user has entered into the searchbox.
254 */
255 void startSearching(const QString& text);
256 void closeSearchBox();
257
258 /**
259 * Stops the loading of a directory. Is connected with the "stopPressed" signal
260 * from the statusbar.
261 */
262 void stopLoading();
263
264 private:
265 /**
266 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
267 */
268 bool isSearchUrl(const KUrl& url) const;
269
270 /**
271 * Saves the state of the current view: contents position,
272 * root URL, ...
273 */
274 void saveViewState();
275
276 private:
277 QVBoxLayout* m_topLayout;
278 KUrlNavigator* m_urlNavigator;
279 DolphinSearchBox* m_searchBox;
280
281 DolphinView* m_view;
282
283 FilterBar* m_filterBar;
284
285 DolphinStatusBar* m_statusBar;
286 QTimer* m_statusBarTimer; // Triggers a delayed update
287 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
288 };
289
290 #endif // DOLPHINVIEWCONTAINER_H