File indexing completed on 2024-04-28 17:03:08

0001 /*
0002  * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef INFORMATIONPANEL_H
0008 #define INFORMATIONPANEL_H
0009 
0010 #include "panels/panel.h"
0011 
0012 #include <KFileItem>
0013 
0014 class InformationPanelContent;
0015 namespace KIO
0016 {
0017 class Job;
0018 }
0019 
0020 /**
0021  * @brief Panel for showing meta information of one ore more selected items.
0022  */
0023 class InformationPanel : public Panel
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit InformationPanel(QWidget *parent = nullptr);
0029     ~InformationPanel() override;
0030 
0031 Q_SIGNALS:
0032     void urlActivated(const QUrl &url);
0033 
0034 public Q_SLOTS:
0035     /**
0036      * This is invoked to inform the panel that the user has selected a new
0037      * set of items.
0038      */
0039     void setSelection(const KFileItemList &selection);
0040 
0041     /**
0042      * Does a delayed request of information for the item \a item.
0043      * If within this delay InformationPanel::setUrl() or InformationPanel::setSelection()
0044      * are invoked, then the request will be skipped. Requesting a delayed item information
0045      * makes sense when hovering items.
0046      */
0047     void requestDelayedItemInfo(const KFileItem &item);
0048 
0049     void slotFilesItemChanged(const KFileItemList &changedFileItems);
0050 
0051 protected:
0052     /** @see Panel::urlChanged() */
0053     bool urlChanged() override;
0054 
0055     /** @see QWidget::showEvent() */
0056     void showEvent(QShowEvent *event) override;
0057 
0058     /** @see QWidget::resizeEvent() */
0059     void resizeEvent(QResizeEvent *event) override;
0060 
0061     /** @see QWidget::contextMenuEvent() */
0062     void contextMenuEvent(QContextMenuEvent *event) override;
0063 
0064 private Q_SLOTS:
0065     /**
0066      * Shows the information for the item of the URL which has been provided by
0067      * InformationPanel::requestDelayedItemInfo() and provides default actions.
0068      */
0069     void showItemInfo();
0070 
0071     /**
0072      * Shows the information for the currently displayed folder as a result from
0073      * a stat job issued in showItemInfo().
0074      */
0075     void slotFolderStatFinished(KJob *job);
0076 
0077     /**
0078      * Triggered if the request for item information has timed out.
0079      * @see InformationPanel::requestDelayedItemInfo()
0080      */
0081     void slotInfoTimeout();
0082 
0083     /**
0084      * Resets the information panel to show the current
0085      * URL (InformationPanel::url()). Is called by
0086      * DolphinInformationPanel::markUrlAsInvalid().
0087      */
0088     void reset();
0089 
0090     void slotFileRenamed(const QString &source, const QString &dest);
0091     void slotFilesAdded(const QString &directory);
0092     void slotFilesChanged(const QStringList &files);
0093     void slotFilesRemoved(const QStringList &files);
0094     void slotEnteredDirectory(const QString &directory);
0095     void slotLeftDirectory(const QString &directory);
0096 
0097 private:
0098     /** Assures that any pending item information request is cancelled. */
0099     void cancelRequest();
0100 
0101     /**
0102      * Returns true, if \a url is equal to the shown URL m_shownUrl.
0103      */
0104     bool isEqualToShownUrl(const QUrl &url) const;
0105 
0106     /**
0107      * Marks the URL as invalid and will reset the Information Panel
0108      * after a short delay. The reset is not done synchronously to
0109      * prevent expensive updates during temporary invalid URLs by
0110      * e. g. changing the directory.
0111      */
0112     void markUrlAsInvalid();
0113 
0114     /**
0115      * Opens a menu which allows to configure which meta information
0116      * should be shown.
0117      */
0118     void showContextMenu(const QPoint &point);
0119 
0120     void init();
0121 
0122 private:
0123     bool m_initialized;
0124     QTimer *m_infoTimer;
0125     QTimer *m_urlChangedTimer;
0126     QTimer *m_resetUrlTimer;
0127 
0128     // URL that is currently shown in the Information Panel.
0129     QUrl m_shownUrl;
0130 
0131     // URL candidate that will replace m_shownURL after a delay.
0132     // Used to remember URLs when hovering items.
0133     QUrl m_urlCandidate;
0134 
0135     // URL candidate that is marked as invalid (e. g. because the directory
0136     // has been deleted or the shown item has been renamed). The Information
0137     // Panel will be reset asynchronously to prevent unnecessary resets when
0138     // a directory has been changed.
0139     QUrl m_invalidUrlCandidate;
0140 
0141     KFileItem m_hoveredItem;
0142     KFileItemList m_selection;
0143 
0144     KIO::Job *m_folderStatJob;
0145 
0146     InformationPanelContent *m_content;
0147     bool m_inConfigurationMode = false;
0148 };
0149 
0150 #endif // INFORMATIONPANEL_H