Debian Codegraph @

src/assets/downloader/tasking/networkquery.h

raw
1 // Copyright (C) 2024 Jarek Kobus
2 // Copyright (C) 2024 The Qt Company Ltd.
3 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5 #ifndef TASKING_NETWORKQUERY_H
6 #define TASKING_NETWORKQUERY_H
7
8 //
9 // W A R N I N G
10 // -------------
11 //
12 // This file is not part of the Qt API. It exists purely as an
13 // implementation detail. This header file may change from version to
14 // version without notice, or even be removed.
15 //
16 // We mean it.
17 //
18
19 #include "tasking_global.h"
20
21 #include "tasktree.h"
22
23 #include <QtNetwork/QNetworkReply>
24 #include <QtNetwork/QNetworkRequest>
25
26 #include <memory>
27
28 QT_BEGIN_NAMESPACE
29 class QNetworkAccessManager;
30
31 namespace Tasking {
32
33 // This class introduces the dependency to Qt::Network, otherwise Tasking namespace
34 // is independent on Qt::Network.
35 // Possibly, it could be placed inside Qt::Network library, as a wrapper around QNetworkReply.
36
37 enum class NetworkOperation { Get, Put, Post, Delete };
38
39 class TASKING_EXPORT NetworkQuery final : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 ~NetworkQuery();
45 void setRequest(const QNetworkRequest &request) { m_request = request; }
46 void setOperation(NetworkOperation operation) { m_operation = operation; }
47 void setWriteData(const QByteArray &data) { m_writeData = data; }
48 void setNetworkAccessManager(QNetworkAccessManager *manager) { m_manager = manager; }
49 QNetworkReply *reply() const { return m_reply.get(); }
50 void start();
51
52 Q_SIGNALS:
53 void started();
54 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
55 #if QT_CONFIG(ssl)
56 void sslErrors(const QList<QSslError> &errors);
57 #endif
58 void done(DoneResult result);
59
60 private:
61 QNetworkRequest m_request;
62 NetworkOperation m_operation = NetworkOperation::Get;
63 QByteArray m_writeData; // Used by Put and Post
64 QNetworkAccessManager *m_manager = nullptr;
65 std::unique_ptr<QNetworkReply> m_reply;
66 };
67
68 using NetworkQueryTask = SimpleCustomTask<NetworkQuery>;
69
70 } // namespace Tasking
71
72 QT_END_NAMESPACE
73
74 #endif // TASKING_NETWORKQUERY_H