VirtualBox

Changeset 82385 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Dec 4, 2019 4:19:20 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9390: UIApplianceImportEditorWidget: Get rid of hardcoded import option types, instead acquire these types through CSystemProperties interface; Besides that, using more modern Qt approach to cache enum data directly without casting it to int.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceImportEditorWidget.cpp

    r79365 r82385  
    253253        if (m_pMACComboBox)
    254254        {
    255             MACAddressImportPolicy macPolicy = static_cast<MACAddressImportPolicy>(m_pMACComboBox->currentIndex());
    256             switch (macPolicy)
     255            const MACAddressImportPolicy enmPolicy = m_pMACComboBox->currentData().value<MACAddressImportPolicy>();
     256            switch (enmPolicy)
    257257            {
    258258                case MACAddressImportPolicy_KeepAllMACs:
     
    326326    /* Translate MAC address policy combo-box: */
    327327    m_pMACComboBoxLabel->setText(tr("MAC Address &Policy:"));
    328     m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepAllMACs,
    329                                 tr("Include all network adapter MAC addresses"));
    330     m_pMACComboBox->setItemText(MACAddressImportPolicy_KeepNATMACs,
    331                                 tr("Include only NAT network adapter MAC addresses"));
    332     m_pMACComboBox->setItemText(MACAddressImportPolicy_StripAllMACs,
    333                                 tr("Generate new MAC addresses for all network adapters"));
    334     m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepAllMACs,
    335                                 tr("Include all network adapter MAC addresses during cloning."), Qt::ToolTipRole);
    336     m_pMACComboBox->setItemData(MACAddressImportPolicy_KeepNATMACs,
    337                                 tr("Include only NAT network adapter MAC addresses during cloning."), Qt::ToolTipRole);
    338     m_pMACComboBox->setItemData(MACAddressImportPolicy_StripAllMACs,
    339                                 tr("Generate new MAC addresses for all network adapters during cloning."), Qt::ToolTipRole);
     328    for (int i = 0; i < m_pMACComboBox->count(); ++i)
     329    {
     330        const MACAddressImportPolicy enmPolicy = m_pMACComboBox->itemData(i).value<MACAddressImportPolicy>();
     331        switch (enmPolicy)
     332        {
     333            case MACAddressImportPolicy_KeepAllMACs:
     334            {
     335                m_pMACComboBox->setItemText(i, tr("Include all network adapter MAC addresses"));
     336                m_pMACComboBox->setItemData(i, tr("Include all network adapter MAC addresses during importing."), Qt::ToolTipRole);
     337                break;
     338            }
     339            case MACAddressImportPolicy_KeepNATMACs:
     340            {
     341                m_pMACComboBox->setItemText(i, tr("Include only NAT network adapter MAC addresses"));
     342                m_pMACComboBox->setItemData(i, tr("Include only NAT network adapter MAC addresses during importing."), Qt::ToolTipRole);
     343                break;
     344            }
     345            case MACAddressImportPolicy_StripAllMACs:
     346            {
     347                m_pMACComboBox->setItemText(i, tr("Generate new MAC addresses for all network adapters"));
     348                m_pMACComboBox->setItemData(i, tr("Generate new MAC addresses for all network adapters during importing."), Qt::ToolTipRole);
     349                break;
     350            }
     351            default:
     352                break;
     353        }
     354    }
    340355
    341356    m_pAdditionalOptionsLabel->setText(tr("Additional Options:"));
     
    362377    AssertReturnVoid(m_pMACComboBox->count() == 0);
    363378
    364     /* Apply hardcoded policies list: */
    365     for (int i = 0; i < (int)MACAddressImportPolicy_MAX; ++i)
    366     {
    367         m_pMACComboBox->addItem(QString::number(i));
    368         m_pMACComboBox->setItemData(i, i);
    369     }
     379    /* Map known import options to known MAC address import policies: */
     380    QMap<KImportOptions, MACAddressImportPolicy> knownOptions;
     381    knownOptions[KImportOptions_KeepAllMACs] = MACAddressImportPolicy_KeepAllMACs;
     382    knownOptions[KImportOptions_KeepNATMACs] = MACAddressImportPolicy_KeepNATMACs;
     383
     384    /* Load currently supported import options: */
     385    CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     386    const QVector<KImportOptions> supportedOptions = comProperties.GetSupportedImportOptions();
     387
     388    /* Check which of supported options/policies are known: */
     389    QList<MACAddressImportPolicy> supportedPolicies;
     390    foreach (const KImportOptions &enmOption, supportedOptions)
     391        if (knownOptions.contains(enmOption))
     392            supportedPolicies << knownOptions.value(enmOption);
     393
     394    /* Add supported policies first: */
     395    foreach (const MACAddressImportPolicy &enmPolicy, supportedPolicies)
     396        m_pMACComboBox->addItem(QString(), QVariant::fromValue(enmPolicy));
     397
     398    /* Add hardcoded policy finally: */
     399    m_pMACComboBox->addItem(QString(), QVariant::fromValue(MACAddressImportPolicy_StripAllMACs));
    370400
    371401    /* Set default: */
    372     setMACAddressImportPolicy(MACAddressImportPolicy_KeepNATMACs);
     402    if (supportedPolicies.contains(MACAddressImportPolicy_KeepNATMACs))
     403        setMACAddressImportPolicy(MACAddressImportPolicy_KeepNATMACs);
     404    else
     405        setMACAddressImportPolicy(MACAddressImportPolicy_StripAllMACs);
    373406}
    374407
    375408void UIApplianceImportEditorWidget::setMACAddressImportPolicy(MACAddressImportPolicy enmMACAddressImportPolicy)
    376409{
    377     const int iIndex = m_pMACComboBox->findData((int)enmMACAddressImportPolicy);
     410    const int iIndex = m_pMACComboBox->findData(enmMACAddressImportPolicy);
    378411    AssertMsg(iIndex != -1, ("Data not found!"));
    379412    m_pMACComboBox->setCurrentIndex(iIndex);
     
    388421void UIApplianceImportEditorWidget::updateMACAddressImportPolicyComboToolTip()
    389422{
    390     const int iCurrentIndex = m_pMACComboBox->currentIndex();
    391     const QString strCurrentToolTip = m_pMACComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
     423    const QString strCurrentToolTip = m_pMACComboBox->currentData(Qt::ToolTipRole).toString();
    392424    AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
    393425    m_pMACComboBox->setToolTip(strCurrentToolTip);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceImportEditorWidget.h

    r79032 r82385  
    3838    MACAddressImportPolicy_MAX
    3939};
     40Q_DECLARE_METATYPE(MACAddressImportPolicy);
    4041
    4142class UIApplianceImportEditorWidget: public UIApplianceEditorWidget
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