]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.h
Cleanup panel related class names: The terms "sidebar"/"sidebarpage" are relicts...
[dolphin.git] / src / panels / information / informationpanel.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef INFORMATIONPANEL_H
21 #define INFORMATIONPANEL_H
22
23 #include <panels/panel.h>
24
25 #include <QtGui/QPushButton>
26 #include <QtGui/QPixmap>
27 #include <QtCore/QEvent>
28 #include <QtGui/QLabel>
29 #include <QtCore/QList>
30
31 #include <kurl.h>
32 #include <kmimetype.h>
33 #include <kdesktopfileactions.h>
34 #include <kvbox.h>
35
36 class QPixmap;
37 class QString;
38 class KFileItem;
39 class QLabel;
40 class PixmapViewer;
41 class MetaDataWidget;
42 class MetaTextLabel;
43
44 /**
45 * @brief Panel for showing meta information of one ore more selected items.
46 */
47 class InformationPanel : public Panel
48 {
49 Q_OBJECT
50
51 public:
52 explicit InformationPanel(QWidget* parent = 0);
53 virtual ~InformationPanel();
54
55 /** @see QWidget::sizeHint() */
56 virtual QSize sizeHint() const;
57
58 public slots:
59 /** @see Panel::setUrl() */
60 virtual void setUrl(const KUrl& url);
61
62 /**
63 * This is invoked to inform the panel that the user has selected a new
64 * set of items.
65 */
66 void setSelection(const KFileItemList& selection);
67
68 /**
69 * Does a delayed request of information for the item \a item.
70 * If within this delay InformationPanel::setUrl() or InformationPanel::setSelection()
71 * are invoked, then the request will be skipped. Requesting a delayed item information
72 * makes sense when hovering items.
73 */
74 void requestDelayedItemInfo(const KFileItem& item);
75
76 protected:
77 /** @see QWidget::showEvent() */
78 virtual void showEvent(QShowEvent* event);
79
80 /** @see QWidget::resizeEvent() */
81 virtual void resizeEvent(QResizeEvent* event);
82
83 private slots:
84 /**
85 * Shows the information for the item of the URL which has been provided by
86 * InformationPanel::requestItemInfo() and provides default actions.
87 */
88 void showItemInfo();
89
90 /**
91 * Triggered if the request for item information has timed out.
92 * @see InformationPanel::requestDelayedItemInfo()
93 */
94 void slotInfoTimeout();
95
96 /**
97 * Marks the currently shown preview as outdated
98 * by greying the content.
99 */
100 void markOutdatedPreview();
101
102 /**
103 * Is invoked if no preview is available for the item. In this
104 * case the icon will be shown.
105 */
106 void showIcon(const KFileItem& item);
107
108 /**
109 * Is invoked if a preview is available for the item. The preview
110 * \a pixmap is shown inside the info page.
111 */
112 void showPreview(const KFileItem& item, const QPixmap& pixmap);
113
114 void slotFileRenamed(const QString& source, const QString& dest);
115 void slotFilesAdded(const QString& directory);
116 void slotFilesChanged(const QStringList& files);
117 void slotFilesRemoved(const QStringList& files);
118 void slotEnteredDirectory(const QString& directory);
119 void slotLeftDirectory(const QString& directory);
120
121 private:
122 /**
123 * Checks whether the an URL is repesented by a place. If yes,
124 * then the place icon and name are shown instead of a preview.
125 * @return True, if the URL represents exactly a place.
126 * @param url The url to check.
127 */
128 bool applyPlace(const KUrl& url);
129
130 /** Assures that any pending item information request is cancelled. */
131 void cancelRequest();
132
133 /**
134 * Shows the meta information for the current shown item inside
135 * a label.
136 */
137 void showMetaInfo();
138
139 /**
140 * Converts the meta key \a key to a readable format into \a text.
141 * Returns true, if the string \a key represents a meta information
142 * that should be shown. If false is returned, \a text is not modified.
143 */
144 bool convertMetaInfo(const QString& key, QString& text) const;
145
146 /**
147 * Returns the item for file where the preview and meta information
148 * should be received, if InformationPanel::showMultipleSelectionInfo()
149 * returns false.
150 */
151 KFileItem fileItem() const;
152
153 /**
154 * Returns true, if the meta information should be shown for
155 * the multiple selected items that are stored in
156 * m_selection. If true is returned, it is assured that
157 * m_selection.count() > 1. If false is returned, the meta
158 * information should be shown for the file
159 * InformationPanel::fileUrl();
160 */
161 bool showMultipleSelectionInfo() const;
162
163 /**
164 * Returns true, if \a url is equal to the shown URL m_shownUrl.
165 */
166 bool isEqualToShownUrl(const KUrl& url) const;
167
168 /**
169 * Sets the text for the label \a m_nameLabel and assures that the
170 * text is split in a way that it can be wrapped within the
171 * label width (QLabel::setWordWrap() does not work if the
172 * text represents one extremely long word).
173 */
174 void setNameLabelText(const QString& text);
175
176 void init();
177
178 private:
179 bool m_initialized;
180 bool m_pendingPreview;
181 QTimer* m_infoTimer;
182 QTimer* m_outdatedPreviewTimer;
183 KUrl m_shownUrl; // URL that is shown as info
184 KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay
185 KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null)
186 KFileItemList m_selection;
187
188 QLabel* m_nameLabel;
189 PixmapViewer* m_preview;
190 MetaDataWidget* m_metaDataWidget;
191 MetaTextLabel* m_metaTextLabel;
192 };
193
194 #endif // INFORMATIONPANEL_H