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