]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
use "Sort by" instead of "Sort By"
[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 <kparts/part.h>
27 #include <kfileitem.h>
28 #include <kfileitemdelegate.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 KDirModel;
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 /**
95 * Triggers the renaming of the currently selected items, where
96 * the user must input a new name for the items.
97 */
98 void renameSelectedItems();
99
100 KFileItem fileItem(const QModelIndex& index) const;
101
102 inline const DolphinStatusBar* statusBar() const;
103 inline DolphinStatusBar* statusBar();
104
105 /**
106 * Returns true, if the URL shown by the navigation bar is editable.
107 * @see KUrlNavigator
108 */
109 bool isUrlEditable() const;
110
111 inline const KUrlNavigator* urlNavigator() const;
112 inline KUrlNavigator* urlNavigator();
113
114 inline const DolphinView* view() const;
115 inline DolphinView* view();
116
117 /** Returns true, if the filter bar is visible. */
118 bool isFilterBarVisible() const;
119
120 /**
121 * Return the DolphinMainWindow this View belongs to. It is guaranteed
122 * that we have one.
123 */
124 inline const DolphinMainWindow* mainWindow() const;
125
126 public slots:
127 /**
128 * Popups the filter bar above the status bar if \a show is true.
129 */
130 void showFilterBar(bool show);
131
132 /**
133 * Updates the number of items (= number of files + number of
134 * directories) in the statusbar. If files are selected, the number
135 * of selected files and the sum of the filesize is shown.
136 */
137 void updateStatusBar();
138
139 signals:
140 /**
141 * Is emitted whenever the filter bar has changed its visibility state.
142 */
143 void showFilterBarChanged(bool shown);
144
145 private slots:
146 void updateProgress(int percent);
147
148 /**
149 * Updates the number of items (= number of directories + number of files)
150 * and shows this information in the statusbar.
151 */
152 void updateItemCount();
153
154 /**
155 * Handles clicking on an item
156 */
157 void slotItemTriggered(const KFileItem& item);
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 void closeFilterBar();
172
173 /**
174 * Filters the currently shown items by \a nameFilter. All items
175 * which contain the given filter string will be shown.
176 */
177 void changeNameFilter(const QString& nameFilter);
178
179 /**
180 * Opens the context menu on the current mouse position.
181 * @item File item context. If item is 0, the context menu
182 * should be applied to \a url.
183 * @url URL which contains \a item.
184 */
185 void openContextMenu(const KFileItem& item, const KUrl& url);
186
187 /**
188 * Saves the position of the contents to the
189 * current history element.
190 */
191 void saveContentsPos(int x, int y);
192
193 /**
194 * Restores the contents position of the view, if the view
195 * is part of the history.
196 */
197 void restoreContentsPos();
198
199 /**
200 * Marks the view container as active
201 * (see DolphinViewContainer::setActive()).
202 */
203 void activate();
204
205 private:
206 /**
207 * Returns the default text of the status bar, if no item is
208 * selected.
209 */
210 QString defaultStatusBarText() const;
211
212 /**
213 * Returns the text for the status bar, if at least one item
214 * is selected.
215 */
216 QString selectionStatusBarText() const;
217
218 private:
219 bool m_showProgress;
220
221 int m_iconSize;
222 int m_folderCount;
223 int m_fileCount;
224
225 DolphinMainWindow* m_mainWindow;
226 QVBoxLayout* m_topLayout;
227 KUrlNavigator* m_urlNavigator;
228
229 DolphinView* m_view;
230
231 FilterBar* m_filterBar;
232 DolphinStatusBar* m_statusBar;
233
234 KDirModel* m_dirModel;
235 DolphinDirLister* m_dirLister;
236 DolphinSortFilterProxyModel* m_proxyModel;
237 };
238
239 const DolphinStatusBar* DolphinViewContainer::statusBar() const
240 {
241 return m_statusBar;
242 }
243
244 DolphinStatusBar* DolphinViewContainer::statusBar()
245 {
246 return m_statusBar;
247 }
248
249 const KUrlNavigator* DolphinViewContainer::urlNavigator() const
250 {
251 return m_urlNavigator;
252 }
253
254 KUrlNavigator* DolphinViewContainer::urlNavigator()
255 {
256 return m_urlNavigator;
257 }
258
259 const DolphinView* DolphinViewContainer::view() const
260 {
261 return m_view;
262 }
263
264 DolphinView* DolphinViewContainer::view()
265 {
266 return m_view;
267 }
268
269 const DolphinMainWindow* DolphinViewContainer::mainWindow() const
270 {
271 return m_mainWindow;
272 }
273 #endif // DOLPHINVIEWCONTAINER_H