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