]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.h
added dialog to configure which meta data should be shown in the Information Panel
[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 #include <panels/information/informationpaneldialog.h>
25
26 #include <QPushButton>
27 #include <QPixmap>
28 #include <QEvent>
29 #include <QLabel>
30 #include <QList>
31 #include <QPointer>
32
33 #include <kurl.h>
34 #include <kmimetype.h>
35 #include <kdesktopfileactions.h>
36 #include <kvbox.h>
37
38 class InformationPanelDialog;
39 class PhononWidget;
40 class PixmapViewer;
41 class MetaDataWidget;
42 class MetaTextLabel;
43 class QPixmap;
44 class QString;
45 class KFileItem;
46 class QLabel;
47 class QScrollArea;
48
49 /**
50 * @brief Panel for showing meta information of one ore more selected items.
51 */
52 class InformationPanel : public Panel
53 {
54 Q_OBJECT
55
56 public:
57 explicit InformationPanel(QWidget* parent = 0);
58 virtual ~InformationPanel();
59
60 /** @see QWidget::sizeHint() */
61 virtual QSize sizeHint() const;
62
63 public slots:
64 /** @see Panel::setUrl() */
65 virtual void setUrl(const KUrl& url);
66
67 /**
68 * This is invoked to inform the panel that the user has selected a new
69 * set of items.
70 */
71 void setSelection(const KFileItemList& selection);
72
73 /**
74 * Does a delayed request of information for the item \a item.
75 * If within this delay InformationPanel::setUrl() or InformationPanel::setSelection()
76 * are invoked, then the request will be skipped. Requesting a delayed item information
77 * makes sense when hovering items.
78 */
79 void requestDelayedItemInfo(const KFileItem& item);
80
81 protected:
82 /** @see QWidget::showEvent() */
83 virtual void showEvent(QShowEvent* event);
84
85 /** @see QWidget::resizeEvent() */
86 virtual void resizeEvent(QResizeEvent* event);
87
88 /** @see QObject::eventFilter() */
89 virtual bool eventFilter(QObject* obj, QEvent* event);
90
91 /** @see QWidget::contextMenuEvent() */
92 virtual void contextMenuEvent(QContextMenuEvent* event);
93
94 private slots:
95 /**
96 * Shows the information for the item of the URL which has been provided by
97 * InformationPanel::requestItemInfo() and provides default actions.
98 */
99 void showItemInfo();
100
101 /**
102 * Triggered if the request for item information has timed out.
103 * @see InformationPanel::requestDelayedItemInfo()
104 */
105 void slotInfoTimeout();
106
107 /**
108 * Marks the currently shown preview as outdated
109 * by greying the content.
110 */
111 void markOutdatedPreview();
112
113 /**
114 * Is invoked if no preview is available for the item. In this
115 * case the icon will be shown.
116 */
117 void showIcon(const KFileItem& item);
118
119 /**
120 * Is invoked if a preview is available for the item. The preview
121 * \a pixmap is shown inside the info page.
122 */
123 void showPreview(const KFileItem& item, const QPixmap& pixmap);
124
125 void slotFileRenamed(const QString& source, const QString& dest);
126 void slotFilesAdded(const QString& directory);
127 void slotFilesChanged(const QStringList& files);
128 void slotFilesRemoved(const QStringList& files);
129 void slotEnteredDirectory(const QString& directory);
130 void slotLeftDirectory(const QString& directory);
131
132 private:
133 /**
134 * Checks whether the an URL is repesented by a place. If yes,
135 * then the place icon and name are shown instead of a preview.
136 * @return True, if the URL represents exactly a place.
137 * @param url The url to check.
138 */
139 bool applyPlace(const KUrl& url);
140
141 /** Assures that any pending item information request is cancelled. */
142 void cancelRequest();
143
144 /**
145 * Shows the meta information for the current shown item inside
146 * a label.
147 */
148 void showMetaInfo();
149
150 /**
151 * Returns the item for file where the preview and meta information
152 * should be received, if InformationPanel::showMultipleSelectionInfo()
153 * returns false.
154 */
155 KFileItem fileItem() const;
156
157 /**
158 * Returns true, if the meta information should be shown for
159 * the multiple selected items that are stored in
160 * m_selection. If true is returned, it is assured that
161 * m_selection.count() > 1. If false is returned, the meta
162 * information should be shown for the file
163 * InformationPanel::fileUrl();
164 */
165 bool showMultipleSelectionInfo() const;
166
167 /**
168 * Returns true, if \a url is equal to the shown URL m_shownUrl.
169 */
170 bool isEqualToShownUrl(const KUrl& url) const;
171
172 /**
173 * Sets the text for the label \a m_nameLabel and assures that the
174 * text is split in a way that it can be wrapped within the
175 * label width (QLabel::setWordWrap() does not work if the
176 * text represents one extremely long word).
177 */
178 void setNameLabelText(const QString& text);
179
180 /**
181 * Resets the information panel to show the current
182 * URL (InformationPanel::url()).
183 */
184 void reset();
185
186 void init();
187
188 private:
189 bool m_initialized;
190 bool m_pendingPreview;
191 QTimer* m_infoTimer;
192 QTimer* m_outdatedPreviewTimer;
193 KUrl m_shownUrl; // URL that is shown as info
194 KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay
195 KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null)
196 KFileItemList m_selection;
197
198 QLabel* m_nameLabel;
199 PixmapViewer* m_preview;
200 PhononWidget* m_phononWidget;
201 MetaDataWidget* m_metaDataWidget;
202
203 QScrollArea* m_metaTextArea;
204 MetaTextLabel* m_metaTextLabel;
205
206 QPointer<InformationPanelDialog> m_dialog;
207 };
208
209 #endif // INFORMATIONPANEL_H