QXmppTransferManager.h

    00001 /*
    00002  * Copyright (C) 2008-2011 The QXmpp developers
    00003  *
    00004  * Author:
    00005  *  Jeremy Lainé
    00006  *
    00007  * Source:
    00008  *  http://code.google.com/p/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 <QUrl>
    00029 #include <QVariant>
    00030
    00031 #include "QXmppClientExtension.h"
    00032 #include "QXmppIq.h"
    00033 #include "QXmppByteStreamIq.h"
    00034
    00035 class QTcpSocket;
    00036 class QXmppByteStreamIq;
    00037 class QXmppIbbCloseIq;
    00038 class QXmppIbbDataIq;
    00039 class QXmppIbbOpenIq;
    00040 class QXmppSocksClient;
    00041 class QXmppSocksServer;
    00042 class QXmppStreamInitiationIq;
    00043 class QXmppTransferJobPrivate;
    00044
    00045 class QXmppTransferFileInfo
    00046 {
    00047 public:
    00048     QXmppTransferFileInfo();
    00049
    00050     QDateTime date() const;
    00051     void setDate(const QDateTime &date);
    00052
    00053     QByteArray hash() const;
    00054     void setHash(const QByteArray &hash);
    00055
    00056     QString name() const;
    00057     void setName(const QString &name);
    00058
    00059     qint64 size() const;
    00060     void setSize(qint64 size);
    00061
    00062     bool operator==(const QXmppTransferFileInfo &other) const;
    00063
    00064 private:
    00065     QDateTime m_date;
    00066     QByteArray m_hash;
    00067     QString m_name;
    00068     qint64 m_size;
    00069 };
    00070
    00075
    00076 class QXmppTransferJob : public QXmppLoggable
    00077 {
    00078     Q_OBJECT
    00079     Q_ENUMS(Direction Error State)
    00080     Q_FLAGS(Method Methods)
    00081     Q_PROPERTY(Direction direction READ direction CONSTANT)
    00082     Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
    00083     Q_PROPERTY(QString jid READ jid CONSTANT)
    00084     Q_PROPERTY(Method method READ method CONSTANT)
    00085     Q_PROPERTY(State state READ state NOTIFY stateChanged)
    00086
    00087     Q_PROPERTY(QString fileName READ fileName CONSTANT)
    00088     Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
    00089
    00090 public:
    00092     enum Direction
    00093     {
    00094         IncomingDirection,
    00095         OutgoingDirection,
    00096     };
    00097
    00099     enum Error
    00100     {
    00101         NoError = 0,
    00102         AbortError,
    00103         FileAccessError,
    00104         FileCorruptError,
    00105         ProtocolError,
    00106     };
    00107
    00109     enum Method
    00110     {
    00111         NoMethod = 0,
    00112         InBandMethod = 1,
    00113         SocksMethod = 2,
    00114         AnyMethod = 3,
    00115     };
    00116     Q_DECLARE_FLAGS(Methods, Method)
    00117
    00118
    00119     enum State
    00120     {
    00121         OfferState = 0,
    00122         StartState = 1,
    00123         TransferState = 2,
    00124         FinishedState = 3,
    00125     };
    00126
    00127     ~QXmppTransferJob();
    00128
    00129     QXmppTransferJob::Direction direction() const;
    00130     QXmppTransferJob::Error error() const;
    00131     QString jid() const;
    00132     QXmppTransferJob::Method method() const;
    00133     QString sid() const;
    00134     qint64 speed() const;
    00135     QXmppTransferJob::State state() const;
    00136
    00137     // XEP-0096 : File transfer
    00138     QXmppTransferFileInfo fileInfo() const;
    00139     QUrl localFileUrl() const;
    00140     void setLocalFileUrl(const QUrl &localFileUrl);
    00141
    00143     QDateTime fileDate() const;
    00144     QByteArray fileHash() const;
    00145     QString fileName() const;
    00146     qint64 fileSize() const;
    00148
    00149 signals:
    00152     void error(QXmppTransferJob::Error error);
    00153
    00161     void finished();
    00162
    00164     void localFileUrlChanged(const QUrl &localFileUrl);
    00165
    00167     void progress(qint64 done, qint64 total);
    00168
    00170     void stateChanged(QXmppTransferJob::State state);
    00171
    00172 public slots:
    00173     void abort();
    00174     void accept(const QString &filePath);
    00175     void accept(QIODevice *output);
    00176
    00177 private slots:
    00178     void _q_disconnected();
    00179     void _q_receiveData();
    00180     void _q_sendData();
    00181     void _q_terminated();
    00182
    00183 private:
    00184     QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QObject *parent);
    00185     void checkData();
    00186     void setState(QXmppTransferJob::State state);
    00187     void terminate(QXmppTransferJob::Error error);
    00188     bool writeData(const QByteArray &data);
    00189
    00190     QXmppTransferJobPrivate *const d;
    00191     friend class QXmppTransferManager;
    00192 };
    00193
    00210
    00211 class QXmppTransferManager : public QXmppClientExtension
    00212 {
    00213     Q_OBJECT
    00214     Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
    00215     Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
    00216     Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
    00217
    00218 public:
    00219     QXmppTransferManager();
    00220
    00221     QString proxy() const;
    00222     void setProxy(const QString &proxyJid);
    00223
    00224     bool proxyOnly() const;
    00225     void setProxyOnly(bool proxyOnly);
    00226
    00227     QXmppTransferJob::Methods supportedMethods() const;
    00228     void setSupportedMethods(QXmppTransferJob::Methods methods);
    00229
    00231     QStringList discoveryFeatures() const;
    00232     bool handleStanza(const QDomElement &element);
    00234
    00235 signals:
    00240     void fileReceived(QXmppTransferJob *job);
    00241
    00243     void jobStarted(QXmppTransferJob *job);
    00244
    00248     void jobFinished(QXmppTransferJob *job);
    00249
    00250 public slots:
    00251     QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &sid = QString());
    00252     QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
    00253
    00254 protected:
    00256     void setClient(QXmppClient* client);
    00258
    00259 private slots:
    00260     void _q_iqReceived(const QXmppIq&);
    00261     void _q_jobDestroyed(QObject *object);
    00262     void _q_jobError(QXmppTransferJob::Error error);
    00263     void _q_jobFinished();
    00264     void _q_jobStateChanged(QXmppTransferJob::State state);
    00265     void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
    00266
    00267 private:
    00268     QXmppTransferJob *getJobByRequestId(QXmppTransferJob::Direction direction, const QString &jid, const QString &id);
    00269     QXmppTransferJob *getJobBySid(QXmppTransferJob::Direction, const QString &jid, const QString &sid);
    00270     void byteStreamIqReceived(const QXmppByteStreamIq&);
    00271     void byteStreamResponseReceived(const QXmppIq&);
    00272     void byteStreamResultReceived(const QXmppByteStreamIq&);
    00273     void byteStreamSetReceived(const QXmppByteStreamIq&);
    00274     void ibbCloseIqReceived(const QXmppIbbCloseIq&);
    00275     void ibbDataIqReceived(const QXmppIbbDataIq&);
    00276     void ibbOpenIqReceived(const QXmppIbbOpenIq&);
    00277     void ibbResponseReceived(const QXmppIq&);
    00278     void streamInitiationIqReceived(const QXmppStreamInitiationIq&);
    00279     void streamInitiationResultReceived(const QXmppStreamInitiationIq&);
    00280     void streamInitiationSetReceived(const QXmppStreamInitiationIq&);
    00281     void socksServerSendOffer(QXmppTransferJob *job);
    00282
    00283     int m_ibbBlockSize;
    00284     QList<QXmppTransferJob*> m_jobs;
    00285     QString m_proxy;
    00286     bool m_proxyOnly;
    00287     QXmppSocksServer *m_socksServer;
    00288     QXmppTransferJob::Methods m_supportedMethods;
    00289 };
    00290
    00291 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
    00292
    00293 #endif

All Classes Functions Enumerations Enumerator Properties