Commit bd396077 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: add addons management UI

parent aea9ebb9
......@@ -40,6 +40,7 @@ libqt4_plugin_la_SOURCES = \
input_manager.cpp input_manager.hpp \
actions_manager.cpp actions_manager.hpp \
extensions_manager.cpp extensions_manager.hpp \
managers/addons_manager.cpp managers/addons_manager.hpp \
recents.cpp recents.hpp \
adapters/seekpoints.cpp adapters/seekpoints.hpp \
adapters/chromaprint.cpp adapters/chromaprint.hpp \
......@@ -141,6 +142,7 @@ nodist_libqt4_plugin_la_SOURCES = \
input_manager.moc.cpp \
actions_manager.moc.cpp \
extensions_manager.moc.cpp \
managers/addons_manager.moc.cpp \
recents.moc.cpp \
adapters/seekpoints.moc.cpp \
adapters/chromaprint.moc.cpp \
......
This diff is collapsed.
......@@ -28,10 +28,13 @@
#include "util/singleton.hpp"
#include <vlc_extensions.h>
#include <vlc_addons.h>
#include <QStringList>
#include <QTreeWidgetItem>
#include <QPushButton>
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QStyledItemDelegate>
class QLabel;
......@@ -39,17 +42,22 @@ class QTabWidget;
class QComboBox;
class QTreeWidget;
class QLineEdit;
class QTextBrowser;
//class QTextBrowser;
class QListView;
class QStyleOptionViewItem;
class QPainter;
class QKeyEvent;
class PluginTab;
class ExtensionTab;
class AddonsTab;
class ExtensionListItem;
class SearchLineEdit;
class ExtensionCopy;
class ExtensionsManager;
class AddonsManager;
class PixmapAnimator;
class DelegateAnimationHelper;
class AddonsSortFilterProxyModel;
class PluginDialog : public QVLCFrame, public Singleton<PluginDialog>
{
......@@ -62,6 +70,7 @@ private:
QTabWidget *tabs;
PluginTab *pluginTab;
ExtensionTab *extensionTab;
AddonsTab *addonsTab;
friend class Singleton<PluginDialog>;
};
......@@ -116,6 +125,28 @@ private:
friend class PluginDialog;
};
class AddonsTab : public QVLCFrame
{
Q_OBJECT
friend class PluginDialog;
private slots:
void moreInformation();
void typeChanged( int );
void installChecked( int );
private:
AddonsTab( intf_thread_t *p_intf );
virtual ~AddonsTab();
bool eventFilter ( QObject * watched, QEvent * event );
QLabel *helpLabel;
QListView *addonsView;
AddonsSortFilterProxyModel *addonsModel;
/* Wait spinner */
PixmapAnimator *spinnerAnimation;
};
class PluginTreeItem : public QTreeWidgetItem
{
public:
......@@ -147,15 +178,16 @@ public:
};
ExtensionListModel( QObject *parent, ExtensionsManager *EM );
ExtensionListModel( QObject *parent = 0 );
virtual ~ExtensionListModel();
enum
{
DescriptionRole = Qt::UserRole,
SummaryRole = Qt::UserRole,
VersionRole,
AuthorRole,
LinkRole,
NameRole
FilenameRole
};
virtual QVariant data( const QModelIndex& index, int role ) const;
......@@ -163,17 +195,83 @@ public:
const QModelIndex& = QModelIndex() ) const;
virtual int rowCount( const QModelIndex& = QModelIndex() ) const;
private slots:
protected slots:
void updateList();
private:
ExtensionsManager *EM;
QList<ExtensionCopy*> extensions;
};
class AddonsListModel: public ExtensionListModel
{
Q_OBJECT
public:
AddonsListModel( AddonsManager *AM, QObject *parent = 0 );
virtual QVariant data( const QModelIndex& index, int role ) const;
virtual QModelIndex index( int row, int column = 0,
const QModelIndex& = QModelIndex() ) const;
virtual int rowCount( const QModelIndex& = QModelIndex() ) const;
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
enum
{
TypeRole = FilenameRole + 1,
DescriptionRole,
UUIDRole,
FlagsRole,
StateRole,
DownloadsCountRole,
ScoreRole
};
protected slots:
void addonAdded( addon_entry_t * );
void addonChanged( const addon_entry_t * );
protected:
class Addon
{
public:
Addon( addon_entry_t * );
~Addon();
bool operator==( const Addon & other ) const;
bool operator==( const addon_entry_t * p_other ) const;
QVariant data( int ) const;
private:
addon_entry_t * p_entry;
};
QList<Addon*> addons;
AddonsManager *AM;
};
class AddonsSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
AddonsSortFilterProxyModel( QObject *parent = 0 );
public slots:
virtual void setTypeFilter( int );
virtual void setStatusFilter( int );
protected:
virtual bool filterAcceptsRow( int, const QModelIndex & ) const;
private:
int i_type_filter;
int i_status_filter;
};
class ExtensionItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
ExtensionItemDelegate( QObject *parent );
virtual ~ExtensionItemDelegate();
......@@ -186,10 +284,42 @@ public:
virtual void initStyleOption( QStyleOptionViewItem *option,
const QModelIndex &index ) const;
private:
protected:
QMargins margins;
};
class AddonItemDelegate : public ExtensionItemDelegate
{
Q_OBJECT
public:
AddonItemDelegate( QObject *parent );
~AddonItemDelegate();
virtual void paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
virtual QSize sizeHint( const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setAnimator( DelegateAnimationHelper *animator );
public slots:
void editButtonClicked();
signals:
void showInfo();
protected:
DelegateAnimationHelper *animator;
QWidget *progressbar;
};
class ExtensionInfoDialog : public QVLCDialog
{
public:
......@@ -197,5 +327,12 @@ public:
intf_thread_t *p_intf, QWidget *parent );
};
class AddonInfoDialog : public QVLCDialog
{
public:
AddonInfoDialog( const QModelIndex &index,
intf_thread_t *p_intf, QWidget *parent );
};
#endif
/*****************************************************************************
* addons_manager.cpp: Addons manager for Qt
****************************************************************************
* Copyright (C) 2013 VideoLAN and authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "addons_manager.hpp"
#include <QApplication>
const QEvent::Type AddonManagerEvent::AddedEvent =
(QEvent::Type)QEvent::registerEventType();
const QEvent::Type AddonManagerEvent::ChangedEvent =
(QEvent::Type)QEvent::registerEventType();
const QEvent::Type AddonManagerEvent::DiscoveryEndedEvent =
(QEvent::Type)QEvent::registerEventType();
AddonsManager::AddonsManager( intf_thread_t *p_intf )
{
p_manager = addons_manager_New( VLC_OBJECT(p_intf) );
if ( !p_manager ) return;
vlc_event_manager_t *p_em = p_manager->p_event_manager;
vlc_event_attach( p_em, vlc_AddonFound, addonsEventsCallback, this );
vlc_event_attach( p_em, vlc_AddonsDiscoveryEnded, addonsEventsCallback, this );
vlc_event_attach( p_em, vlc_AddonChanged, addonsEventsCallback, this );
}
AddonsManager::~AddonsManager()
{
if ( p_manager )
addons_manager_Delete( p_manager );
}
void AddonsManager::findNewAddons()
{
addons_manager_Gather( p_manager, NULL );
}
void AddonsManager::findInstalled()
{
addons_manager_LoadCatalog( p_manager );
}
void AddonsManager::install( QByteArray id )
{
Q_ASSERT( id.size() == sizeof(addon_uuid_t) );
addon_uuid_t addonid;
memcpy( &addonid, id.constData(), sizeof(addon_uuid_t) );
addons_manager_Install( p_manager, addonid );
}
void AddonsManager::remove( QByteArray id )
{
Q_ASSERT( id.size() == sizeof(addon_uuid_t) );
addon_uuid_t addonid;
memcpy( &addonid, id.constData(), sizeof(addon_uuid_t) );
addons_manager_Remove( p_manager, addonid );
}
QString AddonsManager::getAddonType( int i_type )
{
switch ( i_type )
{
case ADDON_SKIN2:
return qtr( "Skins" );
case ADDON_PLAYLIST_PARSER:
return qtr("Playlist parsers");
case ADDON_SERVICE_DISCOVERY:
return qtr("Service Discovery");
case ADDON_EXTENSION:
return qtr("Extensions");
default:
return qtr("Unknown");
}
}
void AddonsManager::addonsEventsCallback( const vlc_event_t *event, void *data )
{
AddonsManager *me = ( AddonsManager * ) data;
QEvent *ev = NULL;
if ( event->type == vlc_AddonFound )
{
ev = new AddonManagerEvent( AddonManagerEvent::AddedEvent,
event->u.addon_generic_event.p_entry );
}
else if ( event->type == vlc_AddonsDiscoveryEnded )
{
ev = new QEvent( AddonManagerEvent::DiscoveryEndedEvent );
}
else if ( event->type == vlc_AddonChanged )
{
ev = new AddonManagerEvent( AddonManagerEvent::ChangedEvent,
event->u.addon_generic_event.p_entry );
}
if ( ev ) QApplication::postEvent( me, ev );
}
void AddonsManager::customEvent( QEvent *event )
{
if ( event->type() == AddonManagerEvent::AddedEvent )
{
AddonManagerEvent *ev = static_cast<AddonManagerEvent *>(event);
emit addonAdded( ev->entry() );
}
else if ( event->type() == AddonManagerEvent::ChangedEvent )
{
AddonManagerEvent *ev = static_cast<AddonManagerEvent *>(event);
emit addonChanged( ev->entry() );
}
else if ( event->type() == AddonManagerEvent::DiscoveryEndedEvent )
{
emit discoveryEnded();
}
}
/*****************************************************************************
* addons_manager.hpp: Addons manager for Qt
****************************************************************************
* Copyright (C) 2013 VideoLAN and authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef ADDONS_MANAGER_HPP
#define ADDONS_MANAGER_HPP
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "qt4.hpp"
#include "util/singleton.hpp"
#include <vlc_events.h>
#include <vlc_addons.h>
#include <QObject>
#include <QEvent>
class AddonManagerEvent : public QEvent
{
public:
static const QEvent::Type AddedEvent;
static const QEvent::Type ChangedEvent;
static const QEvent::Type DiscoveryEndedEvent;
AddonManagerEvent( QEvent::Type type, addon_entry_t *_p_entry )
: QEvent( type ), p_entry( _p_entry )
{
addon_entry_Hold( p_entry );
}
~AddonManagerEvent()
{
addon_entry_Release( p_entry );
}
addon_entry_t *entry() const { return p_entry; }
private:
addon_entry_t *p_entry;
};
class AddonsManager : public QObject, public Singleton<AddonsManager>
{
Q_OBJECT
friend class Singleton<AddonsManager>;
public:
AddonsManager( intf_thread_t * );
~AddonsManager();
static void addonsEventsCallback( const vlc_event_t *, void * );
void customEvent( QEvent * );
void install( QByteArray id );
void remove( QByteArray id );
static QString getAddonType( int );
signals:
void addonAdded( addon_entry_t * );
void addonChanged( const addon_entry_t * );
void discoveryEnded();
public slots:
void findNewAddons();
void findInstalled();
private:
addons_manager_t* p_manager;
};
#endif // ADDONS_MANAGER_HPP
......@@ -153,4 +153,9 @@
<file alias="katsomo">pixmaps/playlist/sidebar-icons/sd/katsomo.png</file>
<file alias="metachannels">pixmaps/playlist/sidebar-icons/sd/metachannels.png</file>
</qresource>
<qresource prefix="/addons">
<file alias="default">pixmaps/addons/addon.png</file>
<file alias="broken">pixmaps/addons/addon_broken.png</file>
<file alias="score">pixmaps/addons/score.png</file>
</qresource>
</RCC>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment