QXmpp  Version:0.9.3
QXmppTransferManager.h
00001 /*
00002  * Copyright (C) 2008-2014 The QXmpp developers
00003  *
00004  * Author:
00005  *  Jeremy Lainé
00006  *
00007  * Source:
00008  *  https://github.com/qxmpp-project/qxmpp
00009  *
00010  * This file is a part of QXmpp library.
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2.1 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  */
00023 
00024 #ifndef QXMPPTRANSFERMANAGER_H
00025 #define QXMPPTRANSFERMANAGER_H
00026 
00027 #include <QDateTime>
00028 #include <QSharedData>
00029 #include <QUrl>
00030 #include <QVariant>
00031 
00032 #include "QXmppClientExtension.h"
00033 
00034 class QTcpSocket;
00035 class QXmppByteStreamIq;
00036 class QXmppIbbCloseIq;
00037 class QXmppIbbDataIq;
00038 class QXmppIbbOpenIq;
00039 class QXmppIq;
00040 class QXmppStreamInitiationIq;
00041 class QXmppTransferFileInfoPrivate;
00042 class QXmppTransferJobPrivate;
00043 class QXmppTransferManager;
00044 class QXmppTransferManagerPrivate;
00045 
00046 class QXMPP_EXPORT QXmppTransferFileInfo
00047 {
00048 public:
00049     QXmppTransferFileInfo();
00050     QXmppTransferFileInfo(const QXmppTransferFileInfo &other);
00051     ~QXmppTransferFileInfo();
00052 
00053     QDateTime date() const;
00054     void setDate(const QDateTime &date);
00055 
00056     QByteArray hash() const;
00057     void setHash(const QByteArray &hash);
00058 
00059     QString name() const;
00060     void setName(const QString &name);
00061 
00062     QString description() const;
00063     void setDescription(const QString &description);
00064 
00065     qint64 size() const;
00066     void setSize(qint64 size);
00067 
00068     bool isNull() const;
00069     QXmppTransferFileInfo& operator=(const QXmppTransferFileInfo &other);
00070     bool operator==(const QXmppTransferFileInfo &other) const;
00071 
00073     void parse(const QDomElement &element);
00074     void toXml(QXmlStreamWriter *writer) const;
00076 
00077 private:
00078     QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
00079 };
00080 
00085 
00086 class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
00087 {
00088     Q_OBJECT
00089     Q_ENUMS(Direction Error State)
00090     Q_FLAGS(Method Methods)
00091     Q_PROPERTY(Direction direction READ direction CONSTANT)
00092     Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
00093     Q_PROPERTY(QString jid READ jid CONSTANT)
00094     Q_PROPERTY(Method method READ method CONSTANT)
00095     Q_PROPERTY(State state READ state NOTIFY stateChanged)
00096 
00097     Q_PROPERTY(QString fileName READ fileName CONSTANT)
00098     Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
00099 
00100 public:
00102     enum Direction
00103     {
00104         IncomingDirection, 
00105         OutgoingDirection  
00106     };
00107 
00109     enum Error
00110     {
00111         NoError = 0,      
00112         AbortError,       
00113         FileAccessError,  
00114         FileCorruptError, 
00115         ProtocolError     
00116     };
00117 
00119     enum Method
00120     {
00121         NoMethod = 0,     
00122         InBandMethod = 1, 
00123         SocksMethod = 2,  
00124         AnyMethod = 3     
00125     };
00126     Q_DECLARE_FLAGS(Methods, Method)
00127 
00128     
00129     enum State
00130     {
00131         OfferState = 0,    
00132         StartState = 1,    
00133         TransferState = 2, 
00134         FinishedState = 3  
00135     };
00136 
00137     ~QXmppTransferJob();
00138 
00139     QXmppTransferJob::Direction direction() const;
00140     QXmppTransferJob::Error error() const;
00141     QString jid() const;
00142     QXmppTransferJob::Method method() const;
00143     QString sid() const;
00144     qint64 speed() const;
00145     QXmppTransferJob::State state() const;
00146 
00147     // XEP-0096 : File transfer
00148     QXmppTransferFileInfo fileInfo() const;
00149     QUrl localFileUrl() const;
00150     void setLocalFileUrl(const QUrl &localFileUrl);
00151 
00153     QDateTime fileDate() const;
00154     QByteArray fileHash() const;
00155     QString fileName() const;
00156     qint64 fileSize() const;
00158 
00159 signals:
00162     void error(QXmppTransferJob::Error error);
00163 
00171     void finished();
00172 
00174     void localFileUrlChanged(const QUrl &localFileUrl);
00175 
00177     void progress(qint64 done, qint64 total);
00178 
00180     void stateChanged(QXmppTransferJob::State state);
00181 
00182 public slots:
00183     void abort();
00184     void accept(const QString &filePath);
00185     void accept(QIODevice *output);
00186 
00187 private slots:
00188     void _q_terminated();
00189 
00190 private:
00191     QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QXmppClient *client, QObject *parent);
00192     void setState(QXmppTransferJob::State state);
00193     void terminate(QXmppTransferJob::Error error);
00194 
00195     QXmppTransferJobPrivate *const d;
00196     friend class QXmppTransferManager;
00197     friend class QXmppTransferManagerPrivate;
00198     friend class QXmppTransferIncomingJob;
00199     friend class QXmppTransferOutgoingJob;
00200 };
00201 
00218 
00219 class QXMPP_EXPORT QXmppTransferManager : public QXmppClientExtension
00220 {
00221     Q_OBJECT
00222     Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
00223     Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
00224     Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
00225 
00226 public:
00227     QXmppTransferManager();
00228     ~QXmppTransferManager();
00229 
00230     QString proxy() const;
00231     void setProxy(const QString &proxyJid);
00232 
00233     bool proxyOnly() const;
00234     void setProxyOnly(bool proxyOnly);
00235 
00236     QXmppTransferJob::Methods supportedMethods() const;
00237     void setSupportedMethods(QXmppTransferJob::Methods methods);
00238 
00240     QStringList discoveryFeatures() const;
00241     bool handleStanza(const QDomElement &element);
00243 
00244 signals:
00249     void fileReceived(QXmppTransferJob *job);
00250 
00252     void jobStarted(QXmppTransferJob *job);
00253 
00257     void jobFinished(QXmppTransferJob *job);
00258 
00259 public slots:
00260     QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &description = QString());
00261     QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
00262 
00263 protected:
00265     void setClient(QXmppClient* client);
00267 
00268 private slots:
00269     void _q_iqReceived(const QXmppIq&);
00270     void _q_jobDestroyed(QObject *object);
00271     void _q_jobError(QXmppTransferJob::Error error);
00272     void _q_jobFinished();
00273     void _q_jobStateChanged(QXmppTransferJob::State state);
00274     void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
00275 
00276 private:
00277     QXmppTransferManagerPrivate *d;
00278 
00279     void byteStreamIqReceived(const QXmppByteStreamIq&);
00280     void byteStreamResponseReceived(const QXmppIq&);
00281     void byteStreamResultReceived(const QXmppByteStreamIq&);
00282     void byteStreamSetReceived(const QXmppByteStreamIq&);
00283     void ibbCloseIqReceived(const QXmppIbbCloseIq&);
00284     void ibbDataIqReceived(const QXmppIbbDataIq&);
00285     void ibbOpenIqReceived(const QXmppIbbOpenIq&);
00286     void ibbResponseReceived(const QXmppIq&);
00287     void streamInitiationIqReceived(const QXmppStreamInitiationIq&);
00288     void streamInitiationResultReceived(const QXmppStreamInitiationIq&);
00289     void streamInitiationSetReceived(const QXmppStreamInitiationIq&);
00290     void socksServerSendOffer(QXmppTransferJob *job);
00291 
00292     friend class QXmppTransferManagerPrivate;
00293 };
00294 
00295 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
00296 
00297 #endif
 All Classes Functions Enumerations Enumerator Properties