1 | /* $Id: UIDownloader.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDownloader class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_networking_UIDownloader_h
|
---|
29 | #define FEQT_INCLUDED_SRC_networking_UIDownloader_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QUrl>
|
---|
36 | #include <QList>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 | #include "UINetworkCustomer.h"
|
---|
41 | #include "UINetworkDefs.h"
|
---|
42 |
|
---|
43 | /* Forward declarations: */
|
---|
44 | class QString;
|
---|
45 | class UINetworkReply;
|
---|
46 |
|
---|
47 | /** Downloader interface.
|
---|
48 | * UINetworkCustomer class extension which allows background http downloading. */
|
---|
49 | class SHARED_LIBRARY_STUFF UIDownloader : public UINetworkCustomer
|
---|
50 | {
|
---|
51 | Q_OBJECT;
|
---|
52 |
|
---|
53 | signals:
|
---|
54 |
|
---|
55 | /** Signals to start acknowledging. */
|
---|
56 | void sigToStartAcknowledging();
|
---|
57 | /** Signals to start downloading. */
|
---|
58 | void sigToStartDownloading();
|
---|
59 | /** Signals to start verifying. */
|
---|
60 | void sigToStartVerifying();
|
---|
61 |
|
---|
62 | /** Notifies listeners about progress change to @a iPercent. */
|
---|
63 | void sigProgressChange(ulong uPercent);
|
---|
64 | /** Notifies listeners about progress failed with @a strError. */
|
---|
65 | void sigProgressFailed(const QString &strError);
|
---|
66 | /** Notifies listeners about progress canceled. */
|
---|
67 | void sigProgressCanceled();
|
---|
68 | /** Notifies listeners about progress finished. */
|
---|
69 | void sigProgressFinished();
|
---|
70 |
|
---|
71 | public:
|
---|
72 |
|
---|
73 | /** Constructs downloader. */
|
---|
74 | UIDownloader();
|
---|
75 |
|
---|
76 | public slots:
|
---|
77 |
|
---|
78 | /** Starts the sequence. */
|
---|
79 | void start() { startDelayedAcknowledging(); }
|
---|
80 | /** Cancels the sequence. */
|
---|
81 | void cancel() { cancelNetworkRequest(); }
|
---|
82 |
|
---|
83 | protected slots:
|
---|
84 |
|
---|
85 | /** Performs acknowledging part. */
|
---|
86 | void sltStartAcknowledging();
|
---|
87 | /** Performs downloading part. */
|
---|
88 | void sltStartDownloading();
|
---|
89 | /** Performs verifying part. */
|
---|
90 | void sltStartVerifying();
|
---|
91 |
|
---|
92 | protected:
|
---|
93 |
|
---|
94 | /** Appends subsequent source to try to download from. */
|
---|
95 | void addSource(const QString &strSource) { m_sources << QUrl(strSource); }
|
---|
96 | /** Defines the only one source to try to download from. */
|
---|
97 | void setSource(const QString &strSource) { m_sources.clear(); addSource(strSource); }
|
---|
98 | /** Returns a list of sources to try to download from. */
|
---|
99 | const QList<QUrl> &sources() const { return m_sources; }
|
---|
100 | /** Returns a current source to try to download from. */
|
---|
101 | const QUrl &source() const { return m_source; }
|
---|
102 |
|
---|
103 | /** Defines the @a strTarget file-path used to save downloaded file to. */
|
---|
104 | void setTarget(const QString &strTarget) { m_strTarget = strTarget; }
|
---|
105 | /** Returns the target file-path used to save downloaded file to. */
|
---|
106 | const QString &target() const { return m_strTarget; }
|
---|
107 |
|
---|
108 | /** Defines the @a strPathSHA256SumsFile. */
|
---|
109 | void setPathSHA256SumsFile(const QString &strPathSHA256SumsFile) { m_strPathSHA256SumsFile = strPathSHA256SumsFile; }
|
---|
110 | /** Returns the SHA-256 sums file-path. */
|
---|
111 | QString pathSHA256SumsFile() const { return m_strPathSHA256SumsFile; }
|
---|
112 |
|
---|
113 | /** Returns description of the current network operation. */
|
---|
114 | virtual QString description() const RT_OVERRIDE;
|
---|
115 |
|
---|
116 | /** Handles network-reply progress for @a iReceived bytes of @a iTotal. */
|
---|
117 | virtual void processNetworkReplyProgress(qint64 iReceived, qint64 iTotal) RT_OVERRIDE;
|
---|
118 | /** Handles network-reply failed with specified @a strError. */
|
---|
119 | virtual void processNetworkReplyFailed(const QString &strError) RT_OVERRIDE;
|
---|
120 | /** Handles network-reply cancel request for @a pReply. */
|
---|
121 | virtual void processNetworkReplyCanceled(UINetworkReply *pReply) RT_OVERRIDE;
|
---|
122 | /** Handles network-reply finish for @a pReply. */
|
---|
123 | virtual void processNetworkReplyFinished(UINetworkReply *pReply) RT_OVERRIDE;
|
---|
124 |
|
---|
125 | /** Asks user for downloading confirmation for passed @a pReply. */
|
---|
126 | virtual bool askForDownloadingConfirmation(UINetworkReply *pReply) = 0;
|
---|
127 | /** Handles downloaded object for passed @a pReply. */
|
---|
128 | virtual void handleDownloadedObject(UINetworkReply *pReply) = 0;
|
---|
129 | /** Handles verified object for passed @a pReply. */
|
---|
130 | virtual void handleVerifiedObject(UINetworkReply *pReply) { Q_UNUSED(pReply); }
|
---|
131 |
|
---|
132 | private:
|
---|
133 |
|
---|
134 | /** UIDownloader states. */
|
---|
135 | enum UIDownloaderState
|
---|
136 | {
|
---|
137 | UIDownloaderState_Null,
|
---|
138 | UIDownloaderState_Acknowledging,
|
---|
139 | UIDownloaderState_Downloading,
|
---|
140 | UIDownloaderState_Verifying
|
---|
141 | };
|
---|
142 |
|
---|
143 | /** Starts delayed acknowledging. */
|
---|
144 | void startDelayedAcknowledging() { emit sigToStartAcknowledging(); }
|
---|
145 | /** Starts delayed downloading. */
|
---|
146 | void startDelayedDownloading() { emit sigToStartDownloading(); }
|
---|
147 | /** Starts delayed verifying. */
|
---|
148 | void startDelayedVerifying() { emit sigToStartVerifying(); }
|
---|
149 |
|
---|
150 | /** Handles acknowledging result. */
|
---|
151 | void handleAcknowledgingResult(UINetworkReply *pReply);
|
---|
152 | /** Handles downloading result. */
|
---|
153 | void handleDownloadingResult(UINetworkReply *pReply);
|
---|
154 | /** Handles verifying result. */
|
---|
155 | void handleVerifyingResult(UINetworkReply *pReply);
|
---|
156 |
|
---|
157 | /** Holds the downloader state. */
|
---|
158 | UIDownloaderState m_state;
|
---|
159 |
|
---|
160 | /** Holds the downloading sources. */
|
---|
161 | QList<QUrl> m_sources;
|
---|
162 | /** Holds the current downloading source. */
|
---|
163 | QUrl m_source;
|
---|
164 |
|
---|
165 | /** Holds the downloading target path. */
|
---|
166 | QString m_strTarget;
|
---|
167 |
|
---|
168 | /** Holds the SHA-256 sums file path. */
|
---|
169 | QString m_strPathSHA256SumsFile;
|
---|
170 | };
|
---|
171 |
|
---|
172 | #endif /* !FEQT_INCLUDED_SRC_networking_UIDownloader_h */
|
---|
173 |
|
---|