Changeset 52218 in vbox
- Timestamp:
- Jul 28, 2014 7:24:01 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 95283
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackend.h
r52215 r52218 71 71 template<> bool canConvert<StorageSlot>(); 72 72 template<> bool canConvert<MenuHelpActionType>(); 73 #ifdef Q_WS_MAC 74 template<> bool canConvert<MenuApplicationActionType>(); 75 #endif /* Q_WS_MAC */ 73 76 template<> bool canConvert<RuntimeMenuType>(); 74 #ifdef Q_WS_MAC75 template<> bool canConvert<RuntimeMenuApplicationActionType>();76 #endif /* Q_WS_MAC */77 77 template<> bool canConvert<RuntimeMenuMachineActionType>(); 78 78 template<> bool canConvert<RuntimeMenuViewActionType>(); … … 125 125 template<> QString toInternalString(const MenuHelpActionType &menuHelpActionType); 126 126 template<> MenuHelpActionType fromInternalString<MenuHelpActionType>(const QString &strMenuHelpActionType); 127 #ifdef Q_WS_MAC 128 template<> QString toInternalString(const MenuApplicationActionType &runtimeMenuApplicationActionType); 129 template<> MenuApplicationActionType fromInternalString<MenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType); 130 #endif /* Q_WS_MAC */ 127 131 template<> QString toInternalString(const RuntimeMenuType &runtimeMenuType); 128 132 template<> RuntimeMenuType fromInternalString<RuntimeMenuType>(const QString &strRuntimeMenuType); 129 #ifdef Q_WS_MAC130 template<> QString toInternalString(const RuntimeMenuApplicationActionType &runtimeMenuApplicationActionType);131 template<> RuntimeMenuApplicationActionType fromInternalString<RuntimeMenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType);132 #endif /* Q_WS_MAC */133 133 template<> QString toInternalString(const RuntimeMenuMachineActionType &runtimeMenuMachineActionType); 134 134 template<> RuntimeMenuMachineActionType fromInternalString<RuntimeMenuMachineActionType>(const QString &strRuntimeMenuMachineActionType); -
trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp
r52215 r52218 35 35 template<> bool canConvert<StorageSlot>() { return true; } 36 36 template<> bool canConvert<MenuHelpActionType>() { return true; } 37 #ifdef Q_WS_MAC 38 template<> bool canConvert<MenuApplicationActionType>() { return true; } 39 #endif /* Q_WS_MAC */ 37 40 template<> bool canConvert<RuntimeMenuType>() { return true; } 38 #ifdef Q_WS_MAC39 template<> bool canConvert<RuntimeMenuApplicationActionType>() { return true; }40 #endif /* Q_WS_MAC */41 41 template<> bool canConvert<RuntimeMenuMachineActionType>() { return true; } 42 42 template<> bool canConvert<RuntimeMenuViewActionType>() { return true; } … … 409 409 } 410 410 411 #ifdef Q_WS_MAC 412 /* QString <= MenuApplicationActionType: */ 413 template<> QString toInternalString(const MenuApplicationActionType &runtimeMenuApplicationActionType) 414 { 415 QString strResult; 416 switch (runtimeMenuApplicationActionType) 417 { 418 case MenuApplicationActionType_About: strResult = "About"; break; 419 case MenuApplicationActionType_Preferences: strResult = "Preferences"; break; 420 case MenuApplicationActionType_Close: strResult = "Close"; break; 421 case MenuApplicationActionType_All: strResult = "All"; break; 422 default: 423 { 424 AssertMsgFailed(("No text for action type=%d", runtimeMenuApplicationActionType)); 425 break; 426 } 427 } 428 return strResult; 429 } 430 431 /* MenuApplicationActionType <= QString: */ 432 template<> MenuApplicationActionType fromInternalString<MenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType) 433 { 434 /* Here we have some fancy stuff allowing us 435 * to search through the keys using 'case-insensitive' rule: */ 436 QStringList keys; QList<MenuApplicationActionType> values; 437 keys << "About"; values << MenuApplicationActionType_About; 438 keys << "Preferences"; values << MenuApplicationActionType_Preferences; 439 keys << "Close"; values << MenuApplicationActionType_Close; 440 keys << "All"; values << MenuApplicationActionType_All; 441 /* Invalid type for unknown words: */ 442 if (!keys.contains(strRuntimeMenuApplicationActionType, Qt::CaseInsensitive)) 443 return MenuApplicationActionType_Invalid; 444 /* Corresponding type for known words: */ 445 return values.at(keys.indexOf(QRegExp(strRuntimeMenuApplicationActionType, Qt::CaseInsensitive))); 446 } 447 #endif /* Q_WS_MAC */ 448 411 449 /* QString <= RuntimeMenuType: */ 412 450 template<> QString toInternalString(const RuntimeMenuType &runtimeMenuType) … … 452 490 return values.at(keys.indexOf(QRegExp(strRuntimeMenuType, Qt::CaseInsensitive))); 453 491 } 454 455 #ifdef Q_WS_MAC456 /* QString <= RuntimeMenuApplicationActionType: */457 template<> QString toInternalString(const RuntimeMenuApplicationActionType &runtimeMenuApplicationActionType)458 {459 QString strResult;460 switch (runtimeMenuApplicationActionType)461 {462 case RuntimeMenuApplicationActionType_About: strResult = "About"; break;463 case RuntimeMenuApplicationActionType_Preferences: strResult = "Preferences"; break;464 case RuntimeMenuApplicationActionType_Close: strResult = "Close"; break;465 case RuntimeMenuApplicationActionType_All: strResult = "All"; break;466 default:467 {468 AssertMsgFailed(("No text for action type=%d", runtimeMenuApplicationActionType));469 break;470 }471 }472 return strResult;473 }474 475 /* RuntimeMenuApplicationActionType <= QString: */476 template<> RuntimeMenuApplicationActionType fromInternalString<RuntimeMenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType)477 {478 /* Here we have some fancy stuff allowing us479 * to search through the keys using 'case-insensitive' rule: */480 QStringList keys; QList<RuntimeMenuApplicationActionType> values;481 keys << "About"; values << RuntimeMenuApplicationActionType_About;482 keys << "Preferences"; values << RuntimeMenuApplicationActionType_Preferences;483 keys << "Close"; values << RuntimeMenuApplicationActionType_Close;484 keys << "All"; values << RuntimeMenuApplicationActionType_All;485 /* Invalid type for unknown words: */486 if (!keys.contains(strRuntimeMenuApplicationActionType, Qt::CaseInsensitive))487 return RuntimeMenuApplicationActionType_Invalid;488 /* Corresponding type for known words: */489 return values.at(keys.indexOf(QRegExp(strRuntimeMenuApplicationActionType, Qt::CaseInsensitive)));490 }491 #endif /* Q_WS_MAC */492 492 493 493 /* QString <= RuntimeMenuMachineActionType: */ -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h
r52215 r52218 378 378 }; 379 379 380 #ifdef Q_WS_MAC 381 /** Menu "Application": Action types. */ 382 enum MenuApplicationActionType 383 { 384 MenuApplicationActionType_Invalid = 0, 385 MenuApplicationActionType_About = RT_BIT(0), 386 MenuApplicationActionType_Preferences = RT_BIT(1), 387 MenuApplicationActionType_Close = RT_BIT(2), 388 MenuApplicationActionType_All = 0xFFFF 389 }; 390 #endif /* Q_WS_MAC */ 391 380 392 /** Runtime UI: Menu types. */ 381 393 enum RuntimeMenuType … … 391 403 RuntimeMenuType_All = 0xFF 392 404 }; 393 394 #ifdef Q_WS_MAC395 /** Runtime UI: Menu "Application": Action types. */396 enum RuntimeMenuApplicationActionType397 {398 RuntimeMenuApplicationActionType_Invalid = 0,399 RuntimeMenuApplicationActionType_About = RT_BIT(0),400 RuntimeMenuApplicationActionType_Preferences = RT_BIT(1),401 RuntimeMenuApplicationActionType_Close = RT_BIT(2),402 RuntimeMenuApplicationActionType_All = 0xFFFF403 };404 #endif /* Q_WS_MAC */405 405 406 406 /** Runtime UI: Menu "Machine": Action types. */ -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r52215 r52218 2504 2504 2505 2505 #ifdef Q_WS_MAC 2506 RuntimeMenuApplicationActionType UIExtraDataManager::restrictedRuntimeMenuApplicationActionTypes(const QString &strID)2506 MenuApplicationActionType UIExtraDataManager::restrictedRuntimeMenuApplicationActionTypes(const QString &strID) 2507 2507 { 2508 2508 /* Prepare result: */ 2509 RuntimeMenuApplicationActionType result = RuntimeMenuApplicationActionType_Invalid;2509 MenuApplicationActionType result = MenuApplicationActionType_Invalid; 2510 2510 /* Get restricted runtime-application-menu action-types: */ 2511 2511 foreach (const QString &strValue, extraDataStringList(GUI_RestrictedRuntimeApplicationMenuActions, strID)) 2512 2512 { 2513 RuntimeMenuApplicationActionType value = gpConverter->fromInternalString<RuntimeMenuApplicationActionType>(strValue);2514 if (value != RuntimeMenuApplicationActionType_Invalid)2515 result = static_cast< RuntimeMenuApplicationActionType>(result | value);2513 MenuApplicationActionType value = gpConverter->fromInternalString<MenuApplicationActionType>(strValue); 2514 if (value != MenuApplicationActionType_Invalid) 2515 result = static_cast<MenuApplicationActionType>(result | value); 2516 2516 } 2517 2517 /* Return result: */ -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h
r52215 r52218 288 288 #ifdef Q_WS_MAC 289 289 /** Mac OS X: Returns restricted Runtime UI action types for Application menu. */ 290 RuntimeMenuApplicationActionType restrictedRuntimeMenuApplicationActionTypes(const QString &strID);290 MenuApplicationActionType restrictedRuntimeMenuApplicationActionTypes(const QString &strID); 291 291 #endif /* Q_WS_MAC */ 292 292 /** Returns restricted Runtime UI action types for Machine menu. */ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp
r52215 r52218 179 179 if (!strIcon.isNull()) 180 180 setIcon(UIIconPool::iconSet(strIcon, strIconDis)); 181 setMenu(new UIMenu);181 prepare(); 182 182 } 183 183 … … 188 188 if (!icon.isNull()) 189 189 setIcon(icon); 190 prepare(); 191 } 192 193 void UIActionMenu::setShowToolTip(bool fShowToolTip) 194 { 195 qobject_cast<UIMenu*>(menu())->setShowToolTip(fShowToolTip); 196 } 197 198 void UIActionMenu::prepare() 199 { 200 /* Create menu: */ 190 201 setMenu(new UIMenu); 191 } 192 193 void UIActionMenu::setShowToolTip(bool fShowToolTip) 194 { 195 qobject_cast<UIMenu*>(menu())->setShowToolTip(fShowToolTip); 202 AssertPtrReturnVoid(menu()); 203 { 204 /* Prepare menu: */ 205 connect(menu(), SIGNAL(aboutToShow()), 206 parent(), SLOT(sltHandleMenuPrepare())); 207 } 196 208 } 197 209 … … 620 632 m_restrictedActionsMenuHelp[level] = restriction; 621 633 updateMenuHelp(); 634 } 635 636 #ifdef Q_WS_MAC 637 bool UIActionPool::isAllowedInMenuApplication(MenuApplicationActionType type) const 638 { 639 foreach (const MenuApplicationActionType &restriction, m_restrictedActionsMenuApplication.values()) 640 if (restriction & type) 641 return false; 642 return true; 643 } 644 645 void UIActionPool::setRestrictionForMenuApplication(UIActionRestrictionLevel level, MenuApplicationActionType restriction) 646 { 647 m_restrictedActionsMenuApplication[level] = restriction; 648 updateMenuHelp(); 649 } 650 #endif /* Q_WS_MAC */ 651 652 void UIActionPool::sltHandleMenuPrepare() 653 { 654 /* Make sure menu is valid: */ 655 UIMenu *pMenu = qobject_cast<UIMenu*>(sender()); 656 AssertPtrReturnVoid(pMenu); 657 /* Make sure action is valid: */ 658 UIAction *pAction = qobject_cast<UIAction*>(pMenu->menuAction()); 659 AssertPtrReturnVoid(pAction); 660 661 /* Determine action index: */ 662 const int iIndex = m_pool.key(pAction); 663 664 /* Update menu if necessary: */ 665 updateMenu(iIndex); 666 667 /* Notify listeners about menu prepared: */ 668 emit sigNotifyAboutMenuPrepare(iIndex, pMenu); 622 669 } 623 670 … … 650 697 #endif /* VBOX_GUI_WITH_NETWORK_MANAGER */ 651 698 m_pool[UIActionIndex_Simple_About] = new UIActionSimpleAbout(this); 699 700 /* Prepare update-handlers for known menus: */ 701 m_menuUpdateHandlers[UIActionIndex_Menu_Help].ptf = &UIActionPool::updateMenuHelp; 702 703 /* Invalidate all known menus: */ 704 m_invalidations.unite(m_menuUpdateHandlers.keys().toSet()); 652 705 653 706 /* Retranslate finally: */ … … 722 775 } 723 776 777 void UIActionPool::updateMenu(int iIndex) 778 { 779 /* Update if menu with such index is invalidated and there is update-handler: */ 780 if (m_invalidations.contains(iIndex) && m_menuUpdateHandlers.contains(iIndex)) 781 (this->*(m_menuUpdateHandlers.value(iIndex).ptf))(); 782 } 783 724 784 void UIActionPool::updateMenuHelp() 725 785 { … … 827 887 const bool fAllowToShowActionAbout = 828 888 #ifdef Q_WS_MAC 829 isAllowedInMenuApplication( RuntimeMenuApplicationActionType_About);889 isAllowedInMenuApplication(MenuApplicationActionType_About); 830 890 #else /* !Q_WS_MAC */ 831 891 isAllowedInMenuHelp(MenuHelpActionType_About); … … 845 905 const bool fAllowToShowActionPreferences = 846 906 #ifdef Q_WS_MAC 847 isAllowedInMenuApplication( RuntimeMenuApplicationActionType_Preferences);907 isAllowedInMenuApplication(MenuApplicationActionType_Preferences); 848 908 #else /* !Q_WS_MAC */ 849 909 isAllowedInMenuHelp(MenuHelpActionType_Preferences); … … 853 913 pMenu->addAction(action(UIActionIndex_Simple_Preferences)); 854 914 } 915 916 917 /* Mark menu as valid: */ 918 m_invalidations.remove(UIActionIndex_Menu_Help); 855 919 } 856 920 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h
r52215 r52218 191 191 private: 192 192 193 /** Prepare routine. */ 194 void prepare(); 195 193 196 /** Updates action text accordingly. */ 194 197 virtual void updateText(); … … 279 282 Q_OBJECT; 280 283 284 /** Pointer to menu update-handler for this class. */ 285 typedef void (UIActionPool::*PTFActionPool)(); 286 /** Pointer to menu update-handler for Runtime sub-class. */ 287 typedef void (UIActionPoolRuntime::*PTFActionPoolRuntime)(); 288 /** Union for two defines above. */ 289 union PointerToFunction 290 { 291 PTFActionPool ptf; 292 PTFActionPoolRuntime ptfr; 293 }; 294 295 signals: 296 297 /** Notifies about menu prepare. */ 298 void sigNotifyAboutMenuPrepare(int iIndex, QMenu *pMenu); 299 281 300 public: 282 301 … … 308 327 void setRestrictionForMenuHelp(UIActionRestrictionLevel level, MenuHelpActionType restriction); 309 328 329 #ifdef Q_WS_MAC 330 /** Returns whether the action with passed @a type is allowed in the 'Application' menu. */ 331 bool isAllowedInMenuApplication(MenuApplicationActionType type) const; 332 /** Defines 'Application' menu @a restriction for passed @a level. */ 333 void setRestrictionForMenuApplication(UIActionRestrictionLevel level, MenuApplicationActionType restriction); 334 #endif /* Q_WS_MAC */ 335 310 336 /** Hot-key processing delegate. */ 311 337 bool processHotKey(const QKeySequence &key); … … 318 344 319 345 protected slots: 346 347 /** Handles menu prepare. */ 348 void sltHandleMenuPrepare(); 320 349 321 350 /** Loads keyboard shortcuts of action-pool into shortcuts-pool. */ … … 343 372 virtual void updateConfiguration(); 344 373 374 /** Update menu routine. */ 375 virtual void updateMenu(int iIndex); 345 376 /** Update menus routine. */ 346 377 virtual void updateMenus() = 0; … … 361 392 /** Holds whether this action-pool is temporary. */ 362 393 const bool m_fTemporary; 363 /** Holds all the actions action-pool contains. */ 394 395 /** Holds the map of actions. */ 364 396 QMap<int, UIAction*> m_pool; 397 /** Holds the map of validation handlers. */ 398 QMap<int, PointerToFunction> m_menuUpdateHandlers; 399 /** Holds the set of invalidated action indexes. */ 400 QSet<int> m_invalidations; 365 401 366 402 /** Holds restricted action types of the Help menu. */ 367 403 QMap<UIActionRestrictionLevel, MenuHelpActionType> m_restrictedActionsMenuHelp; 404 #ifdef Q_WS_MAC 405 /** Holds restricted action types of the Application menu. */ 406 QMap<UIActionRestrictionLevel, MenuApplicationActionType> m_restrictedActionsMenuApplication; 407 #endif /* Q_WS_MAC */ 368 408 }; 369 409 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.cpp
r52215 r52218 1275 1275 updateMenus(); 1276 1276 } 1277 1278 #ifdef Q_WS_MAC1279 bool UIActionPoolRuntime::isAllowedInMenuApplication(RuntimeMenuApplicationActionType type) const1280 {1281 foreach (const RuntimeMenuApplicationActionType &restriction, m_restrictedActionsMenuApplication.values())1282 if (restriction & type)1283 return false;1284 return true;1285 }1286 1287 void UIActionPoolRuntime::setRestrictionForMenuApplication(UIActionRestrictionLevel level, RuntimeMenuApplicationActionType restriction)1288 {1289 m_restrictedActionsMenuApplication[level] = restriction;1290 updateMenuMachine();1291 updateMenuHelp();1292 }1293 #endif /* Q_WS_MAC */1294 1277 1295 1278 bool UIActionPoolRuntime::isAllowedInMenuMachine(RuntimeMenuMachineActionType type) const … … 1455 1438 #endif /* Q_WS_MAC */ 1456 1439 1440 /* Prepare update-handlers for known menus: */ 1441 m_menuUpdateHandlers[UIActionIndexRT_M_Machine].ptfr = &UIActionPoolRuntime::updateMenuMachine; 1442 m_menuUpdateHandlers[UIActionIndexRT_M_Machine_M_Keyboard].ptfr = &UIActionPoolRuntime::updateMenuMachineKeyboard; 1443 m_menuUpdateHandlers[UIActionIndexRT_M_Machine_M_Mouse].ptfr = &UIActionPoolRuntime::updateMenuMachineMouse; 1444 m_menuUpdateHandlers[UIActionIndexRT_M_View].ptfr = &UIActionPoolRuntime::updateMenuView; 1445 m_menuUpdateHandlers[UIActionIndexRT_M_ViewPopup].ptfr = &UIActionPoolRuntime::updateMenuViewPopup; 1446 m_menuUpdateHandlers[UIActionIndexRT_M_View_M_StatusBar].ptfr = &UIActionPoolRuntime::updateMenuViewStatusBar; 1447 m_menuUpdateHandlers[UIActionIndexRT_M_Devices].ptfr = &UIActionPoolRuntime::updateMenuDevices; 1448 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_HardDrives].ptfr = &UIActionPoolRuntime::updateMenuDevicesHardDrives; 1449 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_USBDevices].ptfr = &UIActionPoolRuntime::updateMenuDevicesUSBDevices; 1450 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_Network].ptfr = &UIActionPoolRuntime::updateMenuDevicesNetwork; 1451 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_SharedFolders].ptfr = &UIActionPoolRuntime::updateMenuDevicesSharedFolders; 1452 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_VideoCapture].ptfr = &UIActionPoolRuntime::updateMenuDevicesVideoCapture; 1453 #ifdef VBOX_WITH_DEBUGGER_GUI 1454 m_menuUpdateHandlers[UIActionIndexRT_M_Debug].ptfr = &UIActionPoolRuntime::updateMenuDebug; 1455 #endif /* VBOX_WITH_DEBUGGER_GUI */ 1456 1457 1457 /* Call to base-class: */ 1458 1458 UIActionPool::preparePool(); … … 1546 1546 { 1547 1547 #ifdef Q_WS_MAC 1548 m_restrictedActionsMenuApplication[UIActionRestrictionLevel_Base] = ( RuntimeMenuApplicationActionType)1549 (m_restrictedActionsMenuApplication[UIActionRestrictionLevel_Base] | RuntimeMenuApplicationActionType_Close);1548 m_restrictedActionsMenuApplication[UIActionRestrictionLevel_Base] = (MenuApplicationActionType) 1549 (m_restrictedActionsMenuApplication[UIActionRestrictionLevel_Base] | MenuApplicationActionType_Close); 1550 1550 #else /* !Q_WS_MAC */ 1551 1551 m_restrictedActionsMenuMachine[UIActionRestrictionLevel_Base] = (RuntimeMenuMachineActionType) … … 1556 1556 /* Call to base-class: */ 1557 1557 UIActionPool::updateConfiguration(); 1558 } 1559 1560 void UIActionPoolRuntime::updateMenu(int iIndex) 1561 { 1562 /* Call to base-class: */ 1563 if (iIndex < UIActionIndex_Max) 1564 UIActionPool::updateMenu(iIndex); 1565 1566 /* If menu with such index is invalidated and there is update-handler: */ 1567 if (m_invalidations.contains(iIndex) && m_menuUpdateHandlers.contains(iIndex)) 1568 (this->*(m_menuUpdateHandlers.value(iIndex).ptfr))(); 1558 1569 } 1559 1570 … … 1779 1790 const bool fAllowToShowActionClose = 1780 1791 #ifdef Q_WS_MAC 1781 isAllowedInMenuApplication( RuntimeMenuApplicationActionType_Close);1792 isAllowedInMenuApplication(MenuApplicationActionType_Close); 1782 1793 #else /* !Q_WS_MAC */ 1783 1794 isAllowedInMenuMachine(RuntimeMenuMachineActionType_Close); … … 1785 1796 pMenu->addAction(action(UIActionIndexRT_M_Machine_S_Close)); 1786 1797 action(UIActionIndexRT_M_Machine_S_Close)->setEnabled(fAllowToShowActionClose); 1798 1799 1800 /* Mark menu as valid: */ 1801 m_invalidations.remove(UIActionIndexRT_M_Machine); 1787 1802 } 1788 1803 … … 1800 1815 if (fAllowToShowActionKeyboardSettings) 1801 1816 pMenu->addAction(action(UIActionIndexRT_M_Machine_M_Keyboard_S_Settings)); 1817 1818 /* Mark menu as valid: */ 1819 m_invalidations.remove(UIActionIndexRT_M_Machine_M_Keyboard); 1802 1820 } 1803 1821 … … 1815 1833 if (fAllowToShowActionMouseIntegration) 1816 1834 pMenu->addAction(action(UIActionIndexRT_M_Machine_M_Mouse_T_Integration)); 1835 1836 /* Mark menu as valid: */ 1837 m_invalidations.remove(UIActionIndexRT_M_Machine_M_Mouse); 1817 1838 } 1818 1839 … … 1906 1927 connect(pSubMenu, SIGNAL(aboutToShow()), this, SLOT(sltPrepareMenuViewResize())); 1907 1928 } 1929 1930 1931 /* Mark menu as valid: */ 1932 m_invalidations.remove(UIActionIndexRT_M_View); 1908 1933 } 1909 1934 … … 1954 1979 connect(pSubMenu, SIGNAL(aboutToShow()), this, SLOT(sltPrepareMenuViewResize())); 1955 1980 } 1981 1982 1983 /* Mark menu as valid: */ 1984 m_invalidations.remove(UIActionIndexRT_M_ViewPopup); 1956 1985 } 1957 1986 … … 1975 2004 if (fAllowToShowActionToggleStatusBar) 1976 2005 pMenu->addAction(action(UIActionIndexRT_M_View_M_StatusBar_T_Visibility)); 2006 2007 /* Mark menu as valid: */ 2008 m_invalidations.remove(UIActionIndexRT_M_View_M_StatusBar); 1977 2009 } 1978 2010 … … 2167 2199 if (fAllowToShowActionInstallGuestTools) 2168 2200 pMenu->addAction(action(UIActionIndexRT_M_Devices_S_InstallGuestTools)); 2201 2202 2203 /* Mark menu as valid: */ 2204 m_invalidations.remove(UIActionIndexRT_M_Devices); 2169 2205 } 2170 2206 … … 2182 2218 if (fAllowToShowActionHardDrivesSettings) 2183 2219 pMenu->addAction(action(UIActionIndexRT_M_Devices_M_HardDrives_S_Settings)); 2220 2221 /* Mark menu as valid: */ 2222 m_invalidations.remove(UIActionIndexRT_M_Devices_M_HardDrives); 2184 2223 } 2185 2224 … … 2227 2266 if (fAllowToShowActionSharedFoldersSettings) 2228 2267 pMenu->addAction(action(UIActionIndexRT_M_Devices_M_SharedFolders_S_Settings)); 2268 2269 /* Mark menu as valid: */ 2270 m_invalidations.remove(UIActionIndexRT_M_Devices_M_SharedFolders); 2229 2271 } 2230 2272 … … 2242 2284 if (fAllowToShowActionVideoCaptureSettings) 2243 2285 pMenu->addAction(action(UIActionIndexRT_M_Devices_M_VideoCapture_S_Settings)); 2286 2287 /* Mark menu as valid: */ 2288 m_invalidations.remove(UIActionIndexRT_M_Devices_M_VideoCapture); 2244 2289 } 2245 2290 … … 2276 2321 if (fAllowToShowActionLogDialog) 2277 2322 pMenu->addAction(action(UIActionIndex_Simple_LogDialog)); 2323 2324 /* Mark menu as valid: */ 2325 m_invalidations.remove(UIActionIndexRT_M_Debug); 2278 2326 } 2279 2327 #endif /* VBOX_WITH_DEBUGGER_GUI */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.h
r52215 r52218 127 127 void setRestrictionForMenuBar(UIActionRestrictionLevel level, RuntimeMenuType restriction); 128 128 129 #ifdef Q_WS_MAC130 /** Returns whether the action with passed @a type is allowed in the 'Application' menu. */131 bool isAllowedInMenuApplication(RuntimeMenuApplicationActionType type) const;132 /** Defines 'Application' menu @a restriction for passed @a level. */133 void setRestrictionForMenuApplication(UIActionRestrictionLevel level, RuntimeMenuApplicationActionType restriction);134 #endif /* Q_WS_MAC */135 136 129 /** Returns whether the action with passed @a type is allowed in the 'Machine' menu. */ 137 130 bool isAllowedInMenuMachine(RuntimeMenuMachineActionType type) const; … … 182 175 virtual void updateConfiguration(); 183 176 177 /** Update menu routine. */ 178 void updateMenu(int iIndex); 184 179 /** Update menus routine. */ 185 180 void updateMenus(); … … 231 226 /** Holds restricted menu types. */ 232 227 QMap<UIActionRestrictionLevel, RuntimeMenuType> m_restrictedMenus; 233 #ifdef Q_WS_MAC234 /** Holds restricted action types of the Application menu. */235 QMap<UIActionRestrictionLevel, RuntimeMenuApplicationActionType> m_restrictedActionsMenuApplication;236 #endif /* Q_WS_MAC */237 228 /** Holds restricted action types of the Machine menu. */ 238 229 QMap<UIActionRestrictionLevel, RuntimeMenuMachineActionType> m_restrictedActionsMenuMachine; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r52202 r52218 922 922 923 923 /* 'Devices' actions connections: */ 924 connect(actionPool(), SIGNAL(sigNotifyAboutMenuPrepare(int, QMenu*)), this, SLOT(sltHandleMenuPrepare(int, QMenu*))); 924 925 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_HardDrives_S_Settings), SIGNAL(triggered()), 925 926 this, SLOT(sltOpenStorageSettingsDialog())); 926 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_OpticalDevices)->menu(), SIGNAL(aboutToShow()),927 this, SLOT(sltPrepareStorageMenu()));928 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_FloppyDevices)->menu(), SIGNAL(aboutToShow()),929 this, SLOT(sltPrepareStorageMenu()));930 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices)->menu(), SIGNAL(aboutToShow()),931 this, SLOT(sltPrepareUSBMenu()));932 927 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices_S_Settings), SIGNAL(triggered()), 933 928 this, SLOT(sltOpenUSBDevicesSettingsDialog())); 934 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_WebCams)->menu(), SIGNAL(aboutToShow()),935 this, SLOT(sltPrepareWebCamMenu()));936 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_SharedClipboard)->menu(), SIGNAL(aboutToShow()),937 this, SLOT(sltPrepareSharedClipboardMenu()));938 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_DragAndDrop)->menu(), SIGNAL(aboutToShow()),939 this, SLOT(sltPrepareDragAndDropMenu()));940 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_Network)->menu(), SIGNAL(aboutToShow()),941 this, SLOT(sltPrepareNetworkMenu()));942 929 connect(actionPool()->action(UIActionIndexRT_M_Devices_M_Network_S_Settings), SIGNAL(triggered()), 943 930 this, SLOT(sltOpenNetworkSettingsDialog())); … … 955 942 #ifdef VBOX_WITH_DEBUGGER_GUI 956 943 /* 'Debug' actions connections: */ 957 connect(actionPool()->action(UIActionIndexRT_M_Debug)->menu(), SIGNAL(aboutToShow()),958 this, SLOT(sltPrepareDebugMenu()));959 944 connect(actionPool()->action(UIActionIndexRT_M_Debug_S_ShowStatistics), SIGNAL(triggered()), 960 945 this, SLOT(sltShowDebugStatistics())); … … 979 964 void UIMachineLogic::prepareHandlers() 980 965 { 981 /* Create handlers: */ 966 /* Prepare menu update-handlers: */ 967 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_OpticalDevices] = &UIMachineLogic::updateMenuDevicesStorage; 968 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_FloppyDevices] = &UIMachineLogic::updateMenuDevicesStorage; 969 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_USBDevices] = &UIMachineLogic::updateMenuDevicesUSB; 970 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_WebCams] = &UIMachineLogic::updateMenuDevicesWebCams; 971 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_SharedClipboard] = &UIMachineLogic::updateMenuDevicesSharedClipboard; 972 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_DragAndDrop] = &UIMachineLogic::updateMenuDevicesDragAndDrop; 973 m_menuUpdateHandlers[UIActionIndexRT_M_Devices_M_Network] = &UIMachineLogic::updateMenuDevicesNetwork; 974 #ifdef VBOX_WITH_DEBUGGER_GUI 975 m_menuUpdateHandlers[UIActionIndexRT_M_Debug] = &UIMachineLogic::updateMenuDebug; 976 #endif /* VBOX_WITH_DEBUGGER_GUI */ 977 978 /* Create keyboard/mouse handlers: */ 982 979 setKeyboardHandler(UIKeyboardHandler::create(this, visualStateType())); 983 980 setMouseHandler(UIMouseHandler::create(this, visualStateType())); 984 985 981 /* Update UI session values with current: */ 986 982 uisession()->setKeyboardState(keyboardHandler()->state()); … … 1171 1167 } 1172 1168 1169 void UIMachineLogic::sltHandleMenuPrepare(int iIndex, QMenu *pMenu) 1170 { 1171 /* Update if there is update-handler: */ 1172 if (m_menuUpdateHandlers.contains(iIndex)) 1173 (this->*(m_menuUpdateHandlers.value(iIndex)))(pMenu); 1174 } 1175 1173 1176 void UIMachineLogic::sltToggleGuestAutoresize(bool fEnabled) 1174 1177 { … … 1554 1557 } 1555 1558 1556 void UIMachineLogic::sltPrepareStorageMenu()1557 {1558 /* Get the sender() menu: */1559 QMenu *pMenu = qobject_cast<QMenu*>(sender());1560 AssertMsg(pMenu, ("This slot should only be called on hovering storage menu!\n"));1561 pMenu->clear();1562 1563 /* Determine device-type: */1564 const QMenu *pOpticalDevicesMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_OpticalDevices)->menu();1565 const QMenu *pFloppyDevicesMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_FloppyDevices)->menu();1566 const KDeviceType deviceType = pMenu == pOpticalDevicesMenu ? KDeviceType_DVD :1567 pMenu == pFloppyDevicesMenu ? KDeviceType_Floppy :1568 KDeviceType_Null;1569 AssertMsgReturnVoid(deviceType != KDeviceType_Null, ("Incorrect storage device-type!\n"));1570 1571 /* Prepare/fill all storage menus: */1572 const CMachine machine = session().GetMachine();1573 foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())1574 {1575 /* Current controller: */1576 const CStorageController controller = machine.GetStorageControllerByName(attachment.GetController());1577 /* If controller present and device-type correct: */1578 if (!controller.isNull() && attachment.GetType() == deviceType)1579 {1580 /* Current controller/attachment attributes: */1581 const QString strControllerName = controller.GetName();1582 const StorageSlot storageSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice());1583 1584 /* Prepare current storage menu: */1585 QMenu *pStorageMenu = 0;1586 /* If it will be more than one storage menu: */1587 if (pMenu->menuAction()->data().toInt() > 1)1588 {1589 /* We have to create sub-menu for each of them: */1590 pStorageMenu = new QMenu(QString("%1 (%2)").arg(strControllerName).arg(gpConverter->toString(storageSlot)), pMenu);1591 switch (controller.GetBus())1592 {1593 case KStorageBus_IDE: pStorageMenu->setIcon(QIcon(":/ide_16px.png")); break;1594 case KStorageBus_SATA: pStorageMenu->setIcon(QIcon(":/sata_16px.png")); break;1595 case KStorageBus_SCSI: pStorageMenu->setIcon(QIcon(":/scsi_16px.png")); break;1596 case KStorageBus_Floppy: pStorageMenu->setIcon(QIcon(":/floppy_16px.png")); break;1597 case KStorageBus_SAS: pStorageMenu->setIcon(QIcon(":/sata_16px.png")); break;1598 case KStorageBus_USB: pStorageMenu->setIcon(QIcon(":/usb_16px.png")); break;1599 default: break;1600 }1601 pMenu->addMenu(pStorageMenu);1602 }1603 /* Otherwise just use existing one: */1604 else pStorageMenu = pMenu;1605 1606 /* Fill current storage menu: */1607 vboxGlobal().prepareStorageMenu(*pStorageMenu,1608 this, SLOT(sltMountStorageMedium()),1609 machine, strControllerName, storageSlot);1610 }1611 }1612 }1613 1614 1559 void UIMachineLogic::sltMountStorageMedium() 1615 1560 { … … 1625 1570 /* Update current machine mount-target: */ 1626 1571 vboxGlobal().updateMachineStorage(machine, target); 1627 }1628 1629 void UIMachineLogic::sltPrepareUSBMenu()1630 {1631 /* Get and check the sender menu object: */1632 QMenu *pMenu = qobject_cast<QMenu*>(sender());1633 QMenu *pUSBDevicesMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices)->menu();1634 AssertMsg(pMenu == pUSBDevicesMenu, ("This slot should only be called on hovering USB menu!\n"));1635 Q_UNUSED(pUSBDevicesMenu);1636 1637 /* Clear menu initially: */1638 pMenu->clear();1639 1640 /* Add settings action: */1641 pMenu->addAction(actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices_S_Settings));1642 1643 /* Get current host: */1644 CHost host = vboxGlobal().host();1645 1646 /* Get host USB device list: */1647 CHostUSBDeviceVector devices = host.GetUSBDevices();1648 1649 /* Fill USB device menu: */1650 bool fIsUSBListEmpty = devices.size() == 0;1651 /* If device list is empty: */1652 if (fIsUSBListEmpty)1653 {1654 /* Add only one - "empty" action: */1655 QAction *pEmptyMenuAction = new QAction(pMenu);1656 pEmptyMenuAction->setEnabled(false);1657 pEmptyMenuAction->setText(tr("No USB Devices Connected"));1658 pEmptyMenuAction->setToolTip(tr("No supported devices connected to the host PC"));1659 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/usb_unavailable_16px.png", ":/usb_unavailable_disabled_16px.png"));1660 pMenu->addAction(pEmptyMenuAction);1661 }1662 /* If device list is NOT empty: */1663 else1664 {1665 /* Populate menu with host USB devices: */1666 for (int i = 0; i < devices.size(); ++i)1667 {1668 /* Get current host USB device: */1669 const CHostUSBDevice& hostDevice = devices[i];1670 /* Get USB device from current host USB device: */1671 CUSBDevice device(hostDevice);1672 1673 /* Create USB device action: */1674 QAction *pAttachUSBAction = new QAction(vboxGlobal().details(device), pMenu);1675 pAttachUSBAction->setCheckable(true);1676 connect(pAttachUSBAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachUSBDevice()));1677 pMenu->addAction(pAttachUSBAction);1678 1679 /* Check if that USB device was already attached to this session: */1680 CConsole console = session().GetConsole();1681 CUSBDevice attachedDevice = console.FindUSBDeviceById(device.GetId());1682 pAttachUSBAction->setChecked(!attachedDevice.isNull());1683 pAttachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);1684 1685 /* Set USB attach data: */1686 pAttachUSBAction->setData(QVariant::fromValue(USBTarget(!pAttachUSBAction->isChecked(), device.GetId())));1687 pAttachUSBAction->setToolTip(vboxGlobal().toolTip(device));1688 }1689 }1690 }1691 1692 /**1693 * Prepares menu content when user hovers <b>Webcam</b> submenu of the <b>Devices</b> menu.1694 * @note If host currently have no webcams attached there will be just one dummy action1695 * called <i>No Webcams Connected</i>. Otherwise there will be actions corresponding1696 * to existing webcams allowing user to attach/detach them within the guest.1697 * @note In order to enumerate webcams GUI assigns #WebCamTarget object as internal data1698 * for each the enumerated webcam menu action. Corresponding #sltAttachWebCamDevice1699 * slot will be called on action triggering. It will parse assigned #WebCamTarget data.1700 */1701 void UIMachineLogic::sltPrepareWebCamMenu()1702 {1703 /* Get and check the sender menu object: */1704 QMenu *pMenu = qobject_cast<QMenu*>(sender());1705 QMenu *pWebCamMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_WebCams)->menu();1706 AssertReturnVoid(pMenu == pWebCamMenu); Q_UNUSED(pWebCamMenu);1707 1708 /* Clear menu initially: */1709 pMenu->clear();1710 1711 /* Get current host: */1712 const CHost &host = vboxGlobal().host();1713 1714 /* Get host webcams list: */1715 const CHostVideoInputDeviceVector &webcams = host.GetVideoInputDevices();1716 1717 /* If webcam list is empty: */1718 if (webcams.isEmpty())1719 {1720 /* Add only one - "empty" action: */1721 QAction *pEmptyMenuAction = new QAction(pMenu);1722 pEmptyMenuAction->setEnabled(false);1723 pEmptyMenuAction->setText(tr("No Webcams Connected"));1724 pEmptyMenuAction->setToolTip(tr("No supported webcams connected to the host PC"));1725 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/web_camera_unavailable_16px.png", ":/web_camera_unavailable_disabled_16px.png"));1726 pMenu->addAction(pEmptyMenuAction);1727 }1728 /* If webcam list is NOT empty: */1729 else1730 {1731 /* Populate menu with host webcams: */1732 const QVector<QString> &attachedWebcamPaths = session().GetConsole().GetEmulatedUSB().GetWebcams();1733 foreach (const CHostVideoInputDevice &webcam, webcams)1734 {1735 /* Get webcam data: */1736 const QString &strWebcamName = webcam.GetName();1737 const QString &strWebcamPath = webcam.GetPath();1738 1739 /* Create/configure webcam action: */1740 QAction *pAttachWebcamAction = new QAction(strWebcamName, pMenu);1741 pAttachWebcamAction->setToolTip(vboxGlobal().toolTip(webcam));1742 pAttachWebcamAction->setCheckable(true);1743 pAttachWebcamAction->setChecked(attachedWebcamPaths.contains(strWebcamPath));1744 pAttachWebcamAction->setData(QVariant::fromValue(WebCamTarget(!pAttachWebcamAction->isChecked(), strWebcamName, strWebcamPath)));1745 connect(pAttachWebcamAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachWebCamDevice()));1746 pMenu->addAction(pAttachWebcamAction);1747 }1748 }1749 1572 } 1750 1573 … … 1795 1618 } 1796 1619 1797 /**1798 * Attaches/detaches webcam within the guest.1799 * @note In order to attach/detach webcams #sltPrepareWebCamMenu assigns #WebCamTarget object1800 * as internal data for each the enumerated webcam menu action. Corresponding data1801 * will be parsed here resulting in device attaching/detaching.1802 */1803 1620 void UIMachineLogic::sltAttachWebCamDevice() 1804 1621 { … … 1834 1651 } 1835 1652 1836 void UIMachineLogic::sltPrepareSharedClipboardMenu()1837 {1838 /* Get and check the sender menu object: */1839 QMenu *pMenu = qobject_cast<QMenu*>(sender());1840 QMenu *pSharedClipboardMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_SharedClipboard)->menu();1841 AssertMsg(pMenu == pSharedClipboardMenu, ("This slot should only be called on hovering Shared Clipboard menu!\n"));1842 Q_UNUSED(pSharedClipboardMenu);1843 1844 /* First run: */1845 if (!m_pSharedClipboardActions)1846 {1847 m_pSharedClipboardActions = new QActionGroup(this);1848 for (int i = KClipboardMode_Disabled; i < KClipboardMode_Max; ++i)1849 {1850 KClipboardMode mode = (KClipboardMode)i;1851 QAction *pAction = new QAction(gpConverter->toString(mode), m_pSharedClipboardActions);1852 pMenu->addAction(pAction);1853 pAction->setData(QVariant::fromValue(mode));1854 pAction->setCheckable(true);1855 pAction->setChecked(session().GetMachine().GetClipboardMode() == mode);1856 }1857 connect(m_pSharedClipboardActions, SIGNAL(triggered(QAction*)),1858 this, SLOT(sltChangeSharedClipboardType(QAction*)));1859 }1860 /* Subsequent runs: */1861 else1862 foreach (QAction *pAction, m_pSharedClipboardActions->actions())1863 if (pAction->data().value<KClipboardMode>() == session().GetMachine().GetClipboardMode())1864 pAction->setChecked(true);1865 }1866 1867 1653 void UIMachineLogic::sltChangeSharedClipboardType(QAction *pAction) 1868 1654 { … … 1870 1656 KClipboardMode mode = pAction->data().value<KClipboardMode>(); 1871 1657 session().GetMachine().SetClipboardMode(mode); 1872 }1873 1874 void UIMachineLogic::sltPrepareDragAndDropMenu()1875 {1876 /* Get and check the sender menu object: */1877 QMenu *pMenu = qobject_cast<QMenu*>(sender());1878 QMenu *pDragAndDropMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_DragAndDrop)->menu();1879 AssertMsg(pMenu == pDragAndDropMenu, ("This slot should only be called on hovering Drag'n'drop menu!\n"));1880 Q_UNUSED(pDragAndDropMenu);1881 1882 /* First run: */1883 if (!m_pDragAndDropActions)1884 {1885 m_pDragAndDropActions = new QActionGroup(this);1886 for (int i = KDnDMode_Disabled; i < KDnDMode_Max; ++i)1887 {1888 KDnDMode mode = (KDnDMode)i;1889 QAction *pAction = new QAction(gpConverter->toString(mode), m_pDragAndDropActions);1890 pMenu->addAction(pAction);1891 pAction->setData(QVariant::fromValue(mode));1892 pAction->setCheckable(true);1893 pAction->setChecked(session().GetMachine().GetDnDMode() == mode);1894 }1895 connect(m_pDragAndDropActions, SIGNAL(triggered(QAction*)),1896 this, SLOT(sltChangeDragAndDropType(QAction*)));1897 }1898 /* Subsequent runs: */1899 else1900 foreach (QAction *pAction, m_pDragAndDropActions->actions())1901 if (pAction->data().value<KDnDMode>() == session().GetMachine().GetDnDMode())1902 pAction->setChecked(true);1903 }1904 1905 /** Prepares menu content when user hovers <b>Network</b> submenu of the <b>Devices</b> menu. */1906 void UIMachineLogic::sltPrepareNetworkMenu()1907 {1908 /* Get and check 'the sender' menu object: */1909 QMenu *pMenu = qobject_cast<QMenu*>(sender());1910 QMenu *pNetworkMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_Network)->menu();1911 AssertReturnVoid(pMenu == pNetworkMenu);1912 Q_UNUSED(pNetworkMenu);1913 1914 /* Get and check current machine: */1915 const CMachine &machine = session().GetMachine();1916 AssertReturnVoid(!machine.isNull());1917 1918 /* Determine how many adapters we should display: */1919 KChipsetType chipsetType = machine.GetChipsetType();1920 ULONG uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(chipsetType));1921 1922 /* Enumerate existing network adapters: */1923 QMap<int, bool> adapterData;1924 for (ULONG uSlot = 0; uSlot < uCount; ++uSlot)1925 {1926 /* Get and check iterated adapter: */1927 const CNetworkAdapter &adapter = machine.GetNetworkAdapter(uSlot);1928 AssertReturnVoid(machine.isOk());1929 Assert(!adapter.isNull());1930 if (adapter.isNull())1931 continue;1932 1933 /* Remember adapter data if it is enabled: */1934 if (adapter.GetEnabled())1935 adapterData.insert((int)uSlot, (bool)adapter.GetCableConnected());1936 }1937 AssertReturnVoid(!adapterData.isEmpty());1938 1939 /* Delete all "temporary" actions: */1940 QList<QAction*> actions = pMenu->actions();1941 foreach (QAction *pAction, actions)1942 if (pAction->property("temporary").toBool())1943 delete pAction;1944 1945 /* Add new "temporary" actions: */1946 foreach (int iSlot, adapterData.keys())1947 {1948 QAction *pAction = pMenu->addAction(QIcon(adapterData[iSlot] ? ":/connect_16px.png": ":/disconnect_16px.png"),1949 adapterData.size() == 1 ? tr("Connect Network Adapter") : tr("Connect Network Adapter %1").arg(iSlot + 1),1950 this, SLOT(sltToggleNetworkAdapterConnection()));1951 pAction->setProperty("temporary", true);1952 pAction->setProperty("slot", iSlot);1953 pAction->setCheckable(true);1954 pAction->setChecked(adapterData[iSlot]);1955 }1956 1658 } 1957 1659 … … 2127 1829 #ifdef VBOX_WITH_DEBUGGER_GUI 2128 1830 2129 void UIMachineLogic::sltPrepareDebugMenu()2130 {2131 /* The "Logging" item. */2132 bool fEnabled = false;2133 bool fChecked = false;2134 CConsole console = session().GetConsole();2135 if (console.isOk())2136 {2137 CMachineDebugger cdebugger = console.GetDebugger();2138 if (console.isOk())2139 {2140 fEnabled = true;2141 fChecked = cdebugger.GetLogEnabled() != FALSE;2142 }2143 }2144 if (fEnabled != actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->isEnabled())2145 actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->setEnabled(fEnabled);2146 if (fChecked != actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->isChecked())2147 actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->setChecked(fChecked);2148 }2149 2150 1831 void UIMachineLogic::sltShowDebugStatistics() 2151 1832 { … … 2296 1977 } 2297 1978 1979 void UIMachineLogic::updateMenuDevicesStorage(QMenu *pMenu) 1980 { 1981 /* Clear contents: */ 1982 pMenu->clear(); 1983 1984 /* Determine device-type: */ 1985 const QMenu *pOpticalDevicesMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_OpticalDevices)->menu(); 1986 const QMenu *pFloppyDevicesMenu = actionPool()->action(UIActionIndexRT_M_Devices_M_FloppyDevices)->menu(); 1987 const KDeviceType deviceType = pMenu == pOpticalDevicesMenu ? KDeviceType_DVD : 1988 pMenu == pFloppyDevicesMenu ? KDeviceType_Floppy : 1989 KDeviceType_Null; 1990 AssertMsgReturnVoid(deviceType != KDeviceType_Null, ("Incorrect storage device-type!\n")); 1991 1992 /* Prepare/fill all storage menus: */ 1993 const CMachine machine = session().GetMachine(); 1994 foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments()) 1995 { 1996 /* Current controller: */ 1997 const CStorageController controller = machine.GetStorageControllerByName(attachment.GetController()); 1998 /* If controller present and device-type correct: */ 1999 if (!controller.isNull() && attachment.GetType() == deviceType) 2000 { 2001 /* Current controller/attachment attributes: */ 2002 const QString strControllerName = controller.GetName(); 2003 const StorageSlot storageSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice()); 2004 2005 /* Prepare current storage menu: */ 2006 QMenu *pStorageMenu = 0; 2007 /* If it will be more than one storage menu: */ 2008 if (pMenu->menuAction()->data().toInt() > 1) 2009 { 2010 /* We have to create sub-menu for each of them: */ 2011 pStorageMenu = new QMenu(QString("%1 (%2)").arg(strControllerName).arg(gpConverter->toString(storageSlot)), pMenu); 2012 switch (controller.GetBus()) 2013 { 2014 case KStorageBus_IDE: pStorageMenu->setIcon(QIcon(":/ide_16px.png")); break; 2015 case KStorageBus_SATA: pStorageMenu->setIcon(QIcon(":/sata_16px.png")); break; 2016 case KStorageBus_SCSI: pStorageMenu->setIcon(QIcon(":/scsi_16px.png")); break; 2017 case KStorageBus_Floppy: pStorageMenu->setIcon(QIcon(":/floppy_16px.png")); break; 2018 case KStorageBus_SAS: pStorageMenu->setIcon(QIcon(":/sata_16px.png")); break; 2019 case KStorageBus_USB: pStorageMenu->setIcon(QIcon(":/usb_16px.png")); break; 2020 default: break; 2021 } 2022 pMenu->addMenu(pStorageMenu); 2023 } 2024 /* Otherwise just use existing one: */ 2025 else pStorageMenu = pMenu; 2026 2027 /* Fill current storage menu: */ 2028 vboxGlobal().prepareStorageMenu(*pStorageMenu, 2029 this, SLOT(sltMountStorageMedium()), 2030 machine, strControllerName, storageSlot); 2031 } 2032 } 2033 } 2034 2035 void UIMachineLogic::updateMenuDevicesUSB(QMenu *pMenu) 2036 { 2037 /* Get current host: */ 2038 const CHost host = vboxGlobal().host(); 2039 /* Get host USB device list: */ 2040 const CHostUSBDeviceVector devices = host.GetUSBDevices(); 2041 2042 /* If device list is empty: */ 2043 if (devices.isEmpty()) 2044 { 2045 /* Add only one - "empty" action: */ 2046 QAction *pEmptyMenuAction = pMenu->addAction(UIIconPool::iconSet(":/usb_unavailable_16px.png", 2047 ":/usb_unavailable_disabled_16px.png"), 2048 tr("No USB Devices Connected")); 2049 pEmptyMenuAction->setToolTip(tr("No supported devices connected to the host PC")); 2050 pEmptyMenuAction->setEnabled(false); 2051 } 2052 /* If device list is NOT empty: */ 2053 else 2054 { 2055 /* Populate menu with host USB devices: */ 2056 foreach (const CHostUSBDevice& hostDevice, devices) 2057 { 2058 /* Get USB device from current host USB device: */ 2059 const CUSBDevice device(hostDevice); 2060 2061 /* Create USB device action: */ 2062 QAction *pAttachUSBAction = pMenu->addAction(vboxGlobal().details(device), 2063 this, SLOT(sltAttachUSBDevice())); 2064 pAttachUSBAction->setToolTip(vboxGlobal().toolTip(device)); 2065 pAttachUSBAction->setCheckable(true); 2066 2067 /* Check if that USB device was already attached to this session: */ 2068 CConsole console = session().GetConsole(); 2069 const CUSBDevice attachedDevice = console.FindUSBDeviceById(device.GetId()); 2070 pAttachUSBAction->setChecked(!attachedDevice.isNull()); 2071 pAttachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable); 2072 2073 /* Set USB attach data: */ 2074 pAttachUSBAction->setData(QVariant::fromValue(USBTarget(!pAttachUSBAction->isChecked(), device.GetId()))); 2075 } 2076 } 2077 } 2078 2079 void UIMachineLogic::updateMenuDevicesWebCams(QMenu *pMenu) 2080 { 2081 /* Clear contents: */ 2082 pMenu->clear(); 2083 2084 /* Get current host: */ 2085 const CHost host = vboxGlobal().host(); 2086 /* Get host webcam list: */ 2087 const CHostVideoInputDeviceVector webcams = host.GetVideoInputDevices(); 2088 2089 /* If webcam list is empty: */ 2090 if (webcams.isEmpty()) 2091 { 2092 /* Add only one - "empty" action: */ 2093 QAction *pEmptyMenuAction = pMenu->addAction(UIIconPool::iconSet(":/web_camera_unavailable_16px.png", 2094 ":/web_camera_unavailable_disabled_16px.png"), 2095 tr("No Webcams Connected")); 2096 pEmptyMenuAction->setToolTip(tr("No supported webcams connected to the host PC")); 2097 pEmptyMenuAction->setEnabled(false); 2098 } 2099 /* If webcam list is NOT empty: */ 2100 else 2101 { 2102 /* Populate menu with host webcams: */ 2103 const QVector<QString> attachedWebcamPaths = session().GetConsole().GetEmulatedUSB().GetWebcams(); 2104 foreach (const CHostVideoInputDevice &webcam, webcams) 2105 { 2106 /* Get webcam data: */ 2107 const QString strWebcamName = webcam.GetName(); 2108 const QString strWebcamPath = webcam.GetPath(); 2109 2110 /* Create/configure webcam action: */ 2111 QAction *pAttachWebcamAction = pMenu->addAction(strWebcamName, 2112 this, SLOT(sltAttachWebCamDevice())); 2113 pAttachWebcamAction->setToolTip(vboxGlobal().toolTip(webcam)); 2114 pAttachWebcamAction->setCheckable(true); 2115 2116 /* Check if that webcam was already attached to this session: */ 2117 pAttachWebcamAction->setChecked(attachedWebcamPaths.contains(strWebcamPath)); 2118 2119 /* Set USB attach data: */ 2120 pAttachWebcamAction->setData(QVariant::fromValue(WebCamTarget(!pAttachWebcamAction->isChecked(), strWebcamName, strWebcamPath))); 2121 } 2122 } 2123 } 2124 2125 void UIMachineLogic::updateMenuDevicesSharedClipboard(QMenu *pMenu) 2126 { 2127 /* First run: */ 2128 if (!m_pSharedClipboardActions) 2129 { 2130 m_pSharedClipboardActions = new QActionGroup(this); 2131 for (int i = KClipboardMode_Disabled; i < KClipboardMode_Max; ++i) 2132 { 2133 KClipboardMode mode = (KClipboardMode)i; 2134 QAction *pAction = new QAction(gpConverter->toString(mode), m_pSharedClipboardActions); 2135 pMenu->addAction(pAction); 2136 pAction->setData(QVariant::fromValue(mode)); 2137 pAction->setCheckable(true); 2138 pAction->setChecked(session().GetMachine().GetClipboardMode() == mode); 2139 } 2140 connect(m_pSharedClipboardActions, SIGNAL(triggered(QAction*)), 2141 this, SLOT(sltChangeSharedClipboardType(QAction*))); 2142 } 2143 /* Subsequent runs: */ 2144 else 2145 foreach (QAction *pAction, m_pSharedClipboardActions->actions()) 2146 if (pAction->data().value<KClipboardMode>() == session().GetMachine().GetClipboardMode()) 2147 pAction->setChecked(true); 2148 } 2149 2150 void UIMachineLogic::updateMenuDevicesDragAndDrop(QMenu *pMenu) 2151 { 2152 /* First run: */ 2153 if (!m_pDragAndDropActions) 2154 { 2155 m_pDragAndDropActions = new QActionGroup(this); 2156 for (int i = KDnDMode_Disabled; i < KDnDMode_Max; ++i) 2157 { 2158 KDnDMode mode = (KDnDMode)i; 2159 QAction *pAction = new QAction(gpConverter->toString(mode), m_pDragAndDropActions); 2160 pMenu->addAction(pAction); 2161 pAction->setData(QVariant::fromValue(mode)); 2162 pAction->setCheckable(true); 2163 pAction->setChecked(session().GetMachine().GetDnDMode() == mode); 2164 } 2165 connect(m_pDragAndDropActions, SIGNAL(triggered(QAction*)), 2166 this, SLOT(sltChangeDragAndDropType(QAction*))); 2167 } 2168 /* Subsequent runs: */ 2169 else 2170 foreach (QAction *pAction, m_pDragAndDropActions->actions()) 2171 if (pAction->data().value<KDnDMode>() == session().GetMachine().GetDnDMode()) 2172 pAction->setChecked(true); 2173 } 2174 2175 void UIMachineLogic::updateMenuDevicesNetwork(QMenu *pMenu) 2176 { 2177 /* Get and check current machine: */ 2178 const CMachine machine = session().GetMachine(); 2179 AssertReturnVoid(!machine.isNull()); 2180 2181 /* Determine how many adapters we should display: */ 2182 const KChipsetType chipsetType = machine.GetChipsetType(); 2183 const ULONG uCount = qMin((ULONG)4, vboxGlobal().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(chipsetType)); 2184 2185 /* Enumerate existing network adapters: */ 2186 QMap<int, bool> adapterData; 2187 for (ULONG uSlot = 0; uSlot < uCount; ++uSlot) 2188 { 2189 /* Get and check iterated adapter: */ 2190 const CNetworkAdapter adapter = machine.GetNetworkAdapter(uSlot); 2191 AssertReturnVoid(machine.isOk() && !adapter.isNull()); 2192 2193 /* Skip disabled adapters: */ 2194 if (!adapter.GetEnabled()) 2195 continue; 2196 2197 /* Remember adapter data: */ 2198 adapterData.insert((int)uSlot, (bool)adapter.GetCableConnected()); 2199 } 2200 2201 /* Make sure at least one adapter was enabled: */ 2202 if (adapterData.isEmpty()) 2203 return; 2204 2205 /* Add new actions: */ 2206 foreach (int iSlot, adapterData.keys()) 2207 { 2208 QAction *pAction = pMenu->addAction(UIIconPool::iconSet(adapterData[iSlot] ? ":/connect_16px.png": ":/disconnect_16px.png"), 2209 adapterData.size() == 1 ? tr("Connect Network Adapter") : tr("Connect Network Adapter %1").arg(iSlot + 1), 2210 this, SLOT(sltToggleNetworkAdapterConnection())); 2211 pAction->setProperty("slot", iSlot); 2212 pAction->setCheckable(true); 2213 pAction->setChecked(adapterData[iSlot]); 2214 } 2215 } 2216 2217 #ifdef VBOX_WITH_DEBUGGER_GUI 2218 void UIMachineLogic::updateMenuDebug(QMenu*) 2219 { 2220 /* The "Logging" item. */ 2221 bool fEnabled = false; 2222 bool fChecked = false; 2223 const CConsole console = session().GetConsole(); 2224 if (console.isOk()) 2225 { 2226 const CMachineDebugger cdebugger = console.GetDebugger(); 2227 if (console.isOk()) 2228 { 2229 fEnabled = true; 2230 fChecked = cdebugger.GetLogEnabled() != FALSE; 2231 } 2232 } 2233 if (fEnabled != actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->isEnabled()) 2234 actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->setEnabled(fEnabled); 2235 if (fChecked != actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->isChecked()) 2236 actionPool()->action(UIActionIndexRT_M_Debug_T_Logging)->setChecked(fChecked); 2237 } 2238 #endif /* VBOX_WITH_DEBUGGER_GUI */ 2239 2298 2240 void UIMachineLogic::showGlobalPreferences(const QString &strCategory /* = QString() */, const QString &strControl /* = QString() */) 2299 2241 { -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
r52202 r52218 49 49 Q_OBJECT; 50 50 51 /** Pointer to menu update-handler for this class: */ 52 typedef void (UIMachineLogic::*MenuUpdateHandler)(QMenu *pMenu); 53 51 54 signals: 52 55 … … 196 199 197 200 private slots: 201 202 /** Handle menu prepare. */ 203 void sltHandleMenuPrepare(int iIndex, QMenu *pMenu); 198 204 199 205 /* "Machine" menu functionality: */ … … 225 231 void sltOpenNetworkSettingsDialog(); 226 232 void sltOpenSharedFoldersSettingsDialog(); 227 void sltPrepareStorageMenu();228 233 void sltMountStorageMedium(); 229 void sltPrepareUSBMenu();230 void sltPrepareWebCamMenu();231 234 void sltAttachUSBDevice(); 232 235 void sltAttachWebCamDevice(); 233 void sltPrepareSharedClipboardMenu();234 236 void sltChangeSharedClipboardType(QAction *pAction); 235 void sltPrepareDragAndDropMenu();236 void sltPrepareNetworkMenu();237 237 void sltToggleNetworkAdapterConnection(); 238 238 void sltChangeDragAndDropType(QAction *pAction); … … 244 244 #ifdef VBOX_WITH_DEBUGGER_GUI 245 245 /* "Debug" menu functionality: */ 246 void sltPrepareDebugMenu();247 246 void sltShowDebugStatistics(); 248 247 void sltShowDebugCommandLine(); … … 266 265 267 266 private: 267 268 /** Update 'Devices' : 'Optical/Floppy Devices' menu routine. */ 269 void updateMenuDevicesStorage(QMenu *pMenu); 270 /** Update 'Devices' : 'USB Devices' menu routine. */ 271 void updateMenuDevicesUSB(QMenu *pMenu); 272 /** Update 'Devices' : 'Web Cams' menu routine. */ 273 void updateMenuDevicesWebCams(QMenu *pMenu); 274 /** Update 'Devices' : 'Shared Clipboard' menu routine. */ 275 void updateMenuDevicesSharedClipboard(QMenu *pMenu); 276 /** Update 'Devices' : 'Drag and Drop' menu routine. */ 277 void updateMenuDevicesDragAndDrop(QMenu *pMenu); 278 /** Update 'Devices' : 'Network' menu routine. */ 279 void updateMenuDevicesNetwork(QMenu *pMenu); 280 #ifdef VBOX_WITH_DEBUGGER_GUI 281 /** Update 'Debug' menu routine. */ 282 void updateMenuDebug(QMenu *pMenu); 283 #endif /* VBOX_WITH_DEBUGGER_GUI */ 268 284 269 285 /** Show Global Preferences on the page defined by @a strCategory and tab defined by @a strControl. */ … … 286 302 QActionGroup *m_pSharedClipboardActions; 287 303 QActionGroup *m_pDragAndDropActions; 304 305 /** Holds the map of menu update-handlers. */ 306 QMap<int, MenuUpdateHandler> m_menuUpdateHandlers; 288 307 289 308 bool m_fIsWindowsCreated : 1;
Note:
See TracChangeset
for help on using the changeset viewer.