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