QXmpp Version: 1.12.0
Loading...
Searching...
No Matches
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
15class QTcpSocket;
17class QXmppIbbCloseIq;
18class QXmppIbbDataIq;
19class QXmppIbbOpenIq;
20class QXmppIq;
21class QXmppStreamInitiationIq;
22class QXmppTransferFileInfoPrivate;
23class QXmppTransferJobPrivate;
25class QXmppTransferManagerPrivate;
26
27class QXMPP_EXPORT QXmppTransferFileInfo
28{
29public:
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 static constexpr std::tuple XmlTag = { u"file", QXmpp::Private::ns_stream_initiation_file_transfer };
55 void parse(const QDomElement &element);
56 void toXml(QXmlStreamWriter *writer) const;
58
59private:
60 QSharedDataPointer<QXmppTransferFileInfoPrivate> d;
61};
62
63class QXMPP_EXPORT QXmppTransferJob : public QXmppLoggable
64{
65 Q_OBJECT
66 Q_FLAGS(Method Methods)
68 Q_PROPERTY(Direction direction READ direction CONSTANT)
70 Q_PROPERTY(QUrl localFileUrl READ localFileUrl WRITE setLocalFileUrl NOTIFY localFileUrlChanged)
72 Q_PROPERTY(QString jid READ jid CONSTANT)
74 Q_PROPERTY(Method method READ method CONSTANT)
76 Q_PROPERTY(State state READ state NOTIFY stateChanged)
77
79 Q_PROPERTY(QString fileName READ fileName CONSTANT)
81 Q_PROPERTY(qint64 fileSize READ fileSize CONSTANT)
82
83public:
85 enum Direction {
87 OutgoingDirection
88 };
89 Q_ENUM(Direction)
90
91
92 enum Error {
93 NoError = 0,
97 ProtocolError
98 };
99 Q_ENUM(Error)
100
101
102 enum Method {
103 NoMethod = 0,
104 InBandMethod = 1,
105 SocksMethod = 2,
106 AnyMethod = 3
107 };
108 Q_ENUM(Method)
109 Q_DECLARE_FLAGS(Methods, Method)
110
111
112 enum State {
113 OfferState = 0,
114 StartState = 1,
115 TransferState = 2,
116 FinishedState = 3
117 };
118 Q_ENUM(State)
119
120 ~QXmppTransferJob() override;
121
122 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
124 QXmppTransferJob::Direction direction() const;
126 QString jid() const;
128 QXmppTransferJob::Method method() const;
130 QXmppTransferJob::State state() const;
131
132 QXmppTransferJob::Error error() const;
133 QString sid() const;
134 qint64 speed() const;
135
136 // XEP-0096 : File transfer
137 QXmppTransferFileInfo fileInfo() const;
138 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
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
150Q_SIGNALS:
154
162 void finished();
163
165 void localFileUrlChanged(const QUrl &localFileUrl);
166
168 void progress(qint64 done, qint64 total);
169
172
173public Q_SLOTS:
174 void abort();
175 void accept(const QString &filePath);
176 void accept(QIODevice *output);
177
178private Q_SLOTS:
179 void _q_terminated();
180
181private:
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 const std::unique_ptr<QXmppTransferJobPrivate> d;
187 friend class QXmppTransferManager;
188 friend class QXmppTransferManagerPrivate;
189 friend class QXmppTransferIncomingJob;
190 friend class QXmppTransferOutgoingJob;
191};
192
194{
195 Q_OBJECT
196
198 Q_PROPERTY(QString proxy READ proxy WRITE setProxy)
200 Q_PROPERTY(bool proxyOnly READ proxyOnly WRITE setProxyOnly)
202 Q_PROPERTY(QXmppTransferJob::Methods supportedMethods READ supportedMethods WRITE setSupportedMethods)
203
204public:
206 ~QXmppTransferManager() override;
207
208 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
210 QString proxy() const;
211 void setProxy(const QString &proxyJid);
212
213 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
216 bool proxyOnly() const;
217 void setProxyOnly(bool proxyOnly);
218
219 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
223 QXmppTransferJob::Methods supportedMethods() const;
224 void setSupportedMethods(QXmppTransferJob::Methods methods);
225
227 QStringList discoveryFeatures() const override;
228 bool handleStanza(const QDomElement &element) override;
230
231Q_SIGNALS:
236 void fileReceived(QXmppTransferJob *job);
237
239 void jobStarted(QXmppTransferJob *job);
240
244 void jobFinished(QXmppTransferJob *job);
245
246public Q_SLOTS:
247 QXmppTransferJob *sendFile(const QString &jid, const QString &filePath, const QString &description = QString());
248 QXmppTransferJob *sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid = QString());
249
250protected:
252 void onRegistered(QXmppClient *client) override;
253 void onUnregistered(QXmppClient *client) override;
255
256private Q_SLOTS:
257 void _q_iqReceived(const QXmppIq &);
258 void _q_jobDestroyed(QObject *object);
259 void _q_jobError(QXmppTransferJob::Error error);
260 void _q_jobFinished();
261 void _q_jobStateChanged(QXmppTransferJob::State state);
262 void _q_socksServerConnected(QTcpSocket *socket, const QString &hostName, quint16 port);
263
264private:
265 const std::unique_ptr<QXmppTransferManagerPrivate> d;
266
267 void byteStreamIqReceived(const QXmppByteStreamIq &);
268 void byteStreamResponseReceived(const QXmppIq &);
269 void byteStreamResultReceived(const QXmppByteStreamIq &);
270 void byteStreamSetReceived(const QXmppByteStreamIq &);
271 void ibbCloseIqReceived(const QXmppIbbCloseIq &);
272 void ibbDataIqReceived(const QXmppIbbDataIq &);
273 void ibbOpenIqReceived(const QXmppIbbOpenIq &);
274 void ibbResponseReceived(const QXmppIq &);
275 void streamInitiationIqReceived(const QXmppStreamInitiationIq &);
276 void streamInitiationResultReceived(const QXmppStreamInitiationIq &);
277 void streamInitiationSetReceived(const QXmppStreamInitiationIq &);
278 void socksServerSendOffer(QXmppTransferJob *job);
279
280 friend class QXmppTransferManagerPrivate;
281};
282
283Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppTransferJob::Methods)
284
285#endif
Definition QXmppByteStreamIq.h:14
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:32
Main class for starting and managing connections to XMPP servers.
Definition QXmppClient.h:62
Definition QXmppIbbIq.h:38
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:110
Definition QXmppTransferManager.h:28
QXmppTransferFileInfo(const QXmppTransferFileInfo &other)
Default copy-constructor.
QXmppTransferFileInfo & operator=(const QXmppTransferFileInfo &other)
Default assignment operator.
Definition QXmppTransferManager.h:64
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:102
Direction
This enum is used to describe the direction of a transfer job.
Definition QXmppTransferManager.h:85
@ IncomingDirection
The file is being received.
Definition QXmppTransferManager.h:86
State
This enum is used to describe the state of a transfer job.
Definition QXmppTransferManager.h:112
Error
This enum is used to describe the type of error encountered by a transfer job.
Definition QXmppTransferManager.h:92
@ AbortError
The file transfer was aborted.
Definition QXmppTransferManager.h:94
@ FileAccessError
An error was encountered trying to access a local file.
Definition QXmppTransferManager.h:95
@ FileCorruptError
The file is corrupt: the file size or hash do not match.
Definition QXmppTransferManager.h:96
Definition QXmppTransferManager.h:194