VirtualBox

Changeset 73318 in vbox


Ignore:
Timestamp:
Jul 23, 2018 12:58:55 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9152: Export Appliance wizard: Virtual System Description page: Parse abstract set of cloud-client parameters for export VM operation.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.h

    r73062 r73318  
    4040class QVBoxLayout;
    4141
     42
     43/** Cloud Client Parameter internal kinds. */
     44enum CloudClientParameterKind
     45{
     46    ParameterKind_Invalid,
     47    ParameterKind_Bool,
     48    ParameterKind_Double,
     49    ParameterKind_String,
     50    ParameterKind_Array
     51};
     52
     53/** CloudClient parameter of Bool type, internal level. */
     54struct CloudClientParameterBool
     55{
     56    /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
     57    CloudClientParameterBool()
     58        : value(false) {}
     59    /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
     60    CloudClientParameterBool(const CloudClientParameterBool &other)
     61        : value(other.value) {}
     62    /** Holds the value. */
     63    bool value;
     64};
     65Q_DECLARE_METATYPE(CloudClientParameterBool);
     66
     67/** CloudClient parameter of Double type, internal level. */
     68struct CloudClientParameterDouble
     69{
     70    /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
     71    CloudClientParameterDouble()
     72        : minimum(0), maximum(0), unit(QString()) {}
     73    /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
     74    CloudClientParameterDouble(const CloudClientParameterDouble &other)
     75        : minimum(other.minimum), maximum(other.maximum), unit(other.unit) {}
     76    /** Holds the minimum/base value. */
     77    double   minimum;
     78    /** Holds the maximum value. */
     79    double   maximum;
     80    /** Holds the unit. */
     81    QString  unit;
     82};
     83Q_DECLARE_METATYPE(CloudClientParameterDouble);
     84
     85/** CloudClient parameter of String type, internal level. */
     86struct CloudClientParameterString
     87{
     88    /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
     89    CloudClientParameterString()
     90        : value(QString()) {}
     91    /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
     92    CloudClientParameterString(const CloudClientParameterString &other)
     93        : value(other.value) {}
     94    /** Holds the value. */
     95    QString value;
     96};
     97Q_DECLARE_METATYPE(CloudClientParameterString);
     98
     99/** CloudClient parameter of Array type, internal level. */
     100struct CloudClientParameterArray
     101{
     102    /** Public default constructor to fit Q_DECLARE_METATYPE rule. */
     103    CloudClientParameterArray()
     104        : values(QStringList()) {}
     105    /** Public copy constructor to fit Q_DECLARE_METATYPE rule. */
     106    CloudClientParameterArray(const CloudClientParameterArray &other)
     107        : values(other.values) {}
     108    /** Holds the values array. */
     109    QStringList values;
     110};
     111Q_DECLARE_METATYPE(CloudClientParameterArray);
     112
     113/** CloudClient parameter interface, facade level. */
     114struct CloudClientParameter
     115{
     116    /** Holds the parameter name. */
     117    QString                        name;
     118    /** Holds the parameter type. */
     119    KVirtualSystemDescriptionType  type;
     120    /** Holds the parameter kind. */
     121    CloudClientParameterKind       kind;
     122    /** Holds the parameter abstract getter. */
     123    QVariant                       get;
     124};
     125
     126
    42127/** Appliance tree-view section types. */
    43128enum ApplianceViewSection
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic4.cpp

    r73147 r73318  
    2121
    2222/* Qt includes: */
     23# include <QJsonArray>
     24# include <QJsonDocument>
     25# include <QJsonObject>
     26# include <QJsonValue>
    2327# include <QVBoxLayout>
    2428
     
    3337/* COM includes: */
    3438# include "CAppliance.h"
     39# include "CCloudClient.h"
     40# include "CCloudUserProfileList.h"
    3541# include "CMachine.h"
    3642
     
    4450UIWizardExportAppPage4::UIWizardExportAppPage4()
    4551{
     52}
     53
     54void UIWizardExportAppPage4::populateCloudClientParameters()
     55{
     56    /* Forget current parameters: */
     57    m_listCloudClientParameters.clear();
     58
     59    /* Acquire Cloud User-profiles: */
     60    CCloudUserProfileList comCloudUserProfiles = fieldImp("profiles").value<CCloudUserProfileList>();
     61    AssertMsgReturnVoid(comCloudUserProfiles.isNotNull(),
     62                        ("Cloud User-profiles object is undefined!"));
     63
     64    /* Create Cloud Client: */
     65    CCloudClient comCloudClient = comCloudUserProfiles.CreateCloudClient(fieldImp("profile").toString());
     66    AssertMsgReturnVoid(comCloudUserProfiles.isOk() && comCloudClient.isNotNull(),
     67                        ("Can't create Cloud Client object!"));
     68
     69    /* Read Cloud Client parameters for Export VM operation: */
     70    const QString strJSON = comCloudClient.GetOperationParameters(KCloudOperation_exportVM);
     71
     72    /* Create JSON document on the basis of it, make sure it isn't empty: */
     73    const QJsonDocument document = QJsonDocument::fromJson(strJSON.toUtf8());
     74    AssertMsgReturnVoid(!document.isEmpty(), ("Document is empty!"));
     75
     76    /* Parse JSON document: */
     77    m_listCloudClientParameters = parseJsonDocument(document);
     78}
     79
     80/* static */
     81QList<CloudClientParameter> UIWizardExportAppPage4::parseJsonDocument(const QJsonDocument &document)
     82{
     83    /* Prepare parameters: */
     84    QList<CloudClientParameter> parameters;
     85
     86    /* Convert document to object, make sure it isn't empty: */
     87    QJsonObject documentObject = document.object();
     88    AssertMsgReturn(!documentObject.isEmpty(), ("Document object is empty!"), parameters);
     89
     90    /* Iterate through document object values: */
     91    foreach (const QString &strElementName, documentObject.keys())
     92    {
     93        //printf("Element name: \"%s\"\n", strElementName.toUtf8().constData());
     94
     95        /* Prepare parameter: */
     96        CloudClientParameter parameter;
     97
     98        /* Assign name: */
     99        parameter.name = strElementName;
     100
     101        /* Acquire element, make sure it's an object: */
     102        const QJsonValue element = documentObject.value(strElementName);
     103        AssertMsg(element.isObject(), ("Element '%s' has wrong structure!", strElementName.toUtf8().constData()));
     104        if (!element.isObject())
     105            continue;
     106
     107        /* Convert element to object, make sure it isn't empty: */
     108        const QJsonObject elementObject = element.toObject();
     109        AssertMsg(!elementObject.isEmpty(), ("Element '%s' object has wrong structure!", strElementName.toUtf8().constData()));
     110        if (elementObject.isEmpty())
     111            continue;
     112
     113        /* Iterate through element object values: */
     114        foreach (const QString &strFieldName, elementObject.keys())
     115        {
     116            //printf(" Field name: \"%s\"\n", strFieldName.toUtf8().constData());
     117
     118            /* Acquire field: */
     119            const QJsonValue field = elementObject.value(strFieldName);
     120
     121            /* Parse known fields: */
     122            if (strFieldName == "type")
     123                parameter.type = (KVirtualSystemDescriptionType)(int)parseJsonFieldDouble(strFieldName, field);
     124            else
     125            if (strFieldName == "bool")
     126            {
     127                CloudClientParameterBool get;
     128                get.value = parseJsonFieldBool(strFieldName, field);
     129                parameter.get = QVariant::fromValue(get);
     130                parameter.kind = ParameterKind_Bool;
     131            }
     132            else
     133            if (strFieldName == "min")
     134            {
     135                CloudClientParameterDouble get = parameter.get.value<CloudClientParameterDouble>();
     136                get.minimum = parseJsonFieldDouble(strFieldName, field);
     137                parameter.get = QVariant::fromValue(get);
     138                parameter.kind = ParameterKind_Double;
     139            }
     140            else
     141            if (strFieldName == "max")
     142            {
     143                CloudClientParameterDouble get = parameter.get.value<CloudClientParameterDouble>();
     144                get.maximum = parseJsonFieldDouble(strFieldName, field);
     145                parameter.get = QVariant::fromValue(get);
     146                parameter.kind = ParameterKind_Double;
     147            }
     148            else
     149            if (strFieldName == "unit")
     150            {
     151                CloudClientParameterDouble get = parameter.get.value<CloudClientParameterDouble>();
     152                get.unit = parseJsonFieldString(strFieldName, field);
     153                parameter.get = QVariant::fromValue(get);
     154                parameter.kind = ParameterKind_Double;
     155            }
     156            else
     157            if (strFieldName == "items")
     158            {
     159                CloudClientParameterArray get;
     160                get.values = parseJsonFieldArray(strFieldName, field);
     161                parameter.get = QVariant::fromValue(get);
     162                parameter.kind = ParameterKind_Array;
     163            }
     164        }
     165
     166        /* Append parameter: */
     167        parameters << parameter;
     168    }
     169
     170    /* Return parameters: */
     171    return parameters;
     172}
     173
     174/* static */
     175bool UIWizardExportAppPage4::parseJsonFieldBool(const QString &strFieldName, const QJsonValue &field)
     176{
     177    /* Make sure field is bool: */
     178    AssertMsgReturn(field.isBool(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), false);
     179
     180    const bool fFieldValue = field.toBool();
     181    //printf("  Field value: \"%s\"\n", fFieldValue ? "true" : "false");
     182
     183    return fFieldValue;
     184}
     185
     186/* static */
     187double UIWizardExportAppPage4::parseJsonFieldDouble(const QString &strFieldName, const QJsonValue &field)
     188{
     189    /* Make sure field is double: */
     190    AssertMsgReturn(field.isDouble(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), 0);
     191
     192    const double dFieldValue = field.toDouble();
     193    //printf("  Field value: \"%f\"\n", dFieldValue);
     194
     195    return dFieldValue;
     196}
     197
     198/* static */
     199QString UIWizardExportAppPage4::parseJsonFieldString(const QString &strFieldName, const QJsonValue &field)
     200{
     201    /* Make sure field is string: */
     202    AssertMsgReturn(field.isString(), ("Field '%s' has wrong structure!", strFieldName.toUtf8().constData()), QString());
     203
     204    const QString strFieldValue = field.toString();
     205    //printf("  Field value: \"%s\"\n", strFieldValue.toUtf8().constData());
     206
     207    return strFieldValue;
     208}
     209
     210/* static */
     211QStringList UIWizardExportAppPage4::parseJsonFieldArray(const QString &strFieldName, const QJsonValue &field)
     212{
     213    /* Make sure field is array: */
     214    AssertMsgReturn(field.isArray(), ("Item '%s' has wrong structure!", strFieldName.toUtf8().constData()), QStringList());
     215
     216    const QJsonArray fieldValueArray = field.toArray();
     217    QStringList fieldValueStirngList;
     218    for (int i = 0; i < fieldValueArray.count(); ++i)
     219        fieldValueStirngList << fieldValueArray[i].toString();
     220    //printf("  Field value: \"%s\"\n", fieldValueStirngList.join(", ").toUtf8().constData());
     221
     222    return fieldValueStirngList;
    46223}
    47224
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic4.h

    r72920 r73318  
    2020
    2121/* Qt includes: */
     22#include <QList>
    2223#include <QVariant>
    2324
     
    2728
    2829/* Forward declarations: */
     30class QJsonDocument;
     31class QJsonValue;
    2932class QIRichTextLabel;
    3033class UIWizardExportApp;
     
    3942    UIWizardExportAppPage4();
    4043
     44    /** Populates cloud client parameters. */
     45    void populateCloudClientParameters();
     46
     47    /** Parses JSON @a document. */
     48    static QList<CloudClientParameter> parseJsonDocument(const QJsonDocument &document);
     49    /** Parses JSON bool @a field. */
     50    static bool parseJsonFieldBool(const QString &strFieldName, const QJsonValue &field);
     51    /** Parses JSON double @a field. */
     52    static double parseJsonFieldDouble(const QString &strFieldName, const QJsonValue &field);
     53    /** Parses JSON string @a field. */
     54    static QString parseJsonFieldString(const QString &strFieldName, const QJsonValue &field);
     55    /** Parses JSON array @a field. */
     56    static QStringList parseJsonFieldArray(const QString &strFieldName, const QJsonValue &field);
     57
    4158    /** Refreshes appliance settings widget. */
    4259    void refreshApplianceSettingsWidget();
     
    4461    /** Returns the appliance widget reference. */
    4562    ExportAppliancePointer applianceWidget() const { return m_pApplianceWidget; }
     63
     64    /** Holds the cloud client parameters. */
     65    QList<CloudClientParameter> m_listCloudClientParameters;
    4666
    4767    /** Holds the appliance widget reference. */
Note: See TracChangeset for help on using the changeset viewer.

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