[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt: add playCount property in MLMedia

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Aug 5 08:34:32 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
1e3abca0 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: add playCount property in MLMedia

- - - - -
5dda46f8 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: store thumbnailStatus in MLMedia

- - - - -
ba0e5088 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: allow modification inside MLMedia

derive classes may want to change the data to keep it sync with parent models, don't add setters since MLMedia itself don't need to change

- - - - -
db397e90 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: add progressTime in MLMedia

- - - - -
10b70bc7 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: derive MLVideo from MLMedia

- - - - -
554e464c by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: derive MLPlaylistMedia from MLMedia

- - - - -
b975e608 by Prince Gupta at 2024-08-05T08:04:10+00:00
qt: remove unused functions from MLPlaylistMedia

- - - - -


8 changed files:

- modules/gui/qt/medialibrary/mlmedia.hpp
- modules/gui/qt/medialibrary/mlplaylistmedia.cpp
- modules/gui/qt/medialibrary/mlplaylistmedia.hpp
- modules/gui/qt/medialibrary/mlplaylistmodel.cpp
- modules/gui/qt/medialibrary/mlvideo.cpp
- modules/gui/qt/medialibrary/mlvideo.hpp
- modules/gui/qt/medialibrary/mlvideogroupsmodel.cpp
- modules/gui/qt/medialibrary/mlvideomodel.cpp


Changes:

=====================================
modules/gui/qt/medialibrary/mlmedia.hpp
=====================================
@@ -41,6 +41,7 @@ class MLMedia : public MLItem
     Q_PROPERTY(QString bannerCover READ bannerCover CONSTANT FINAL)
     Q_PROPERTY(VLCTick duration READ duration CONSTANT FINAL)
     Q_PROPERTY(qreal progress READ progress CONSTANT FINAL)
+    Q_PROPERTY(int playCount READ playCount CONSTANT FINAL)
 
 public:
     MLMedia() : MLItem {MLItemId()} {}
@@ -50,8 +51,11 @@ public:
     {
         const auto getThumbnail = [](const vlc_ml_thumbnail_t & thumbnail)
         {
-            return (thumbnail.i_status == VLC_ML_THUMBNAIL_STATUS_AVAILABLE)
+            const QString mrl =
+                    (thumbnail.i_status == VLC_ML_THUMBNAIL_STATUS_AVAILABLE)
                     ? qfu(thumbnail.psz_mrl) : QString {};
+
+            return MLThumbnail{ mrl, thumbnail.i_status };
         };
 
         m_title = qfu(media->psz_title);
@@ -60,23 +64,45 @@ public:
         m_bannerCover = getThumbnail(media->thumbnails[VLC_ML_THUMBNAIL_BANNER]);
         m_duration = VLCTick::fromMS(media->i_duration);
         m_progress = media->f_progress;
+        m_playCount = media->i_playcount;
     }
 
     QString title() const { return m_title; }
     QString fileName() const { return m_fileName; }
-    QString smallCover() const { return m_smallCover; }
-    QString bannerCover() const { return m_bannerCover; }
     VLCTick duration() const {  return m_duration; }
     qreal progress() const { return m_progress; }
+    int playCount() const { return m_playCount; }
+
+    QString smallCover(vlc_ml_thumbnail_status_t* status = nullptr) const
+    {
+        if (status) *status = m_smallCover.status;
+        return m_smallCover.mrl;
+    }
+
+    QString bannerCover(vlc_ml_thumbnail_status_t* status = nullptr) const
+    {
+        if (status) *status = m_bannerCover.status;
+        return m_bannerCover.mrl;
+    }
+
+    VLCTick progressTime() const { return VLCTick::fromMS(m_duration * m_progress); }
 
     Q_INVOKABLE bool valid() const { return getId().id != INVALID_MLITEMID_ID; }
 
-private:
+
+protected:
+    struct MLThumbnail
+    {
+        QString mrl;
+        vlc_ml_thumbnail_status_t status;
+    };
+
     QString m_title;
     QString m_fileName;
-    QString m_smallCover;
-    QString m_bannerCover;
+    MLThumbnail m_smallCover;
+    MLThumbnail m_bannerCover;
     VLCTick m_duration;
     qreal m_progress;
+    int m_playCount;
 };
 


=====================================
modules/gui/qt/medialibrary/mlplaylistmedia.cpp
=====================================
@@ -28,14 +28,7 @@
 //-------------------------------------------------------------------------------------------------
 
 MLPlaylistMedia::MLPlaylistMedia(const vlc_ml_media_t * data)
-    : MLItem(MLItemId(data->i_id, VLC_ML_PARENT_UNKNOWN))
-    , m_type(data->i_type)
-    , m_title(qfu(data->psz_title))
-    , m_thumbnail(qfu(data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl))
-    , m_thumbnailStatus(data->thumbnails[VLC_ML_THUMBNAIL_SMALL].i_status)
-    , m_duration(data->i_duration)
-    , m_progress(data->f_progress)
-    , m_playCount(data->i_playcount)
+    : MLMedia(data)
 {
     for (const vlc_ml_file_t & file : ml_range_iterate<vlc_ml_file_t>(data->p_files))
     {
@@ -112,30 +105,10 @@ vlc_ml_media_type_t MLPlaylistMedia::getType() const
     return m_type;
 }
 
-QString MLPlaylistMedia::getTitle() const
-{
-    return m_title;
-}
-
-// FIXME: We have the same code in MLVideo implementation.
-QString MLPlaylistMedia::getThumbnail(vlc_ml_thumbnail_status_t* status)
-{
-    if (status)
-        *status = m_thumbnailStatus;
-    return m_thumbnail;
-}
-
-void MLPlaylistMedia::setThumbnail(const QString& thumbnail, vlc_ml_thumbnail_status_t status)
-{
-    m_thumbnail = thumbnail;
-    m_thumbnailStatus = status;
-}
-
-//-------------------------------------------------------------------------------------------------
 
-VLCTick MLPlaylistMedia::getDuration() const
+void MLPlaylistMedia::setSmallCover(const QString& thumbnail, vlc_ml_thumbnail_status_t status)
 {
-    return VLCTick::fromMS(m_duration);
+    m_smallCover = { thumbnail, status };
 }
 
 //-------------------------------------------------------------------------------------------------
@@ -167,25 +140,6 @@ QString MLPlaylistMedia::getMRLDisplay() const
 
 //-------------------------------------------------------------------------------------------------
 
-double MLPlaylistMedia::getProgress() const
-{
-    return m_progress;
-}
-
-VLCTick MLPlaylistMedia::getProgressTime() const
-{
-    return VLCTick::fromMS(m_duration * m_progress);
-}
-
-//-------------------------------------------------------------------------------------------------
-
-unsigned int MLPlaylistMedia::getPlayCount() const
-{
-    return m_playCount;
-}
-
-//-------------------------------------------------------------------------------------------------
-
 QList<VideoDescription> MLPlaylistMedia::getVideo() const
 {
     return m_video;


=====================================
modules/gui/qt/medialibrary/mlplaylistmedia.hpp
=====================================
@@ -24,6 +24,8 @@
 #endif
 
 // MediaLibrary includes
+#include "mlmedia.hpp"
+
 // NOTE: We need that header for VideoDescription and AudioDescription.
 #include "mlvideo.hpp"
 
@@ -35,7 +37,7 @@ class VLCTick;
 // Forward declarations
 struct vlc_medialibrary_t;
 
-class MLPlaylistMedia : public MLItem
+class MLPlaylistMedia : public MLMedia
 {
 public:
     MLPlaylistMedia( const vlc_ml_media_t * data);
@@ -45,12 +47,7 @@ public: // Interface
 
     vlc_ml_media_type_t getType() const;
 
-    QString getTitle() const;
-
-    QString getThumbnail(vlc_ml_thumbnail_status_t* status = nullptr);
-    void setThumbnail(const QString& thumbnail, vlc_ml_thumbnail_status_t status);
-
-    VLCTick getDuration() const;
+    void setSmallCover(const QString& thumbnail, vlc_ml_thumbnail_status_t status);
 
     QString getResolutionName() const;
 
@@ -59,41 +56,16 @@ public: // Interface
     QString getMRL       () const;
     QString getMRLDisplay() const;
 
-    double   getProgress    () const;
-    VLCTick getProgressTime() const;
-
-    unsigned int getPlayCount() const;
-
     QList<VideoDescription> getVideo() const;
     QList<AudioDescription> getAudio() const;
 
-
-private: // Events
-    static void onMlEvent(void * data, const vlc_ml_event_t * event);
-
-    void onMlEvent(const vlc_ml_event_t * event);
-
-private: // Properties
+private:
+    // Properties
     vlc_ml_media_type_t m_type;
 
-    QString m_title;
-
-    QString                   m_thumbnail;
-    vlc_ml_thumbnail_status_t m_thumbnailStatus;
-
-    int64_t m_duration;
-
     QString m_resolution;
-
     QString m_channel;
-
     QUrl m_mrl;
-
-    double   m_progress;
-    QString m_progressTime;
-
-    unsigned int m_playCount;
-
     QList<VideoDescription> m_video;
     QList<AudioDescription> m_audio;
 };


=====================================
modules/gui/qt/medialibrary/mlplaylistmodel.cpp
=====================================
@@ -341,11 +341,11 @@ QVariant MLPlaylistModel::itemRoleData(MLItem *item, int role) const /* override
         case MEDIA_IS_NEW:
             return QVariant::fromValue(media->isNew());
         case MEDIA_TITLE:
-            return QVariant::fromValue(media->getTitle());
+            return QVariant::fromValue(media->title());
         case MEDIA_THUMBNAIL:
         {
             vlc_ml_thumbnail_status_t status;
-            QString thumbnail = media->getThumbnail(&status);
+            QString thumbnail = media->smallCover(&status);
             if ((media->getType() == VLC_ML_MEDIA_TYPE_VIDEO)
                 && (status == VLC_ML_THUMBNAIL_STATUS_MISSING
                     || status == VLC_ML_THUMBNAIL_STATUS_FAILURE))
@@ -356,11 +356,11 @@ QVariant MLPlaylistModel::itemRoleData(MLItem *item, int role) const /* override
             return QVariant::fromValue(thumbnail);
         }
         case MEDIA_DURATION:
-            return QVariant::fromValue(media->getDuration());
+            return QVariant::fromValue(media->duration());
         case MEDIA_PROGRESS:
-            return QVariant::fromValue(media->getProgress());
+            return QVariant::fromValue(media->progress());
         case MEDIA_PLAYCOUNT:
-            return QVariant::fromValue(media->getPlayCount());
+            return QVariant::fromValue(media->playCount());
         case MEDIA_RESOLUTION:
             return QVariant::fromValue(media->getResolutionName());
         case MEDIA_CHANNEL:
@@ -374,7 +374,7 @@ QVariant MLPlaylistModel::itemRoleData(MLItem *item, int role) const /* override
         case MEDIA_AUDIO_TRACK:
             return QVariant::fromValue(media->getAudio());
         case MEDIA_TITLE_FIRST_SYMBOL:
-            return QVariant::fromValue(getFirstSymbol(media->getTitle()));
+            return QVariant::fromValue(getFirstSymbol(media->title()));
         default:
             return QVariant();
     }
@@ -453,7 +453,7 @@ void MLPlaylistModel::onVlcMlEvent(const MLEvent & event) /* override */
 void MLPlaylistModel::thumbnailUpdated(const QModelIndex& idx, MLItem* mlitem, const QString& mrl, vlc_ml_thumbnail_status_t status) /* override */
 {
     auto playlistItem = static_cast<MLPlaylistMedia*>(mlitem);
-    playlistItem->setThumbnail(mrl, status);
+    playlistItem->setSmallCover(mrl, status);
     emit dataChanged(idx, idx, { MEDIA_THUMBNAIL });
 }
 


=====================================
modules/gui/qt/medialibrary/mlvideo.cpp
=====================================
@@ -75,13 +75,7 @@ unsigned int AudioDescription::getSampleRate() const
 }
 
 MLVideo::MLVideo(const vlc_ml_media_t* data)
-    : MLItem( MLItemId( 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_duration( data->i_duration )
-    , m_progress( data->f_progress )
-    , m_playCount( data->i_playcount )
-    , m_thumbnailStatus( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].i_status )
+    : MLMedia ( data )
 {
     assert( data->i_type == VLC_ML_MEDIA_TYPE_VIDEO || data->i_type == VLC_ML_MEDIA_TYPE_UNKNOWN );
 
@@ -166,32 +160,9 @@ void MLVideo::setIsFavorite(bool isFavorite)
     m_isFavorite = isFavorite;
 }
 
-QString MLVideo::getFileName() const
+void MLVideo::setSmallCover(vlc_ml_thumbnail_status_t status, QString mrl)
 {
-    return m_fileName;
-}
-
-QString MLVideo::getTitle() const
-{
-    return m_title;
-}
-
-QString MLVideo::getThumbnail(vlc_ml_thumbnail_status_t* status)
-{
-    if (status)
-        *status = m_thumbnailStatus;
-    return m_thumbnail;
-}
-
-void MLVideo::setThumbnail(vlc_ml_thumbnail_status_t status, QString mrl)
-{
-    m_thumbnailStatus = status;
-    m_thumbnail = mrl;
-}
-
-VLCTick MLVideo::getDuration() const
-{
-    return VLCTick::fromMS(m_duration);
+    m_smallCover = {mrl, status};
 }
 
 QString MLVideo::getMRL() const
@@ -213,21 +184,6 @@ QString MLVideo::getChannel() const
     return m_channel;
 }
 
-float MLVideo::getProgress() const
-{
-    return m_progress;
-}
-
-unsigned int MLVideo::getPlayCount() const
-{
-    return m_playCount;
-}
-
-VLCTick MLVideo::getProgressTime() const
-{
-    return VLCTick::fromMS(m_duration * m_progress);
-}
-
 QList<VideoDescription> MLVideo::getVideoDesc() const
 {
     return m_videoDesc;


=====================================
modules/gui/qt/medialibrary/mlvideo.hpp
=====================================
@@ -29,6 +29,7 @@
 
 #include <vlc_media_library.h>
 #include "mlqmltypes.hpp"
+#include "mlmedia.hpp"
 
 #include <functional>
 
@@ -109,7 +110,7 @@ private:
     QString m_encoding;
 };
 
-class MLVideo : public MLItem
+class MLVideo : public MLMedia
 {
 public:
     MLVideo(const vlc_ml_media_t *data);
@@ -118,18 +119,11 @@ public:
     void setIsNew(bool isNew);
     bool isFavorite() const;
     void setIsFavorite(bool isFavorite);
-    QString getFileName() const;
-    QString getTitle() const;
-    QString getThumbnail(vlc_ml_thumbnail_status_t* status);
-    void setThumbnail(vlc_ml_thumbnail_status_t status, QString mrl);
-    VLCTick getDuration() const;
+    void setSmallCover(vlc_ml_thumbnail_status_t status, QString mrl);
     QString getResolutionName() const;
     QString getChannel() const;
     QString getMRL() const;
     QString getDisplayMRL() const;
-    float getProgress() const;
-    unsigned int getPlayCount() const;
-    VLCTick getProgressTime() const;
     QList<AudioDescription> getAudioDesc() const;
     QList<VideoDescription> getVideoDesc() const;
     QList<SubtitleDescription> getSubtitleDesc() const;
@@ -137,17 +131,9 @@ public:
 private:
     bool m_isNew;
     bool m_isFavorite;
-    QString m_fileName;
-    QString m_title;
-    QString m_thumbnail;
-    int64_t m_duration;
     QUrl m_mrl;
     QString m_resolution;
     QString m_channel;
-    float m_progress;
-    QString m_progressTime;
-    unsigned int m_playCount;
-    vlc_ml_thumbnail_status_t m_thumbnailStatus;
     QList<AudioDescription> m_audioDesc;
     QList<VideoDescription> m_videoDesc;
     QList<SubtitleDescription> m_subtitleDesc;


=====================================
modules/gui/qt/medialibrary/mlvideogroupsmodel.cpp
=====================================
@@ -126,11 +126,11 @@ QVariant MLVideoGroupsModel::itemRoleData(MLItem * item, const int role) const /
         switch (role)
         {
             case Qt::DisplayRole:
-                return QVariant::fromValue(video->getTitle());
+                return QVariant::fromValue(video->title());
             case GROUP_TITLE_FIRST_SYMBOL:
                 // videos and groups are shown mixed, force this item into a group
                 // for grouping the data must be sorted by title
-                return QVariant::fromValue( getFirstSymbol(video->getTitle() ));
+                return QVariant::fromValue( getFirstSymbol(video->title() ));
             case GROUP_IS_VIDEO:
                 return true;
             case GROUP_DATE:


=====================================
modules/gui/qt/medialibrary/mlvideomodel.cpp
=====================================
@@ -107,13 +107,13 @@ QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
         case VIDEO_IS_FAVORITE:
             return QVariant::fromValue( video->isFavorite() );
         case VIDEO_FILENAME:
-            return QVariant::fromValue( video->getFileName() );
+            return QVariant::fromValue( video->fileName() );
         case VIDEO_TITLE:
-            return QVariant::fromValue( video->getTitle() );
+            return QVariant::fromValue( video->title() );
         case VIDEO_THUMBNAIL:
         {
             vlc_ml_thumbnail_status_t status;
-            const QString thumbnail = video->getThumbnail(&status);
+            const QString thumbnail = video->smallCover(&status);
             if (status == VLC_ML_THUMBNAIL_STATUS_MISSING || status == VLC_ML_THUMBNAIL_STATUS_FAILURE)
             {
                 generateThumbnail(item->getId().id);
@@ -126,11 +126,11 @@ QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
             return QVariant::fromValue( videoUrl.isLocalFile() );
         }
         case VIDEO_DURATION:
-            return QVariant::fromValue( video->getDuration() );
+            return QVariant::fromValue( video->duration() );
         case VIDEO_PROGRESS:
-            return QVariant::fromValue( video->getProgress() );
+            return QVariant::fromValue( video->progress() );
         case VIDEO_PLAYCOUNT:
-            return QVariant::fromValue( video->getPlayCount() );
+            return QVariant::fromValue( video->playCount() );
         case VIDEO_RESOLUTION:
             return QVariant::fromValue( video->getResolutionName() );
         case VIDEO_CHANNEL:
@@ -146,7 +146,7 @@ QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
         case VIDEO_SUBTITLE_TRACK:
             return getVariantList( video->getSubtitleDesc() );
         case VIDEO_TITLE_FIRST_SYMBOL:
-            return QVariant::fromValue( getFirstSymbol( video->getTitle() ) );
+            return QVariant::fromValue( getFirstSymbol( video->title() ) );
 
         default:
             return {};
@@ -243,7 +243,7 @@ void MLVideoModel::onVlcMlEvent(const MLEvent &event)
 void MLVideoModel::thumbnailUpdated(const QModelIndex& idx, MLItem* mlitem, const QString& mrl, vlc_ml_thumbnail_status_t status)
 {
     auto videoItem = static_cast<MLVideo*>(mlitem);
-    videoItem->setThumbnail(status, mrl);
+    videoItem->setSmallCover(status, mrl);
     emit dataChanged(idx, idx, {VIDEO_THUMBNAIL});
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/45c071e76e8a7bf0e2e4503d1a5140f4b777ff4a...b975e608aabb288bd79ead5a30efe47d48114264

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/45c071e76e8a7bf0e2e4503d1a5140f4b777ff4a...b975e608aabb288bd79ead5a30efe47d48114264
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list