VirtualBox

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


Ignore:
Timestamp:
Feb 17, 2023 3:21:52 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155917
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking CConsole wrapper usage step-by-step; This one is about webcams stuff.

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

Legend:

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

    r98547 r98621  
    758758        QApplication::translate("UIMessageCenter", "Failed to acquire update agent parameter.") +
    759759        UIErrorString::formatErrorInfo(comAgent));
     760}
     761
     762/* static */
     763void UINotificationMessage::cannotAcquireEmulatedUSBParameter(const CEmulatedUSB &comDispatcher)
     764{
     765    createMessage(
     766        QApplication::translate("UIMessageCenter", "Emulated USB failure ..."),
     767        QApplication::translate("UIMessageCenter", "Failed to acquire emulated USB parameter.") +
     768        UIErrorString::formatErrorInfo(comDispatcher));
    760769}
    761770
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r98547 r98621  
    326326          * @param  comAgent  Brings the object parameter get acquired from. */
    327327        static void cannotAcquireUpdateAgentParameter(const CUpdateAgent &comAgent);
     328        /** Notifies about inability to acquire IEmulatedUSB parameter.
     329          * @param  comDispatcher  Brings the object parameter get acquired from. */
     330        static void cannotAcquireEmulatedUSBParameter(const CEmulatedUSB &comDispatcher);
    328331        /** Notifies about inability to acquire IVirtualSystemDescription parameter.
    329332          * @param  comVsd  Brings the object parameter get acquired from. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98620 r98621  
    559559{
    560560    return uisession()->detachUSBDevice(uId);
     561}
     562
     563bool UIMachine::webcamDevices(QList<WebcamDeviceInfo> &guiWebcamDevices)
     564{
     565    return uisession()->webcamDevices(guiWebcamDevices);
     566}
     567
     568bool UIMachine::webcamAttach(const QString &strPath, const QString &strName)
     569{
     570    return uisession()->webcamAttach(strPath, strName);
     571}
     572
     573bool UIMachine::webcamDetach(const QString &strPath, const QString &strName)
     574{
     575    return uisession()->webcamDetach(strPath, strName);
    561576}
    562577
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98620 r98621  
    417417        /** Detaches USB device with passed @a uId. */
    418418        bool detachUSBDevice(const QUuid &uId);
     419
     420        /** Returns a list of web cam devices. */
     421        bool webcamDevices(QList<WebcamDeviceInfo> &guiWebcamDevices);
     422        /** Attaches web cam device with passed @a strName and @a strPath. */
     423        bool webcamAttach(const QString &strPath, const QString &strName);
     424        /** Detaches web cam device with passed @a strName and @a strPath. */
     425        bool webcamDetach(const QString &strPath, const QString &strName);
    419426    /** @} */
    420427
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineDefs.h

    r98620 r98621  
    8888};
    8989
     90/** Robust struct to bring web cam device info to machine-logic. */
     91struct WebcamDeviceInfo
     92{
     93    QString  m_strName;
     94    QString  m_strPath;
     95    QString  m_strToolTip;
     96    bool     m_fIsChecked;
     97};
     98
    9099#endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineDefs_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r98620 r98621  
    11071107    m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_Network] =         &UIMachineLogic::updateMenuDevicesNetwork;
    11081108    m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_USBDevices] =      &UIMachineLogic::updateMenuDevicesUSB;
    1109     m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_WebCams] =         &UIMachineLogic::updateMenuDevicesWebCams;
     1109    m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_WebCams] =         &UIMachineLogic::updateMenuDevicesWebcams;
    11101110    m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_SharedClipboard] = &UIMachineLogic::updateMenuDevicesSharedClipboard;
    11111111    m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_DragAndDrop] =     &UIMachineLogic::updateMenuDevicesDragAndDrop;
     
    22802280}
    22812281
    2282 void UIMachineLogic::sltAttachWebCamDevice()
     2282void UIMachineLogic::sltAttachWebcamDevice()
    22832283{
    22842284    /* Get and check sender action object: */
     
    22892289    WebCamTarget target = pAction->data().value<WebCamTarget>();
    22902290
    2291     /* Get current emulated USB: */
    2292     CEmulatedUSB dispatcher = console().GetEmulatedUSB();
    2293 
    22942291    /* Attach webcam device: */
    22952292    if (target.attach)
    2296     {
    2297         /* Try to attach corresponding device: */
    2298         dispatcher.WebcamAttach(target.path, "");
    2299         /* Check if dispatcher is OK: */
    2300         if (!dispatcher.isOk())
    2301             UINotificationMessage::cannotAttachWebCam(dispatcher, target.name, machineName());
    2302     }
     2293        uimachine()->webcamAttach(target.path, target.name);
    23032294    /* Detach webcam device: */
    23042295    else
    2305     {
    2306         /* Try to detach corresponding device: */
    2307         dispatcher.WebcamDetach(target.path);
    2308         /* Check if dispatcher is OK: */
    2309         if (!dispatcher.isOk())
    2310             UINotificationMessage::cannotDetachWebCam(dispatcher, target.name, machineName());
    2311     }
     2296        uimachine()->webcamDetach(target.path, target.name);
    23122297}
    23132298
     
    28182803}
    28192804
    2820 void UIMachineLogic::updateMenuDevicesWebCams(QMenu *pMenu)
     2805void UIMachineLogic::updateMenuDevicesWebcams(QMenu *pMenu)
    28212806{
    28222807    /* Clear contents: */
    28232808    pMenu->clear();
    28242809
    2825     /* Get current host: */
    2826     const CHost host = uiCommon().host();
    2827     /* Get host webcam list: */
    2828     const CHostVideoInputDeviceVector webcams = host.GetVideoInputDevices();
     2810    /* Acquire device list: */
     2811    QList<WebcamDeviceInfo> guiWebcamDevices;
     2812    const bool fSuccess = uimachine()->webcamDevices(guiWebcamDevices);
    28292813
    28302814    /* If webcam list is empty: */
    2831     if (webcams.isEmpty())
     2815    if (!fSuccess || guiWebcamDevices.isEmpty())
    28322816    {
    28332817        /* Add only one - "empty" action: */
     
    28422826    {
    28432827        /* Populate menu with host webcams: */
    2844         const QVector<QString> attachedWebcamPaths = console().GetEmulatedUSB().GetWebcams();
    2845         foreach (const CHostVideoInputDevice &webcam, webcams)
    2846         {
    2847             /* Get webcam data: */
    2848             const QString strWebcamName = webcam.GetName();
    2849             const QString strWebcamPath = webcam.GetPath();
    2850 
    2851             /* Create/configure webcam action: */
    2852             QAction *pAttachWebcamAction = pMenu->addAction(strWebcamName,
    2853                                                             this, SLOT(sltAttachWebCamDevice()));
    2854             pAttachWebcamAction->setToolTip(uiCommon().usbToolTip(webcam));
     2828        foreach (const WebcamDeviceInfo &guiWebcamDevice, guiWebcamDevices)
     2829        {
     2830            /* Create webcam device action: */
     2831            QAction *pAttachWebcamAction = pMenu->addAction(guiWebcamDevice.m_strName,
     2832                                                            this, SLOT(sltAttachWebcamDevice()));
     2833            pAttachWebcamAction->setToolTip(guiWebcamDevice.m_strToolTip);
    28552834            pAttachWebcamAction->setCheckable(true);
    2856 
    2857             /* Check if that webcam was already attached to this session: */
    2858             pAttachWebcamAction->setChecked(attachedWebcamPaths.contains(strWebcamPath));
    2859 
    2860             /* Set USB attach data: */
    2861             pAttachWebcamAction->setData(QVariant::fromValue(WebCamTarget(!pAttachWebcamAction->isChecked(), strWebcamName, strWebcamPath)));
     2835            pAttachWebcamAction->setChecked(guiWebcamDevice.m_fIsChecked);
     2836            pAttachWebcamAction->setData(QVariant::fromValue(WebCamTarget(!pAttachWebcamAction->isChecked(),
     2837                                                                          guiWebcamDevice.m_strName,
     2838                                                                          guiWebcamDevice.m_strPath)));
    28622839        }
    28632840    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r98605 r98621  
    302302    void sltOpenSettingsDialogSharedFolders();
    303303    void sltAttachUSBDevice();
    304     void sltAttachWebCamDevice();
     304    void sltAttachWebcamDevice();
    305305    void sltChangeSharedClipboardType(QAction *pAction);
    306306    void sltToggleNetworkAdapterConnection();
     
    353353    void updateMenuDevicesUSB(QMenu *pMenu);
    354354    /** Update 'Devices' : 'Web Cams' menu routine. */
    355     void updateMenuDevicesWebCams(QMenu *pMenu);
     355    void updateMenuDevicesWebcams(QMenu *pMenu);
    356356    /** Update 'Devices' : 'Shared Clipboard' menu routine. */
    357357    void updateMenuDevicesSharedClipboard(QMenu *pMenu);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98620 r98621  
    5757
    5858/* COM includes: */
     59#include "CEmulatedUSB.h"
    5960#include "CGraphicsAdapter.h"
    6061#include "CHostNetworkInterface.h"
    6162#include "CHostUSBDevice.h"
     63#include "CHostVideoInputDevice.h"
    6264#include "CMedium.h"
    6365#include "CMediumAttachment.h"
     
    466468        UINotificationMessage::cannotDetachUSBDevice(comConsole, uiCommon().usbDetails(comUSBDevice));
    467469        /// @todo make sure UICommon::usbDetails is checked for errors as well
     470    }
     471    return fSuccess;
     472}
     473
     474bool UISession::webcamDevices(QList<WebcamDeviceInfo> &guiWebcamDevices)
     475{
     476    const CHost comHost = uiCommon().host();
     477    const CHostVideoInputDeviceVector comHostVideoInputDevices = comHost.GetVideoInputDevices();
     478    bool fSuccess = comHost.isOk();
     479    if (!fSuccess)
     480        UINotificationMessage::cannotAcquireHostParameter(comHost);
     481    else
     482    {
     483        CConsole comConsole = console();
     484        CEmulatedUSB comEmulatedUSB = comConsole.GetEmulatedUSB();
     485        fSuccess = comConsole.isOk();
     486        if (!fSuccess)
     487            UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
     488        else
     489        {
     490            const QVector<QString> attachedWebcamPaths = comEmulatedUSB.GetWebcams();
     491            fSuccess = comEmulatedUSB.isOk();
     492            if (!fSuccess)
     493                UINotificationMessage::cannotAcquireEmulatedUSBParameter(comEmulatedUSB);
     494            else
     495            {
     496                foreach (const CHostVideoInputDevice &comHostVideoInputDevice, comHostVideoInputDevices)
     497                {
     498                    /* Fill structure fields: */
     499                    WebcamDeviceInfo guiWebcamDevice;
     500                    if (fSuccess)
     501                    {
     502                        guiWebcamDevice.m_strName = comHostVideoInputDevice.GetName();
     503                        fSuccess = comHostVideoInputDevice.isOk();
     504                    }
     505                    if (fSuccess)
     506                    {
     507                        guiWebcamDevice.m_strPath = comHostVideoInputDevice.GetPath();
     508                        fSuccess = comHostVideoInputDevice.isOk();
     509                    }
     510                    if (fSuccess)
     511                    {
     512                        /// @todo make sure UICommon::usbToolTip is checked for errors as well
     513                        guiWebcamDevice.m_strToolTip = uiCommon().usbToolTip(comHostVideoInputDevice);
     514                        fSuccess = comHostVideoInputDevice.isOk();
     515                    }
     516                    if (fSuccess)
     517                        guiWebcamDevice.m_fIsChecked = attachedWebcamPaths.contains(guiWebcamDevice.m_strPath);
     518
     519                    /* Append or break if necessary: */
     520                    if (fSuccess)
     521                        guiWebcamDevices << guiWebcamDevice;
     522                    else
     523                        break;
     524                }
     525            }
     526        }
     527    }
     528    return fSuccess;
     529}
     530
     531bool UISession::webcamAttach(const QString &strPath, const QString &strName)
     532{
     533    CConsole comConsole = console();
     534    CEmulatedUSB comDispatcher = comConsole.GetEmulatedUSB();
     535    bool fSuccess = comConsole.isOk();
     536    if (!fSuccess)
     537        UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
     538    else
     539    {
     540        comDispatcher.WebcamAttach(strPath, "");
     541        fSuccess = comDispatcher.isOk();
     542        if (!fSuccess)
     543            UINotificationMessage::cannotAttachWebCam(comDispatcher, strName, machineName());
     544    }
     545    return fSuccess;
     546}
     547
     548bool UISession::webcamDetach(const QString &strPath, const QString &strName)
     549{
     550    CConsole comConsole = console();
     551    CEmulatedUSB comDispatcher = comConsole.GetEmulatedUSB();
     552    bool fSuccess = comConsole.isOk();
     553    if (!fSuccess)
     554        UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
     555    else
     556    {
     557        comDispatcher.WebcamDetach(strPath);
     558        fSuccess = comDispatcher.isOk();
     559        if (!fSuccess)
     560            UINotificationMessage::cannotDetachWebCam(comDispatcher, strName, machineName());
    468561    }
    469562    return fSuccess;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98620 r98621  
    282282        /** Detaches USB device with passed @a uId. */
    283283        bool detachUSBDevice(const QUuid &uId);
     284
     285        /** Returns a list of web cam devices. */
     286        bool webcamDevices(QList<WebcamDeviceInfo> &guiWebcamDevices);
     287        /** Attaches web cam device with passed @a strName and @a strPath. */
     288        bool webcamAttach(const QString &strPath, const QString &strName);
     289        /** Detaches web cam device with passed @a strName and @a strPath. */
     290        bool webcamDetach(const QString &strPath, const QString &strName);
    284291    /** @} */
    285292
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