QXmpp: QXmppRosterManager.h Source File

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
QXmppRosterManager.h
1// SPDX-FileCopyrightText: 2010 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
3// SPDX-FileCopyrightText: 2021 Melvin Keskin <melvo@olomono.de>
4// SPDX-FileCopyrightText: 2024 Filipe Azevedo <pasnox@gmail.com>
5//
6// SPDX-License-Identifier: LGPL-2.1-or-later
7
8#ifndef QXMPPROSTERMANAGER_H
9#define QXMPPROSTERMANAGER_H
10
11#include "QXmppClientExtension.h"
12#include "QXmppPresence.h"
13#include "QXmppRosterIq.h"
14#include "QXmppSendResult.h"
15
16#include <variant>
17
18#include <QMap>
19#include <QObject>
20#include <QStringList>
21
22template<typename T>
23class QXmppTask;
24class QXmppRosterManagerPrivate;
25
83 class QXMPP_EXPORT QXmppRosterManager : public QXmppClientExtension
84{
85 Q_OBJECT
86
87public:
89 using Result = std::variant<QXmpp::Success, QXmppError>;
90
91 explicit QXmppRosterManager(QXmppClient *stream);
92 ~QXmppRosterManager() override;
93
94 bool isRosterReceived() const;
95 QStringList getRosterBareJids() const;
96 QXmppRosterIq::Item getRosterEntry(const QString &bareJid) const;
97
98 QStringList getResources(const QString &bareJid) const;
99 QMap<QString, QXmppPresence> getAllPresencesForBareJid(
100 const QString &bareJid) const;
101 QXmppPresence getPresence(const QString &bareJid,
102 const QString &resource) const;
103
104 QXmppTask<Result> addRosterItem(const QString &bareJid, const QString &name = {}, const QSet<QString> &groups = {});
105 QXmppTask<Result> removeRosterItem(const QString &bareJid);
106 QXmppTask<Result> renameRosterItem(const QString &bareJid, const QString &name);
107 QXmppTask<QXmpp::SendResult> subscribeTo(const QString &bareJid, const QString &reason = {});
108 QXmppTask<QXmpp::SendResult> unsubscribeFrom(const QString &bareJid, const QString &reason = {});
109
111 bool handleStanza(const QDomElement &element) override;
113
114 Q_SLOT bool acceptSubscription(const QString &bareJid, const QString &reason = {});
115 Q_SLOT bool refuseSubscription(const QString &bareJid, const QString &reason = {});
116 Q_SLOT bool addItem(const QString &bareJid, const QString &name = {}, const QSet<QString> &groups = {});
117 Q_SLOT bool removeItem(const QString &bareJid);
118 Q_SLOT bool renameItem(const QString &bareJid, const QString &name);
119 Q_SLOT bool subscribe(const QString &bareJid, const QString &reason = {});
120 Q_SLOT bool unsubscribe(const QString &bareJid, const QString &reason = {});
121
130 Q_SIGNAL void rosterReceived();
131
133 Q_SIGNAL void presenceChanged(const QString &bareJid, const QString &resource);
134
144 Q_SIGNAL void subscriptionReceived(const QString &bareJid);
145
146 Q_SIGNAL void subscriptionRequestReceived(const QString &subscriberBareJid, const QXmppPresence &presence);
147
150 Q_SIGNAL void itemAdded(const QString &bareJid);
151
154 Q_SIGNAL void itemChanged(const QString &bareJid);
155
158 Q_SIGNAL void itemRemoved(const QString &bareJid);
159
160protected:
161 void onRegistered(QXmppClient *client) override;
162 void onUnregistered(QXmppClient *client) override;
163
164private:
165 using RosterResult = std::variant<QXmppRosterIq, QXmppError>;
166
167 Q_SLOT void _q_connected();
168 Q_SLOT void _q_disconnected();
169 Q_SLOT void _q_presenceReceived(const QXmppPresence &);
170
171 void handleSubscriptionRequest(const QString &bareJid, const QXmppPresence &presence);
172 QXmppTask<RosterResult> requestRoster();
173
174 const std::unique_ptr<QXmppRosterManagerPrivate> d;
175
176 friend class QXmppMixManager;
177};
178
179#endif // QXMPPROSTER_H
QXmppClientExtension::onUnregistered
virtual void onUnregistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:95
QXmppClientExtension::onRegistered
virtual void onRegistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:85
QXmppClientExtension::client
QXmppClient * client() const
Definition QXmppClientExtension.cpp:57
QXmppClientExtension::QXmppClientExtension
QXmppClientExtension()
Definition QXmppClientExtension.cpp:12
QXmppClientExtension::handleStanza
virtual bool handleStanza(const QDomElement &stanza)
You need to implement this method to process incoming XMPP stanzas.
Definition client/compat/removed_api.cpp:44
QXmppPresence
The QXmppPresence class represents an XMPP presence stanza.
Definition QXmppPresence.h:22
QXmppRosterIq::Item
The QXmppRosterIq::Item class represents a roster entry.
Definition QXmppRosterIq.h:34
QXmppRosterManager::addRosterItem
QXmppTask< Result > addRosterItem(const QString &bareJid, const QString &name={}, const QSet< QString > &groups={})
Definition QXmppRosterManager.cpp:330
QXmppRosterManager::isRosterReceived
bool isRosterReceived() const
Definition QXmppRosterManager.cpp:701
QXmppRosterManager::getAllPresencesForBareJid
QMap< QString, QXmppPresence > getAllPresencesForBareJid(const QString &bareJid) const
Definition QXmppRosterManager.cpp:665
QXmppRosterManager::itemAdded
Q_SIGNAL void itemAdded(const QString &bareJid)
QXmppRosterManager::itemChanged
Q_SIGNAL void itemChanged(const QString &bareJid)
QXmppRosterManager::getRosterEntry
QXmppRosterIq::Item getRosterEntry(const QString &bareJid) const
Definition QXmppRosterManager.cpp:633
QXmppRosterManager::getPresence
QXmppPresence getPresence(const QString &bareJid, const QString &resource) const
Definition QXmppRosterManager.cpp:681
QXmppRosterManager::presenceChanged
Q_SIGNAL void presenceChanged(const QString &bareJid, const QString &resource)
This signal is emitted when the presence of a particular bareJid and resource changes.
QXmppRosterManager::subscriptionReceived
Q_SIGNAL void subscriptionReceived(const QString &bareJid)
QXmppRosterManager::getRosterBareJids
QStringList getRosterBareJids() const
Definition QXmppRosterManager.cpp:622
QXmppRosterManager::itemRemoved
Q_SIGNAL void itemRemoved(const QString &bareJid)
QXmppRosterManager::QXmppRosterManager
QXmppRosterManager(QXmppClient *stream)
Definition QXmppRosterManager.cpp:121
QXmppRosterManager::getResources
QStringList getResources(const QString &bareJid) const
Definition QXmppRosterManager.cpp:649
QXmppRosterManager::subscriptionRequestReceived
Q_SIGNAL void subscriptionRequestReceived(const QString &subscriberBareJid, const QXmppPresence &presence)
QXmppRosterManager::rosterReceived
Q_SIGNAL void rosterReceived()
QXmppRosterManager::Result
std::variant< QXmpp::Success, QXmppError > Result
Empty result containing QXmpp::Success or a QXmppError.
Definition QXmppRosterManager.h:89
QXmppTask
Definition QXmppTask.h:46