]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Rename the setter showFilterBar() to setFilterBarVisible().
[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 <kfileitem.h>
25 #include <kfileitemdelegate.h>
26 #include <kglobalsettings.h>
27 #include <kio/job.h>
28
29 #include <kurlnavigator.h>
30
31 #include <QElapsedTimer>
32 #include <QWidget>
33
34 #include <views/dolphinview.h>
35
36 class FilterBar;
37 class KUrl;
38 class DolphinModel;
39 class KUrlNavigator;
40 class DolphinDirLister;
41 class DolphinSearchBox;
42 class DolphinSortFilterProxyModel;
43 class DolphinStatusBar;
44
45 /**
46 * @short Represents a view for the directory content
47 * including the navigation bar, filter bar and status bar.
48 *
49 * View modes for icons, details and columns are supported. Currently
50 * Dolphin allows to have up to two views inside the main window.
51 *
52 * @see DolphinView
53 * @see FilterBar
54 * @see KUrlNavigator
55 * @see DolphinStatusBar
56 */
57 class DolphinViewContainer : public QWidget
58 {
59 Q_OBJECT
60
61 public:
62 DolphinViewContainer(const KUrl& url, QWidget* parent);
63 virtual ~DolphinViewContainer();
64
65 /**
66 * Returns the current active URL, where all actions are applied.
67 * The URL navigator is synchronized with this URL.
68 */
69 KUrl url() const;
70
71 /**
72 * If \a active is true, the view container will marked as active. The active
73 * view container is defined as view where all actions are applied to.
74 */
75 void setActive(bool active);
76 bool isActive() const;
77
78 const DolphinStatusBar* statusBar() const;
79 DolphinStatusBar* statusBar();
80
81 const KUrlNavigator* urlNavigator() const;
82 KUrlNavigator* urlNavigator();
83
84 const DolphinView* view() const;
85 DolphinView* view();
86
87 /**
88 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
89 */
90 void refresh();
91
92 /** Returns true, if the filter bar is visible. */
93 bool isFilterBarVisible() const;
94
95 /**
96 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
97 * will be hidden and replaced by a line editor that allows to enter a search term.
98 */
99 void setSearchModeEnabled(bool enabled);
100 bool isSearchModeEnabled() const;
101
102 public slots:
103 /**
104 * Sets the current active URL, where all actions are applied. The
105 * URL navigator is synchronized with this URL. The signals
106 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
107 * are emitted.
108 * @see DolphinViewContainer::urlNavigator()
109 */
110 void setUrl(const KUrl& url);
111
112 /**
113 * Popups the filter bar above the status bar if \a visible is true.
114 */
115 void setFilterBarVisible(bool visible);
116
117 signals:
118 /**
119 * Is emitted whenever the filter bar has changed its visibility state.
120 */
121 void showFilterBarChanged(bool shown);
122
123 /**
124 * Is emitted when the write state of the folder has been changed. The application
125 * should disable all actions like "Create New..." that depend on the write
126 * state.
127 */
128 void writeStateChanged(bool isFolderWritable);
129
130 /**
131 * Is emitted if the search mode has been enabled or disabled.
132 * (see DolphinViewContainer::setSearchModeEnabled() and
133 * DolphinViewContainer::isSearchModeEnabled())
134 */
135 void searchModeChanged(bool enabled);
136
137 private slots:
138 /**
139 * Updates the number of items (= number of files + number of
140 * directories) in the statusbar. If files are selected, the number
141 * of selected files and the sum of the filesize is shown. The update
142 * is done asynchronously, as getting the sum of the
143 * filesizes can be an expensive operation.
144 */
145 void delayedStatusBarUpdate();
146
147 /**
148 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
149 * updates the status bar synchronously.
150 */
151 void updateStatusBar();
152
153 void initializeProgress();
154
155 void updateProgress(int percent);
156
157 /**
158 * Assures that the viewport position is restored and updates the
159 * statusbar to reflect the current content.
160 */
161 void slotDirListerCompleted();
162
163 /**
164 * Handles clicking on an item. If the item is a directory, the
165 * directory is opened in the view. If the item is a file, the file
166 * gets started by the corresponding application.
167 */
168 void slotItemTriggered(const KFileItem& item);
169
170 /**
171 * Opens a the file \a url by opening the corresponding application.
172 * Is connected with the signal urlIsFile() from DolphinDirLister and will
173 * get invoked if the user manually has entered a file into the URL navigator.
174 */
175 void openFile(const KUrl& url);
176
177 /**
178 * Shows the information for the item \a item inside the statusbar. If the
179 * item is null, the default statusbar information is shown.
180 */
181 void showItemInfo(const KFileItem& item);
182
183 /** Shows the information \a msg inside the statusbar. */
184 void showInfoMessage(const QString& msg);
185
186 /** Shows the error message \a msg inside the statusbar. */
187 void showErrorMessage(const QString& msg);
188
189 /** Shows the "operation completed" message \a msg inside the statusbar. */
190 void showOperationCompletedMessage(const QString& msg);
191
192 void closeFilterBar();
193
194 /**
195 * Filters the currently shown items by \a nameFilter. All items
196 * which contain the given filter string will be shown.
197 */
198 void setNameFilter(const QString& nameFilter);
199
200 /**
201 * Marks the view container as active
202 * (see DolphinViewContainer::setActive()).
203 */
204 void activate();
205
206 /**
207 * Saves the state of the current view: contents position,
208 * root URL, ...
209 */
210 void saveViewState();
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 slotUrlNavigatorLocationChanged(const KUrl& url);
217
218 /**
219 * Is connected with the URL navigator and drops the URLs
220 * above the destination \a destination.
221 */
222 void dropUrls(const KUrl& destination, QDropEvent* event);
223
224 /**
225 * Is invoked when a redirection is done and changes the
226 * URL of the URL navigator to \a newUrl without triggering
227 * a reloading of the directory.
228 */
229 void redirect(const KUrl& oldUrl, const KUrl& newUrl);
230
231 /** Requests the focus for the view \a m_view. */
232 void requestFocus();
233
234 /**
235 * Saves the currently used URL completion mode of
236 * the URL navigator.
237 */
238 void saveUrlCompletionMode(KGlobalSettings::Completion completion);
239
240 void slotHistoryChanged();
241
242 /**
243 * Gets the search URL from the searchbox and starts searching.
244 * @param text Text the user has entered into the searchbox.
245 */
246 void startSearching(const QString& text);
247 void closeSearchBox();
248
249 private:
250 /**
251 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
252 */
253 bool isSearchUrl(const KUrl& url) const;
254
255 private:
256 bool m_isFolderWritable;
257
258 QVBoxLayout* m_topLayout;
259 KUrlNavigator* m_urlNavigator;
260 DolphinSearchBox* m_searchBox;
261
262 DolphinView* m_view;
263
264 FilterBar* m_filterBar;
265
266 DolphinStatusBar* m_statusBar;
267 QTimer* m_statusBarTimer; // Triggers a delayed update
268 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
269
270 DolphinModel* m_dolphinModel;
271 DolphinDirLister* m_dirLister;
272 DolphinSortFilterProxyModel* m_proxyModel;
273 };
274
275 inline const DolphinStatusBar* DolphinViewContainer::statusBar() const
276 {
277 return m_statusBar;
278 }
279
280 inline DolphinStatusBar* DolphinViewContainer::statusBar()
281 {
282 return m_statusBar;
283 }
284
285 inline const KUrlNavigator* DolphinViewContainer::urlNavigator() const
286 {
287 return m_urlNavigator;
288 }
289
290 inline KUrlNavigator* DolphinViewContainer::urlNavigator()
291 {
292 return m_urlNavigator;
293 }
294
295 inline const DolphinView* DolphinViewContainer::view() const
296 {
297 return m_view;
298 }
299
300 inline DolphinView* DolphinViewContainer::view()
301 {
302 return m_view;
303 }
304
305 #endif // DOLPHINVIEWCONTAINER_H