]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
First big step to make it possible that the DolphinView can be embedded as KPart...
[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 DolphinController;
40 class FilterBar;
41 class KFileItemDelegate;
42 class KUrl;
43 class KDirModel;
44 class KUrlNavigator;
45 class DolphinColumnView;
46 class DolphinDetailsView;
47 class DolphinDirLister;
48 class DolphinIconsView;
49 class DolphinMainWindow;
50 class DolphinSortFilterProxyModel;
51 class DolphinStatusBar;
52 class QModelIndex;
53 class ViewProperties;
54
55 /**
56 * @short Represents a view for the directory content
57 * including the navigation bar, filter bar and status bar.
58 *
59 * View modes for icons, details and columns are supported. Currently
60 * Dolphin allows to have up to two views inside the main window.
61 *
62 * @see DolphinView
63 * @see FilterBar
64 * @see KUrlNavigator
65 * @see DolphinStatusBar
66 */
67 class DolphinViewContainer : public QWidget
68 {
69 Q_OBJECT
70
71 public:
72 DolphinViewContainer(DolphinMainWindow* mainwindow,
73 QWidget *parent,
74 const KUrl& url,
75 DolphinView::Mode mode = DolphinView::IconsView,
76 bool showHiddenFiles = false);
77
78 virtual ~DolphinViewContainer();
79
80 /**
81 * Sets the current active URL, where all actions are applied. The
82 * URL navigator is synchronized with this URL. The signals
83 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
84 * are emitted.
85 * @see DolphinViewContainer::urlNavigator()
86 */
87 void setUrl(const KUrl& url);
88
89 /**
90 * Returns the current active URL, where all actions are applied.
91 * The URL navigator is synchronized with this URL.
92 */
93 const KUrl& url() const;
94
95 /**
96 * If \a active is true, the view container will marked as active. The active
97 * view container is defined as view where all actions are applied to.
98 */
99 void setActive(bool active);
100 bool isActive() const;
101
102 /**
103 * Triggers the renaming of the currently selected items, where
104 * the user must input a new name for the items.
105 */
106 void renameSelectedItems();
107
108 KFileItem* fileItem(const QModelIndex index) const;
109
110 /**
111 * Renames the filename of the source URL by the new file name.
112 * If the new file name already exists, a dialog is opened which
113 * asks the user to enter a new name.
114 */
115 void rename(const KUrl& source, const QString& newName);
116
117 DolphinStatusBar* statusBar() const;
118
119 /**
120 * Returns true, if the URL shown by the navigation bar is editable.
121 * @see KUrlNavigator
122 */
123 bool isUrlEditable() const;
124
125 inline KUrlNavigator* urlNavigator() const;
126
127 inline DolphinView* view() const;
128
129 /** Returns true, if the filter bar is visible. */
130 bool isFilterBarVisible() const;
131
132 /**
133 * Return the DolphinMainWindow this View belongs to. It is guaranteed
134 * that we have one.
135 */
136 DolphinMainWindow* mainWindow() const ;
137
138 public slots:
139 /**
140 * Popups the filter bar above the status bar if \a show is true.
141 */
142 void showFilterBar(bool show);
143
144 /**
145 * Updates the number of items (= number of files + number of
146 * directories) in the statusbar. If files are selected, the number
147 * of selected files and the sum of the filesize is shown.
148 */
149 void updateStatusBar();
150
151 signals:
152 /**
153 * Is emitted whenever the filter bar has changed its visibility state.
154 */
155 void showFilterBarChanged(bool shown);
156
157 private slots:
158 void updateProgress(int percent);
159
160 /**
161 * Updates the number of items (= number of directories + number of files)
162 * and shows this information in the statusbar.
163 */
164 void updateItemCount();
165
166 /** Shows the information \a msg inside the statusbar. */
167 void showInfoMessage(const QString& msg);
168
169 /** Shows the error message \a msg inside the statusbar. */
170 void showErrorMessage(const QString& msg);
171
172 void closeFilterBar();
173
174 /**
175 * Filters the currently shown items by \a nameFilter. All items
176 * which contain the given filter string will be shown.
177 */
178 void changeNameFilter(const QString& nameFilter);
179
180 /**
181 * Opens the context menu on the current mouse postition.
182 * @item File item context. If item is 0, the context menu
183 * should be applied to \a url.
184 * @url URL which contains \a item.
185 */
186 void openContextMenu(KFileItem* item, const KUrl& url);
187
188 private:
189 /**
190 * Returns the default text of the status bar, if no item is
191 * selected.
192 */
193 QString defaultStatusBarText() const;
194
195 /**
196 * Returns the text for the status bar, if at least one item
197 * is selected.
198 */
199 QString selectionStatusBarText() const;
200
201 private:
202 bool m_showProgress;
203
204 int m_iconSize;
205 int m_folderCount;
206 int m_fileCount;
207
208 DolphinMainWindow* m_mainWindow;
209 QVBoxLayout* m_topLayout;
210 KUrlNavigator* m_urlNavigator;
211
212 DolphinView* m_view;
213
214 FilterBar* m_filterBar;
215 DolphinStatusBar* m_statusBar;
216
217 KDirModel* m_dirModel;
218 DolphinDirLister* m_dirLister;
219 DolphinSortFilterProxyModel* m_proxyModel;
220 };
221
222 KUrlNavigator* DolphinViewContainer::urlNavigator() const
223 {
224 return m_urlNavigator;
225 }
226
227 DolphinView* DolphinViewContainer::view() const
228 {
229 return m_view;
230 }
231
232 #endif // DOLPHINVIEWCONTAINER_H