]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.h
Merge branch 'release/20.04'
[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 "config-kactivities.h"
24 #include "views/dolphinview.h"
25
26 #include <KCompletion>
27 #include <KFileItem>
28 #include <KIO/Job>
29 #include <KUrlNavigator>
30
31 #include <QElapsedTimer>
32 #include <QPushButton>
33 #include <QWidget>
34
35 #ifdef HAVE_KACTIVITIES
36 namespace KActivities {
37 class ResourceInstance;
38 }
39 #endif
40
41 class FilterBar;
42 class KMessageWidget;
43 class QUrl;
44 class KUrlNavigator;
45 class DolphinSearchBox;
46 class DolphinStatusBar;
47
48 /**
49 * @short Represents a view for the directory content
50 * including the navigation bar, filter bar and status bar.
51 *
52 * View modes for icons, compact and details are supported. Currently
53 * Dolphin allows to have up to two views inside the main window.
54 *
55 * @see DolphinView
56 * @see FilterBar
57 * @see KUrlNavigator
58 * @see DolphinStatusBar
59 */
60 class DolphinViewContainer : public QWidget
61 {
62 Q_OBJECT
63
64 public:
65 enum MessageType
66 {
67 Information,
68 Warning,
69 Error
70 };
71
72 DolphinViewContainer(const QUrl& url, QWidget* parent);
73 ~DolphinViewContainer() override;
74
75 /**
76 * Returns the current active URL, where all actions are applied.
77 * The URL navigator is synchronized with this URL.
78 */
79 QUrl url() const;
80
81 /**
82 * If \a active is true, the view container will marked as active. The active
83 * view container is defined as view where all actions are applied to.
84 */
85 void setActive(bool active);
86 bool isActive() const;
87
88 /**
89 * If \a grab is set to true, the container automatically grabs the focus
90 * as soon as the URL has been changed. Per default the grabbing
91 * of the focus is enabled.
92 */
93 void setAutoGrabFocus(bool grab);
94 bool autoGrabFocus() const;
95
96 QString currentSearchText() const;
97
98 const DolphinStatusBar* statusBar() const;
99 DolphinStatusBar* statusBar();
100
101 const KUrlNavigator* urlNavigator() const;
102 KUrlNavigator* urlNavigator();
103
104 const DolphinView* view() const;
105 DolphinView* view();
106
107 /**
108 * Shows the message \msg with the given type non-modal above
109 * the view-content.
110 */
111 void showMessage(const QString& msg, MessageType type);
112
113 /**
114 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
115 */
116 void readSettings();
117
118 /** Returns true, if the filter bar is visible. */
119 bool isFilterBarVisible() const;
120
121
122 /** Returns true if the search mode is enabled. */
123 bool isSearchModeEnabled() const;
124
125 /**
126 * @return Text that should be used for the current URL when creating
127 * a new place.
128 */
129 QString placesText() const;
130
131 /**
132 * Reload the view of this container. This will also hide messages in a messagewidget.
133 */
134 void reload();
135
136 /**
137 * @return Returns a Caption suitable for display in the window title.
138 * It is calculated depending on GeneralSettings::showFullPathInTitlebar().
139 * If it's false, it calls caption().
140 */
141 QString captionWindowTitle() const;
142
143 /**
144 * @return Returns a Caption suitable for display to the user. It is
145 * calculated depending on settings, if a search is active and other
146 * factors.
147 */
148 QString caption() const;
149
150 public slots:
151 /**
152 * Sets the current active URL, where all actions are applied. The
153 * URL navigator is synchronized with this URL. The signals
154 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
155 * are emitted.
156 * @see DolphinViewContainer::urlNavigator()
157 */
158 void setUrl(const QUrl& url);
159
160 /**
161 * Popups the filter bar above the status bar if \a visible is true.
162 * It \a visible is true, it is assured that the filter bar gains
163 * the keyboard focus.
164 */
165 void setFilterBarVisible(bool visible);
166
167 /**
168 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
169 * will be hidden and replaced by a line editor that allows to enter a search term.
170 */
171 void setSearchModeEnabled(bool enabled);
172
173 signals:
174 /**
175 * Is emitted whenever the filter bar has changed its visibility state.
176 */
177 void showFilterBarChanged(bool shown);
178 /**
179 * Is emitted whenever the search mode has changed its state.
180 */
181 void searchModeEnabledChanged(bool enabled);
182
183 /**
184 * Is emitted when the write state of the folder has been changed. The application
185 * should disable all actions like "Create New..." that depend on the write
186 * state.
187 */
188 void writeStateChanged(bool isFolderWritable);
189
190 private slots:
191 /**
192 * Updates the number of items (= number of files + number of
193 * directories) in the statusbar. If files are selected, the number
194 * of selected files and the sum of the filesize is shown. The update
195 * is done asynchronously, as getting the sum of the
196 * filesizes can be an expensive operation.
197 * Unless a previous OperationCompletedMessage was set very shortly before
198 * calling this method, it will be overwritten (see DolphinStatusBar::setMessage).
199 * Previous ErrorMessages however are always preserved.
200 */
201 void delayedStatusBarUpdate();
202
203 /**
204 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
205 * updates the status bar synchronously.
206 */
207 void updateStatusBar();
208
209 void updateDirectoryLoadingProgress(int percent);
210
211 void updateDirectorySortingProgress(int percent);
212
213 /**
214 * Updates the statusbar to show an undetermined progress with the correct
215 * context information whether a searching or a directory loading is done.
216 */
217 void slotDirectoryLoadingStarted();
218
219 /**
220 * Assures that the viewport position is restored and updates the
221 * statusbar to reflect the current content.
222 */
223 void slotDirectoryLoadingCompleted();
224
225 /**
226 * Updates the statusbar to show, that the directory loading has
227 * been canceled.
228 */
229 void slotDirectoryLoadingCanceled();
230
231 /**
232 * Is called if the URL set by DolphinView::setUrl() represents
233 * a file and not a directory. Takes care to activate the file.
234 */
235 void slotUrlIsFileError(const QUrl& url);
236
237 /**
238 * Handles clicking on an item. If the item is a directory, the
239 * directory is opened in the view. If the item is a file, the file
240 * gets started by the corresponding application.
241 */
242 void slotItemActivated(const KFileItem& item);
243
244 /**
245 * Handles activation of multiple files. The files get started by
246 * the corresponding applications.
247 */
248 void slotItemsActivated(const KFileItemList& items);
249
250 /**
251 * Shows the information for the item \a item inside the statusbar. If the
252 * item is null, the default statusbar information is shown.
253 */
254 void showItemInfo(const KFileItem& item);
255
256 void closeFilterBar();
257
258 /**
259 * Filters the currently shown items by \a nameFilter. All items
260 * which contain the given filter string will be shown.
261 */
262 void setNameFilter(const QString& nameFilter);
263
264 /**
265 * Marks the view container as active
266 * (see DolphinViewContainer::setActive()).
267 */
268 void activate();
269
270 /**
271 * Is invoked if the signal urlAboutToBeChanged() from the URL navigator
272 * is emitted. Tries to save the view-state.
273 */
274 void slotUrlNavigatorLocationAboutToBeChanged(const QUrl& url);
275
276 /**
277 * Restores the current view to show \a url and assures
278 * that the root URL of the view is respected.
279 */
280 void slotUrlNavigatorLocationChanged(const QUrl& url);
281
282 /**
283 * @see KUrlNavigator::urlSelectionRequested
284 */
285 void slotUrlSelectionRequested(const QUrl& url);
286
287 /**
288 * Is invoked when a redirection is done and changes the
289 * URL of the URL navigator to \a newUrl without triggering
290 * a reloading of the directory.
291 */
292 void redirect(const QUrl& oldUrl, const QUrl& newUrl);
293
294 /** Requests the focus for the view \a m_view. */
295 void requestFocus();
296
297 /**
298 * Saves the currently used URL completion mode of
299 * the URL navigator.
300 */
301 void saveUrlCompletionMode(KCompletion::CompletionMode completion);
302
303 void slotReturnPressed();
304
305 /**
306 * Gets the search URL from the searchbox and starts searching.
307 */
308 void startSearching();
309 void closeSearchBox();
310
311 /**
312 * Stops the loading of a directory. Is connected with the "stopPressed" signal
313 * from the statusbar.
314 */
315 void stopDirectoryLoading();
316
317 void slotStatusBarZoomLevelChanged(int zoomLevel);
318
319 /**
320 * Slot that calls showMessage(msg, Error).
321 */
322 void showErrorMessage(const QString& msg);
323
324 private:
325 /**
326 * @return True if the URL protocol is a search URL (e. g. baloosearch:// or filenamesearch://).
327 */
328 bool isSearchUrl(const QUrl& url) const;
329
330 /**
331 * Saves the state of the current view: contents position,
332 * root URL, ...
333 */
334 void saveViewState();
335
336 /**
337 * Restores the state of the current view iff the URL navigator contains a
338 * non-empty location state.
339 */
340 void tryRestoreViewState();
341
342 private:
343 QVBoxLayout* m_topLayout;
344 QWidget* m_navigatorWidget;
345 KUrlNavigator* m_urlNavigator;
346 QPushButton* m_emptyTrashButton;
347 DolphinSearchBox* m_searchBox;
348 bool m_searchModeEnabled;
349 KMessageWidget* m_messageWidget;
350
351 DolphinView* m_view;
352
353 FilterBar* m_filterBar;
354
355 DolphinStatusBar* m_statusBar;
356 QTimer* m_statusBarTimer; // Triggers a delayed update
357 QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
358 bool m_autoGrabFocus;
359
360 #ifdef HAVE_KACTIVITIES
361 private:
362 KActivities::ResourceInstance * m_activityResourceInstance;
363 #endif
364 };
365
366 #endif // DOLPHINVIEWCONTAINER_H