QXmpp: QXmppUserTuneItem.h Source File

QXmpp Version: 1.14.4

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
19 class QXMPP_EXPORT QXmppTuneItem : public QXmppPubSubBaseItem
20{
21public:
22 QXmppTuneItem();
23 QXmppTuneItem(const QXmppTuneItem &other);
24 QXmppTuneItem(QXmppTuneItem &&);
25 ~QXmppTuneItem();
26
27 QXmppTuneItem &operator=(const QXmppTuneItem &other);
28 QXmppTuneItem &operator=(QXmppTuneItem &&);
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
QXmppPubSubBaseItem::serializePayload
virtual void serializePayload(QXmlStreamWriter *writer) const
Definition QXmppPubSubBaseItem.cpp:154
QXmppPubSubBaseItem::QXmppPubSubBaseItem
QXmppPubSubBaseItem(const QString &id={}, const QString &publisher={})
Definition QXmppPubSubBaseItem.cpp:62
QXmppPubSubBaseItem::parsePayload
virtual void parsePayload(const QDomElement &payloadElement)
Definition QXmppPubSubBaseItem.cpp:144
QXmppPubSubBaseItem::isItem
static bool isItem(const QDomElement &element)
Definition QXmppPubSubBaseItem.cpp:134
QXmppTuneItem
Definition QXmppUserTuneItem.h:20
QXmppTuneItem::QXmppTuneItem
QXmppTuneItem()
Definition QXmppUserTuneItem.cpp:52
QXmppTuneItem::QXmppTuneItem
QXmppTuneItem(QXmppTuneItem &&)
Move-constructor.
QXmppTuneItem::lengthAsTime
QTime lengthAsTime() const
Definition QXmppUserTuneItem.h:35
QXmppTuneItem::setLength
void setLength(std::optional< std::chrono::seconds > time)
Definition QXmppUserTuneItem.h:56
QXmppTuneItem::artist
QString artist() const
Definition QXmppUserTuneItem.cpp:70
QXmppTuneItem::operator=
QXmppTuneItem & operator=(QXmppTuneItem &&)
Move-assignment operator.
QXmppTuneItem::operator=
QXmppTuneItem & operator=(const QXmppTuneItem &other)
Assignment operator.
QXmppTuneItem::lengthAsDuration
std::optional< std::chrono::seconds > lengthAsDuration() const
Definition QXmppUserTuneItem.h:49
QXmppTuneItem::setLength
void setLength(std::optional< quint16 > length)
Definition QXmppUserTuneItem.cpp:94
QXmppTuneItem::setLength
void setLength(const QTime &time)
Definition QXmppUserTuneItem.h:42
QXmppTuneItem::length
std::optional< quint16 > length() const
Definition QXmppUserTuneItem.cpp:86
QXmppTuneItem::setArtist
void setArtist(QString artist)
Definition QXmppUserTuneItem.cpp:78
QXmppTuneItem::QXmppTuneItem
QXmppTuneItem(const QXmppTuneItem &other)
Copy-constructor.