From f2aadfefa283aafc88131c643b97acd28989ac20 Mon Sep 17 00:00:00 2001 From: Cochise César Date: Mon, 10 Jan 2022 01:27:06 -0300 Subject: Implement XEP-0080: User Location --- src/client/QXmppUserLocationManager.cpp | 96 +++++++++++++++++++++++++++++++++ src/client/QXmppUserLocationManager.h | 39 ++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 src/client/QXmppUserLocationManager.cpp create mode 100644 src/client/QXmppUserLocationManager.h (limited to 'src/client') diff --git a/src/client/QXmppUserLocationManager.cpp b/src/client/QXmppUserLocationManager.cpp new file mode 100644 index 00000000..d85a47d5 --- /dev/null +++ b/src/client/QXmppUserLocationManager.cpp @@ -0,0 +1,96 @@ +// SPDX-FileCopyrightText: 2022 Cochise César +// SPDX-FileCopyrightText: 2022 Linus Jahn +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppUserLocationManager.h" + +#include "QXmppConstants_p.h" +#include "QXmppGeolocItem.h" +#include "QXmppPep_p.h" + +using namespace QXmpp::Private; + +/// +/// \class QXmppUserLocationManager +/// +/// The QXmppUserLocationManager implements \xep{0080, User Location}. You'll receive +/// location updates from all presence subscriptions. You can publish location +/// information on the user's account (publish()) and request location information +/// from specific accounts (request()). +/// +/// The manager needs to be added to the client first and also requires the +/// QXmppPubSubManager. +/// \code +/// QXmppClient client; +/// auto *pubSubManager = client.addNewExtension(); +/// auto *locationManager = client.addNewExtension(); +/// \endcode +/// +/// \since QXmpp 1.5 +/// +/// \ingroup Managers +/// + +/// +/// \typedef QXmppUserLocationManager::Item +/// +/// Used pubsub item type. +/// + +/// +/// \typedef QXmppUserLocationManager::GetResult +/// +/// Contains the User Location information or an error. +/// + +/// +/// \typedef QXmppUserLocationManager::PublishResult +/// +/// Contains the ID of the published item on success or a stanza error. +/// + +/// +/// \fn QXmppUserLocationManager::itemReceived() +/// +/// Emitted whenever a \xep{0080, User Location} items event arrives. +/// + +QXmppUserLocationManager::QXmppUserLocationManager() = default; + +QStringList QXmppUserLocationManager::discoveryFeatures() const +{ + return { + ns_geoloc, + ns_geoloc_notify, + }; +} + +/// +/// Request User Location information from an account. +/// +/// \param jid The account JID to request. +/// +auto QXmppUserLocationManager::request(const QString &jid) + -> QFuture +{ + return Pep::request(pubSub(), jid, ns_geoloc, this); +} + +/// +/// Publishes User Location information on the user's account. +/// +/// \param item The User Location item to be published. +/// +auto QXmppUserLocationManager::publish(const QXmppGeolocItem &item) + -> QFuture +{ + return pubSub()->publishPepItem(ns_geoloc, item); +} + +/// \cond +bool QXmppUserLocationManager::handlePubSubEvent(const QDomElement &element, const QString &pubSubService, const QString &nodeName) +{ + return Pep::handlePubSubEvent(element, pubSubService, nodeName, ns_geoloc, this, &QXmppUserLocationManager::itemReceived); +} +/// \endcond diff --git a/src/client/QXmppUserLocationManager.h b/src/client/QXmppUserLocationManager.h new file mode 100644 index 00000000..9033d512 --- /dev/null +++ b/src/client/QXmppUserLocationManager.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2022 Linus Jahn +// SPDX-FileCopyrightText: 2022 Cochise César +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPUSERLOCATIONMANAGER_H +#define QXMPPUSERLOCATIONMANAGER_H + +#include "QXmppPubSubEventManager.h" + +#include + +class QXmppGeolocItem; + +class QXMPP_EXPORT QXmppUserLocationManager : public QXmppPubSubEventManager +{ + Q_OBJECT + +public: + using Item = QXmppGeolocItem; + using GetResult = std::variant; + using PublishResult = std::variant; + + QXmppUserLocationManager(); + + QStringList discoveryFeatures() const override; + + QFuture request(const QString &jid); + QFuture publish(const Item &); + + Q_SIGNAL void itemReceived(const QString &jid, const QXmppGeolocItem &); + +protected: + /// \cond + bool handlePubSubEvent(const QDomElement &element, const QString &pubSubService, const QString &nodeName) override; + /// \endcond +}; + +#endif // QXMPPUSERLOCATIONMANAGER_H -- cgit v1.2.3