VirtualBox

Changeset 86696 in vbox


Ignore:
Timestamp:
Oct 23, 2020 5:31:51 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141079
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Cloud Profile Manager: Replace direct COM getter calls to UICloudNetworkingStuff namespace stuff; Corresponding code is reusable and tested for API call failures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/profilemanager/UICloudProfileManager.cpp

    r86692 r86696  
    252252void UICloudProfileManagerWidget::sltApplyCloudProfileDetailsChanges()
    253253{
    254     /* It can be that there is provider item, not profile item currently selected.
     254    /* It can be that this is provider item, not profile item currently selected.
    255255     * In such case we are not applying parameters, we are creating new one profile. */
    256256    QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
     
    261261    /* Get profile item: */
    262262    UIItemCloudProfile *pProfileItem = qobject_cast<UIItemCloudProfile*>(pItem);
    263     AssertMsgReturnVoid(pProfileItem, ("Current item must not be null!\n"));
    264 
    265     /* Get item data: */
    266     UIDataCloudProfile oldData = *pProfileItem;
    267     UIDataCloudProfile newData = m_pDetailsWidget->data();
    268 
    269     /* Get VirtualBox for further activities: */
    270     const CVirtualBox comVBox = uiCommon().virtualBox();
    271 
    272     /* Get CloudProviderManager for further activities: */
    273     CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
    274     /* Show error message if necessary: */
    275     if (!comVBox.isOk())
    276         msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
    277     else
    278     {
    279         /* Get provider item: */
    280         UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pProfileItem->parentItem());
    281         /* Acquire provider short name: */
    282         const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
    283 
    284         /* Look for corresponding provider: */
    285         CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderByShortName(strShortName);
    286         /* Show error message if necessary: */
    287         if (!comCloudProviderManager.isOk())
    288             msgCenter().cannotAcquireCloudProviderManagerParameter(comCloudProviderManager, this);
    289         else
     263    AssertPtrReturnVoid(pProfileItem);
     264    /* Get provider item: */
     265    UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pProfileItem->parentItem());
     266    AssertPtrReturnVoid(pProviderItem);
     267
     268    /* Acquire provider short name: */
     269    const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
     270
     271    /* Look for corresponding provider: */
     272    CCloudProvider comCloudProvider = cloudProviderByShortName(strShortName, this);
     273    if (comCloudProvider.isNotNull())
     274    {
     275        /* Get old/new data: */
     276        UIDataCloudProfile oldData = *pProfileItem;
     277        UIDataCloudProfile newData = m_pDetailsWidget->data();
     278
     279        /* Look for corresponding profile: */
     280        CCloudProfile comCloudProfile = cloudProfileByName(strShortName, oldData.m_strName, this);
     281        if (comCloudProfile.isNotNull())
    290282        {
    291             /* Look for corresponding profile: */
    292             CCloudProfile comCloudProfile = comCloudProvider.GetProfileByName(oldData.m_strName);
     283            /* Set profile name, if necessary: */
     284            if (newData.m_strName != oldData.m_strName)
     285                comCloudProfile.SetName(newData.m_strName);
    293286            /* Show error message if necessary: */
    294             if (!comCloudProvider.isOk())
    295                 msgCenter().cannotFindCloudProfile(comCloudProvider, oldData.m_strName, this);
     287            if (!comCloudProfile.isOk())
     288                msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
    296289            else
    297290            {
    298                 /* Set profile name, if necessary: */
    299                 if (newData.m_strName != oldData.m_strName)
    300                     comCloudProfile.SetName(newData.m_strName);
    301                 /* Show error message if necessary: */
    302                 if (!comCloudProfile.isOk())
    303                     msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
    304                 else
     291                /* Iterate through old/new data: */
     292                foreach (const QString &strKey, oldData.m_data.keys())
    305293                {
    306                     /* Iterate through old/new data: */
    307                     foreach (const QString &strKey, oldData.m_data.keys())
     294                    /* Get values: */
     295                    const QString strOldValue = oldData.m_data.value(strKey).first;
     296                    const QString strNewValue = newData.m_data.value(strKey).first;
     297                    if (strNewValue != strOldValue)
    308298                    {
    309                         /* Get values: */
    310                         const QString strOldValue = oldData.m_data.value(strKey).first;
    311                         const QString strNewValue = newData.m_data.value(strKey).first;
    312                         if (strNewValue != strOldValue)
     299                        /* Apply property: */
     300                        comCloudProfile.SetProperty(strKey, strNewValue);
     301                        /* Show error message if necessary: */
     302                        if (!comCloudProfile.isOk())
    313303                        {
    314                             /* Apply property: */
    315                             comCloudProfile.SetProperty(strKey, strNewValue);
    316                             /* Show error message if necessary: */
    317                             if (!comCloudProfile.isOk())
    318                             {
    319                                 msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
    320                                 break;
    321                             }
     304                            msgCenter().cannotAssignCloudProfileParameter(comCloudProfile, this);
     305                            break;
    322306                        }
    323307                    }
    324308                }
    325 
    326                 /* If profile is Ok finally: */
    327                 if (comCloudProfile.isOk())
    328                 {
    329                     /* Save profile changes: */
    330                     comCloudProvider.SaveProfiles();
    331                     /* Show error message if necessary: */
    332                     if (!comCloudProvider.isOk())
    333                         msgCenter().cannotSaveCloudProfiles(comCloudProvider, this);
    334                 }
     309            }
     310
     311            /* If profile is Ok finally: */
     312            if (comCloudProfile.isOk())
     313            {
     314                /* Save profile changes: */
     315                comCloudProvider.SaveProfiles();
     316                /* Show error message if necessary: */
     317                if (!comCloudProvider.isOk())
     318                    msgCenter().cannotSaveCloudProfiles(comCloudProvider, this);
    335319            }
    336320        }
     
    343327    QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
    344328    UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pItem);
    345     AssertMsgReturnVoid(pProviderItem, ("Current item must not be null!\n"));
     329    AssertPtrReturnVoid(pProviderItem);
    346330
    347331    /* Acquire profile name if not proposed by details widget: */
     
    366350    }
    367351
    368     /* Get VirtualBox for further activities: */
    369     const CVirtualBox comVBox = uiCommon().virtualBox();
    370 
    371     /* Get CloudProviderManager for further activities: */
    372     CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
    373     /* Show error message if necessary: */
    374     if (!comVBox.isOk())
    375         msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
    376     else
    377     {
    378         /* Acquire provider short name: */
    379         const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
    380 
    381         /* Look for corresponding provider: */
    382         CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderByShortName(strShortName);
     352    /* Acquire provider short name: */
     353    const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
     354
     355    /* Look for corresponding provider: */
     356    CCloudProvider comCloudProvider = cloudProviderByShortName(strShortName, this);
     357    if (comCloudProvider.isNotNull())
     358    {
     359        /* Create new profile: */
     360        const QVector<QString> keys = pProviderItem->m_propertyDescriptions.keys().toVector();
     361        const QVector<QString> values(keys.size());
     362        comCloudProvider.CreateProfile(strProfileName, keys, values);
    383363        /* Show error message if necessary: */
    384         if (!comCloudProviderManager.isOk())
    385             msgCenter().cannotAcquireCloudProviderManagerParameter(comCloudProviderManager, this);
     364        if (!comCloudProvider.isOk())
     365            msgCenter().cannotCreateCloudProfile(comCloudProvider, this);
    386366        else
    387367        {
    388             /* Create new profile: */
    389             const QVector<QString> keys = pProviderItem->m_propertyDescriptions.keys().toVector();
    390             const QVector<QString> values(keys.size());
    391             comCloudProvider.CreateProfile(strProfileName, keys, values);
     368            /* Save profile changes: */
     369            comCloudProvider.SaveProfiles();
    392370            /* Show error message if necessary: */
    393371            if (!comCloudProvider.isOk())
    394                 msgCenter().cannotCreateCloudProfile(comCloudProvider, this);
    395             else
    396             {
    397                 /* Save profile changes: */
    398                 comCloudProvider.SaveProfiles();
    399                 /* Show error message if necessary: */
    400                 if (!comCloudProvider.isOk())
    401                     msgCenter().cannotSaveCloudProfiles(comCloudProvider, this);
    402             }
     372                msgCenter().cannotSaveCloudProfiles(comCloudProvider, this);
    403373        }
    404374    }
     
    410380    QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
    411381    UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pItem);
    412     AssertMsgReturnVoid(pProviderItem, ("Current item must not be null!\n"));
     382    AssertPtrReturnVoid(pProviderItem);
    413383
    414384    /* If there are profiles exist => confirm cloud profile import. */
     
    417387        return;
    418388
    419     /* Get VirtualBox for further activities: */
    420     const CVirtualBox comVBox = uiCommon().virtualBox();
    421 
    422     /* Get CloudProviderManager for further activities: */
    423     CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
    424     /* Show error message if necessary: */
    425     if (!comVBox.isOk())
    426         msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
    427     else
    428     {
    429         /* Acquire provider short name: */
    430         const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
    431 
    432         /* Look for corresponding provider: */
    433         CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderByShortName(strShortName);
     389    /* Acquire provider short name: */
     390    const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
     391
     392    /* Look for corresponding provider: */
     393    CCloudProvider comCloudProvider = cloudProviderByShortName(strShortName, this);
     394    if (comCloudProvider.isNotNull())
     395    {
     396        /* Import profiles: */
     397        comCloudProvider.ImportProfiles();
    434398        /* Show error message if necessary: */
    435         if (!comCloudProviderManager.isOk())
    436             msgCenter().cannotAcquireCloudProviderManagerParameter(comCloudProviderManager, this);
    437         else
    438         {
    439             /* Import profiles: */
    440             comCloudProvider.ImportProfiles();
    441 
    442             /* Show error message if necessary: */
    443             if (!comCloudProvider.isOk())
    444                 msgCenter().cannotImportCloudProfiles(comCloudProvider, this);
    445         }
     399        if (!comCloudProvider.isOk())
     400            msgCenter().cannotImportCloudProfiles(comCloudProvider, this);
    446401    }
    447402}
     
    452407    QITreeWidgetItem *pItem = QITreeWidgetItem::toItem(m_pTreeWidget->currentItem());
    453408    UIItemCloudProfile *pProfileItem = qobject_cast<UIItemCloudProfile*>(pItem);
    454     AssertMsgReturnVoid(pProfileItem, ("Current item must not be null!\n"));
    455 
    456     /* Get profile name: */
    457     const QString strProfileName(pProfileItem->name());
     409    AssertPtrReturnVoid(pProfileItem);
     410    /* Get provider item: */
     411    UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pProfileItem->parentItem());
     412    AssertPtrReturnVoid(pProviderItem);
     413
     414    /* Acquire profile name: */
     415    const QString strProfileName = pProfileItem->name();
    458416
    459417    /* Confirm cloud profile removal: */
     
    461419        return;
    462420
    463     /* Get VirtualBox for further activities: */
    464     const CVirtualBox comVBox = uiCommon().virtualBox();
    465 
    466     /* Get CloudProviderManager for further activities: */
    467     CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
    468     /* Show error message if necessary: */
    469     if (!comVBox.isOk())
    470         msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
    471     else
    472     {
    473         /* Get provider item: */
    474         UIItemCloudProvider *pProviderItem = qobject_cast<UIItemCloudProvider*>(pProfileItem->parentItem());
    475         /* Acquire provider short name: */
    476         const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
    477 
    478         /* Look for corresponding provider: */
    479         CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderByShortName(strShortName);
    480         /* Show error message if necessary: */
    481         if (!comCloudProviderManager.isOk())
    482             msgCenter().cannotAcquireCloudProviderManagerParameter(comCloudProviderManager, this);
    483         else
     421    /* Acquire provider short name: */
     422    const QString strShortName = pProviderItem->data(Column_Name, Data_ProviderShortName).toString();
     423
     424    /* Look for corresponding provider: */
     425    CCloudProvider comCloudProvider = cloudProviderByShortName(strShortName, this);
     426    if (comCloudProvider.isNotNull())
     427    {
     428        /* Look for corresponding profile: */
     429        CCloudProfile comCloudProfile = cloudProfileByName(strShortName, strProfileName, this);
     430        if (comCloudProfile.isNotNull())
    484431        {
    485             /* Look for corresponding profile: */
    486             CCloudProfile comCloudProfile = comCloudProvider.GetProfileByName(strProfileName);
     432            /* Remove current profile: */
     433            comCloudProfile.Remove();
    487434            /* Show error message if necessary: */
    488             if (!comCloudProvider.isOk())
    489                 msgCenter().cannotFindCloudProfile(comCloudProvider, strProfileName, this);
     435            if (!comCloudProfile.isOk())
     436                msgCenter().cannotRemoveCloudProfile(comCloudProfile, this);
    490437            else
    491438            {
    492                 /* Remove current profile: */
    493                 comCloudProfile.Remove();
    494                 /* Show error message if necessary: */
    495                 if (!comCloudProfile.isOk())
    496                     msgCenter().cannotRemoveCloudProfile(comCloudProfile, this);
    497 
    498439                /* Save profile changes: */
    499440                comCloudProvider.SaveProfiles();
     
    855796    /* Gather provider settings: */
    856797    if (comProvider.isOk())
    857         providerData.m_uId = comProvider.GetId();
     798        cloudProviderId(comProvider, providerData.m_uId, this);
    858799    if (comProvider.isOk())
    859         providerData.m_strShortName = comProvider.GetShortName();
     800        cloudProviderShortName(comProvider, providerData.m_strShortName);
    860801    if (comProvider.isOk())
    861         providerData.m_strName = comProvider.GetName();
    862     const QString strProviderPath = UIItemCloudProvider::definition(providerData.m_strShortName);
    863     providerData.m_fRestricted = restrictions.contains(strProviderPath);
     802        cloudProviderName(comProvider, providerData.m_strName);
     803    providerData.m_fRestricted = restrictions.contains(UIItemCloudProvider::definition(providerData.m_strShortName));
    864804    foreach (const QString &strSupportedPropertyName, comProvider.GetSupportedPropertyNames())
    865805        providerData.m_propertyDescriptions[strSupportedPropertyName] = comProvider.GetPropertyDescription(strSupportedPropertyName);
    866 
    867     /* Show error message if necessary: */
    868     if (!comProvider.isOk())
    869         msgCenter().cannotAcquireCloudProviderParameter(comProvider, this);
    870806}
    871807
     
    880816    /* Gather profile settings: */
    881817    if (comProfile.isOk())
    882         profileData.m_strName = comProfile.GetName();
    883     const QString strProfilePath = UIItemCloudProfile::definition(providerData.m_strShortName, profileData.m_strName);
    884     profileData.m_fRestricted = restrictions.contains(strProfilePath);
    885 
     818        cloudProfileName(comProfile, profileData.m_strName);
     819    profileData.m_fRestricted = restrictions.contains(UIItemCloudProfile::definition(providerData.m_strShortName, profileData.m_strName));
    886820    if (comProfile.isOk())
    887821    {
    888         /* Acquire properties: */
    889822        QVector<QString> keys;
    890823        QVector<QString> values;
    891         QVector<QString> descriptions;
    892         values = comProfile.GetProperties(QString(), keys);
    893 
    894         /* Sync sizes: */
    895         values.resize(keys.size());
    896         descriptions.resize(keys.size());
    897 
    898         if (comProfile.isOk())
    899         {
    900             /* Enumerate all the keys: */
     824        if (cloudProfileProperties(comProfile, keys, values))
    901825            for (int i = 0; i < keys.size(); ++i)
    902826                profileData.m_data[keys.at(i)] = qMakePair(values.at(i), providerData.m_propertyDescriptions.value(keys.at(i)));
    903         }
    904     }
    905 
    906     /* Show error message if necessary: */
    907     if (!comProfile.isOk())
    908         msgCenter().cannotAcquireCloudProfileParameter(comProfile, this);
     827    }
    909828}
    910829
Note: See TracChangeset for help on using the changeset viewer.

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