Changeset 98620 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 17, 2023 3:12:34 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 155916
- 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 544 544 { 545 545 return uisession()->putEventMultiTouch(iCount, contacts, fIsTouchScreen, uScanTime); 546 } 547 548 bool UIMachine::usbDevices(QList<USBDeviceInfo> &guiUSBDevices) 549 { 550 return uisession()->usbDevices(guiUSBDevices); 551 } 552 553 bool UIMachine::attachUSBDevice(const QUuid &uId) 554 { 555 return uisession()->attachUSBDevice(uId); 556 } 557 558 bool UIMachine::detachUSBDevice(const QUuid &uId) 559 { 560 return uisession()->detachUSBDevice(uId); 546 561 } 547 562 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h
r98617 r98620 409 409 /** @} */ 410 410 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 411 421 /** @name Virtualization stuff. 412 422 ** @{ */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineDefs.h
r98103 r98620 31 31 # pragma once 32 32 #endif 33 34 /* Qt includes: */ 35 #include <QString> 36 #include <QUuid> 33 37 34 38 /* Other VBox includes: */ … … 74 78 }; 75 79 80 /** Robust struct to bring USB device info to machine-logic. */ 81 struct USBDeviceInfo 82 { 83 QUuid m_uId; 84 QString m_strName; 85 QString m_strToolTip; 86 bool m_fIsChecked; 87 bool m_fIsEnabled; 88 }; 89 76 90 #endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineDefs_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r98606 r98620 2274 2274 /* Attach USB device: */ 2275 2275 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); 2292 2277 /* Detach USB device: */ 2293 2278 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); 2306 2280 } 2307 2281 … … 2811 2785 void UIMachineLogic::updateMenuDevicesUSB(QMenu *pMenu) 2812 2786 { 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); 2817 2790 2818 2791 /* If device list is empty: */ 2819 if ( devices.isEmpty())2792 if (!fSuccess || guiUSBDevices.isEmpty()) 2820 2793 { 2821 2794 /* Add only one - "empty" action: */ … … 2830 2803 { 2831 2804 /* Populate menu with host USB devices: */ 2832 foreach (const CHostUSBDevice& hostDevice, devices)2805 foreach (const USBDeviceInfo &guiUSBDevice, guiUSBDevices) 2833 2806 { 2834 /* Get USB device from current host USB device: */2835 const CUSBDevice device(hostDevice);2836 2837 2807 /* Create USB device action: */ 2838 QAction *pAttachUSBAction = pMenu->addAction( uiCommon().usbDetails(device),2808 QAction *pAttachUSBAction = pMenu->addAction(guiUSBDevice.m_strName, 2839 2809 this, SLOT(sltAttachUSBDevice())); 2840 pAttachUSBAction->setToolTip( uiCommon().usbToolTip(device));2810 pAttachUSBAction->setToolTip(guiUSBDevice.m_strToolTip); 2841 2811 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))); 2850 2816 } 2851 2817 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
r98617 r98620 66 66 #include "CSystemProperties.h" 67 67 #include "CUSBController.h" 68 #include "CUSBDevice.h" 68 69 #include "CUSBDeviceFilter.h" 69 70 #include "CUSBDeviceFilters.h" … … 77 78 # include <iprt/ldr.h> 78 79 #endif 80 81 /* VirtualBox interface declarations: */ 82 #include <VBox/com/VirtualBox.h> 79 83 80 84 /* External includes: */ … … 373 377 if (!fSuccess) 374 378 UINotificationMessage::cannotChangeMouseParameter(comMouse); 379 return fSuccess; 380 } 381 382 bool 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 439 bool 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 458 bool 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 } 375 469 return fSuccess; 376 470 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
r98617 r98620 40 40 /* GUI includes: */ 41 41 #include "UIExtraDataDefs.h" 42 #include "UIMachineDefs.h" 42 43 #include "UIMediumDefs.h" 43 44 #include "UIMousePointerShapeData.h" … … 273 274 /** @} */ 274 275 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 275 286 /** @name Guest additions stuff. 276 287 ** @{ */
Note:
See TracChangeset
for help on using the changeset viewer.