VirtualBox

Changeset 38431 in vbox


Ignore:
Timestamp:
Aug 12, 2011 11:04:16 AM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime USB device menu: Correct handling of attaching/detaching failures, some source code refactoring.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/nls/VirtualBox_ru.ts

    r38412 r38431  
    25132513    <message>
    25142514        <source>No supported devices connected to the host PC</source>
    2515         <translation></translation>
     2515        <translation>Нет поддерживаемых USB устройств, подсоединенных к хосту</translation>
    25162516    </message>
    25172517</context>
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r38348 r38431  
    13221322void UIMachineLogic::sltPrepareUSBMenu()
    13231323{
    1324     /* Get the sender() menu: */
     1324    /* Get and check the sender menu object: */
    13251325    QMenu *pMenu = qobject_cast<QMenu*>(sender());
    1326 #ifdef RT_STRICT
    13271326    QMenu *pUSBDevicesMenu = gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu();
    1328 #endif
    13291327    AssertMsg(pMenu == pUSBDevicesMenu, ("This slot should only be called on hovering USB menu!\n"));
     1328    Q_UNUSED(pUSBDevicesMenu);
     1329
     1330    /* Clear menu initially: */
    13301331    pMenu->clear();
    13311332
    1332     /* Get HOST: */
     1333    /* Get current host: */
    13331334    CHost host = vboxGlobal().virtualBox().GetHost();
    13341335
    1335     /* Get USB devices list: */
     1336    /* Get host USB device list: */
    13361337    CHostUSBDeviceVector devices = host.GetUSBDevices();
    13371338
    1338     /* Fill USB devices menu: */
     1339    /* Fill USB device menu: */
    13391340    bool fIsUSBListEmpty = devices.size() == 0;
     1341    /* If device list is empty: */
    13401342    if (fIsUSBListEmpty)
    13411343    {
    1342         /* Fill USB devices menu: */
     1344        /* Add only one - "empty" action: */
    13431345        QAction *pEmptyMenuAction = new QAction(pMenu);
    13441346        pEmptyMenuAction->setEnabled(false);
    1345         pEmptyMenuAction->setText(QApplication::translate("UIMachineLogic", "No USB Devices Connected"));
     1347        pEmptyMenuAction->setText(tr("No USB Devices Connected"));
     1348        pEmptyMenuAction->setToolTip(tr("No supported devices connected to the host PC"));
    13461349        pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
    1347         pEmptyMenuAction->setToolTip(QApplication::translate("UIMachineLogic", "No supported devices connected to the host PC"));
    1348     }
     1350        pMenu->addAction(pEmptyMenuAction);
     1351    }
     1352    /* If device list is NOT empty: */
    13491353    else
    13501354    {
    1351         foreach (const CHostUSBDevice hostDevice, devices)
    1352         {
    1353             /* Get common USB device: */
     1355        /* Populate menu with host USB devices: */
     1356        for (int i = 0; i < devices.size(); ++i)
     1357        {
     1358            /* Get current host USB device: */
     1359            const CHostUSBDevice& hostDevice = devices[i];
     1360            /* Get USB device from current host USB device: */
    13541361            CUSBDevice device(hostDevice);
    13551362
    13561363            /* Create USB device action: */
    1357             QAction *attachUSBAction = new QAction(vboxGlobal().details(device), pMenu);
    1358             attachUSBAction->setCheckable(true);
    1359             connect(attachUSBAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachUSBDevice()));
    1360             pMenu->addAction(attachUSBAction);
     1364            QAction *pAttachUSBAction = new QAction(vboxGlobal().details(device), pMenu);
     1365            pAttachUSBAction->setCheckable(true);
     1366            connect(pAttachUSBAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachUSBDevice()));
     1367            pMenu->addAction(pAttachUSBAction);
    13611368
    13621369            /* Check if that USB device was already attached to this session: */
    13631370            CConsole console = session().GetConsole();
    13641371            CUSBDevice attachedDevice = console.FindUSBDeviceById(device.GetId());
    1365             attachUSBAction->setChecked(!attachedDevice.isNull());
    1366             attachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);
     1372            pAttachUSBAction->setChecked(!attachedDevice.isNull());
     1373            pAttachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);
    13671374
    13681375            /* Set USB attach data: */
    1369             attachUSBAction->setData(QVariant::fromValue(USBTarget(!attachUSBAction->isChecked(), device.GetId())));
    1370             attachUSBAction->setToolTip(vboxGlobal().toolTip(device));
     1376            pAttachUSBAction->setData(QVariant::fromValue(USBTarget(!pAttachUSBAction->isChecked(), device.GetId())));
     1377            pAttachUSBAction->setToolTip(vboxGlobal().toolTip(device));
    13711378        }
    13721379    }
     
    13751382void UIMachineLogic::sltAttachUSBDevice()
    13761383{
    1377     /* Get sender action: */
    1378     QAction *action = qobject_cast<QAction*>(sender());
    1379     AssertMsg(action, ("This slot should only be called on selecting USB menu item!\n"));
     1384    /* Get and check sender action object: */
     1385    QAction *pAction = qobject_cast<QAction*>(sender());
     1386    AssertMsg(pAction, ("This slot should only be called on selecting USB menu item!\n"));
     1387
     1388    /* Get operation target: */
     1389    USBTarget target = pAction->data().value<USBTarget>();
    13801390
    13811391    /* Get current console: */
    13821392    CConsole console = session().GetConsole();
    13831393
    1384     /* Get USB target: */
    1385     USBTarget target = action->data().value<USBTarget>();
    1386     CUSBDevice device = console.FindUSBDeviceById(target.id);
    1387 
    13881394    /* Attach USB device: */
    13891395    if (target.attach)
    13901396    {
     1397        /* Try to attach corresponding device: */
    13911398        console.AttachUSBDevice(target.id);
     1399        /* Check if console is OK: */
    13921400        if (!console.isOk())
     1401        {
     1402            /* Get current host: */
     1403            CHost host = vboxGlobal().virtualBox().GetHost();
     1404            /* Search the host for the corresponding USB device: */
     1405            CHostUSBDevice hostDevice = host.FindUSBDeviceById(target.id);
     1406            /* Get USB device from host USB device: */
     1407            CUSBDevice device(hostDevice);
     1408            /* Show a message about procedure failure: */
    13931409            msgCenter().cannotAttachUSBDevice(console, vboxGlobal().details(device));
    1394     }
     1410        }
     1411    }
     1412    /* Detach USB device: */
    13951413    else
    13961414    {
     1415        /* Search the console for the corresponding USB device: */
     1416        CUSBDevice device = console.FindUSBDeviceById(target.id);
     1417        /* Try to detach corresponding device: */
    13971418        console.DetachUSBDevice(target.id);
     1419        /* Check if console is OK: */
    13981420        if (!console.isOk())
     1421        {
     1422            /* Show a message about procedure failure: */
    13991423            msgCenter().cannotDetachUSBDevice(console, vboxGlobal().details(device));
     1424        }
    14001425    }
    14011426}
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