]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Fix small problem when building categories and sorting by name. Better readable code.
[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 DolphinView::Mode mode = DolphinView::IconsView,
70 bool showHiddenFiles = false);
71
72 virtual ~DolphinViewContainer();
73
74 /**
75 * Sets the current active URL, where all actions are applied. The
76 * URL navigator is synchronized with this URL. The signals
77 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
78 * are emitted.
79 * @see DolphinViewContainer::urlNavigator()
80 */
81 void setUrl(const KUrl& url);
82
83 /**
84 * Returns the current active URL, where all actions are applied.
85 * The URL navigator is synchronized with this URL.
86 */
87 const KUrl& url() const;
88
89 /**
90 * If \a active is true, the view container will marked as active. The active
91 * view container is defined as view where all actions are applied to.
92 */
93 void setActive(bool active);
94 bool isActive() const;
95
96 /**
97 * Triggers the renaming of the currently selected items, where
98 * the user must input a new name for the items.
99 */
100 void renameSelectedItems();
101
102 KFileItem* fileItem(const QModelIndex index) const;
103
104 inline const DolphinStatusBar* statusBar() const;
105 inline DolphinStatusBar* statusBar();
106
107 /**
108 * Returns true, if the URL shown by the navigation bar is editable.
109 * @see KUrlNavigator
110 */
111 bool isUrlEditable() const;
112
113 inline const KUrlNavigator* urlNavigator() const;
114 inline KUrlNavigator* urlNavigator();
115
116 inline const DolphinView* view() const;
117 inline DolphinView* view();
118
119 /** Returns true, if the filter bar is visible. */
120 bool isFilterBarVisible() const;
121
122 /**
123 * Return the DolphinMainWindow this View belongs to. It is guaranteed
124 * that we have one.
125 */
126 inline const DolphinMainWindow* mainWindow() const;
127
128 public slots:
129 /**
130 * Popups the filter bar above the status bar if \a show is true.
131 */
132 void showFilterBar(bool show);
133
134 /**
135 * Updates the number of items (= number of files + number of
136 * directories) in the statusbar. If files are selected, the number
137 * of selected files and the sum of the filesize is shown.
138 */
139 void updateStatusBar();
140
141 signals:
142 /**
143 * Is emitted whenever the filter bar has changed its visibility state.
144 */
145 void showFilterBarChanged(bool shown);
146
147 private slots:
148 void updateProgress(int percent);
149
150 /**
151 * Updates the number of items (= number of directories + number of files)
152 * and shows this information in the statusbar.
153 */
154 void updateItemCount();
155
156 /**
157 * Shows the item information for the URL \a url inside the statusbar. If the
158 * URL is empty, the default statusbar information is shown.
159 */
160 void showItemInfo(const KUrl& url);
161
162 /** Shows the information \a msg inside the statusbar. */
163 void showInfoMessage(const QString& msg);
164
165 /** Shows the error message \a msg inside the statusbar. */
166 void showErrorMessage(const QString& msg);
167
168 void closeFilterBar();
169
170 /**
171 * Filters the currently shown items by \a nameFilter. All items
172 * which contain the given filter string will be shown.
173 */
174 void changeNameFilter(const QString& nameFilter);
175
176 /**
177 * Opens the context menu on the current mouse postition.
178 * @item File item context. If item is 0, the context menu
179 * should be applied to \a url.
180 * @url URL which contains \a item.
181 */
182 void openContextMenu(KFileItem* item, const KUrl& url);
183
184 /**
185 * Saves the position of the contents to the
186 * current history element.
187 */
188 void saveContentsPos(int x, int y);
189
190 /**
191 * Restores the contents position of the view, if the view
192 * is part of the history.
193 */
194 void restoreContentsPos();
195
196 /**
197 * Marks the view container as active
198 * (see DolphinViewContainer::setActive()).
199 */
200 void activate();
201
202 private:
203 /**
204 * Returns the default text of the status bar, if no item is
205 * selected.
206 */
207 QString defaultStatusBarText() const;
208
209 /**
210 * Returns the text for the status bar, if at least one item
211 * is selected.
212 */
213 QString selectionStatusBarText() const;
214
215 private:
216 bool m_showProgress;
217
218 int m_iconSize;
219 int m_folderCount;
220 int m_fileCount;
221
222 DolphinMainWindow* m_mainWindow;
223 QVBoxLayout* m_topLayout;
224 KUrlNavigator* m_urlNavigator;
225
226 DolphinView* m_view;
227
228 FilterBar* m_filterBar;
229 DolphinStatusBar* m_statusBar;
230
231 KDirModel* m_dirModel;
232 DolphinDirLister* m_dirLister;
233 DolphinSortFilterProxyModel* m_proxyModel;
234 };
235
236 const DolphinStatusBar* DolphinViewContainer::statusBar() const
237 {
238 return m_statusBar;
239 }
240
241 DolphinStatusBar* DolphinViewContainer::statusBar()
242 {
243 return m_statusBar;
244 }
245
246 const KUrlNavigator* DolphinViewContainer::urlNavigator() const
247 {
248 return m_urlNavigator;
249 }
250
251 KUrlNavigator* DolphinViewContainer::urlNavigator()
252 {
253 return m_urlNavigator;
254 }
255
256 const DolphinView* DolphinViewContainer::view() const
257 {
258 return m_view;
259 }
260
261 DolphinView* DolphinViewContainer::view()
262 {
263 return m_view;
264 }
265
266 const DolphinMainWindow* DolphinViewContainer::mainWindow() const
267 {
268 return m_mainWindow;
269 }
270 #endif // DOLPHINVIEWCONTAINER_H