VirtualBox

Changeset 54305 in vbox


Ignore:
Timestamp:
Feb 19, 2015 6:38:23 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: Proper initialization/validation for Video Capture, Remote Desktop and Network Adapter Cable toggle-actions.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r54285 r54305  
    6969# include "CHostNetworkInterface.h"
    7070# include "CVRDEServer.h"
     71# include "CNetworkAdapter.h"
    7172# include "CEmulatedUSB.h"
    7273# ifdef VBOX_WITH_DRAG_AND_DROP
     
    20072008}
    20082009
     2010void UIMessageCenter::cannotToggleVideoCapture(const CMachine &machine, bool fEnable)
     2011{
     2012    /* Get machine-name preserving error-info: */
     2013    QString strMachineName(CMachine(machine).GetName());
     2014    error(0, MessageType_Error,
     2015          fEnable ?
     2016              tr("Failed to enable video capturing for the virtual machine <b>%1</b>.").arg(strMachineName) :
     2017              tr("Failed to disable video capturing for the virtual machine <b>%1</b>.").arg(strMachineName),
     2018          formatErrorInfo(machine));
     2019}
     2020
    20092021void UIMessageCenter::cannotToggleVRDEServer(const CVRDEServer &server, const QString &strMachineName, bool fEnable)
    20102022{
     
    20162028}
    20172029
    2018 void UIMessageCenter::cannotToggleVideoCapture(const CMachine &machine, bool fEnable)
    2019 {
    2020     /* Get machine-name preserving error-info: */
    2021     QString strMachineName(CMachine(machine).GetName());
    2022     error(0, MessageType_Error,
    2023           fEnable ?
    2024               tr("Failed to enable video capturing for the virtual machine <b>%1</b>.").arg(strMachineName) :
    2025               tr("Failed to disable video capturing for the virtual machine <b>%1</b>.").arg(strMachineName),
    2026           formatErrorInfo(machine));
     2030void UIMessageCenter::cannotToggleNetworkAdapterCable(const CNetworkAdapter &adapter, const QString &strMachineName, bool fConnect)
     2031{
     2032    error(0, MessageType_Error,
     2033          fConnect ?
     2034              tr("Failed to connect network adapter cable of the virtual machine <b>%1</b>.").arg(strMachineName) :
     2035              tr("Failed to disconnect network adapter cable of the virtual machine <b>%1</b>.").arg(strMachineName),
     2036          formatErrorInfo(adapter));
    20272037}
    20282038
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r54223 r54305  
    298298    void cannotAttachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const;
    299299    void cannotDetachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const;
     300    void cannotToggleVideoCapture(const CMachine &machine, bool fEnable);
    300301    void cannotToggleVRDEServer(const CVRDEServer &server, const QString &strMachineName, bool fEnable);
    301     void cannotToggleVideoCapture(const CMachine &machine, bool fEnable);
     302    void cannotToggleNetworkAdapterCable(const CNetworkAdapter &adapter, const QString &strMachineName, bool fConnect);
    302303    void remindAboutGuestAdditionsAreNotActive() const;
    303304    void cannotMountGuestAdditions(const QString &strMachineName) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r54303 r54305  
    16051605
    16061606    /* Update Video Capture state: */
    1607     AssertMsg(machine().isOk(), ("Machine should be OK!\n"));
    16081607    machine().SetVideoCaptureEnabled(fEnabled);
    1609     /* Machine is not OK? */
    16101608    if (!machine().isOk())
    16111609    {
     1610        /* Make sure action is updated: */
     1611        uisession()->updateStatusVideoCapture();
    16121612        /* Notify about the error: */
    1613         msgCenter().cannotToggleVideoCapture(machine(), fEnabled);
    1614         /* Make sure action is updated! */
     1613        return msgCenter().cannotToggleVideoCapture(machine(), fEnabled);
     1614    }
     1615
     1616    /* Save machine-settings: */
     1617    machine().SaveSettings();
     1618    if (!machine().isOk())
     1619    {
     1620        /* Make sure action is updated: */
    16151621        uisession()->updateStatusVideoCapture();
    1616     }
    1617     /* Machine is OK? */
    1618     else
    1619     {
    1620         /* Save machine-settings: */
    1621         machine().SaveSettings();
    1622         /* Machine is not OK? */
    1623         if (!machine().isOk())
    1624         {
    1625             /* Notify about the error: */
    1626             msgCenter().cannotSaveMachineSettings(machine());
    1627             /* Make sure action is updated! */
    1628             uisession()->updateStatusVideoCapture();
    1629         }
     1622        /* Notify about the error: */
     1623        return msgCenter().cannotSaveMachineSettings(machine());
    16301624    }
    16311625}
     
    16391633    /* Access VRDE server: */
    16401634    CVRDEServer server = machine().GetVRDEServer();
    1641     AssertMsg(!server.isNull(), ("VRDE server should NOT be null!\n"));
    1642     if (!machine().isOk() || server.isNull())
    1643         return;
     1635    AssertMsgReturnVoid(machine().isOk() && !server.isNull(),
     1636                        ("VRDE server should NOT be null!\n"));
    16441637
    16451638    /* Make sure something had changed: */
     
    16471640        return;
    16481641
    1649     /* Server is OK? */
    1650     if (server.isOk())
    1651     {
    1652         /* Update VRDE server state: */
    1653         server.SetEnabled(fEnabled);
    1654         /* Server still OK? */
    1655         if (server.isOk())
    1656         {
    1657             /* Save machine-settings: */
    1658             machine().SaveSettings();
    1659             /* Machine still OK? */
    1660             if (!machine().isOk())
    1661             {
    1662                 /* Notify about the error: */
    1663                 msgCenter().cannotSaveMachineSettings(machine());
    1664                 /* Make sure action is updated! */
    1665                 uisession()->updateStatusVRDE();
    1666             }
    1667         }
    1668         else
    1669         {
    1670             /* Notify about the error: */
    1671             msgCenter().cannotToggleVRDEServer(server, machineName(), fEnabled);
    1672             /* Make sure action is updated! */
    1673             uisession()->updateStatusVRDE();
    1674         }
     1642    /* Update VRDE server state: */
     1643    server.SetEnabled(fEnabled);
     1644    if (!server.isOk())
     1645    {
     1646        /* Make sure action is updated: */
     1647        uisession()->updateStatusVRDE();
     1648        /* Notify about the error: */
     1649        return msgCenter().cannotToggleVRDEServer(server, machineName(), fEnabled);
     1650    }
     1651
     1652    /* Save machine-settings: */
     1653    machine().SaveSettings();
     1654    if (!machine().isOk())
     1655    {
     1656        /* Make sure action is updated: */
     1657        uisession()->updateStatusVRDE();
     1658        /* Notify about the error: */
     1659        return msgCenter().cannotSaveMachineSettings(machine());
    16751660    }
    16761661}
     
    18281813}
    18291814
    1830 /** Toggles network adapter's <i>Cable Connected</i> state. */
    18311815void UIMachineLogic::sltToggleNetworkAdapterConnection()
    18321816{
     1817    /* Do not process if window(s) missed! */
     1818    if (!isMachineWindowsCreated())
     1819        return;
     1820
    18331821    /* Get and check 'the sender' action object: */
    18341822    QAction *pAction = qobject_cast<QAction*>(sender());
    1835     AssertReturnVoid(pAction);
     1823    AssertMsgReturnVoid(pAction, ("Sender action should NOT be null!\n"));
    18361824
    18371825    /* Get operation target: */
    18381826    CNetworkAdapter adapter = machine().GetNetworkAdapter((ULONG)pAction->property("slot").toInt());
    1839     AssertReturnVoid(machine().isOk() && !adapter.isNull());
     1827    AssertMsgReturnVoid(machine().isOk() && !adapter.isNull(),
     1828                        ("Network adapter should NOT be null!\n"));
    18401829
    18411830    /* Connect/disconnect cable to/from target: */
    1842     adapter.SetCableConnected(!adapter.GetCableConnected());
     1831    const bool fConnect = !adapter.GetCableConnected();
     1832    adapter.SetCableConnected(fConnect);
     1833    if (!adapter.isOk())
     1834        return msgCenter().cannotToggleNetworkAdapterCable(adapter, machineName(), fConnect);
     1835
     1836    /* Save machine-settings: */
    18431837    machine().SaveSettings();
    18441838    if (!machine().isOk())
    1845         msgCenter().cannotSaveMachineSettings(machine());
     1839        return msgCenter().cannotSaveMachineSettings(machine());
    18461840}
    18471841
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r54303 r54305  
    746746void UISession::sltVRDEChange()
    747747{
    748     /* Get VRDE server: */
    749     const CVRDEServer &server = machine().GetVRDEServer();
    750     bool fIsVRDEServerAvailable = !server.isNull();
    751     /* Show/Hide VRDE action depending on VRDE server availability status: */
    752     // TODO: Is this status can be changed at runtime?
    753     //       Because if no => the place for that stuff is in prepareActions().
    754     actionPool()->action(UIActionIndexRT_M_View_T_VRDEServer)->setVisible(fIsVRDEServerAvailable);
    755     /* Check/Uncheck VRDE action depending on VRDE server activity status: */
    756     if (fIsVRDEServerAvailable)
    757         actionPool()->action(UIActionIndexRT_M_View_T_VRDEServer)->setChecked(server.GetEnabled());
     748    /* Make sure VRDE server is present: */
     749    const CVRDEServer server = machine().GetVRDEServer();
     750    AssertMsgReturnVoid(machine().isOk() && !server.isNull(),
     751                        ("VRDE server should NOT be null!\n"));
     752
     753    /* Check/Uncheck VRDE Server action depending on feature status: */
     754    actionPool()->action(UIActionIndexRT_M_View_T_VRDEServer)->blockSignals(true);
     755    actionPool()->action(UIActionIndexRT_M_View_T_VRDEServer)->setChecked(server.GetEnabled());
     756    actionPool()->action(UIActionIndexRT_M_View_T_VRDEServer)->blockSignals(false);
     757
    758758    /* Notify listeners about VRDE change: */
    759759    emit sigVRDEChange();
     
    763763{
    764764    /* Check/Uncheck Video Capture action depending on feature status: */
     765    actionPool()->action(UIActionIndexRT_M_View_M_VideoCapture_T_Start)->blockSignals(true);
    765766    actionPool()->action(UIActionIndexRT_M_View_M_VideoCapture_T_Start)->setChecked(machine().GetVideoCaptureEnabled());
     767    actionPool()->action(UIActionIndexRT_M_View_M_VideoCapture_T_Start)->blockSignals(false);
     768
    766769    /* Notify listeners about Video Capture change: */
    767770    emit sigVideoCaptureChange();
     
    10741077        /* Get host: */
    10751078        const CHost host = vboxGlobal().host();
    1076         UIExtraDataMetaDefs::RuntimeMenuDevicesActionType restriction = UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_Invalid;
     1079        UIExtraDataMetaDefs::RuntimeMenuViewActionType restrictionForView = UIExtraDataMetaDefs::RuntimeMenuViewActionType_Invalid;
     1080        UIExtraDataMetaDefs::RuntimeMenuDevicesActionType restrictionForDevices = UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_Invalid;
     1081
     1082        /* VRDE server stuff: */
     1083        {
     1084            /* Initialize 'View' menu: */
     1085            const CVRDEServer server = machine().GetVRDEServer();
     1086            if (server.isNull())
     1087                restrictionForView = (UIExtraDataMetaDefs::RuntimeMenuViewActionType)(restrictionForView | UIExtraDataMetaDefs::RuntimeMenuViewActionType_VRDEServer);
     1088        }
    10771089
    10781090        /* Storage stuff: */
     
    10931105            pFloppyDevicesMenu->setData(iDevicesCountFD);
    10941106            if (!iDevicesCountCD)
    1095                 restriction = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restriction | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_OpticalDevices);
     1107                restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_OpticalDevices);
    10961108            if (!iDevicesCountFD)
    1097                 restriction = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restriction | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_FloppyDevices);
     1109                restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_FloppyDevices);
    10981110        }
    10991111
     
    11141126            }
    11151127            if (!fAtLeastOneAdapterActive)
    1116                 restriction = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restriction | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_Network);
     1128                restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_Network);
    11171129        }
    11181130
     
    11241136                                     && machine().GetUSBProxyAvailable();
    11251137            if (!fUSBEnabled)
    1126                 restriction = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restriction | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_USBDevices);
     1138                restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_USBDevices);
    11271139        }
    11281140
     
    11331145            const bool fWebCamsEnabled = host.isOk() && !machine().GetUSBControllers().isEmpty();
    11341146            if (!fWebCamsEnabled)
    1135                 restriction = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restriction | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_WebCams);
    1136         }
    1137 
    1138         /* Apply cumulative restriction: */
    1139         actionPool()->toRuntime()->setRestrictionForMenuDevices(UIActionRestrictionLevel_Session, restriction);
     1147                restrictionForDevices = (UIExtraDataMetaDefs::RuntimeMenuDevicesActionType)(restrictionForDevices | UIExtraDataMetaDefs::RuntimeMenuDevicesActionType_WebCams);
     1148        }
     1149
     1150        /* Apply cumulative restriction for 'View' menu: */
     1151        actionPool()->toRuntime()->setRestrictionForMenuView(UIActionRestrictionLevel_Session, restrictionForView);
     1152        /* Apply cumulative restriction for 'Devices' menu: */
     1153        actionPool()->toRuntime()->setRestrictionForMenuDevices(UIActionRestrictionLevel_Session, restrictionForDevices);
    11401154
    11411155#ifdef Q_WS_MAC
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r54160 r54305  
    245245    const QVector<ComObjPtr<UIFrameBuffer> >& frameBuffers() const { return m_frameBufferVector; }
    246246
    247     /* Temporary API: */
     247    /** Updates VRDE Server action state. */
    248248    void updateStatusVRDE() { sltVRDEChange(); }
     249    /** Updates Video Capture action state. */
    249250    void updateStatusVideoCapture() { sltVideoCaptureChange(); }
    250251
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