QXmpp  Version:0.4.91
 All Classes Functions Enumerations Enumerator Properties Groups
QXmppTransferManager.h
1 /*
2  * Copyright (C) 2008-2011 The QXmpp developers
3  *
4  * Author:
5  * Jeremy LainĂ©
6  *
7  * Source:
8  * http://code.google.com/p/qxmpp
9  *
10  * This file is a part of QXmpp library.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  */
23 
24 #ifndef QXMPPTRANSFERMANAGER_H
25 #define QXMPPTRANSFERMANAGER_H
26 
27 #include <QDateTime>
28 #include <QSharedData>
29 #include <QUrl>
30 #include <QVariant>
31 
32 #include "QXmppClientExtension.h"
33 
34 class QTcpSocket;
35 class QXmppByteStreamIq;
36 class QXmppIbbCloseIq;
37 class QXmppIbbDataIq;
38 class QXmppIbbOpenIq;
39 class QXmppIq;
40 class QXmppStreamInitiationIq;
41 class QXmppTransferFileInfoPrivate;
42 class QXmppTransferJobPrivate;
44 class QXmppTransferManagerPrivate;
45 
46 class QXMPP_EXPORT QXmppTransferFileInfo
47 {
48 public:
49  QXmppTransferFileInfo();
50  QXmppTransferFileInfo(const QXmppTransferFileInfo &other);
51  ~QXmppTransferFileInfo();
52 
53  QDateTime date() const;
54  void setDate(const QDateTime &date);
55 
56  QByteArray hash() const;
57  void setHash(const QByteArray &hash);
58 
59  QString name() const;
60  void setName(const QString &name);
61 
62  qint64 size() const;
63  void setSize(qint64 size);
64 
65  QXmppTransferFileInfo& operator=(const QXmppTransferFileInfo &other);
66  bool operator==(const QXmppTransferFileInfo &other) const;
67 
68 private:
69  QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
70 };
71 
76 
77 class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
78 {
79  Q_OBJECT
80  Q_ENUMS(Direction Error State)
81  Q_FLAGS(Method Methods)
82  Q_PROPERTY(Direction direction READ direction CONSTANT)
83  Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
84  Q_PROPERTY(QString jid READ jid CONSTANT)
85  Q_PROPERTY(Method method READ method CONSTANT)
86  Q_PROPERTY(State state READ state NOTIFY stateChanged)
87 
88  Q_PROPERTY(QString fileName READ fileName CONSTANT)
89  Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
90 
91 public:
93  enum Direction
94  {
97  };
98 
100  enum Error
101  {
102  NoError = 0,
107  };
108 
110  enum Method
111  {
112  NoMethod = 0,
113  InBandMethod = 1,
114  SocksMethod = 2,
115  AnyMethod = 3,
116  };
117  Q_DECLARE_FLAGS(Methods, Method)
118 
119 
120  enum State
121  {
122  OfferState = 0,
123  StartState = 1,
124  TransferState = 2,
125  FinishedState = 3,
126  };
127 
128  ~QXmppTransferJob();
129 
130  QXmppTransferJob::Direction direction() const;
131  QXmppTransferJob::Error error() const;
132  QString jid() const;
133  QXmppTransferJob::Method method() const;
134  QString sid() const;
135  qint64 speed() const;
136  QXmppTransferJob::State state() const;
137 
138  // XEP-0096 : File transfer
139  QXmppTransferFileInfo fileInfo() const;
140  QUrl localFileUrl() const;
141  void setLocalFileUrl(const QUrl &localFileUrl);
142 
144  QDateTime fileDate() const;
145  QByteArray fileHash() const;
146  QString fileName() const;
147  qint64 fileSize() const;
149 
150 signals:
153  void error(QXmppTransferJob::Error error);
154 
162  void finished();
163 
165  void localFileUrlChanged(const QUrl &localFileUrl);
166 
168  void progress(qint64 done, qint64 total);
169 
171  void stateChanged(QXmppTransferJob::State state);
172 
173 public slots:
174  void abort();
175  void accept(const QString &filePath);
176  void accept(QIODevice *output);
177 
178 private slots:
179  void _q_terminated();
180 
181 private:
182  QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QXmppClient *client, QObject *parent);
183  void setState(QXmppTransferJob::State state);
184  void terminate(QXmppTransferJob::Error error);
185 
186  QXmppTransferJobPrivate *const d;
187  friend class QXmppTransferManager;
188  friend class QXmppTransferManagerPrivate;
189  friend class QXmppTransferIncomingJob;
190  friend class QXmppTransferOutgoingJob;
191 };
192 
209 
210 class QXMPP_EXPORT QXmppTransferManager : public QXmppClientExtension
211 {
212  Q_OBJECT
213  Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
214  Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
215  Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
216 
217 public:
219  ~QXmppTransferManager();
220 
221  QString proxy() const;
222  void setProxy(const QString &proxyJid);
223 
224  bool proxyOnly() const;
225  void setProxyOnly(bool proxyOnly);
226 
227  QXmppTransferJob::Methods supportedMethods() const;
228  void setSupportedMethods(QXmppTransferJob::Methods methods);
229 
231  QStringList discoveryFeatures() const;
232  bool handleStanza(const QDomElement &element);
234 
235 signals:
240  void fileReceived(QXmppTransferJob *job);
241 
243  void jobStarted(QXmppTransferJob *job);
244 
248  void jobFinished(QXmppTransferJob *job);
249 
250 public slots:
251  QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &sid = QString());
252  QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
253 
254 protected:
256  void setClient(QXmppClient* client);
258 
259 private slots:
260  void _q_iqReceived(const QXmppIq&);
261  void _q_jobDestroyed(QObject *object);
262  void _q_jobError(QXmppTransferJob::Error error);
263  void _q_jobFinished();
264  void _q_jobStateChanged(QXmppTransferJob::State state);
265  void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
266 
267 private:
268  QXmppTransferManagerPrivate *d;
269 
270  void byteStreamIqReceived(const QXmppByteStreamIq&);
271  void byteStreamResponseReceived(const QXmppIq&);
272  void byteStreamResultReceived(const QXmppByteStreamIq&);
273  void byteStreamSetReceived(const QXmppByteStreamIq&);
274  void ibbCloseIqReceived(const QXmppIbbCloseIq&);
275  void ibbDataIqReceived(const QXmppIbbDataIq&);
276  void ibbOpenIqReceived(const QXmppIbbOpenIq&);
277  void ibbResponseReceived(const QXmppIq&);
278  void streamInitiationIqReceived(const QXmppStreamInitiationIq&);
279  void streamInitiationResultReceived(const QXmppStreamInitiationIq&);
280  void streamInitiationSetReceived(const QXmppStreamInitiationIq&);
281  void socksServerSendOffer(QXmppTransferJob *job);
282 
283  friend class QXmppTransferManagerPrivate;
284 };
285 
286 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
287 
288 #endif