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