1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef DOWNLOADUTIL_H |
6 | #define DOWNLOADUTIL_H |
7 | |
8 | #include <QObject> |
9 | #include <memory> |
10 | #include <QFile> |
11 | |
12 | class DownloadUtilPrivate; |
13 | class DownloadUtil : public QObject |
14 | { |
15 | Q_OBJECT |
16 | public: |
17 | explicit DownloadUtil(const QString &srcUrl, |
18 | const QString &dstPath, |
19 | const QString &fileName, |
20 | QObject *parent = nullptr); |
21 | virtual ~DownloadUtil(); |
22 | |
23 | bool start(); |
24 | void cancel(); |
25 | |
26 | signals: |
27 | void sigProgress(qint64 bytesRead, qint64 totalBytes); |
28 | void sigFinished(); |
29 | void sigFailed(); |
30 | |
31 | private: |
32 | void startRequest(const QUrl &url); |
33 | std::unique_ptr<QFile> openFileForWrite(const QString& fileName); |
34 | |
35 | private: |
36 | DownloadUtilPrivate *const d; |
37 | |
38 | |
39 | }; |
40 | |
41 | #endif // DOWNLOADUTIL_H |
42 | |
43 |