Changeset 263 in vbox for trunk/src/VBox
- Timestamp:
- Jan 24, 2007 12:15:05 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 17802
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h
r1 r263 44 44 class QIStateIndicator; 45 45 46 class VBoxUSBLedTip; 47 46 48 class VBoxConsoleWnd : public QMainWindow 47 49 { … … 91 93 DisableMouseIntegrAction = 0x20, 92 94 Caption = 0x40, 95 USBStuff = 0x80, 93 96 AllStuff = 0xFF, 94 97 }; … … 123 126 void prepareFloppyMenu(); 124 127 void prepareDVDMenu(); 128 void prepareUSBMenu(); 125 129 126 130 void captureFloppy (int id); 127 131 void captureDVD (int id); 132 void switchUSB (int id); 133 void makeUSBToolTip (int id); 128 134 129 135 void showIndicatorContextMenu (QIStateIndicator *ind, QContextMenuEvent *e); … … 182 188 QPopupMenu *devicesMountFloppyMenu; 183 189 QPopupMenu *devicesMountDVDMenu; 190 QPopupMenu *devicesUSBMenu; 184 191 185 192 #ifdef VBOX_WITH_DEBUGGER_GUI … … 194 201 devicesMountFloppyMenuId, 195 202 devicesMountDVDMenuId, 203 devicesUSBMenuId, 196 204 #ifdef VBOX_WITH_DEBUGGER_GUI 197 205 dbgMenuId, … … 204 212 // widgets 205 213 VBoxConsoleView *console; 206 QIStateIndicator *hd_light, *cd_light, *fd_light, *net_light ;214 QIStateIndicator *hd_light, *cd_light, *fd_light, *net_light, *usb_light; 207 215 QIStateIndicator *mouse_state, *hostkey_state; 208 216 QHBox *hostkey_hbox; 209 217 QLabel *hostkey_name; 210 218 219 VBoxUSBLedTip *mUsbLedTip; 220 211 221 QTimer *idle_timer; 212 222 CEnums::MachineState machine_state; … … 217 227 QMap <int, CHostDVDDrive> hostDVDMap; 218 228 QMap <int, CHostFloppyDrive> hostFloppyMap; 229 QMap <int, CUSBDevice> hostUSBMap; 219 230 220 231 QPoint normal_pos; -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r86 r263 44 44 #include <qlineedit.h> 45 45 #include <qtextedit.h> 46 #include <qtooltip.h> 46 47 #include <qdir.h> 47 48 … … 60 61 #include <VBox/err.h> 61 62 #endif 63 64 /** class VBoxUSBLedTip 65 * 66 * The VBoxUSBLedTip class is an auxiliary ToolTip class 67 * for the USB LED indicator. 68 */ 69 class VBoxUSBLedTip : public QToolTip 70 { 71 public: 72 73 VBoxUSBLedTip (QWidget *aWidget, const CSession &aSession) : 74 QToolTip (aWidget), mSession (aSession) {} 75 ~VBoxUSBLedTip() { remove (parentWidget()); } 76 77 protected: 78 79 void maybeTip (const QPoint &/* aPoint */) 80 { 81 CUSBDeviceEnumerator en = mSession.GetConsole().GetUSBDevices().Enumerate(); 82 QString devices; 83 while (en.HasMore()) 84 { 85 CUSBDevice usb = en.GetNext(); 86 devices += QString ("[<b><nobr>%1 %2 (%3)</nobr></b>]<br>") 87 .arg (usb.GetManufacturer()) 88 .arg (usb.GetProduct()) 89 .arg (usb.GetRevision()); 90 } 91 QString toolTip = QObject::tr ( 92 "<qt>Indicates the activity of " 93 "the attached USB devices" 94 "<br>%1</qt>" 95 ); 96 if (devices.isNull()) 97 devices += QObject::tr ("[<b>not attached</b>]"); 98 tip (parentWidget()->rect(), toolTip.arg (devices)); 99 } 100 101 const CSession &mSession; 102 }; 62 103 63 104 /** \class VBoxConsoleWnd … … 88 129 #endif 89 130 , console (0) 131 , mUsbLedTip (0) 90 132 , machine_state (CEnums::InvalidMachineState) 91 133 , no_auto_close (false) … … 239 281 devicesMountFloppyMenu = new QPopupMenu (devicesMenu, "devicesMountFloppyMenu"); 240 282 devicesMountDVDMenu = new QPopupMenu (devicesMenu, "devicesMountDVDMenu"); 283 devicesUSBMenu = new QPopupMenu (devicesMenu, "devicesUSBMenu"); 241 284 242 285 devicesMenu->insertItem (VBoxGlobal::iconSet ("fd_16px.png", "fd_disabled_16px.png"), … … 248 291 devicesUnmountDVDAction->addTo (devicesMenu); 249 292 devicesMenu->insertSeparator(); 293 devicesMenu->insertItem (VBoxGlobal::iconSet ("usb_16px.png", "usb_disabled_16px.png"), 294 QString::null, devicesUSBMenu, devicesUSBMenuId); 250 295 devicesInstallGuestToolsAction->addTo (devicesMenu); 251 296 menuBar()->insertItem (QString::null, devicesMenu, devicesMenuId); … … 254 299 devicesMenu->setItemParameter (devicesMountFloppyMenuId, 0); 255 300 devicesMenu->setItemParameter (devicesMountDVDMenuId, 0); 301 devicesMenu->setItemParameter (devicesUSBMenuId, 0); 256 302 257 303 #ifdef VBOX_WITH_DEBUGGER_GUI … … 303 349 net_light->setStateIcon (CEnums::DeviceWriting, QPixmap::fromMimeSource ("nw_write_16px.png")); 304 350 net_light->setStateIcon (CEnums::InvalidActivity, QPixmap::fromMimeSource ("nw_disabled_16px.png")); 351 usb_light = new QIStateIndicator (CEnums::DeviceIdle, indicatorBox, "usb_light", WNoAutoErase); 352 usb_light->setStateIcon (CEnums::DeviceIdle, QPixmap::fromMimeSource ("usb_16px.png")); 353 usb_light->setStateIcon (CEnums::DeviceReading, QPixmap::fromMimeSource ("usb_read_16px.png")); 354 usb_light->setStateIcon (CEnums::DeviceWriting, QPixmap::fromMimeSource ("usb_write_16px.png")); 355 usb_light->setStateIcon (CEnums::InvalidActivity, QPixmap::fromMimeSource ("usb_disabled_16px.png")); 305 356 /* mouse */ 306 357 (new QFrame (indicatorBox))->setFrameStyle (QFrame::VLine | QFrame::Sunken); … … 363 414 connect (devicesMountFloppyMenu, SIGNAL(aboutToShow()), this, SLOT(prepareFloppyMenu())); 364 415 connect (devicesMountDVDMenu, SIGNAL(aboutToShow()), this, SLOT(prepareDVDMenu())); 416 connect (devicesUSBMenu, SIGNAL(aboutToShow()), this, SLOT(prepareUSBMenu())); 365 417 366 418 connect (devicesMountFloppyMenu, SIGNAL(activated(int)), this, SLOT(captureFloppy(int))); 367 419 connect (devicesMountDVDMenu, SIGNAL(activated(int)), this, SLOT(captureDVD(int))); 420 connect (devicesUSBMenu, SIGNAL(activated(int)), this, SLOT(switchUSB(int))); 421 connect (devicesUSBMenu, SIGNAL(highlighted(int)), this, SLOT(makeUSBToolTip(int))); 368 422 369 423 connect (helpWebAction, SIGNAL (activated()), … … 377 431 this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *))); 378 432 connect (cd_light, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)), 433 this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *))); 434 connect (usb_light, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)), 379 435 this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *))); 380 436 … … 395 451 VBoxConsoleWnd::~VBoxConsoleWnd() 396 452 { 453 delete mUsbLedTip; 397 454 } 398 455 … … 502 559 } 503 560 } 561 562 /* initialize usb stuff */ 563 bool isUsbAvailable = cmachine.GetUSBController().GetEnabled(); 564 devicesMenu->setItemVisible (devicesUSBMenuId, isUsbAvailable); 565 mUsbLedTip = new VBoxUSBLedTip (usb_light, csession); 504 566 505 567 /* start an idle timer that will update device lighths */ … … 1051 1113 devicesMenu->changeItem (devicesMountFloppyMenuId, tr ("Mount &Floppy")); 1052 1114 devicesMenu->changeItem (devicesMountDVDMenuId, tr ("Mount &CD/DVD-ROM")); 1115 devicesMenu->changeItem (devicesUSBMenuId, tr ("&USB Devices")); 1053 1116 1054 1117 menuBar()->changeItem (vmMenuId, tr ("&VM")); … … 1207 1270 QToolTip::add (net_light, tip.arg (count)); 1208 1271 } 1272 if (element & USBStuff) 1273 { 1274 devicesUSBMenu->setEnabled (machine_state == CEnums::Running); 1275 } 1209 1276 if (element & PauseAction) 1210 1277 { … … 1703 1770 1704 1771 /** 1772 * Prepares the "USB Devices" menu by populating the existent host 1773 * USB Devices. 1774 */ 1775 void VBoxConsoleWnd::prepareUSBMenu() 1776 { 1777 if (!console) return; 1778 1779 devicesUSBMenu->clear(); 1780 CHost host = vboxGlobal().virtualBox().GetHost(); 1781 1782 bool isUSBEmpty = host.GetUSBDevices().GetCount() == 0; 1783 if (isUSBEmpty) 1784 { 1785 int id = devicesUSBMenu->insertItem (tr ("[No device attached to host]")); 1786 devicesUSBMenu->setItemEnabled (id, !isUSBEmpty); 1787 return; 1788 } 1789 1790 CHostUSBDeviceEnumerator en = host.GetUSBDevices().Enumerate(); 1791 while (en.HasMore()) 1792 { 1793 CHostUSBDevice iterator = en.GetNext(); 1794 CUSBDevice usb = CUnknown (iterator); 1795 int id = devicesUSBMenu->insertItem (QString ("%1 %2 [%3]") 1796 .arg (usb.GetManufacturer()) 1797 .arg (usb.GetProduct()) 1798 .arg (usb.GetRevision())); 1799 hostUSBMap [id] = usb; 1800 CUSBDevice attachedUSB = 1801 csession.GetConsole().GetUSBDevices().FindById (usb.GetId()); 1802 devicesUSBMenu->setItemChecked (id, !attachedUSB.isNull()); 1803 devicesUSBMenu->setItemEnabled (id, iterator.GetState() != 1804 CEnums::USBDeviceUnavailable); 1805 } 1806 } 1807 1808 /** 1705 1809 * Captures a floppy device corresponding to a given menu id. 1706 1810 */ … … 1746 1850 updateAppearanceOf (DVDStuff); 1747 1851 } 1852 } 1853 1854 /** 1855 * Attach/Detach selected USB Device. 1856 */ 1857 void VBoxConsoleWnd::switchUSB (int id) 1858 { 1859 if (!console) return; 1860 1861 CUSBDevice usb = hostUSBMap [id]; 1862 /* if null then some other item but usb device is selected */ 1863 if (usb.isNull()) return; 1864 1865 if (devicesUSBMenu->isItemChecked (id)) 1866 csession.GetConsole().DetachUSBDevice (usb.GetId()); 1867 else 1868 csession.GetConsole().AttachUSBDevice (usb.GetId()); 1869 } 1870 1871 /** 1872 * Update tooltip for highlighted USB Device. 1873 */ 1874 void VBoxConsoleWnd::makeUSBToolTip (int id) 1875 { 1876 if (!console) return; 1877 1878 CUSBDevice usb = hostUSBMap [id]; 1879 /* if null then some other item but usb device is selected */ 1880 if (usb.isNull()) return; 1881 1882 QString tip = tr ("Vendor ID: %1\nProduct ID: %2\nSerial Number: %3") 1883 .arg (usb.GetVendorId()).arg (usb.GetProductId()).arg (usb.GetSerialNumber()); 1884 QToolTip::remove (devicesUSBMenu); 1885 QToolTip::add (devicesUSBMenu, tip); 1748 1886 } 1749 1887 … … 1764 1902 devicesMountFloppyMenu->exec (e->globalPos()); 1765 1903 devicesMenu->setItemParameter (devicesMountFloppyMenuId, 0); 1904 } 1905 else 1906 if (ind == usb_light) 1907 { 1908 // set "this is a context menu" flag 1909 devicesMenu->setItemParameter (devicesUSBMenuId, 1); 1910 devicesUSBMenu->exec (e->globalPos()); 1911 devicesMenu->setItemParameter (devicesUSBMenuId, 0); 1766 1912 } 1767 1913 } … … 1824 1970 machine_state = state; 1825 1971 1826 updateAppearanceOf (Caption | FloppyStuff | DVDStuff | PauseAction |1972 updateAppearanceOf (Caption | FloppyStuff | DVDStuff | USBStuff | PauseAction | 1827 1973 DisableMouseIntegrAction ); 1828 1974
Note:
See TracChangeset
for help on using the changeset viewer.