]> cloud.milkyroute.net Git - dolphin.git/blob - src/infosidebarpage.h
PreviewJob API change (KFileItems by value)
[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 <QPixmap>
27 #include <QEvent>
28 #include <QLabel>
29 #include <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 Prototype for a information sidebar.
53 *
54 * Will be exchanged in future releases by pluggable sidebar pages...
55 */
56 class InfoSidebarPage : public SidebarPage
57 {
58 Q_OBJECT
59
60 public:
61 explicit InfoSidebarPage(QWidget* parent = 0);
62 virtual ~InfoSidebarPage();
63
64 public slots:
65 void setUrl(const KUrl& url);
66 void setSelection(const KFileItemList& selection);
67
68 private slots:
69 /**
70 * Does a delayed request of information for the item of the given Url and
71 * provides default actions.
72 *
73 * @see InfoSidebarPage::showItemInfo()
74 */
75 void requestDelayedItemInfo(const KUrl& url);
76
77 /**
78 * Shows the information for the item of the Url which has been provided by
79 * InfoSidebarPage::requestItemInfo() and provides default actions.
80 */
81 void showItemInfo();
82
83 /**
84 * Triggered if the request for item information has timed out.
85 * @see InfoSidebarPage::requestDelayedItemInfo()
86 */
87 void slotTimeout();
88
89 /**
90 * Is invoked if no preview is available for the item. In this
91 * case the icon will be shown.
92 */
93 void slotPreviewFailed(const KFileItem& item);
94
95 /**
96 * Is invoked if a preview is available for the item. The preview
97 * \a pixmap is shown inside the info page.
98 */
99 void gotPreview(const KFileItem& item, const QPixmap& pixmap);
100
101 /**
102 * Starts the service of m_actionsVector with the index \index on
103 * the shown Url (or the selected items if available).
104 */
105 void startService(int index);
106
107 private:
108 /**
109 * Checks whether the an Url is repesented by a bookmark. If yes,
110 * then the bookmark icon and name are shown instead of a preview.
111 * @return True, if the Url represents exactly a bookmark.
112 * @param url The url to check.
113 */
114 bool applyBookmark(const KUrl& url);
115
116 /** Assures that any pending item information request is cancelled. */
117 void cancelRequest();
118
119 // TODO: the following methods are just a prototypes for meta
120 // info generation...
121 void createMetaInfo();
122 void addInfoLine(const QString& labelText,
123 const QString& infoText);
124 void beginInfoLines();
125 void endInfoLines();
126
127 /**
128 * Returns true, if the string \a key represents a meta information
129 * that should be shown.
130 */
131 bool showMetaInfo(const QString& key) const;
132
133 /**
134 * Inserts the available actions to the info page for the given item.
135 */
136 void insertActions();
137
138 bool m_multipleSelection;
139 bool m_pendingPreview;
140 QTimer* m_timer;
141 KUrl m_shownUrl;
142 KUrl m_urlCandidate;
143 KFileItemList m_currentSelection;
144
145 PixmapViewer* m_preview;
146 QLabel* m_name;
147
148 QString m_infoLines;
149 QLabel* m_infos;
150
151 KVBox* m_actionBox;
152 QVector<KDesktopFileActions::Service> m_actionsVector;
153
154 MetaDataWidget* m_metadataWidget;
155 };
156
157 // TODO #1: move to SidebarPage?
158 // TODO #2: quite same button from the optical point of view as UrlNavigatorButton
159 // -> provide helper class or common base class
160 class ServiceButton : public QPushButton
161 {
162 Q_OBJECT
163
164 public:
165 ServiceButton(const QIcon& icon,
166 const QString& text,
167 QWidget* parent,
168 int index);
169 virtual ~ServiceButton();
170
171 signals:
172 void requestServiceStart(int index);
173
174 protected:
175 virtual void paintEvent(QPaintEvent* event);
176 virtual void enterEvent(QEvent* event);
177 virtual void leaveEvent(QEvent* event);
178
179 private slots:
180 void slotReleased();
181
182 private:
183 bool m_hover;
184 int m_index;
185 };
186
187 #endif // INFOSIDEBARPAGE_H