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