VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networking/UINetworkRequest.cpp@ 103977

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

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp70873
    /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp74233
    /branches/VBox-4.2/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp91223
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp79645-79692
File size: 5.4 KB
Line 
1/* $Id: UINetworkRequest.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINetworkRequest class implementation.
4 */
5
6/*
7 * Copyright (C) 2011-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/* Qt includes: */
29#include <QVariant>
30
31/* GUI includes: */
32#include "UINetworkRequest.h"
33#include "UINetworkRequestManager.h"
34
35/* Other VBox includes: */
36#include "iprt/assert.h"
37
38
39UINetworkRequest::UINetworkRequest(UINetworkRequestType enmType,
40 const QList<QUrl> &urls,
41 const QString &strTarget,
42 const UserDictionary &requestHeaders)
43 : m_enmType(enmType)
44 , m_urls(urls)
45 , m_strTarget(strTarget)
46 , m_requestHeaders(requestHeaders)
47 , m_iUrlIndex(-1)
48 , m_fRunning(false)
49{
50 prepare();
51}
52
53UINetworkRequest::~UINetworkRequest()
54{
55 cleanup();
56}
57
58void UINetworkRequest::sltHandleNetworkReplyProgress(qint64 iReceived, qint64 iTotal)
59{
60 /* Notify network-request listeners: */
61 emit sigProgress(iReceived, iTotal);
62}
63
64void UINetworkRequest::sltHandleNetworkReplyFinish()
65{
66 /* Mark network-reply as non-running: */
67 m_fRunning = false;
68
69 /* Make sure network-reply still valid: */
70 if (!m_pReply)
71 return;
72
73 /* If network-reply has no errors: */
74 if (m_pReply->error() == UINetworkReply::NoError)
75 {
76 /* Notify network-request listeners: */
77 emit sigFinished();
78 }
79 /* If network-request was canceled: */
80 else if (m_pReply->error() == UINetworkReply::OperationCanceledError)
81 {
82 /* Notify network-request listeners: */
83 emit sigCanceled();
84 }
85 /* If some other error occured: */
86 else
87 {
88 /* Check if we are able to handle error: */
89 bool fErrorHandled = false;
90
91 /* Handle redirection: */
92 switch (m_pReply->error())
93 {
94 case UINetworkReply::ContentReSendError:
95 {
96 /* Check whether redirection link was acquired: */
97 const QString strRedirect = m_pReply->header(UINetworkReply::LocationHeader).toString();
98 if (!strRedirect.isEmpty())
99 {
100 /* Cleanup current network-reply first: */
101 cleanupNetworkReply();
102
103 /* Choose redirect-source as current url: */
104 m_url = strRedirect;
105
106 /* Create new network-reply finally: */
107 prepareNetworkReply();
108
109 /* Mark this error handled: */
110 fErrorHandled = true;
111 }
112 break;
113 }
114 default:
115 break;
116 }
117
118 /* If error still unhandled: */
119 if (!fErrorHandled)
120 {
121 /* Check if we have other urls in queue: */
122 if (m_iUrlIndex < m_urls.size() - 1)
123 {
124 /* Cleanup current network-reply first: */
125 cleanupNetworkReply();
126
127 /* Choose next url as current: */
128 ++m_iUrlIndex;
129 m_url = m_urls.at(m_iUrlIndex);
130
131 /* Create new network-reply finally: */
132 prepareNetworkReply();
133 }
134 else
135 {
136 /* Notify network-request listeners: */
137 emit sigFailed(m_pReply->errorString());
138 }
139 }
140 }
141}
142
143void UINetworkRequest::sltCancel()
144{
145 /* Abort network-reply if present: */
146 if (m_pReply)
147 {
148 if (m_fRunning)
149 m_pReply->abort();
150 else
151 emit sigCanceled();
152 }
153}
154
155void UINetworkRequest::prepare()
156{
157 /* Choose first url as current: */
158 m_iUrlIndex = 0;
159 m_url = m_urls.at(m_iUrlIndex);
160
161 /* Prepare network-reply: */
162 prepareNetworkReply();
163}
164
165void UINetworkRequest::prepareNetworkReply()
166{
167 /* Create network-reply: */
168 m_pReply = new UINetworkReply(m_enmType, m_url, m_strTarget, m_requestHeaders);
169 AssertPtrReturnVoid(m_pReply.data());
170 {
171 /* Prepare network-reply: */
172 connect(m_pReply.data(), &UINetworkReply::downloadProgress,
173 this, &UINetworkRequest::sltHandleNetworkReplyProgress);
174 connect(m_pReply.data(), &UINetworkReply::finished,
175 this, &UINetworkRequest::sltHandleNetworkReplyFinish);
176
177 /* Mark network-reply as running: */
178 m_fRunning = true;
179
180 /* Notify network-request listeners: */
181 emit sigStarted();
182 }
183}
184
185void UINetworkRequest::cleanupNetworkReply()
186{
187 /* Destroy network-reply: */
188 AssertPtrReturnVoid(m_pReply.data());
189 m_pReply->disconnect();
190 m_pReply->deleteLater();
191 m_pReply = 0;
192}
193
194void UINetworkRequest::cleanup()
195{
196 /* Cleanup network-reply: */
197 cleanupNetworkReply();
198}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette