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