diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-24 10:42:26 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-02-24 10:42:26 +0000 |
| commit | 9334406b1ac2716ba799c5bb71d25efefaca29bc (patch) | |
| tree | 0e5f93d0edb3ddbdfba05dd5d0c8773cdffda1a7 /example | |
| parent | c6015694703439c8913735a2300b4cad039bbebb (diff) | |
| download | qxmpp-9334406b1ac2716ba799c5bb71d25efefaca29bc.tar.gz | |
update ibbTransferSource example to use QXmppTransferManager
Diffstat (limited to 'example')
| -rw-r--r-- | example/example_3_ibbTransferSource/ibbClient.cpp | 68 | ||||
| -rw-r--r-- | example/example_3_ibbTransferSource/ibbClient.h | 14 |
2 files changed, 31 insertions, 51 deletions
diff --git a/example/example_3_ibbTransferSource/ibbClient.cpp b/example/example_3_ibbTransferSource/ibbClient.cpp index bb13b87c..1e38f378 100644 --- a/example/example_3_ibbTransferSource/ibbClient.cpp +++ b/example/example_3_ibbTransferSource/ibbClient.cpp @@ -1,8 +1,9 @@ /*
- * Copyright (C) 2008-2009 QXmpp Developers
+ * Copyright (C) 2008-2010 QXmpp Developers
*
- * Author:
+ * Authors:
* Ian Reinhart Geiser
+ * Jeremy Lainé
*
* Source:
* http://code.google.com/p/qxmpp
@@ -22,64 +23,49 @@ */
-#include "ibbClient.h"
+#include <QDebug>
+
#include "QXmppMessage.h"
#include "QXmppUtils.h"
-#include "QXmppIbbTransferManager.h"
-#include <QBuffer>
-#include <qdebug.h>
+
+#include "ibbClient.h"
ibbClient::ibbClient(QObject *parent)
: QXmppClient(parent)
{
- m_buffer = new QBuffer(this);
- QByteArray bytes;
- for( int idx = 0; idx < 1000; idx++ )
- bytes += generateStanzaHash().toLatin1();
-
- m_buffer->setData( bytes );
- m_buffer->open(QIODevice::ReadOnly);
-
- connect( this, SIGNAL(connected()),
- this, SLOT(slotConnected()));
- connect( getIbbTransferManager(), SIGNAL(byteStreamCanceled(QString,QString)),
- this, SLOT( slotByteStreamCanceled(QString,QString)) );
- connect( getIbbTransferManager(), SIGNAL(byteStreamClosed(QString,QString)),
- this, SLOT( slotByteStreamClosed(QString,QString)) );
- connect( getIbbTransferManager(), SIGNAL( byteStreamOpened(QString)),
- this, SLOT( slotByteStreamOpened(QString)) );
- connect( getIbbTransferManager(), SIGNAL( byteStreamRequestReceived(QString,QString)),
- this, SLOT( slotByteStreamRequestReceived(QString,QString)) );
-}
-
-ibbClient::~ibbClient()
-{
-
+ bool check = connect( this, SIGNAL(connected()),
+ this, SLOT(slotConnected()) );
+ Q_ASSERT(check);
}
void ibbClient::slotConnected()
{
- getIbbTransferManager()->sendByteStreamRequest( generateStanzaHash(), "client@geiseri.com/QXmpp", m_buffer );
-}
+ QXmppTransferJob *job = getTransferManager().sendFile( "client@geiseri.com/QXmpp", "ibbClient.cpp" );
+ bool check = connect( job, SIGNAL(error(QXmppTransferJob::Error)),
+ this, SLOT(slotError(QXmppTransferJob::Error)) );
+ Q_ASSERT(check);
-void ibbClient::slotByteStreamRequestReceived( const QString &sid, const QString &remoteJid )
-{
- qDebug() << "Remote JID:" << remoteJid << " asked for transfer";
- getIbbTransferManager()->acceptByteStreamRequest( sid, m_buffer );
+ 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);
}
-void ibbClient::slotByteStreamClosed( const QString &sid , const QString &reason )
+void ibbClient::slotError(QXmppTransferJob::Error error)
{
- qDebug() << "Transmission done" << m_buffer->buffer();
+ qDebug() << "Transmission failed:" << error;
}
-void ibbClient::slotByteStreamCanceled( const QString &sid , const QString &reason )
+void ibbClient::slotFinished()
{
- qDebug() << "Transmission canceled" << reason;
+ qDebug() << "Transmission finished";
}
-void ibbClient::slotByteStreamOpened( const QString &sid )
+void ibbClient::slotProgress(qint64 done, qint64 total)
{
- qDebug() << "Bytestream opened";
+ qDebug() << "Transmission progress:" << done << "/" << total;
}
diff --git a/example/example_3_ibbTransferSource/ibbClient.h b/example/example_3_ibbTransferSource/ibbClient.h index 0a674d05..5029771a 100644 --- a/example/example_3_ibbTransferSource/ibbClient.h +++ b/example/example_3_ibbTransferSource/ibbClient.h @@ -26,8 +26,7 @@ #define IBBCLIENT_H
#include "QXmppClient.h"
-
-class QBuffer;
+#include "QXmppTransferManager.h"
class ibbClient : public QXmppClient
{
@@ -35,17 +34,12 @@ class ibbClient : public QXmppClient public:
ibbClient(QObject *parent = 0);
- ~ibbClient();
public slots:
void slotConnected();
- void slotByteStreamRequestReceived( const QString &sid, const QString &remoteJid );
- void slotByteStreamClosed( const QString &sid , const QString &reason );
- void slotByteStreamCanceled( const QString &sid , const QString &reason );
- void slotByteStreamOpened( const QString &sid );
-private:
- QBuffer *m_buffer;
-
+ void slotError(QXmppTransferJob::Error error);
+ void slotFinished();
+ void slotProgress(qint64 done, qint64 total);
};
#endif // IBBCLIENT_H
|
