VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp@ 41461

Last change on this file since 41461 was 41461, checked in by vboxsync, 13 years ago

FE/Qt: Network manager stuff: Adding network-operations state-indicator for status-bar. It is used in VM selector status-bar while some network-operation is being loading or failed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 7.1 KB
Line 
1/* $Id: UINetworkManager.cpp 41461 2012-05-28 10:45:44Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UINetworkManager stuff implementation
6 */
7
8/*
9 * Copyright (C) 2011-2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Global includes: */
21#include <QWidget>
22
23/* Local includes: */
24#include "UINetworkManager.h"
25#include "UINetworkManagerDialog.h"
26#include "UINetworkManagerIndicator.h"
27#include "UINetworkRequest.h"
28#include "UINetworkCustomer.h"
29#include "VBoxGlobal.h"
30
31UINetworkManager* UINetworkManager::m_pInstance = 0;
32
33void UINetworkManager::create()
34{
35 /* Check that instance do NOT exist: */
36 if (m_pInstance)
37 return;
38
39 /* Create instance: */
40 new UINetworkManager;
41
42 /* Prepare instance: */
43 m_pInstance->prepare();
44}
45
46void UINetworkManager::destroy()
47{
48 /* Check that instance exists: */
49 if (!m_pInstance)
50 return;
51
52 /* Cleanup instance: */
53 m_pInstance->cleanup();
54
55 /* Destroy instance: */
56 delete m_pInstance;
57}
58
59UINetworkManagerDialog* UINetworkManager::window() const
60{
61 return m_pNetworkManagerDialog;
62}
63
64UINetworkManagerIndicator* UINetworkManager::indicator() const
65{
66 return m_pNetworkManagerIndicator;
67}
68
69void UINetworkManager::show()
70{
71 /* Show network-manager dialog: */
72 m_pNetworkManagerDialog->showNormal();
73}
74
75void UINetworkManager::createNetworkRequest(const QNetworkRequest &request, UINetworkRequestType type, const QString &strDescription,
76 UINetworkCustomer *pCustomer)
77{
78 /* Create network-request: */
79 UINetworkRequest *pNetworkRequest = new UINetworkRequest(request, type, strDescription, pCustomer, this);
80 /* Prepare created network-request: */
81 prepareNetworkRequest(pNetworkRequest);
82}
83
84void UINetworkManager::createNetworkRequest(const QList<QNetworkRequest> &requests, UINetworkRequestType type, const QString &strDescription,
85 UINetworkCustomer *pCustomer)
86{
87 /* Create network-request: */
88 UINetworkRequest *pNetworkRequest = new UINetworkRequest(requests, type, strDescription, pCustomer, this);
89 /* Prepare created network-request: */
90 prepareNetworkRequest(pNetworkRequest);
91}
92
93UINetworkManager::UINetworkManager()
94{
95 /* Prepare instance: */
96 m_pInstance = this;
97}
98
99UINetworkManager::~UINetworkManager()
100{
101 /* Cleanup instance: */
102 m_pInstance = 0;
103}
104
105void UINetworkManager::prepare()
106{
107 /* Prepare network-manager dialog: */
108 m_pNetworkManagerDialog = new UINetworkManagerDialog;
109 connect(m_pNetworkManagerDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
110
111 /* Prepare network-manager state-indicator: */
112 m_pNetworkManagerIndicator = new UINetworkManagerIndicator;
113 connect(m_pNetworkManagerIndicator, SIGNAL(mouseDoubleClicked(QIStateIndicator *, QMouseEvent *)), this, SLOT(show()));
114}
115
116void UINetworkManager::cleanup()
117{
118 /* Cleanup network-requests first: */
119 cleanupNetworkRequests();
120
121 /* Cleanup network-manager state-indicator: */
122 delete m_pNetworkManagerIndicator;
123
124 /* Cleanup network-manager dialog: */
125 delete m_pNetworkManagerDialog;
126}
127
128void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
129{
130 /* Prepare listeners for network-request: */
131 connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)),
132 this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
133 connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)),
134 this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
135 connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)),
136 this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
137 connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)),
138 this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
139
140 /* Add network-request into map: */
141 m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
142}
143
144void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
145{
146 /* Delete network-request from map: */
147 delete m_requests[uuid];
148 m_requests.remove(uuid);
149}
150
151void UINetworkManager::cleanupNetworkRequests()
152{
153 /* Get all the request IDs: */
154 const QList<QUuid> &uuids = m_requests.keys();
155 /* Cleanup corresponding requests: */
156 for (int i = 0; i < uuids.size(); ++i)
157 cleanupNetworkRequest(uuids[i]);
158}
159
160void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
161{
162 /* Make sure corresponding map contains received ID: */
163 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
164
165 /* Get corresponding network-request: */
166 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
167
168 /* Get corresponding customer: */
169 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
170
171 /* Send to customer to process: */
172 pNetworkCustomer->processNetworkReplyProgress(iReceived, iTotal);
173}
174
175void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
176{
177 /* Make sure corresponding map contains received ID: */
178 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
179
180 /* Get corresponding network-request: */
181 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
182
183 /* Get corresponding customer: */
184 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
185
186 /* Send to customer to process: */
187 pNetworkCustomer->processNetworkReplyCanceled(pNetworkRequest->reply());
188
189 /* Cleanup network-request: */
190 cleanupNetworkRequest(uuid);
191}
192
193void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
194{
195 /* Make sure corresponding map contains received ID: */
196 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
197
198 /* Get corresponding network-request: */
199 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
200
201 /* Get corresponding customer: */
202 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
203
204 /* Send to customer to process: */
205 pNetworkCustomer->processNetworkReplyFinished(pNetworkRequest->reply());
206
207 /* Cleanup network-request: */
208 cleanupNetworkRequest(uuid);
209}
210
211void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
212{
213 /* Make sure corresponding map contains received ID: */
214 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
215
216 /* Get corresponding network-request: */
217 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
218
219 /* Get corresponding customer: */
220 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
221
222 /* If customer made a force-call: */
223 if (pNetworkCustomer->isItForceCall())
224 {
225 /* Just show the dialog: */
226 show();
227 }
228}
229
Note: See TracBrowser for help on using the repository browser.

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