VirtualBox

Changeset 98728 in vbox


Ignore:
Timestamp:
Feb 24, 2023 4:27:05 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156029
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking CMachine wrapper usage step-by-step; Audio stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r98727 r98728  
    4747/* COM includes: */
    4848#include "CAudioAdapter.h"
     49#include "CAudioSettings.h"
    4950#include "CBooleanFormValue.h"
    5051#include "CChoiceFormValue.h"
     
    685686        QApplication::translate("UIMessageCenter", "Graphics adapter failure ..."),
    686687        QApplication::translate("UIMessageCenter", "Failed to acquire graphics adapter parameter.") +
     688        UIErrorString::formatErrorInfo(comAdapter));
     689}
     690
     691/* static */
     692void UINotificationMessage::cannotAcquireAudioSettingsParameter(const CAudioSettings &comSettings)
     693{
     694    createMessage(
     695        QApplication::translate("UIMessageCenter", "Audio settings failure ..."),
     696        QApplication::translate("UIMessageCenter", "Failed to acquire audio settings parameter.") +
     697        UIErrorString::formatErrorInfo(comSettings));
     698}
     699
     700/* static */
     701void UINotificationMessage::cannotAcquireAudioAdapterParameter(const CAudioAdapter &comAdapter)
     702{
     703    createMessage(
     704        QApplication::translate("UIMessageCenter", "Audio adapter failure ..."),
     705        QApplication::translate("UIMessageCenter", "Failed to acquire audio adapter parameter.") +
    687706        UIErrorString::formatErrorInfo(comAdapter));
    688707}
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r98727 r98728  
    302302          * @param  comAdapter  Brings the object parameter get acquired from. */
    303303        static void cannotAcquireGraphicsAdapterParameter(const CGraphicsAdapter &comAdapter);
     304        /** Notifies about inability to acquire IAudioSettings parameter.
     305          * @param  comSettings  Brings the object parameter get acquired from. */
     306        static void cannotAcquireAudioSettingsParameter(const CAudioSettings &comSettings);
     307        /** Notifies about inability to acquire IAudioAdapter parameter.
     308          * @param  comAdapter  Brings the object parameter get acquired from. */
     309        static void cannotAcquireAudioAdapterParameter(const CAudioAdapter &comAdapter);
    304310        /** Notifies about inability to acquire IConsole parameter.
    305311          * @param  comConsole  Brings the object parameter get acquired from. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98727 r98728  
    249249{
    250250    /* Make sure Audio adapter is present: */
    251     const CAudioSettings comAudioSettings = uisession()->machine().GetAudioSettings();
    252     AssertMsgReturnVoid(uisession()->machine().isOk() && comAudioSettings.isNotNull(),
    253                         ("Audio audio settings should NOT be null!\n"));
    254     const CAudioAdapter comAdapter = comAudioSettings.GetAdapter();
    255     AssertMsgReturnVoid(comAudioSettings.isOk() && comAdapter.isNotNull(),
    256                         ("Audio audio adapter should NOT be null!\n"));
     251    bool fAdapterPresent = false;
     252    acquireWhetherAudioAdapterPresent(fAdapterPresent);
     253    AssertMsgReturnVoid(fAdapterPresent,
     254                        ("Audio adapter can't be null!\n"));
    257255
    258256    /* Check/Uncheck Audio adapter output/input actions depending on features status: */
     257    bool fAudioOutputEnabled = false;
     258    bool fAudioInputEnabled = false;
     259    acquireWhetherAudioAdapterOutputEnabled(fAudioOutputEnabled);
     260    acquireWhetherAudioAdapterInputEnabled(fAudioInputEnabled);
    259261    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Output)->blockSignals(true);
    260     actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Output)->setChecked(comAdapter.GetEnabledOut());
     262    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Output)->setChecked(fAudioOutputEnabled);
    261263    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Output)->blockSignals(false);
    262264    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Input)->blockSignals(true);
    263     actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Input)->setChecked(comAdapter.GetEnabledIn());
     265    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Input)->setChecked(fAudioInputEnabled);
    264266    actionPool()->action(UIActionIndexRT_M_Devices_M_Audio_T_Input)->blockSignals(false);
    265267}
     
    375377{
    376378    return uisession()->acquireCurrentSnapshotName(strName);
     379}
     380
     381bool UIMachine::acquireWhetherAudioAdapterPresent(bool &fPresent)
     382{
     383    return uisession()->acquireWhetherAudioAdapterPresent(fPresent);
     384}
     385
     386bool UIMachine::acquireWhetherAudioAdapterEnabled(bool &fEnabled)
     387{
     388    return uisession()->acquireWhetherAudioAdapterEnabled(fEnabled);
     389}
     390
     391bool UIMachine::acquireWhetherAudioAdapterOutputEnabled(bool &fEnabled)
     392{
     393    return uisession()->acquireWhetherAudioAdapterOutputEnabled(fEnabled);
     394}
     395
     396bool UIMachine::acquireWhetherAudioAdapterInputEnabled(bool &fEnabled)
     397{
     398    return uisession()->acquireWhetherAudioAdapterInputEnabled(fEnabled);
     399}
     400
     401bool UIMachine::setAudioAdapterOutputEnabled(bool fEnabled)
     402{
     403    return uisession()->setAudioAdapterOutputEnabled(fEnabled);
     404}
     405
     406bool UIMachine::setAudioAdapterInputEnabled(bool fEnabled)
     407{
     408    return uisession()->setAudioAdapterInputEnabled(fEnabled);
    377409}
    378410
     
    16661698    /* Audio stuff: */
    16671699    {
    1668         /* Check whether audio controller is enabled. */
    1669         const CAudioSettings comAudioSettings = uisession()->machine().GetAudioSettings();
    1670         const CAudioAdapter comAudioAdapter = comAudioSettings.GetAdapter();
    1671         if (comAudioAdapter.isNull() || !comAudioAdapter.GetEnabled())
     1700        /* Check whether audio adapter is present & enabled: */
     1701        bool fAdapterPresent = false;
     1702        bool fAdapterEnabled = false;
     1703        acquireWhetherAudioAdapterPresent(fAdapterPresent);
     1704        acquireWhetherAudioAdapterEnabled(fAdapterEnabled);
     1705        if (!fAdapterPresent || !fAdapterEnabled)
    16721706            restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)
    16731707                                    (restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_Audio);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98727 r98728  
    260260        /** Acquires current snapshot name. */
    261261        bool acquireCurrentSnapshotName(QString &strName);
     262    /** @} */
     263
     264    /** @name Audio stuff.
     265     ** @{ */
     266        /** Acquires whether audio adapter is present. */
     267        bool acquireWhetherAudioAdapterPresent(bool &fPresent);
     268        /** Acquires whether audio adapter is enabled. */
     269        bool acquireWhetherAudioAdapterEnabled(bool &fEnabled);
     270        /** Acquires whether audio adapter output is enabled. */
     271        bool acquireWhetherAudioAdapterOutputEnabled(bool &fEnabled);
     272        /** Acquires whether audio adapter input is enabled. */
     273        bool acquireWhetherAudioAdapterInputEnabled(bool &fEnabled);
     274        /** Defines whether audio adapter output is enabled. */
     275        bool setAudioAdapterOutputEnabled(bool fEnabled);
     276        /** Defines whether audio adapter input is enabled. */
     277        bool setAudioAdapterInputEnabled(bool fEnabled);
    262278    /** @} */
    263279
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r98727 r98728  
    21732173        return;
    21742174
    2175     /* Access audio adapter: */
    2176     CAudioSettings const comAudioSettings = machine().GetAudioSettings();
    2177     CAudioAdapter        comAdapter       = comAudioSettings.GetAdapter();
    2178     AssertMsgReturnVoid(machine().isOk() && comAdapter.isNotNull(),
     2175    /* Make sure audio adapter present: */
     2176    bool fAdapterPresent = false;
     2177    uimachine()->acquireWhetherAudioAdapterPresent(fAdapterPresent);
     2178    AssertMsgReturnVoid(fAdapterPresent,
    21792179                        ("Audio adapter should NOT be null!\n"));
    21802180
    21812181    /* Make sure something had changed: */
    2182     if (comAdapter.GetEnabledOut() == static_cast<BOOL>(fEnabled))
    2183         return;
    2184 
    2185     /* Update audio output state: */
    2186     comAdapter.SetEnabledOut(fEnabled);
    2187     if (!comAdapter.isOk())
    2188     {
    2189         /* Make sure action is updated: */
    2190         uimachine()->updateStateAudioActions();
    2191         /* Notify about the error: */
    2192         return UINotificationMessage::cannotToggleAudioOutput(comAdapter, machineName(), fEnabled);
    2193     }
    2194 
    2195     /* Save machine-settings, make sure action is updated in case of failure: */
    2196     if (!uimachine()->saveSettings())
     2182    bool fAudioOutputEnabled = false;
     2183    uimachine()->acquireWhetherAudioAdapterOutputEnabled(fAudioOutputEnabled);
     2184    if (fAudioOutputEnabled == fEnabled)
     2185        return;
     2186
     2187    /* Update and save audio adapter output state,
     2188     * make sure action is updated in case of failure: */
     2189    if (   !uimachine()->setAudioAdapterOutputEnabled(fEnabled)
     2190        || !uimachine()->saveSettings())
    21972191        return uimachine()->updateStateAudioActions();
    21982192}
     
    22042198        return;
    22052199
    2206     /* Access audio adapter: */
    2207     CAudioSettings const comAudioSettings = machine().GetAudioSettings();
    2208     CAudioAdapter        comAdapter       = comAudioSettings.GetAdapter();
    2209     AssertMsgReturnVoid(machine().isOk() && comAdapter.isNotNull(),
     2200    /* Make sure audio adapter present: */
     2201    bool fAdapterPresent = false;
     2202    uimachine()->acquireWhetherAudioAdapterPresent(fAdapterPresent);
     2203    AssertMsgReturnVoid(fAdapterPresent,
    22102204                        ("Audio adapter should NOT be null!\n"));
    22112205
    22122206    /* Make sure something had changed: */
    2213     if (comAdapter.GetEnabledIn() == static_cast<BOOL>(fEnabled))
    2214         return;
    2215 
    2216     /* Update audio input state: */
    2217     comAdapter.SetEnabledIn(fEnabled);
    2218     if (!comAdapter.isOk())
    2219     {
    2220         /* Make sure action is updated: */
    2221         uimachine()->updateStateAudioActions();
    2222         /* Notify about the error: */
    2223         return UINotificationMessage::cannotToggleAudioInput(comAdapter, machineName(), fEnabled);
    2224     }
    2225 
    2226     /* Save machine-settings, make sure action is updated in case of failure: */
    2227     if (!uimachine()->saveSettings())
     2207    bool fAudioInputEnabled = false;
     2208    uimachine()->acquireWhetherAudioAdapterInputEnabled(fAudioInputEnabled);
     2209    if (fAudioInputEnabled == fEnabled)
     2210        return;
     2211
     2212    /* Update and save audio adapter input state,
     2213     * make sure action is updated in case of failure: */
     2214    if (   !uimachine()->setAudioAdapterInputEnabled(fEnabled)
     2215        || !uimachine()->saveSettings())
    22282216        return uimachine()->updateStateAudioActions();
    22292217}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98727 r98728  
    5757
    5858/* COM includes: */
     59#include "CAudioAdapter.h"
     60#include "CAudioSettings.h"
    5961#include "CEmulatedUSB.h"
    6062#include "CGraphicsAdapter.h"
     
    674676}
    675677
     678bool UISession::acquireWhetherAudioAdapterPresent(bool &fPresent)
     679{
     680    CMachine comMachine = machine();
     681    CAudioSettings comSettings = comMachine.GetAudioSettings();
     682    const bool fSuccess = comMachine.isOk();
     683    if (!fSuccess)
     684        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     685    else
     686    {
     687        CAudioAdapter comAdapter = comSettings.GetAdapter();
     688        fPresent = comSettings.isOk() && comAdapter.isNotNull();
     689    }
     690    return fSuccess;
     691}
     692
     693bool UISession::acquireWhetherAudioAdapterEnabled(bool &fEnabled)
     694{
     695    CMachine comMachine = machine();
     696    CAudioSettings comSettings = comMachine.GetAudioSettings();
     697    bool fSuccess = comMachine.isOk();
     698    if (!fSuccess)
     699        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     700    else
     701    {
     702        CAudioAdapter comAdapter = comSettings.GetAdapter();
     703        fSuccess = comSettings.isOk();
     704        if (!fSuccess)
     705            UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
     706        {
     707            const BOOL fAdapterEnabled = comAdapter.GetEnabled();
     708            fSuccess = comAdapter.isOk();
     709            if (!fSuccess)
     710                UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
     711            else
     712                fEnabled = fAdapterEnabled == TRUE;
     713        }
     714    }
     715    return fSuccess;
     716}
     717
     718bool UISession::acquireWhetherAudioAdapterOutputEnabled(bool &fEnabled)
     719{
     720    CMachine comMachine = machine();
     721    CAudioSettings comSettings = comMachine.GetAudioSettings();
     722    bool fSuccess = comMachine.isOk();
     723    if (!fSuccess)
     724        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     725    else
     726    {
     727        CAudioAdapter comAdapter = comSettings.GetAdapter();
     728        fSuccess = comSettings.isOk();
     729        if (!fSuccess)
     730            UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
     731        {
     732            const BOOL fOutputEnabled = comAdapter.GetEnabledOut();
     733            fSuccess = comAdapter.isOk();
     734            if (!fSuccess)
     735                UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
     736            else
     737                fEnabled = fOutputEnabled == TRUE;
     738        }
     739    }
     740    return fSuccess;
     741}
     742
     743bool UISession::acquireWhetherAudioAdapterInputEnabled(bool &fEnabled)
     744{
     745    CMachine comMachine = machine();
     746    CAudioSettings comSettings = comMachine.GetAudioSettings();
     747    bool fSuccess = comMachine.isOk();
     748    if (!fSuccess)
     749        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     750    else
     751    {
     752        CAudioAdapter comAdapter = comSettings.GetAdapter();
     753        fSuccess = comSettings.isOk();
     754        if (!fSuccess)
     755            UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
     756        {
     757            const BOOL fInputEnabled = comAdapter.GetEnabledIn();
     758            fSuccess = comAdapter.isOk();
     759            if (!fSuccess)
     760                UINotificationMessage::cannotAcquireAudioAdapterParameter(comAdapter);
     761            else
     762                fEnabled = fInputEnabled == TRUE;
     763        }
     764    }
     765    return fSuccess;
     766}
     767
     768bool UISession::setAudioAdapterOutputEnabled(bool fEnabled)
     769{
     770    CMachine comMachine = machine();
     771    CAudioSettings comSettings = comMachine.GetAudioSettings();
     772    bool fSuccess = comMachine.isOk();
     773    if (!fSuccess)
     774        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     775    else
     776    {
     777        CAudioAdapter comAdapter = comSettings.GetAdapter();
     778        fSuccess = comSettings.isOk();
     779        if (!fSuccess)
     780            UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
     781        {
     782            comAdapter.SetEnabledOut(fEnabled);
     783            fSuccess = comAdapter.isOk();
     784            if (!fSuccess)
     785                UINotificationMessage::cannotToggleAudioOutput(comAdapter, machineName(), fEnabled);
     786        }
     787    }
     788    return fSuccess;
     789}
     790
     791bool UISession::setAudioAdapterInputEnabled(bool fEnabled)
     792{
     793    CMachine comMachine = machine();
     794    CAudioSettings comSettings = comMachine.GetAudioSettings();
     795    bool fSuccess = comMachine.isOk();
     796    if (!fSuccess)
     797        UINotificationMessage::cannotAcquireMachineParameter(comMachine);
     798    else
     799    {
     800        CAudioAdapter comAdapter = comSettings.GetAdapter();
     801        fSuccess = comSettings.isOk();
     802        if (!fSuccess)
     803            UINotificationMessage::cannotAcquireAudioSettingsParameter(comSettings);
     804        {
     805            comAdapter.SetEnabledIn(fEnabled);
     806            fSuccess = comAdapter.isOk();
     807            if (!fSuccess)
     808                UINotificationMessage::cannotToggleAudioInput(comAdapter, machineName(), fEnabled);
     809        }
     810    }
     811    return fSuccess;
     812}
     813
    676814UIFrameBuffer *UISession::frameBuffer(ulong uScreenId) const
    677815{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98727 r98728  
    335335        /** Returns whether GA can be upgraded. */
    336336        bool guestAdditionsUpgradable();
     337    /** @} */
     338
     339    /** @name Audio stuff.
     340     ** @{ */
     341        /** Acquires whether audio adapter is present. */
     342        bool acquireWhetherAudioAdapterPresent(bool &fPresent);
     343        /** Acquires whether audio adapter is enabled. */
     344        bool acquireWhetherAudioAdapterEnabled(bool &fEnabled);
     345        /** Acquires whether audio adapter output is enabled. */
     346        bool acquireWhetherAudioAdapterOutputEnabled(bool &fEnabled);
     347        /** Acquires whether audio adapter input is enabled. */
     348        bool acquireWhetherAudioAdapterInputEnabled(bool &fEnabled);
     349        /** Defines whether audio adapter output is enabled. */
     350        bool setAudioAdapterOutputEnabled(bool fEnabled);
     351        /** Defines whether audio adapter input is enabled. */
     352        bool setAudioAdapterInputEnabled(bool fEnabled);
    337353    /** @} */
    338354
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