VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloader.cpp@ 82781

Last change on this file since 82781 was 79365, checked in by vboxsync, 5 years ago

Renaming VBoxGlobal to UICommon for bugref:9049 as planned.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: UIDownloader.cpp 79365 2019-06-26 15:57:32Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIDownloader class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/* GUI includes: */
19#include "UICommon.h"
20#include "VBoxUtils.h"
21#include "UIDownloader.h"
22#include "UIMessageCenter.h"
23#include "UINetworkReply.h"
24
25
26void UIDownloader::start()
27{
28 startDelayedAcknowledging();
29}
30
31void UIDownloader::sltStartAcknowledging()
32{
33 /* Set state to acknowledging: */
34 m_state = UIDownloaderState_Acknowledging;
35
36 /* Send HEAD requests: */
37 createNetworkRequest(UINetworkRequestType_HEAD, m_sources);
38}
39
40void UIDownloader::sltStartDownloading()
41{
42 /* Set state to downloading: */
43 m_state = UIDownloaderState_Downloading;
44
45 /* Send GET request: */
46 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_source, m_strTarget);
47}
48
49void UIDownloader::sltStartVerifying()
50{
51 /* Set state to verifying: */
52 m_state = UIDownloaderState_Verifying;
53
54 /* Send GET request: */
55 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_strPathSHA256SumsFile);
56}
57
58UIDownloader::UIDownloader()
59 : m_state(UIDownloaderState_Null)
60{
61 /* Connect listeners: */
62 connect(this, &UIDownloader::sigToStartAcknowledging, this, &UIDownloader::sltStartAcknowledging, Qt::QueuedConnection);
63 connect(this, &UIDownloader::sigToStartDownloading, this, &UIDownloader::sltStartDownloading, Qt::QueuedConnection);
64 connect(this, &UIDownloader::sigToStartVerifying, this, &UIDownloader::sltStartVerifying, Qt::QueuedConnection);
65}
66
67const QString UIDownloader::description() const
68{
69 /* Look for known state: */
70 switch (m_state)
71 {
72 case UIDownloaderState_Acknowledging: return tr("Looking for %1...");
73 case UIDownloaderState_Downloading: return tr("Downloading %1...");
74 case UIDownloaderState_Verifying: return tr("Verifying %1...");
75 default: break;
76 }
77 /* Return null-string by default: */
78 return QString();
79}
80
81void UIDownloader::processNetworkReplyProgress(qint64, qint64)
82{
83}
84
85void UIDownloader::processNetworkReplyCanceled(UINetworkReply *)
86{
87 /* Delete downloader: */
88 deleteLater();
89}
90
91void UIDownloader::processNetworkReplyFinished(UINetworkReply *pNetworkReply)
92{
93 /* Process reply: */
94 switch (m_state)
95 {
96 case UIDownloaderState_Acknowledging:
97 {
98 handleAcknowledgingResult(pNetworkReply);
99 break;
100 }
101 case UIDownloaderState_Downloading:
102 {
103 handleDownloadingResult(pNetworkReply);
104 break;
105 }
106 case UIDownloaderState_Verifying:
107 {
108 handleVerifyingResult(pNetworkReply);
109 break;
110 }
111 default:
112 break;
113 }
114}
115
116void UIDownloader::handleAcknowledgingResult(UINetworkReply *pNetworkReply)
117{
118 /* Get the final source: */
119 m_source = pNetworkReply->url();
120
121 /* Ask for downloading: */
122 if (askForDownloadingConfirmation(pNetworkReply))
123 {
124 /* Start downloading: */
125 startDelayedDownloading();
126 }
127 else
128 {
129 /* Delete downloader: */
130 deleteLater();
131 }
132}
133
134void UIDownloader::handleDownloadingResult(UINetworkReply *pNetworkReply)
135{
136 /* Handle downloaded object: */
137 handleDownloadedObject(pNetworkReply);
138
139 /* Check whether we should do verification: */
140 if (!m_strPathSHA256SumsFile.isEmpty())
141 {
142 /* Start verifying: */
143 startDelayedVerifying();
144 }
145 else
146 {
147 /* Delete downloader: */
148 deleteLater();
149 }
150}
151
152void UIDownloader::handleVerifyingResult(UINetworkReply *pNetworkReply)
153{
154 /* Handle verified object: */
155 handleVerifiedObject(pNetworkReply);
156
157 /* Delete downloader: */
158 deleteLater();
159}
160
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use