]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Fixed performance issues related to selections and deleting of files:
[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 "dolphinview.h"
25
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
28 #include <kglobalsettings.h>
29 #include <kio/job.h>
30
31 #include <kurlnavigator.h>
32
33 #include <QtGui/QKeyEvent>
34 #include <QtCore/QLinkedList>
35 #include <QtGui/QListView>
36 #include <QtGui/QBoxLayout>
37 #include <QtGui/QWidget>
38
39 class FilterBar;
40 class KUrl;
41 class DolphinModel;
42 class KUrlNavigator;
43 class DolphinDirLister;
44 class DolphinMainWindow;
45 class DolphinSortFilterProxyModel;
46 class DolphinStatusBar;
47 class QModelIndex;
48
49 /**
50 * @short Represents a view for the directory content
51 * including the navigation bar, filter bar and status bar.
52 *
53 * View modes for icons, details and columns are supported. Currently
54 * Dolphin allows to have up to two views inside the main window.
55 *
56 * @see DolphinView
57 * @see FilterBar
58 * @see KUrlNavigator
59 * @see DolphinStatusBar
60 */
61 class DolphinViewContainer : public QWidget
62 {
63 Q_OBJECT
64
65 public:
66 DolphinViewContainer(DolphinMainWindow* mainwindow,
67 QWidget *parent,
68 const KUrl& url);
69
70 virtual ~DolphinViewContainer();
71
72 /**
73 * Sets the current active URL, where all actions are applied. The
74 * URL navigator is synchronized with this URL. The signals
75 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
76 * are emitted.
77 * @see DolphinViewContainer::urlNavigator()
78 */
79 void setUrl(const KUrl& url);
80
81 /**
82 * Returns the current active URL, where all actions are applied.
83 * The URL navigator is synchronized with this URL.
84 */
85 const KUrl& url() const;
86
87 /**
88 * If \a active is true, the view container will marked as active. The active
89 * view container is defined as view where all actions are applied to.
90 */
91 void setActive(bool active);
92 bool isActive() const;
93
94 const DolphinStatusBar* statusBar() const;
95 DolphinStatusBar* statusBar();
96
97 /**
98 * Returns true, if the URL shown by the navigation bar is editable.
99 * @see KUrlNavigator
100 */
101 bool isUrlEditable() const;
102
103 const KUrlNavigator* urlNavigator() const;
104 KUrlNavigator* urlNavigator();
105
106 const DolphinView* view() const;
107 DolphinView* view();
108
109 /**
110 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
111 */
112 void refresh();
113
114 /** Returns true, if the filter bar is visible. */
115 bool isFilterBarVisible() const;
116
117 public slots:
118 /**
119 * Popups the filter bar above the status bar if \a show is true.
120 */
121 void showFilterBar(bool show);
122
123 signals:
124 /**
125 * Is emitted whenever the filter bar has changed its visibility state.
126 */
127 void showFilterBarChanged(bool shown);
128
129 private slots:
130 /**
131 * Updates the number of items (= number of files + number of
132 * directories) in the statusbar. If files are selected, the number
133 * of selected files and the sum of the filesize is shown. The update
134 * is done asynchronously, as getting the sum of the
135 * filesizes can be an expensive operation.
136 */
137 void delayedStatusBarUpdate();
138
139 /**
140 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
141 * updates the status bar synchronously.
142 */
143 void updateStatusBar();
144
145 void updateProgress(int percent);
146
147 /**
148 * Assures that the viewport position is restored and updates the
149 * statusbar to reflect the current content.
150 */
151 void slotDirListerCompleted();
152
153 /**
154 * Handles clicking on an item. If the item is a directory, the
155 * directory is opened in the view. If the item is a file, the file
156 * gets started by the corresponding application.
157 */
158 void slotItemTriggered(const KFileItem& item);
159
160 /**
161 * Opens a the file \a url by opening the corresponding application.
162 * Is connected with the signal urlIsFile() from DolphinDirLister and will
163 * get invoked if the user manually has entered a file into the URL navigator.
164 */
165 void openFile(const KUrl& url);
166
167 /**
168 * Shows the information for the item \a item inside the statusbar. If the
169 * item is null, the default statusbar information is shown.
170 */
171 void showItemInfo(const KFileItem& item);
172
173 /** Shows the information \a msg inside the statusbar. */
174 void showInfoMessage(const QString& msg);
175
176 /** Shows the error message \a msg inside the statusbar. */
177 void showErrorMessage(const QString& msg);
178
179 /** Shows the "operation completed" message \a msg inside the statusbar. */
180 void showOperationCompletedMessage(const QString& msg);
181
182 void closeFilterBar();
183
184 /**
185 * Filters the currently shown items by \a nameFilter. All items
186 * which contain the given filter string will be shown.
187 */
188 void setNameFilter(const QString& nameFilter);
189
190 /**
191 * Opens the context menu on the current mouse position.
192 * @item File item context. If item is null, the context menu
193 * should be applied to \a url.
194 * @url URL which contains \a item.
195 * @customActions Actions that should be added to the context menu,
196 * if the file item is null.
197 */
198 void openContextMenu(const KFileItem& item,
199 const KUrl& url,
200 const QList<QAction*>& customActions);
201
202 /**
203 * Saves the position of the contents to the
204 * current history element.
205 */
206 void saveContentsPos(int x, int y);
207
208 /**
209 * Restores the contents position of the view, if the view
210 * is part of the history.
211 */
212 void restoreContentsPos();
213
214 /**
215 * Marks the view container as active
216 * (see DolphinViewContainer::setActive()).
217 */
218 void activate();
219
220 /**
221 * Restores the current view to show \a url and assures
222 * that the root URL of the view is respected.
223 */
224 void restoreView(const KUrl& url);
225
226 /**
227 * Saves the root URL of the current URL \a url
228 * into the URL navigator.
229 */
230 void saveRootUrl(const KUrl& url);
231
232 /**
233 * Is connected with the URL navigator and drops the URLs
234 * above the destination \a destination.
235 */
236 void dropUrls(const KUrl& destination, QDropEvent* event);
237
238 /**
239 * Is invoked when a redirection is done and changes the
240 * URL of the URL navigator to \a newUrl without triggering
241 * a reloading of the directory.
242 */
243 void redirect(const KUrl& oldUrl, const KUrl& newUrl);
244
245 /** Requests the focus for the view \a m_view. */
246 void requestFocus();
247
248 /**
249 * Saves the currently used URL completion mode of
250 * the URL navigator.
251 */
252 void saveUrlCompletionMode(KGlobalSettings::Completion completion);
253
254 void slotHistoryChanged();
255
256 private:
257 bool m_showProgress;
258 bool m_isFolderWritable;
259
260 DolphinMainWindow* m_mainWindow;
261 QVBoxLayout* m_topLayout;
262 KUrlNavigator* m_urlNavigator;
263
264 DolphinView* m_view;
265
266 FilterBar* m_filterBar;
267
268 DolphinStatusBar* m_statusBar;
269 QTimer* m_statusBarTimer;
270
271 DolphinModel* m_dolphinModel;
272 DolphinDirLister* m_dirLister;
273 DolphinSortFilterProxyModel* m_proxyModel;
274 };
275
276 inline const DolphinStatusBar* DolphinViewContainer::statusBar() const
277 {
278 return m_statusBar;
279 }
280
281 inline DolphinStatusBar* DolphinViewContainer::statusBar()
282 {
283 return m_statusBar;
284 }
285
286 inline const KUrlNavigator* DolphinViewContainer::urlNavigator() const
287 {
288 return m_urlNavigator;
289 }
290
291 inline KUrlNavigator* DolphinViewContainer::urlNavigator()
292 {
293 return m_urlNavigator;
294 }
295
296 inline const DolphinView* DolphinViewContainer::view() const
297 {
298 return m_view;
299 }
300
301 inline DolphinView* DolphinViewContainer::view()
302 {
303 return m_view;
304 }
305
306 #endif // DOLPHINVIEWCONTAINER_H