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