]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/informationpanel.h
We won't get translated labels for Nepomuk literals in KDE 4.3.0... At least assure...
[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 <QPushButton>
26 #include <QPixmap>
27 #include <QEvent>
28 #include <QLabel>
29 #include <QList>
30
31 #include <kconfig.h>
32 #include <kurl.h>
33 #include <kmimetype.h>
34 #include <kdesktopfileactions.h>
35 #include <kvbox.h>
36
37 class InformationPanelDialog;
38 class PhononWidget;
39 class PixmapViewer;
40 class MetaDataWidget;
41 class MetaTextLabel;
42 class QPixmap;
43 class QString;
44 class KFileItem;
45 class KSeparator;
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 void slotPlayingStarted();
133 void slotPlayingStopped();
134
135 private:
136 /**
137 * Checks whether the an URL is repesented by a place. If yes,
138 * then the place icon and name are shown instead of a preview.
139 * @return True, if the URL represents exactly a place.
140 * @param url The url to check.
141 */
142 bool applyPlace(const KUrl& url);
143
144 /** Assures that any pending item information request is cancelled. */
145 void cancelRequest();
146
147 /**
148 * Shows the meta information for the current shown item inside
149 * a label.
150 */
151 void showMetaInfo();
152
153 /**
154 * Returns the item for file where the preview and meta information
155 * should be received, if InformationPanel::showMultipleSelectionInfo()
156 * returns false.
157 */
158 KFileItem fileItem() const;
159
160 /**
161 * Returns true, if the meta information should be shown for
162 * the multiple selected items that are stored in
163 * m_selection. If true is returned, it is assured that
164 * m_selection.count() > 1. If false is returned, the meta
165 * information should be shown for the file
166 * InformationPanel::fileUrl();
167 */
168 bool showMultipleSelectionInfo() const;
169
170 /**
171 * Returns true, if \a url is equal to the shown URL m_shownUrl.
172 */
173 bool isEqualToShownUrl(const KUrl& url) const;
174
175 /**
176 * Sets the text for the label \a m_nameLabel and assures that the
177 * text is split in a way that it can be wrapped within the
178 * label width (QLabel::setWordWrap() does not work if the
179 * text represents one extremely long word).
180 */
181 void setNameLabelText(const QString& text);
182
183 /**
184 * Resets the information panel to show the current
185 * URL (InformationPanel::url()).
186 */
187 void reset();
188
189 /**
190 * Assures that the settings for the meta information
191 * are initialized with proper default values.
192 */
193 void initMetaInfoSettings(KConfigGroup& group);
194
195 void updatePhononWidget();
196
197 /**
198 * Temporary helper method for KDE 4.3 as we currently don't get
199 * translated labels for Nepmok literals: Replaces camelcase labels
200 * like "fileLocation" by "File Location:".
201 */
202 QString tunedLabel(const QString& label) const;
203
204 void init();
205
206 private:
207 bool m_initialized;
208 bool m_pendingPreview;
209 QTimer* m_infoTimer;
210 QTimer* m_outdatedPreviewTimer;
211 KUrl m_shownUrl; // URL that is shown as info
212 KUrl m_urlCandidate; // URL candidate that will replace m_shownURL after a delay
213 KFileItem m_fileItem; // file item for m_shownUrl if available (otherwise null)
214 KFileItemList m_selection;
215
216 QLabel* m_nameLabel;
217 PixmapViewer* m_preview;
218 KSeparator* m_previewSeparator;
219 PhononWidget* m_phononWidget;
220 MetaDataWidget* m_metaDataWidget;
221 KSeparator* m_metaDataSeparator;
222
223 QScrollArea* m_metaTextArea;
224 MetaTextLabel* m_metaTextLabel;
225 };
226
227 #endif // INFORMATIONPANEL_H