VirtualBox

Ignore:
Timestamp:
May 31, 2019 11:30:25 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131011
Message:

FE/Qt: bugref:9434: Import Appliance wizard: 1st page: A bit of local style cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic1.cpp

    r78880 r78892  
    6767void UIWizardImportAppPage1::populateSources()
    6868{
     69    /* To be executed just once, so combo should be empty: */
    6970    AssertReturnVoid(m_pSourceComboBox->count() == 0);
    7071
    71     /* Compose hardcoded sources list: */
     72    /* Compose hardcoded sources list, there might be few of list items: */
    7273    QStringList sources;
    7374    sources << "local";
     
    7576    foreach (const QString &strShortName, sources)
    7677    {
    77         /* Compose empty item, fill it's data: */
     78        /* Compose empty combo item, fill it's data: */
    7879        m_pSourceComboBox->addItem(QString());
    7980        m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, strShortName, SourceData_ShortName);
    8081    }
    8182
    82     /* Initialize Cloud Provider Manager: */
     83    /* Do we have OCI source? */
    8384    bool fOCIPresent = false;
    84     CVirtualBox comVBox = vboxGlobal().virtualBox();
    85     m_comCloudProviderManager = comVBox.GetCloudProviderManager();
    86     /* Show error message if necessary: */
    87     if (!comVBox.isOk())
    88         msgCenter().cannotAcquireCloudProviderManager(comVBox);
    89     else
    90     {
     85
     86    /* Main API request sequence, can be interrupted after any step: */
     87    do
     88    {
     89        /* Initialize Cloud Provider Manager: */
     90        CVirtualBox comVBox = vboxGlobal().virtualBox();
     91        m_comCloudProviderManager = comVBox.GetCloudProviderManager();
     92        if (!comVBox.isOk())
     93        {
     94            msgCenter().cannotAcquireCloudProviderManager(comVBox);
     95            break;
     96        }
     97
    9198        /* Acquire existing providers: */
    9299        const QVector<CCloudProvider> providers = m_comCloudProviderManager.GetProviders();
    93         /* Show error message if necessary: */
    94100        if (!m_comCloudProviderManager.isOk())
     101        {
    95102            msgCenter().cannotAcquireCloudProviderManagerParameter(m_comCloudProviderManager);
    96         else
    97         {
    98             /* Iterate through existing providers: */
    99             foreach (const CCloudProvider &comProvider, providers)
    100             {
    101                 /* Skip if we have nothing to populate (file missing?): */
    102                 if (comProvider.isNull())
    103                     continue;
    104 
    105                 /* Compose empty item, fill it's data: */
    106                 m_pSourceComboBox->addItem(QString());
    107                 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetId(),        SourceData_ID);
    108                 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetName(),      SourceData_Name);
    109                 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetShortName(), SourceData_ShortName);
    110                 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, true,                       SourceData_IsItCloudFormat);
    111                 if (m_pSourceComboBox->itemData(m_pSourceComboBox->count() - 1, SourceData_ShortName).toString() == "OCI")
    112                     fOCIPresent = true;
    113             }
    114         }
    115     }
     103            break;
     104        }
     105
     106        /* Iterate through existing providers: */
     107        foreach (const CCloudProvider &comProvider, providers)
     108        {
     109            /* Skip if we have nothing to populate (file missing?): */
     110            if (comProvider.isNull())
     111                continue;
     112
     113            /* Compose empty item, fill it's data: */
     114            m_pSourceComboBox->addItem(QString());
     115            m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetId(),        SourceData_ID);
     116            m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetName(),      SourceData_Name);
     117            m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetShortName(), SourceData_ShortName);
     118            m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, true,                       SourceData_IsItCloudFormat);
     119            if (m_pSourceComboBox->itemData(m_pSourceComboBox->count() - 1, SourceData_ShortName).toString() == "OCI")
     120                fOCIPresent = true;
     121        }
     122    }
     123    while (0);
    116124
    117125    /* Set default: */
     
    140148    if (!sourceId().isNull())
    141149    {
    142         /* (Re)initialize Cloud Provider: */
    143         m_comCloudProvider = m_comCloudProviderManager.GetProviderById(sourceId());
    144         /* Show error message if necessary: */
    145         if (!m_comCloudProviderManager.isOk())
    146             msgCenter().cannotFindCloudProvider(m_comCloudProviderManager, sourceId());
    147         else
    148         {
     150        /* Main API request sequence, can be interrupted after any step: */
     151        do
     152        {
     153            /* (Re)initialize Cloud Provider: */
     154            m_comCloudProvider = m_comCloudProviderManager.GetProviderById(sourceId());
     155            if (!m_comCloudProviderManager.isOk())
     156            {
     157                msgCenter().cannotFindCloudProvider(m_comCloudProviderManager, sourceId());
     158                break;
     159            }
     160
    149161            /* Acquire existing profile names: */
    150162            const QVector<QString> profileNames = m_comCloudProvider.GetProfileNames();
    151             /* Show error message if necessary: */
    152163            if (!m_comCloudProvider.isOk())
     164            {
    153165                msgCenter().cannotAcquireCloudProviderParameter(m_comCloudProvider);
    154             else
    155             {
    156                 /* Iterate through existing profile names: */
    157                 foreach (const QString &strProfileName, profileNames)
    158                 {
    159                     /* Skip if we have nothing to show (wtf happened?): */
    160                     if (strProfileName.isEmpty())
    161                         continue;
    162 
    163                     /* Compose item, fill it's data: */
    164                     m_pAccountComboBox->addItem(strProfileName);
    165                     m_pAccountComboBox->setItemData(m_pAccountComboBox->count() - 1, strProfileName, AccountData_ProfileName);
    166                 }
    167             }
    168         }
    169 
    170         /* Set previous/default item if possible: */
    171         int iNewIndex = -1;
    172         if (   iNewIndex == -1
    173             && !strOldData.isNull())
    174             iNewIndex = m_pAccountComboBox->findData(strOldData, AccountData_ProfileName);
    175         if (   iNewIndex == -1
    176             && m_pAccountComboBox->count() > 0)
    177             iNewIndex = 0;
    178         if (iNewIndex != -1)
    179             m_pAccountComboBox->setCurrentIndex(iNewIndex);
     166                break;
     167            }
     168
     169            /* Iterate through existing profile names: */
     170            foreach (const QString &strProfileName, profileNames)
     171            {
     172                /* Skip if we have nothing to show (wtf happened?): */
     173                if (strProfileName.isEmpty())
     174                    continue;
     175
     176                /* Compose item, fill it's data: */
     177                m_pAccountComboBox->addItem(strProfileName);
     178                m_pAccountComboBox->setItemData(m_pAccountComboBox->count() - 1, strProfileName, AccountData_ProfileName);
     179            }
     180
     181            /* Set previous/default item if possible: */
     182            int iNewIndex = -1;
     183            if (   iNewIndex == -1
     184                && !strOldData.isNull())
     185                iNewIndex = m_pAccountComboBox->findData(strOldData, AccountData_ProfileName);
     186            if (   iNewIndex == -1
     187                && m_pAccountComboBox->count() > 0)
     188                iNewIndex = 0;
     189            if (iNewIndex != -1)
     190                m_pAccountComboBox->setCurrentIndex(iNewIndex);
     191        }
     192        while (0);
    180193    }
    181194
     
    186199void UIWizardImportAppPage1::populateAccountProperties()
    187200{
     201    /* Block signals while updating: */
     202    m_pAccountPropertyTable->blockSignals(true);
     203
    188204    /* Clear table initially: */
    189205    m_pAccountPropertyTable->clear();
     
    194210
    195211    /* If both provider and profile chosen: */
    196     if (!m_comCloudProvider.isNull() && !profileName().isNull())
    197     {
    198         /* Acquire Cloud Profile: */
    199         m_comCloudProfile = m_comCloudProvider.GetProfileByName(profileName());
    200         /* Show error message if necessary: */
    201         if (!m_comCloudProvider.isOk())
    202             msgCenter().cannotFindCloudProfile(m_comCloudProvider, profileName());
    203         else
    204         {
    205             /* Acquire properties: */
     212    if (m_comCloudProvider.isNotNull() && !profileName().isNull())
     213    {
     214        /* Main API request sequence, can be interrupted after any step: */
     215        do
     216        {
     217            /* Acquire Cloud Profile: */
     218            m_comCloudProfile = m_comCloudProvider.GetProfileByName(profileName());
     219            if (!m_comCloudProvider.isOk())
     220            {
     221                msgCenter().cannotFindCloudProfile(m_comCloudProvider, profileName());
     222                break;
     223            }
     224
     225            /* Acquire profile properties: */
    206226            QVector<QString> keys;
    207227            QVector<QString> values;
    208228            values = m_comCloudProfile.GetProperties(QString(), keys);
    209             /* Show error message if necessary: */
    210229            if (!m_comCloudProfile.isOk())
     230            {
    211231                msgCenter().cannotAcquireCloudProfileParameter(m_comCloudProfile);
    212             else
    213             {
    214                 /* Configure table: */
    215                 m_pAccountPropertyTable->setRowCount(keys.size());
    216                 m_pAccountPropertyTable->setColumnCount(2);
    217 
    218                 /* Push acquired keys/values to data fields: */
    219                 for (int i = 0; i < m_pAccountPropertyTable->rowCount(); ++i)
     232                break;
     233            }
     234
     235            /* Configure table: */
     236            m_pAccountPropertyTable->setRowCount(keys.size());
     237            m_pAccountPropertyTable->setColumnCount(2);
     238
     239            /* Push acquired keys/values to data fields: */
     240            for (int i = 0; i < m_pAccountPropertyTable->rowCount(); ++i)
     241            {
     242                /* Create key item: */
     243                QTableWidgetItem *pItemK = new QTableWidgetItem(keys.at(i));
     244                if (pItemK)
    220245                {
    221                     /* Create key item: */
    222                     QTableWidgetItem *pItemK = new QTableWidgetItem(keys.at(i));
    223                     if (pItemK)
    224                     {
    225                         /* Non-editable for sure, but non-selectable? */
    226                         pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsEditable);
    227                         pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsSelectable);
    228 
    229                         /* Use non-translated description as tool-tip: */
    230                         const QString strToolTip = m_comCloudProvider.GetPropertyDescription(keys.at(i));
    231                         /* Show error message if necessary: */
    232                         if (!m_comCloudProfile.isOk())
    233                             msgCenter().cannotAcquireCloudProfileParameter(m_comCloudProfile);
    234                         else
    235                             pItemK->setData(Qt::UserRole, strToolTip);
    236 
    237                         /* Insert into table: */
    238                         m_pAccountPropertyTable->setItem(i, 0, pItemK);
    239                     }
    240 
    241                     /* Create value item: */
    242                     QTableWidgetItem *pItemV = new QTableWidgetItem(values.at(i));
    243                     if (pItemV)
    244                     {
    245                         /* Non-editable for sure, but non-selectable? */
    246                         pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsEditable);
    247                         pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsSelectable);
    248 
    249                         /* Use the value as tool-tip, there can be quite long values: */
    250                         const QString strToolTip = values.at(i);
    251                         pItemV->setToolTip(strToolTip);
    252 
    253                         /* Insert into table: */
    254                         m_pAccountPropertyTable->setItem(i, 1, pItemV);
    255                     }
     246                    /* Non-editable for sure, but non-selectable? */
     247                    pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsEditable);
     248                    pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsSelectable);
     249
     250                    /* Use non-translated description as tool-tip: */
     251                    const QString strToolTip = m_comCloudProvider.GetPropertyDescription(keys.at(i));
     252                    /* Show error message if necessary: */
     253                    if (!m_comCloudProfile.isOk())
     254                        msgCenter().cannotAcquireCloudProfileParameter(m_comCloudProfile);
     255                    else
     256                        pItemK->setData(Qt::UserRole, strToolTip);
     257
     258                    /* Insert into table: */
     259                    m_pAccountPropertyTable->setItem(i, 0, pItemK);
    256260                }
    257261
    258                 /* Update table tool-tips: */
    259                 updateAccountPropertyTableToolTips();
    260 
    261                 /* Adjust the table: */
    262                 adjustAccountPropertyTable();
    263             }
    264         }
    265     }
     262                /* Create value item: */
     263                QTableWidgetItem *pItemV = new QTableWidgetItem(values.at(i));
     264                if (pItemV)
     265                {
     266                    /* Non-editable for sure, but non-selectable? */
     267                    pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsEditable);
     268                    pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsSelectable);
     269
     270                    /* Use the value as tool-tip, there can be quite long values: */
     271                    const QString strToolTip = values.at(i);
     272                    pItemV->setToolTip(strToolTip);
     273
     274                    /* Insert into table: */
     275                    m_pAccountPropertyTable->setItem(i, 1, pItemV);
     276                }
     277            }
     278
     279            /* Update table tool-tips: */
     280            updateAccountPropertyTableToolTips();
     281
     282            /* Adjust the table: */
     283            adjustAccountPropertyTable();
     284        }
     285        while (0);
     286    }
     287
     288    /* Unblock signals after update: */
     289    m_pAccountPropertyTable->blockSignals(false);
    266290}
    267291
    268292void UIWizardImportAppPage1::populateAccountInstances()
    269293{
     294    /* Block signals while updating: */
     295    m_pAccountInstanceList->blockSignals(true);
     296
    270297    /* Clear list initially: */
    271298    m_pAccountInstanceList->clear();
     
    274301
    275302    /* If profile chosen: */
    276     if (!m_comCloudProfile.isNull())
    277     {
    278         /* Acquire Cloud Client: */
    279         m_comCloudClient = m_comCloudProfile.CreateCloudClient();
    280         /* Show error message if necessary: */
    281         if (!m_comCloudProfile.isOk())
    282             msgCenter().cannotCreateCloudClient(m_comCloudProfile);
    283         else
    284         {
    285             /* Read Cloud Client VM instances.
    286              * Please take into account that for now CCloudClient::ListInstances
    287              * doesn't support OR-ed enum combinations, so we have to aquire
    288              * Stopped and Running cloud VM instances separately.  That also means
    289              * that there will be two subsequent progress dialogs shown. */
     303    if (m_comCloudProfile.isNotNull())
     304    {
     305        /* Main API request sequence, can be interrupted after any step: */
     306        do
     307        {
     308            /* Acquire Cloud Client: */
     309            m_comCloudClient = m_comCloudProfile.CreateCloudClient();
     310            if (!m_comCloudProfile.isOk())
     311            {
     312                msgCenter().cannotCreateCloudClient(m_comCloudProfile);
     313                break;
     314            }
     315
     316            // WORKAROUND:
     317            // Please take into account that for now CCloudClient::ListInstances doesn't support OR-ed enum combinations,
     318            // so we have to aquire Stopped and Running cloud VM instances separately.  That also means that there will be
     319            // two subsequent progress dialogs shown.
    290320            /// @todo rework when it's possible to do the right way
    291             do
    292             {
    293                 /* Stopped VM names and ids: */
    294                 CStringArray comNamesStopped;
    295                 CStringArray comIDsStopped;
    296 
    297                 /* Ask for Stopped cloud VMs: */
    298                 CProgress comProgressStopped = m_comCloudClient.ListInstances(KCloudMachineState_Stopped, comNamesStopped, comIDsStopped);
    299                 if (!m_comCloudClient.isOk())
     321
     322            /* Stopped VM names and ids: */
     323            CStringArray comNamesStopped;
     324            CStringArray comIDsStopped;
     325
     326            /* Ask for Stopped cloud VMs: */
     327            CProgress comProgressStopped = m_comCloudClient.ListInstances(KCloudMachineState_Stopped, comNamesStopped, comIDsStopped);
     328            if (!m_comCloudClient.isOk())
     329            {
     330                msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
     331                break;
     332            }
     333
     334            /* Show "Acquire cloud instances" progress: */
     335            msgCenter().showModalProgressDialog(comProgressStopped, UIWizardImportApp::tr("Acquire stopped cloud instances..."),
     336                                                ":/progress_reading_appliance_90px.png", 0, 0);
     337            if (!comProgressStopped.isOk() || comProgressStopped.GetResultCode() != 0)
     338            {
     339                msgCenter().cannotAcquireCloudClientParameter(comProgressStopped);
     340                break;
     341            }
     342
     343            /* Running VM names and ids: */
     344            CStringArray comNamesRunning;
     345            CStringArray comIDsRunning;
     346
     347            /* Ask for Running cloud VMs: */
     348            CProgress comProgressRunning = m_comCloudClient.ListInstances(KCloudMachineState_Running, comNamesRunning, comIDsRunning);
     349            if (!m_comCloudClient.isOk())
     350            {
     351                msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
     352                break;
     353            }
     354
     355            /* Show "Acquire cloud instances" progress: */
     356            msgCenter().showModalProgressDialog(comProgressRunning, UIWizardImportApp::tr("Acquire running cloud instances..."),
     357                                                ":/progress_reading_appliance_90px.png", 0, 0);
     358            if (!comProgressRunning.isOk() || comProgressRunning.GetResultCode() != 0)
     359            {
     360                msgCenter().cannotAcquireCloudClientParameter(comProgressRunning);
     361                break;
     362            }
     363
     364            /* Push acquired names to list rows: */
     365            const QVector<QString> names = comNamesStopped.GetValues() + comNamesRunning.GetValues();
     366            const QVector<QString> ids = comIDsStopped.GetValues() + comIDsRunning.GetValues();
     367            for (int i = 0; i < names.size(); ++i)
     368            {
     369                /* Create list item: */
     370                QListWidgetItem *pItem = new QListWidgetItem(names.at(i), m_pAccountInstanceList);
     371                if (pItem)
    300372                {
    301                     msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
    302                     break;
     373                    pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
     374                    pItem->setData(Qt::UserRole, ids.at(i));
    303375                }
    304 
    305                 /* Show "Acquire cloud instances" progress: */
    306                 msgCenter().showModalProgressDialog(comProgressStopped, UIWizardImportApp::tr("Acquire stopped cloud instances..."),
    307                                                     ":/progress_reading_appliance_90px.png", 0, 0);
    308                 if (!comProgressStopped.isOk() || comProgressStopped.GetResultCode() != 0)
    309                 {
    310                     msgCenter().cannotAcquireCloudClientParameter(comProgressStopped);
    311                     break;
    312                 }
    313 
    314                 /* Running VM names and ids: */
    315                 CStringArray comNamesRunning;
    316                 CStringArray comIDsRunning;
    317 
    318                 /* Ask for Running cloud VMs: */
    319                 CProgress comProgressRunning = m_comCloudClient.ListInstances(KCloudMachineState_Running, comNamesRunning, comIDsRunning);
    320                 if (!m_comCloudClient.isOk())
    321                 {
    322                     msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
    323                     break;
    324                 }
    325 
    326                 /* Show "Acquire cloud instances" progress: */
    327                 msgCenter().showModalProgressDialog(comProgressRunning, UIWizardImportApp::tr("Acquire running cloud instances..."),
    328                                                     ":/progress_reading_appliance_90px.png", 0, 0);
    329                 if (!comProgressRunning.isOk() || comProgressRunning.GetResultCode() != 0)
    330                 {
    331                     msgCenter().cannotAcquireCloudClientParameter(comProgressRunning);
    332                     break;
    333                 }
    334 
    335                 /* Push acquired names to list rows: */
    336                 const QVector<QString> names = comNamesStopped.GetValues() + comNamesRunning.GetValues();
    337                 const QVector<QString> ids = comIDsStopped.GetValues() + comIDsRunning.GetValues();
    338                 for (int i = 0; i < names.size(); ++i)
    339                 {
    340                     /* Create list item: */
    341                     QListWidgetItem *pItem = new QListWidgetItem(names.at(i), m_pAccountInstanceList);
    342                     if (pItem)
    343                     {
    344                         pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
    345                         pItem->setData(Qt::UserRole, ids.at(i));
    346                     }
    347                 }
    348                 /* Choose the 1st one by default if possible: */
    349                 if (m_pAccountInstanceList->count())
    350                     m_pAccountInstanceList->setCurrentRow(0);
    351             }
    352             while (0);
    353         }
    354     }
     376            }
     377
     378            /* Choose the 1st one by default if possible: */
     379            if (m_pAccountInstanceList->count())
     380                m_pAccountInstanceList->setCurrentRow(0);
     381        }
     382        while (0);
     383    }
     384
     385    /* Unblock signals after update: */
     386    m_pAccountInstanceList->blockSignals(false);
    355387}
    356388
     
    365397    if (m_comCloudClient.isNotNull())
    366398    {
    367         /* The underlying sequence is quite a large one, and each subsequent step depends on previous one.  I do not want to
    368          * make embedded ifs or multiple exit points, that's more or less Ok with few of them but certainly not with many. */
     399        /* Main API request sequence, can be interrupted after any step: */
    369400        do
    370401        {
     
    889920    if (isSourceCloudOne())
    890921    {
    891         /* Populate form properties: */
     922        /* Create appliance & populate form properties: */
    892923        populateFormProperties();
    893924        /* And make sure they are not null: */
    894         return m_comVSDForm.isNotNull();
     925        return m_comAppliance.isNotNull() && m_comVSDForm.isNotNull();
    895926    }
    896927    else
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