diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-12-10 16:46:56 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-12-10 16:46:56 +0000 |
| commit | 322725554e52c46638481c34ee6f652d173c58f4 (patch) | |
| tree | b104bdc6db1b05f2babd3c15da66951e34e065a1 /examples/example_6_rpcClient/rpcClient.cpp | |
| parent | 0fc9ad87ac985ae40b2f205c88f901024967c3ec (diff) | |
cleanup RPC examples to use qxmpp.testX@gmail.com accounts
Diffstat (limited to 'examples/example_6_rpcClient/rpcClient.cpp')
| -rw-r--r-- | examples/example_6_rpcClient/rpcClient.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/examples/example_6_rpcClient/rpcClient.cpp b/examples/example_6_rpcClient/rpcClient.cpp index 3f63d062..9e244393 100644 --- a/examples/example_6_rpcClient/rpcClient.cpp +++ b/examples/example_6_rpcClient/rpcClient.cpp @@ -21,46 +21,52 @@ * */ +#include <QDebug> +#include <QTimer> -#include "rpcClient.h" #include "QXmppRemoteMethod.h" -#include <qdebug.h> -#include <QTimer> +#include "QXmppUtils.h" + +#include "rpcClient.h" rpcClient::rpcClient(QObject *parent) : QXmppClient(parent) { - connect( this, SIGNAL(connected()), this, SLOT(isConnected())); + bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)), + this, SLOT(slotPresenceReceived(QXmppPresence))); + Q_ASSERT(check); + Q_UNUSED(check); } rpcClient::~rpcClient() { - -} - -void rpcClient::isConnected() -{ - //We need to wait until we have sent the presense stuff, or for some - //reason the server ignores us... - QTimer::singleShot(5000, this, SLOT(invokeRemoteMethod())); } -void rpcClient::invokeRemoteMethod() +void rpcClient::slotInvokeRemoteMethod() { QXmppRemoteMethodResult methodResult = callRemoteMethod( - "server@geiseri.com/QXmpp", "RemoteInterface.echoString", "This is a test" ); + m_remoteJid, "RemoteInterface.echoString", "This is a test" ); if( methodResult.hasError ) - error( methodResult.code, methodResult.errorMessage ); + qDebug() << "Error:" << methodResult.code << methodResult.errorMessage; else - result( methodResult.result ); + qDebug() << "Result:" << methodResult.result; } -void rpcClient::result(const QVariant &value ) -{ - qDebug() << "Result:" << value; -} +/// A presence was received. -void rpcClient::error( int code, const QString &message ) +void rpcClient::slotPresenceReceived(const QXmppPresence &presence) { - qDebug() << "Error:" << code << message; + const QLatin1String recipient("qxmpp.test1@gmail.com"); + + // if we are the recipient, or if the presence is not from the recipient, + // do nothing + if (jidToBareJid(configuration().jid()) == recipient || + jidToBareJid(presence.from()) != recipient || + presence.type() != QXmppPresence::Available) + return; + + // invoke the remote method in 1 second + m_remoteJid = presence.from(); + QTimer::singleShot(1000, this, SLOT(slotInvokeRemoteMethod())); } + |
