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