QXmpp Version: 1.5.6
Loading...
Searching...
No Matches
QXmppUserTuneItem.h
1// SPDX-FileCopyrightText: 2020 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPUSERTUNEITEM_H
6#define QXMPPUSERTUNEITEM_H
7
8#include "QXmppPubSubBaseItem.h"
9
10#include <chrono>
11#include <optional>
12
13#include <QSharedDataPointer>
14#include <QTime>
15
16class QXmppTuneItemPrivate;
17class QUrl;
18
19class QXMPP_EXPORT QXmppTuneItem : public QXmppPubSubBaseItem
20{
21public:
26
29
30 QString artist() const;
31 void setArtist(QString artist);
32
33 std::optional<quint16> length() const;
34 void setLength(std::optional<quint16> length);
35 inline QTime lengthAsTime() const
36 {
37 if (auto len = length()) {
38 return QTime::fromMSecsSinceStartOfDay(len.value() * 1000);
39 }
40 return {};
41 }
42 inline void setLength(const QTime &time)
43 {
44 if (time.isValid()) {
45 setLength(time.msecsSinceStartOfDay() / 1000);
46 }
47 setLength(std::optional<quint16>());
48 }
49 inline std::optional<std::chrono::seconds> lengthAsDuration() const
50 {
51 if (auto len = length()) {
52 return std::chrono::seconds(*len);
53 }
54 return {};
55 }
56 inline void setLength(std::optional<std::chrono::seconds> time)
57 {
58 if (time) {
59 setLength(quint16(time->count()));
60 }
61 setLength(std::optional<quint16>());
62 }
63
64 std::optional<quint8> rating() const;
65 void setRating(std::optional<quint8> rating);
66
67 QString source() const;
68 void setSource(QString source);
69
70 QString title() const;
71 void setTitle(QString title);
72
73 QString track() const;
74 void setTrack(QString track);
75
76 QUrl uri() const;
77 void setUri(QUrl uri);
78
79 static bool isItem(const QDomElement &itemElement);
80
81protected:
83 void parsePayload(const QDomElement &payloadElement) override;
84 void serializePayload(QXmlStreamWriter *writer) const override;
86
87private:
88 QSharedDataPointer<QXmppTuneItemPrivate> d;
89};
90
91Q_DECLARE_METATYPE(QXmppTuneItem)
92
93#endif // QXMPPUSERTUNEITEM_H
Definition QXmppPubSubBaseItem.h:19
virtual void serializePayload(QXmlStreamWriter *writer) const
Definition QXmppPubSubBaseItem.cpp:150
virtual void parsePayload(const QDomElement &payloadElement)
Definition QXmppPubSubBaseItem.cpp:140
static bool isItem(const QDomElement &element)
Definition QXmppPubSubBaseItem.cpp:130
Definition QXmppUserTuneItem.h:20
QXmppTuneItem(QXmppTuneItem &&)
Move-constructor.
void setLength(const QTime &time)
Definition QXmppUserTuneItem.h:42
QXmppTuneItem & operator=(QXmppTuneItem &&)
Move-assignment operator.
QXmppTuneItem & operator=(const QXmppTuneItem &other)
Assignment operator.
std::optional< std::chrono::seconds > lengthAsDuration() const
Definition QXmppUserTuneItem.h:49
QTime lengthAsTime() const
Definition QXmppUserTuneItem.h:35
void setLength(std::optional< std::chrono::seconds > time)
Definition QXmppUserTuneItem.h:56
QXmppTuneItem(const QXmppTuneItem &other)
Copy-constructor.