[vlc-devel] [PATCH 7/8] qt: medialib: handle events from the UI thread
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Mon Nov 9 11:51:49 CET 2020
On Mon, Nov 9, 2020, at 10:58 AM, Romain Vimont wrote:
> The medialib events notify changes that must be reflected in the UI, but
> they can be executed from any thread, so it is incorrect to update the
> UI from there (for example calling dataChanged() using an index not
> necessary valid within the UI thread).
>
> The callbacks provide an event structure pointing to data which are only
> valid during the callback, so create a struct to copy the values and
> dispatch the events to the UI thread.
> ---
> modules/gui/qt/Makefile.am | 1 +
> modules/gui/qt/medialibrary/mlalbummodel.cpp | 8 +-
> modules/gui/qt/medialibrary/mlalbummodel.hpp | 2 +-
> .../gui/qt/medialibrary/mlalbumtrackmodel.cpp | 12 +-
> .../gui/qt/medialibrary/mlalbumtrackmodel.hpp | 2 +-
> modules/gui/qt/medialibrary/mlartistmodel.cpp | 6 +-
> modules/gui/qt/medialibrary/mlartistmodel.hpp | 2 +-
> modules/gui/qt/medialibrary/mlbasemodel.cpp | 10 +-
> modules/gui/qt/medialibrary/mlbasemodel.hpp | 11 +-
> modules/gui/qt/medialibrary/mlevent.hpp | 108 ++++++++++++++++++
> modules/gui/qt/medialibrary/mlgenremodel.cpp | 4 +-
> modules/gui/qt/medialibrary/mlgenremodel.hpp | 2 +-
> .../gui/qt/medialibrary/mlrecentsmodel.cpp | 4 +-
> .../gui/qt/medialibrary/mlrecentsmodel.hpp | 2 +-
> .../qt/medialibrary/mlrecentsvideomodel.cpp | 4 +-
> .../qt/medialibrary/mlrecentsvideomodel.hpp | 2 +-
> modules/gui/qt/medialibrary/mlurlmodel.cpp | 4 +-
> modules/gui/qt/medialibrary/mlurlmodel.hpp | 2 +-
> modules/gui/qt/medialibrary/mlvideomodel.cpp | 4 +-
> modules/gui/qt/medialibrary/mlvideomodel.hpp | 2 +-
> 20 files changed, 152 insertions(+), 40 deletions(-)
> create mode 100644 modules/gui/qt/medialibrary/mlevent.hpp
>
> diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
> index 1d1880a777..f327b81317 100644
> --- a/modules/gui/qt/Makefile.am
> +++ b/modules/gui/qt/Makefile.am
> @@ -146,6 +146,7 @@ libqt_plugin_la_SOURCES = \
> gui/qt/medialibrary/mlbasemodel.hpp \
> gui/qt/medialibrary/mlbookmarkmodel.cpp \
> gui/qt/medialibrary/mlbookmarkmodel.hpp \
> + gui/qt/medialibrary/mlevent.hpp \
> gui/qt/medialibrary/mlfoldersmodel.cpp \
> gui/qt/medialibrary/mlfoldersmodel.hpp \
> gui/qt/medialibrary/mlgenre.cpp \
> diff --git a/modules/gui/qt/medialibrary/mlalbummodel.cpp
> b/modules/gui/qt/medialibrary/mlalbummodel.cpp
> index 2326c43718..acb6e7fbec 100644
> --- a/modules/gui/qt/medialibrary/mlalbummodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlalbummodel.cpp
> @@ -113,9 +113,9 @@ QByteArray
> MLAlbumModel::criteriaToName(vlc_ml_sorting_criteria_t criteria) cons
> return M_names_to_criteria.key(criteria, "");
> }
>
> -void MLAlbumModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLAlbumModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch( event->i_type )
> + switch( event.i_type )
> {
> case VLC_ML_EVENT_ALBUM_ADDED:
> case VLC_ML_EVENT_ALBUM_DELETED:
> @@ -124,12 +124,12 @@ void MLAlbumModel::onVlcMlEvent(const
> vlc_ml_event_t* event)
> break;
> case VLC_ML_EVENT_ARTIST_DELETED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_ARTIST &&
> - event->deletion.i_entity_id == m_parent.id )
> + event.deletion.i_entity_id == m_parent.id )
> m_need_reset = true;
> break;
> case VLC_ML_EVENT_GENRE_DELETED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_GENRE &&
> - event->deletion.i_entity_id == m_parent.id )
> + event.deletion.i_entity_id == m_parent.id )
> m_need_reset = true;
> break;
> default:
> diff --git a/modules/gui/qt/medialibrary/mlalbummodel.hpp
> b/modules/gui/qt/medialibrary/mlalbummodel.hpp
> index 972fbc64a7..804f32fe5b 100644
> --- a/modules/gui/qt/medialibrary/mlalbummodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlalbummodel.hpp
> @@ -63,7 +63,7 @@ private:
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const
> override;
> QByteArray criteriaToName(vlc_ml_sorting_criteria_t criteria)
> const override;
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
> void thumbnailUpdated(int idx) override;
>
> static QHash<QByteArray, vlc_ml_sorting_criteria_t>
> M_names_to_criteria;
> diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
> b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
> index d0efbf56f9..4d07c93757 100644
> --- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
> @@ -144,12 +144,12 @@ QByteArray
> MLAlbumTrackModel::criteriaToName(vlc_ml_sorting_criteria_t criteria)
> return M_names_to_criteria.key(criteria, "");
> }
>
> -void MLAlbumTrackModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLAlbumTrackModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_MEDIA_ADDED:
> - if ( event->creation.p_media->i_subtype ==
> VLC_ML_MEDIA_SUBTYPE_ALBUMTRACK )
> + if ( event.creation.media.i_subtype ==
> VLC_ML_MEDIA_SUBTYPE_ALBUMTRACK )
> m_need_reset = true;
> break;
> case VLC_ML_EVENT_MEDIA_UPDATED:
> @@ -160,17 +160,17 @@ void MLAlbumTrackModel::onVlcMlEvent(const
> vlc_ml_event_t* event)
> break;
> case VLC_ML_EVENT_ALBUM_UPDATED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_ALBUM &&
> - m_parent.id == event->modification.i_entity_id )
> + m_parent.id == event.modification.i_entity_id )
> m_need_reset = true;
> break;
> case VLC_ML_EVENT_ALBUM_DELETED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_ALBUM &&
> - m_parent.id == event->deletion.i_entity_id )
> + m_parent.id == event.deletion.i_entity_id )
> m_need_reset = true;
> break;
> case VLC_ML_EVENT_GENRE_DELETED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_GENRE &&
> - m_parent.id == event->deletion.i_entity_id )
> + m_parent.id == event.deletion.i_entity_id )
> m_need_reset = true;
> break;
> }
> diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
> b/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
> index 30a00ec478..93785660ce 100644
> --- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
> @@ -63,7 +63,7 @@ private:
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const
> override;
> QByteArray criteriaToName(vlc_ml_sorting_criteria_t criteria)
> const override;
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
>
> static QHash<QByteArray, vlc_ml_sorting_criteria_t>
> M_names_to_criteria;
> };
> diff --git a/modules/gui/qt/medialibrary/mlartistmodel.cpp
> b/modules/gui/qt/medialibrary/mlartistmodel.cpp
> index d9db186457..8bc65fb6b0 100644
> --- a/modules/gui/qt/medialibrary/mlartistmodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlartistmodel.cpp
> @@ -114,9 +114,9 @@ QByteArray
> MLArtistModel::criteriaToName(vlc_ml_sorting_criteria_t criteria) con
> return M_names_to_criteria.key(criteria, "");
> }
>
> -void MLArtistModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLArtistModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_ARTIST_ADDED:
> case VLC_ML_EVENT_ARTIST_UPDATED:
> @@ -125,7 +125,7 @@ void MLArtistModel::onVlcMlEvent(const
> vlc_ml_event_t* event)
> break;
> case VLC_ML_EVENT_GENRE_DELETED:
> if ( m_parent.id != 0 && m_parent.type ==
> VLC_ML_PARENT_GENRE &&
> - m_parent.id == event->deletion.i_entity_id )
> + m_parent.id == event.deletion.i_entity_id )
> m_need_reset = true;
> break;
> }
> diff --git a/modules/gui/qt/medialibrary/mlartistmodel.hpp
> b/modules/gui/qt/medialibrary/mlartistmodel.hpp
> index ef92fdf65d..af495d969d 100644
> --- a/modules/gui/qt/medialibrary/mlartistmodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlartistmodel.hpp
> @@ -54,7 +54,7 @@ private:
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const
> override;
> QByteArray criteriaToName(vlc_ml_sorting_criteria_t criteria)
> const override;
> - virtual void onVlcMlEvent(const vlc_ml_event_t* event) override;
> + virtual void onVlcMlEvent(const MLEvent &event) override;
> void thumbnailUpdated(int idx) override;
>
> static QHash<QByteArray, vlc_ml_sorting_criteria_t>
> M_names_to_criteria;
> diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp
> b/modules/gui/qt/medialibrary/mlbasemodel.cpp
> index f5b88da271..9805e9e86b 100644
> --- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
> @@ -70,12 +70,12 @@ void MLBaseModel::onResetRequested()
> endResetModel();
> }
>
> -void MLBaseModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLBaseModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch(event->i_type)
> + switch(event.i_type)
> {
> case VLC_ML_EVENT_BACKGROUND_IDLE_CHANGED:
> - if ( event->background_idle_changed.b_idle && m_need_reset )
> + if ( event.background_idle_changed.b_idle && m_need_reset )
> {
> emit resetRequested();
> m_need_reset = false;
> @@ -95,7 +95,9 @@ QString MLBaseModel::getFirstSymbol(QString str)
> void MLBaseModel::onVlcMlEvent(void* data, const vlc_ml_event_t* event)
> {
> auto self = static_cast<MLBaseModel*>(data);
> - self->onVlcMlEvent(event);
> + QMetaObject::invokeMethod(self, [self, event = MLEvent(event)] {
> + self->onVlcMlEvent(event);
> + });
> }
>
> MLParentId MLBaseModel::parentId() const
> diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp
> b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> index 4da5f5e31d..e52e7506c6 100644
> --- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> @@ -31,6 +31,7 @@
> #include "mlqmltypes.hpp"
> #include "medialib.hpp"
> #include <memory>
> +#include "mlevent.hpp"
>
> class MediaLib;
>
> @@ -103,7 +104,7 @@ public:
> virtual unsigned int getCount() const = 0;
>
> protected:
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event );
> + virtual void onVlcMlEvent( const MLEvent &event );
>
> MLParentId m_parent;
>
> @@ -271,16 +272,16 @@ protected:
> return m_item_list[idx - m_query_param.i_offset].get();
> }
>
> - virtual void onVlcMlEvent(const vlc_ml_event_t* event) override
> + virtual void onVlcMlEvent(const MLEvent &event) override
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED:
> {
> - if (event->media_thumbnail_generated.b_success) {
> + if (event.media_thumbnail_generated.b_success) {
> int idx = static_cast<int>(m_query_param.i_offset);
> for ( const auto& it : m_item_list ) {
> - if (it->getId().id ==
> event->media_thumbnail_generated.p_media->i_id) {
> + if (it->getId().id ==
> event.media_thumbnail_generated.i_media_id) {
> thumbnailUpdated(idx);
> break;
> }
> diff --git a/modules/gui/qt/medialibrary/mlevent.hpp
> b/modules/gui/qt/medialibrary/mlevent.hpp
> new file mode 100644
> index 0000000000..9ff34f2c3f
> --- /dev/null
> +++ b/modules/gui/qt/medialibrary/mlevent.hpp
> @@ -0,0 +1,108 @@
> +/*****************************************************************************
> + * 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.
> +
> *****************************************************************************/
> +#pragma once
> +
> +#include <vlc_media_library.h>
> +
> +/**
> + * Owned (and simplified) version of vlc_ml_event_t, which can be
> copied and
> + * moved to another thread.
> + */
> +struct MLEvent
> +{
> + int i_type;
> + union
> + {
> + struct
> + {
> + int64_t i_entity_id;
> + union {
> + struct {
> + vlc_ml_media_subtype_t i_subtype;
> + } media;
> + };
> + } creation;
> + struct
> + {
> + int64_t i_entity_id;
> + } modification;
> + struct
> + {
> + int64_t i_entity_id;
> + } deletion;
> + struct
> + {
> + bool b_idle;
> + } background_idle_changed;
> + struct
> + {
> + int64_t i_media_id;
> + bool b_success;
> + } media_thumbnail_generated;
> + };
> +
> + explicit MLEvent(const vlc_ml_event_t *event)
> + {
> + i_type = event->i_type;
> + switch (event->i_type)
> + {
> + case VLC_ML_EVENT_MEDIA_ADDED:
> + creation.i_entity_id = event->creation.p_media->i_id;
> + creation.media.i_subtype =
> event->creation.p_media->i_subtype;
> + break;
> + case VLC_ML_EVENT_ARTIST_ADDED:
> + creation.i_entity_id = event->creation.p_artist->i_id;
> + break;
> + case VLC_ML_EVENT_ALBUM_ADDED:
> + creation.i_entity_id = event->creation.p_album->i_id;
> + break;
> + case VLC_ML_EVENT_PLAYLIST_ADDED:
> + creation.i_entity_id =
> event->creation.p_playlist->i_id;
> + break;
> + case VLC_ML_EVENT_GENRE_ADDED:
> + creation.i_entity_id = event->creation.p_genre->i_id;
> + break;
> + case VLC_ML_EVENT_BOOKMARKS_ADDED:
> + creation.i_entity_id =
> event->creation.p_bookmark->i_media_id;
> + break;
> + case VLC_ML_EVENT_MEDIA_UPDATED:
> + case VLC_ML_EVENT_ARTIST_UPDATED:
> + case VLC_ML_EVENT_ALBUM_UPDATED:
> + case VLC_ML_EVENT_PLAYLIST_UPDATED:
> + case VLC_ML_EVENT_GENRE_UPDATED:
> + case VLC_ML_EVENT_BOOKMARKS_UPDATED:
> + modification.i_entity_id =
> event->modification.i_entity_id;
> + break;
> + case VLC_ML_EVENT_MEDIA_DELETED:
> + case VLC_ML_EVENT_ARTIST_DELETED:
> + case VLC_ML_EVENT_ALBUM_DELETED:
> + case VLC_ML_EVENT_PLAYLIST_DELETED:
> + case VLC_ML_EVENT_GENRE_DELETED:
> + case VLC_ML_EVENT_BOOKMARKS_DELETED:
> + deletion.i_entity_id = event->deletion.i_entity_id;
> + break;
> + case VLC_ML_EVENT_BACKGROUND_IDLE_CHANGED:
> + background_idle_changed.b_idle =
> event->background_idle_changed.b_idle;
> + break;
> + case VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED:
> + media_thumbnail_generated.i_media_id =
> event->media_thumbnail_generated.p_media->i_id;
> + media_thumbnail_generated.b_success =
> event->media_thumbnail_generated.b_success;
> + break;
> + }
> + }
> +};
> diff --git a/modules/gui/qt/medialibrary/mlgenremodel.cpp
> b/modules/gui/qt/medialibrary/mlgenremodel.cpp
> index 9e83fbfdb5..55bf5e78a9 100644
> --- a/modules/gui/qt/medialibrary/mlgenremodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlgenremodel.cpp
> @@ -89,9 +89,9 @@ size_t MLGenreModel::countTotalElements() const
> return vlc_ml_count_genres( m_ml, &queryParams );
> }
>
> -void MLGenreModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLGenreModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_GENRE_ADDED:
> case VLC_ML_EVENT_GENRE_UPDATED:
> diff --git a/modules/gui/qt/medialibrary/mlgenremodel.hpp
> b/modules/gui/qt/medialibrary/mlgenremodel.hpp
> index bef6eb140a..6943207d03 100644
> --- a/modules/gui/qt/medialibrary/mlgenremodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlgenremodel.hpp
> @@ -54,7 +54,7 @@ public:
> private:
> std::vector<std::unique_ptr<MLGenre>> fetch() override;
> size_t countTotalElements() const override;
> - void onVlcMlEvent(const vlc_ml_event_t* event) override;
> + void onVlcMlEvent(const MLEvent &event) override;
> void thumbnailUpdated(int idx) override;
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const
> override;
> diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
> b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
> index 3b1ef5ffa9..8cdcbfacbf 100644
> --- a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
> @@ -111,9 +111,9 @@ size_t MLRecentsModel::countTotalElements() const
> return realCount;
> }
>
> -void MLRecentsModel::onVlcMlEvent( const vlc_ml_event_t* event )
> +void MLRecentsModel::onVlcMlEvent( const MLEvent &event )
> {
> - switch ( event->i_type )
> + switch ( event.i_type )
> {
> case VLC_ML_EVENT_MEDIA_ADDED:
> case VLC_ML_EVENT_MEDIA_UPDATED:
> diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
> b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
> index 6feb7da3da..8040c2918f 100644
> --- a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
> @@ -84,7 +84,7 @@ private:
> vlc_ml_sorting_criteria_t nameToCriteria( QByteArray /* name */ )
> const override{
> return VLC_ML_SORTING_DEFAULT;
> }
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
> };
>
> #endif // ML_RECENTS_MODEL_H
> diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
> b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
> index 35e8a544b1..2e7c1947f6 100644
> --- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
> @@ -118,9 +118,9 @@ size_t MLRecentsVideoModel::countTotalElements()
> const
> return std::min(m_video_count,numberOfItemsToShow);
> }
>
> -void MLRecentsVideoModel::onVlcMlEvent( const vlc_ml_event_t* event )
> +void MLRecentsVideoModel::onVlcMlEvent( const MLEvent &event )
> {
> - switch ( event->i_type )
> + switch ( event.i_type )
> {
> case VLC_ML_EVENT_MEDIA_ADDED:
> case VLC_ML_EVENT_MEDIA_UPDATED:
> diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
> b/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
> index ef6e473ae6..65c923b8bd 100644
> --- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.hpp
> @@ -53,7 +53,7 @@ private:
> vlc_ml_sorting_criteria_t nameToCriteria( QByteArray /* name */ )
> const override{
> return VLC_ML_SORTING_DEFAULT;
> }
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
> void setNumberOfItemsToShow(int);
> int getNumberOfItemsToShow();
> int m_video_count;
> diff --git a/modules/gui/qt/medialibrary/mlurlmodel.cpp
> b/modules/gui/qt/medialibrary/mlurlmodel.cpp
> index 5f48f3071e..92a114a4fe 100644
> --- a/modules/gui/qt/medialibrary/mlurlmodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlurlmodel.cpp
> @@ -106,9 +106,9 @@ vlc_ml_sorting_criteria_t
> MLUrlModel::roleToCriteria(int role) const
> }
> }
>
> -void MLUrlModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLUrlModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_MEDIA_UPDATED:
> case VLC_ML_EVENT_HISTORY_CHANGED:
> diff --git a/modules/gui/qt/medialibrary/mlurlmodel.hpp
> b/modules/gui/qt/medialibrary/mlurlmodel.hpp
> index 8feb87a4f8..425edb48e5 100644
> --- a/modules/gui/qt/medialibrary/mlurlmodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlurlmodel.hpp
> @@ -73,7 +73,7 @@ private:
> std::vector<std::unique_ptr<MLUrl>> fetch() override;
> size_t countTotalElements() const override;
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
> };
>
> #endif // MLURLMODEL_H
> diff --git a/modules/gui/qt/medialibrary/mlvideomodel.cpp
> b/modules/gui/qt/medialibrary/mlvideomodel.cpp
> index 80fe7f15e7..21332e298a 100644
> --- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
> +++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
> @@ -137,9 +137,9 @@ QByteArray
> MLVideoModel::criteriaToName(vlc_ml_sorting_criteria_t criteria) cons
> return M_names_to_criteria.key(criteria, "");
> }
>
> -void MLVideoModel::onVlcMlEvent(const vlc_ml_event_t* event)
> +void MLVideoModel::onVlcMlEvent(const MLEvent &event)
> {
> - switch (event->i_type)
> + switch (event.i_type)
> {
> case VLC_ML_EVENT_MEDIA_ADDED:
> case VLC_ML_EVENT_MEDIA_UPDATED:
> diff --git a/modules/gui/qt/medialibrary/mlvideomodel.hpp
> b/modules/gui/qt/medialibrary/mlvideomodel.hpp
> index 4c85885106..653c6e164c 100644
> --- a/modules/gui/qt/medialibrary/mlvideomodel.hpp
> +++ b/modules/gui/qt/medialibrary/mlvideomodel.hpp
> @@ -67,7 +67,7 @@ private:
> size_t countTotalElements() const override;
> vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
> vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const
> override;
> - virtual void onVlcMlEvent( const vlc_ml_event_t* event ) override;
> + virtual void onVlcMlEvent( const MLEvent &event ) override;
> virtual void thumbnailUpdated( int ) override;
>
> static QHash<QByteArray, vlc_ml_sorting_criteria_t> M_names_to_criteria;
Hi,
Wouldn't it be better to transfer the ownership of the provided data to the callback, rather than copying it every time?
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list