VirtualBox

Changeset 82392 in vbox for trunk/src


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

FE/Qt: bugref:9390: UIWizardExportAppPageBasic2 and UIWizardExportAppPageExpert: Get rid of hardcoded export 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/wizards/exportappliance
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic2.cpp

    r82386 r82392  
    4343/* COM includes: */
    4444#include "CMachine.h"
     45#include "CSystemProperties.h"
    4546
    4647
     
    134135    AssertReturnVoid(m_pMACComboBox->count() == 0);
    135136
    136     /* Apply hardcoded policies list: */
    137     for (int i = 0; i < (int)MACAddressExportPolicy_MAX; ++i)
    138     {
    139         m_pMACComboBox->addItem(QString::number(i));
    140         m_pMACComboBox->setItemData(i, i);
    141     }
     137    /* Map known export options to known MAC address export policies: */
     138    QMap<KExportOptions, MACAddressExportPolicy> knownOptions;
     139    knownOptions[KExportOptions_StripAllMACs] = MACAddressExportPolicy_StripAllMACs;
     140    knownOptions[KExportOptions_StripAllNonNATMACs] = MACAddressExportPolicy_StripAllNonNATMACs;
     141
     142    /* Load currently supported export options: */
     143    CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     144    const QVector<KExportOptions> supportedOptions = comProperties.GetSupportedExportOptions();
     145
     146    /* Check which of supported options/policies are known: */
     147    QList<MACAddressExportPolicy> supportedPolicies;
     148    foreach (const KExportOptions &enmOption, supportedOptions)
     149        if (knownOptions.contains(enmOption))
     150            supportedPolicies << knownOptions.value(enmOption);
     151
     152    /* Add supported policies first: */
     153    foreach (const MACAddressExportPolicy &enmPolicy, supportedPolicies)
     154        m_pMACComboBox->addItem(QString(), QVariant::fromValue(enmPolicy));
     155
     156    /* Add hardcoded policy finally: */
     157    m_pMACComboBox->addItem(QString(), QVariant::fromValue(MACAddressExportPolicy_KeepAllMACs));
    142158
    143159    /* Set default: */
    144     setMACAddressExportPolicy(MACAddressExportPolicy_StripAllNonNATMACs);
     160    if (supportedPolicies.contains(MACAddressExportPolicy_StripAllNonNATMACs))
     161        setMACAddressExportPolicy(MACAddressExportPolicy_StripAllNonNATMACs);
     162    else
     163        setMACAddressExportPolicy(MACAddressExportPolicy_KeepAllMACs);
    145164}
    146165
     
    507526void UIWizardExportAppPage2::updateMACAddressExportPolicyComboToolTip()
    508527{
    509     const int iCurrentIndex = m_pMACComboBox->currentIndex();
    510     const QString strCurrentToolTip = m_pMACComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
     528    const QString strCurrentToolTip = m_pMACComboBox->currentData(Qt::ToolTipRole).toString();
    511529    AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
    512530    m_pMACComboBox->setToolTip(strCurrentToolTip);
     
    577595void UIWizardExportAppPage2::setMACAddressExportPolicy(MACAddressExportPolicy enmMACAddressExportPolicy)
    578596{
    579     const int iIndex = m_pMACComboBox->findData((int)enmMACAddressExportPolicy);
     597    const int iIndex = m_pMACComboBox->findData(enmMACAddressExportPolicy);
    580598    AssertMsg(iIndex != -1, ("Data not found!"));
    581599    m_pMACComboBox->setCurrentIndex(iIndex);
     
    584602MACAddressExportPolicy UIWizardExportAppPage2::macAddressExportPolicy() const
    585603{
    586     const int iIndex = m_pMACComboBox->currentIndex();
    587     return (MACAddressExportPolicy)m_pMACComboBox->itemData(iIndex).toInt();
     604    return m_pMACComboBox->currentData().value<MACAddressExportPolicy>();
    588605}
    589606
     
    10491066    /* Translate MAC address policy combo-box: */
    10501067    m_pMACComboBoxLabel->setText(UIWizardExportApp::tr("MAC Address &Policy:"));
    1051     m_pMACComboBox->setItemText(MACAddressExportPolicy_KeepAllMACs,
    1052                                 UIWizardExportApp::tr("Include all network adapter MAC addresses"));
    1053     m_pMACComboBox->setItemText(MACAddressExportPolicy_StripAllNonNATMACs,
    1054                                 UIWizardExportApp::tr("Include only NAT network adapter MAC addresses"));
    1055     m_pMACComboBox->setItemText(MACAddressExportPolicy_StripAllMACs,
    1056                                 UIWizardExportApp::tr("Strip all network adapter MAC addresses"));
    1057     m_pMACComboBox->setItemData(MACAddressExportPolicy_KeepAllMACs,
    1058                                 UIWizardExportApp::tr("Include all network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
    1059     m_pMACComboBox->setItemData(MACAddressExportPolicy_StripAllNonNATMACs,
    1060                                 UIWizardExportApp::tr("Include only NAT network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
    1061     m_pMACComboBox->setItemData(MACAddressExportPolicy_StripAllMACs,
    1062                                 UIWizardExportApp::tr("Strip all network adapter MAC addresses from exported appliance archive."), Qt::ToolTipRole);
     1068    for (int i = 0; i < m_pMACComboBox->count(); ++i)
     1069    {
     1070        const MACAddressExportPolicy enmPolicy = m_pMACComboBox->itemData(i).value<MACAddressExportPolicy>();
     1071        switch (enmPolicy)
     1072        {
     1073            case MACAddressExportPolicy_KeepAllMACs:
     1074            {
     1075                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Include all network adapter MAC addresses"));
     1076                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Include all network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
     1077                break;
     1078            }
     1079            case MACAddressExportPolicy_StripAllNonNATMACs:
     1080            {
     1081                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Include only NAT network adapter MAC addresses"));
     1082                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Include only NAT network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
     1083                break;
     1084            }
     1085            case MACAddressExportPolicy_StripAllMACs:
     1086            {
     1087                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Strip all network adapter MAC addresses"));
     1088                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Strip all network adapter MAC addresses from exported appliance archive."), Qt::ToolTipRole);
     1089                break;
     1090            }
     1091            default:
     1092                break;
     1093        }
     1094    }
    10631095
    10641096    /* Translate addtional stuff: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageExpert.cpp

    r82386 r82392  
    516516    /* Translate MAC address policy combo-box: */
    517517    m_pMACComboBoxLabel->setText(UIWizardExportApp::tr("MAC Address &Policy:"));
    518     m_pMACComboBox->setItemText(MACAddressExportPolicy_KeepAllMACs,
    519                                 UIWizardExportApp::tr("Include all network adapter MAC addresses"));
    520     m_pMACComboBox->setItemText(MACAddressExportPolicy_StripAllNonNATMACs,
    521                                 UIWizardExportApp::tr("Include only NAT network adapter MAC addresses"));
    522     m_pMACComboBox->setItemText(MACAddressExportPolicy_StripAllMACs,
    523                                 UIWizardExportApp::tr("Strip all network adapter MAC addresses"));
    524     m_pMACComboBox->setItemData(MACAddressExportPolicy_KeepAllMACs,
    525                                 UIWizardExportApp::tr("Include all network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
    526     m_pMACComboBox->setItemData(MACAddressExportPolicy_StripAllNonNATMACs,
    527                                 UIWizardExportApp::tr("Include only NAT network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
    528     m_pMACComboBox->setItemData(MACAddressExportPolicy_StripAllMACs,
    529                                 UIWizardExportApp::tr("Strip all network adapter MAC addresses from exported appliance archive."), Qt::ToolTipRole);
     518    for (int i = 0; i < m_pMACComboBox->count(); ++i)
     519    {
     520        const MACAddressExportPolicy enmPolicy = m_pMACComboBox->itemData(i).value<MACAddressExportPolicy>();
     521        switch (enmPolicy)
     522        {
     523            case MACAddressExportPolicy_KeepAllMACs:
     524            {
     525                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Include all network adapter MAC addresses"));
     526                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Include all network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
     527                break;
     528            }
     529            case MACAddressExportPolicy_StripAllNonNATMACs:
     530            {
     531                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Include only NAT network adapter MAC addresses"));
     532                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Include only NAT network adapter MAC addresses in exported appliance archive."), Qt::ToolTipRole);
     533                break;
     534            }
     535            case MACAddressExportPolicy_StripAllMACs:
     536            {
     537                m_pMACComboBox->setItemText(i, UIWizardExportApp::tr("Strip all network adapter MAC addresses"));
     538                m_pMACComboBox->setItemData(i, UIWizardExportApp::tr("Strip all network adapter MAC addresses from exported appliance archive."), Qt::ToolTipRole);
     539                break;
     540            }
     541            default:
     542                break;
     543        }
     544    }
    530545
    531546    /* Translate addtional stuff: */
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