diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-19 13:20:38 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-19 13:20:38 +0000 |
| commit | b9dd4f292c5f4fea69fd8c7bd8c8aad90d5e55b7 (patch) | |
| tree | 258011382e1d400414947b0b6b87f5d8f73459fe /example | |
| parent | 12dae9a8f4bb86498b99500b36b9ef6eb605ce12 (diff) | |
| download | qxmpp-b9dd4f292c5f4fea69fd8c7bd8c8aad90d5e55b7.tar.gz | |
* use qxmpp.testX@gmail.com credentials for consistency
* wait for the recipient to be online before sending file
Diffstat (limited to 'example')
| -rw-r--r-- | example/example_3_transferHandling/main.cpp | 4 | ||||
| -rw-r--r-- | example/example_3_transferHandling/xmppClient.cpp | 56 | ||||
| -rw-r--r-- | example/example_3_transferHandling/xmppClient.h | 2 |
3 files changed, 34 insertions, 28 deletions
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: |
