[vlc-devel] [PATCH 25/26] qt: make ml video meta classes base on Q_GADGET

Prince Gupta guptaprince8832 at gmail.com
Thu Dec 17 17:26:23 UTC 2020


---
 modules/gui/qt/medialibrary/mlvideo.cpp | 24 +++++++++-----------
 modules/gui/qt/medialibrary/mlvideo.hpp | 29 +++++++++++++++----------
 2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index cefb9504d6..97cce0c28a 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -22,9 +22,8 @@
 
 #include <vlc_thumbnailer.h>
 
-VideoDescription::VideoDescription(const QString &codec, const QString &language, const unsigned int fps, QObject *parent)
-    : QObject(parent)
-    , m_codec(codec)
+VideoDescription::VideoDescription(const QString &codec, const QString &language, const unsigned int fps)
+    : m_codec(codec)
     , m_language(language)
     , m_fps(fps)
 {
@@ -45,9 +44,8 @@ unsigned int VideoDescription::getFps() const
     return m_fps;
 }
 
-AudioDescription::AudioDescription(const QString &codec, const QString &language, const unsigned int nbChannels, const unsigned int sampleRate, QObject *parent)
-    : QObject(parent)
-    , m_codec(codec)
+AudioDescription::AudioDescription(const QString &codec, const QString &language, const unsigned int nbChannels, const unsigned int sampleRate)
+    : m_codec(codec)
     , m_language(language)
     , m_nbchannels(nbChannels)
     , m_sampleRate(sampleRate)
@@ -105,21 +103,19 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
         if ( track.i_type == VLC_ML_TRACK_TYPE_AUDIO ) {
             numChannel = std::max( numChannel , track.a.i_nbChannels );
 
-            m_audioDesc.push_back( new AudioDescription ( QString::fromUtf8( track.psz_codec ) ,
+            m_audioDesc.push_back( QVariant::fromValue(AudioDescription ( QString::fromUtf8( track.psz_codec ) ,
                                                          QString::fromUtf8( track.psz_language  ) ,
                                                          track.a.i_nbChannels ,
-                                                         track.a.i_sampleRate ,
-                                                         this )
+                                                         track.a.i_sampleRate))
                                    );
         }
         else if ( track.i_type == VLC_ML_TRACK_TYPE_VIDEO ){
             maxWidth = std::max( maxWidth, track.v.i_width );
             maxHeight = std::max( maxHeight, track.v.i_height );
 
-            m_videoDesc.push_back(  new VideoDescription( QString::fromUtf8( track.psz_codec ) ,
+            m_videoDesc.push_back(  QVariant::fromValue(VideoDescription( QString::fromUtf8( track.psz_codec ) ,
                                                         QString::fromUtf8( track.psz_language ) ,
-                                                        track.v.i_fpsNum,
-                                                        this )
+                                                        track.v.i_fpsNum))
                                   );
         }
     }
@@ -242,12 +238,12 @@ QString MLVideo::getProgressTime() const
     return MsToString(m_duration * m_progress);
 }
 
-QObjectList MLVideo::getVideoDesc() const
+QVariantList MLVideo::getVideoDesc() const
 {
     return m_videoDesc;
 }
 
-QObjectList MLVideo::getAudioDesc() const
+QVariantList MLVideo::getAudioDesc() const
 {
     return m_audioDesc;
 }
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index 8041881280..2d4968b34f 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -26,22 +26,24 @@
 #include "qt.hpp"
 
 #include <QObject>
+#include <QVariant>
 #include <vlc_media_library.h>
 #include "mlhelper.hpp"
 #include "mlqmltypes.hpp"
 
 #include <functional>
 
-class VideoDescription : public QObject
+class VideoDescription
 {
-    Q_OBJECT
+    Q_GADGET
 
     Q_PROPERTY(QString codec READ getCodec CONSTANT)
     Q_PROPERTY(QString language READ getLanguage CONSTANT)
     Q_PROPERTY(unsigned int fps READ getFps CONSTANT)
 
 public:
-    VideoDescription(const QString& codec, const QString& language, unsigned int fps, QObject *parent = nullptr);
+    VideoDescription() = default;
+    VideoDescription(const QString& codec, const QString& language, unsigned int fps);
 
     QString getCodec() const;
     QString getLanguage() const;
@@ -53,10 +55,11 @@ private:
     QString m_language;
     unsigned int m_fps;
 };
+Q_DECLARE_METATYPE(VideoDescription)
 
-class AudioDescription : public QObject
+class AudioDescription
 {
-    Q_OBJECT
+    Q_GADGET
 
     Q_PROPERTY(QString codec READ getCodec CONSTANT)
     Q_PROPERTY(QString language READ getLanguage CONSTANT)
@@ -64,7 +67,8 @@ class AudioDescription : public QObject
     Q_PROPERTY(unsigned int sampleRate READ getSampleRate CONSTANT)
 
 public:
-    AudioDescription(const QString& codec, const QString& language, unsigned int nbChannels, unsigned int sampleRate, QObject *parent = nullptr);
+    AudioDescription() = default;
+    AudioDescription(const QString& codec, const QString& language, unsigned int nbChannels, unsigned int sampleRate);
 
     QString getCodec() const;
     QString getLanguage() const;
@@ -78,6 +82,7 @@ private:
     unsigned int m_nbchannels;
     unsigned int m_sampleRate;
 };
+Q_DECLARE_METATYPE(AudioDescription)
 
 class MLVideo : public QObject, public MLItem
 {
@@ -95,8 +100,8 @@ class MLVideo : public QObject, public MLItem
     Q_PROPERTY(QString resolution_name READ getResolutionName CONSTANT);
     Q_PROPERTY(QString channel READ getChannel CONSTANT);
     Q_PROPERTY(QString progressTime READ getProgressTime CONSTANT);
-    Q_PROPERTY(QObjectList audioDesc READ getAudioDesc CONSTANT);
-    Q_PROPERTY(QObjectList videoDesc READ getVideoDesc CONSTANT);
+    Q_PROPERTY(QVariantList audioDesc READ getAudioDesc CONSTANT);
+    Q_PROPERTY(QVariantList videoDesc READ getVideoDesc CONSTANT);
 
 public:
     MLVideo(vlc_medialibrary_t *ml, const vlc_ml_media_t *data, QObject *parent = nullptr);
@@ -112,8 +117,8 @@ public:
     float getProgress() const;
     unsigned int getPlayCount() const;
     QString getProgressTime() const;
-    QObjectList getAudioDesc() const;
-    QObjectList getVideoDesc() const;
+    QVariantList getAudioDesc() const;
+    QVariantList getVideoDesc() const;
 
     MLVideo* clone(QObject* parent = nullptr) const;
 
@@ -137,8 +142,8 @@ private:
     QString m_progressTime;
     unsigned int m_playCount;
     vlc_ml_thumbnail_status_t m_thumbnailStatus;
-    QObjectList m_audioDesc;
-    QObjectList m_videoDesc;
+    QVariantList m_audioDesc;
+    QVariantList m_videoDesc;
 
     std::unique_ptr<vlc_ml_event_callback_t,
                     std::function<void(vlc_ml_event_callback_t*)>> m_ml_event_handle;
-- 
2.25.1



More information about the vlc-devel mailing list