From dfec49b06fc305cc55631e5473b9ba19c729cd03 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Mon, 21 Oct 2019 17:01:03 +0200 Subject: Port away from deprecated client extension getters of the QXmppClient This replaces the deprecated getters in the examples and in the documentation. --- .../example_2_rosterHandling.cpp | 35 +++++------- .../example_2_rosterHandling.h | 5 ++ examples/example_9_vCard/example_9_vCard.cpp | 64 +++++++++------------- examples/example_9_vCard/example_9_vCard.h | 6 ++ src/client/QXmppClient.cpp | 29 ++++++---- src/client/QXmppClient.h | 22 ++++---- src/client/QXmppRosterManager.h | 31 ++++++----- src/client/QXmppVCardManager.h | 4 +- src/client/QXmppVersionManager.h | 4 ++ 9 files changed, 103 insertions(+), 97 deletions(-) diff --git a/examples/example_2_rosterHandling/example_2_rosterHandling.cpp b/examples/example_2_rosterHandling/example_2_rosterHandling.cpp index ec063ab5..86ca555b 100644 --- a/examples/example_2_rosterHandling/example_2_rosterHandling.cpp +++ b/examples/example_2_rosterHandling/example_2_rosterHandling.cpp @@ -29,30 +29,22 @@ #include "example_2_rosterHandling.h" xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) + : QXmppClient(parent), + m_rosterManager(findExtension()) { - bool check; - Q_UNUSED(check); + connect(this, &QXmppClient::connected, + this, &xmppClient::clientConnected); - check = connect(this, SIGNAL(connected()), - SLOT(clientConnected())); - Q_ASSERT(check); + connect(m_rosterManager, &QXmppRosterManager::rosterReceived, + this, &xmppClient::rosterReceived); - check = connect(&this->rosterManager(), SIGNAL(rosterReceived()), - SLOT(rosterReceived())); - Q_ASSERT(check); - - /// Then QXmppRoster::presenceChanged() is emitted whenever presence of someone - /// in roster changes - check = connect(&this->rosterManager(), SIGNAL(presenceChanged(QString,QString)), - SLOT(presenceChanged(QString,QString))); - Q_ASSERT(check); + /// Then QXmppRoster::presenceChanged() is emitted whenever presence of + /// someone in roster changes + connect(m_rosterManager, &QXmppRosterManager::presenceChanged, + this, &xmppClient::presenceChanged); } -xmppClient::~xmppClient() -{ - -} +xmppClient::~xmppClient() = default; void xmppClient::clientConnected() { @@ -62,8 +54,9 @@ void xmppClient::clientConnected() void xmppClient::rosterReceived() { qDebug("example_2_rosterHandling:: Roster received"); - foreach (const QString &bareJid, rosterManager().getRosterBareJids()) { - QString name = rosterManager().getRosterEntry(bareJid).name(); + const QStringList jids = m_rosterManager->getRosterBareJids(); + for (const QString &bareJid : jids) { + QString name = m_rosterManager->getRosterEntry(bareJid).name(); if(name.isEmpty()) name = "-"; qDebug("example_2_rosterHandling:: Roster received: %s [%s]", qPrintable(bareJid), qPrintable(name)); diff --git a/examples/example_2_rosterHandling/example_2_rosterHandling.h b/examples/example_2_rosterHandling/example_2_rosterHandling.h index 06bcc6d1..8eefae48 100644 --- a/examples/example_2_rosterHandling/example_2_rosterHandling.h +++ b/examples/example_2_rosterHandling/example_2_rosterHandling.h @@ -27,6 +27,8 @@ #include "QXmppClient.h" +class QXmppRosterManager; + class xmppClient : public QXmppClient { Q_OBJECT @@ -39,6 +41,9 @@ public slots: void clientConnected(); void rosterReceived(); void presenceChanged(const QString& bareJid, const QString& resource); + +private: + QXmppRosterManager *m_rosterManager; }; #endif // XMPPCLIENT_H diff --git a/examples/example_9_vCard/example_9_vCard.cpp b/examples/example_9_vCard/example_9_vCard.cpp index f2f04e67..1fe9e76a 100644 --- a/examples/example_9_vCard/example_9_vCard.cpp +++ b/examples/example_9_vCard/example_9_vCard.cpp @@ -21,10 +21,9 @@ * */ -#include - #include #include +#include #include #include #include @@ -39,53 +38,43 @@ #include "example_9_vCard.h" xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) + : QXmppClient(parent), + m_rosterManager(findExtension()), + m_vCardManager(findExtension()) { - bool check; - Q_UNUSED(check); - - check = connect(this, SIGNAL(connected()), - SLOT(clientConnected())); - Q_ASSERT(check); + connect(this, &QXmppClient::connected, this, &xmppClient::clientConnected); - check = connect(&this->rosterManager(), SIGNAL(rosterReceived()), - SLOT(rosterReceived())); - Q_ASSERT(check); + connect(m_rosterManager, &QXmppRosterManager::rosterReceived, + this, &xmppClient::rosterReceived); } -xmppClient::~xmppClient() -{ - -} +xmppClient::~xmppClient() = default; void xmppClient::clientConnected() { - std::cout<<"example_9_vCard:: CONNECTED"<vCardManager(), SIGNAL(vCardReceived(QXmppVCardIq)), - SLOT(vCardReceived(QXmppVCardIq))); - Q_ASSERT(check); - Q_UNUSED(check); - - QStringList list = rosterManager().getRosterBareJids(); - for(int i = 0; i < list.size(); ++i) - { - // request vCard of all the bareJids in roster - vCardManager().requestVCard(list.at(i)); - } + qDebug() << "example_9_vCard: Roster Received"; + + connect(m_vCardManager, &QXmppVCardManager::vCardReceived, + this, &xmppClient::vCardReceived); + + // request vCard of all the bareJids in roster + const QStringList jids = m_rosterManager->getRosterBareJids(); + for (const auto &jid : jids) + m_vCardManager->requestVCard(jid); } void xmppClient::vCardReceived(const QXmppVCardIq& vCard) { QString bareJid = vCard.from(); - std::cout<<"example_9_vCard:: vCard Received:: " << qPrintable(bareJid) <(); + + const QStringList resources = rosterManager + ? rosterManager->getResources(bareJid) + : QStringList(); + + if (!resources.isEmpty()) { + for (const auto &resource : resources) { + sendPacket( + QXmppMessage({}, bareJid + QStringLiteral("/") + resource, message) + ); } - } - else - { - sendPacket(QXmppMessage("", bareJid, message)); + } else { + sendPacket(QXmppMessage({}, bareJid, message)); } } diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h index 5f765602..d3726334 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -64,9 +64,9 @@ class QXmppVersionManager; /// QXmppConfiguration::setAutoReconnectionEnabled(). /// /// Not all the managers or extensions have been enabled by default. One can -/// enable/disable the managers using the functions addExtension() and -/// removeExtension(). findExtension() can be used to find reference/pointer to -/// particular instansiated and enabled manager. +/// enable/disable the managers using the functions \c addExtension() and +/// \c removeExtension(). \c findExtension() can be used to find reference/ +/// pointer to particular instansiated and enabled manager. /// /// List of managers enabled by default: /// - QXmppRosterManager @@ -168,8 +168,8 @@ public: signals: - /// This signal is emitted when the client connects successfully to the XMPP - /// server i.e. when a successful XMPP connection is established. + /// This signal is emitted when the client connects successfully to the + /// XMPP server i.e. when a successful XMPP connection is established. /// XMPP Connection involves following sequential steps: /// - TCP socket connection /// - Client sends start stream @@ -182,15 +182,15 @@ signals: /// After all these steps a successful XMPP connection is established and /// connected() signal is emitted. /// - /// After the connected() signal is emitted QXmpp will send the roster request - /// to the server. On receiving the roster, QXmpp will emit - /// QXmppRosterManager::rosterReceived(). After this signal, QXmppRosterManager object gets - /// populated and you can use rosterManager() to get the handle of QXmppRosterManager object. - /// + /// After the connected() signal is emitted QXmpp will send the roster + /// request to the server. On receiving the roster, QXmpp will emit + /// QXmppRosterManager::rosterReceived(). After this signal, + /// QXmppRosterManager object gets populated and you can use + /// \c findExtension() to get the handle of + /// QXmppRosterManager object. void connected(); /// This signal is emitted when the XMPP connection disconnects. - /// void disconnected(); /// This signal is emitted when the XMPP connection encounters any error. diff --git a/src/client/QXmppRosterManager.h b/src/client/QXmppRosterManager.h index 869b6b42..6b050197 100644 --- a/src/client/QXmppRosterManager.h +++ b/src/client/QXmppRosterManager.h @@ -35,29 +35,32 @@ class QXmppRosterManagerPrivate; -/// \brief The QXmppRosterManager class provides access to a connected client's roster. +/// \brief The QXmppRosterManager class provides access to a connected client's +/// roster. /// /// \note It's object should not be created using it's constructor. Instead -/// QXmppClient::rosterManager() should be used to get the reference of instantiated -/// object this class. +/// \c QXmppClient::findExtension() should be used to get +/// the instantiated object of this class. /// -/// It stores all the Roster and Presence details of all the roster entries (that -/// is all the bareJids) in the client's friend's list. It provides the +/// It stores all the Roster and Presence details of all the roster entries +/// (that is all the bareJids) in the client's friend's list. It provides the /// functionality to get all the bareJids in the client's roster and Roster and /// Presence details of the same. /// -/// After the successful xmpp connection that after the signal QXmppClient::connected() -/// is emitted QXmpp requests for getting the roster. Once QXmpp receives the roster -/// the signal QXmppRosterManager::rosterReceived() is emitted and after that user can -/// use the functions of this class to get roster entries. +/// After the QXmpp connected successfully to the XMPP server the signal +/// \c QXmppClient::connected() is emitted and the roster is requested from the +/// server. Once QXmpp receives the roster the signal +/// \c QXmppRosterManager::rosterReceived() is emitted and after that the +/// methods of this class can be used to get the roster entries. /// -/// Function QXmppRosterManager::isRosterReceived() tells whether the roster has been -/// received or not. +/// \c QXmppRosterManager::isRosterReceived() can be used to find out whether +/// the roster has been received yet. /// -/// The itemAdded(), itemChanged() and itemRemoved() signals are emitted whenever roster -/// entries are added, changed or removed. +/// The \c itemAdded(), \c itemChanged() and \c itemRemoved() signals are +/// emitted whenever roster entries are added, changed or removed. /// -/// The presenceChanged() signal is emitted whenever the presence for a roster item changes. +/// The \c presenceChanged() signal is emitted whenever the presence for a +/// roster item changes. /// /// \ingroup Managers diff --git a/src/client/QXmppVCardManager.h b/src/client/QXmppVCardManager.h index 328fe4a0..55a150f7 100644 --- a/src/client/QXmppVCardManager.h +++ b/src/client/QXmppVCardManager.h @@ -34,8 +34,8 @@ class QXmppVCardManagerPrivate; /// implementation of XEP-0054: vcard-temp. /// /// \note It's object should not be created using it's constructor. Instead -/// QXmppClient::vCardManager() should be used to get the reference of instantiated -/// object this class. +/// \c QXmppClient::findExtension() should be used to get +/// the instantiated object of this class. /// /// Getting vCards of entries in Roster:
/// It doesn't store vCards of the JIDs in the roster of connected user. Instead diff --git a/src/client/QXmppVersionManager.h b/src/client/QXmppVersionManager.h index eb992611..9a6fc7a8 100644 --- a/src/client/QXmppVersionManager.h +++ b/src/client/QXmppVersionManager.h @@ -32,6 +32,10 @@ class QXmppVersionManagerPrivate; /// \brief The QXmppVersionManager class makes it possible to request for /// the software version of an entity as defined by XEP-0092: Software Version. /// +/// \note It's object should not be created using it's constructor. Instead +/// \c QXmppClient::findExtension() should be used to get +/// the instantiated object of this class. +/// /// \ingroup Managers class QXMPP_EXPORT QXmppVersionManager : public QXmppClientExtension -- cgit v1.2.3