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