]> cloud.milkyroute.net Git - dolphin.git/blob - src/infosidebarpage.h
- rename m_name to m_nameLabel for consistency
[dolphin.git] / src / infosidebarpage.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 INFOSIDEBARPAGE_H
21 #define INFOSIDEBARPAGE_H
22
23 #include <sidebarpage.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 namespace KIO
37 {
38 class Job;
39 }
40
41 class QPixmap;
42 class QIcon;
43 class QString;
44 class QPainter;
45 class KFileItem;
46 class QLabel;
47 class KVBox;
48 class PixmapViewer;
49 class MetaDataWidget;
50
51 /**
52 * @brief Sidebar for showing meta information of one ore more selected items.
53 */
54 class InfoSidebarPage : public SidebarPage
55 {
56 Q_OBJECT
57
58 public:
59 explicit InfoSidebarPage(QWidget* parent = 0);
60 virtual ~InfoSidebarPage();
61
62 public slots:
63 /** @see SidebarPage::setUrl() */
64 virtual void setUrl(const KUrl& url);
65
66 /** @see SidebarPage::setSelection() */
67 virtual void setSelection(const KFileItemList& selection);
68
69 /**
70 * Does a delayed request of information for the item of the given URL.
71 * If within this delay InfoSidebarPage::setUrl() or InfoSidebarPage::setSelection()
72 * are invoked, then the request will be skipped. Requesting a delayed item information
73 * makes sense when hovering items.
74 */
75 void requestDelayedItemInfo(const KUrl& url);
76
77 protected:
78 /** @see QWidget::showEvent() */
79 virtual void showEvent(QShowEvent* event);
80
81 /** @see QWidget::resizeEvent() */
82 virtual void resizeEvent(QResizeEvent* event);
83
84 private slots:
85 /**
86 * Shows the information for the item of the URL which has been provided by
87 * InfoSidebarPage::requestItemInfo() and provides default actions.
88 */
89 void showItemInfo();
90
91 /**
92 * Triggered if the request for item information has timed out.
93 * @see InfoSidebarPage::requestDelayedItemInfo()
94 */
95 void slotTimeout();
96
97 /**
98 * Is invoked if no preview is available for the item. In this
99 * case the icon will be shown.
100 */
101 void showIcon(const KFileItem& item);
102
103 /**
104 * Is invoked if a preview is available for the item. The preview
105 * \a pixmap is shown inside the info page.
106 */
107 void showPreview(const KFileItem& item, const QPixmap& pixmap);
108
109 private:
110 enum { TimerDelay = 300 };
111
112 /**
113 * Checks whether the an URL is repesented by a bookmark. If yes,
114 * then the bookmark icon and name are shown instead of a preview.
115 * @return True, if the URL represents exactly a bookmark.
116 * @param url The url to check.
117 */
118 bool applyBookmark(const KUrl& url);
119
120 /** Assures that any pending item information request is cancelled. */
121 void cancelRequest();
122
123 /**
124 * Shows the meta information for the current shown item inside
125 * a label.
126 */
127 void showMetaInfo();
128
129 /**
130 * Adds the texts \a labelText and \a infoText as one formated line
131 * to text.
132 */
133 void addInfoLine(QString& text,
134 const QString& labelText,
135 const QString& infoText);
136
137 /**
138 * Converts the meta key \a key to a readable format into \a text.
139 * Returns true, if the string \a key represents a meta information
140 * that should be shown. If false is returned, \a text is not modified.
141 */
142 bool convertMetaInfo(const QString& key, QString& text) const;
143
144 private:
145 bool m_pendingPreview;
146 QTimer* m_timer;
147 KUrl m_shownUrl;
148 KUrl m_urlCandidate;
149
150 PixmapViewer* m_preview;
151 QLabel* m_nameLabel;
152
153 QLabel* m_infoLabel;
154
155 MetaDataWidget* m_metadataWidget;
156 };
157
158 #endif // INFOSIDEBARPAGE_H