QXmpp  Version: 1.6.0
QXmppMucManager.h
1 // SPDX-FileCopyrightText: 2010 Jeremy LainĂ© <jeremy.laine@m4x.org>
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 
5 #ifndef QXMPPMUCMANAGER_H
6 #define QXMPPMUCMANAGER_H
7 
8 #include "QXmppClientExtension.h"
9 #include "QXmppMucIq.h"
10 #include "QXmppPresence.h"
11 
12 class QXmppDataForm;
13 class QXmppDiscoveryIq;
14 class QXmppMessage;
15 class QXmppMucManagerPrivate;
16 class QXmppMucRoom;
17 class QXmppMucRoomPrivate;
18 
39 
40 class QXMPP_EXPORT QXmppMucManager : public QXmppClientExtension
41 {
42  Q_OBJECT
44  Q_PROPERTY(QList<QXmppMucRoom *> rooms READ rooms NOTIFY roomAdded)
45 
46 public:
48  ~QXmppMucManager() override;
49 
50  QXmppMucRoom *addRoom(const QString &roomJid);
51 
52  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
54  QList<QXmppMucRoom *> rooms() const;
55 
57  QStringList discoveryFeatures() const override;
58  bool handleStanza(const QDomElement &element) override;
60 
61 Q_SIGNALS:
63  void invitationReceived(const QString &roomJid, const QString &inviter, const QString &reason);
64 
66  void roomAdded(QXmppMucRoom *room);
67 
68 protected:
70  void setClient(QXmppClient *client) override;
72 
73 private Q_SLOTS:
74  void _q_messageReceived(const QXmppMessage &message);
75  void _q_roomDestroyed(QObject *object);
76 
77 private:
78  const std::unique_ptr<QXmppMucManagerPrivate> d;
79 };
80 
85 
86 class QXMPP_EXPORT QXmppMucRoom : public QObject
87 {
88  Q_OBJECT
89  Q_FLAGS(Action Actions)
90 
91 
92  Q_PROPERTY(QXmppMucRoom::Actions allowedActions READ allowedActions NOTIFY allowedActionsChanged)
94  Q_PROPERTY(bool isJoined READ isJoined NOTIFY isJoinedChanged)
96  Q_PROPERTY(QString jid READ jid CONSTANT)
98  Q_PROPERTY(QString name READ name NOTIFY nameChanged)
100  Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
102  Q_PROPERTY(QStringList participants READ participants NOTIFY participantsChanged)
104  Q_PROPERTY(QString password READ password WRITE setPassword)
106  Q_PROPERTY(QString subject READ subject WRITE setSubject NOTIFY subjectChanged)
107 
108 public:
110  enum Action {
111  NoAction = 0,
112  SubjectAction = 1,
113  ConfigurationAction = 2,
114  PermissionsAction = 4,
115  KickAction = 8
116  };
117  Q_DECLARE_FLAGS(Actions, Action)
118 
119  ~QXmppMucRoom() override;
120 
121  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
123  Actions allowedActions() const;
124 
125  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
127  bool isJoined() const;
128 
129  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
131  QString jid() const;
132 
133  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
139  QString name() const;
140 
141  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
143  QString nickName() const;
144  void setNickName(const QString &nickName);
145 
146  Q_INVOKABLE QString participantFullJid(const QString &jid) const;
147  QXmppPresence participantPresence(const QString &jid) const;
148 
149  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
155  QStringList participants() const;
156 
157  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
159  QString password() const;
160  void setPassword(const QString &password);
161 
162  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
164  QString subject() const;
165  void setSubject(const QString &subject);
166 
167 Q_SIGNALS:
169  void allowedActionsChanged(QXmppMucRoom::Actions actions);
170 
172  void configurationReceived(const QXmppDataForm &configuration);
173 
175  void error(const QXmppStanza::Error &error);
176 
178  void joined();
179 
181  void kicked(const QString &jid, const QString &reason);
182 
184  void isJoinedChanged();
186 
188  void left();
189 
191  void messageReceived(const QXmppMessage &message);
192 
194  void nameChanged(const QString &name);
195 
197  void nickNameChanged(const QString &nickName);
198 
200  void participantAdded(const QString &jid);
201 
203  void participantChanged(const QString &jid);
204 
206  void participantRemoved(const QString &jid);
207 
209  void participantsChanged();
211 
213  void permissionsReceived(const QList<QXmppMucItem> &permissions);
214 
216  void subjectChanged(const QString &subject);
217 
218 public Q_SLOTS:
219  bool ban(const QString &jid, const QString &reason);
220  bool join();
221  bool kick(const QString &jid, const QString &reason);
222  bool leave(const QString &message = QString());
223  bool requestConfiguration();
224  bool requestPermissions();
225  bool setConfiguration(const QXmppDataForm &form);
226  bool setPermissions(const QList<QXmppMucItem> &permissions);
227  bool sendInvitation(const QString &jid, const QString &reason);
228  bool sendMessage(const QString &text);
229 
230 private Q_SLOTS:
231  void _q_disconnected();
232  void _q_discoveryInfoReceived(const QXmppDiscoveryIq &iq);
233  void _q_messageReceived(const QXmppMessage &message);
234  void _q_presenceReceived(const QXmppPresence &presence);
235 
236 private:
237  QXmppMucRoom(QXmppClient *client, const QString &jid, QObject *parent);
238  const std::unique_ptr<QXmppMucRoomPrivate> d;
239  friend class QXmppMucManager;
240 };
241 
242 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppMucRoom::Actions)
243 
244 #endif
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:33
virtual void setClient(QXmppClient *client)
Definition: QXmppClientExtension.cpp:88
virtual QStringList discoveryFeatures() const
Definition: QXmppClientExtension.cpp:22
virtual bool handleStanza(const QDomElement &stanza)
You need to implement this method to process incoming XMPP stanzas.
Definition: QXmppClientExtension.cpp:51
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:84
Definition: QXmppDataForm.h:27
Definition: QXmppDiscoveryIq.h:18
Action
Definition: QXmppExternalService.h:27
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:38
The QXmppMucManager class makes it possible to interact with multi-user chat rooms as defined by XEP-...
Definition: QXmppMucManager.h:41
void invitationReceived(const QString &roomJid, const QString &inviter, const QString &reason)
This signal is emitted when an invitation to a chat room is received.
void roomAdded(QXmppMucRoom *room)
This signal is emitted when a new room is managed.
The QXmppMucRoom class represents a multi-user chat room as defined by XEP-0045: Multi-User Chat.
Definition: QXmppMucManager.h:87
void error(const QXmppStanza::Error &error)
This signal is emitted when an error is encountered.
void participantChanged(const QString &jid)
This signal is emitted when a participant changes.
void messageReceived(const QXmppMessage &message)
This signal is emitted when a message is received.
void participantRemoved(const QString &jid)
This signal is emitted when a participant leaves the room.
void configurationReceived(const QXmppDataForm &configuration)
This signal is emitted when the configuration form for the room is received.
void nickNameChanged(const QString &nickName)
This signal is emitted when your own nick name changes.
void subjectChanged(const QString &subject)
This signal is emitted when the room's subject changes.
void nameChanged(const QString &name)
This signal is emitted when the room's human-readable name changes.
void participantAdded(const QString &jid)
This signal is emitted when a participant joins the room.
void left()
This signal is emitted once you have left the room.
void joined()
This signal is emitted once you have joined the room.
void permissionsReceived(const QList< QXmppMucItem > &permissions)
This signal is emitted when the room's permissions are received.
void allowedActionsChanged(QXmppMucRoom::Actions actions)
This signal is emitted when the allowed actions change.
Action
This enum is used to describe chat room actions.
Definition: QXmppMucManager.h:110
void kicked(const QString &jid, const QString &reason)
This signal is emitted if you get kicked from the room.
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:21
The Error class represents a stanza error.
Definition: QXmppStanza.h:94