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/example_3_transferHandling/xmppClient.cpp | |
| 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/example_3_transferHandling/xmppClient.cpp')
| -rw-r--r-- | example/example_3_transferHandling/xmppClient.cpp | 56 |
1 files changed, 31 insertions, 25 deletions
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) |
