VirtualBox

Changeset 49333 in vbox


Ignore:
Timestamp:
Oct 30, 2013 1:42:57 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 7037: Runtime UI: Extending *Devices* menu with *Webcams* menu.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox2.qrc

    r48388 r49333  
    217217        <file alias="vrdp_warning_16px.png">images/vrdp_warning_16px.png</file>
    218218        <file alias="reset_warnings_16px.png">images/reset_warnings_16px.png</file>
     219        <file alias="web_camera_16px.png">images/web_camera_16px.png</file>
     220        <file alias="web_camera_disabled_16px.png">images/web_camera_disabled_16px.png</file>
    219221    </qresource>
    220222</RCC>
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r49272 r49333  
    6464#include "CHostNetworkInterface.h"
    6565#include "CVRDEServer.h"
     66#include "CEmulatedUSB.h"
    6667#ifdef VBOX_WITH_DRAG_AND_DROP
    6768# include "CGuest.h"
     
    19321933             .arg(strDevice, strMachineName),
    19331934          formatErrorInfo(errorInfo));
     1935}
     1936
     1937void UIMessageCenter::cannotAttachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const
     1938{
     1939    error(0, MessageType_Error,
     1940          tr("Failed to attach the webcam <b>%1</b> to the virtual machine <b>%2</b>.")
     1941             .arg(strWebCamName, strMachineName),
     1942          formatErrorInfo(dispatcher));
     1943}
     1944
     1945void UIMessageCenter::cannotDetachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const
     1946{
     1947    error(0, MessageType_Error,
     1948          tr("Failed to detach the webcam <b>%1</b> from the virtual machine <b>%2</b>.")
     1949             .arg(strWebCamName, strMachineName),
     1950          formatErrorInfo(dispatcher));
    19341951}
    19351952
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r48458 r49333  
    295295    void cannotDetachUSBDevice(const CConsole &console, const QString &strDevice) const;
    296296    void cannotDetachUSBDevice(const CVirtualBoxErrorInfo &errorInfo, const QString &strDevice, const QString &strMachineName) const;
     297    void cannotAttachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const;
     298    void cannotDetachWebCam(const CEmulatedUSB &dispatcher, const QString &strWebCamName, const QString &strMachineName) const;
    297299    void cannotToggleVRDEServer(const CVRDEServer &server, const QString &strMachineName, bool fEnable);
    298300    void cannotToggleVideoCapture(const CMachine &machine, bool fEnable);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r49307 r49333  
    108108#include "CUSBController.h"
    109109#include "CHostUSBDevice.h"
     110#include "CHostVideoInputDevice.h"
    110111#include "CMediumFormat.h"
    111112#include "CSharedFolder.h"
     
    10771078
    10781079    return tip;
     1080}
     1081
     1082/** Returns the multi-line description of the given CHostVideoInputDevice filter. */
     1083QString VBoxGlobal::toolTip(const CHostVideoInputDevice &webcam) const
     1084{
     1085    QStringList records;
     1086
     1087    QString strAlias = webcam.GetAlias();
     1088    if (!strAlias.isEmpty())
     1089        records << tr("<nobr>Alias: %1</nobr>", "webcam tooltip").arg(strAlias);
     1090
     1091    QString strName = webcam.GetName();
     1092    if (!strName.isEmpty())
     1093        records << tr("<nobr>Name: %1</nobr>", "webcam tooltip").arg(strName);
     1094
     1095    QString strPath = webcam.GetPath();
     1096    if (!strPath.isEmpty())
     1097        records << tr("<nobr>Path: %1</nobr>", "webcam tooltip").arg(strPath);
     1098
     1099    return records.join("<br>");
    10791100}
    10801101
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r48906 r49333  
    5050class CMedium;
    5151class CUSBDevice;
     52class CHostVideoInputDevice;
    5253class QSpinBox;
    5354class UIMediumEnumerator;
     
    232233    QString toolTip (const CUSBDevice &aDevice) const;
    233234    QString toolTip (const CUSBDeviceFilter &aFilter) const;
     235    QString toolTip(const CHostVideoInputDevice &webcam) const;
    234236
    235237    QString detailsReport (const CMachine &aMachine, bool aWithLinks);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.cpp

    r49277 r49333  
    727727    {
    728728        setName(QApplication::translate("UIActionPool", "&USB Devices"));
     729    }
     730};
     731
     732class UIActionMenuWebCams : public UIActionMenu
     733{
     734    Q_OBJECT;
     735
     736public:
     737
     738    UIActionMenuWebCams(UIActionPool *pParent)
     739        : UIActionMenu(pParent, ":/web_camera_16px.png", ":/web_camera_disabled_16px.png")
     740    {
     741        qobject_cast<UIMenu*>(menu())->setShowToolTips(true);
     742        retranslateUi();
     743    }
     744
     745protected:
     746
     747    void retranslateUi()
     748    {
     749        setName(QApplication::translate("UIActionPool", "&Webcams"));
    729750    }
    730751};
     
    12771298        delete m_pool[UIActionIndexRuntime_Menu_USBDevices];
    12781299    m_pool[UIActionIndexRuntime_Menu_USBDevices] = new UIActionMenuUSBDevices(this);
     1300    if (m_pool[UIActionIndexRuntime_Menu_WebCams])
     1301        delete m_pool[UIActionIndexRuntime_Menu_WebCams];
     1302    m_pool[UIActionIndexRuntime_Menu_WebCams] = new UIActionMenuWebCams(this);
    12791303    if (m_pool[UIActionIndexRuntime_Menu_SharedClipboard])
    12801304        delete m_pool[UIActionIndexRuntime_Menu_SharedClipboard];
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.h

    r46626 r49333  
    5858    UIActionIndexRuntime_Menu_FloppyDevices,
    5959    UIActionIndexRuntime_Menu_USBDevices,
     60    UIActionIndexRuntime_Menu_WebCams,
    6061    UIActionIndexRuntime_Menu_SharedClipboard,
    6162    UIActionIndexRuntime_Menu_DragAndDrop,
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r49177 r49333  
    7272#include "CVRDEServer.h"
    7373#include "CSystemProperties.h"
     74#include "CHostVideoInputDevice.h"
     75#include "CEmulatedUSB.h"
    7476#ifdef Q_WS_MAC
    7577# include "CGuest.h"
     
    130132};
    131133Q_DECLARE_METATYPE(USBTarget);
     134
     135/** Describes enumerated webcam item. */
     136struct WebCamTarget
     137{
     138    WebCamTarget() : attach(false), name(QString()), path(QString()) {}
     139    WebCamTarget(bool fAttach, const QString &strName, const QString &strPath)
     140        : attach(fAttach), name(strName), path(strPath) {}
     141    bool attach;
     142    QString name;
     143    QString path;
     144};
     145Q_DECLARE_METATYPE(WebCamTarget);
    132146
    133147/* static */
     
    786800    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices));
    787801    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices));
     802    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_WebCams));
    788803    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_SharedClipboard));
    789804    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_DragAndDrop));
     
    847862    connect(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu(), SIGNAL(aboutToShow()),
    848863            this, SLOT(sltPrepareUSBMenu()));
     864    connect(gActionPool->action(UIActionIndexRuntime_Menu_WebCams)->menu(), SIGNAL(aboutToShow()),
     865            this, SLOT(sltPrepareWebCamMenu()));
    849866    connect(gActionPool->action(UIActionIndexRuntime_Menu_SharedClipboard)->menu(), SIGNAL(aboutToShow()),
    850867            this, SLOT(sltPrepareSharedClipboardMenu()));
     
    18341851}
    18351852
     1853/**
     1854 * Prepares menu content when user hovers <b>Webcam</b> submenu of the <b>Devices</b> menu.
     1855 * @note If host currently have no webcams attached there will be just one dummy action
     1856 *       called <i>No Webcams Connected</i>. Otherwise there will be actions corresponding
     1857 *       to existing webcams allowing user to attach/detach them within the guest.
     1858 * @note In order to enumerate webcams GUI assigns #WebCamTarget object as internal data
     1859 *       for each the enumerated webcam menu action. Corresponding #sltAttachWebCamDevice
     1860 *       slot will be called on action triggering. It will parse assigned #WebCamTarget data.
     1861 */
     1862void UIMachineLogic::sltPrepareWebCamMenu()
     1863{
     1864    /* Get and check the sender menu object: */
     1865    QMenu *pMenu = qobject_cast<QMenu*>(sender());
     1866    QMenu *pWebCamMenu = gActionPool->action(UIActionIndexRuntime_Menu_WebCams)->menu();
     1867    AssertReturnVoid(pMenu == pWebCamMenu); Q_UNUSED(pWebCamMenu);
     1868
     1869    /* Clear menu initially: */
     1870    pMenu->clear();
     1871
     1872    /* Get current host: */
     1873    const CHost &host = vboxGlobal().host();
     1874
     1875    /* Get host webcams list: */
     1876    const CHostVideoInputDeviceVector &webcams = host.GetVideoInputDevices();
     1877
     1878    /* If webcam list is empty: */
     1879    if (webcams.isEmpty())
     1880    {
     1881        /* Add only one - "empty" action: */
     1882        QAction *pEmptyMenuAction = new QAction(pMenu);
     1883        pEmptyMenuAction->setEnabled(false);
     1884        pEmptyMenuAction->setText(tr("No Webcams Connected"));
     1885        pEmptyMenuAction->setToolTip(tr("No supported devices connected to the host PC"));
     1886        pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/vm_delete_16px.png", ":/vm_delete_disabled_16px.png")); // TODO: Change icon!
     1887        pMenu->addAction(pEmptyMenuAction);
     1888    }
     1889    /* If webcam list is NOT empty: */
     1890    else
     1891    {
     1892        /* Populate menu with host webcams: */
     1893        const QVector<QString> &attachedWebcamPaths = session().GetConsole().GetEmulatedUSB().GetWebcams();
     1894        foreach (const CHostVideoInputDevice &webcam, webcams)
     1895        {
     1896            /* Get webcam data: */
     1897            const QString &strWebcamName = webcam.GetName();
     1898            const QString &strWebcamPath = webcam.GetPath();
     1899
     1900            /* Create/configure webcam action: */
     1901            QAction *pAttachWebcamAction = new QAction(strWebcamName, pMenu);
     1902            pAttachWebcamAction->setToolTip(vboxGlobal().toolTip(webcam));
     1903            pAttachWebcamAction->setCheckable(true);
     1904            pAttachWebcamAction->setChecked(attachedWebcamPaths.contains(strWebcamPath));
     1905            pAttachWebcamAction->setData(QVariant::fromValue(WebCamTarget(!pAttachWebcamAction->isChecked(), strWebcamName, strWebcamPath)));
     1906            connect(pAttachWebcamAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachWebCamDevice()));
     1907            pMenu->addAction(pAttachWebcamAction);
     1908        }
     1909    }
     1910}
     1911
    18361912void UIMachineLogic::sltAttachUSBDevice()
    18371913{
     
    18771953            msgCenter().cannotDetachUSBDevice(console, vboxGlobal().details(device));
    18781954        }
     1955    }
     1956}
     1957
     1958/**
     1959 * Attaches/detaches webcam within the guest.
     1960 * @note In order to attach/detach webcams #sltPrepareWebCamMenu assigns #WebCamTarget object
     1961 *       as internal data for each the enumerated webcam menu action. Corresponding data
     1962 *       will be parsed here resulting in device attaching/detaching.
     1963 */
     1964void UIMachineLogic::sltAttachWebCamDevice()
     1965{
     1966    /* Get and check sender action object: */
     1967    QAction *pAction = qobject_cast<QAction*>(sender());
     1968    AssertReturnVoid(pAction);
     1969
     1970    /* Get operation target: */
     1971    WebCamTarget target = pAction->data().value<WebCamTarget>();
     1972
     1973    /* Get current emulated USB: */
     1974    const CConsole &console = session().GetConsole();
     1975    CEmulatedUSB dispatcher = console.GetEmulatedUSB();
     1976
     1977    /* Attach webcam device: */
     1978    if (target.attach)
     1979    {
     1980        /* Try to attach corresponding device: */
     1981        dispatcher.WebcamAttach(target.path, "");
     1982        /* Check if dispatcher is OK: */
     1983        if (!dispatcher.isOk())
     1984            msgCenter().cannotAttachWebCam(dispatcher, target.name, console.GetMachine().GetName());
     1985    }
     1986    /* Detach webcam device: */
     1987    else
     1988    {
     1989        /* Try to detach corresponding device: */
     1990        dispatcher.WebcamDetach(target.path);
     1991        /* Check if dispatcher is OK: */
     1992        if (!dispatcher.isOk())
     1993            msgCenter().cannotDetachWebCam(dispatcher, target.name, console.GetMachine().GetName());
    18791994    }
    18801995}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r49309 r49333  
    204204    void sltMountRecentStorageMedium();
    205205    void sltPrepareUSBMenu();
     206    void sltPrepareWebCamMenu();
    206207    void sltAttachUSBDevice();
     208    void sltAttachWebCamDevice();
    207209    void sltPrepareSharedClipboardMenu();
    208210    void sltChangeSharedClipboardType(QAction *pAction);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineMenuBar.cpp

    r47478 r49333  
    256256    pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices)->menu());
    257257    pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu());
     258    pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_WebCams)->menu());
    258259    pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_SharedClipboard)->menu());
    259260    pMenu->addMenu(gActionPool->action(UIActionIndexRuntime_Menu_DragAndDrop)->menu());
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r49177 r49333  
    7676#include "CUSBController.h"
    7777#include "CUSBDeviceFilters.h"
     78#include "CHostVideoInputDevice.h"
    7879#include "CSnapshot.h"
    7980#include "CMedium.h"
     
    14101411void UISession::reinitMenuPool()
    14111412{
     1413    /* Get host: */
     1414    const CHost &host = vboxGlobal().host();
     1415
    14121416    /* Get uisession machine: */
    14131417    const CMachine &machine = session().GetConsole().GetMachine();
     
    14481452            }
    14491453        }
     1454
    14501455        /* Show/Hide Network Adapters action depending on overall adapters activity status: */
    14511456        gActionPool->action(UIActionIndexRuntime_Simple_NetworkSettings)->setVisible(fAtLeastOneAdapterActive);
     
    14541459    /* USB stuff: */
    14551460    {
    1456         /*
    1457          * Check whether there is at least one OHCI USB controllers with
    1458          * an available proxy.
    1459          */
     1461        /* Check whether there is at least one OHCI USB controllers with an available proxy. */
    14601462        const CUSBDeviceFilters &filters = machine.GetUSBDeviceFilters();
    14611463        ULONG cOhciCtls = machine.GetUSBControllerCountByType(KUSBControllerType_OHCI);
     
    14641466        /* Show/Hide USB menu depending on controller availability, activity and USB-proxy presence: */
    14651467        gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->setVisible(fUSBEnabled);
     1468    }
     1469
     1470    /* WebCams stuff: */
     1471    {
     1472        /* Check whether there is an accessible video input devices pool: */
     1473        const CHostVideoInputDeviceVector &webcams = host.GetVideoInputDevices();
     1474        bool fWebCamsEnabled = host.isOk(); Q_UNUSED(webcams);
     1475
     1476        /* Show/Hide WebCams menu depending on ExtPack availability: */
     1477        gActionPool->action(UIActionIndexRuntime_Menu_WebCams)->setVisible(fWebCamsEnabled);
    14661478    }
    14671479}
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