[vlc-commits] qt: medialib: define a super-type for list items

Romain Vimont git at videolan.org
Tue Dec 8 14:19:18 UTC 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Nov 24 15:48:28 2020 +0100| [985b37d0290200d37337fbee0481c6b6d9838288] | committer: Pierre Lamot

qt: medialib: define a super-type for list items

Concrete medialib item types are defined by the template parameter on
MLSlidingWindowModel.

Create a super-type to be able to "untemplatize" MLSlidingWindowModel
(in order to simplify and improve compilation times).

As a side-effect, this also makes explicit the necessity to define a
getId() method (called from MLSlidingWindowModel), a constraint which
could not be explicitly expressed on a template parameter.

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=985b37d0290200d37337fbee0481c6b6d9838288
---

 modules/gui/qt/medialibrary/mlalbum.cpp        |  9 ++-------
 modules/gui/qt/medialibrary/mlalbum.hpp        |  4 +---
 modules/gui/qt/medialibrary/mlalbumtrack.cpp   |  9 ++-------
 modules/gui/qt/medialibrary/mlalbumtrack.hpp   |  4 +---
 modules/gui/qt/medialibrary/mlartist.cpp       |  9 ++-------
 modules/gui/qt/medialibrary/mlartist.hpp       |  4 +---
 modules/gui/qt/medialibrary/mlgenre.cpp        | 11 +++--------
 modules/gui/qt/medialibrary/mlgenre.hpp        |  4 +---
 modules/gui/qt/medialibrary/mlqmltypes.hpp     | 12 ++++++++++++
 modules/gui/qt/medialibrary/mlrecentsmodel.cpp |  4 ++--
 modules/gui/qt/medialibrary/mlrecentsmodel.hpp |  4 +---
 modules/gui/qt/medialibrary/mlurlmodel.cpp     |  4 ++--
 modules/gui/qt/medialibrary/mlurlmodel.hpp     |  4 +---
 modules/gui/qt/medialibrary/mlvideo.cpp        | 13 ++++---------
 modules/gui/qt/medialibrary/mlvideo.hpp        |  5 +----
 15 files changed, 36 insertions(+), 64 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlalbum.cpp b/modules/gui/qt/medialibrary/mlalbum.cpp
index 6f3b5f053c..6a80648b33 100644
--- a/modules/gui/qt/medialibrary/mlalbum.cpp
+++ b/modules/gui/qt/medialibrary/mlalbum.cpp
@@ -20,8 +20,8 @@
 
 MLAlbum::MLAlbum(vlc_medialibrary_t* _ml, const vlc_ml_album_t *_data, QObject *_parent)
     : QObject( _parent )
+    , MLItem        ( MLItemId( _data->i_id, VLC_ML_PARENT_ALBUM ) )
     , m_ml          ( _ml )
-    , m_id          ( _data->i_id, VLC_ML_PARENT_ALBUM )
     , m_title       ( QString::fromUtf8( _data->psz_title ) )
     , m_releaseYear ( _data->i_year )
     , m_shortSummary( QString::fromUtf8( _data->psz_summary ) )
@@ -58,8 +58,8 @@ MLAlbum::MLAlbum(vlc_medialibrary_t* _ml, const vlc_ml_album_t *_data, QObject *
 //private ctor for cloning
 MLAlbum::MLAlbum(const MLAlbum& _album, QObject *_parent)
     : QObject( _parent )
+    , MLItem        ( _album.getId() )
     , m_ml          ( _album.m_ml )
-    , m_id          ( _album.m_id )
     , m_title       ( _album.m_title )
     , m_releaseYear ( _album.m_releaseYear )
     , m_shortSummary( _album.m_shortSummary )
@@ -70,11 +70,6 @@ MLAlbum::MLAlbum(const MLAlbum& _album, QObject *_parent)
 {
 }
 
-MLItemId MLAlbum::getId() const
-{
-    return m_id;
-}
-
 QString MLAlbum::getTitle() const
 {
     return m_title;
diff --git a/modules/gui/qt/medialibrary/mlalbum.hpp b/modules/gui/qt/medialibrary/mlalbum.hpp
index 525834a91c..3050227796 100644
--- a/modules/gui/qt/medialibrary/mlalbum.hpp
+++ b/modules/gui/qt/medialibrary/mlalbum.hpp
@@ -31,7 +31,7 @@
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
-class MLAlbum : public QObject
+class MLAlbum : public QObject, public MLItem
 {
     Q_OBJECT
 
@@ -48,7 +48,6 @@ class MLAlbum : public QObject
 public:
     MLAlbum(vlc_medialibrary_t* _ml, const vlc_ml_album_t *_data, QObject *_parent = nullptr);
 
-    MLItemId getId() const;
     QString getTitle() const;
     unsigned int getReleaseYear() const;
     QString getShortSummary() const;
@@ -70,7 +69,6 @@ private:
 
     vlc_medialibrary_t* m_ml;
 
-    MLItemId m_id;
     QString m_title;
     unsigned int m_releaseYear;
     QString m_shortSummary;
diff --git a/modules/gui/qt/medialibrary/mlalbumtrack.cpp b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
index 4d13479150..1bc1d600cb 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrack.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
@@ -22,7 +22,7 @@
 
 MLAlbumTrack::MLAlbumTrack(vlc_medialibrary_t* _ml, const vlc_ml_media_t *_data, QObject *_parent )
     : QObject( _parent )
-    , m_id         ( _data->i_id, VLC_ML_PARENT_UNKNOWN )
+    , MLItem       ( MLItemId( _data->i_id, VLC_ML_PARENT_UNKNOWN ) )
     , m_title      ( QString::fromUtf8( _data->psz_title ) )
     , m_trackNumber( _data->album_track.i_track_nb )
     , m_discNumber( _data->album_track.i_disc_nb )
@@ -84,7 +84,7 @@ MLAlbumTrack::MLAlbumTrack(vlc_medialibrary_t* _ml, const vlc_ml_media_t *_data,
 
 MLAlbumTrack::MLAlbumTrack(const MLAlbumTrack &albumtrack, QObject *_parent)
     : QObject( _parent )
-    , m_id           ( albumtrack.m_id )
+    , MLItem         ( albumtrack.getId() )
     , m_title        ( albumtrack.m_title )
     , m_albumTitle   ( albumtrack.m_albumTitle )
     , m_artist       ( albumtrack.m_artist )
@@ -97,11 +97,6 @@ MLAlbumTrack::MLAlbumTrack(const MLAlbumTrack &albumtrack, QObject *_parent)
 {
 }
 
-MLItemId MLAlbumTrack::getId() const
-{
-    return m_id;
-}
-
 QString MLAlbumTrack::getTitle() const
 {
     return m_title;
diff --git a/modules/gui/qt/medialibrary/mlalbumtrack.hpp b/modules/gui/qt/medialibrary/mlalbumtrack.hpp
index 19b40619a6..70b0e001f3 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrack.hpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrack.hpp
@@ -31,7 +31,7 @@
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
-class MLAlbumTrack : public QObject
+class MLAlbumTrack : public QObject, public MLItem
 {
     Q_OBJECT
 
@@ -49,7 +49,6 @@ class MLAlbumTrack : public QObject
 public:
     MLAlbumTrack(vlc_medialibrary_t *_ml, const vlc_ml_media_t *_data, QObject *_parent = nullptr);
 
-    MLItemId getId() const;
     QString getTitle() const;
     QString getAlbumTitle() const;
     QString getArtist() const;
@@ -65,7 +64,6 @@ public:
 private:
     MLAlbumTrack(const MLAlbumTrack& albumtrack, QObject *_parent = nullptr);
 
-    MLItemId m_id;
     QString m_title;
     QString m_albumTitle;
     QString m_artist;
diff --git a/modules/gui/qt/medialibrary/mlartist.cpp b/modules/gui/qt/medialibrary/mlartist.cpp
index e66a323a98..af40f2018e 100644
--- a/modules/gui/qt/medialibrary/mlartist.cpp
+++ b/modules/gui/qt/medialibrary/mlartist.cpp
@@ -21,7 +21,7 @@
 
 MLArtist::MLArtist(const vlc_ml_artist_t* _data, QObject *_parent)
     : QObject(_parent)
-    , m_id      ( _data->i_id, VLC_ML_PARENT_ARTIST )
+    , MLItem    ( MLItemId( _data->i_id, VLC_ML_PARENT_ARTIST ) )
     , m_name    ( QString::fromUtf8( _data->psz_name ) )
     , m_shortBio( QString::fromUtf8( _data->psz_shortbio ) )
     , m_cover   ( QString::fromUtf8( _data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
@@ -33,7 +33,7 @@ MLArtist::MLArtist(const vlc_ml_artist_t* _data, QObject *_parent)
 
 MLArtist::MLArtist(const MLArtist &artist, QObject *_parent)
     : QObject(_parent)
-    , m_id      ( artist.m_id )
+    , MLItem    ( artist.getId() )
     , m_name    ( artist.m_name )
     , m_shortBio( artist.m_shortBio )
     , m_cover   ( artist.m_cover )
@@ -43,11 +43,6 @@ MLArtist::MLArtist(const MLArtist &artist, QObject *_parent)
 
 }
 
-MLItemId MLArtist::getId() const
-{
-    return m_id;
-}
-
 QString MLArtist::getName() const
 {
     return m_name;
diff --git a/modules/gui/qt/medialibrary/mlartist.hpp b/modules/gui/qt/medialibrary/mlartist.hpp
index 355196f69a..099b8c208f 100644
--- a/modules/gui/qt/medialibrary/mlartist.hpp
+++ b/modules/gui/qt/medialibrary/mlartist.hpp
@@ -34,7 +34,7 @@
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
-class MLArtist : public QObject
+class MLArtist : public QObject, public MLItem
 {
     Q_OBJECT
 
@@ -48,7 +48,6 @@ class MLArtist : public QObject
 public:
     MLArtist(const vlc_ml_artist_t *_data, QObject *_parent = nullptr);
 
-    MLItemId getId() const;
     QString getName() const;
     QString getShortBio() const;
     QString getCover() const;
@@ -64,7 +63,6 @@ public:
 private:
     MLArtist(const MLArtist &artist, QObject *_parent = nullptr);
 
-    MLItemId m_id;
     QString m_name;
     QString m_shortBio;
     QString m_cover;
diff --git a/modules/gui/qt/medialibrary/mlgenre.cpp b/modules/gui/qt/medialibrary/mlgenre.cpp
index 66fe0184a9..316db042a8 100644
--- a/modules/gui/qt/medialibrary/mlgenre.cpp
+++ b/modules/gui/qt/medialibrary/mlgenre.cpp
@@ -211,8 +211,8 @@ private:
 
 MLGenre::MLGenre(vlc_medialibrary_t* ml, const vlc_ml_genre_t *_data, QObject *_parent )
     : QObject(_parent)
+    , MLItem    ( MLItemId( _data->i_id, VLC_ML_PARENT_GENRE ) )
     , m_ml      ( ml )
-    , m_id      ( _data->i_id, VLC_ML_PARENT_GENRE )
     , m_name    ( QString::fromUtf8( _data->psz_name ) )
     , m_nbTracks ( (unsigned int)_data->i_nb_tracks )
 
@@ -223,8 +223,8 @@ MLGenre::MLGenre(vlc_medialibrary_t* ml, const vlc_ml_genre_t *_data, QObject *_
 
 MLGenre::MLGenre(const MLGenre &genre, QObject *_parent)
     : QObject(_parent)
+    , MLItem    ( genre.getId() )
     , m_ml      ( genre.m_ml )
-    , m_id      ( genre.m_id )
     , m_name    ( genre.m_name )
     , m_nbTracks( genre.m_nbTracks )
 {
@@ -242,11 +242,6 @@ MLGenre::~MLGenre()
     }
 }
 
-MLItemId MLGenre::getId() const
-{
-    return m_id;
-}
-
 QString MLGenre::getName() const
 {
     return m_name;
@@ -291,7 +286,7 @@ void MLGenre::generateThumbnail()
         dir.mkdir("qt-genre-covers");
         dir.cd("qt-genre-covers");
 
-        QString filename = QString("genre_thumbnail_%1.jpg").arg(m_id.id);
+        QString filename = QString("genre_thumbnail_%1.jpg").arg(getId().id);
         QString absoluteFilePath =  dir.absoluteFilePath(filename);
         if (dir.exists(filename))
         {
diff --git a/modules/gui/qt/medialibrary/mlgenre.hpp b/modules/gui/qt/medialibrary/mlgenre.hpp
index 8eebe7c1f6..8f47e631cd 100644
--- a/modules/gui/qt/medialibrary/mlgenre.hpp
+++ b/modules/gui/qt/medialibrary/mlgenre.hpp
@@ -33,7 +33,7 @@
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
-class MLGenre : public QObject
+class MLGenre : public QObject, public MLItem
 {
     Q_OBJECT
 
@@ -46,7 +46,6 @@ public:
     MLGenre( vlc_medialibrary_t* _ml, const vlc_ml_genre_t *_data, QObject *_parent = nullptr);
     ~MLGenre();
 
-    MLItemId getId() const;
     QString getName() const;
     unsigned int getNbTracks() const;
     QString getCover() const;
@@ -68,7 +67,6 @@ private:
 
     vlc_medialibrary_t* m_ml;
 
-    MLItemId m_id;
     QString m_name;
     QString m_cover;
     QRunnable* m_coverTask = nullptr;
diff --git a/modules/gui/qt/medialibrary/mlqmltypes.hpp b/modules/gui/qt/medialibrary/mlqmltypes.hpp
index 7adcdb7d07..cc4f75e4e0 100644
--- a/modules/gui/qt/medialibrary/mlqmltypes.hpp
+++ b/modules/gui/qt/medialibrary/mlqmltypes.hpp
@@ -62,4 +62,16 @@ public:
 
 Q_DECLARE_METATYPE(MLItemId)
 
+class MLItem
+{
+public:
+    MLItem(MLItemId id) : m_id(id) {}
+    virtual ~MLItem() = default;
+
+    MLItemId getId() const { return m_id; };
+
+private:
+    MLItemId m_id;
+};
+
 #endif // MLQMLTYPES_HPP
diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
index 7d4b5cc7e2..25029467b0 100644
--- a/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlrecentsmodel.cpp
@@ -20,14 +20,14 @@
 #include <QDateTime>
 
 MLRecentMedia::MLRecentMedia( const vlc_ml_media_t *media )
-    : m_id (media->i_id, VLC_ML_PARENT_UNKNOWN)
+    : MLItem( MLItemId( media->i_id, VLC_ML_PARENT_UNKNOWN ) )
     , m_url ( media->p_files->i_nb_items > 0 ? media->p_files->p_items[0].psz_mrl : "" )
     , m_lastPlayedDate(QDateTime::fromTime_t( media->i_last_played_date ))
 {
 }
 
 MLRecentMedia::MLRecentMedia( const MLRecentMedia& media )
-    : m_id(media.m_id)
+    : MLItem(media.getId())
     , m_url(media.m_url)
     , m_lastPlayedDate(media.m_lastPlayedDate)
 {
diff --git a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
index d551c7700a..2c586f6b60 100644
--- a/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlrecentsmodel.hpp
@@ -32,7 +32,7 @@
 #include <QObject>
 #include <QDateTime>
 
-class MLRecentMedia {
+class MLRecentMedia : public MLItem {
 public:
     MLRecentMedia( const vlc_ml_media_t *_data );
 
@@ -40,12 +40,10 @@ public:
 
     inline QUrl getUrl() const { return m_url; }
     inline QDateTime getLastPlayedDate() const { return m_lastPlayedDate; }
-    inline MLItemId getId() const { return m_id; }
 
     MLRecentMedia *clone() const;
 
 private:
-    MLItemId m_id;
     QUrl m_url;
     QDateTime m_lastPlayedDate;
 };
diff --git a/modules/gui/qt/medialibrary/mlurlmodel.cpp b/modules/gui/qt/medialibrary/mlurlmodel.cpp
index dc199ed657..268f96b967 100644
--- a/modules/gui/qt/medialibrary/mlurlmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlurlmodel.cpp
@@ -97,7 +97,7 @@ void MLUrlModel::onVlcMlEvent(const MLEvent &event)
 }
 
 MLUrl::MLUrl(const vlc_ml_media_t *_data)
-    : m_id( _data->i_id, VLC_ML_PARENT_UNKNOWN )
+    : MLItem( MLItemId( _data->i_id, VLC_ML_PARENT_UNKNOWN ) )
     , m_url( _data->p_files->i_nb_items > 0 ? _data->p_files->p_items[0].psz_mrl : "" )
     , m_lastPlayedDate(
           QDateTime::fromTime_t( _data->i_last_played_date ).toString( QLocale::system().dateFormat( QLocale::ShortFormat ) )
@@ -106,7 +106,7 @@ MLUrl::MLUrl(const vlc_ml_media_t *_data)
 }
 
 MLUrl::MLUrl(const MLUrl &url)
-    : m_id( url.m_id )
+    : MLItem( url.getId() )
     , m_url( url.m_url )
     , m_lastPlayedDate( url.m_lastPlayedDate )
 {
diff --git a/modules/gui/qt/medialibrary/mlurlmodel.hpp b/modules/gui/qt/medialibrary/mlurlmodel.hpp
index ac9e3202ae..4a28aa0f3a 100644
--- a/modules/gui/qt/medialibrary/mlurlmodel.hpp
+++ b/modules/gui/qt/medialibrary/mlurlmodel.hpp
@@ -30,7 +30,7 @@
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
-class MLUrl {
+class MLUrl : public MLItem {
 public:
     MLUrl( const vlc_ml_media_t *_data );
 
@@ -38,12 +38,10 @@ public:
 
     QString getUrl() const;
     QString getLastPlayedDate() const;
-    MLItemId getId() const { return m_id; }
 
     MLUrl *clone() const;
 
 private:
-    MLItemId m_id;
     QString m_url;
     QString m_lastPlayedDate;
 };
diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index a13bafd907..cefb9504d6 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -76,8 +76,8 @@ unsigned int AudioDescription::getSampleRate() const
 
 MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* parent)
     : QObject( parent )
+    , MLItem( MLItemId( data->i_id, VLC_ML_PARENT_UNKNOWN ) )
     , m_ml( ml )
-    , m_id( data->i_id, VLC_ML_PARENT_UNKNOWN )
     , m_title( QString::fromUtf8( data->psz_title ) )
     , m_thumbnail( QString::fromUtf8( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
     , m_progress( data->f_progress )
@@ -143,8 +143,8 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
 
 MLVideo::MLVideo(const MLVideo& video, QObject* parent)
     : QObject( parent )
+    , MLItem( video.getId() )
     , m_ml( video.m_ml )
-    , m_id( video.m_id )
     , m_title( video.m_title )
     , m_thumbnail( video.m_thumbnail )
     , m_duration( video.m_duration )
@@ -165,7 +165,7 @@ void MLVideo::onMlEvent( const vlc_ml_event_t* event )
     if ( event->i_type != VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED ||
          event->media_thumbnail_generated.i_size != VLC_ML_THUMBNAIL_SMALL )
         return;
-    if ( event->media_thumbnail_generated.p_media->i_id != m_id.id )
+    if ( event->media_thumbnail_generated.p_media->i_id != getId().id )
         return;
     if ( event->media_thumbnail_generated.b_success == false )
     {
@@ -180,11 +180,6 @@ void MLVideo::onMlEvent( const vlc_ml_event_t* event )
     emit onThumbnailChanged( m_thumbnail );
 }
 
-MLItemId MLVideo::getId() const
-{
-    return m_id;
-}
-
 QString MLVideo::getTitle() const
 {
     return m_title;
@@ -196,7 +191,7 @@ QString MLVideo::getThumbnail()
          m_thumbnailStatus == VLC_ML_THUMBNAIL_STATUS_FAILURE )
     {
         m_ml_event_handle.reset( vlc_ml_event_register_callback( m_ml, onMlEvent, this ) );
-        vlc_ml_media_generate_thumbnail( m_ml, m_id.id, VLC_ML_THUMBNAIL_SMALL,
+        vlc_ml_media_generate_thumbnail( m_ml, getId().id, VLC_ML_THUMBNAIL_SMALL,
                                          512, 320, .15 );
     }
 
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index 545ffe7614..8041881280 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -79,7 +79,7 @@ private:
     unsigned int m_sampleRate;
 };
 
-class MLVideo : public QObject
+class MLVideo : public QObject, public MLItem
 {
     Q_OBJECT
 
@@ -101,7 +101,6 @@ class MLVideo : public QObject
 public:
     MLVideo(vlc_medialibrary_t *ml, const vlc_ml_media_t *data, QObject *parent = nullptr);
 
-    MLItemId getId() const;
     QString getTitle() const;
     QString getThumbnail();
     QString getDuration() const;
@@ -127,9 +126,7 @@ private:
     static void onMlEvent( void* data, const vlc_ml_event_t* event );
     void onMlEvent( const vlc_ml_event_t* event );
 
-
     vlc_medialibrary_t* m_ml;
-    MLItemId m_id;
     QString m_title;
     QString m_thumbnail;
     int64_t m_duration;



More information about the vlc-commits mailing list