]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinview.h
Merge remote-tracking branch 'fork/work/zakharafoniam/useful-groups'
[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 /**
377 * @returns the height of the scrollbar at the bottom of the view or zero if no such scroll bar is visible.
378 */
379 int horizontalScrollBarHeight() const;
380
381 /**
382 * Set the offset for any view items that small statusbar would otherwise
383 * cover. For example, in compact view this is used to make sure no
384 * item is covered by statusbar.
385 */
386 void setStatusBarOffset(int offset);
387
388 public Q_SLOTS:
389
390 void reload();
391
392 /**
393 * Changes the directory to \a url. If the current directory is equal to
394 * \a url, nothing will be done (use DolphinView::reload() instead).
395 */
396 void setUrl(const QUrl &url);
397
398 /**
399 * Selects all items.
400 * @see DolphinView::selectedItems()
401 */
402 void selectAll();
403
404 /**
405 * Inverts the current selection: selected items get unselected,
406 * unselected items get selected.
407 * @see DolphinView::selectedItems()
408 */
409 void invertSelection();
410
411 void clearSelection();
412
413 /**
414 * Triggers the renaming of the currently selected items, where
415 * the user must input a new name for the items.
416 */
417 void renameSelectedItems();
418
419 /**
420 * Moves all selected items to the trash.
421 */
422 void trashSelectedItems();
423
424 /**
425 * Deletes all selected items.
426 */
427 void deleteSelectedItems();
428
429 /**
430 * Copies all selected items to the clipboard and marks
431 * the items as cut.
432 */
433 void cutSelectedItemsToClipboard();
434
435 /** Copies all selected items to the clipboard. */
436 void copySelectedItemsToClipboard();
437
438 /**
439 * Copies all selected items to @p destinationUrl.
440 */
441 void copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl);
442
443 /**
444 * Moves all selected items to @p destinationUrl.
445 */
446 void moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl);
447
448 /** Pastes the clipboard data to this view. */
449 void paste();
450
451 /**
452 * Pastes the clipboard data into the currently selected
453 * folder. If the current selection is not exactly one folder, no
454 * paste operation is done.
455 */
456 void pasteIntoFolder();
457
458 /**
459 * Copies the path of the first selected KFileItem into Clipboard.
460 */
461 void copyPathToClipboard();
462
463 /**
464 * Creates duplicates of selected items, appending "copy"
465 * to the end.
466 */
467 void duplicateSelectedItems();
468
469 /**
470 * Handles a drop of @p dropEvent onto widget @p dropWidget and destination @p destUrl
471 */
472 void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget);
473
474 void stopLoading();
475
476 /**
477 * Applies the state that has been restored by restoreViewState()
478 * to the view.
479 */
480 void updateViewState();
481
482 Q_SIGNALS:
483 /**
484 * Is emitted if the view has been activated by e. g. a mouse click.
485 */
486 void activated();
487
488 /** Is emitted if the URL of the view has been changed to \a url. */
489 void urlChanged(const QUrl &url);
490
491 /**
492 * Is emitted when clicking on an item with the left mouse button.
493 */
494 void itemActivated(const KFileItem &item);
495
496 /**
497 * Is emitted when clicking on a file with the middle mouse button.
498 * @note: This will not be emitted for folders or file archives that will/can be opened like folders.
499 */
500 void fileMiddleClickActivated(const KFileItem &item);
501
502 /**
503 * Is emitted when multiple items have been activated by e. g.
504 * context menu open with.
505 */
506 void itemsActivated(const KFileItemList &items);
507
508 /**
509 * Is emitted if items have been added or deleted.
510 */
511 void itemCountChanged();
512
513 /**
514 * Is emitted if a new tab should be opened for the URL \a url.
515 */
516 void tabRequested(const QUrl &url);
517
518 /**
519 * Is emitted if a new tab should be opened for the URL \a url and set as active.
520 */
521 void activeTabRequested(const QUrl &url);
522
523 /**
524 * Is emitted if a new window should be opened for the URL \a url.
525 */
526 void windowRequested(const QUrl &url);
527
528 /**
529 * Is emitted if the view mode (IconsView, DetailsView,
530 * PreviewsView) has been changed.
531 */
532 void modeChanged(DolphinView::Mode current, DolphinView::Mode previous);
533
534 /** Is emitted if the 'show preview' property has been changed. */
535 void previewsShownChanged(bool shown);
536
537 /** Is emitted if the 'show hidden files' property has been changed. */
538 void hiddenFilesShownChanged(bool shown);
539
540 /** Is emitted if the 'grouped sorting' property has been changed. */
541 void groupedSortingChanged(bool groupedSorting);
542
543 /** Is emitted in reaction to a requestStatusBarText() call.
544 * @see requestStatusBarText() */
545 void statusBarTextChanged(QString statusBarText);
546
547 /** Is emitted if the sorting by name, size or date has been changed. */
548 void sortRoleChanged(const QByteArray &role);
549
550 /** Is emitted if the sort order (ascending or descending) has been changed. */
551 void sortOrderChanged(Qt::SortOrder order);
552
553 /** Is emitted if the grouping by name, size or date has been changed. */
554 void groupRoleChanged(const QByteArray &role);
555
556 /** Is emitted if the group order (ascending or descending) has been changed. */
557 void groupOrderChanged(Qt::SortOrder order);
558
559 /**
560 * Is emitted if the sorting of files and folders (separate with folders
561 * first or mixed) has been changed.
562 */
563 void sortFoldersFirstChanged(bool foldersFirst);
564
565 /**
566 * Is emitted if the sorting of hidden files has been changed.
567 */
568 void sortHiddenLastChanged(bool hiddenLast);
569
570 /** Is emitted if the additional information shown for this view has been changed. */
571 void visibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous);
572
573 /** Is emitted if the zoom level has been changed by zooming in or out. */
574 void zoomLevelChanged(int current, int previous);
575
576 /**
577 * Is emitted if information of an item is requested to be shown e. g. in the panel.
578 * If item is null, no item information request is pending.
579 */
580 void requestItemInfo(const KFileItem &item);
581
582 /**
583 * Is emitted whenever the selection has been changed.
584 */
585 void selectionChanged(const KFileItemList &selection);
586
587 /**
588 * Is emitted if a context menu is requested for the item \a item,
589 * which is part of \a url. If the item is null, the context menu
590 * for the URL should be shown.
591 */
592 void requestContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url);
593
594 /**
595 * Is emitted if an information message with the content \a msg
596 * should be shown.
597 */
598 void infoMessage(const QString &msg);
599
600 /**
601 * Is emitted if an error message with the content \a msg
602 * should be shown.
603 */
604 void errorMessage(const QString &message, const int kioErrorCode);
605
606 /**
607 * Is emitted if an "operation completed" message with the content \a msg
608 * should be shown.
609 */
610 void operationCompletedMessage(const QString &msg);
611
612 /**
613 * Is emitted after DolphinView::setUrl() has been invoked and
614 * the current directory is loaded. If this signal is emitted,
615 * it is assured that the view contains already the correct root
616 * URL and property settings.
617 */
618 void directoryLoadingStarted();
619
620 /**
621 * Is emitted after the directory triggered by DolphinView::setUrl()
622 * has been loaded.
623 */
624 void directoryLoadingCompleted();
625
626 /**
627 * Is emitted after the directory loading triggered by DolphinView::setUrl()
628 * has been canceled.
629 */
630 void directoryLoadingCanceled();
631
632 /**
633 * Is emitted after DolphinView::setUrl() has been invoked and provides
634 * the information how much percent of the current directory have been loaded.
635 */
636 void directoryLoadingProgress(int percent);
637
638 /**
639 * Is emitted if the sorting is done asynchronously and provides the
640 * progress information of the sorting.
641 */
642 void directorySortingProgress(int percent);
643
644 /**
645 * Emitted when the file-item-model emits redirection.
646 * Testcase: fish://localhost
647 */
648 void redirection(const QUrl &oldUrl, const QUrl &newUrl);
649
650 /**
651 * Is emitted when the URL set by DolphinView::setUrl() represents a file.
652 * In this case no signal errorMessage() will be emitted.
653 */
654 void urlIsFileError(const QUrl &url);
655
656 /**
657 * Is emitted when the write state of the folder has been changed. The application
658 * should disable all actions like "Create New..." that depend on the write
659 * state.
660 */
661 void writeStateChanged(bool isFolderWritable);
662
663 /**
664 * Is emitted if the URL should be changed to the previous URL of the
665 * history (e.g. because the "back"-mousebutton has been pressed).
666 */
667 void goBackRequested();
668
669 /**
670 * Is emitted if the URL should be changed to the next URL of the
671 * history (e.g. because the "next"-mousebutton has been pressed).
672 */
673 void goForwardRequested();
674
675 /**
676 * Used to request either entering or leaving of selection mode
677 * Entering is typically requested on press and hold.
678 * Leaving by pressing Escape when no item is selected.
679 */
680 void selectionModeChangeRequested(bool enabled);
681
682 /**
683 * Is emitted when the user wants to move the focus to another view.
684 */
685 void toggleActiveViewRequested();
686
687 /**
688 * Is emitted when the user clicks a tag or a link
689 * in the metadata widget of a tooltip.
690 */
691 void urlActivated(const QUrl &url);
692
693 void goUpRequested();
694
695 void fileItemsChanged(const KFileItemList &changedFileItems);
696
697 /**
698 * Emitted when the current directory of the model was removed.
699 */
700 void currentDirectoryRemoved();
701
702 /**
703 * Emitted when the view's background is double-clicked.
704 * Used to trigger an user configured action.
705 */
706 void doubleClickViewBackground(Qt::MouseButton button);
707
708 protected:
709 /** Changes the zoom level if Control is pressed during a wheel event. */
710 void wheelEvent(QWheelEvent *event) override;
711
712 void hideEvent(QHideEvent *event) override;
713 bool event(QEvent *event) override;
714
715 private Q_SLOTS:
716 /**
717 * Marks the view as active (DolphinView:isActive() will return true)
718 * and emits the 'activated' signal if it is not already active.
719 */
720 void activate();
721
722 void slotItemActivated(int index);
723 void slotItemsActivated(const KItemSet &indexes);
724 void slotItemMiddleClicked(int index);
725 void slotItemContextMenuRequested(int index, const QPointF &pos);
726 void slotViewContextMenuRequested(const QPointF &pos);
727 void slotHeaderContextMenuRequested(const QPointF &pos);
728 void slotHeaderColumnWidthChangeFinished(const QByteArray &role, qreal current);
729 void slotSidePaddingWidthChanged(qreal leftPaddingWidth, qreal rightPaddingWidth);
730 void slotItemHovered(int index);
731 void slotItemUnhovered(int index);
732 void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event);
733 void slotModelChanged(KItemModelBase *current, KItemModelBase *previous);
734 void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons);
735 void slotSelectedItemTextPressed(int index);
736 void slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to);
737 void slotItemLinkCreatedFromJob(KIO::Job *, const QUrl &, const QString &, const QUrl &to);
738 void slotIncreaseZoom();
739 void slotDecreaseZoom();
740 void slotSwipeUp();
741
742 /*
743 * Is called when new items get pasted or dropped.
744 */
745 void slotItemCreated(const QUrl &url);
746 /*
747 * Is called after all pasted or dropped items have been copied to destination.
748 */
749 void slotJobResult(KJob *job);
750
751 /**
752 * Emits the signal \a selectionChanged() with a small delay. This is
753 * because getting all file items for the selection can be an expensive
754 * operation. Fast selection changes are collected in this case and
755 * the signal is emitted only after no selection change has been done
756 * within a small delay.
757 */
758 void slotSelectionChanged(const KItemSet &current, const KItemSet &previous);
759
760 /**
761 * Is called by emitDelayedSelectionChangedSignal() and emits the
762 * signal \a selectionChanged() with all selected file items as parameter.
763 */
764 void emitSelectionChangedSignal();
765
766 /**
767 * Helper method for DolphinView::requestStatusBarText().
768 * Calculates the amount of folders and files and their total size in
769 * response to a KStatJob::result(), then calls emitStatusBarText().
770 * @see requestStatusBarText()
771 * @see emitStatusBarText()
772 */
773 void slotStatJobResult(KJob *job);
774
775 /**
776 * Updates the view properties of the current URL to the
777 * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst.
778 */
779 void updateSortFoldersFirst(bool foldersFirst);
780
781 /**
782 * Updates the view properties of the current URL to the
783 * sorting of hidden files given by \a hiddenLast.
784 */
785 void updateSortHiddenLast(bool hiddenLast);
786
787 /**
788 * Indicates in the status bar that the delete operation
789 * of the job \a job has been finished.
790 */
791 void slotDeleteFileFinished(KJob *job);
792
793 /**
794 * Indicates in the status bar that the trash operation
795 * of the job \a job has been finished.
796 */
797 void slotTrashFileFinished(KJob *job);
798
799 /**
800 * Invoked when the rename job is done, for error handling.
801 */
802 void slotRenamingResult(KJob *job);
803
804 /**
805 * Invoked when the file item model has started the loading
806 * of the directory specified by DolphinView::url().
807 */
808 void slotDirectoryLoadingStarted();
809
810 /**
811 * Invoked when the file item model indicates that the loading of a directory has
812 * been completed. Assures that pasted items and renamed items get selected.
813 */
814 void slotDirectoryLoadingCompleted();
815
816 /**
817 * Invoked when the file item model indicates that the loading of a directory has
818 * been canceled.
819 */
820 void slotDirectoryLoadingCanceled();
821
822 /**
823 * Is invoked when items of KFileItemModel have been changed.
824 */
825 void slotItemsChanged();
826
827 /**
828 * Is invoked when the sort order has been changed by the user by clicking
829 * on a header item. The view properties of the directory will get updated.
830 */
831 void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous);
832
833 /**
834 * Is invoked when the sort role has been changed by the user by clicking
835 * on a header item. The view properties of the directory will get updated.
836 */
837 void slotSortRoleChangedByHeader(const QByteArray &current, const QByteArray &previous);
838
839 /**
840 * Is invoked when the visible roles have been changed by the user by dragging
841 * a header item. The view properties of the directory will get updated.
842 */
843 void slotVisibleRolesChangedByHeader(const QList<QByteArray> &current, const QList<QByteArray> &previous);
844
845 void slotRoleEditingCanceled();
846 void slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value);
847
848 /**
849 * Observes the item with the URL \a url. As soon as the directory
850 * model indicates that the item is available, the item will
851 * get selected and it is assured that the item stays visible.
852 */
853 void observeCreatedItem(const QUrl &url);
854
855 /**
856 * Selects the next item after prev selection deleted/trashed
857 */
858 void selectNextItem();
859
860 /**
861 * Called when a redirection happens.
862 * Testcase: fish://localhost
863 */
864 void slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl);
865
866 void slotTwoClicksRenamingTimerTimeout();
867
868 void onDirectoryLoadingCompletedAfterJob();
869
870 private:
871 void loadDirectory(const QUrl &url, bool reload = false);
872
873 /**
874 * Applies the view properties which are defined by the current URL
875 * to the DolphinView properties. The view properties are read from a
876 * .directory file either in the current directory, or in the
877 * share/apps/dolphin/view_properties/ subfolder of the user's .kde folder.
878 */
879 void applyViewProperties();
880
881 /**
882 * Applies the given view properties to the DolphinView.
883 */
884 void applyViewProperties(const ViewProperties &props);
885
886 /**
887 * Applies the m_mode property to the corresponding
888 * itemlayout-property of the KItemListView.
889 */
890 void applyModeToView();
891
892 /**
893 * Changes the current view based on the content of the directory.
894 */
895 void applyDynamicView();
896
897 enum Selection { HasSelection, NoSelection };
898 /**
899 * Helper method for DolphinView::requestStatusBarText().
900 * Generates the status bar text from the parameters and
901 * then emits statusBarTextChanged().
902 * @param totalFileSize the sum of the sizes of the files
903 * @param selection if HasSelection is passed, the emitted status bar text will say
904 * that the folders and files which are counted here are selected.
905 */
906 void emitStatusBarText(const int folderCount, const int fileCount, KIO::filesize_t totalFileSize, const Selection selection);
907
908 /**
909 * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
910 * Pastes the clipboard data into the URL \a url.
911 */
912 void pasteToUrl(const QUrl &url);
913
914 /**
915 * Returns a list of URLs for all selected items. The list is
916 * simplified, so that when the URLs are part of different tree
917 * levels, only the parent is returned.
918 */
919 QList<QUrl> simplifiedSelectedUrls() const;
920
921 /**
922 * Returns the MIME data for all selected items.
923 */
924 QMimeData *selectionMimeData() const;
925
926 /**
927 * Updates m_isFolderWritable dependent on whether the folder represented by
928 * the current URL is writable. If the state has changed, the signal
929 * writeStateChanged() will be emitted.
930 */
931 void updateWritableState();
932
933 /**
934 * @return The current URL if no viewproperties-context is given (see
935 * DolphinView::viewPropertiesContext(), otherwise the context
936 * is returned.
937 */
938 QUrl viewPropertiesUrl() const;
939
940 /**
941 * Clears the selection and updates current item and selection according to the parameters
942 *
943 * @param current URL to be set as current
944 * @param selected list of selected items
945 */
946 void forceUrlsSelection(const QUrl &current, const QList<QUrl> &selected);
947
948 void abortTwoClicksRenaming();
949
950 void updatePlaceholderLabel();
951
952 bool tryShowNameToolTip(QHelpEvent *event);
953
954 private:
955 void updatePalette();
956 void showLoadingPlaceholder();
957
958 bool m_active;
959 bool m_tabsForFiles;
960 bool m_assureVisibleCurrentIndex;
961 bool m_isFolderWritable;
962 bool m_dragging; // True if a dragging is done. Required to be able to decide whether a
963 // tooltip may be shown when hovering an item.
964 bool m_selectNextItem;
965
966 enum class LoadingState { Idle, Loading, Canceled, Completed };
967 LoadingState m_loadingState = LoadingState::Idle;
968
969 QUrl m_url;
970 QString m_viewPropertiesContext;
971 Mode m_mode;
972 QList<QByteArray> m_visibleRoles;
973
974 QPointer<KIO::StatJob> m_statJobForStatusBarText;
975
976 QVBoxLayout *m_topLayout;
977
978 KFileItemModel *m_model;
979 DolphinItemListView *m_view;
980 KItemListContainer *m_container;
981
982 ToolTipManager *m_toolTipManager;
983
984 QTimer *m_selectionChangedTimer;
985
986 QUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
987 bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not
988 QPoint m_restoredContentsPosition;
989
990 // Used for tracking the accumulated scroll amount (for zooming with high
991 // resolution scroll wheels)
992 int m_controlWheelAccumulatedDelta;
993
994 QList<QUrl> m_selectedUrls; // Used for making the view to remember selections after F5 and file operations
995 bool m_clearSelectionBeforeSelectingNewItems;
996 bool m_markFirstNewlySelectedItemAsCurrent;
997 /// Decides whether items created by jobs should automatically be selected.
998 bool m_selectJobCreatedItems;
999
1000 VersionControlObserver *m_versionControlObserver;
1001
1002 QTimer *m_twoClicksRenamingTimer;
1003 QUrl m_twoClicksRenamingItemUrl;
1004 QLabel *m_placeholderLabel;
1005 QTimer *m_showLoadingPlaceholderTimer;
1006
1007 /// The information roleIndex of the list column header currently hovered
1008 std::optional<int> m_hoveredColumnHeaderIndex;
1009
1010 /// Used for selection mode. @see setSelectionMode()
1011 std::unique_ptr<QProxyStyle> m_proxyStyle;
1012
1013 // For unit tests
1014 friend class TestBase;
1015 friend class DolphinDetailsViewTest;
1016 friend class DolphinMainWindowTest;
1017 friend class DolphinPart; // Accesses m_model
1018 void updateSelectionState();
1019 };
1020
1021 /// Allow using DolphinView::Mode in QVariant
1022 Q_DECLARE_METATYPE(DolphinView::Mode)
1023
1024 #endif // DOLPHINVIEW_H