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