From de4fe392c0a40aba6f640bd10f3d2d047e4849d6 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Tue, 4 Aug 2015 15:11:55 +0200 Subject: [PATCH] Moved formatDuration to DataUtils --- src/datautils.cpp | 13 +++++++++++++ src/datautils.h | 1 + src/video.cpp | 12 ++---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/datautils.cpp b/src/datautils.cpp index dbaf3af..59e2376 100644 --- a/src/datautils.cpp +++ b/src/datautils.cpp @@ -101,3 +101,16 @@ QString DataUtils::formatDateTime(const QDateTime &dt) { } return s; } + +QString DataUtils::formatDuration(uint secs) { + uint d = secs; + QString res; + uint seconds = d % 60; + d /= 60; + uint minutes = d % 60; + d /= 60; + uint hours = d % 24; + if (hours == 0) + return res.sprintf("%d:%02d", minutes, seconds); + return res.sprintf("%d:%02d:%02d", hours, minutes, seconds); +} diff --git a/src/datautils.h b/src/datautils.h index bce1ca8..ad6d203 100644 --- a/src/datautils.h +++ b/src/datautils.h @@ -11,6 +11,7 @@ public: static QString systemRegioneCode(); static uint parseIsoPeriod(const QString &isoPeriod); static QString formatDateTime(const QDateTime &dt); + static QString formatDuration(uint secs); private: DataUtils() { } diff --git a/src/video.cpp b/src/video.cpp index 9d3c3d7..03edbda 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -25,6 +25,7 @@ $END_LICENSE */ #include "jsfunctions.h" #include "temporary.h" #include "compatibility/qurlqueryhelper.h" +#include "datautils.h" namespace The { NetworkAccess* http(); @@ -473,16 +474,7 @@ QString Video::decryptSignature(const QString &s) { } QString Video::formattedDuration() const { - int duration = m_duration; - QString res; - int seconds = duration % 60; - duration /= 60; - int minutes = duration % 60; - duration /= 60; - int hours = duration % 24; - if (hours == 0) - return res.sprintf("%d:%02d", minutes, seconds); - return res.sprintf("%d:%02d:%02d", hours, minutes, seconds); + return DataUtils::formatDuration(m_duration); } void Video::saveDefinitionForUrl(const QString& url, const VideoDefinition& definition) { -- 2.39.5