VirtualBox

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


Ignore:
Timestamp:
May 3, 2011 7:39:41 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt: 4989: UISettingsCache template integrated into Audio page.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp

    r36519 r36924  
    3636    UISettingsPageMachine::fetchData(data);
    3737
    38     /* Fill internal variables with corresponding values: */
    39     const CAudioAdapter &audio = m_machine.GetAudioAdapter();
    40     m_cache.m_fAudioEnabled = audio.GetEnabled();
    41     m_cache.m_audioDriverType = audio.GetAudioDriver();
    42     m_cache.m_audioControllerType = audio.GetAudioController();
     38    /* Prepare audio data: */
     39    UIDataSettingsMachineAudio audioData;
     40
     41    /* Check if adapter is valid: */
     42    const CAudioAdapter &adapter = m_machine.GetAudioAdapter();
     43    if (!adapter.isNull())
     44    {
     45        /* Gather audio data: */
     46        audioData.m_fAudioEnabled = adapter.GetEnabled();
     47        audioData.m_audioDriverType = adapter.GetAudioDriver();
     48        audioData.m_audioControllerType = adapter.GetAudioController();
     49    }
     50
     51    /* Cache audio data: */
     52    m_cache.cacheInitialData(audioData);
    4353
    4454    /* Upload machine to data: */
     
    5060void UIMachineSettingsAudio::getFromCache()
    5161{
    52     /* Apply internal variables data to QWidget(s): */
    53     mGbAudio->setChecked(m_cache.m_fAudioEnabled);
    54     mCbAudioDriver->setCurrentIndex(mCbAudioDriver->findText(vboxGlobal().toString(m_cache.m_audioDriverType)));
    55     mCbAudioController->setCurrentIndex(mCbAudioController->findText(vboxGlobal().toString(m_cache.m_audioControllerType)));
     62    /* Get audio data from cache: */
     63    const UIDataSettingsMachineAudio &audioData = m_cache.base();
     64
     65    /* Load audio data to page: */
     66    mGbAudio->setChecked(audioData.m_fAudioEnabled);
     67    mCbAudioDriver->setCurrentIndex(mCbAudioDriver->findText(vboxGlobal().toString(audioData.m_audioDriverType)));
     68    mCbAudioController->setCurrentIndex(mCbAudioController->findText(vboxGlobal().toString(audioData.m_audioControllerType)));
    5669}
    5770
     
    6073void UIMachineSettingsAudio::putToCache()
    6174{
    62     /* Gather internal variables data from QWidget(s): */
    63     m_cache.m_fAudioEnabled = mGbAudio->isChecked();
    64     m_cache.m_audioDriverType = vboxGlobal().toAudioDriverType(mCbAudioDriver->currentText());
    65     m_cache.m_audioControllerType = vboxGlobal().toAudioControllerType(mCbAudioController->currentText());
     75    /* Prepare audio data: */
     76    UIDataSettingsMachineAudio audioData = m_cache.base();
     77
     78    /* Gather audio data: */
     79    audioData.m_fAudioEnabled = mGbAudio->isChecked();
     80    audioData.m_audioDriverType = vboxGlobal().toAudioDriverType(mCbAudioDriver->currentText());
     81    audioData.m_audioControllerType = vboxGlobal().toAudioControllerType(mCbAudioController->currentText());
     82
     83    /* Cache audio data: */
     84    m_cache.cacheCurrentData(audioData);
    6685}
    6786
     
    7392    UISettingsPageMachine::fetchData(data);
    7493
    75     if (isMachineOffline())
     94    /* Check if audio data was changed: */
     95    if (m_cache.wasChanged())
    7696    {
    77         CAudioAdapter audio = m_machine.GetAudioAdapter();
    78         audio.SetEnabled(m_cache.m_fAudioEnabled);
    79         audio.SetAudioDriver(m_cache.m_audioDriverType);
    80         audio.SetAudioController(m_cache.m_audioControllerType);
     97        /* Check if adapter still valid: */
     98        CAudioAdapter adapter = m_machine.GetAudioAdapter();
     99        if (!adapter.isNull())
     100        {
     101            /* Get audio data from cache: */
     102            const UIDataSettingsMachineAudio &audioData = m_cache.data();
     103
     104            /* Store audio data: */
     105            if (isMachineOffline())
     106            {
     107                adapter.SetEnabled(audioData.m_fAudioEnabled);
     108                adapter.SetAudioDriver(audioData.m_audioDriverType);
     109                adapter.SetAudioController(audioData.m_audioControllerType);
     110            }
     111        }
    81112    }
    82113
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.h

    r36357 r36924  
    2424#include "COMDefs.h"
    2525
    26 /* Machine settings / Audio page / Cache: */
    27 struct UISettingsCacheMachineAudio
     26/* Machine settings / Audio page / Data: */
     27struct UIDataSettingsMachineAudio
    2828{
     29    /* Default constructor: */
     30    UIDataSettingsMachineAudio()
     31        : m_fAudioEnabled(false)
     32        , m_audioDriverType(KAudioDriverType_Null)
     33        , m_audioControllerType(KAudioControllerType_AC97) {}
     34    /* Functions: */
     35    bool equal(const UIDataSettingsMachineAudio &other) const
     36    {
     37        return (m_fAudioEnabled == other.m_fAudioEnabled) &&
     38               (m_audioDriverType == other.m_audioDriverType) &&
     39               (m_audioControllerType == other.m_audioControllerType);
     40    }
     41    /* Operators: */
     42    bool operator==(const UIDataSettingsMachineAudio &other) const { return equal(other); }
     43    bool operator!=(const UIDataSettingsMachineAudio &other) const { return !equal(other); }
     44    /* Variables: */
    2945    bool m_fAudioEnabled;
    3046    KAudioDriverType m_audioDriverType;
    3147    KAudioControllerType m_audioControllerType;
    3248};
     49typedef UISettingsCache<UIDataSettingsMachineAudio> UICacheSettingsMachineAudio;
    3350
    3451/* Machine settings / Audio page: */
     
    6986
    7087    /* Cache: */
    71     UISettingsCacheMachineAudio m_cache;
     88    UICacheSettingsMachineAudio m_cache;
    7289};
    7390
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