]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinview.h
Fix uninitialised value
[dolphin.git] / src / views / dolphinview.h
1 /*
2 * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Gregor Kališnik <gregor@podnapisi.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef DOLPHINVIEW_H
9 #define DOLPHINVIEW_H
10
11 #include "dolphin_export.h"
12 #include "dolphintabwidget.h"
13 #include "tooltips/tooltipmanager.h"
14
15 #include "config-dolphin.h"
16 #include <KFileItem>
17 #include <KIO/Job>
18 #include <kio/fileundomanager.h>
19 #include <kparts/part.h>
20
21 #include <QMimeData>
22 #include <QPointer>
23 #include <QUrl>
24 #include <QWidget>
25
26 #include <memory>
27
28 typedef KIO::FileUndoManager::CommandType CommandType;
29 class QVBoxLayout;
30 class DolphinItemListView;
31 class KFileItemModel;
32 class KItemListContainer;
33 class KItemModelBase;
34 class KItemSet;
35 class ToolTipManager;
36 class VersionControlObserver;
37 class ViewProperties;
38 class QLabel;
39 class QGraphicsSceneDragDropEvent;
40 class QHelpEvent;
41 class QProxyStyle;
42 class QRegularExpression;
43
44 /**
45 * @short Represents a view for the directory content.
46 *
47 * View modes for icons, compact and details are supported. It's
48 * possible to adjust:
49 * - sort order
50 * - sort type
51 * - show hidden files
52 * - show previews
53 * - enable grouping
54 */
55 class DOLPHIN_EXPORT DolphinView : public QWidget
56 {
57 Q_OBJECT
58
59 public:
60 /**
61 * Defines the view mode for a directory. The
62 * view mode is automatically updated if the directory itself
63 * defines a view mode (see class ViewProperties for details).
64 */
65 enum Mode {
66 /**
67 * The items are shown as icons with a name-label below.
68 */
69 IconsView = 0,
70
71 /**
72 * The icon, the name and the size of the items are
73 * shown per default as a table.
74 */
75 DetailsView,
76
77 /**
78 * The items are shown as icons with the name-label aligned
79 * to the right side.
80 */
81 CompactView
82 };
83
84 /**
85 * @param url Specifies the content which should be shown.
86 * @param parent Parent widget of the view.
87 */
88 DolphinView(const QUrl &url, QWidget *parent);
89
90 ~DolphinView() override;
91
92 /**
93 * Returns the current active URL, where all actions are applied.
94 * The URL navigator is synchronized with this URL.
95 */
96 QUrl url() const;
97
98 /**
99 * If \a active is true, the view will marked as active. The active
100 * view is defined as view where all actions are applied to.
101 */
102 void setActive(bool active);
103 bool isActive() const;
104
105 /**
106 * Changes the view mode for the current directory to \a mode.
107 * If the view properties should be remembered for each directory
108 * (GeneralSettings::globalViewProps() returns false), then the
109 * changed view mode will be stored automatically.
110 */
111 void setViewMode(Mode mode);
112 Mode viewMode() const;
113
114 /**
115 * Enables or disables a mode for quick and easy selection of items.
116 */
117 void setSelectionModeEnabled(bool enabled);
118 bool selectionMode() const;
119
120 /**
121 * Turns on the file preview for the all files of the current directory,
122 * if \a show is true.
123 * If the view properties should be remembered for each directory
124 * (GeneralSettings::globalViewProps() returns false), then the
125 * preview setting will be stored automatically.
126 */
127 void setPreviewsShown(bool show);
128 bool previewsShown() const;
129
130 /**
131 * Shows all hidden files of the current directory,
132 * if \a show is true.
133 * If the view properties should be remembered for each directory
134 * (GeneralSettings::globalViewProps() returns false), then the
135 * show hidden file setting will be stored automatically.
136 */
137 void setHiddenFilesShown(bool show);
138 bool hiddenFilesShown() const;
139
140 /**
141 * Turns on sorting by groups if \a enable is true.
142 */
143 void setGroupedSorting(bool grouped);
144 bool groupedSorting() const;
145
146 /**
147 * Returns the items of the view.
148 */
149 KFileItemList items() const;
150
151 /**
152 * @return The number of items. itemsCount() is faster in comparison
153 * to items().count().
154 */
155 int itemsCount() const;
156
157 /**
158 * Returns the selected items. The list is empty if no item has been
159 * selected.
160 */
161 KFileItemList selectedItems() const;
162
163 /**
164 * Returns the number of selected items (this is faster than
165 * invoking selectedItems().count()).
166 */
167 int selectedItemsCount() const;
168
169 /**
170 * Marks the items indicated by \p urls to get selected after the
171 * directory DolphinView::url() has been loaded. Note that nothing
172 * gets selected if no loading of a directory has been triggered
173 * by DolphinView::setUrl() or DolphinView::reload().
174 */
175 void markUrlsAsSelected(const QList<QUrl> &urls);
176
177 /**
178 * Marks the item indicated by \p url to be scrolled to and as the
179 * current item after directory DolphinView::url() has been loaded.
180 */
181 void markUrlAsCurrent(const QUrl &url);
182
183 /**
184 * All items that match the regular expression \a regexp will get selected
185 * if \a enabled is true and deselected if \a enabled is false.
186 *
187 * Note that to match the whole string the pattern should be anchored:
188 * - you can anchor the pattern with QRegularExpression::anchoredPattern()
189 * - if you use QRegularExpresssion::wildcardToRegularExpression(), don't use
190 * QRegularExpression::anchoredPattern() as the former already returns an
191 * anchored pattern
192 */
193 void selectItems(const QRegularExpression &regexp, bool enabled);
194
195 /**
196 * Sets the zoom level to \a level. It is assured that the used
197 * level is adjusted to be inside the range ZoomLevelInfo::minimumLevel() and
198 * ZoomLevelInfo::maximumLevel().
199 */
200 void setZoomLevel(int level);
201 int zoomLevel() const;
202
203 /**
204 * Resets the view's icon size to the default value
205 */
206 void resetZoomLevel();
207
208 void setSortRole(const QByteArray &role);
209 QByteArray sortRole() const;
210
211 void setSortOrder(Qt::SortOrder order);
212 Qt::SortOrder sortOrder() const;
213
214 /** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */
215 void setSortFoldersFirst(bool foldersFirst);
216 bool sortFoldersFirst() const;
217
218 /** Sets a separate sorting with hidden files and folders last (true) or not (false). */
219 void setSortHiddenLast(bool hiddenLast);
220 bool sortHiddenLast() const;
221
222 /** Sets the additional information which should be shown for the items. */
223 void setVisibleRoles(const QList<QByteArray> &roles);
224
225 /** Returns the additional information which should be shown for the items. */
226 QList<QByteArray> visibleRoles() const;
227
228 void reload();
229
230 /**
231 * Refreshes the view to get synchronized with the settings (e.g. icons size,
232 * font, ...).
233 */
234 void readSettings();
235
236 /**
237 * Saves the current settings (e.g. icons size, font, ..).
238 */
239 void writeSettings();
240
241 /**
242 * Filters the currently shown items by \a nameFilter. All items
243 * which contain the given filter string will be shown.
244 */
245 void setNameFilter(const QString &nameFilter);
246 QString nameFilter() const;
247
248 /**
249 * Filters the currently shown items by \a filters. All items
250 * whose content-type matches those given by the list of filters
251 * will be shown.
252 */
253 void setMimeTypeFilters(const QStringList &filters);
254 QStringList mimeTypeFilters() const;
255
256 /**
257 * Tells the view to generate an updated status bar text. The result
258 * is returned through the statusBarTextChanged(QString statusBarText) signal.
259 * It will carry a textual representation of the state of the current
260 * folder or selected items, suitable for use in the status bar.
261 * Any pending requests of status bar text are killed.
262 */
263 void requestStatusBarText();
264
265 /**
266 * Returns the version control actions that are provided for the items \p items.
267 * Usually the actions are presented in the context menu.
268 */
269 QList<QAction *> versionControlActions(const KFileItemList &items) const;
270
271 /**
272 * Returns the state of the paste action:
273 * first is whether the action should be enabled
274 * second is the text for the action
275 */
276 QPair<bool, QString> pasteInfo() const;
277
278 /**
279 * If \a tabsForFiles is true, the signal tabRequested() will also
280 * emitted also for files. Per default tabs for files is disabled
281 * and hence the signal tabRequested() will only be emitted for
282 * directories.
283 */
284 void setTabsForFilesEnabled(bool tabsForFiles);
285 bool isTabsForFilesEnabled() const;
286
287 /**
288 * Returns true if the current view allows folders to be expanded,
289 * i.e. presents a hierarchical view to the user.
290 */
291 bool itemsExpandable() const;
292
293 /**
294 * @returns true if the @p item is one of the items() of this view and
295 * is currently expanded. false otherwise.
296 * Only directories in view modes that allow expanding can ever be expanded.
297 */
298 bool isExpanded(const KFileItem &item) const;
299
300 /**
301 * Restores the view state (current item, contents position, details view expansion state)
302 */
303 void restoreState(QDataStream &stream);
304
305 /**
306 * Saves the view state (current item, contents position, details view expansion state)
307 */
308 void saveState(QDataStream &stream);
309
310 /**
311 * Returns the root item which represents the current URL.
312 */
313 KFileItem rootItem() const;
314
315 /**
316 * Sets a context that is used for remembering the view-properties.
317 * Per default the context is empty and the path of the currently set URL
318 * is used for remembering the view-properties. Setting a custom context
319 * makes sense if specific types of URLs (e.g. search-URLs) should
320 * share common view-properties.
321 */
322 void setViewPropertiesContext(const QString &context);
323 QString viewPropertiesContext() const;
324
325 /**
326 * Checks if the given \a item can be opened as folder (e.g. archives).
327 * This function will also adjust the \a url (e.g. change the protocol).
328 * @return a valid and adjusted url if the item can be opened as folder,
329 * otherwise return an empty url.
330 */
331 static QUrl openItemAsFolderUrl(const KFileItem &item, const bool browseThroughArchives = true);
332
333 /**
334 * Hides tooltip displayed over element.
335 */
336 void hideToolTip(const ToolTipManager::HideBehavior behavior = ToolTipManager::HideBehavior::Later);
337
338 public Q_SLOTS:
339 /**
340 * Changes the directory to \a url. If the current directory is equal to
341 * \a url, nothing will be done (use DolphinView::reload() instead).
342 */
343 void setUrl(const QUrl &url);
344
345 /**
346 * Selects all items.
347 * @see DolphinView::selectedItems()
348 */
349 void selectAll();
350
351 /**
352 * Inverts the current selection: selected items get unselected,
353 * unselected items get selected.
354 * @see DolphinView::selectedItems()
355 */
356 void invertSelection();
357
358 void clearSelection();
359
360 /**
361 * Triggers the renaming of the currently selected items, where
362 * the user must input a new name for the items.
363 */
364 void renameSelectedItems();
365
366 /**
367 * Moves all selected items to the trash.
368 */
369 void trashSelectedItems();
370
371 /**
372 * Deletes all selected items.
373 */
374 void deleteSelectedItems();
375
376 /**
377 * Copies all selected items to the clipboard and marks
378 * the items as cut.
379 */
380 void cutSelectedItemsToClipboard();
381
382 /** Copies all selected items to the clipboard. */
383 void copySelectedItemsToClipboard();
384
385 /**
386 * Copies all selected items to @p destinationUrl.
387 */
388 void copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl);
389
390 /**
391 * Moves all selected items to @p destinationUrl.
392 */
393 void moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl);
394
395 /** Pastes the clipboard data to this view. */
396 void paste();
397
398 /**
399 * Pastes the clipboard data into the currently selected
400 * folder. If the current selection is not exactly one folder, no
401 * paste operation is done.
402 */
403 void pasteIntoFolder();
404
405 /**
406 * Copies the path of the first selected KFileItem into Clipboard.
407 */
408 void copyPathToClipboard();
409
410 /**
411 * Creates duplicates of selected items, appending "copy"
412 * to the end.
413 */
414 void duplicateSelectedItems();
415
416 /**
417 * Handles a drop of @p dropEvent onto widget @p dropWidget and destination @p destUrl
418 */
419 void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget);
420
421 void stopLoading();
422
423 /**
424 * Applies the state that has been restored by restoreViewState()
425 * to the view.
426 */
427 void updateViewState();
428
429 /** Activates the view if the item list container gets focus. */
430 bool eventFilter(QObject *watched, QEvent *event) override;
431
432 Q_SIGNALS:
433 /**
434 * Is emitted if the view has been activated by e. g. a mouse click.
435 */
436 void activated();
437
438 /** Is emitted if the URL of the view has been changed to \a url. */
439 void urlChanged(const QUrl &url);
440
441 /**
442 * Is emitted when clicking on an item with the left mouse button.
443 */
444 void itemActivated(const KFileItem &item);
445
446 /**
447 * Is emitted when multiple items have been activated by e. g.
448 * context menu open with.
449 */
450 void itemsActivated(const KFileItemList &items);
451
452 /**
453 * Is emitted if items have been added or deleted.
454 */
455 void itemCountChanged();
456
457 /**
458 * Is emitted if a new tab should be opened for the URL \a url.
459 */
460 void tabRequested(const QUrl &url);
461
462 /**
463 * Is emitted if a new tab should be opened for the URL \a url and set as active.
464 */
465 void activeTabRequested(const QUrl &url);
466
467 /**
468 * Is emitted if a new window should be opened for the URL \a url.
469 */
470 void windowRequested(const QUrl &url);
471
472 /**
473 * Is emitted if the view mode (IconsView, DetailsView,
474 * PreviewsView) has been changed.
475 */
476 void modeChanged(DolphinView::Mode current, DolphinView::Mode previous);
477
478 /** Is emitted if the 'show preview' property has been changed. */
479 void previewsShownChanged(bool shown);
480
481 /** Is emitted if the 'show hidden files' property has been changed. */
482 void hiddenFilesShownChanged(bool shown);
483
484 /** Is emitted if the 'grouped sorting' property has been changed. */
485 void groupedSortingChanged(bool groupedSorting);
486
487 /** Is emitted in reaction to a requestStatusBarText() call.
488 * @see requestStatusBarText() */
489 void statusBarTextChanged(QString statusBarText);
490
491 /** Is emitted if the sorting by name, size or date has been changed. */
492 void sortRoleChanged(const QByteArray &role);
493
494 /** Is emitted if the sort order (ascending or descending) has been changed. */
495 void sortOrderChanged(Qt::SortOrder order);
496
497 /**
498 * Is emitted if the sorting of files and folders (separate with folders
499 * first or mixed) has been changed.
500 */
501 void sortFoldersFirstChanged(bool foldersFirst);
502
503 /**
504 * Is emitted if the sorting of hidden files has been changed.
505 */
506 void sortHiddenLastChanged(bool hiddenLast);
507
508 /** Is emitted if the additional information shown for this view has been changed. */
509 void visibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous);
510
511 /** Is emitted if the zoom level has been changed by zooming in or out. */
512 void zoomLevelChanged(int current, int previous);
513
514 /**
515 * Is emitted if information of an item is requested to be shown e. g. in the panel.
516 * If item is null, no item information request is pending.
517 */
518 void requestItemInfo(const KFileItem &item);
519
520 /**
521 * Is emitted whenever the selection has been changed.
522 */
523 void selectionChanged(const KFileItemList &selection);
524
525 /**
526 * Is emitted if a context menu is requested for the item \a item,
527 * which is part of \a url. If the item is null, the context menu
528 * for the URL should be shown.
529 */
530 void requestContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url);
531
532 /**
533 * Is emitted if an information message with the content \a msg
534 * should be shown.
535 */
536 void infoMessage(const QString &msg);
537
538 /**
539 * Is emitted if an error message with the content \a msg
540 * should be shown.
541 */
542 void errorMessage(const QString &msg);
543
544 /**
545 * Is emitted if an "operation completed" message with the content \a msg
546 * should be shown.
547 */
548 void operationCompletedMessage(const QString &msg);
549
550 /**
551 * Is emitted after DolphinView::setUrl() has been invoked and
552 * the current directory is loaded. If this signal is emitted,
553 * it is assured that the view contains already the correct root
554 * URL and property settings.
555 */
556 void directoryLoadingStarted();
557
558 /**
559 * Is emitted after the directory triggered by DolphinView::setUrl()
560 * has been loaded.
561 */
562 void directoryLoadingCompleted();
563
564 /**
565 * Is emitted after the directory loading triggered by DolphinView::setUrl()
566 * has been canceled.
567 */
568 void directoryLoadingCanceled();
569
570 /**
571 * Is emitted after DolphinView::setUrl() has been invoked and provides
572 * the information how much percent of the current directory have been loaded.
573 */
574 void directoryLoadingProgress(int percent);
575
576 /**
577 * Is emitted if the sorting is done asynchronously and provides the
578 * progress information of the sorting.
579 */
580 void directorySortingProgress(int percent);
581
582 /**
583 * Emitted when the file-item-model emits redirection.
584 * Testcase: fish://localhost
585 */
586 void redirection(const QUrl &oldUrl, const QUrl &newUrl);
587
588 /**
589 * Is emitted when the URL set by DolphinView::setUrl() represents a file.
590 * In this case no signal errorMessage() will be emitted.
591 */
592 void urlIsFileError(const QUrl &url);
593
594 /**
595 * Is emitted when the write state of the folder has been changed. The application
596 * should disable all actions like "Create New..." that depend on the write
597 * state.
598 */
599 void writeStateChanged(bool isFolderWritable);
600
601 /**
602 * Is emitted if the URL should be changed to the previous URL of the
603 * history (e.g. because the "back"-mousebutton has been pressed).
604 */
605 void goBackRequested();
606
607 /**
608 * Is emitted if the URL should be changed to the next URL of the
609 * history (e.g. because the "next"-mousebutton has been pressed).
610 */
611 void goForwardRequested();
612
613 /**
614 * Used to request either entering or leaving of selection mode
615 * Entering is typically requested on press and hold.
616 * Leaving by pressing Escape when no item is selected.
617 */
618 void selectionModeChangeRequested(bool enabled);
619
620 /**
621 * Is emitted when the user wants to move the focus to another view.
622 */
623 void toggleActiveViewRequested();
624
625 /**
626 * Is emitted when the user clicks a tag or a link
627 * in the metadata widget of a tooltip.
628 */
629 void urlActivated(const QUrl &url);
630
631 void goUpRequested();
632
633 void fileItemsChanged(const KFileItemList &changedFileItems);
634
635 /**
636 * Emitted when the current directory of the model was removed.
637 */
638 void currentDirectoryRemoved();
639
640 protected:
641 /** Changes the zoom level if Control is pressed during a wheel event. */
642 void wheelEvent(QWheelEvent *event) override;
643
644 void hideEvent(QHideEvent *event) override;
645 bool event(QEvent *event) override;
646
647 private Q_SLOTS:
648 /**
649 * Marks the view as active (DolphinView:isActive() will return true)
650 * and emits the 'activated' signal if it is not already active.
651 */
652 void activate();
653
654 void slotItemActivated(int index);
655 void slotItemsActivated(const KItemSet &indexes);
656 void slotItemMiddleClicked(int index);
657 void slotItemContextMenuRequested(int index, const QPointF &pos);
658 void slotViewContextMenuRequested(const QPointF &pos);
659 void slotHeaderContextMenuRequested(const QPointF &pos);
660 void slotHeaderColumnWidthChangeFinished(const QByteArray &role, qreal current);
661 void slotSidePaddingWidthChanged(qreal width);
662 void slotItemHovered(int index);
663 void slotItemUnhovered(int index);
664 void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event);
665 void slotModelChanged(KItemModelBase *current, KItemModelBase *previous);
666 void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons);
667 void slotRenameDialogRenamingFinished(const QList<QUrl> &urls);
668 void slotSelectedItemTextPressed(int index);
669 void slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to);
670 void slotIncreaseZoom();
671 void slotDecreaseZoom();
672 void slotSwipeUp();
673
674 /*
675 * Is called when new items get pasted or dropped.
676 */
677 void slotItemCreated(const QUrl &url);
678 /*
679 * Is called after all pasted or dropped items have been copied to destination.
680 */
681 void slotJobResult(KJob *job);
682
683 /**
684 * Emits the signal \a selectionChanged() with a small delay. This is
685 * because getting all file items for the selection can be an expensive
686 * operation. Fast selection changes are collected in this case and
687 * the signal is emitted only after no selection change has been done
688 * within a small delay.
689 */
690 void slotSelectionChanged(const KItemSet &current, const KItemSet &previous);
691
692 /**
693 * Is called by emitDelayedSelectionChangedSignal() and emits the
694 * signal \a selectionChanged() with all selected file items as parameter.
695 */
696 void emitSelectionChangedSignal();
697
698 /**
699 * Helper method for DolphinView::requestStatusBarText().
700 * Calculates the amount of folders and files and their total size in
701 * response to a KStatJob::result(), then calls emitStatusBarText().
702 * @see requestStatusBarText()
703 * @see emitStatusBarText()
704 */
705 void slotStatJobResult(KJob *job);
706
707 /**
708 * Updates the view properties of the current URL to the
709 * sorting given by \a role.
710 */
711 void updateSortRole(const QByteArray &role);
712
713 /**
714 * Updates the view properties of the current URL to the
715 * sort order given by \a order.
716 */
717 void updateSortOrder(Qt::SortOrder order);
718
719 /**
720 * Updates the view properties of the current URL to the
721 * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst.
722 */
723 void updateSortFoldersFirst(bool foldersFirst);
724
725 /**
726 * Updates the view properties of the current URL to the
727 * sorting of hidden files given by \a hiddenLast.
728 */
729 void updateSortHiddenLast(bool hiddenLast);
730
731 /**
732 * Indicates in the status bar that the delete operation
733 * of the job \a job has been finished.
734 */
735 void slotDeleteFileFinished(KJob *job);
736
737 /**
738 * Indicates in the status bar that the trash operation
739 * of the job \a job has been finished.
740 */
741 void slotTrashFileFinished(KJob *job);
742
743 /**
744 * Invoked when the rename job is done, for error handling.
745 */
746 void slotRenamingResult(KJob *job);
747
748 /**
749 * Invoked when the file item model has started the loading
750 * of the directory specified by DolphinView::url().
751 */
752 void slotDirectoryLoadingStarted();
753
754 /**
755 * Invoked when the file item model indicates that the loading of a directory has
756 * been completed. Assures that pasted items and renamed items get selected.
757 */
758 void slotDirectoryLoadingCompleted();
759
760 /**
761 * Invoked when the file item model indicates that the loading of a directory has
762 * been canceled.
763 */
764 void slotDirectoryLoadingCanceled();
765
766 /**
767 * Is invoked when items of KFileItemModel have been changed.
768 */
769 void slotItemsChanged();
770
771 /**
772 * Is invoked when the sort order has been changed by the user by clicking
773 * on a header item. The view properties of the directory will get updated.
774 */
775 void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous);
776
777 /**
778 * Is invoked when the sort role has been changed by the user by clicking
779 * on a header item. The view properties of the directory will get updated.
780 */
781 void slotSortRoleChangedByHeader(const QByteArray &current, const QByteArray &previous);
782
783 /**
784 * Is invoked when the visible roles have been changed by the user by dragging
785 * a header item. The view properties of the directory will get updated.
786 */
787 void slotVisibleRolesChangedByHeader(const QList<QByteArray> &current, const QList<QByteArray> &previous);
788
789 void slotRoleEditingCanceled();
790 void slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value);
791
792 /**
793 * Observes the item with the URL \a url. As soon as the directory
794 * model indicates that the item is available, the item will
795 * get selected and it is assured that the item stays visible.
796 */
797 void observeCreatedItem(const QUrl &url);
798
799 /**
800 * Selects the next item after prev selection deleted/trashed
801 */
802 void selectNextItem();
803
804 /**
805 * Called when a redirection happens.
806 * Testcase: fish://localhost
807 */
808 void slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl);
809
810 void slotTwoClicksRenamingTimerTimeout();
811
812 private:
813 void loadDirectory(const QUrl &url, bool reload = false);
814
815 /**
816 * Applies the view properties which are defined by the current URL
817 * to the DolphinView properties. The view properties are read from a
818 * .directory file either in the current directory, or in the
819 * share/apps/dolphin/view_properties/ subfolder of the user's .kde folder.
820 */
821 void applyViewProperties();
822
823 /**
824 * Applies the given view properties to the DolphinView.
825 */
826 void applyViewProperties(const ViewProperties &props);
827
828 /**
829 * Applies the m_mode property to the corresponding
830 * itemlayout-property of the KItemListView.
831 */
832 void applyModeToView();
833
834 enum Selection { HasSelection, NoSelection };
835 /**
836 * Helper method for DolphinView::requestStatusBarText().
837 * Generates the status bar text from the parameters and
838 * then emits statusBarTextChanged().
839 * @param totalFileSize the sum of the sizes of the files
840 * @param selection if HasSelection is passed, the emitted status bar text will say
841 * that the folders and files which are counted here are selected.
842 */
843 void emitStatusBarText(const int folderCount, const int fileCount, KIO::filesize_t totalFileSize, const Selection selection);
844
845 /**
846 * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
847 * Pastes the clipboard data into the URL \a url.
848 */
849 void pasteToUrl(const QUrl &url);
850
851 /**
852 * Returns a list of URLs for all selected items. The list is
853 * simplified, so that when the URLs are part of different tree
854 * levels, only the parent is returned.
855 */
856 QList<QUrl> simplifiedSelectedUrls() const;
857
858 /**
859 * Returns the MIME data for all selected items.
860 */
861 QMimeData *selectionMimeData() const;
862
863 /**
864 * Updates m_isFolderWritable dependent on whether the folder represented by
865 * the current URL is writable. If the state has changed, the signal
866 * writeableStateChanged() will be emitted.
867 */
868 void updateWritableState();
869
870 /**
871 * @return The current URL if no viewproperties-context is given (see
872 * DolphinView::viewPropertiesContext(), otherwise the context
873 * is returned.
874 */
875 QUrl viewPropertiesUrl() const;
876
877 /**
878 * Clears the selection and updates current item and selection according to the parameters
879 *
880 * @param current URL to be set as current
881 * @param selected list of selected items
882 */
883 void forceUrlsSelection(const QUrl &current, const QList<QUrl> &selected);
884
885 void abortTwoClicksRenaming();
886
887 void updatePlaceholderLabel();
888
889 bool tryShowNameToolTip(QHelpEvent *event);
890
891 private:
892 void updatePalette();
893 void showLoadingPlaceholder();
894
895 bool m_active;
896 bool m_tabsForFiles;
897 bool m_assureVisibleCurrentIndex;
898 bool m_isFolderWritable;
899 bool m_dragging; // True if a dragging is done. Required to be able to decide whether a
900 // tooltip may be shown when hovering an item.
901 bool m_selectNextItem;
902
903 enum class LoadingState { Idle, Loading, Canceled, Completed };
904 LoadingState m_loadingState = LoadingState::Idle;
905
906 QUrl m_url;
907 QString m_viewPropertiesContext;
908 Mode m_mode;
909 QList<QByteArray> m_visibleRoles;
910
911 QPointer<KIO::StatJob> m_statJobForStatusBarText;
912
913 QVBoxLayout *m_topLayout;
914
915 KFileItemModel *m_model;
916 DolphinItemListView *m_view;
917 KItemListContainer *m_container;
918
919 ToolTipManager *m_toolTipManager;
920
921 QTimer *m_selectionChangedTimer;
922
923 QUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
924 bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not
925 QPoint m_restoredContentsPosition;
926
927 // Used for tracking the accumulated scroll amount (for zooming with high
928 // resolution scroll wheels)
929 int m_controlWheelAccumulatedDelta;
930
931 QList<QUrl> m_selectedUrls; // Used for making the view to remember selections after F5
932 bool m_clearSelectionBeforeSelectingNewItems;
933 bool m_markFirstNewlySelectedItemAsCurrent;
934
935 VersionControlObserver *m_versionControlObserver;
936
937 QTimer *m_twoClicksRenamingTimer;
938 QUrl m_twoClicksRenamingItemUrl;
939 QLabel *m_placeholderLabel;
940 QTimer *m_showLoadingPlaceholderTimer;
941
942 /// The information roleIndex of the list column header currently hovered
943 std::optional<int> m_hoveredColumnHearderRoleIndex;
944
945 /// Used for selection mode. @see setSelectionMode()
946 std::unique_ptr<QProxyStyle> m_proxyStyle;
947
948 // For unit tests
949 friend class TestBase;
950 friend class DolphinDetailsViewTest;
951 friend class DolphinMainWindowTest;
952 friend class DolphinPart; // Accesses m_model
953 };
954
955 /// Allow using DolphinView::Mode in QVariant
956 Q_DECLARE_METATYPE(DolphinView::Mode)
957
958 #endif // DOLPHINVIEW_H