[vlc-commits] qt: notify dataChanged when a thumbnail is updated from the medialibrary
Pierre Lamot
git at videolan.org
Thu Feb 20 13:56:38 CET 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Feb 13 17:45:10 2020 +0100| [683dc6ee2dc67d1ba82834a724a27e2a4bca67ca] | committer: Jean-Baptiste Kempf
qt: notify dataChanged when a thumbnail is updated from the medialibrary
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=683dc6ee2dc67d1ba82834a724a27e2a4bca67ca
---
modules/gui/qt/medialibrary/mlalbum.cpp | 2 +-
modules/gui/qt/medialibrary/mlalbum.hpp | 4 ++--
modules/gui/qt/medialibrary/mlalbummodel.cpp | 9 +++++++--
modules/gui/qt/medialibrary/mlalbummodel.hpp | 1 +
modules/gui/qt/medialibrary/mlartistmodel.cpp | 7 ++++++-
modules/gui/qt/medialibrary/mlartistmodel.hpp | 1 +
modules/gui/qt/medialibrary/mlbasemodel.hpp | 25 +++++++++++++++++++++++++
modules/gui/qt/medialibrary/mlgenremodel.cpp | 7 ++++++-
modules/gui/qt/medialibrary/mlgenremodel.hpp | 1 +
modules/gui/qt/medialibrary/mlvideomodel.cpp | 8 +++++++-
modules/gui/qt/medialibrary/mlvideomodel.hpp | 1 +
11 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/modules/gui/qt/medialibrary/mlalbum.cpp b/modules/gui/qt/medialibrary/mlalbum.cpp
index 88df4f034a..2c4a1e9bb8 100644
--- a/modules/gui/qt/medialibrary/mlalbum.cpp
+++ b/modules/gui/qt/medialibrary/mlalbum.cpp
@@ -62,7 +62,7 @@ MLAlbum::MLAlbum(const MLAlbum& _album, QObject *_parent)
{
}
-MLParentId MLAlbum::getParentId() const
+MLParentId MLAlbum::getId() const
{
return m_id;
}
diff --git a/modules/gui/qt/medialibrary/mlalbum.hpp b/modules/gui/qt/medialibrary/mlalbum.hpp
index be14d0a990..b907e441b0 100644
--- a/modules/gui/qt/medialibrary/mlalbum.hpp
+++ b/modules/gui/qt/medialibrary/mlalbum.hpp
@@ -35,7 +35,7 @@ class MLAlbum : public QObject
{
Q_OBJECT
- Q_PROPERTY(MLParentId id READ getParentId CONSTANT)
+ Q_PROPERTY(MLParentId id READ getId CONSTANT)
Q_PROPERTY(QString title READ getTitle CONSTANT)
Q_PROPERTY(unsigned int releaseyear READ getReleaseYear CONSTANT)
Q_PROPERTY(QString shortsummary READ getShortSummary CONSTANT)
@@ -47,7 +47,7 @@ class MLAlbum : public QObject
public:
MLAlbum(vlc_medialibrary_t* _ml, const vlc_ml_album_t *_data, QObject *_parent = nullptr);
- MLParentId getParentId() const;
+ MLParentId getId() const;
QString getTitle() const;
unsigned int getReleaseYear() const;
QString getShortSummary() const;
diff --git a/modules/gui/qt/medialibrary/mlalbummodel.cpp b/modules/gui/qt/medialibrary/mlalbummodel.cpp
index b5ee3f251e..0d4b438284 100644
--- a/modules/gui/qt/medialibrary/mlalbummodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbummodel.cpp
@@ -44,7 +44,7 @@ QVariant MLAlbumModel::data(const QModelIndex &index, int role) const
switch (role)
{
case ALBUM_ID :
- return QVariant::fromValue( ml_item->getParentId() );
+ return QVariant::fromValue( ml_item->getId() );
case ALBUM_TITLE :
return QVariant::fromValue( ml_item->getTitle() );
case ALBUM_RELEASE_YEAR :
@@ -125,7 +125,12 @@ void MLAlbumModel::onVlcMlEvent(const vlc_ml_event_t* event)
default:
break;
}
- MLBaseModel::onVlcMlEvent( event );
+ MLSlidingWindowModel::onVlcMlEvent( event );
+}
+
+void MLAlbumModel::thumbnailUpdated(int idx)
+{
+ emit dataChanged(index(idx), index(idx), {ALBUM_COVER});
}
vlc_ml_sorting_criteria_t MLAlbumModel::roleToCriteria(int role) const
diff --git a/modules/gui/qt/medialibrary/mlalbummodel.hpp b/modules/gui/qt/medialibrary/mlalbummodel.hpp
index b0befe5b77..6b5dcfc145 100644
--- a/modules/gui/qt/medialibrary/mlalbummodel.hpp
+++ b/modules/gui/qt/medialibrary/mlalbummodel.hpp
@@ -60,6 +60,7 @@ private:
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;
+ void thumbnailUpdated(int idx) 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 3994bd9197..c453b83701 100644
--- a/modules/gui/qt/medialibrary/mlartistmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlartistmodel.cpp
@@ -137,5 +137,10 @@ void MLArtistModel::onVlcMlEvent(const vlc_ml_event_t* event)
m_need_reset = true;
break;
}
- MLBaseModel::onVlcMlEvent(event);
+ MLSlidingWindowModel::onVlcMlEvent(event);
+}
+
+void MLArtistModel::thumbnailUpdated(int idx)
+{
+ emit dataChanged(index(idx), index(idx), {ARTIST_COVER});
}
diff --git a/modules/gui/qt/medialibrary/mlartistmodel.hpp b/modules/gui/qt/medialibrary/mlartistmodel.hpp
index e3e0a2433d..66ca9b35ce 100644
--- a/modules/gui/qt/medialibrary/mlartistmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlartistmodel.hpp
@@ -45,6 +45,7 @@ private:
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;
+ 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.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp
index bdacb415b6..ff0157e92a 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
@@ -193,9 +193,34 @@ protected:
return m_item_list[idx - m_query_param.i_offset].get();
}
+ virtual void onVlcMlEvent(const vlc_ml_event_t* event) override
+ {
+ switch (event->i_type)
+ {
+ case VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED:
+ {
+ 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) {
+ thumbnailUpdated(idx);
+ break;
+ }
+ idx += 1;
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ MLBaseModel::onVlcMlEvent( event );
+ }
+
private:
virtual size_t countTotalElements() const = 0;
virtual std::vector<std::unique_ptr<T>> fetch() = 0;
+ virtual void thumbnailUpdated( int ) {}
protected:
mutable std::vector<std::unique_ptr<T>> m_item_list;
diff --git a/modules/gui/qt/medialibrary/mlgenremodel.cpp b/modules/gui/qt/medialibrary/mlgenremodel.cpp
index 433a8e7cde..a3f9a2dec6 100644
--- a/modules/gui/qt/medialibrary/mlgenremodel.cpp
+++ b/modules/gui/qt/medialibrary/mlgenremodel.cpp
@@ -111,7 +111,12 @@ void MLGenreModel::onVlcMlEvent(const vlc_ml_event_t* event)
m_need_reset = true;
break;
}
- MLBaseModel::onVlcMlEvent(event);
+ MLSlidingWindowModel::onVlcMlEvent(event);
+}
+
+void MLGenreModel::thumbnailUpdated(int idx)
+{
+ emit dataChanged(index(idx), index(idx), {GENRE_COVER});
}
vlc_ml_sorting_criteria_t MLGenreModel::roleToCriteria(int role) const
diff --git a/modules/gui/qt/medialibrary/mlgenremodel.hpp b/modules/gui/qt/medialibrary/mlgenremodel.hpp
index c83ee01688..2b171e5b42 100644
--- a/modules/gui/qt/medialibrary/mlgenremodel.hpp
+++ b/modules/gui/qt/medialibrary/mlgenremodel.hpp
@@ -43,6 +43,7 @@ private:
std::vector<std::unique_ptr<MLGenre>> fetch() override;
size_t countTotalElements() const override;
void onVlcMlEvent(const vlc_ml_event_t* 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/mlvideomodel.cpp b/modules/gui/qt/medialibrary/mlvideomodel.cpp
index 365cd4d3cf..3338970730 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
@@ -162,8 +162,14 @@ void MLVideoModel::onVlcMlEvent(const vlc_ml_event_t* event)
default:
break;
}
- MLBaseModel::onVlcMlEvent( event );
+ MLSlidingWindowModel::onVlcMlEvent( event );
}
+
+void MLVideoModel::thumbnailUpdated(int idx)
+{
+ emit dataChanged(index(idx), index(idx), {VIDEO_THUMBNAIL});
+}
+
QString MLVideoModel::getFirstSymbol( const QString& str )
{
QString ret("#");
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.hpp b/modules/gui/qt/medialibrary/mlvideomodel.hpp
index 2e55a5f94e..ecde78171c 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.hpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.hpp
@@ -48,6 +48,7 @@ private:
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 thumbnailUpdated( int ) override;
static QHash<QByteArray, vlc_ml_sorting_criteria_t> M_names_to_criteria;
static QString getFirstSymbol( const QString& str );
More information about the vlc-commits
mailing list