File indexing completed on 2024-05-05 10:08:00
0001 /* 0002 * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com> 0003 * SPDX-FileCopyrightText: 2006 Gregor Kališnik <gregor@podnapisi.net> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef DOLPHINVIEW_H 0009 #define DOLPHINVIEW_H 0010 0011 #include "dolphin_export.h" 0012 #include "dolphintabwidget.h" 0013 #include "tooltips/tooltipmanager.h" 0014 0015 #include "config-dolphin.h" 0016 #include <KFileItem> 0017 #include <KIO/StatJob> 0018 #include <kio/fileundomanager.h> 0019 #include <kparts/part.h> 0020 0021 #include <QMimeData> 0022 #include <QPointer> 0023 #include <QUrl> 0024 #include <QWidget> 0025 0026 #include <memory> 0027 0028 typedef KIO::FileUndoManager::CommandType CommandType; 0029 class QVBoxLayout; 0030 class DolphinItemListView; 0031 class KFileItemModel; 0032 class KItemListContainer; 0033 class KItemModelBase; 0034 class KItemSet; 0035 class ToolTipManager; 0036 class VersionControlObserver; 0037 class ViewProperties; 0038 class QLabel; 0039 class QGraphicsSceneDragDropEvent; 0040 class QHelpEvent; 0041 class QProxyStyle; 0042 class QRegularExpression; 0043 0044 /** 0045 * @short Represents a view for the directory content. 0046 * 0047 * View modes for icons, compact and details are supported. It's 0048 * possible to adjust: 0049 * - sort order 0050 * - sort type 0051 * - show hidden files 0052 * - show previews 0053 * - enable grouping 0054 */ 0055 class DOLPHIN_EXPORT DolphinView : public QWidget 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 /** 0061 * Defines the view mode for a directory. The 0062 * view mode is automatically updated if the directory itself 0063 * defines a view mode (see class ViewProperties for details). 0064 */ 0065 enum Mode { 0066 /** 0067 * The items are shown as icons with a name-label below. 0068 */ 0069 IconsView = 0, 0070 0071 /** 0072 * The icon, the name and the size of the items are 0073 * shown per default as a table. 0074 */ 0075 DetailsView, 0076 0077 /** 0078 * The items are shown as icons with the name-label aligned 0079 * to the right side. 0080 */ 0081 CompactView 0082 }; 0083 0084 /** 0085 * @param url Specifies the content which should be shown. 0086 * @param parent Parent widget of the view. 0087 */ 0088 DolphinView(const QUrl &url, QWidget *parent); 0089 0090 ~DolphinView() override; 0091 0092 /** 0093 * Returns the current active URL, where all actions are applied. 0094 * The URL navigator is synchronized with this URL. 0095 */ 0096 QUrl url() const; 0097 0098 /** 0099 * If \a active is true, the view will marked as active. The active 0100 * view is defined as view where all actions are applied to. 0101 */ 0102 void setActive(bool active); 0103 bool isActive() const; 0104 0105 /** 0106 * Changes the view mode for the current directory to \a mode. 0107 * If the view properties should be remembered for each directory 0108 * (GeneralSettings::globalViewProps() returns false), then the 0109 * changed view mode will be stored automatically. 0110 */ 0111 void setViewMode(Mode mode); 0112 Mode viewMode() const; 0113 0114 /** 0115 * Enables or disables a mode for quick and easy selection of items. 0116 */ 0117 void setSelectionModeEnabled(bool enabled); 0118 bool selectionMode() const; 0119 0120 /** 0121 * Turns on the file preview for the all files of the current directory, 0122 * if \a show is true. 0123 * If the view properties should be remembered for each directory 0124 * (GeneralSettings::globalViewProps() returns false), then the 0125 * preview setting will be stored automatically. 0126 */ 0127 void setPreviewsShown(bool show); 0128 bool previewsShown() const; 0129 0130 /** 0131 * Shows all hidden files of the current directory, 0132 * if \a show is true. 0133 * If the view properties should be remembered for each directory 0134 * (GeneralSettings::globalViewProps() returns false), then the 0135 * show hidden file setting will be stored automatically. 0136 */ 0137 void setHiddenFilesShown(bool show); 0138 bool hiddenFilesShown() const; 0139 0140 /** 0141 * Turns on sorting by groups if \a enable is true. 0142 */ 0143 void setGroupedSorting(bool grouped); 0144 bool groupedSorting() const; 0145 0146 /** 0147 * Returns the items of the view. 0148 */ 0149 KFileItemList items() const; 0150 0151 /** 0152 * @return The number of items. itemsCount() is faster in comparison 0153 * to items().count(). 0154 */ 0155 int itemsCount() const; 0156 0157 /** 0158 * Returns the selected items. The list is empty if no item has been 0159 * selected. 0160 */ 0161 KFileItemList selectedItems() const; 0162 0163 /** 0164 * Returns the number of selected items (this is faster than 0165 * invoking selectedItems().count()). 0166 */ 0167 int selectedItemsCount() const; 0168 0169 /** 0170 * Marks the items indicated by \p urls to get selected after the 0171 * directory DolphinView::url() has been loaded. Note that nothing 0172 * gets selected if no loading of a directory has been triggered 0173 * by DolphinView::setUrl() or DolphinView::reload(). 0174 */ 0175 void markUrlsAsSelected(const QList<QUrl> &urls); 0176 0177 /** 0178 * Marks the item indicated by \p url to be scrolled to and as the 0179 * current item after directory DolphinView::url() has been loaded. 0180 */ 0181 void markUrlAsCurrent(const QUrl &url); 0182 0183 /** 0184 * All items that match the regular expression \a regexp will get selected 0185 * if \a enabled is true and deselected if \a enabled is false. 0186 * 0187 * Note that to match the whole string the pattern should be anchored: 0188 * - you can anchor the pattern with QRegularExpression::anchoredPattern() 0189 * - if you use QRegularExpresssion::wildcardToRegularExpression(), don't use 0190 * QRegularExpression::anchoredPattern() as the former already returns an 0191 * anchored pattern 0192 */ 0193 void selectItems(const QRegularExpression ®exp, bool enabled); 0194 0195 /** 0196 * Sets the zoom level to \a level. It is assured that the used 0197 * level is adjusted to be inside the range ZoomLevelInfo::minimumLevel() and 0198 * ZoomLevelInfo::maximumLevel(). 0199 */ 0200 void setZoomLevel(int level); 0201 int zoomLevel() const; 0202 0203 /** 0204 * Resets the view's icon size to the default value 0205 */ 0206 void resetZoomLevel(); 0207 0208 void setSortRole(const QByteArray &role); 0209 QByteArray sortRole() const; 0210 0211 void setSortOrder(Qt::SortOrder order); 0212 Qt::SortOrder sortOrder() const; 0213 0214 /** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */ 0215 void setSortFoldersFirst(bool foldersFirst); 0216 bool sortFoldersFirst() const; 0217 0218 /** Sets a separate sorting with hidden files and folders last (true) or not (false). */ 0219 void setSortHiddenLast(bool hiddenLast); 0220 bool sortHiddenLast() const; 0221 0222 /** Sets the additional information which should be shown for the items. */ 0223 void setVisibleRoles(const QList<QByteArray> &roles); 0224 0225 /** Returns the additional information which should be shown for the items. */ 0226 QList<QByteArray> visibleRoles() const; 0227 0228 /** 0229 * Refreshes the view to get synchronized with the settings (e.g. icons size, 0230 * font, ...). 0231 */ 0232 void readSettings(); 0233 0234 /** 0235 * Saves the current settings (e.g. icons size, font, ..). 0236 */ 0237 void writeSettings(); 0238 0239 /** 0240 * Filters the currently shown items by \a nameFilter. All items 0241 * which contain the given filter string will be shown. 0242 */ 0243 void setNameFilter(const QString &nameFilter); 0244 QString nameFilter() const; 0245 0246 /** 0247 * Filters the currently shown items by \a filters. All items 0248 * whose content-type matches those given by the list of filters 0249 * will be shown. 0250 */ 0251 void setMimeTypeFilters(const QStringList &filters); 0252 QStringList mimeTypeFilters() const; 0253 0254 /** 0255 * Tells the view to generate an updated status bar text. The result 0256 * is returned through the statusBarTextChanged(QString statusBarText) signal. 0257 * It will carry a textual representation of the state of the current 0258 * folder or selected items, suitable for use in the status bar. 0259 * Any pending requests of status bar text are killed. 0260 */ 0261 void requestStatusBarText(); 0262 0263 /** 0264 * Returns the version control actions that are provided for the items \p items. 0265 * Usually the actions are presented in the context menu. 0266 */ 0267 QList<QAction *> versionControlActions(const KFileItemList &items) const; 0268 0269 /** 0270 * Returns the state of the paste action: 0271 * first is whether the action should be enabled 0272 * second is the text for the action 0273 */ 0274 QPair<bool, QString> pasteInfo() const; 0275 0276 /** 0277 * If \a tabsForFiles is true, the signal tabRequested() will also 0278 * emitted also for files. Per default tabs for files is disabled 0279 * and hence the signal tabRequested() will only be emitted for 0280 * directories. 0281 */ 0282 void setTabsForFilesEnabled(bool tabsForFiles); 0283 bool isTabsForFilesEnabled() const; 0284 0285 /** 0286 * Returns true if the current view allows folders to be expanded, 0287 * i.e. presents a hierarchical view to the user. 0288 */ 0289 bool itemsExpandable() const; 0290 0291 /** 0292 * @returns true if the @p item is one of the items() of this view and 0293 * is currently expanded. false otherwise. 0294 * Only directories in view modes that allow expanding can ever be expanded. 0295 */ 0296 bool isExpanded(const KFileItem &item) const; 0297 0298 /** 0299 * Restores the view state (current item, contents position, details view expansion state) 0300 */ 0301 void restoreState(QDataStream &stream); 0302 0303 /** 0304 * Saves the view state (current item, contents position, details view expansion state) 0305 */ 0306 void saveState(QDataStream &stream); 0307 0308 /** 0309 * Returns the root item which represents the current URL. 0310 */ 0311 KFileItem rootItem() const; 0312 0313 /** 0314 * Sets a context that is used for remembering the view-properties. 0315 * Per default the context is empty and the path of the currently set URL 0316 * is used for remembering the view-properties. Setting a custom context 0317 * makes sense if specific types of URLs (e.g. search-URLs) should 0318 * share common view-properties. 0319 */ 0320 void setViewPropertiesContext(const QString &context); 0321 QString viewPropertiesContext() const; 0322 0323 /** 0324 * Checks if the given \a item can be opened as folder (e.g. archives). 0325 * This function will also adjust the \a url (e.g. change the protocol). 0326 * @return a valid and adjusted url if the item can be opened as folder, 0327 * otherwise return an empty url. 0328 */ 0329 static QUrl openItemAsFolderUrl(const KFileItem &item, const bool browseThroughArchives = true); 0330 0331 /** 0332 * Hides tooltip displayed over element. 0333 */ 0334 void hideToolTip(const ToolTipManager::HideBehavior behavior = ToolTipManager::HideBehavior::Later); 0335 0336 /** 0337 * Check if the space key should be handled as a normal key, even if it's 0338 * used as a keyboard shortcut. 0339 * 0340 * See BUG 465489 0341 */ 0342 bool handleSpaceAsNormalKey() const; 0343 0344 /** Activates the view if the item list container gets focus. */ 0345 bool eventFilter(QObject *watched, QEvent *event) override; 0346 0347 /** 0348 * Returns whether the folder represented by the current URL is writable. 0349 */ 0350 bool isFolderWritable() const; 0351 0352 public Q_SLOTS: 0353 0354 void reload(); 0355 0356 /** 0357 * Changes the directory to \a url. If the current directory is equal to 0358 * \a url, nothing will be done (use DolphinView::reload() instead). 0359 */ 0360 void setUrl(const QUrl &url); 0361 0362 /** 0363 * Selects all items. 0364 * @see DolphinView::selectedItems() 0365 */ 0366 void selectAll(); 0367 0368 /** 0369 * Inverts the current selection: selected items get unselected, 0370 * unselected items get selected. 0371 * @see DolphinView::selectedItems() 0372 */ 0373 void invertSelection(); 0374 0375 void clearSelection(); 0376 0377 /** 0378 * Triggers the renaming of the currently selected items, where 0379 * the user must input a new name for the items. 0380 */ 0381 void renameSelectedItems(); 0382 0383 /** 0384 * Moves all selected items to the trash. 0385 */ 0386 void trashSelectedItems(); 0387 0388 /** 0389 * Deletes all selected items. 0390 */ 0391 void deleteSelectedItems(); 0392 0393 /** 0394 * Copies all selected items to the clipboard and marks 0395 * the items as cut. 0396 */ 0397 void cutSelectedItemsToClipboard(); 0398 0399 /** Copies all selected items to the clipboard. */ 0400 void copySelectedItemsToClipboard(); 0401 0402 /** 0403 * Copies all selected items to @p destinationUrl. 0404 */ 0405 void copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl); 0406 0407 /** 0408 * Moves all selected items to @p destinationUrl. 0409 */ 0410 void moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl); 0411 0412 /** Pastes the clipboard data to this view. */ 0413 void paste(); 0414 0415 /** 0416 * Pastes the clipboard data into the currently selected 0417 * folder. If the current selection is not exactly one folder, no 0418 * paste operation is done. 0419 */ 0420 void pasteIntoFolder(); 0421 0422 /** 0423 * Copies the path of the first selected KFileItem into Clipboard. 0424 */ 0425 void copyPathToClipboard(); 0426 0427 /** 0428 * Creates duplicates of selected items, appending "copy" 0429 * to the end. 0430 */ 0431 void duplicateSelectedItems(); 0432 0433 /** 0434 * Handles a drop of @p dropEvent onto widget @p dropWidget and destination @p destUrl 0435 */ 0436 void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget); 0437 0438 void stopLoading(); 0439 0440 /** 0441 * Applies the state that has been restored by restoreViewState() 0442 * to the view. 0443 */ 0444 void updateViewState(); 0445 0446 Q_SIGNALS: 0447 /** 0448 * Is emitted if the view has been activated by e. g. a mouse click. 0449 */ 0450 void activated(); 0451 0452 /** Is emitted if the URL of the view has been changed to \a url. */ 0453 void urlChanged(const QUrl &url); 0454 0455 /** 0456 * Is emitted when clicking on an item with the left mouse button. 0457 */ 0458 void itemActivated(const KFileItem &item); 0459 0460 /** 0461 * Is emitted when clicking on a file with the middle mouse button. 0462 * @note: This will not be emitted for folders or file archives that will/can be opened like folders. 0463 */ 0464 void fileMiddleClickActivated(const KFileItem &item); 0465 0466 /** 0467 * Is emitted when multiple items have been activated by e. g. 0468 * context menu open with. 0469 */ 0470 void itemsActivated(const KFileItemList &items); 0471 0472 /** 0473 * Is emitted if items have been added or deleted. 0474 */ 0475 void itemCountChanged(); 0476 0477 /** 0478 * Is emitted if a new tab should be opened for the URL \a url. 0479 */ 0480 void tabRequested(const QUrl &url); 0481 0482 /** 0483 * Is emitted if a new tab should be opened for the URL \a url and set as active. 0484 */ 0485 void activeTabRequested(const QUrl &url); 0486 0487 /** 0488 * Is emitted if a new window should be opened for the URL \a url. 0489 */ 0490 void windowRequested(const QUrl &url); 0491 0492 /** 0493 * Is emitted if the view mode (IconsView, DetailsView, 0494 * PreviewsView) has been changed. 0495 */ 0496 void modeChanged(DolphinView::Mode current, DolphinView::Mode previous); 0497 0498 /** Is emitted if the 'show preview' property has been changed. */ 0499 void previewsShownChanged(bool shown); 0500 0501 /** Is emitted if the 'show hidden files' property has been changed. */ 0502 void hiddenFilesShownChanged(bool shown); 0503 0504 /** Is emitted if the 'grouped sorting' property has been changed. */ 0505 void groupedSortingChanged(bool groupedSorting); 0506 0507 /** Is emitted in reaction to a requestStatusBarText() call. 0508 * @see requestStatusBarText() */ 0509 void statusBarTextChanged(QString statusBarText); 0510 0511 /** Is emitted if the sorting by name, size or date has been changed. */ 0512 void sortRoleChanged(const QByteArray &role); 0513 0514 /** Is emitted if the sort order (ascending or descending) has been changed. */ 0515 void sortOrderChanged(Qt::SortOrder order); 0516 0517 /** 0518 * Is emitted if the sorting of files and folders (separate with folders 0519 * first or mixed) has been changed. 0520 */ 0521 void sortFoldersFirstChanged(bool foldersFirst); 0522 0523 /** 0524 * Is emitted if the sorting of hidden files has been changed. 0525 */ 0526 void sortHiddenLastChanged(bool hiddenLast); 0527 0528 /** Is emitted if the additional information shown for this view has been changed. */ 0529 void visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); 0530 0531 /** Is emitted if the zoom level has been changed by zooming in or out. */ 0532 void zoomLevelChanged(int current, int previous); 0533 0534 /** 0535 * Is emitted if information of an item is requested to be shown e. g. in the panel. 0536 * If item is null, no item information request is pending. 0537 */ 0538 void requestItemInfo(const KFileItem &item); 0539 0540 /** 0541 * Is emitted whenever the selection has been changed. 0542 */ 0543 void selectionChanged(const KFileItemList &selection); 0544 0545 /** 0546 * Is emitted if a context menu is requested for the item \a item, 0547 * which is part of \a url. If the item is null, the context menu 0548 * for the URL should be shown. 0549 */ 0550 void requestContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url); 0551 0552 /** 0553 * Is emitted if an information message with the content \a msg 0554 * should be shown. 0555 */ 0556 void infoMessage(const QString &msg); 0557 0558 /** 0559 * Is emitted if an error message with the content \a msg 0560 * should be shown. 0561 */ 0562 void errorMessage(const QString &msg); 0563 0564 /** 0565 * Is emitted if an "operation completed" message with the content \a msg 0566 * should be shown. 0567 */ 0568 void operationCompletedMessage(const QString &msg); 0569 0570 /** 0571 * Is emitted after DolphinView::setUrl() has been invoked and 0572 * the current directory is loaded. If this signal is emitted, 0573 * it is assured that the view contains already the correct root 0574 * URL and property settings. 0575 */ 0576 void directoryLoadingStarted(); 0577 0578 /** 0579 * Is emitted after the directory triggered by DolphinView::setUrl() 0580 * has been loaded. 0581 */ 0582 void directoryLoadingCompleted(); 0583 0584 /** 0585 * Is emitted after the directory loading triggered by DolphinView::setUrl() 0586 * has been canceled. 0587 */ 0588 void directoryLoadingCanceled(); 0589 0590 /** 0591 * Is emitted after DolphinView::setUrl() has been invoked and provides 0592 * the information how much percent of the current directory have been loaded. 0593 */ 0594 void directoryLoadingProgress(int percent); 0595 0596 /** 0597 * Is emitted if the sorting is done asynchronously and provides the 0598 * progress information of the sorting. 0599 */ 0600 void directorySortingProgress(int percent); 0601 0602 /** 0603 * Emitted when the file-item-model emits redirection. 0604 * Testcase: fish://localhost 0605 */ 0606 void redirection(const QUrl &oldUrl, const QUrl &newUrl); 0607 0608 /** 0609 * Is emitted when the URL set by DolphinView::setUrl() represents a file. 0610 * In this case no signal errorMessage() will be emitted. 0611 */ 0612 void urlIsFileError(const QUrl &url); 0613 0614 /** 0615 * Is emitted when the write state of the folder has been changed. The application 0616 * should disable all actions like "Create New..." that depend on the write 0617 * state. 0618 */ 0619 void writeStateChanged(bool isFolderWritable); 0620 0621 /** 0622 * Is emitted if the URL should be changed to the previous URL of the 0623 * history (e.g. because the "back"-mousebutton has been pressed). 0624 */ 0625 void goBackRequested(); 0626 0627 /** 0628 * Is emitted if the URL should be changed to the next URL of the 0629 * history (e.g. because the "next"-mousebutton has been pressed). 0630 */ 0631 void goForwardRequested(); 0632 0633 /** 0634 * Used to request either entering or leaving of selection mode 0635 * Entering is typically requested on press and hold. 0636 * Leaving by pressing Escape when no item is selected. 0637 */ 0638 void selectionModeChangeRequested(bool enabled); 0639 0640 /** 0641 * Is emitted when the user wants to move the focus to another view. 0642 */ 0643 void toggleActiveViewRequested(); 0644 0645 /** 0646 * Is emitted when the user clicks a tag or a link 0647 * in the metadata widget of a tooltip. 0648 */ 0649 void urlActivated(const QUrl &url); 0650 0651 void goUpRequested(); 0652 0653 void fileItemsChanged(const KFileItemList &changedFileItems); 0654 0655 /** 0656 * Emitted when the current directory of the model was removed. 0657 */ 0658 void currentDirectoryRemoved(); 0659 0660 protected: 0661 /** Changes the zoom level if Control is pressed during a wheel event. */ 0662 void wheelEvent(QWheelEvent *event) override; 0663 0664 void hideEvent(QHideEvent *event) override; 0665 bool event(QEvent *event) override; 0666 0667 private Q_SLOTS: 0668 /** 0669 * Marks the view as active (DolphinView:isActive() will return true) 0670 * and emits the 'activated' signal if it is not already active. 0671 */ 0672 void activate(); 0673 0674 void slotItemActivated(int index); 0675 void slotItemsActivated(const KItemSet &indexes); 0676 void slotItemMiddleClicked(int index); 0677 void slotItemContextMenuRequested(int index, const QPointF &pos); 0678 void slotViewContextMenuRequested(const QPointF &pos); 0679 void slotHeaderContextMenuRequested(const QPointF &pos); 0680 void slotHeaderColumnWidthChangeFinished(const QByteArray &role, qreal current); 0681 void slotSidePaddingWidthChanged(qreal width); 0682 void slotItemHovered(int index); 0683 void slotItemUnhovered(int index); 0684 void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event); 0685 void slotModelChanged(KItemModelBase *current, KItemModelBase *previous); 0686 void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons); 0687 void slotRenameDialogRenamingFinished(const QList<QUrl> &urls); 0688 void slotSelectedItemTextPressed(int index); 0689 void slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to); 0690 void slotIncreaseZoom(); 0691 void slotDecreaseZoom(); 0692 void slotSwipeUp(); 0693 0694 /* 0695 * Is called when new items get pasted or dropped. 0696 */ 0697 void slotItemCreated(const QUrl &url); 0698 /* 0699 * Is called after all pasted or dropped items have been copied to destination. 0700 */ 0701 void slotJobResult(KJob *job); 0702 0703 /** 0704 * Emits the signal \a selectionChanged() with a small delay. This is 0705 * because getting all file items for the selection can be an expensive 0706 * operation. Fast selection changes are collected in this case and 0707 * the signal is emitted only after no selection change has been done 0708 * within a small delay. 0709 */ 0710 void slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous); 0711 0712 /** 0713 * Is called by emitDelayedSelectionChangedSignal() and emits the 0714 * signal \a selectionChanged() with all selected file items as parameter. 0715 */ 0716 void emitSelectionChangedSignal(); 0717 0718 /** 0719 * Helper method for DolphinView::requestStatusBarText(). 0720 * Calculates the amount of folders and files and their total size in 0721 * response to a KStatJob::result(), then calls emitStatusBarText(). 0722 * @see requestStatusBarText() 0723 * @see emitStatusBarText() 0724 */ 0725 void slotStatJobResult(KJob *job); 0726 0727 /** 0728 * Updates the view properties of the current URL to the 0729 * sorting given by \a role. 0730 */ 0731 void updateSortRole(const QByteArray &role); 0732 0733 /** 0734 * Updates the view properties of the current URL to the 0735 * sort order given by \a order. 0736 */ 0737 void updateSortOrder(Qt::SortOrder order); 0738 0739 /** 0740 * Updates the view properties of the current URL to the 0741 * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst. 0742 */ 0743 void updateSortFoldersFirst(bool foldersFirst); 0744 0745 /** 0746 * Updates the view properties of the current URL to the 0747 * sorting of hidden files given by \a hiddenLast. 0748 */ 0749 void updateSortHiddenLast(bool hiddenLast); 0750 0751 /** 0752 * Indicates in the status bar that the delete operation 0753 * of the job \a job has been finished. 0754 */ 0755 void slotDeleteFileFinished(KJob *job); 0756 0757 /** 0758 * Indicates in the status bar that the trash operation 0759 * of the job \a job has been finished. 0760 */ 0761 void slotTrashFileFinished(KJob *job); 0762 0763 /** 0764 * Invoked when the rename job is done, for error handling. 0765 */ 0766 void slotRenamingResult(KJob *job); 0767 0768 /** 0769 * Invoked when the file item model has started the loading 0770 * of the directory specified by DolphinView::url(). 0771 */ 0772 void slotDirectoryLoadingStarted(); 0773 0774 /** 0775 * Invoked when the file item model indicates that the loading of a directory has 0776 * been completed. Assures that pasted items and renamed items get selected. 0777 */ 0778 void slotDirectoryLoadingCompleted(); 0779 0780 /** 0781 * Invoked when the file item model indicates that the loading of a directory has 0782 * been canceled. 0783 */ 0784 void slotDirectoryLoadingCanceled(); 0785 0786 /** 0787 * Is invoked when items of KFileItemModel have been changed. 0788 */ 0789 void slotItemsChanged(); 0790 0791 /** 0792 * Is invoked when the sort order has been changed by the user by clicking 0793 * on a header item. The view properties of the directory will get updated. 0794 */ 0795 void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous); 0796 0797 /** 0798 * Is invoked when the sort role has been changed by the user by clicking 0799 * on a header item. The view properties of the directory will get updated. 0800 */ 0801 void slotSortRoleChangedByHeader(const QByteArray ¤t, const QByteArray &previous); 0802 0803 /** 0804 * Is invoked when the visible roles have been changed by the user by dragging 0805 * a header item. The view properties of the directory will get updated. 0806 */ 0807 void slotVisibleRolesChangedByHeader(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); 0808 0809 void slotRoleEditingCanceled(); 0810 void slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value); 0811 0812 /** 0813 * Observes the item with the URL \a url. As soon as the directory 0814 * model indicates that the item is available, the item will 0815 * get selected and it is assured that the item stays visible. 0816 */ 0817 void observeCreatedItem(const QUrl &url); 0818 0819 /** 0820 * Selects the next item after prev selection deleted/trashed 0821 */ 0822 void selectNextItem(); 0823 0824 /** 0825 * Called when a redirection happens. 0826 * Testcase: fish://localhost 0827 */ 0828 void slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl); 0829 0830 void slotTwoClicksRenamingTimerTimeout(); 0831 0832 void onDirectoryLoadingCompletedAfterJob(); 0833 0834 private: 0835 void loadDirectory(const QUrl &url, bool reload = false); 0836 0837 /** 0838 * Applies the view properties which are defined by the current URL 0839 * to the DolphinView properties. The view properties are read from a 0840 * .directory file either in the current directory, or in the 0841 * share/apps/dolphin/view_properties/ subfolder of the user's .kde folder. 0842 */ 0843 void applyViewProperties(); 0844 0845 /** 0846 * Applies the given view properties to the DolphinView. 0847 */ 0848 void applyViewProperties(const ViewProperties &props); 0849 0850 /** 0851 * Applies the m_mode property to the corresponding 0852 * itemlayout-property of the KItemListView. 0853 */ 0854 void applyModeToView(); 0855 0856 enum Selection { HasSelection, NoSelection }; 0857 /** 0858 * Helper method for DolphinView::requestStatusBarText(). 0859 * Generates the status bar text from the parameters and 0860 * then emits statusBarTextChanged(). 0861 * @param totalFileSize the sum of the sizes of the files 0862 * @param selection if HasSelection is passed, the emitted status bar text will say 0863 * that the folders and files which are counted here are selected. 0864 */ 0865 void emitStatusBarText(const int folderCount, const int fileCount, KIO::filesize_t totalFileSize, const Selection selection); 0866 0867 /** 0868 * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder(). 0869 * Pastes the clipboard data into the URL \a url. 0870 */ 0871 void pasteToUrl(const QUrl &url); 0872 0873 /** 0874 * Returns a list of URLs for all selected items. The list is 0875 * simplified, so that when the URLs are part of different tree 0876 * levels, only the parent is returned. 0877 */ 0878 QList<QUrl> simplifiedSelectedUrls() const; 0879 0880 /** 0881 * Returns the MIME data for all selected items. 0882 */ 0883 QMimeData *selectionMimeData() const; 0884 0885 /** 0886 * Updates m_isFolderWritable dependent on whether the folder represented by 0887 * the current URL is writable. If the state has changed, the signal 0888 * writeStateChanged() will be emitted. 0889 */ 0890 void updateWritableState(); 0891 0892 /** 0893 * @return The current URL if no viewproperties-context is given (see 0894 * DolphinView::viewPropertiesContext(), otherwise the context 0895 * is returned. 0896 */ 0897 QUrl viewPropertiesUrl() const; 0898 0899 /** 0900 * Clears the selection and updates current item and selection according to the parameters 0901 * 0902 * @param current URL to be set as current 0903 * @param selected list of selected items 0904 */ 0905 void forceUrlsSelection(const QUrl ¤t, const QList<QUrl> &selected); 0906 0907 void abortTwoClicksRenaming(); 0908 0909 void updatePlaceholderLabel(); 0910 0911 bool tryShowNameToolTip(QHelpEvent *event); 0912 0913 private: 0914 void updatePalette(); 0915 void showLoadingPlaceholder(); 0916 0917 bool m_active; 0918 bool m_tabsForFiles; 0919 bool m_assureVisibleCurrentIndex; 0920 bool m_isFolderWritable; 0921 bool m_dragging; // True if a dragging is done. Required to be able to decide whether a 0922 // tooltip may be shown when hovering an item. 0923 bool m_selectNextItem; 0924 0925 enum class LoadingState { Idle, Loading, Canceled, Completed }; 0926 LoadingState m_loadingState = LoadingState::Idle; 0927 0928 QUrl m_url; 0929 QString m_viewPropertiesContext; 0930 Mode m_mode; 0931 QList<QByteArray> m_visibleRoles; 0932 0933 QPointer<KIO::StatJob> m_statJobForStatusBarText; 0934 0935 QVBoxLayout *m_topLayout; 0936 0937 KFileItemModel *m_model; 0938 DolphinItemListView *m_view; 0939 KItemListContainer *m_container; 0940 0941 ToolTipManager *m_toolTipManager; 0942 0943 QTimer *m_selectionChangedTimer; 0944 0945 QUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5 0946 bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not 0947 QPoint m_restoredContentsPosition; 0948 0949 // Used for tracking the accumulated scroll amount (for zooming with high 0950 // resolution scroll wheels) 0951 int m_controlWheelAccumulatedDelta; 0952 0953 QList<QUrl> m_selectedUrls; // Used for making the view to remember selections after F5 and file operations 0954 bool m_clearSelectionBeforeSelectingNewItems; 0955 bool m_markFirstNewlySelectedItemAsCurrent; 0956 /// Decides whether items created by jobs should automatically be selected. 0957 bool m_selectJobCreatedItems; 0958 0959 VersionControlObserver *m_versionControlObserver; 0960 0961 QTimer *m_twoClicksRenamingTimer; 0962 QUrl m_twoClicksRenamingItemUrl; 0963 QLabel *m_placeholderLabel; 0964 QTimer *m_showLoadingPlaceholderTimer; 0965 0966 /// The information roleIndex of the list column header currently hovered 0967 std::optional<int> m_hoveredColumnHeaderIndex; 0968 0969 /// Used for selection mode. @see setSelectionMode() 0970 std::unique_ptr<QProxyStyle> m_proxyStyle; 0971 0972 // For unit tests 0973 friend class TestBase; 0974 friend class DolphinDetailsViewTest; 0975 friend class DolphinMainWindowTest; 0976 friend class DolphinPart; // Accesses m_model 0977 void updateSelectionState(); 0978 }; 0979 0980 /// Allow using DolphinView::Mode in QVariant 0981 Q_DECLARE_METATYPE(DolphinView::Mode) 0982 0983 #endif // DOLPHINVIEW_H