QXmpp  Version: 1.6.0
QXmppTransferManager.h
1 // SPDX-FileCopyrightText: 2010 Jeremy LainĂ© <jeremy.laine@m4x.org>
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 
5 #ifndef QXMPPTRANSFERMANAGER_H
6 #define QXMPPTRANSFERMANAGER_H
7 
8 #include "QXmppClientExtension.h"
9 
10 #include <QDateTime>
11 #include <QSharedData>
12 #include <QUrl>
13 #include <QVariant>
14 
15 class QTcpSocket;
16 class QXmppByteStreamIq;
17 class QXmppIbbCloseIq;
18 class QXmppIbbDataIq;
19 class QXmppIbbOpenIq;
20 class QXmppIq;
21 class QXmppStreamInitiationIq;
22 class QXmppTransferFileInfoPrivate;
23 class QXmppTransferJobPrivate;
25 class QXmppTransferManagerPrivate;
26 
27 class QXMPP_EXPORT QXmppTransferFileInfo
28 {
29 public:
33 
34  QDateTime date() const;
35  void setDate(const QDateTime &date);
36 
37  QByteArray hash() const;
38  void setHash(const QByteArray &hash);
39 
40  QString name() const;
41  void setName(const QString &name);
42 
43  QString description() const;
44  void setDescription(const QString &description);
45 
46  qint64 size() const;
47  void setSize(qint64 size);
48 
49  bool isNull() const;
51  bool operator==(const QXmppTransferFileInfo &other) const;
52 
54  void parse(const QDomElement &element);
55  void toXml(QXmlStreamWriter *writer) const;
57 
58 private:
59  QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
60 };
61 
62 class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
63 {
64  Q_OBJECT
65  Q_FLAGS(Method Methods)
67  Q_PROPERTY(Direction direction READ direction CONSTANT)
69  Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
71  Q_PROPERTY(QString jid READ jid CONSTANT)
73  Q_PROPERTY(Method method READ method CONSTANT)
75  Q_PROPERTY(State state READ state NOTIFY stateChanged)
76 
77 
78  Q_PROPERTY(QString fileName READ fileName CONSTANT)
80  Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
81 
82 public:
84  enum Direction {
86  OutgoingDirection
87  };
88  Q_ENUM(Direction)
89 
90 
91  enum Error {
92  NoError = 0,
96  ProtocolError
97  };
98  Q_ENUM(Error)
99 
100 
101  enum Method {
102  NoMethod = 0,
103  InBandMethod = 1,
104  SocksMethod = 2,
105  AnyMethod = 3
106  };
107  Q_ENUM(Method)
108  Q_DECLARE_FLAGS(Methods, Method)
109 
110 
111  enum State {
112  OfferState = 0,
113  StartState = 1,
114  TransferState = 2,
115  FinishedState = 3
116  };
117  Q_ENUM(State)
118 
119  ~QXmppTransferJob() override;
120 
121  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
123  QXmppTransferJob::Direction direction() const;
125  QString jid() const;
127  QXmppTransferJob::Method method() const;
129  QXmppTransferJob::State state() const;
130 
131  QXmppTransferJob::Error error() const;
132  QString sid() const;
133  qint64 speed() const;
134 
135  // XEP-0096 : File transfer
136  QXmppTransferFileInfo fileInfo() const;
137  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
139  QUrl localFileUrl() const;
140  void setLocalFileUrl(const QUrl &localFileUrl);
141 
143  QDateTime fileDate() const;
144  QByteArray fileHash() const;
145  QString fileName() const;
146  qint64 fileSize() const;
148 
149 Q_SIGNALS:
153 
161  void finished();
162 
164  void localFileUrlChanged(const QUrl &localFileUrl);
165 
167  void progress(qint64 done, qint64 total);
168 
171 
172 public Q_SLOTS:
173  void abort();
174  void accept(const QString &filePath);
175  void accept(QIODevice *output);
176 
177 private Q_SLOTS:
178  void _q_terminated();
179 
180 private:
181  QXmppTransferJob(const QString &jid, QXmppTransferJob::Direction direction, QXmppClient *client, QObject *parent);
182  void setState(QXmppTransferJob::State state);
183  void terminate(QXmppTransferJob::Error error);
184 
185  const std::unique_ptr<QXmppTransferJobPrivate> d;
186  friend class QXmppTransferManager;
187  friend class QXmppTransferManagerPrivate;
188  friend class QXmppTransferIncomingJob;
189  friend class QXmppTransferOutgoingJob;
190 };
191 
192 class QXMPP_EXPORT QXmppTransferManager : public QXmppClientExtension
193 {
194  Q_OBJECT
195 
197  Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
199  Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
201  Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
202 
203 public:
205  ~QXmppTransferManager() override;
206 
207  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
209  QString proxy() const;
210  void setProxy(const QString &proxyJid);
211 
212  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
215  bool proxyOnly() const;
216  void setProxyOnly(bool proxyOnly);
217 
218  // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
222  QXmppTransferJob::Methods supportedMethods() const;
223  void setSupportedMethods(QXmppTransferJob::Methods methods);
224 
226  QStringList discoveryFeatures() const override;
227  bool handleStanza(const QDomElement &element) override;
229 
230 Q_SIGNALS:
236 
239 
244 
245 public Q_SLOTS:
246  QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &description = QString());
247  QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
248 
249 protected:
251  void setClient(QXmppClient *client) override;
253 
254 private Q_SLOTS:
255  void _q_iqReceived(const QXmppIq &);
256  void _q_jobDestroyed(QObject *object);
257  void _q_jobError(QXmppTransferJob::Error error);
258  void _q_jobFinished();
259  void _q_jobStateChanged(QXmppTransferJob::State state);
260  void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
261 
262 private:
263  const std::unique_ptr<QXmppTransferManagerPrivate> d;
264 
265  void byteStreamIqReceived(const QXmppByteStreamIq &);
266  void byteStreamResponseReceived(const QXmppIq &);
267  void byteStreamResultReceived(const QXmppByteStreamIq &);
268  void byteStreamSetReceived(const QXmppByteStreamIq &);
269  void ibbCloseIqReceived(const QXmppIbbCloseIq &);
270  void ibbDataIqReceived(const QXmppIbbDataIq &);
271  void ibbOpenIqReceived(const QXmppIbbOpenIq &);
272  void ibbResponseReceived(const QXmppIq &);
273  void streamInitiationIqReceived(const QXmppStreamInitiationIq &);
274  void streamInitiationResultReceived(const QXmppStreamInitiationIq &);
275  void streamInitiationSetReceived(const QXmppStreamInitiationIq &);
276  void socksServerSendOffer(QXmppTransferJob *job);
277 
278  friend class QXmppTransferManagerPrivate;
279 };
280 
281 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
282 
283 #endif
Definition: QXmppByteStreamIq.h:13
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:33
The QXmppClient class is the main class for using QXmpp.
Definition: QXmppClient.h:84
Definition: QXmppIbbIq.h:36
Definition: QXmppIbbIq.h:12
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:23
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:105
Definition: QXmppTransferManager.h:28
QXmppTransferFileInfo(const QXmppTransferFileInfo &other)
Default copy-constructor.
QXmppTransferFileInfo & operator=(const QXmppTransferFileInfo &other)
Default assignment operator.
Definition: QXmppTransferManager.h:63
void stateChanged(QXmppTransferJob::State state)
This signal is emitted when the transfer job changes state.
void progress(qint64 done, qint64 total)
This signal is emitted to indicate the progress of this transfer job.
void error(QXmppTransferJob::Error error)
void localFileUrlChanged(const QUrl &localFileUrl)
This signal is emitted when the local file URL changes.
Method
This enum is used to describe a transfer method.
Definition: QXmppTransferManager.h:101
Direction
This enum is used to describe the direction of a transfer job.
Definition: QXmppTransferManager.h:84
@ IncomingDirection
The file is being received.
Definition: QXmppTransferManager.h:85
State
This enum is used to describe the state of a transfer job.
Definition: QXmppTransferManager.h:111
Error
This enum is used to describe the type of error encountered by a transfer job.
Definition: QXmppTransferManager.h:91
@ AbortError
The file transfer was aborted.
Definition: QXmppTransferManager.h:93
@ FileAccessError
An error was encountered trying to access a local file.
Definition: QXmppTransferManager.h:94
@ FileCorruptError
The file is corrupt: the file size or hash do not match.
Definition: QXmppTransferManager.h:95
Definition: QXmppTransferManager.h:193
void fileReceived(QXmppTransferJob *job)
void jobStarted(QXmppTransferJob *job)
This signal is emitted whenever a transfer job is started.
void jobFinished(QXmppTransferJob *job)