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