VirtualBox

Changeset 82563 in vbox


Ignore:
Timestamp:
Dec 12, 2019 8:36:15 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9611: UINetworkAttachmentEditor: Get rid of hardcoded network attachment types, instead acquire these types through CSystemProperties interface.

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

Legend:

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

    r81422 r82563  
    2929
    3030/* COM includes: */
     31#ifdef VBOX_WITH_CLOUD_NET
     32# include "CCloudNetwork.h"
     33#endif
    3134#include "CHostNetworkInterface.h"
    3235#include "CNATNetwork.h"
    33 #ifdef VBOX_WITH_CLOUD_NET
    34 #include "CCloudNetwork.h"
    35 #endif /* VBOX_WITH_CLOUD_NET */
     36#include "CSystemProperties.h"
    3637
    3738
     
    4344    , m_fWithLabels(fWithLabels)
    4445    , m_enmRestrictedNetworkAttachmentTypes(UIExtraDataMetaDefs::DetailsElementOptionTypeNetwork_Invalid)
     46    , m_enmType(KNetworkAttachmentType_Max)
    4547    , m_pLabelType(0)
    4648    , m_pComboType(0)
     
    6668    if (!m_pComboType)
    6769        return;
    68 
    69     /* Search for an item with required data value, choose item to be current if found: */
    70     const int iIndex = m_pComboType->findData(QVariant::fromValue(enmType));
    71     if (iIndex != -1)
    72         m_pComboType->setCurrentIndex(iIndex);
     70    /* Make sure type is changed: */
     71    if (m_enmType == enmType)
     72        return;
     73
     74    /* Remember requested type: */
     75    m_enmType = enmType;
     76    /* Repopulate finally, supported values might change: */
     77    populateTypeCombo();
    7378}
    7479
    7580KNetworkAttachmentType UINetworkAttachmentEditor::valueType() const
    7681{
    77     /* Make sure combo is there: */
    78     if (!m_pComboType)
    79         return KNetworkAttachmentType_Null;
    80 
    81     /* Return current item data: */
    82     return m_pComboType->currentData().value<KNetworkAttachmentType>();
     82    return m_pComboType ? m_pComboType->currentData().value<KNetworkAttachmentType>() : m_enmType;
    8383}
    8484
     
    190190        {
    191191            const KNetworkAttachmentType enmType = m_pComboType->itemData(i).value<KNetworkAttachmentType>();
    192             m_pComboType->setItemText(i, gpConverter->toString(enmType));
     192            const QString strName = gpConverter->toString(enmType);
     193            m_pComboType->setItemData(i, strName, Qt::ToolTipRole);
     194            m_pComboType->setItemText(i, strName);
    193195        }
    194196    }
     
    338340    m_pComboType->blockSignals(true);
    339341
    340     /* Remember currently selected type index: */
    341     int iCurrentAttachment = m_pComboType->currentIndex();
    342 
    343342    /* Clear the type combo-box: */
    344343    m_pComboType->clear();
    345344
    346     /* Populate attachments: */
     345    /* Load currently supported network attachment types (system-properties getter): */
     346    CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     347    QVector<KNetworkAttachmentType> supportedTypes = comProperties.GetSupportedNetworkAttachmentTypes();
     348    /* Take currently requested type into account if it's sane: */
     349    if (!supportedTypes.contains(m_enmType) && m_enmType != KNetworkAttachmentType_Max)
     350        supportedTypes.prepend(m_enmType);
     351
     352    /* Populate attachment types: */
    347353    int iAttachmentTypeIndex = 0;
    348     // WORKAROUND:
    349     // We want some hardcoded order, so prepare a list of enum values.
    350     QList<KNetworkAttachmentType> attachmentTypes  = QList<KNetworkAttachmentType>() << KNetworkAttachmentType_Null
    351                                                   << KNetworkAttachmentType_NAT << KNetworkAttachmentType_NATNetwork
    352                                                   << KNetworkAttachmentType_Bridged << KNetworkAttachmentType_Internal
    353                                                   << KNetworkAttachmentType_HostOnly << KNetworkAttachmentType_Generic;
    354 #ifdef VBOX_WITH_CLOUD_NET
    355     attachmentTypes.append(KNetworkAttachmentType_Cloud);
    356 #endif /* VBOX_WITH_CLOUD_NET */
    357     for (int i = 0; i < attachmentTypes.size(); ++i)
    358     {
    359         const KNetworkAttachmentType enmType = attachmentTypes.at(i);
     354    foreach (const KNetworkAttachmentType &enmType, supportedTypes)
     355    {
     356        /* Filter currently restricted network attachment types (extra-data getter): */
    360357        if (m_enmRestrictedNetworkAttachmentTypes & toUiNetworkAdapterEnum(enmType))
    361358            continue;
     
    366363    }
    367364
    368     /* Restore previously selected type index: */
    369     m_pComboType->setCurrentIndex(iCurrentAttachment == -1 ? 0 : iCurrentAttachment);
     365    /* Restore previously selected type if possible: */
     366    const int iIndex = m_pComboType->findData(m_enmType);
     367    m_pComboType->setCurrentIndex(iIndex != -1 ? iIndex : 0);
    370368
    371369    /* Handle combo item change: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINetworkAttachmentEditor.h

    r81422 r82563  
    134134    QMap<KNetworkAttachmentType, QString>      m_name;
    135135
     136    /** Holds the requested type. */
     137    KNetworkAttachmentType  m_enmType;
     138
    136139    /** Holds the type label instance. */
    137140    QLabel     *m_pLabelType;
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