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