QXmpp Version: 1.10.0
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
56class QXMPP_EXPORT QXmppRosterManager : public QXmppClientExtension
57{
58 Q_OBJECT
59
60public:
62 using Result = std::variant<QXmpp::Success, QXmppError>;
63
64 explicit QXmppRosterManager(QXmppClient *stream);
65 ~QXmppRosterManager() override;
66
67 bool isRosterReceived() const;
68 QStringList getRosterBareJids() const;
69 QXmppRosterIq::Item getRosterEntry(const QString &bareJid) const;
70
71 QStringList getResources(const QString &bareJid) const;
72 QMap<QString, QXmppPresence> getAllPresencesForBareJid(
73 const QString &bareJid) const;
74 QXmppPresence getPresence(const QString &bareJid,
75 const QString &resource) const;
76
77 QXmppTask<Result> addRosterItem(const QString &bareJid, const QString &name = {}, const QSet<QString> &groups = {});
78 QXmppTask<Result> removeRosterItem(const QString &bareJid);
79 QXmppTask<Result> renameRosterItem(const QString &bareJid, const QString &name);
80 QXmppTask<QXmpp::SendResult> subscribeTo(const QString &bareJid, const QString &reason = {});
81 QXmppTask<QXmpp::SendResult> unsubscribeFrom(const QString &bareJid, const QString &reason = {});
82
84 bool handleStanza(const QDomElement &element) override;
86
87public Q_SLOTS:
88 bool acceptSubscription(const QString &bareJid, const QString &reason = {});
89 bool refuseSubscription(const QString &bareJid, const QString &reason = {});
90 bool addItem(const QString &bareJid, const QString &name = {}, const QSet<QString> &groups = {});
91 bool removeItem(const QString &bareJid);
92 bool renameItem(const QString &bareJid, const QString &name);
93 bool subscribe(const QString &bareJid, const QString &reason = {});
94 bool unsubscribe(const QString &bareJid, const QString &reason = {});
95
96Q_SIGNALS:
106
108 void presenceChanged(const QString &bareJid, const QString &resource);
109
119 void subscriptionReceived(const QString &bareJid);
120
121 void subscriptionRequestReceived(const QString &subscriberBareJid, const QXmppPresence &presence);
122
125 void itemAdded(const QString &bareJid);
126
129 void itemChanged(const QString &bareJid);
130
133 void itemRemoved(const QString &bareJid);
134
135protected:
136 void onRegistered(QXmppClient *client) override;
137 void onUnregistered(QXmppClient *client) override;
138
139private Q_SLOTS:
140 void _q_connected();
141 void _q_disconnected();
142 void _q_presenceReceived(const QXmppPresence &);
143
144private:
145 using RosterResult = std::variant<QXmppRosterIq, QXmppError>;
146
147 void handleSubscriptionRequest(const QString &bareJid, const QXmppPresence &presence, bool accept);
148 QXmppTask<RosterResult> requestRoster();
149
150 const std::unique_ptr<QXmppRosterManagerPrivate> d;
151
152 friend class QXmppMixManager;
153};
154
155#endif // QXMPPROSTER_H
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:32
virtual void onUnregistered(QXmppClient *client)
Definition: QXmppClientExtension.cpp:95
virtual void onRegistered(QXmppClient *client)
Definition: QXmppClientExtension.cpp:85
virtual bool handleStanza(const QDomElement &stanza)
You need to implement this method to process incoming XMPP stanzas.
Definition: client/compat/removed_api.cpp:26
Main class for starting and managing connections to XMPP servers.
Definition: QXmppClient.h:62
Definition: QXmppMixManager.h:20
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:22
The QXmppRosterIq::Item class represents a roster entry.
Definition: QXmppRosterIq.h:33
The QXmppRosterManager class provides access to a connected client's roster.
Definition: QXmppRosterManager.h:57
void subscriptionReceived(const QString &bareJid)
void subscriptionRequestReceived(const QString &subscriberBareJid, const QXmppPresence &presence)
void itemRemoved(const QString &bareJid)
void itemChanged(const QString &bareJid)
void itemAdded(const QString &bareJid)
void presenceChanged(const QString &bareJid, const QString &resource)
This signal is emitted when the presence of a particular bareJid and resource changes.
std::variant< QXmpp::Success, QXmppError > Result
Empty result containing QXmpp::Success or a QXmppError.
Definition: QXmppRosterManager.h:62
Definition: QXmppTask.h:62