]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
e6fd8fd0a04ff75c4eefa14db3306412ab10ef38
[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 /**
124 * Updates the number of items (= number of files + number of
125 * directories) in the statusbar. If files are selected, the number
126 * of selected files and the sum of the filesize is shown.
127 */
128 void updateStatusBar();
129
130 signals:
131 /**
132 * Is emitted whenever the filter bar has changed its visibility state.
133 */
134 void showFilterBarChanged(bool shown);
135
136 private slots:
137 void updateProgress(int percent);
138
139 /**
140 * Assures that the viewport position is restored and updates the
141 * statusbar to reflect the current content.
142 */
143 void slotDirListerCompleted();
144
145 /**
146 * Handles clicking on an item. If the item is a directory, the
147 * directory is opened in the view. If the item is a file, the file
148 * gets started by the corresponding application.
149 */
150 void slotItemTriggered(const KFileItem& item);
151
152 /**
153 * Opens a the file \a url by opening the corresponding application.
154 * Is connected with the signal urlIsFile() from DolphinDirLister and will
155 * get invoked if the user manually has entered a file into the URL navigator.
156 */
157 void openFile(const KUrl& url);
158
159 /**
160 * Shows the information for the item \a item inside the statusbar. If the
161 * item is null, the default statusbar information is shown.
162 */
163 void showItemInfo(const KFileItem& item);
164
165 /** Shows the information \a msg inside the statusbar. */
166 void showInfoMessage(const QString& msg);
167
168 /** Shows the error message \a msg inside the statusbar. */
169 void showErrorMessage(const QString& msg);
170
171 /** Shows the "operation completed" message \a msg inside the statusbar. */
172 void showOperationCompletedMessage(const QString& msg);
173
174 void closeFilterBar();
175
176 /**
177 * Filters the currently shown items by \a nameFilter. All items
178 * which contain the given filter string will be shown.
179 */
180 void setNameFilter(const QString& nameFilter);
181
182 /**
183 * Opens the context menu on the current mouse position.
184 * @item File item context. If item is null, the context menu
185 * should be applied to \a url.
186 * @url URL which contains \a item.
187 * @customActions Actions that should be added to the context menu,
188 * if the file item is null.
189 */
190 void openContextMenu(const KFileItem& item,
191 const KUrl& url,
192 const QList<QAction*>& customActions);
193
194 /**
195 * Saves the position of the contents to the
196 * current history element.
197 */
198 void saveContentsPos(int x, int y);
199
200 /**
201 * Restores the contents position of the view, if the view
202 * is part of the history.
203 */
204 void restoreContentsPos();
205
206 /**
207 * Marks the view container as active
208 * (see DolphinViewContainer::setActive()).
209 */
210 void activate();
211
212 /**
213 * Restores the current view to show \a url and assures
214 * that the root URL of the view is respected.
215 */
216 void restoreView(const KUrl& url);
217
218 /**
219 * Saves the root URL of the current URL \a url
220 * into the URL navigator.
221 */
222 void saveRootUrl(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 private:
247 bool m_showProgress;
248 bool m_isFolderWritable;
249
250 DolphinMainWindow* m_mainWindow;
251 QVBoxLayout* m_topLayout;
252 KUrlNavigator* m_urlNavigator;
253
254 DolphinView* m_view;
255
256 FilterBar* m_filterBar;
257 DolphinStatusBar* m_statusBar;
258
259 DolphinModel* m_dolphinModel;
260 DolphinDirLister* m_dirLister;
261 DolphinSortFilterProxyModel* m_proxyModel;
262 };
263
264 inline const DolphinStatusBar* DolphinViewContainer::statusBar() const
265 {
266 return m_statusBar;
267 }
268
269 inline DolphinStatusBar* DolphinViewContainer::statusBar()
270 {
271 return m_statusBar;
272 }
273
274 inline const KUrlNavigator* DolphinViewContainer::urlNavigator() const
275 {
276 return m_urlNavigator;
277 }
278
279 inline KUrlNavigator* DolphinViewContainer::urlNavigator()
280 {
281 return m_urlNavigator;
282 }
283
284 inline const DolphinView* DolphinViewContainer::view() const
285 {
286 return m_view;
287 }
288
289 inline DolphinView* DolphinViewContainer::view()
290 {
291 return m_view;
292 }
293
294 #endif // DOLPHINVIEWCONTAINER_H