QXmpp  Version: 1.7.1
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 
41 class QXMPP_EXPORT QXmppMucManager : public QXmppClientExtension
42 {
43  Q_OBJECT
45  Q_PROPERTY(QList<QXmppMucRoom *> rooms READ rooms NOTIFY roomAdded)
46 
47 public:
49  ~QXmppMucManager() override;
50 
51  QXmppMucRoom *addRoom(const QString &roomJid);
52 
53  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
55  QList<QXmppMucRoom *> rooms() const;
56 
58  QStringList discoveryFeatures() const override;
59  bool handleStanza(const QDomElement &element) override;
61 
62 Q_SIGNALS:
64  void invitationReceived(const QString &roomJid, const QString &inviter, const QString &reason);
65 
67  void roomAdded(QXmppMucRoom *room);
68 
69 protected:
71  void onRegistered(QXmppClient *client) override;
72  void onUnregistered(QXmppClient *client) override;
74 
75 private Q_SLOTS:
76  void _q_messageReceived(const QXmppMessage &message);
77  void _q_roomDestroyed(QObject *object);
78 
79 private:
80  const std::unique_ptr<QXmppMucManagerPrivate> d;
81 };
82 
87 
88 class QXMPP_EXPORT QXmppMucRoom : public QObject
89 {
90  Q_OBJECT
91  Q_FLAGS(Action Actions)
92 
93 
94  Q_PROPERTY(QXmppMucRoom::Actions allowedActions READ allowedActions NOTIFY allowedActionsChanged)
96  Q_PROPERTY(bool isJoined READ isJoined NOTIFY isJoinedChanged)
98  Q_PROPERTY(QString jid READ jid CONSTANT)
100  Q_PROPERTY(QString name READ name NOTIFY nameChanged)
102  Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
104  Q_PROPERTY(QStringList participants READ participants NOTIFY participantsChanged)
106  Q_PROPERTY(QString password READ password WRITE setPassword)
108  Q_PROPERTY(QString subject READ subject WRITE setSubject NOTIFY subjectChanged)
109 
110 public:
112  enum Action {
113  NoAction = 0,
114  SubjectAction = 1,
115  ConfigurationAction = 2,
116  PermissionsAction = 4,
117  KickAction = 8
118  };
119  Q_DECLARE_FLAGS(Actions, Action)
120 
121  ~QXmppMucRoom() override;
122 
123  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
125  Actions allowedActions() const;
126 
127  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
129  bool isJoined() const;
130 
131  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
133  QString jid() const;
134 
135  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
141  QString name() const;
142 
143  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
145  QString nickName() const;
146  void setNickName(const QString &nickName);
147 
148  Q_INVOKABLE QString participantFullJid(const QString &jid) const;
149  QXmppPresence participantPresence(const QString &jid) const;
150 
151  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
157  QStringList participants() const;
158 
159  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
161  QString password() const;
162  void setPassword(const QString &password);
163 
164  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
166  QString subject() const;
167  void setSubject(const QString &subject);
168 
169 Q_SIGNALS:
171  void allowedActionsChanged(QXmppMucRoom::Actions actions);
172 
174  void configurationReceived(const QXmppDataForm &configuration);
175 
177  void error(const QXmppStanza::Error &error);
178 
180  void joined();
181 
183  void kicked(const QString &jid, const QString &reason);
184 
186  void isJoinedChanged();
188 
190  void left();
191 
193  void messageReceived(const QXmppMessage &message);
194 
196  void nameChanged(const QString &name);
197 
199  void nickNameChanged(const QString &nickName);
200 
202  void participantAdded(const QString &jid);
203 
205  void participantChanged(const QString &jid);
206 
208  void participantRemoved(const QString &jid);
209 
211  void participantsChanged();
213 
215  void permissionsReceived(const QList<QXmppMucItem> &permissions);
216 
218  void subjectChanged(const QString &subject);
219 
220 public Q_SLOTS:
221  bool ban(const QString &jid, const QString &reason);
222  bool join();
223  bool kick(const QString &jid, const QString &reason);
224  bool leave(const QString &message = QString());
225  bool requestConfiguration();
226  bool requestPermissions();
227  bool setConfiguration(const QXmppDataForm &form);
228  bool setPermissions(const QList<QXmppMucItem> &permissions);
229  bool sendInvitation(const QString &jid, const QString &reason);
230  bool sendMessage(const QString &text);
231 
232 private Q_SLOTS:
233  void _q_disconnected();
234  void _q_discoveryInfoReceived(const QXmppDiscoveryIq &iq);
235  void _q_messageReceived(const QXmppMessage &message);
236  void _q_presenceReceived(const QXmppPresence &presence);
237 
238 private:
239  QXmppMucRoom(QXmppClient *client, const QString &jid, QObject *parent);
240  const std::unique_ptr<QXmppMucRoomPrivate> d;
241  friend class QXmppMucManager;
242 };
243 
244 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppMucRoom::Actions)
245 
246 #endif
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:33
virtual QStringList discoveryFeatures() const
Definition: QXmppClientExtension.cpp:22
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
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:85
Definition: QXmppDataForm.h:27
Definition: QXmppDiscoveryIq.h:18
Action
Definition: QXmppExternalService.h:27
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:39
The QXmppMucManager class makes it possible to interact with multi-user chat rooms as defined by XEP-...
Definition: QXmppMucManager.h:42
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:89
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:112
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