Changeset 78989 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 5, 2019 11:27:24 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic2.cpp
r78987 r78989 47 47 /* COM includes: */ 48 48 #include "CCloudClient.h" 49 #include "CMachine.h" 49 50 50 51 … … 293 294 } 294 295 295 void UIWizardExportAppPage2::populateCloudClientParameters() 296 { 297 /* Forget current parameters: */ 298 m_cloudClientParameters.clear(); 299 300 /* Return if no profile chosen: */ 301 if (m_comCloudProfile.isNull()) 302 return; 303 304 /* Create Cloud Client: */ 305 CCloudClient comCloudClient = m_comCloudProfile.CreateCloudClient(); 306 /* Show error message if necessary: */ 307 if (!m_comCloudProfile.isOk()) 308 msgCenter().cannotCreateCloudClient(m_comCloudProfile); 309 else 310 { 311 /* Read Cloud Client parameters for Export VM operation: */ 312 const QString strJSON = comCloudClient.GetExportLaunchParameters(); 313 /* Show error message if necessary: */ 314 if (!comCloudClient.isOk()) 315 msgCenter().cannotAcquireCloudClientParameter(comCloudClient); 316 else 296 void UIWizardExportAppPage2::populateFormProperties() 297 { 298 /* Clear appliance: */ 299 m_comAppliance = CAppliance(); 300 /* Clear form properties: */ 301 m_comVSDForm = CVirtualSystemDescriptionForm(); 302 303 /* If profile chosen: */ 304 if (m_comCloudProfile.isNotNull()) 305 { 306 /* Main API request sequence, can be interrupted after any step: */ 307 do 317 308 { 318 /* Create JSON document and parse it: */ 319 const QJsonDocument document = QJsonDocument::fromJson(strJSON.toUtf8()); 320 if (!document.isEmpty()) 321 m_cloudClientParameters = parseJsonDocument(document); 309 /* Perform cloud export procedure for first uuid only: */ 310 const QList<QUuid> uuids = fieldImp("machineIDs").value<QList<QUuid> >(); 311 AssertReturnVoid(!uuids.isEmpty()); 312 const QUuid uMachineId = uuids.first(); 313 314 /* Get the machine with the uMachineId: */ 315 CVirtualBox comVBox = vboxGlobal().virtualBox(); 316 CMachine comMachine = comVBox.FindMachine(uMachineId.toString()); 317 if (!comVBox.isOk()) 318 { 319 msgCenter().cannotFindMachineById(comVBox, uMachineId); 320 break; 321 } 322 323 /* Create appliance: */ 324 CAppliance comAppliance = comVBox.CreateAppliance(); 325 if (!comVBox.isOk()) 326 { 327 msgCenter().cannotCreateAppliance(comVBox); 328 break; 329 } 330 331 /* Remember appliance: */ 332 m_comAppliance = comAppliance; 333 334 /* Add the export virtual system description to our appliance object: */ 335 CVirtualSystemDescription comVSD = comMachine.ExportTo(m_comAppliance, qobject_cast<UIWizardExportApp*>(wizardImp())->uri()); 336 if (!comMachine.isOk()) 337 { 338 msgCenter().cannotExportAppliance(comMachine, m_comAppliance.GetPath(), thisImp()); 339 break; 340 } 341 342 /* Create Cloud Client: */ 343 CCloudClient comCloudClient = m_comCloudProfile.CreateCloudClient(); 344 if (!m_comCloudProfile.isOk()) 345 { 346 msgCenter().cannotCreateCloudClient(m_comCloudProfile); 347 break; 348 } 349 350 /* Read Cloud Client description form: */ 351 CVirtualSystemDescriptionForm comForm; 352 CProgress comExportDescriptionFormProgress = comCloudClient.GetExportLaunchDescriptionForm(comVSD, comForm); 353 if (!comCloudClient.isOk()) 354 { 355 msgCenter().cannotAcquireCloudClientParameter(comCloudClient); 356 break; 357 } 358 359 /* Show "Acquire export form" progress: */ 360 msgCenter().showModalProgressDialog(comExportDescriptionFormProgress, UIWizardExportApp::tr("Acquire export form..."), 361 ":/progress_reading_appliance_90px.png", 0, 0); 362 if (!comExportDescriptionFormProgress.isOk() || comExportDescriptionFormProgress.GetResultCode() != 0) 363 { 364 msgCenter().cannotAcquireCloudClientParameter(comExportDescriptionFormProgress); 365 break; 366 } 367 368 /* Remember form: */ 369 m_comVSDForm = comForm; 322 370 } 323 } 324 } 325 326 /* static */ 327 AbstractVSDParameterList UIWizardExportAppPage2::parseJsonDocument(const QJsonDocument &document) 328 { 329 /* Prepare parameters: */ 330 AbstractVSDParameterList parameters; 331 332 /* Convert document to object, make sure it isn't empty: */ 333 QJsonObject documentObject = document.object(); 334 AssertMsgReturn(!documentObject.isEmpty(), ("Document object is empty!"), parameters); 335 336 /* Iterate through document object values: */ 337 foreach (const QString &strElementName, documentObject.keys()) 338 { 339 //printf("Element name: \"%s\"\n", strElementName.toUtf8().constData()); 340 341 /* Prepare parameter: */ 342 AbstractVSDParameter parameter; 343 344 /* Assign name: */ 345 parameter.name = strElementName; 346 347 /* Acquire element, make sure it's an object: */ 348 const QJsonValue element = documentObject.value(strElementName); 349 AssertMsg(element.isObject(), ("Element '%s' has wrong structure!", strElementName.toUtf8().constData())); 350 if (!element.isObject()) 351 continue; 352 353 /* Convert element to object, make sure it isn't empty: */ 354 const QJsonObject elementObject = element.toObject(); 355 AssertMsg(!elementObject.isEmpty(), ("Element '%s' object has wrong structure!", strElementName.toUtf8().constData())); 356 if (elementObject.isEmpty()) 357 continue; 358 359 /* Iterate through element object values: */ 360 foreach (const QString &strFieldName, elementObject.keys()) 361 { 362 //printf(" Field name: \"%s\"\n", strFieldName.toUtf8().constData()); 363 364 /* Acquire field: */ 365 const QJsonValue field = elementObject.value(strFieldName); 366 367 /* Parse known fields: */ 368 if (strFieldName == "type") 369 parameter.type = (KVirtualSystemDescriptionType)(int)parseJsonFieldDouble(strFieldName, field); 370 else 371 if (strFieldName == "bool") 372 { 373 AbstractVSDParameterBool get; 374 get.value = parseJsonFieldBool(strFieldName, field); 375 parameter.get = QVariant::fromValue(get); 376 parameter.kind = ParameterKind_Bool; 377 } 378 else 379 if (strFieldName == "min") 380 { 381 AbstractVSDParameterDouble get = parameter.get.value<AbstractVSDParameterDouble>(); 382 get.minimum = parseJsonFieldDouble(strFieldName, field); 383 parameter.get = QVariant::fromValue(get); 384 parameter.kind = ParameterKind_Double; 385 } 386 else 387 if (strFieldName == "max") 388 { 389 AbstractVSDParameterDouble get = parameter.get.value<AbstractVSDParameterDouble>(); 390 get.maximum = parseJsonFieldDouble(strFieldName, field); 391 parameter.get = QVariant::fromValue(get); 392 parameter.kind = ParameterKind_Double; 393 } 394 else 395 if (strFieldName == "unit") 396 { 397 AbstractVSDParameterDouble get = parameter.get.value<AbstractVSDParameterDouble>(); 398 get.unit = parseJsonFieldString(strFieldName, field); 399 parameter.get = QVariant::fromValue(get); 400 parameter.kind = ParameterKind_Double; 401 } 402 else 403 if (strFieldName == "items") 404 { 405 AbstractVSDParameterArray get; 406 get.values = parseJsonFieldArray(strFieldName, field); 407 parameter.get = QVariant::fromValue(get); 408 parameter.kind = ParameterKind_Array; 409 } 410 else 411 if (strFieldName == "name") 412 { 413 AbstractVSDParameterString get; 414 get.value = parseJsonFieldString(strFieldName, field); 415 parameter.get = QVariant::fromValue(get); 416 parameter.kind = ParameterKind_String; 417 } 418 } 419 420 /* Append parameter: */ 421 parameters << parameter; 422 } 423 424 /* Return parameters: */ 425 return parameters; 426 } 427 428 /* static */ 429 bool UIWizardExportAppPage2::parseJsonFieldBool(const QString &strFieldName, const QJsonValue &field) 430 { 431 /* Make sure field is bool: */ 432 Q_UNUSED(strFieldName); 433 AssertMsgReturn(field.isBool(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), false); 434 const bool fFieldValue = field.toBool(); 435 //printf(" Field value: \"%s\"\n", fFieldValue ? "true" : "false"); 436 437 return fFieldValue; 438 } 439 440 /* static */ 441 double UIWizardExportAppPage2::parseJsonFieldDouble(const QString &strFieldName, const QJsonValue &field) 442 { 443 /* Make sure field is double: */ 444 Q_UNUSED(strFieldName); 445 AssertMsgReturn(field.isDouble(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), 0); 446 const double dFieldValue = field.toDouble(); 447 //printf(" Field value: \"%f\"\n", dFieldValue); 448 449 return dFieldValue; 450 } 451 452 /* static */ 453 QString UIWizardExportAppPage2::parseJsonFieldString(const QString &strFieldName, const QJsonValue &field) 454 { 455 /* Make sure field is string: */ 456 Q_UNUSED(strFieldName); 457 AssertMsgReturn(field.isString(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), QString()); 458 const QString strFieldValue = field.toString(); 459 //printf(" Field value: \"%s\"\n", strFieldValue.toUtf8().constData()); 460 461 return strFieldValue; 462 } 463 464 /* static */ 465 QIStringPairList UIWizardExportAppPage2::parseJsonFieldArray(const QString &strFieldName, const QJsonValue &field) 466 { 467 /* Make sure field is array: */ 468 Q_UNUSED(strFieldName); 469 AssertMsgReturn(field.isArray(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), QIStringPairList()); 470 const QJsonArray fieldValueArray = field.toArray(); 471 QIStringPairList fieldValueStringPairList; 472 /* Parse array: */ 473 for (int i = 0; i < fieldValueArray.count(); ++i) 474 { 475 /* Parse current array value: */ 476 const QJsonValue value = fieldValueArray[i]; 477 /* If value is of string type, we just take it: */ 478 if (value.isString()) 479 fieldValueStringPairList << qMakePair(fieldValueArray[i].toString(), QString()); 480 /* If value is of object type, we take object key/value pairs: */ 481 else if (value.isObject()) 482 { 483 const QJsonObject valueObject = value.toObject(); 484 foreach (const QString &strKey, valueObject.keys()) 485 fieldValueStringPairList << qMakePair(strKey, valueObject.value(strKey).toString()); 486 } 487 } 488 //QStringList test; 489 //foreach (const QIStringPair &pair, fieldValueStringPairList) 490 // if (pair.second.isNull()) 491 // test << QString("{%1}").arg(pair.first); 492 // else 493 // test << QString("{%1 : %2}").arg(pair.first, pair.second); 494 //printf(" Field value: \"%s\"\n", test.join(", ").toUtf8().constData()); 495 496 return fieldValueStringPairList; 371 while (0); 372 } 497 373 } 498 374 … … 735 611 } 736 612 737 AbstractVSDParameterList UIWizardExportAppPage2::cloudClientParameters() const 738 { 739 return m_cloudClientParameters; 613 CAppliance UIWizardExportAppPage2::appliance() const 614 { 615 return m_comAppliance; 616 } 617 618 CVirtualSystemDescriptionForm UIWizardExportAppPage2::vsdForm() const 619 { 620 return m_comVSDForm; 740 621 } 741 622 … … 1018 899 this, &UIWizardExportAppPageBasic2::sltHandleAccountButtonClick); 1019 900 1020 /* Register classes: */1021 qRegisterMetaType<AbstractVSDParameterList>();1022 901 /* Register fields: */ 1023 902 registerField("format", this, "format"); … … 1028 907 registerField("includeISOsSelected", this, "includeISOsSelected"); 1029 908 registerField("providerShortName", this, "providerShortName"); 1030 registerField("cloudClientParameters", this, "cloudClientParameters"); 909 registerField("appliance", this, "appliance"); 910 registerField("vsdForm", this, "vsdForm"); 1031 911 } 1032 912 … … 1181 1061 if (isFormatCloudOne()) 1182 1062 { 1183 /* Populate cloud client parameters: */ 1184 populateCloudClientParameters(); 1185 /* Which is required to continue to the next page: */ 1186 fResult = !field("cloudClientParameters").value<AbstractVSDParameterList>().isEmpty(); 1063 /* Create appliance and populate form properties: */ 1064 populateFormProperties(); 1065 /* Which are required to continue to the next page: */ 1066 fResult = field("appliance").value<CAppliance>().isNotNull() 1067 && field("vsdForm").value<CVirtualSystemDescriptionForm>().isNotNull(); 1187 1068 } 1188 1069 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic2.h
r78077 r78989 31 31 /* COM includes: */ 32 32 #include "COMEnums.h" 33 #include "CAppliance.h" 33 34 #include "CCloudProfile.h" 34 35 #include "CCloudProvider.h" 35 36 #include "CCloudProviderManager.h" 37 #include "CVirtualSystemDescriptionForm.h" 36 38 37 39 /* Forward declarations: */ … … 90 92 /** Populates account properties. */ 91 93 void populateAccountProperties(); 92 /** Populates cloud client parameters. */ 93 void populateCloudClientParameters(); 94 95 /** Parses JSON @a document. */ 96 static AbstractVSDParameterList parseJsonDocument(const QJsonDocument &document); 97 /** Parses JSON bool @a field. */ 98 static bool parseJsonFieldBool(const QString &strFieldName, const QJsonValue &field); 99 /** Parses JSON double @a field. */ 100 static double parseJsonFieldDouble(const QString &strFieldName, const QJsonValue &field); 101 /** Parses JSON string @a field. */ 102 static QString parseJsonFieldString(const QString &strFieldName, const QJsonValue &field); 103 /** Parses JSON array @a field. */ 104 static QIStringPairList parseJsonFieldArray(const QString &strFieldName, const QJsonValue &field); 94 /** Populates form properties. */ 95 void populateFormProperties(); 105 96 106 97 /** Updates page appearance. */ … … 162 153 /** Returns profile name. */ 163 154 QString profileName() const; 164 /** Returns Cloud Client parameters. */ 165 AbstractVSDParameterList cloudClientParameters() const; 155 /** Returns Appliance object. */ 156 CAppliance appliance() const; 157 /** Returns Virtual System Description Form object. */ 158 CVirtualSystemDescriptionForm vsdForm() const; 166 159 167 160 /** Holds whether default format should be Export to OCI. */ … … 169 162 170 163 /** Holds the Cloud Provider Manager reference. */ 171 CCloudProviderManager m_comCloudProviderManager;164 CCloudProviderManager m_comCloudProviderManager; 172 165 /** Holds the Cloud Provider object reference. */ 173 CCloudProvider m_comCloudProvider;166 CCloudProvider m_comCloudProvider; 174 167 /** Holds the Cloud Profile object reference. */ 175 CCloudProfile m_comCloudProfile; 176 /** Holds the cloud client parameters. */ 177 AbstractVSDParameterList m_cloudClientParameters; 168 CCloudProfile m_comCloudProfile; 169 /** Holds the Appliance object reference. */ 170 CAppliance m_comAppliance; 171 /** Holds the Virtual System Description Form object reference. */ 172 CVirtualSystemDescriptionForm m_comVSDForm; 178 173 179 174 /** Holds the default appliance name. */ … … 239 234 Q_PROPERTY(bool includeISOsSelected READ isIncludeISOsSelected WRITE setIncludeISOsSelected); 240 235 Q_PROPERTY(QString providerShortName READ providerShortName); 241 Q_PROPERTY(AbstractVSDParameterList cloudClientParameters READ cloudClientParameters); 236 Q_PROPERTY(CAppliance appliance READ appliance); 237 Q_PROPERTY(CVirtualSystemDescriptionForm vsdForm READ vsdForm); 242 238 243 239 public: … … 251 247 virtual bool event(QEvent *pEvent) /* override */; 252 248 249 /** Allows access wizard from base part. */ 250 UIWizard *wizardImp() { return UIWizardPage::wizard(); } 253 251 /** Allows access wizard-field from base part. */ 254 252 QVariant fieldImp(const QString &strFieldName) const { return UIWizardPage::field(strFieldName); } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageExpert.cpp
r78988 r78989 347 347 /* Populate account properties: */ 348 348 populateAccountProperties(); 349 /* Populate cloud client parameters: */350 populate CloudClientParameters();349 /* Populate form properties: */ 350 populateFormProperties(); 351 351 352 352 /* Setup connections: */ … … 369 369 qRegisterMetaType<ExportAppliancePointer>(); 370 370 371 /* Register classes: */372 qRegisterMetaType<AbstractVSDParameterList>();373 371 /* Register fields: */ 374 372 registerField("machineNames", this, "machineNames"); … … 381 379 registerField("includeISOsSelected", this, "includeISOsSelected"); 382 380 registerField("providerShortName", this, "providerShortName"); 383 registerField("cloudClientParameters", this, "cloudClientParameters"); 381 registerField("appliance", this, "appliance"); 382 registerField("vsdForm", this, "vsdForm"); 384 383 registerField("applianceWidget", this, "applianceWidget"); 385 384 } … … 528 527 || ( fCSP 529 528 && m_comCloudProfile.isNotNull() 530 && !m_cloudClientParameters.isEmpty()); 529 && m_comAppliance.isNotNull() 530 && m_comVSDForm.isNotNull()); 531 531 } 532 532 … … 574 574 populateAccounts(); 575 575 populateAccountProperties(); 576 populate CloudClientParameters();576 populateFormProperties(); 577 577 refreshApplianceSettingsWidget(); 578 578 emit completeChanged(); … … 599 599 /* Refresh required settings: */ 600 600 populateAccountProperties(); 601 populate CloudClientParameters();601 populateFormProperties(); 602 602 refreshApplianceSettingsWidget(); 603 603 emit completeChanged(); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageExpert.h
r78077 r78989 46 46 Q_PROPERTY(bool includeISOsSelected READ isIncludeISOsSelected WRITE setIncludeISOsSelected); 47 47 Q_PROPERTY(QString providerShortName READ providerShortName); 48 Q_PROPERTY(AbstractVSDParameterList cloudClientParameters READ cloudClientParameters); 48 Q_PROPERTY(CAppliance appliance READ appliance); 49 Q_PROPERTY(CVirtualSystemDescriptionForm vsdForm READ vsdForm); 49 50 Q_PROPERTY(ExportAppliancePointer applianceWidget READ applianceWidget); 50 51
Note:
See TracChangeset
for help on using the changeset viewer.