VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UICloudNetworkingStuff.cpp

Last change on this file was 104291, checked in by vboxsync, 6 weeks ago

FE/Qt. bugref:10622. Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.6 KB
Line 
1/* $Id: UICloudNetworkingStuff.cpp 104291 2024-04-11 09:40:12Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UICloudNetworkingStuff namespace implementation.
4 */
5
6/*
7 * Copyright (C) 2020-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 "UICloudNetworkingStuff.h"
33#include "UIErrorString.h"
34#include "UIGlobalSession.h"
35#include "UIMessageCenter.h"
36
37/* COM includes: */
38#include "CAppliance.h"
39#include "CForm.h"
40#include "CProgress.h"
41#include "CStringArray.h"
42#include "CVirtualBox.h"
43#include "CVirtualBoxErrorInfo.h"
44#include "CVirtualSystemDescription.h"
45
46
47CCloudProviderManager UICloudNetworkingStuff::cloudProviderManager(UINotificationCenter *pParent /* = 0 */)
48{
49 /* Acquire VBox: */
50 const CVirtualBox comVBox = gpGlobalSession->virtualBox();
51 if (comVBox.isNotNull())
52 {
53 /* Acquire cloud provider manager: */
54 CCloudProviderManager comProviderManager = comVBox.GetCloudProviderManager();
55 if (!comVBox.isOk())
56 UINotificationMessage::cannotAcquireVirtualBoxParameter(comVBox, pParent);
57 else
58 return comProviderManager;
59 }
60 /* Null by default: */
61 return CCloudProviderManager();
62}
63
64CCloudProviderManager UICloudNetworkingStuff::cloudProviderManager(QString &strErrorMessage)
65{
66 /* Acquire VBox: */
67 const CVirtualBox comVBox = gpGlobalSession->virtualBox();
68 if (comVBox.isNotNull())
69 {
70 /* Acquire cloud provider manager: */
71 CCloudProviderManager comProviderManager = comVBox.GetCloudProviderManager();
72 if (!comVBox.isOk())
73 strErrorMessage = UIErrorString::formatErrorInfo(comVBox);
74 else
75 return comProviderManager;
76 }
77 /* Null by default: */
78 return CCloudProviderManager();
79}
80
81CCloudProvider UICloudNetworkingStuff::cloudProviderByShortName(const QString &strProviderShortName,
82 UINotificationCenter *pParent /* = 0 */)
83{
84 /* Acquire cloud provider manager: */
85 CCloudProviderManager comProviderManager = cloudProviderManager(pParent);
86 if (comProviderManager.isNotNull())
87 {
88 /* Acquire cloud provider: */
89 CCloudProvider comProvider = comProviderManager.GetProviderByShortName(strProviderShortName);
90 if (!comProviderManager.isOk())
91 UINotificationMessage::cannotAcquireCloudProviderManagerParameter(comProviderManager, pParent);
92 else
93 return comProvider;
94 }
95 /* Null by default: */
96 return CCloudProvider();
97}
98
99CCloudProvider UICloudNetworkingStuff::cloudProviderByShortName(const QString &strProviderShortName,
100 QString &strErrorMessage)
101{
102 /* Acquire cloud provider manager: */
103 CCloudProviderManager comProviderManager = cloudProviderManager(strErrorMessage);
104 if (comProviderManager.isNotNull())
105 {
106 /* Acquire cloud provider: */
107 CCloudProvider comProvider = comProviderManager.GetProviderByShortName(strProviderShortName);
108 if (!comProviderManager.isOk())
109 strErrorMessage = UIErrorString::formatErrorInfo(comProviderManager);
110 else
111 return comProvider;
112 }
113 /* Null by default: */
114 return CCloudProvider();
115}
116
117CCloudProfile UICloudNetworkingStuff::cloudProfileByName(const QString &strProviderShortName,
118 const QString &strProfileName,
119 UINotificationCenter *pParent /* = 0 */)
120{
121 /* Acquire cloud provider: */
122 CCloudProvider comProvider = cloudProviderByShortName(strProviderShortName, pParent);
123 if (comProvider.isNotNull())
124 {
125 /* Acquire cloud profile: */
126 CCloudProfile comProfile = comProvider.GetProfileByName(strProfileName);
127 if (!comProvider.isOk())
128 UINotificationMessage::cannotAcquireCloudProviderParameter(comProvider, pParent);
129 else
130 return comProfile;
131 }
132 /* Null by default: */
133 return CCloudProfile();
134}
135
136CCloudProfile UICloudNetworkingStuff::cloudProfileByName(const QString &strProviderShortName,
137 const QString &strProfileName,
138 QString &strErrorMessage)
139{
140 /* Acquire cloud provider: */
141 CCloudProvider comProvider = cloudProviderByShortName(strProviderShortName, strErrorMessage);
142 if (comProvider.isNotNull())
143 {
144 /* Acquire cloud profile: */
145 CCloudProfile comProfile = comProvider.GetProfileByName(strProfileName);
146 if (!comProvider.isOk())
147 strErrorMessage = UIErrorString::formatErrorInfo(comProvider);
148 else
149 return comProfile;
150 }
151 /* Null by default: */
152 return CCloudProfile();
153}
154
155CCloudClient UICloudNetworkingStuff::cloudClient(CCloudProfile comProfile,
156 UINotificationCenter *pParent /* = 0 */)
157{
158 /* Create cloud client: */
159 CCloudClient comClient = comProfile.CreateCloudClient();
160 if (!comProfile.isOk())
161 UINotificationMessage::cannotCreateCloudClient(comProfile, pParent);
162 else
163 return comClient;
164 /* Null by default: */
165 return CCloudClient();
166}
167
168CCloudClient UICloudNetworkingStuff::cloudClient(CCloudProfile comProfile,
169 QString &strErrorMessage)
170{
171 /* Create cloud client: */
172 CCloudClient comClient = comProfile.CreateCloudClient();
173 if (!comProfile.isOk())
174 strErrorMessage = UIErrorString::formatErrorInfo(comProfile);
175 else
176 return comClient;
177 /* Null by default: */
178 return CCloudClient();
179}
180
181CCloudClient UICloudNetworkingStuff::cloudClientByName(const QString &strProviderShortName,
182 const QString &strProfileName,
183 UINotificationCenter *pParent /* = 0 */)
184{
185 /* Acquire cloud profile: */
186 CCloudProfile comProfile = cloudProfileByName(strProviderShortName, strProfileName, pParent);
187 if (comProfile.isNotNull())
188 return cloudClient(comProfile, pParent);
189 /* Null by default: */
190 return CCloudClient();
191}
192
193CCloudClient UICloudNetworkingStuff::cloudClientByName(const QString &strProviderShortName,
194 const QString &strProfileName,
195 QString &strErrorMessage)
196{
197 /* Acquire cloud profile: */
198 CCloudProfile comProfile = cloudProfileByName(strProviderShortName, strProfileName, strErrorMessage);
199 if (comProfile.isNotNull())
200 return cloudClient(comProfile, strErrorMessage);
201 /* Null by default: */
202 return CCloudClient();
203}
204
205CVirtualSystemDescription UICloudNetworkingStuff::createVirtualSystemDescription(UINotificationCenter *pParent /* = 0 */)
206{
207 /* Acquire VBox: */
208 CVirtualBox comVBox = gpGlobalSession->virtualBox();
209 if (comVBox.isNotNull())
210 {
211 /* Create appliance: */
212 CAppliance comAppliance = comVBox.CreateAppliance();
213 if (!comVBox.isOk())
214 UINotificationMessage::cannotCreateAppliance(comVBox, pParent);
215 else
216 {
217 /* Append it with one (1) description we need: */
218 comAppliance.CreateVirtualSystemDescriptions(1);
219 if (!comAppliance.isOk())
220 UINotificationMessage::cannotCreateVirtualSystemDescription(comAppliance, pParent);
221 else
222 {
223 /* Get received description: */
224 const QVector<CVirtualSystemDescription> descriptions = comAppliance.GetVirtualSystemDescriptions();
225 AssertReturn(!descriptions.isEmpty(), CVirtualSystemDescription());
226 return descriptions.at(0);
227 }
228 }
229 }
230 /* Null by default: */
231 return CVirtualSystemDescription();
232}
233
234QVector<CCloudProvider> UICloudNetworkingStuff::listCloudProviders(UINotificationCenter *pParent /* = 0 */)
235{
236 /* Acquire cloud provider manager: */
237 CCloudProviderManager comProviderManager = cloudProviderManager(pParent);
238 if (comProviderManager.isNotNull())
239 {
240 /* Acquire cloud providers: */
241 QVector<CCloudProvider> providers = comProviderManager.GetProviders();
242 if (!comProviderManager.isOk())
243 UINotificationMessage::cannotAcquireCloudProviderManagerParameter(comProviderManager, pParent);
244 else
245 return providers;
246 }
247 /* Return empty list by default: */
248 return QVector<CCloudProvider>();
249}
250
251bool UICloudNetworkingStuff::cloudProviderId(const CCloudProvider &comCloudProvider,
252 QUuid &uResult,
253 UINotificationCenter *pParent /* = 0 */)
254{
255 const QUuid uId = comCloudProvider.GetId();
256 if (!comCloudProvider.isOk())
257 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
258 else
259 {
260 uResult = uId;
261 return true;
262 }
263 return false;
264}
265
266bool UICloudNetworkingStuff::cloudProviderShortName(const CCloudProvider &comCloudProvider,
267 QString &strResult,
268 UINotificationCenter *pParent /* = 0 */)
269{
270 const QString strShortName = comCloudProvider.GetShortName();
271 if (!comCloudProvider.isOk())
272 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
273 else
274 {
275 strResult = strShortName;
276 return true;
277 }
278 return false;
279}
280
281bool UICloudNetworkingStuff::cloudProviderName(const CCloudProvider &comCloudProvider,
282 QString &strResult,
283 UINotificationCenter *pParent /* = 0 */)
284{
285 const QString strName = comCloudProvider.GetName();
286 if (!comCloudProvider.isOk())
287 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
288 else
289 {
290 strResult = strName;
291 return true;
292 }
293 return false;
294}
295
296QVector<CCloudProfile> UICloudNetworkingStuff::listCloudProfiles(const CCloudProvider &comCloudProvider,
297 UINotificationCenter *pParent /* = 0 */)
298{
299 /* Check cloud provider: */
300 if (comCloudProvider.isNotNull())
301 {
302 /* Acquire cloud providers: */
303 QVector<CCloudProfile> profiles = comCloudProvider.GetProfiles();
304 if (!comCloudProvider.isOk())
305 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
306 else
307 return profiles;
308 }
309 /* Return empty list by default: */
310 return QVector<CCloudProfile>();
311}
312
313bool UICloudNetworkingStuff::cloudProfileName(const CCloudProfile &comCloudProfile,
314 QString &strResult,
315 UINotificationCenter *pParent /* = 0 */)
316{
317 const QString strName = comCloudProfile.GetName();
318 if (!comCloudProfile.isOk())
319 UINotificationMessage::cannotAcquireCloudProfileParameter(comCloudProfile, pParent);
320 else
321 {
322 strResult = strName;
323 return true;
324 }
325 return false;
326}
327
328bool UICloudNetworkingStuff::cloudProfileProperties(const CCloudProfile &comCloudProfile,
329 QVector<QString> &keys,
330 QVector<QString> &values,
331 UINotificationCenter *pParent /* = 0 */)
332{
333 QVector<QString> aKeys;
334 QVector<QString> aValues;
335 aValues = comCloudProfile.GetProperties(QString(), aKeys);
336 if (!comCloudProfile.isOk())
337 UINotificationMessage::cannotAcquireCloudProfileParameter(comCloudProfile, pParent);
338 else
339 {
340 aValues.resize(aKeys.size());
341 keys = aKeys;
342 values = aValues;
343 return true;
344 }
345 return false;
346}
347
348bool UICloudNetworkingStuff::listCloudImages(const CCloudClient &comCloudClient,
349 CStringArray &comNames,
350 CStringArray &comIDs,
351 UINotificationCenter *pParent)
352{
353 /* Currently we are interested in Available images only: */
354 const QVector<KCloudImageState> cloudImageStates = QVector<KCloudImageState>()
355 << KCloudImageState_Available;
356
357 /* List cloud images: */
358 UINotificationProgressCloudImageList *pNotification =
359 new UINotificationProgressCloudImageList(comCloudClient, cloudImageStates);
360 UINotificationReceiver receiver1;
361 UINotificationReceiver receiver2;
362 QObject::connect(pNotification, &UINotificationProgressCloudImageList::sigImageNamesReceived,
363 &receiver1, &UINotificationReceiver::setReceiverProperty);
364 QObject::connect(pNotification, &UINotificationProgressCloudImageList::sigImageIdsReceived,
365 &receiver2, &UINotificationReceiver::setReceiverProperty);
366 if (pParent->handleNow(pNotification))
367 {
368 comNames = receiver1.property("received_value").value<CStringArray>();
369 comIDs = receiver2.property("received_value").value<CStringArray>();
370 return true;
371 }
372
373 /* Return false by default: */
374 return false;
375}
376
377bool UICloudNetworkingStuff::listCloudSourceBootVolumes(const CCloudClient &comCloudClient,
378 CStringArray &comNames,
379 CStringArray &comIDs,
380 UINotificationCenter *pParent)
381{
382 /* List cloud source boot volumes: */
383 UINotificationProgressCloudSourceBootVolumeList *pNotification =
384 new UINotificationProgressCloudSourceBootVolumeList(comCloudClient);
385 UINotificationReceiver receiver1;
386 UINotificationReceiver receiver2;
387 QObject::connect(pNotification, &UINotificationProgressCloudSourceBootVolumeList::sigImageNamesReceived,
388 &receiver1, &UINotificationReceiver::setReceiverProperty);
389 QObject::connect(pNotification, &UINotificationProgressCloudSourceBootVolumeList::sigImageIdsReceived,
390 &receiver2, &UINotificationReceiver::setReceiverProperty);
391 if (pParent->handleNow(pNotification))
392 {
393 comNames = receiver1.property("received_value").value<CStringArray>();
394 comIDs = receiver2.property("received_value").value<CStringArray>();
395 return true;
396 }
397
398 /* Return false by default: */
399 return false;
400}
401
402bool UICloudNetworkingStuff::listCloudInstances(const CCloudClient &comCloudClient,
403 CStringArray &comNames,
404 CStringArray &comIDs,
405 UINotificationCenter *pParent)
406{
407 /* List cloud instances: */
408 UINotificationProgressCloudInstanceList *pNotification =
409 new UINotificationProgressCloudInstanceList(comCloudClient);
410 UINotificationReceiver receiver1;
411 UINotificationReceiver receiver2;
412 QObject::connect(pNotification, &UINotificationProgressCloudInstanceList::sigImageNamesReceived,
413 &receiver1, &UINotificationReceiver::setReceiverProperty);
414 QObject::connect(pNotification, &UINotificationProgressCloudInstanceList::sigImageIdsReceived,
415 &receiver2, &UINotificationReceiver::setReceiverProperty);
416 if (pParent->handleNow(pNotification))
417 {
418 comNames = receiver1.property("received_value").value<CStringArray>();
419 comIDs = receiver2.property("received_value").value<CStringArray>();
420 return true;
421 }
422
423 /* Return false by default: */
424 return false;
425}
426
427bool UICloudNetworkingStuff::listCloudSourceInstances(const CCloudClient &comCloudClient,
428 CStringArray &comNames,
429 CStringArray &comIDs,
430 UINotificationCenter *pParent)
431{
432 /* List cloud source instances: */
433 UINotificationProgressCloudSourceInstanceList *pNotification =
434 new UINotificationProgressCloudSourceInstanceList(comCloudClient);
435 UINotificationReceiver receiver1;
436 UINotificationReceiver receiver2;
437 QObject::connect(pNotification, &UINotificationProgressCloudSourceInstanceList::sigImageNamesReceived,
438 &receiver1, &UINotificationReceiver::setReceiverProperty);
439 QObject::connect(pNotification, &UINotificationProgressCloudSourceInstanceList::sigImageIdsReceived,
440 &receiver2, &UINotificationReceiver::setReceiverProperty);
441 if (pParent->handleNow(pNotification))
442 {
443 comNames = receiver1.property("received_value").value<CStringArray>();
444 comIDs = receiver2.property("received_value").value<CStringArray>();
445 return true;
446 }
447
448 /* Return false by default: */
449 return false;
450}
451
452bool UICloudNetworkingStuff::exportDescriptionForm(const CCloudClient &comCloudClient,
453 const CVirtualSystemDescription &comDescription,
454 CVirtualSystemDescriptionForm &comResult,
455 UINotificationCenter *pParent)
456{
457 /* Prepare export VSD form: */
458 UINotificationProgressExportVSDFormCreate *pNotification =
459 new UINotificationProgressExportVSDFormCreate(comCloudClient, comDescription);
460 UINotificationReceiver receiver;
461 QObject::connect(pNotification, &UINotificationProgressExportVSDFormCreate::sigVSDFormCreated,
462 &receiver, &UINotificationReceiver::setReceiverProperty);
463 if (pParent->handleNow(pNotification))
464 {
465 comResult = receiver.property("received_value").value<CVirtualSystemDescriptionForm>();
466 return true;
467 }
468
469 /* False by default: */
470 return false;
471}
472
473bool UICloudNetworkingStuff::importDescriptionForm(const CCloudClient &comCloudClient,
474 const CVirtualSystemDescription &comDescription,
475 CVirtualSystemDescriptionForm &comResult,
476 UINotificationCenter *pParent)
477{
478 /* Prepare import VSD form: */
479 UINotificationProgressImportVSDFormCreate *pNotification =
480 new UINotificationProgressImportVSDFormCreate(comCloudClient, comDescription);
481 UINotificationReceiver receiver;
482 QObject::connect(pNotification, &UINotificationProgressImportVSDFormCreate::sigVSDFormCreated,
483 &receiver, &UINotificationReceiver::setReceiverProperty);
484 if (pParent->handleNow(pNotification))
485 {
486 comResult = receiver.property("received_value").value<CVirtualSystemDescriptionForm>();
487 return true;
488 }
489
490 /* False by default: */
491 return false;
492}
493
494bool UICloudNetworkingStuff::cloudMachineId(const CCloudMachine &comCloudMachine,
495 QUuid &uResult,
496 UINotificationCenter *pParent /* = 0 */)
497{
498 const QUuid uId = comCloudMachine.GetId();
499 if (!comCloudMachine.isOk())
500 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
501 else
502 {
503 uResult = uId;
504 return true;
505 }
506 return false;
507}
508
509bool UICloudNetworkingStuff::cloudMachineName(const CCloudMachine &comCloudMachine,
510 QString &strResult,
511 UINotificationCenter *pParent /* = 0 */)
512{
513 const QString strName = comCloudMachine.GetName();
514 if (!comCloudMachine.isOk())
515 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
516 else
517 {
518 strResult = strName;
519 return true;
520 }
521 return false;
522}
523
524bool UICloudNetworkingStuff::cloudMachineConsoleConnectionFingerprint(const CCloudMachine &comCloudMachine,
525 QString &strResult,
526 UINotificationCenter *pParent /* = 0 */)
527{
528 const QString strConsoleConnectionFingerprint = comCloudMachine.GetConsoleConnectionFingerprint();
529 if (!comCloudMachine.isOk())
530 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
531 else
532 {
533 strResult = strConsoleConnectionFingerprint;
534 return true;
535 }
536 return false;
537}
538
539bool UICloudNetworkingStuff::cloudMachineSettingsForm(const CCloudMachine &comCloudMachine,
540 CForm &comResult,
541 UINotificationCenter *pParent)
542{
543 /* Acquire machine name first: */
544 QString strMachineName;
545 if (!cloudMachineName(comCloudMachine, strMachineName))
546 return false;
547
548 /* Prepare VM settings form: */
549 UINotificationProgressCloudMachineSettingsFormCreate *pNotification =
550 new UINotificationProgressCloudMachineSettingsFormCreate(comCloudMachine, strMachineName);
551 UINotificationReceiver receiver;
552 QObject::connect(pNotification, &UINotificationProgressCloudMachineSettingsFormCreate::sigSettingsFormCreated,
553 &receiver, &UINotificationReceiver::setReceiverProperty);
554 if (pParent->handleNow(pNotification))
555 {
556 comResult = receiver.property("received_value").value<CForm>();
557 return true;
558 }
559
560 /* False by default: */
561 return false;
562}
563
564bool UICloudNetworkingStuff::cloudMachineSettingsForm(CCloudMachine comCloudMachine,
565 CForm &comResult,
566 QString &strErrorMessage)
567{
568 /* Prepare settings form: */
569 CForm comForm;
570
571 /* Now execute GetSettingsForm async method: */
572 CProgress comProgress = comCloudMachine.GetSettingsForm(comForm);
573 if (!comCloudMachine.isOk())
574 {
575 strErrorMessage = UIErrorString::formatErrorInfo(comCloudMachine);
576 return false;
577 }
578
579 /* Wait for "Get settings form" progress: */
580 comProgress.WaitForCompletion(-1);
581 if (comProgress.GetCanceled())
582 return false;
583 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
584 {
585 strErrorMessage = UIErrorString::formatErrorInfo(comProgress);
586 return false;
587 }
588
589 /* Return result: */
590 comResult = comForm;
591 return true;
592}
593
594bool UICloudNetworkingStuff::applyCloudMachineSettingsForm(const CCloudMachine &comCloudMachine,
595 const CForm &comForm,
596 UINotificationCenter *pParent)
597{
598 /* Acquire machine name first: */
599 QString strMachineName;
600 if (!cloudMachineName(comCloudMachine, strMachineName))
601 return false;
602
603 /* Apply VM settings form: */
604 UINotificationProgressCloudMachineSettingsFormApply *pNotification =
605 new UINotificationProgressCloudMachineSettingsFormApply(comForm, strMachineName);
606 return pParent->handleNow(pNotification);
607}
608
609void UICloudNetworkingStuff::createCloudMachineClone(const QString &strProviderShortName,
610 const QString &strProfileName,
611 const CCloudMachine &comCloudMachine,
612 const QString &strCloneName,
613 UINotificationCenter *pParent)
614{
615 /* Create cloud client: */
616 CCloudClient comCloudClient = cloudClientByName(strProviderShortName,
617 strProfileName,
618 pParent);
619 if (comCloudClient.isNotNull())
620 {
621 /* Clone specified cloud machine asynchronously: */
622 UINotificationProgressCloudMachineClone *pNotification =
623 new UINotificationProgressCloudMachineClone(comCloudClient, comCloudMachine, strCloneName);
624 pParent->append(pNotification);
625 }
626}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use