aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-10-21 17:01:03 +0200
committerLNJ <lnj@kaidan.im>2019-10-23 12:13:18 +0200
commitdfec49b06fc305cc55631e5473b9ba19c729cd03 (patch)
tree268083483bec5f41ce9b4dab1f0a9ece3f5258ed
parent91157d28b88ef3bab80100cd816c643809944a27 (diff)
downloadqxmpp-dfec49b06fc305cc55631e5473b9ba19c729cd03.tar.gz
Port away from deprecated client extension getters of the QXmppClient
This replaces the deprecated getters in the examples and in the documentation.
-rw-r--r--examples/example_2_rosterHandling/example_2_rosterHandling.cpp35
-rw-r--r--examples/example_2_rosterHandling/example_2_rosterHandling.h5
-rw-r--r--examples/example_9_vCard/example_9_vCard.cpp64
-rw-r--r--examples/example_9_vCard/example_9_vCard.h6
-rw-r--r--src/client/QXmppClient.cpp29
-rw-r--r--src/client/QXmppClient.h22
-rw-r--r--src/client/QXmppRosterManager.h31
-rw-r--r--src/client/QXmppVCardManager.h4
-rw-r--r--src/client/QXmppVersionManager.h4
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<QXmppRosterManager>())
{
- 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 <iostream>
-
#include <QBuffer>
#include <QCoreApplication>
+#include <QDebug>
#include <QDir>
#include <QFile>
#include <QImage>
@@ -39,53 +38,43 @@
#include "example_9_vCard.h"
xmppClient::xmppClient(QObject *parent)
- : QXmppClient(parent)
+ : QXmppClient(parent),
+ m_rosterManager(findExtension<QXmppRosterManager>()),
+ m_vCardManager(findExtension<QXmppVCardManager>())
{
- 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"<<std::endl;
+ qDebug() << "example_9_vCard: CONNECTED";
}
void xmppClient::rosterReceived()
{
- std::cout<<"example_9_vCard:: Roster Received"<<std::endl;
- bool check = connect(&this->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) <<std::endl;
+ qDebug() << "example_9_vCard: vCard Received:" << bareJid;
- QString out("FullName: %1\nNickName: %2\n");
- std::cout<<qPrintable(out.arg(vCard.fullName()).arg(vCard.nickName())) <<std::endl;
+ qDebug() << "FullName:" << vCard.fullName();
+ qDebug() << "Nickname:" << vCard.nickName();
QString vCardsDir("vCards/");
@@ -94,12 +83,11 @@ void xmppClient::vCardReceived(const QXmppVCardIq& vCard)
dir.mkdir(vCardsDir);
QFile file("vCards/" + bareJid + ".xml");
- if(file.open(QIODevice::ReadWrite))
- {
+ if (file.open(QIODevice::ReadWrite)) {
QXmlStreamWriter stream(&file);
vCard.toXml(&stream);
file.close();
- std::cout<<"example_9_vCard:: vCard written to the file:: " << qPrintable(bareJid) <<std::endl;
+ qDebug() << "example_9_vCard: vCard written to the file:" << bareJid;
}
QString name("vCards/" + bareJid + ".png");
@@ -109,10 +97,8 @@ void xmppClient::vCardReceived(const QXmppVCardIq& vCard)
buffer.open(QIODevice::ReadOnly);
QImageReader imageReader(&buffer);
QImage image = imageReader.read();
- if(image.save(name))
- {
- std::cout<<"example_9_vCard:: Avatar saved to file" <<std::endl<<std::endl;
- }
+ if (image.save(name))
+ qDebug() << "example_9_vCard: Avatar saved to file";
}
int main(int argc, char *argv[])
diff --git a/examples/example_9_vCard/example_9_vCard.h b/examples/example_9_vCard/example_9_vCard.h
index 24fc4b6c..09de39c8 100644
--- a/examples/example_9_vCard/example_9_vCard.h
+++ b/examples/example_9_vCard/example_9_vCard.h
@@ -27,7 +27,9 @@
#include "QXmppClient.h"
+class QXmppRosterManager;
class QXmppVCardIq;
+class QXmppVCardManager;
class xmppClient : public QXmppClient
{
@@ -41,6 +43,10 @@ public slots:
void clientConnected();
void rosterReceived();
void vCardReceived(const QXmppVCardIq&);
+
+private:
+ QXmppRosterManager *m_rosterManager;
+ QXmppVCardManager *m_vCardManager;
};
#endif // XMPPCLIENT_H
diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp
index deef3dbc..b71fd8e9 100644
--- a/src/client/QXmppClient.cpp
+++ b/src/client/QXmppClient.cpp
@@ -361,22 +361,31 @@ QXmppRosterManager& QXmppClient::rosterManager()
/// is offline or not present in the roster, it will still send a message to
/// the bareJid.
///
+/// \note Usage of this method is discouraged because most modern clients use
+/// carbon messages (XEP-0280: Message Carbons) and MAM (XEP-0313: Message
+/// Archive Management) and so could possibly receive messages multiple times
+/// or not receive them at all.
+/// \c QXmppClient::sendPacket() should be used instead with a \c QXmppMessage.
+///
/// \param bareJid bareJid of the receiving entity
/// \param message Message string to be sent.
void QXmppClient::sendMessage(const QString& bareJid, const QString& message)
{
- QStringList resources = rosterManager().getResources(bareJid);
- if(!resources.isEmpty())
- {
- for(int i = 0; i < resources.size(); ++i)
- {
- sendPacket(QXmppMessage("", bareJid + "/" + resources.at(i), message));
+ QXmppRosterManager *rosterManager = findExtension<QXmppRosterManager>();
+
+ 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<QXmppRosterManager>() 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<QXmppRosterManager>() 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<QXmppVCardManager>() should be used to get
+/// the instantiated object of this class.
///
/// <B>Getting vCards of entries in Roster:</B><BR>
/// 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<QXmppVersionManager>() should be used to get
+/// the instantiated object of this class.
+///
/// \ingroup Managers
class QXMPP_EXPORT QXmppVersionManager : public QXmppClientExtension