VirtualBox

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

Last change on this file since 43138 was 42901, checked in by vboxsync, 12 years ago

FE/Qt: Do not create network-manager indicator for VM-console process.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 7.3 KB
Line 
1/* $Id: UINetworkManager.cpp 42901 2012-08-21 11:17:21Z 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 : m_pNetworkManagerDialog(0)
95 , m_pNetworkManagerIndicator(0)
96{
97 /* Prepare instance: */
98 m_pInstance = this;
99}
100
101UINetworkManager::~UINetworkManager()
102{
103 /* Cleanup instance: */
104 m_pInstance = 0;
105}
106
107void UINetworkManager::prepare()
108{
109 /* Prepare network-manager dialog: */
110 m_pNetworkManagerDialog = new UINetworkManagerDialog;
111 connect(m_pNetworkManagerDialog, SIGNAL(sigCancelNetworkRequests()), this, SIGNAL(sigCancelNetworkRequests()));
112
113 /* Prepare network-manager state-indicator: */
114 if (!vboxGlobal().isVMConsoleProcess())
115 {
116 m_pNetworkManagerIndicator = new UINetworkManagerIndicator;
117 connect(m_pNetworkManagerIndicator, SIGNAL(mouseDoubleClicked(QIStateIndicator *, QMouseEvent *)), this, SLOT(show()));
118 }
119}
120
121void UINetworkManager::cleanup()
122{
123 /* Cleanup network-requests first: */
124 cleanupNetworkRequests();
125
126 /* Cleanup network-manager state-indicator: */
127 if (!vboxGlobal().isVMConsoleProcess())
128 {
129 delete m_pNetworkManagerIndicator;
130 m_pNetworkManagerIndicator = 0;
131 }
132
133 /* Cleanup network-manager dialog: */
134 delete m_pNetworkManagerDialog;
135}
136
137void UINetworkManager::prepareNetworkRequest(UINetworkRequest *pNetworkRequest)
138{
139 /* Prepare listeners for network-request: */
140 connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid&, qint64, qint64)),
141 this, SLOT(sltHandleNetworkRequestProgress(const QUuid&, qint64, qint64)));
142 connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid&)),
143 this, SLOT(sltHandleNetworkRequestCancel(const QUuid&)));
144 connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid&)),
145 this, SLOT(sltHandleNetworkRequestFinish(const QUuid&)));
146 connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid&, const QString&)),
147 this, SLOT(sltHandleNetworkRequestFailure(const QUuid&, const QString&)));
148
149 /* Add network-request into map: */
150 m_requests.insert(pNetworkRequest->uuid(), pNetworkRequest);
151}
152
153void UINetworkManager::cleanupNetworkRequest(QUuid uuid)
154{
155 /* Delete network-request from map: */
156 delete m_requests[uuid];
157 m_requests.remove(uuid);
158}
159
160void UINetworkManager::cleanupNetworkRequests()
161{
162 /* Get all the request IDs: */
163 const QList<QUuid> &uuids = m_requests.keys();
164 /* Cleanup corresponding requests: */
165 for (int i = 0; i < uuids.size(); ++i)
166 cleanupNetworkRequest(uuids[i]);
167}
168
169void UINetworkManager::sltHandleNetworkRequestProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
170{
171 /* Make sure corresponding map contains received ID: */
172 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
173
174 /* Get corresponding network-request: */
175 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
176
177 /* Get corresponding customer: */
178 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
179
180 /* Send to customer to process: */
181 pNetworkCustomer->processNetworkReplyProgress(iReceived, iTotal);
182}
183
184void UINetworkManager::sltHandleNetworkRequestCancel(const QUuid &uuid)
185{
186 /* Make sure corresponding map contains received ID: */
187 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
188
189 /* Get corresponding network-request: */
190 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
191
192 /* Get corresponding customer: */
193 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
194
195 /* Send to customer to process: */
196 pNetworkCustomer->processNetworkReplyCanceled(pNetworkRequest->reply());
197
198 /* Cleanup network-request: */
199 cleanupNetworkRequest(uuid);
200}
201
202void UINetworkManager::sltHandleNetworkRequestFinish(const QUuid &uuid)
203{
204 /* Make sure corresponding map contains received ID: */
205 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
206
207 /* Get corresponding network-request: */
208 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
209
210 /* Get corresponding customer: */
211 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
212
213 /* Send to customer to process: */
214 pNetworkCustomer->processNetworkReplyFinished(pNetworkRequest->reply());
215
216 /* Cleanup network-request: */
217 cleanupNetworkRequest(uuid);
218}
219
220void UINetworkManager::sltHandleNetworkRequestFailure(const QUuid &uuid, const QString &)
221{
222 /* Make sure corresponding map contains received ID: */
223 AssertMsg(m_requests.contains(uuid), ("Network-request NOT found!\n"));
224
225 /* Get corresponding network-request: */
226 UINetworkRequest *pNetworkRequest = m_requests.value(uuid);
227
228 /* Get corresponding customer: */
229 UINetworkCustomer *pNetworkCustomer = pNetworkRequest->customer();
230
231 /* If customer made a force-call: */
232 if (pNetworkCustomer->isItForceCall())
233 {
234 /* Just show the dialog: */
235 show();
236 }
237}
238
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