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