[vlc-devel] [PATCH 1/2] qt: add extension manager model

Pierre Lamot pierre at videolabs.io
Fri Oct 11 10:51:10 CEST 2019


Hi,

Sorry for the late review.

On samedi 31 août 2019 14:54:39 CEST Sagar Kohli wrote:
> ---
>  modules/gui/qt/Makefile.am                    |   3 +
>  modules/gui/qt/components/extension_model.cpp | 141 ++++++++++++++++++
>  modules/gui/qt/components/extension_model.hpp |  91 +++++++++++
>  modules/gui/qt/main_interface.cpp             |   3 +
>  4 files changed, 238 insertions(+)
>  create mode 100644 modules/gui/qt/components/extension_model.cpp
>  create mode 100644 modules/gui/qt/components/extension_model.hpp
> 
> diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
> index bdf5dcd5cf..1107905966 100644
> --- a/modules/gui/qt/Makefile.am
> +++ b/modules/gui/qt/Makefile.am
> @@ -176,6 +176,8 @@ libqt_plugin_la_SOURCES = \
>  	gui/qt/components/sout/sout_widgets.cpp \
>  	gui/qt/components/sout/sout_widgets.hpp \
>  	gui/qt/components/sout/profiles.hpp \
> +	gui/qt/components/extension_model.cpp \
> +	gui/qt/components/extension_model.hpp \
>  	gui/qt/util/animators.cpp gui/qt/util/animators.hpp \
>  	gui/qt/util/input_slider.cpp gui/qt/util/input_slider.hpp \
>  	gui/qt/util/input_models.cpp gui/qt/util/input_models.hpp \
> @@ -298,6 +300,7 @@ nodist_libqt_plugin_la_SOURCES = \
>  	gui/qt/components/playlist/playlist_controller.moc.cpp \
>  	gui/qt/components/sout/profile_selector.moc.cpp \
>  	gui/qt/components/sout/sout_widgets.moc.cpp \
> +	gui/qt/components/extension_model.moc.cpp \
>  	gui/qt/util/animators.moc.cpp \
>  	gui/qt/util/input_slider.moc.cpp \
>  	gui/qt/util/input_models.moc.cpp \
> diff --git a/modules/gui/qt/components/extension_model.cpp b/modules/gui/qt/components/extension_model.cpp
> new file mode 100644
> index 0000000000..e28d878e88
> --- /dev/null
> +++ b/modules/gui/qt/components/extension_model.cpp
> @@ -0,0 +1,141 @@
> +/*****************************************************************************
> + * Copyright (C) 2019 VLC authors and VideoLAN
> + *
> + * 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 "extension_model.hpp"
> +
> +ExtensionModel::ExtensionModel(extension_t *p_ext, QObject *parent)
> +    : QObject(parent), m_ext(p_ext)
> +{
> +}
> +
> +QString ExtensionModel::name() const
> +{
> +    return qfu( m_ext->psz_name );
> +}
> +
> +QString ExtensionModel::title() const
> +{
> +    return qfu( m_ext->psz_title );
> +}
> +
> +QString ExtensionModel::description() const
> +{
> +    return qfu( m_ext->psz_description );
> +}
> +
> +QString ExtensionModel::shortdes() const
> +{
> +    return qfu( m_ext->psz_shortdescription );
> +}
> +
> +QString ExtensionModel::author() const
> +{
> +    return qfu( m_ext->psz_author );
> +}
> +
> +QString ExtensionModel::version() const
> +{
> +    return qfu( m_ext->psz_version );
> +}
> +
> +QUrl ExtensionModel::url() const
> +{
> +    return qfu( m_ext->psz_url );
> +}
> +
> +ExtensionManager::ExtensionManager(QObject *)
> +{
> +}
> +
> +ExtensionManager::~ExtensionManager()
> +{
> +    // Clear extensions list
> +    m_extensionsList.clear();
> +}
> +
> +void ExtensionManager::updateList()
> +{
> +    // Clear extensions list
> +    m_extensionsList.clear();

You should check that EM has been set.

> +    // Find new extensions
> +    extensions_manager_t *p_mgr = EM->getManager();
> +    if( !p_mgr )
> +        return;
> +
> +    vlc_mutex_locker lock( &p_mgr->lock );
> +    extension_t *p_ext;
> +    ARRAY_FOREACH( p_ext, p_mgr->extensions )
> +    {
> +        m_extensionsList.emplace_back( std::make_unique<ExtensionModel> ( p_ext, this ) );
> +    }
> +}
> +
> +void ExtensionManager::activate(int row)
> +{
> +    uint16_t i_ext = (uint16_t)row;
> +

You should check that EM has been set.

> +    extensions_manager_t *p_mgr = EM->getManager();
> +
> +    vlc_mutex_locker lock( &p_mgr->lock );
> +
> +    extension_t *p_ext = ARRAY_VAL( p_mgr->extensions, i_ext );
> +    assert( p_ext != NULL);

the assertion seems a little strong here. I'd rather have a warning and return.

> +    if( extension_TriggerOnly( p_mgr, p_ext ) )
> +    {
> +        extension_Trigger( p_mgr, p_ext );
> +    }
> +    else
> +    {
> +        if( !extension_IsActivated( p_mgr, p_ext ) )
> +            extension_Activate( p_mgr, p_ext );
> +        else
> +            extension_Deactivate( p_mgr, p_ext );
> +    }
> +}
> +
> +int ExtensionManager::itemSize(QQmlListProperty<ExtensionModel> *property)
> +{
> +    ExtensionManager *extManager = static_cast< ExtensionManager *>(property->data);
> +    return extManager->m_extensionsList.size();
> +}
> +
> +ExtensionModel *ExtensionManager::itemAt(QQmlListProperty<ExtensionModel> *property, int index)
> +{
> +    ExtensionManager *extManager = static_cast< ExtensionManager *>(property->data);
> +    return extManager->m_extensionsList[index].get();
> +}
> +
> +QQmlListProperty<ExtensionModel> ExtensionManager::getExtensions()
> +{
> +    return QQmlListProperty<ExtensionModel>(this, static_cast<void *>(this), &itemSize, &itemAt);
> +}
> +
> +QmlMainContext* ExtensionManager::getMainCtx()
> +{
> +    return m_mainCtx;
> +}
> +
> +void ExtensionManager::setMainCtx(QmlMainContext *ctx)
> +{
> +    m_mainCtx = ctx;

you should check that m_mainCtx is not null.

> +    EM = ExtensionsManager::getInstance(m_mainCtx->getIntf());
> +    CONNECT( EM, extensionsUpdated(), this, updateList() );
> +    EM->loadExtensions();
> +}
> diff --git a/modules/gui/qt/components/extension_model.hpp b/modules/gui/qt/components/extension_model.hpp
> new file mode 100644
> index 0000000000..896ec59081
> --- /dev/null
> +++ b/modules/gui/qt/components/extension_model.hpp
> @@ -0,0 +1,91 @@
> +/*****************************************************************************
> + * Copyright (C) 2019 VLC authors and VideoLAN
> + *
> + * 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 EXTENSION_MODEL_HPP
> +#define EXTENSION_MODEL_HPP
> +
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#include <QAbstractListModel>
> +#include "extensions_manager.hpp"
> +#include <QQmlListProperty>
> +#include <QStringList>
> +#include <vlc_extensions.h>
> +#include "qml_main_context.hpp"
> +#include <QUrl>
> +#include <QObject>
> +#include <QList>
> +
> +class ExtensionModel : public QObject
> +{
> +    Q_OBJECT
> +
> +    Q_PROPERTY(QString name READ name CONSTANT)
> +    Q_PROPERTY(QString title READ title CONSTANT)
> +    Q_PROPERTY(QString description READ description CONSTANT)
> +    Q_PROPERTY(QString shortdes READ shortdes CONSTANT)
> +    Q_PROPERTY(QString author READ author CONSTANT)
> +    Q_PROPERTY(QString version READ version CONSTANT)
> +    Q_PROPERTY(QUrl url READ url CONSTANT)
> +
> +private:
> +    extension_t *m_ext;
> +
> +public:
> +    ExtensionModel(extension_t *p_ext, QObject *parent=0);
> +
> +    QString name() const;
> +    QString title() const;
> +    QString description() const;
> +    QString shortdes() const;
> +    QString author() const;
> +    QString version() const;
> +    QUrl url() const;
> +
> +};
> +
> +class ExtensionManager: public QObject
> +{
> +    Q_OBJECT
> +    Q_PROPERTY(QQmlListProperty<ExtensionModel> extensions READ getExtensions CONSTANT);
> +    Q_PROPERTY(QmlMainContext* mainCtx READ getMainCtx WRITE setMainCtx);
> +
> +public:
> +    ExtensionManager(QObject *parent = nullptr);
> +    virtual ~ExtensionManager();
> +
> +    static int itemSize(QQmlListProperty<ExtensionModel> *property);
> +    static ExtensionModel *itemAt(QQmlListProperty<ExtensionModel> *property, int index);
> +    QQmlListProperty<ExtensionModel> getExtensions();
> +    QmlMainContext* getMainCtx();
> +    void setMainCtx(QmlMainContext*);
> +
> +protected slots:
> +    void updateList();
> +    Q_INVOKABLE void activate(int row);

Why is your slot protected? it is called from outside in your QML patch.

> +private:
> +    ExtensionsManager *EM;
> +    std::vector<std::unique_ptr<ExtensionModel>> m_extensionsList;
> +    QmlMainContext* m_mainCtx;
> +    
> +};
> +
> +#endif // EXTENSION_MODEL_HPP
> diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
> index eb28983885..707d4ea520 100644
> --- a/modules/gui/qt/main_interface.cpp
> +++ b/modules/gui/qt/main_interface.cpp
> @@ -54,6 +54,7 @@
>  #include "components/mediacenter/mlnetworkmodel.hpp"
>  #include "components/recent_media_model.hpp"
>  #include "components/settings.hpp"
> +#include "components/extension_model.hpp"
>  
>  #include "components/navigation_history.hpp"
>  #include "components/aboutmodel.hpp"
> @@ -374,6 +375,8 @@ void MainInterface::createMainWidget( QSettings * )
>      qmlRegisterType<DialogModel>("org.videolan.vlc", 0, 1, "DialogModel");
>  
>      qmlRegisterType<QmlEventFilter>( "org.videolan.vlc", 0, 1, "EventFilter" );
> +    qmlRegisterType<ExtensionManager>( "org.videolan.vlc", 0, 1, "ExtensionManager");
> +    qmlRegisterUncreatableType<ExtensionModel>( "org.videolan.vlc", 0, 1, "ExtensionModel", "");
>  
>      qmlRegisterType<PlayerControlBarModel>( "org.videolan.vlc", 0, 1, "PlayerControlBarModel");
>  
> 


-- 
--
Pierre Lamot





More information about the vlc-devel mailing list