VirtualBox

Changeset 82828 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 22, 2020 2:14:02 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135797
Message:

FE/Qt: bugref:9611: UIAudioHostDriverEditor: Get rid of hardcoded audio driver 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/UIAudioHostDriverEditor.cpp

    r80079 r82828  
    2323/* GUI includes: */
    2424#include "QIComboBox.h"
     25#include "UICommon.h"
    2526#include "UIConverter.h"
    2627#include "UIAudioHostDriverEditor.h"
     28
     29/* COM includes: */
     30#include "CSystemProperties.h"
    2731
    2832
     
    3034    : QIWithRetranslateUI<QWidget>(pParent)
    3135    , m_fWithLabel(fWithLabel)
     36    , m_enmValue(KAudioDriverType_Max)
    3237    , m_pLabel(0)
    3338    , m_pCombo(0)
     
    4045    if (m_pCombo)
    4146    {
    42         int iIndex = m_pCombo->findData(QVariant::fromValue(enmValue));
     47        /* Update cached value and
     48         * combo if value has changed: */
     49        if (m_enmValue != enmValue)
     50        {
     51            m_enmValue = enmValue;
     52            populateCombo();
     53        }
     54
     55        /* Look for proper index to choose: */
     56        int iIndex = m_pCombo->findData(QVariant::fromValue(m_enmValue));
    4357        if (iIndex != -1)
    4458            m_pCombo->setCurrentIndex(iIndex);
     
    4862KAudioDriverType UIAudioHostDriverEditor::value() const
    4963{
    50     return m_pCombo ? m_pCombo->itemData(m_pCombo->currentIndex()).value<KAudioDriverType>() : KAudioDriverType_Null;
     64    return m_pCombo ? m_pCombo->currentData().value<KAudioDriverType>() : m_enmValue;
    5165}
    5266
     
    95109            {
    96110                setFocusProxy(m_pCombo->focusProxy());
     111                /* This is necessary since contents is dynamical now: */
     112                m_pCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    97113                if (m_pLabel)
    98114                    m_pLabel->setBuddy(m_pCombo->focusProxy());
     
    119135void UIAudioHostDriverEditor::populateCombo()
    120136{
    121     /* Fill combo manually: */
    122     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Null));
    123 #ifdef Q_OS_WIN
    124     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_DirectSound));
    125 # ifdef VBOX_WITH_WINMM
    126     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_WinMM));
    127 # endif
    128 #endif
    129 #ifdef VBOX_WITH_AUDIO_OSS
    130     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_OSS));
    131 #endif
    132 #ifdef VBOX_WITH_AUDIO_ALSA
    133     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_ALSA));
    134 #endif
    135 #ifdef VBOX_WITH_AUDIO_PULSE
    136     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_Pulse));
    137 #endif
    138 #ifdef Q_OS_MACX
    139     m_pCombo->addItem(QString(), QVariant::fromValue(KAudioDriverType_CoreAudio));
    140 #endif
     137    if (m_pCombo)
     138    {
     139        /* Clear combo first of all: */
     140        m_pCombo->clear();
     141
     142        /* Load currently supported audio driver types: */
     143        CSystemProperties comProperties = uiCommon().virtualBox().GetSystemProperties();
     144        m_supportedValues = comProperties.GetSupportedAudioDriverTypes();
     145
     146        /* Make sure requested value if sane is present as well: */
     147        if (   m_enmValue != KAudioDriverType_Max
     148            && !m_supportedValues.contains(m_enmValue))
     149            m_supportedValues.prepend(m_enmValue);
     150
     151        /* Update combo with all the supported values: */
     152        foreach (const KAudioDriverType &enmType, m_supportedValues)
     153            m_pCombo->addItem(QString(), QVariant::fromValue(enmType));
     154
     155        /* Retranslate finally: */
     156        retranslateUi();
     157    }
    141158}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIAudioHostDriverEditor.h

    r80081 r82828  
    5757    KAudioDriverType value() const;
    5858
     59    /** Returns the vector of supported values. */
     60    QVector<KAudioDriverType> supportedValues() const { return m_supportedValues; }
     61
    5962protected:
    6063
     
    7780    bool  m_fWithLabel;
    7881
     82    /** Holds the value to be selected. */
     83    KAudioDriverType  m_enmValue;
     84
     85    /** Holds the vector of supported values. */
     86    QVector<KAudioDriverType>  m_supportedValues;
     87
    7988    /** Holds the label instance. */
    8089    QLabel     *m_pLabel;
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