]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.h
InformationPanel: Allow to refresh the panel when its displayed content changes
[dolphin.git] / src / panels / information / informationpanel.h
1 /*
2 * SPDX-FileCopyrightText: 2006-2009 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef INFORMATIONPANEL_H
8 #define INFORMATIONPANEL_H
9
10 #include "panels/panel.h"
11
12 #include <KFileItem>
13
14 class InformationPanelContent;
15 namespace KIO
16 {
17 class Job;
18 }
19
20 /**
21 * @brief Panel for showing meta information of one ore more selected items.
22 */
23 class InformationPanel : public Panel
24 {
25 Q_OBJECT
26
27 public:
28 explicit InformationPanel(QWidget* parent = nullptr);
29 ~InformationPanel() override;
30
31 Q_SIGNALS:
32 void urlActivated(const QUrl& url);
33
34 public Q_SLOTS:
35 /**
36 * This is invoked to inform the panel that the user has selected a new
37 * set of items.
38 */
39 void setSelection(const KFileItemList& selection);
40
41 /**
42 * Does a delayed request of information for the item \a item.
43 * If within this delay InformationPanel::setUrl() or InformationPanel::setSelection()
44 * are invoked, then the request will be skipped. Requesting a delayed item information
45 * makes sense when hovering items.
46 */
47 void requestDelayedItemInfo(const KFileItem& item);
48
49 void slotFilesItemChanged(const KFileItemList &changedFileItems);
50
51 protected:
52 /** @see Panel::urlChanged() */
53 bool urlChanged() override;
54
55 /** @see QWidget::showEvent() */
56 void showEvent(QShowEvent* event) override;
57
58 /** @see QWidget::resizeEvent() */
59 void resizeEvent(QResizeEvent* event) override;
60
61 /** @see QWidget::contextMenuEvent() */
62 void contextMenuEvent(QContextMenuEvent* event) override;
63
64 private Q_SLOTS:
65 /**
66 * Shows the information for the item of the URL which has been provided by
67 * InformationPanel::requestDelayedItemInfo() and provides default actions.
68 */
69 void showItemInfo();
70
71 /**
72 * Shows the information for the currently displayed folder as a result from
73 * a stat job issued in showItemInfo().
74 */
75 void slotFolderStatFinished(KJob* job);
76
77 /**
78 * Triggered if the request for item information has timed out.
79 * @see InformationPanel::requestDelayedItemInfo()
80 */
81 void slotInfoTimeout();
82
83 /**
84 * Resets the information panel to show the current
85 * URL (InformationPanel::url()). Is called by
86 * DolphinInformationPanel::markUrlAsInvalid().
87 */
88 void reset();
89
90 void slotFileRenamed(const QString& source, const QString& dest);
91 void slotFilesAdded(const QString& directory);
92 void slotFilesChanged(const QStringList& files);
93 void slotFilesRemoved(const QStringList& files);
94 void slotEnteredDirectory(const QString& directory);
95 void slotLeftDirectory(const QString& directory);
96
97 private:
98 /** Assures that any pending item information request is cancelled. */
99 void cancelRequest();
100
101 /**
102 * Returns true, if \a url is equal to the shown URL m_shownUrl.
103 */
104 bool isEqualToShownUrl(const QUrl& url) const;
105
106 /**
107 * Marks the URL as invalid and will reset the Information Panel
108 * after a short delay. The reset is not done synchronously to
109 * prevent expensive updates during temporary invalid URLs by
110 * e. g. changing the directory.
111 */
112 void markUrlAsInvalid();
113
114 /**
115 * Opens a menu which allows to configure which meta information
116 * should be shown.
117 */
118 void showContextMenu(const QPoint &point);
119
120 void init();
121
122 private:
123 bool m_initialized;
124 QTimer* m_infoTimer;
125 QTimer* m_urlChangedTimer;
126 QTimer* m_resetUrlTimer;
127
128 // URL that is currently shown in the Information Panel.
129 QUrl m_shownUrl;
130
131 // URL candidate that will replace m_shownURL after a delay.
132 // Used to remember URLs when hovering items.
133 QUrl m_urlCandidate;
134
135 // URL candidate that is marked as invalid (e. g. because the directory
136 // has been deleted or the shown item has been renamed). The Information
137 // Panel will be reset asynchronously to prevent unnecessary resets when
138 // a directory has been changed.
139 QUrl m_invalidUrlCandidate;
140
141 KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null)
142 KFileItemList m_selection;
143
144 KIO::Job* m_folderStatJob;
145
146 InformationPanelContent* m_content;
147 bool m_inConfigurationMode = false;
148 };
149
150 #endif // INFORMATIONPANEL_H