From b9dd4f292c5f4fea69fd8c7bd8c8aad90d5e55b7 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Mon, 19 Jul 2010 13:20:38 +0000 Subject: * use qxmpp.testX@gmail.com credentials for consistency * wait for the recipient to be online before sending file --- example/example_3_transferHandling/main.cpp | 4 +- example/example_3_transferHandling/xmppClient.cpp | 56 +++++++++++++---------- example/example_3_transferHandling/xmppClient.h | 2 +- 3 files changed, 34 insertions(+), 28 deletions(-) (limited to 'example/example_3_transferHandling') diff --git a/example/example_3_transferHandling/main.cpp b/example/example_3_transferHandling/main.cpp index 2f51e855..9b379180 100644 --- a/example/example_3_transferHandling/main.cpp +++ b/example/example_3_transferHandling/main.cpp @@ -41,10 +41,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: ibbClient send|receive\n"); return EXIT_FAILURE; } - const QString username = strcmp(argv[1], "send") ? QLatin1String("client") : QLatin1String("server"); + const QString username = (!strcmp(argv[1], "send")) ? QLatin1String("qxmpp.test1") : QLatin1String("qxmpp.test2"); xmppClient client; client.getConfiguration().setUseSASLAuthentication( false ); - client.connectToServer("jabber.geiseri.com", username, "Passw0rd", "geiseri.com"); + client.connectToServer("talk.google.com", username, "qxmpp123", "gmail.com"); return a.exec(); } diff --git a/example/example_3_transferHandling/xmppClient.cpp b/example/example_3_transferHandling/xmppClient.cpp index 23eed959..12c5fed6 100644 --- a/example/example_3_transferHandling/xmppClient.cpp +++ b/example/example_3_transferHandling/xmppClient.cpp @@ -36,8 +36,8 @@ xmppClient::xmppClient(QObject *parent) // comment the following to use all available methods (highly recommended) transferManager().setSupportedMethods(QXmppTransferJob::InBandMethod); - bool check = connect(this, SIGNAL(connected()), - this, SLOT(slotConnected()) ); + bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)), + this, SLOT(slotPresenceReceived(QXmppPresence))); Q_ASSERT(check); check = connect(&transferManager(), SIGNAL(fileReceived(QXmppTransferJob*)), @@ -56,29 +56,6 @@ void xmppClient::sendOnceAvailable(const QString &recipient, const QString &file m_sendFile = file; } -void xmppClient::slotConnected() -{ - const QLatin1String recipient("client@geiseri.com/QXmpp"); - - // if we are the recipient, do nothing - if (getConfiguration().jid() == recipient) - return; - - QXmppTransferJob *job = transferManager().sendFile(recipient, "xmppClient.cpp"); - - bool check = connect( job, SIGNAL(error(QXmppTransferJob::Error)), - this, SLOT(slotError(QXmppTransferJob::Error)) ); - Q_ASSERT(check); - - check = connect( job, SIGNAL(finished()), - this, SLOT(slotFinished()) ); - Q_ASSERT(check); - - check = connect( job, SIGNAL(progress(qint64,qint64)), - this, SLOT(slotProgress(qint64,qint64)) ); - Q_ASSERT(check); -} - /// A file transfer failed. void xmppClient::slotError(QXmppTransferJob::Error error) @@ -114,6 +91,35 @@ void xmppClient::slotFinished() qDebug() << "Transmission finished"; } +/// A presence was received + +void xmppClient::slotPresenceReceived(const QXmppPresence &presence) +{ + const QLatin1String recipient("qxmpp.test2@gmail.com"); + + // if we are the recipient, or if the presence is not from the recipient, + // do nothing + if (getConfiguration().jidBare() == recipient || + jidToBareJid(presence.from()) != recipient || + presence.type() != QXmppPresence::Available) + return; + + // send the file and connect to the job's signals + QXmppTransferJob *job = transferManager().sendFile(presence.from(), "xmppClient.cpp"); + + bool check = connect( job, SIGNAL(error(QXmppTransferJob::Error)), + this, SLOT(slotError(QXmppTransferJob::Error)) ); + Q_ASSERT(check); + + check = connect( job, SIGNAL(finished()), + this, SLOT(slotFinished()) ); + Q_ASSERT(check); + + check = connect( job, SIGNAL(progress(qint64,qint64)), + this, SLOT(slotProgress(qint64,qint64)) ); + Q_ASSERT(check); +} + /// A file transfer has made progress. void xmppClient::slotProgress(qint64 done, qint64 total) diff --git a/example/example_3_transferHandling/xmppClient.h b/example/example_3_transferHandling/xmppClient.h index dc730d3e..ce401e22 100644 --- a/example/example_3_transferHandling/xmppClient.h +++ b/example/example_3_transferHandling/xmppClient.h @@ -39,10 +39,10 @@ public: void sendOnceAvailable(const QString &recipient, const QString &file); private slots: - void slotConnected(); void slotError(QXmppTransferJob::Error error); void slotFileReceived(QXmppTransferJob *job); void slotFinished(); + void slotPresenceReceived(const QXmppPresence &presence); void slotProgress(qint64 done, qint64 total); private: -- cgit v1.2.3