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