QXmppMucManager.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Jeremy Lainé
  6. *
  7. * Source:
  8. * http://code.google.com/p/qxmpp
  9. *
  10. * This file is a part of QXmpp library.
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. */
  23. #ifndef QXMPPMUCMANAGER_H
  24. #define QXMPPMUCMANAGER_H
  25. #include "QXmppClientExtension.h"
  26. #include "QXmppMucIq.h"
  27. #include "QXmppPresence.h"
  28. class QXmppDataForm;
  29. class QXmppDiscoveryIq;
  30. class QXmppMessage;
  31. class QXmppMucManagerPrivate;
  32. class QXmppMucRoom;
  33. class QXmppMucRoomPrivate;
  34. /// \brief The QXmppMucManager class makes it possible to interact with
  35. /// multi-user chat rooms as defined by XEP-0045: Multi-User Chat.
  36. ///
  37. /// To make use of this manager, you need to instantiate it and load it into
  38. /// the QXmppClient instance as follows:
  39. ///
  40. /// \code
  41. /// QXmppMucManager *manager = new QXmppMucManager;
  42. /// client->addExtension(manager);
  43. /// \endcode
  44. ///
  45. /// You can then join a room as follows:
  46. ///
  47. /// \code
  48. /// QXmppMucRoom *room = manager->addRoom("room@conference.example.com");
  49. /// room->setNickName("mynick");
  50. /// room->join();
  51. /// \endcode
  52. ///
  53. /// \ingroup Managers
  54. class QXMPP_EXPORT QXmppMucManager : public QXmppClientExtension
  55. {
  56. Q_OBJECT
  57. Q_PROPERTY(QList<QXmppMucRoom*> rooms READ rooms NOTIFY roomAdded)
  58. public:
  59. QXmppMucManager();
  60. ~QXmppMucManager();
  61. QXmppMucRoom *addRoom(const QString &roomJid);
  62. QList<QXmppMucRoom*> rooms() const;
  63. /// \cond
  64. QStringList discoveryFeatures() const;
  65. bool handleStanza(const QDomElement &element);
  66. /// \endcond
  67. signals:
  68. /// This signal is emitted when an invitation to a chat room is received.
  69. void invitationReceived(const QString &roomJid, const QString &inviter, const QString &reason);
  70. /// This signal is emitted when a new room is managed.
  71. void roomAdded(QXmppMucRoom *room);
  72. protected:
  73. /// \cond
  74. void setClient(QXmppClient* client);
  75. /// \endcond
  76. private slots:
  77. void _q_messageReceived(const QXmppMessage &message);
  78. void _q_roomDestroyed(QObject *object);
  79. private:
  80. QXmppMucManagerPrivate *d;
  81. };
  82. /// \brief The QXmppMucRoom class represents a multi-user chat room
  83. /// as defined by XEP-0045: Multi-User Chat.
  84. ///
  85. /// \sa QXmppMucManager
  86. class QXMPP_EXPORT QXmppMucRoom : public QObject
  87. {
  88. Q_OBJECT
  89. Q_FLAGS(Action Actions)
  90. Q_PROPERTY(QXmppMucRoom::Actions allowedActions READ allowedActions NOTIFY allowedActionsChanged)
  91. Q_PROPERTY(bool isJoined READ isJoined NOTIFY isJoinedChanged)
  92. Q_PROPERTY(QString jid READ jid CONSTANT)
  93. Q_PROPERTY(QString name READ name NOTIFY nameChanged)
  94. Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
  95. Q_PROPERTY(QStringList participants READ participants NOTIFY participantsChanged)
  96. Q_PROPERTY(QString password READ password WRITE setPassword)
  97. Q_PROPERTY(QString subject READ subject WRITE setSubject NOTIFY subjectChanged)
  98. public:
  99. /// This enum is used to describe chat room actions.
  100. enum Action {
  101. NoAction = 0, ///< no action
  102. SubjectAction = 1, ///< change the room's subject
  103. ConfigurationAction = 2, ///< change the room's configuration
  104. PermissionsAction = 4, ///< change the room's permissions
  105. KickAction = 8, ///< kick users from the room
  106. };
  107. Q_DECLARE_FLAGS(Actions, Action)
  108. ~QXmppMucRoom();
  109. Actions allowedActions() const;
  110. bool isJoined() const;
  111. QString jid() const;
  112. QString name() const;
  113. QString nickName() const;
  114. void setNickName(const QString &nickName);
  115. Q_INVOKABLE QString participantFullJid(const QString &jid) const;
  116. QXmppPresence participantPresence(const QString &jid) const;
  117. QStringList participants() const;
  118. QString password() const;
  119. void setPassword(const QString &password);
  120. QString subject() const;
  121. void setSubject(const QString &subject);
  122. signals:
  123. /// This signal is emitted when the allowed actions change.
  124. void allowedActionsChanged(QXmppMucRoom::Actions actions) const;
  125. /// This signal is emitted when the configuration form for the room is received.
  126. void configurationReceived(const QXmppDataForm &configuration);
  127. /// This signal is emitted when an error is encountered.
  128. void error(const QXmppStanza::Error &error);
  129. /// This signal is emitted once you have joined the room.
  130. void joined();
  131. /// This signal is emitted if you get kicked from the room.
  132. void kicked(const QString &jid, const QString &reason);
  133. /// \cond
  134. void isJoinedChanged();
  135. /// \endcond
  136. /// This signal is emitted once you have left the room.
  137. void left();
  138. /// This signal is emitted when a message is received.
  139. void messageReceived(const QXmppMessage &message);
  140. /// This signal is emitted when the room's human-readable name changes.
  141. void nameChanged(const QString &name);
  142. /// This signal is emitted when your own nick name changes.
  143. void nickNameChanged(const QString &nickName);
  144. /// This signal is emitted when a participant joins the room.
  145. void participantAdded(const QString &jid);
  146. /// This signal is emitted when a participant changes.
  147. void participantChanged(const QString &jid);
  148. /// This signal is emitted when a participant leaves the room.
  149. void participantRemoved(const QString &jid);
  150. /// \cond
  151. void participantsChanged();
  152. /// \endcond
  153. /// This signal is emitted when the room's permissions are received.
  154. void permissionsReceived(const QList<QXmppMucItem> &permissions);
  155. /// This signal is emitted when the room's subject changes.
  156. void subjectChanged(const QString &subject);
  157. public slots:
  158. bool ban(const QString &jid, const QString &reason);
  159. bool join();
  160. bool kick(const QString &jid, const QString &reason);
  161. bool leave(const QString &message = QString());
  162. bool requestConfiguration();
  163. bool requestPermissions();
  164. bool setConfiguration(const QXmppDataForm &form);
  165. bool setPermissions(const QList<QXmppMucItem> &permissions);
  166. bool sendInvitation(const QString &jid, const QString &reason);
  167. bool sendMessage(const QString &text);
  168. private slots:
  169. void _q_disconnected();
  170. void _q_discoveryInfoReceived(const QXmppDiscoveryIq &iq);
  171. void _q_messageReceived(const QXmppMessage &message);
  172. void _q_presenceReceived(const QXmppPresence &presence);
  173. private:
  174. QXmppMucRoom(QXmppClient *client, const QString &jid, QObject *parent);
  175. QXmppMucRoomPrivate *d;
  176. friend class QXmppMucManager;
  177. };
  178. Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppMucRoom::Actions)
  179. #endif