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