aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppOutOfBandUrl.cpp
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2022-09-28 13:38:25 +0200
committerLinus Jahn <lnj@kaidan.im>2022-09-28 15:56:05 +0200
commit1916eca1a982b22c10c1c737fcbcb86bee0ec5cc (patch)
tree7ebda6bc36a8e0df2b0130cb844902f840d37a47 /src/base/QXmppOutOfBandUrl.cpp
parent61564526f1cfd53c31353aeb6df26ba0f5da9834 (diff)
downloadqxmpp-1916eca1a982b22c10c1c737fcbcb86bee0ec5cc.tar.gz
Allow adding multiple oob urls and a description
Diffstat (limited to 'src/base/QXmppOutOfBandUrl.cpp')
-rw-r--r--src/base/QXmppOutOfBandUrl.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/base/QXmppOutOfBandUrl.cpp b/src/base/QXmppOutOfBandUrl.cpp
new file mode 100644
index 00000000..d986ae11
--- /dev/null
+++ b/src/base/QXmppOutOfBandUrl.cpp
@@ -0,0 +1,88 @@
+// SPDX-FileCopyrightText: 2022 Jonah BrĂ¼chert <jbb@kaidan.im>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#include "QXmppOutOfBandUrl.h"
+
+#include "QXmppConstants_p.h"
+
+#include <QDomElement>
+#include <QXmlStreamWriter>
+
+class QXmppOutOfBandUrlPrivate : public QSharedData
+{
+public:
+ QString url;
+ std::optional<QString> description;
+};
+
+///
+/// \class QXmppOutOfBandUrl
+///
+/// A URL and a description of its contents, from \xep{0066}: Out of Band Data
+///
+/// \since QXmpp 1.5
+///
+
+QXmppOutOfBandUrl::QXmppOutOfBandUrl()
+ : d(new QXmppOutOfBandUrlPrivate())
+{
+}
+
+QXMPP_PRIVATE_DEFINE_RULE_OF_SIX(QXmppOutOfBandUrl);
+
+///
+/// Returns the attached URL
+///
+const QString &QXmppOutOfBandUrl::url() const
+{
+ return d->url;
+}
+
+///
+/// Sets the attached URL
+///
+void QXmppOutOfBandUrl::setUrl(const QString &url)
+{
+ d->url = url;
+}
+
+///
+/// Returns the description of the URL
+///
+const std::optional<QString> &QXmppOutOfBandUrl::description() const
+{
+ return d->description;
+}
+
+///
+/// Set the description of the URL
+///
+void QXmppOutOfBandUrl::setDescription(const std::optional<QString> &description)
+{
+ d->description = description;
+}
+
+/// \cond
+bool QXmppOutOfBandUrl::parse(const QDomElement &el)
+{
+ d->url = el.firstChildElement(QStringLiteral("url")).text();
+ auto childEl = el.firstChildElement(QStringLiteral("desc"));
+ if (!childEl.isNull()) {
+ d->description = childEl.text();
+ }
+
+ return true;
+}
+
+void QXmppOutOfBandUrl::toXml(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement(QStringLiteral("x"));
+ writer->writeDefaultNamespace(ns_oob);
+ writer->writeTextElement(QStringLiteral("url"), d->url);
+ if (d->description) {
+ writer->writeTextElement(QStringLiteral("desc"), *d->description);
+ }
+ writer->writeEndElement();
+}
+/// \endcond