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