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