VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networking/UIDownloader.cpp@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: UIDownloader.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDownloader class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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/* GUI includes: */
29#include "UICommon.h"
30#include "VBoxUtils.h"
31#include "UIDownloader.h"
32#include "UIMessageCenter.h"
33#include "UINetworkReply.h"
34
35
36UIDownloader::UIDownloader()
37 : m_state(UIDownloaderState_Null)
38{
39 /* Connect async listeners for our own commands: */
40 connect(this, &UIDownloader::sigToStartAcknowledging, this, &UIDownloader::sltStartAcknowledging, Qt::QueuedConnection);
41 connect(this, &UIDownloader::sigToStartDownloading, this, &UIDownloader::sltStartDownloading, Qt::QueuedConnection);
42 connect(this, &UIDownloader::sigToStartVerifying, this, &UIDownloader::sltStartVerifying, Qt::QueuedConnection);
43}
44
45void UIDownloader::sltStartAcknowledging()
46{
47 /* Set state to acknowledging: */
48 m_state = UIDownloaderState_Acknowledging;
49
50 /* Send HEAD requests: */
51 createNetworkRequest(UINetworkRequestType_HEAD, m_sources);
52}
53
54void UIDownloader::sltStartDownloading()
55{
56 /* Set state to downloading: */
57 m_state = UIDownloaderState_Downloading;
58
59 /* Send GET request: */
60 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_source, m_strTarget);
61}
62
63void UIDownloader::sltStartVerifying()
64{
65 /* Set state to verifying: */
66 m_state = UIDownloaderState_Verifying;
67
68 /* Send GET request: */
69 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_strPathSHA256SumsFile);
70}
71
72QString UIDownloader::description() const
73{
74 /* Look for known state: */
75 switch (m_state)
76 {
77 case UIDownloaderState_Acknowledging: return tr("Looking for %1...");
78 case UIDownloaderState_Downloading: return tr("Downloading %1...");
79 case UIDownloaderState_Verifying: return tr("Verifying %1...");
80 default: break;
81 }
82 /* Return null-string by default: */
83 return QString();
84}
85
86void UIDownloader::processNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
87{
88 /* Notify listeners: */
89 emit sigProgressChange((double)iReceived / iTotal * 100);
90}
91
92void UIDownloader::processNetworkReplyFailed(const QString &strError)
93{
94 /* Notify listeners: */
95 emit sigProgressFailed(strError);
96}
97
98void UIDownloader::processNetworkReplyCanceled(UINetworkReply *)
99{
100 /* Notify listeners: */
101 emit sigProgressCanceled();
102}
103
104void UIDownloader::processNetworkReplyFinished(UINetworkReply *pNetworkReply)
105{
106 /* Process reply: */
107 switch (m_state)
108 {
109 case UIDownloaderState_Acknowledging:
110 {
111 handleAcknowledgingResult(pNetworkReply);
112 break;
113 }
114 case UIDownloaderState_Downloading:
115 {
116 handleDownloadingResult(pNetworkReply);
117 break;
118 }
119 case UIDownloaderState_Verifying:
120 {
121 handleVerifyingResult(pNetworkReply);
122 break;
123 }
124 default:
125 break;
126 }
127}
128
129void UIDownloader::handleAcknowledgingResult(UINetworkReply *pNetworkReply)
130{
131 /* Get the final source: */
132 m_source = pNetworkReply->url();
133
134 /* Ask for downloading: */
135 if (askForDownloadingConfirmation(pNetworkReply))
136 {
137 /* Start downloading: */
138 startDelayedDownloading();
139 }
140 else
141 {
142 /* Notify listeners: */
143 emit sigProgressFinished();
144 }
145}
146
147void UIDownloader::handleDownloadingResult(UINetworkReply *pNetworkReply)
148{
149 /* Handle downloaded object: */
150 handleDownloadedObject(pNetworkReply);
151
152 /* Check whether we should do verification: */
153 if (!m_strPathSHA256SumsFile.isEmpty())
154 {
155 /* Start verifying: */
156 startDelayedVerifying();
157 }
158 else
159 {
160 /* Notify listeners: */
161 emit sigProgressFinished();
162 }
163}
164
165void UIDownloader::handleVerifyingResult(UINetworkReply *pNetworkReply)
166{
167 /* Handle verified object: */
168 handleVerifiedObject(pNetworkReply);
169
170 /* Notify listeners: */
171 emit sigProgressFinished();
172}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use