[vlc-devel] [PATCH 1/7] qt: provide durationShort in video and album tracks model
Prince Gupta
guptaprince8832 at gmail.com
Tue Jun 9 11:46:27 CEST 2020
---
modules/gui/qt/medialibrary/mlalbumtrack.cpp | 32 +++++++++++++------
modules/gui/qt/medialibrary/mlalbumtrack.hpp | 3 ++
.../gui/qt/medialibrary/mlalbumtrackmodel.cpp | 5 +++
modules/gui/qt/medialibrary/mlvideo.cpp | 11 ++++++-
modules/gui/qt/medialibrary/mlvideo.hpp | 2 ++
modules/gui/qt/medialibrary/mlvideomodel.cpp | 4 +++
6 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/modules/gui/qt/medialibrary/mlalbumtrack.cpp b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
index 56eff2a63a..764a72d708 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrack.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrack.cpp
@@ -35,14 +35,22 @@ MLAlbumTrack::MLAlbumTrack(vlc_medialibrary_t* _ml, const vlc_ml_media_t *_data,
int min = (t_sec / 60) % 60;
int hour = t_sec / 3600;
if (hour == 0)
+ {
m_duration = QString("%1:%2")
.arg(min, 2, 10, QChar('0'))
.arg(sec, 2, 10, QChar('0'));
+ m_durationShort = m_duration;
+ }
else
+ {
m_duration = QString("%1:%2:%3")
.arg(hour, 2, 10, QChar('0'))
.arg(min, 2, 10, QChar('0'))
.arg(sec, 2, 10, QChar('0'));
+ m_durationShort = QString("%1h%2")
+ .arg(hour)
+ .arg(min, 2, 10, QChar('0'));
+ }
for( const vlc_ml_file_t& file: ml_range_iterate<vlc_ml_file_t>( _data->p_files ) )
if( file.i_type == VLC_ML_FILE_TYPE_MAIN )
@@ -76,15 +84,16 @@ 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 )
- , m_title ( albumtrack.m_title )
- , m_albumTitle ( albumtrack.m_albumTitle )
- , m_artist ( albumtrack.m_artist )
- , m_cover ( albumtrack.m_cover )
- , m_trackNumber( albumtrack.m_trackNumber )
- , m_discNumber ( albumtrack.m_discNumber )
- , m_duration ( albumtrack.m_duration )
- , m_mrl ( albumtrack.m_mrl )
+ , m_id ( albumtrack.m_id )
+ , m_title ( albumtrack.m_title )
+ , m_albumTitle ( albumtrack.m_albumTitle )
+ , m_artist ( albumtrack.m_artist )
+ , m_cover ( albumtrack.m_cover )
+ , m_trackNumber ( albumtrack.m_trackNumber )
+ , m_discNumber ( albumtrack.m_discNumber )
+ , m_duration ( albumtrack.m_duration )
+ , m_durationShort( albumtrack.m_durationShort )
+ , m_mrl ( albumtrack.m_mrl )
{
}
@@ -128,6 +137,11 @@ QString MLAlbumTrack::getDuration() const
return m_duration;
}
+QString MLAlbumTrack::getDurationShort() const
+{
+ return m_durationShort;
+}
+
QString MLAlbumTrack::getMRL() const
{
return m_mrl;
diff --git a/modules/gui/qt/medialibrary/mlalbumtrack.hpp b/modules/gui/qt/medialibrary/mlalbumtrack.hpp
index 884419173f..c9abbed671 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrack.hpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrack.hpp
@@ -43,6 +43,7 @@ class MLAlbumTrack : public QObject
Q_PROPERTY(unsigned int track_number READ getTrackNumber CONSTANT)
Q_PROPERTY(unsigned int disc_number READ getDiscNumber CONSTANT)
Q_PROPERTY(QString duration READ getDuration CONSTANT)
+ Q_PROPERTY(QString durationShort READ getDurationShort CONSTANT)
Q_PROPERTY(QString mrl READ getMRL CONSTANT)
public:
@@ -56,6 +57,7 @@ public:
unsigned int getTrackNumber() const;
unsigned int getDiscNumber() const;
QString getDuration() const;
+ QString getDurationShort() const;
QString getMRL() const;
MLAlbumTrack* clone(QObject *parent = nullptr) const;
@@ -71,6 +73,7 @@ private:
unsigned int m_trackNumber;
unsigned int m_discNumber;
QString m_duration;
+ QString m_durationShort;
QString m_mrl;
ml_unique_ptr<vlc_ml_media_t> m_data;
diff --git a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
index 1107927a76..0d6819ea34 100644
--- a/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
@@ -27,6 +27,7 @@ enum Role {
TRACK_NUMBER,
TRACK_DISC_NUMBER,
TRACK_DURATION,
+ TRACK_DURATION_SHORT,
TRACK_ALBUM,
TRACK_ARTIST,
@@ -76,6 +77,8 @@ QVariant MLAlbumTrackModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue( ml_track->getDiscNumber() );
case TRACK_DURATION :
return QVariant::fromValue( ml_track->getDuration() );
+ case TRACK_DURATION_SHORT :
+ return QVariant::fromValue( ml_track->getDurationShort() );
case TRACK_ALBUM:
return QVariant::fromValue( ml_track->getAlbumTitle() );
case TRACK_ARTIST:
@@ -100,6 +103,7 @@ QHash<int, QByteArray> MLAlbumTrackModel::roleNames() const
{ TRACK_NUMBER, "track_number" },
{ TRACK_DISC_NUMBER, "disc_number" },
{ TRACK_DURATION, "duration" },
+ { TRACK_DURATION_SHORT, "durationShort" },
{ TRACK_ALBUM, "album_title"},
{ TRACK_ARTIST, "main_artist"},
{ TRACK_TITLE_FIRST_SYMBOL, "title_first_symbol"},
@@ -142,6 +146,7 @@ vlc_ml_sorting_criteria_t MLAlbumTrackModel::roleToCriteria(int role) const
case TRACK_NUMBER :
return VLC_ML_SORTING_TRACKNUMBER;
case TRACK_DURATION :
+ case TRACK_DURATION_SHORT :
return VLC_ML_SORTING_DURATION;
default:
return VLC_ML_SORTING_DEFAULT;
diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index a4452aac51..8dbe58bb74 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -24,7 +24,7 @@
namespace
{
-QString MsToString( int64_t time )
+QString MsToString( int64_t time , bool doShort = false )
{
if (time < 0)
return "--:--";
@@ -37,6 +37,10 @@ QString MsToString( int64_t time )
return QString("%1:%2")
.arg(min, 2, 10, QChar('0'))
.arg(sec, 2, 10, QChar('0'));
+ else if ( doShort )
+ return QString("%1h%2")
+ .arg(hour)
+ .arg(min, 2, 10, QChar('0'));
else
return QString("%1:%2:%3")
.arg(hour, 2, 10, QChar('0'))
@@ -181,6 +185,11 @@ QString MLVideo::getDuration() const
return MsToString( m_duration );
}
+QString MLVideo::getDurationShort() const
+{
+ return MsToString( m_duration, true );
+}
+
QString MLVideo::getMRL() const
{
return m_mrl.toEncoded();
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index 4644e3177a..c5f6bbb23b 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -40,6 +40,7 @@ class MLVideo : public QObject
Q_PROPERTY(QString title READ getTitle CONSTANT);
Q_PROPERTY(QString thumbnail READ getThumbnail NOTIFY onThumbnailChanged);
Q_PROPERTY(QString duration READ getDuration CONSTANT);
+ Q_PROPERTY(QString durationShort READ getDurationShort CONSTANT);
Q_PROPERTY(QString mrl READ getMRL CONSTANT);
Q_PROPERTY(QString displayMrl READ getDisplayMRL CONSTANT)
Q_PROPERTY(float progress READ getProgress CONSTANT);
@@ -57,6 +58,7 @@ public:
QString getTitle() const;
QString getThumbnail();
QString getDuration() const;
+ QString getDurationShort() const;
QString getResolutionName() const;
QString getChannel() const;
QString getMRL() const;
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.cpp b/modules/gui/qt/medialibrary/mlvideomodel.cpp
index 4f303c6487..a46444e340 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
@@ -25,6 +25,7 @@ enum Role {
VIDEO_TITLE,
VIDEO_THUMBNAIL,
VIDEO_DURATION,
+ VIDEO_DURATION_SHORT,
VIDEO_PROGRESS,
VIDEO_PLAYCOUNT,
VIDEO_RESOLUTION,
@@ -66,6 +67,8 @@ QVariant MLVideoModel::data(const QModelIndex& index, int role) const
return QVariant::fromValue( video->getThumbnail() );
case VIDEO_DURATION:
return QVariant::fromValue( video->getDuration() );
+ case VIDEO_DURATION_SHORT:
+ return QVariant::fromValue( video->getDurationShort() );
case VIDEO_PROGRESS:
return QVariant::fromValue( video->getProgress() );
case VIDEO_PLAYCOUNT:
@@ -97,6 +100,7 @@ QHash<int, QByteArray> MLVideoModel::roleNames() const
{ VIDEO_TITLE, "title" },
{ VIDEO_THUMBNAIL, "thumbnail" },
{ VIDEO_DURATION, "duration" },
+ { VIDEO_DURATION_SHORT, "durationShort" },
{ VIDEO_PROGRESS, "progress" },
{ VIDEO_PLAYCOUNT, "playcount" },
{ VIDEO_RESOLUTION, "resolution_name" },
--
2.25.1
More information about the vlc-devel
mailing list