From 83cf37a7dc4d1d97dd20d7c02003b978af5e0834 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 9 Mar 2022 12:05:23 +0100 Subject: Refactor QXmppTuneItem --- src/base/QXmppTuneItem.h | 54 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'src/base/QXmppTuneItem.h') diff --git a/src/base/QXmppTuneItem.h b/src/base/QXmppTuneItem.h index 363a1c00..1819775a 100644 --- a/src/base/QXmppTuneItem.h +++ b/src/base/QXmppTuneItem.h @@ -7,7 +7,11 @@ #include "QXmppPubSubItem.h" +#include +#include + #include +#include class QXmppTuneItemPrivate; class QUrl; @@ -22,25 +26,53 @@ public: QXmppTuneItem &operator=(const QXmppTuneItem &other); QString artist() const; - void setArtist(const QString &artist); - - quint16 length() const; - void setLength(quint16 length); - - quint8 rating() const; - void setRating(quint8 rating); + void setArtist(QString artist); + + std::optional length() const; + void setLength(std::optional length); + inline QTime lengthAsTime() const + { + if (auto len = length()) { + return QTime::fromMSecsSinceStartOfDay(len.value() * 1000); + } + return {}; + } + inline void setLength(const QTime &time) + { + if (time.isValid()) { + setLength(time.msecsSinceStartOfDay() / 1000); + } + setLength(std::optional()); + } + inline std::optional lengthAsDuration() const + { + if (auto len = length()) { + return std::chrono::seconds(*len); + } + return {}; + } + inline void setLength(std::optional time) + { + if (time) { + setLength(quint16(time->count())); + } + setLength(std::optional()); + } + + std::optional rating() const; + void setRating(std::optional rating); QString source() const; - void setSource(const QString &source); + void setSource(QString source); QString title() const; - void setTitle(const QString &title); + void setTitle(QString title); QString track() const; - void setTrack(const QString &track); + void setTrack(QString track); QUrl uri() const; - void setUri(const QUrl &uri); + void setUri(QUrl uri); static bool isItem(const QDomElement &itemElement); -- cgit v1.2.3