VirtualBox

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


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

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

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98617 r98620  
    544544{
    545545    return uisession()->putEventMultiTouch(iCount, contacts, fIsTouchScreen, uScanTime);
     546}
     547
     548bool UIMachine::usbDevices(QList<USBDeviceInfo> &guiUSBDevices)
     549{
     550    return uisession()->usbDevices(guiUSBDevices);
     551}
     552
     553bool UIMachine::attachUSBDevice(const QUuid &uId)
     554{
     555    return uisession()->attachUSBDevice(uId);
     556}
     557
     558bool UIMachine::detachUSBDevice(const QUuid &uId)
     559{
     560    return uisession()->detachUSBDevice(uId);
    546561}
    547562
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98617 r98620  
    409409    /** @} */
    410410
     411    /** @name USB stuff.
     412     ** @{ */
     413        /** Returns a list of USB devices. */
     414        bool usbDevices(QList<USBDeviceInfo> &guiUSBDevices);
     415        /** Attaches USB device with passed @a uId. */
     416        bool attachUSBDevice(const QUuid &uId);
     417        /** Detaches USB device with passed @a uId. */
     418        bool detachUSBDevice(const QUuid &uId);
     419    /** @} */
     420
    411421    /** @name Virtualization stuff.
    412422     ** @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineDefs.h

    r98103 r98620  
    3131# pragma once
    3232#endif
     33
     34/* Qt includes: */
     35#include <QString>
     36#include <QUuid>
    3337
    3438/* Other VBox includes: */
     
    7478};
    7579
     80/** Robust struct to bring USB device info to machine-logic. */
     81struct USBDeviceInfo
     82{
     83    QUuid    m_uId;
     84    QString  m_strName;
     85    QString  m_strToolTip;
     86    bool     m_fIsChecked;
     87    bool     m_fIsEnabled;
     88};
     89
    7690#endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineDefs_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r98606 r98620  
    22742274    /* Attach USB device: */
    22752275    if (target.attach)
    2276     {
    2277         /* Try to attach corresponding device: */
    2278         console().AttachUSBDevice(target.id, QString(""));
    2279         /* Check if console is OK: */
    2280         if (!console().isOk())
    2281         {
    2282             /* Get current host: */
    2283             CHost host = uiCommon().host();
    2284             /* Search the host for the corresponding USB device: */
    2285             CHostUSBDevice hostDevice = host.FindUSBDeviceById(target.id);
    2286             /* Get USB device from host USB device: */
    2287             CUSBDevice device(hostDevice);
    2288             /* Show a message about procedure failure: */
    2289             UINotificationMessage::cannotAttachUSBDevice(console(), uiCommon().usbDetails(device));
    2290         }
    2291     }
     2276        uimachine()->attachUSBDevice(target.id);
    22922277    /* Detach USB device: */
    22932278    else
    2294     {
    2295         /* Search the console for the corresponding USB device: */
    2296         CUSBDevice device = console().FindUSBDeviceById(target.id);
    2297         /* Try to detach corresponding device: */
    2298         console().DetachUSBDevice(target.id);
    2299         /* Check if console is OK: */
    2300         if (!console().isOk())
    2301         {
    2302             /* Show a message about procedure failure: */
    2303             UINotificationMessage::cannotDetachUSBDevice(console(), uiCommon().usbDetails(device));
    2304         }
    2305     }
     2279        uimachine()->detachUSBDevice(target.id);
    23062280}
    23072281
     
    28112785void UIMachineLogic::updateMenuDevicesUSB(QMenu *pMenu)
    28122786{
    2813     /* Get current host: */
    2814     const CHost host = uiCommon().host();
    2815     /* Get host USB device list: */
    2816     const CHostUSBDeviceVector devices = host.GetUSBDevices();
     2787    /* Acquire device list: */
     2788    QList<USBDeviceInfo> guiUSBDevices;
     2789    const bool fSuccess = uimachine()->usbDevices(guiUSBDevices);
    28172790
    28182791    /* If device list is empty: */
    2819     if (devices.isEmpty())
     2792    if (!fSuccess || guiUSBDevices.isEmpty())
    28202793    {
    28212794        /* Add only one - "empty" action: */
     
    28302803    {
    28312804        /* Populate menu with host USB devices: */
    2832         foreach (const CHostUSBDevice& hostDevice, devices)
     2805        foreach (const USBDeviceInfo &guiUSBDevice, guiUSBDevices)
    28332806        {
    2834             /* Get USB device from current host USB device: */
    2835             const CUSBDevice device(hostDevice);
    2836 
    28372807            /* Create USB device action: */
    2838             QAction *pAttachUSBAction = pMenu->addAction(uiCommon().usbDetails(device),
     2808            QAction *pAttachUSBAction = pMenu->addAction(guiUSBDevice.m_strName,
    28392809                                                         this, SLOT(sltAttachUSBDevice()));
    2840             pAttachUSBAction->setToolTip(uiCommon().usbToolTip(device));
     2810            pAttachUSBAction->setToolTip(guiUSBDevice.m_strToolTip);
    28412811            pAttachUSBAction->setCheckable(true);
    2842 
    2843             /* Check if that USB device was already attached to this session: */
    2844             const CUSBDevice attachedDevice = console().FindUSBDeviceById(device.GetId());
    2845             pAttachUSBAction->setChecked(!attachedDevice.isNull());
    2846             pAttachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);
    2847 
    2848             /* Set USB attach data: */
    2849             pAttachUSBAction->setData(QVariant::fromValue(USBTarget(!pAttachUSBAction->isChecked(), device.GetId())));
     2812            pAttachUSBAction->setChecked(guiUSBDevice.m_fIsChecked);
     2813            pAttachUSBAction->setEnabled(guiUSBDevice.m_fIsEnabled);
     2814            pAttachUSBAction->setData(QVariant::fromValue(USBTarget(!pAttachUSBAction->isChecked(),
     2815                                                                    guiUSBDevice.m_uId)));
    28502816        }
    28512817    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98617 r98620  
    6666#include "CSystemProperties.h"
    6767#include "CUSBController.h"
     68#include "CUSBDevice.h"
    6869#include "CUSBDeviceFilter.h"
    6970#include "CUSBDeviceFilters.h"
     
    7778# include <iprt/ldr.h>
    7879#endif
     80
     81/* VirtualBox interface declarations: */
     82#include <VBox/com/VirtualBox.h>
    7983
    8084/* External includes: */
     
    373377    if (!fSuccess)
    374378        UINotificationMessage::cannotChangeMouseParameter(comMouse);
     379    return fSuccess;
     380}
     381
     382bool UISession::usbDevices(QList<USBDeviceInfo> &guiUSBDevices)
     383{
     384    const CHost comHost = uiCommon().host();
     385    const CHostUSBDeviceVector comHostUSBDevices = comHost.GetUSBDevices();
     386    bool fSuccess = comHost.isOk();
     387    if (!fSuccess)
     388        UINotificationMessage::cannotAcquireHostParameter(comHost);
     389    else
     390    {
     391        foreach (const CHostUSBDevice &comHostUSBDevice, comHostUSBDevices)
     392        {
     393            /* Get USB device from current host USB device,
     394             * this stuff requires #include <VBox/com/VirtualBox.h> */
     395            const CUSBDevice comUSBDevice(comHostUSBDevice);
     396
     397            /* Fill structure fields: */
     398            USBDeviceInfo guiUSBDevice;
     399            if (fSuccess)
     400            {
     401                guiUSBDevice.m_uId = comUSBDevice.GetId();
     402                fSuccess = comUSBDevice.isOk();
     403            }
     404            if (fSuccess)
     405            {
     406                /// @todo make sure UICommon::usbDetails is checked for errors as well
     407                guiUSBDevice.m_strName = uiCommon().usbDetails(comUSBDevice);
     408                fSuccess = comUSBDevice.isOk();
     409            }
     410            if (fSuccess)
     411            {
     412                /// @todo make sure UICommon::usbToolTip is checked for errors as well
     413                guiUSBDevice.m_strToolTip = uiCommon().usbToolTip(comUSBDevice);
     414                fSuccess = comUSBDevice.isOk();
     415            }
     416            if (fSuccess)
     417            {
     418                /* Check if that USB device was already attached to this session;
     419                 * Nothing to check for errors here because error is valid case as well. */
     420                const CUSBDevice comAttachedDevice = console().FindUSBDeviceById(guiUSBDevice.m_uId);
     421                guiUSBDevice.m_fIsChecked = !comAttachedDevice.isNull();
     422            }
     423            if (fSuccess)
     424            {
     425                guiUSBDevice.m_fIsEnabled = comHostUSBDevice.GetState() != KUSBDeviceState_Unavailable;
     426                fSuccess = comHostUSBDevice.isOk();
     427            }
     428
     429            /* Append or break if necessary: */
     430            if (fSuccess)
     431                guiUSBDevices << guiUSBDevice;
     432            else
     433                break;
     434        }
     435    }
     436    return fSuccess;
     437}
     438
     439bool UISession::attachUSBDevice(const QUuid &uId)
     440{
     441    CConsole comConsole = console();
     442    comConsole.AttachUSBDevice(uId, QString(""));
     443    const bool fSuccess = comConsole.isOk();
     444    if (!fSuccess)
     445    {
     446        CHost comHost = uiCommon().host();
     447        /* Nothing to check for errors here because error is valid case as well. */
     448        CHostUSBDevice comHostUSBDevice = comHost.FindUSBDeviceById(uId);
     449        /* Get USB device from current host USB device,
     450         * this stuff requires #include <VBox/com/VirtualBox.h> */
     451        CUSBDevice comUSBDevice(comHostUSBDevice);
     452        UINotificationMessage::cannotAttachUSBDevice(comConsole, uiCommon().usbDetails(comUSBDevice));
     453        /// @todo make sure UICommon::usbDetails is checked for errors as well
     454    }
     455    return fSuccess;
     456}
     457
     458bool UISession::detachUSBDevice(const QUuid &uId)
     459{
     460    CConsole comConsole = console();
     461    comConsole.DetachUSBDevice(uId);
     462    const bool fSuccess = comConsole.isOk();
     463    if (!fSuccess)
     464    {
     465        CUSBDevice comUSBDevice = CConsole(comConsole).FindUSBDeviceById(uId);
     466        UINotificationMessage::cannotDetachUSBDevice(comConsole, uiCommon().usbDetails(comUSBDevice));
     467        /// @todo make sure UICommon::usbDetails is checked for errors as well
     468    }
    375469    return fSuccess;
    376470}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98617 r98620  
    4040/* GUI includes: */
    4141#include "UIExtraDataDefs.h"
     42#include "UIMachineDefs.h"
    4243#include "UIMediumDefs.h"
    4344#include "UIMousePointerShapeData.h"
     
    273274    /** @} */
    274275
     276    /** @name USB stuff.
     277     ** @{ */
     278        /** Returns a list of USB devices. */
     279        bool usbDevices(QList<USBDeviceInfo> &guiUSBDevices);
     280        /** Attaches USB device with passed @a uId. */
     281        bool attachUSBDevice(const QUuid &uId);
     282        /** Detaches USB device with passed @a uId. */
     283        bool detachUSBDevice(const QUuid &uId);
     284    /** @} */
     285
    275286    /** @name Guest additions stuff.
    276287     ** @{ */
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