1 /*****************************************************************************
2  * plugins.hpp : Plug-ins and extensions listing
3  ****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id: f4cf5adf2882fda8f376c43e0f05c95f7e03a49a $
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 
24 #ifndef QVLC_PLUGIN_DIALOG_H_
25 #define QVLC_PLUGIN_DIALOG_H_ 1
26 
27 #include "util/qvlcframe.hpp"
28 #include "util/singleton.hpp"
29 
30 #include <vlc_extensions.h>
31 #include <vlc_addons.h>
32 
33 #include <QStringList>
34 #include <QTreeWidgetItem>
35 #include <QPushButton>
36 #include <QAbstractListModel>
37 #include <QSortFilterProxyModel>
38 #include <QStyledItemDelegate>
39 
40 class QLabel;
41 class QTabWidget;
42 class QComboBox;
43 class QTreeWidget;
44 class QLineEdit;
45 class QSignalMapper;
46 //class QTextBrowser;
47 class QListView;
48 class QStyleOptionViewItem;
49 class QPainter;
50 class QKeyEvent;
51 class PluginTab;
52 class ExtensionTab;
53 class AddonsTab;
54 class ExtensionListItem;
55 class SearchLineEdit;
56 class ExtensionCopy;
57 class ExtensionsManager;
58 class AddonsManager;
59 class PixmapAnimator;
60 class DelegateAnimationHelper;
61 class AddonsSortFilterProxyModel;
62 
63 class PluginDialog : public QVLCFrame, public Singleton<PluginDialog>
64 {
65     Q_OBJECT
66 
67 private:
68     PluginDialog( intf_thread_t * );
69     virtual ~PluginDialog();
70 
71     QTabWidget *tabs;
72     PluginTab *pluginTab;
73     ExtensionTab *extensionTab;
74     AddonsTab *addonsTab;
75 
76     friend class Singleton<PluginDialog>;
77 };
78 
79 class PluginTab : public QVLCFrame
80 {
81     Q_OBJECT
82 public:
83     enum
84     {
85         NAME = 0,
86         CAPABILITY,
87         SCORE
88     };
89 
90 protected:
91     void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE;
92 
93 private:
94     PluginTab( intf_thread_t *p_intf );
95     virtual ~PluginTab();
96 
97     void FillTree();
98     QTreeWidget *treePlugins;
99     SearchLineEdit *edit;
100 
101 private slots:
102     void search( const QString& );
103 
104     friend class PluginDialog;
105 };
106 
107 class ExtensionTab : public QVLCFrame
108 {
109     Q_OBJECT
110 
111 protected:
112     void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE;
113 
114 private:
115     ExtensionTab( intf_thread_t *p_intf );
116     virtual ~ExtensionTab();
117 
118 private slots:
119     void moreInformation();
120     void updateButtons();
121 
122 private:
123     QListView *extList;
124     QPushButton *butMoreInfo;
125 
126     friend class PluginDialog;
127 };
128 
129 class AddonsTab : public QVLCFrame
130 {
131     Q_OBJECT
132     friend class PluginDialog;
133 
134 protected:
135     void keyPressEvent( QKeyEvent *keyEvent ) Q_DECL_OVERRIDE;
136 
137 private slots:
138     void moreInformation();
139     void installChecked( int );
140     void reposync();
141 
142 private:
143     AddonsTab( intf_thread_t *p_intf );
144     virtual ~AddonsTab();
145     bool eventFilter ( QObject * watched, QEvent * event );
146 
147     enum
148     {
149         ONLYLOCALADDONS = 0,
150         WITHONLINEADDONS
151     };
152     QListView *addonsView;
153     AddonsSortFilterProxyModel *addonsModel;
154     /* Wait spinner */
155     PixmapAnimator *spinnerAnimation;
156     bool b_localdone;
157     QSignalMapper *signalMapper;
158 };
159 
160 class PluginTreeItem : public QTreeWidgetItem
161 {
162 public:
PluginTreeItem(QStringList & qs_item,int Type=QTreeWidgetItem::Type)163     PluginTreeItem(QStringList &qs_item, int Type = QTreeWidgetItem::Type)
164             : QTreeWidgetItem (qs_item, Type) {}
~PluginTreeItem()165     virtual ~PluginTreeItem() {}
166 
167     virtual bool operator< ( const QTreeWidgetItem & other ) const;
168 };
169 
170 class ExtensionListModel : public QAbstractListModel
171 {
172 
173     Q_OBJECT
174 
175 public:
176     /* Safe copy of the extension_t struct */
177     class ExtensionCopy
178     {
179 
180     public:
181         ExtensionCopy( extension_t * );
182         ~ExtensionCopy();
183         QVariant data( int role ) const;
184 
185     private:
186         QString name, title, description, shortdesc, author, version, url;
187         QPixmap *icon;
188     };
189 
190     ExtensionListModel( QObject *parent, ExtensionsManager *EM );
191     ExtensionListModel( QObject *parent = 0 );
192     virtual ~ExtensionListModel();
193 
194     enum
195     {
196         SummaryRole = Qt::UserRole,
197         VersionRole,
198         AuthorRole,
199         LinkRole,
200         FilenameRole
201     };
202 
203     QVariant data( const QModelIndex& index, int role ) const Q_DECL_OVERRIDE;
204     QModelIndex index( int row, int column = 0,
205                        const QModelIndex& = QModelIndex() ) const Q_DECL_OVERRIDE;
206     int rowCount( const QModelIndex& = QModelIndex() ) const Q_DECL_OVERRIDE;
207 
208 protected slots:
209     void updateList();
210 
211 private:
212     ExtensionsManager *EM;
213     QList<ExtensionCopy*> extensions;
214 };
215 
216 class AddonsListModel: public ExtensionListModel
217 {
218     Q_OBJECT
219 
220 public:
221     AddonsListModel( AddonsManager *AM, QObject *parent = 0 );
222     virtual ~AddonsListModel();
223     QVariant data( const QModelIndex& index, int role ) const Q_DECL_OVERRIDE;
224     QModelIndex index( int row, int column = 0,
225                        const QModelIndex& = QModelIndex() ) const Q_DECL_OVERRIDE;
226     int rowCount( const QModelIndex& = QModelIndex() ) const Q_DECL_OVERRIDE;
227     Qt::ItemFlags flags( const QModelIndex &index ) const Q_DECL_OVERRIDE;
228     bool setData( const QModelIndex &index, const QVariant &value, int role ) Q_DECL_OVERRIDE;
229 
230     enum
231     {
232         TypeRole = FilenameRole + 1,
233         DescriptionRole,
234         UUIDRole,
235         FlagsRole,
236         StateRole,
237         DownloadsCountRole,
238         ScoreRole
239     };
240 
241     static QColor getColorByAddonType( int );
242 
243 protected slots:
244     void addonAdded( addon_entry_t * );
245     void addonChanged( const addon_entry_t * );
246 
247 protected:
248 
249     class Addon
250     {
251     public:
252         Addon( addon_entry_t * );
253         ~Addon();
254         bool operator==( const Addon & other ) const;
255         bool operator==( const addon_entry_t * p_other ) const;
256         QVariant data( int ) const;
257     private:
258         addon_entry_t * p_entry;
259     };
260 
261     QList<Addon*> addons;
262     AddonsManager *AM;
263 };
264 
265 class AddonsSortFilterProxyModel : public QSortFilterProxyModel
266 {
267     Q_OBJECT
268 
269 public:
270     AddonsSortFilterProxyModel( QObject *parent = 0 );
271 
272 public slots:
273     virtual void setTypeFilter( int );
274     virtual void setStatusFilter( int );
275 
276 protected:
277     bool filterAcceptsRow( int, const QModelIndex & ) const Q_DECL_OVERRIDE;
278 
279 private:
280     int i_type_filter;
281     int i_status_filter;
282 };
283 
284 class ExtensionItemDelegate : public QStyledItemDelegate
285 {
286     Q_OBJECT
287 
288 public:
289     ExtensionItemDelegate( QObject *parent );
290     virtual ~ExtensionItemDelegate();
291 
292     void paint( QPainter *painter,
293                 const QStyleOptionViewItem &option,
294                 const QModelIndex &index ) const Q_DECL_OVERRIDE;
295     QSize sizeHint( const QStyleOptionViewItem &option,
296                     const QModelIndex &index ) const Q_DECL_OVERRIDE;
297     void initStyleOption( QStyleOptionViewItem *option,
298                           const QModelIndex &index ) const Q_DECL_OVERRIDE;
299 
300 protected:
301     QMargins margins;
302 };
303 
304 
305 class AddonItemDelegate : public ExtensionItemDelegate
306 {
307     Q_OBJECT
308 
309 public:
310     AddonItemDelegate( QObject *parent );
311     ~AddonItemDelegate();
312 
313     void paint( QPainter *painter,
314                 const QStyleOptionViewItem &option,
315                 const QModelIndex &index ) const Q_DECL_OVERRIDE;
316     QSize sizeHint( const QStyleOptionViewItem &option,
317                     const QModelIndex &index ) const Q_DECL_OVERRIDE;
318     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
319     void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
320     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE;
321     void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
322 
323     void setAnimator( DelegateAnimationHelper *animator );
324 
325 public slots:
326     void editButtonClicked();
327 
328 signals:
329     void showInfo();
330 
331 protected:
332     DelegateAnimationHelper *animator;
333     QWidget *progressbar;
334 };
335 
336 class ExtensionInfoDialog : public QVLCDialog
337 {
338 public:
339     ExtensionInfoDialog( const QModelIndex &index,
340                          intf_thread_t *p_intf, QWidget *parent );
341 };
342 
343 class AddonInfoDialog : public QVLCDialog
344 {
345 public:
346     AddonInfoDialog( const QModelIndex &index,
347                      intf_thread_t *p_intf, QWidget *parent );
348 };
349 
350 #endif
351 
352