VirtualBox

Changeset 52218 in vbox


Ignore:
Timestamp:
Jul 28, 2014 7:24:01 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95283
Message:

FE/Qt: 7462: Runtime UI: Menu-bar, menu cleanup/rework (part 11).

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  
    7171template<> bool canConvert<StorageSlot>();
    7272template<> bool canConvert<MenuHelpActionType>();
     73#ifdef Q_WS_MAC
     74template<> bool canConvert<MenuApplicationActionType>();
     75#endif /* Q_WS_MAC */
    7376template<> bool canConvert<RuntimeMenuType>();
    74 #ifdef Q_WS_MAC
    75 template<> bool canConvert<RuntimeMenuApplicationActionType>();
    76 #endif /* Q_WS_MAC */
    7777template<> bool canConvert<RuntimeMenuMachineActionType>();
    7878template<> bool canConvert<RuntimeMenuViewActionType>();
     
    125125template<> QString toInternalString(const MenuHelpActionType &menuHelpActionType);
    126126template<> MenuHelpActionType fromInternalString<MenuHelpActionType>(const QString &strMenuHelpActionType);
     127#ifdef Q_WS_MAC
     128template<> QString toInternalString(const MenuApplicationActionType &runtimeMenuApplicationActionType);
     129template<> MenuApplicationActionType fromInternalString<MenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType);
     130#endif /* Q_WS_MAC */
    127131template<> QString toInternalString(const RuntimeMenuType &runtimeMenuType);
    128132template<> RuntimeMenuType fromInternalString<RuntimeMenuType>(const QString &strRuntimeMenuType);
    129 #ifdef Q_WS_MAC
    130 template<> QString toInternalString(const RuntimeMenuApplicationActionType &runtimeMenuApplicationActionType);
    131 template<> RuntimeMenuApplicationActionType fromInternalString<RuntimeMenuApplicationActionType>(const QString &strRuntimeMenuApplicationActionType);
    132 #endif /* Q_WS_MAC */
    133133template<> QString toInternalString(const RuntimeMenuMachineActionType &runtimeMenuMachineActionType);
    134134template<> RuntimeMenuMachineActionType fromInternalString<RuntimeMenuMachineActionType>(const QString &strRuntimeMenuMachineActionType);
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp

    r52215 r52218  
    3535template<> bool canConvert<StorageSlot>() { return true; }
    3636template<> bool canConvert<MenuHelpActionType>() { return true; }
     37#ifdef Q_WS_MAC
     38template<> bool canConvert<MenuApplicationActionType>() { return true; }
     39#endif /* Q_WS_MAC */
    3740template<> bool canConvert<RuntimeMenuType>() { return true; }
    38 #ifdef Q_WS_MAC
    39 template<> bool canConvert<RuntimeMenuApplicationActionType>() { return true; }
    40 #endif /* Q_WS_MAC */
    4141template<> bool canConvert<RuntimeMenuMachineActionType>() { return true; }
    4242template<> bool canConvert<RuntimeMenuViewActionType>() { return true; }
     
    409409}
    410410
     411#ifdef Q_WS_MAC
     412/* QString <= MenuApplicationActionType: */
     413template<> 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: */
     432template<> 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
    411449/* QString <= RuntimeMenuType: */
    412450template<> QString toInternalString(const RuntimeMenuType &runtimeMenuType)
     
    452490    return values.at(keys.indexOf(QRegExp(strRuntimeMenuType, Qt::CaseInsensitive)));
    453491}
    454 
    455 #ifdef Q_WS_MAC
    456 /* 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 us
    479      * 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 */
    492492
    493493/* QString <= RuntimeMenuMachineActionType: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r52215 r52218  
    378378};
    379379
     380#ifdef Q_WS_MAC
     381/** Menu "Application": Action types. */
     382enum 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
    380392/** Runtime UI: Menu types. */
    381393enum RuntimeMenuType
     
    391403    RuntimeMenuType_All     = 0xFF
    392404};
    393 
    394 #ifdef Q_WS_MAC
    395 /** Runtime UI: Menu "Application": Action types. */
    396 enum RuntimeMenuApplicationActionType
    397 {
    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         = 0xFFFF
    403 };
    404 #endif /* Q_WS_MAC */
    405405
    406406/** Runtime UI: Menu "Machine": Action types. */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r52215 r52218  
    25042504
    25052505#ifdef Q_WS_MAC
    2506 RuntimeMenuApplicationActionType UIExtraDataManager::restrictedRuntimeMenuApplicationActionTypes(const QString &strID)
     2506MenuApplicationActionType UIExtraDataManager::restrictedRuntimeMenuApplicationActionTypes(const QString &strID)
    25072507{
    25082508    /* Prepare result: */
    2509     RuntimeMenuApplicationActionType result = RuntimeMenuApplicationActionType_Invalid;
     2509    MenuApplicationActionType result = MenuApplicationActionType_Invalid;
    25102510    /* Get restricted runtime-application-menu action-types: */
    25112511    foreach (const QString &strValue, extraDataStringList(GUI_RestrictedRuntimeApplicationMenuActions, strID))
    25122512    {
    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);
    25162516    }
    25172517    /* Return result: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r52215 r52218  
    288288    #ifdef Q_WS_MAC
    289289        /** Mac OS X: Returns restricted Runtime UI action types for Application menu. */
    290         RuntimeMenuApplicationActionType restrictedRuntimeMenuApplicationActionTypes(const QString &strID);
     290        MenuApplicationActionType restrictedRuntimeMenuApplicationActionTypes(const QString &strID);
    291291    #endif /* Q_WS_MAC */
    292292        /** Returns restricted Runtime UI action types for Machine menu. */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r52215 r52218  
    179179    if (!strIcon.isNull())
    180180        setIcon(UIIconPool::iconSet(strIcon, strIconDis));
    181     setMenu(new UIMenu);
     181    prepare();
    182182}
    183183
     
    188188    if (!icon.isNull())
    189189        setIcon(icon);
     190    prepare();
     191}
     192
     193void UIActionMenu::setShowToolTip(bool fShowToolTip)
     194{
     195    qobject_cast<UIMenu*>(menu())->setShowToolTip(fShowToolTip);
     196}
     197
     198void UIActionMenu::prepare()
     199{
     200    /* Create menu: */
    190201    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    }
    196208}
    197209
     
    620632    m_restrictedActionsMenuHelp[level] = restriction;
    621633    updateMenuHelp();
     634}
     635
     636#ifdef Q_WS_MAC
     637bool 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
     645void UIActionPool::setRestrictionForMenuApplication(UIActionRestrictionLevel level, MenuApplicationActionType restriction)
     646{
     647    m_restrictedActionsMenuApplication[level] = restriction;
     648    updateMenuHelp();
     649}
     650#endif /* Q_WS_MAC */
     651
     652void 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);
    622669}
    623670
     
    650697#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
    651698    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());
    652705
    653706    /* Retranslate finally: */
     
    722775}
    723776
     777void 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
    724784void UIActionPool::updateMenuHelp()
    725785{
     
    827887    const bool fAllowToShowActionAbout =
    828888#ifdef Q_WS_MAC
    829         isAllowedInMenuApplication(RuntimeMenuApplicationActionType_About);
     889        isAllowedInMenuApplication(MenuApplicationActionType_About);
    830890#else /* !Q_WS_MAC */
    831891        isAllowedInMenuHelp(MenuHelpActionType_About);
     
    845905        const bool fAllowToShowActionPreferences =
    846906#ifdef Q_WS_MAC
    847             isAllowedInMenuApplication(RuntimeMenuApplicationActionType_Preferences);
     907            isAllowedInMenuApplication(MenuApplicationActionType_Preferences);
    848908#else /* !Q_WS_MAC */
    849909            isAllowedInMenuHelp(MenuHelpActionType_Preferences);
     
    853913            pMenu->addAction(action(UIActionIndex_Simple_Preferences));
    854914    }
     915
     916
     917    /* Mark menu as valid: */
     918    m_invalidations.remove(UIActionIndex_Menu_Help);
    855919}
    856920
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r52215 r52218  
    191191private:
    192192
     193    /** Prepare routine. */
     194    void prepare();
     195
    193196    /** Updates action text accordingly. */
    194197    virtual void updateText();
     
    279282    Q_OBJECT;
    280283
     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
     295signals:
     296
     297    /** Notifies about menu prepare. */
     298    void sigNotifyAboutMenuPrepare(int iIndex, QMenu *pMenu);
     299
    281300public:
    282301
     
    308327    void setRestrictionForMenuHelp(UIActionRestrictionLevel level, MenuHelpActionType restriction);
    309328
     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
    310336    /** Hot-key processing delegate. */
    311337    bool processHotKey(const QKeySequence &key);
     
    318344
    319345protected slots:
     346
     347    /** Handles menu prepare. */
     348    void sltHandleMenuPrepare();
    320349
    321350    /** Loads keyboard shortcuts of action-pool into shortcuts-pool. */
     
    343372    virtual void updateConfiguration();
    344373
     374    /** Update menu routine. */
     375    virtual void updateMenu(int iIndex);
    345376    /** Update menus routine. */
    346377    virtual void updateMenus() = 0;
     
    361392    /** Holds whether this action-pool is temporary. */
    362393    const bool m_fTemporary;
    363     /** Holds all the actions action-pool contains. */
     394
     395    /** Holds the map of actions. */
    364396    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;
    365401
    366402    /** Holds restricted action types of the Help menu. */
    367403    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 */
    368408};
    369409
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.cpp

    r52215 r52218  
    12751275    updateMenus();
    12761276}
    1277 
    1278 #ifdef Q_WS_MAC
    1279 bool UIActionPoolRuntime::isAllowedInMenuApplication(RuntimeMenuApplicationActionType type) const
    1280 {
    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 */
    12941277
    12951278bool UIActionPoolRuntime::isAllowedInMenuMachine(RuntimeMenuMachineActionType type) const
     
    14551438#endif /* Q_WS_MAC */
    14561439
     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
    14571457    /* Call to base-class: */
    14581458    UIActionPool::preparePool();
     
    15461546    {
    15471547#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);
    15501550#else /* !Q_WS_MAC */
    15511551        m_restrictedActionsMenuMachine[UIActionRestrictionLevel_Base] = (RuntimeMenuMachineActionType)
     
    15561556    /* Call to base-class: */
    15571557    UIActionPool::updateConfiguration();
     1558}
     1559
     1560void 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))();
    15581569}
    15591570
     
    17791790    const bool fAllowToShowActionClose =
    17801791#ifdef Q_WS_MAC
    1781         isAllowedInMenuApplication(RuntimeMenuApplicationActionType_Close);
     1792        isAllowedInMenuApplication(MenuApplicationActionType_Close);
    17821793#else /* !Q_WS_MAC */
    17831794        isAllowedInMenuMachine(RuntimeMenuMachineActionType_Close);
     
    17851796    pMenu->addAction(action(UIActionIndexRT_M_Machine_S_Close));
    17861797    action(UIActionIndexRT_M_Machine_S_Close)->setEnabled(fAllowToShowActionClose);
     1798
     1799
     1800    /* Mark menu as valid: */
     1801    m_invalidations.remove(UIActionIndexRT_M_Machine);
    17871802}
    17881803
     
    18001815    if (fAllowToShowActionKeyboardSettings)
    18011816        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);
    18021820}
    18031821
     
    18151833    if (fAllowToShowActionMouseIntegration)
    18161834        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);
    18171838}
    18181839
     
    19061927            connect(pSubMenu, SIGNAL(aboutToShow()), this, SLOT(sltPrepareMenuViewResize()));
    19071928        }
     1929
     1930
     1931    /* Mark menu as valid: */
     1932    m_invalidations.remove(UIActionIndexRT_M_View);
    19081933}
    19091934
     
    19541979            connect(pSubMenu, SIGNAL(aboutToShow()), this, SLOT(sltPrepareMenuViewResize()));
    19551980        }
     1981
     1982
     1983    /* Mark menu as valid: */
     1984    m_invalidations.remove(UIActionIndexRT_M_ViewPopup);
    19561985}
    19571986
     
    19752004    if (fAllowToShowActionToggleStatusBar)
    19762005        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);
    19772009}
    19782010
     
    21672199    if (fAllowToShowActionInstallGuestTools)
    21682200        pMenu->addAction(action(UIActionIndexRT_M_Devices_S_InstallGuestTools));
     2201
     2202
     2203    /* Mark menu as valid: */
     2204    m_invalidations.remove(UIActionIndexRT_M_Devices);
    21692205}
    21702206
     
    21822218    if (fAllowToShowActionHardDrivesSettings)
    21832219        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);
    21842223}
    21852224
     
    22272266    if (fAllowToShowActionSharedFoldersSettings)
    22282267        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);
    22292271}
    22302272
     
    22422284    if (fAllowToShowActionVideoCaptureSettings)
    22432285        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);
    22442289}
    22452290
     
    22762321    if (fAllowToShowActionLogDialog)
    22772322        pMenu->addAction(action(UIActionIndex_Simple_LogDialog));
     2323
     2324    /* Mark menu as valid: */
     2325    m_invalidations.remove(UIActionIndexRT_M_Debug);
    22782326}
    22792327#endif /* VBOX_WITH_DEBUGGER_GUI */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionPoolRuntime.h

    r52215 r52218  
    127127    void setRestrictionForMenuBar(UIActionRestrictionLevel level, RuntimeMenuType restriction);
    128128
    129 #ifdef Q_WS_MAC
    130     /** 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 
    136129    /** Returns whether the action with passed @a type is allowed in the 'Machine' menu. */
    137130    bool isAllowedInMenuMachine(RuntimeMenuMachineActionType type) const;
     
    182175    virtual void updateConfiguration();
    183176
     177    /** Update menu routine. */
     178    void updateMenu(int iIndex);
    184179    /** Update menus routine. */
    185180    void updateMenus();
     
    231226    /** Holds restricted menu types. */
    232227    QMap<UIActionRestrictionLevel, RuntimeMenuType> m_restrictedMenus;
    233 #ifdef Q_WS_MAC
    234     /** Holds restricted action types of the Application menu. */
    235     QMap<UIActionRestrictionLevel, RuntimeMenuApplicationActionType> m_restrictedActionsMenuApplication;
    236 #endif /* Q_WS_MAC */
    237228    /** Holds restricted action types of the Machine menu. */
    238229    QMap<UIActionRestrictionLevel, RuntimeMenuMachineActionType> m_restrictedActionsMenuMachine;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r52202 r52218  
    922922
    923923    /* 'Devices' actions connections: */
     924    connect(actionPool(), SIGNAL(sigNotifyAboutMenuPrepare(int, QMenu*)), this, SLOT(sltHandleMenuPrepare(int, QMenu*)));
    924925    connect(actionPool()->action(UIActionIndexRT_M_Devices_M_HardDrives_S_Settings), SIGNAL(triggered()),
    925926            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()));
    932927    connect(actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices_S_Settings), SIGNAL(triggered()),
    933928            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()));
    942929    connect(actionPool()->action(UIActionIndexRT_M_Devices_M_Network_S_Settings), SIGNAL(triggered()),
    943930            this, SLOT(sltOpenNetworkSettingsDialog()));
     
    955942#ifdef VBOX_WITH_DEBUGGER_GUI
    956943    /* 'Debug' actions connections: */
    957     connect(actionPool()->action(UIActionIndexRT_M_Debug)->menu(), SIGNAL(aboutToShow()),
    958             this, SLOT(sltPrepareDebugMenu()));
    959944    connect(actionPool()->action(UIActionIndexRT_M_Debug_S_ShowStatistics), SIGNAL(triggered()),
    960945            this, SLOT(sltShowDebugStatistics()));
     
    979964void UIMachineLogic::prepareHandlers()
    980965{
    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: */
    982979    setKeyboardHandler(UIKeyboardHandler::create(this, visualStateType()));
    983980    setMouseHandler(UIMouseHandler::create(this, visualStateType()));
    984 
    985981    /* Update UI session values with current: */
    986982    uisession()->setKeyboardState(keyboardHandler()->state());
     
    11711167}
    11721168
     1169void 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
    11731176void UIMachineLogic::sltToggleGuestAutoresize(bool fEnabled)
    11741177{
     
    15541557}
    15551558
    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 
    16141559void UIMachineLogic::sltMountStorageMedium()
    16151560{
     
    16251570    /* Update current machine mount-target: */
    16261571    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     else
    1664     {
    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 action
    1695  *       called <i>No Webcams Connected</i>. Otherwise there will be actions corresponding
    1696  *       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 data
    1698  *       for each the enumerated webcam menu action. Corresponding #sltAttachWebCamDevice
    1699  *       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     else
    1730     {
    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     }
    17491572}
    17501573
     
    17951618}
    17961619
    1797 /**
    1798  * Attaches/detaches webcam within the guest.
    1799  * @note In order to attach/detach webcams #sltPrepareWebCamMenu assigns #WebCamTarget object
    1800  *       as internal data for each the enumerated webcam menu action. Corresponding data
    1801  *       will be parsed here resulting in device attaching/detaching.
    1802  */
    18031620void UIMachineLogic::sltAttachWebCamDevice()
    18041621{
     
    18341651}
    18351652
    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     else
    1862         foreach (QAction *pAction, m_pSharedClipboardActions->actions())
    1863             if (pAction->data().value<KClipboardMode>() == session().GetMachine().GetClipboardMode())
    1864                 pAction->setChecked(true);
    1865 }
    1866 
    18671653void UIMachineLogic::sltChangeSharedClipboardType(QAction *pAction)
    18681654{
     
    18701656    KClipboardMode mode = pAction->data().value<KClipboardMode>();
    18711657    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     else
    1900         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     }
    19561658}
    19571659
     
    21271829#ifdef VBOX_WITH_DEBUGGER_GUI
    21281830
    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 
    21501831void UIMachineLogic::sltShowDebugStatistics()
    21511832{
     
    22961977}
    22971978
     1979void 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
     2035void 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
     2079void 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
     2125void 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
     2150void 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
     2175void 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
     2218void 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
    22982240void UIMachineLogic::showGlobalPreferences(const QString &strCategory /* = QString() */, const QString &strControl /* = QString() */)
    22992241{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r52202 r52218  
    4949    Q_OBJECT;
    5050
     51    /** Pointer to menu update-handler for this class: */
     52    typedef void (UIMachineLogic::*MenuUpdateHandler)(QMenu *pMenu);
     53
    5154signals:
    5255
     
    196199
    197200private slots:
     201
     202    /** Handle menu prepare. */
     203    void sltHandleMenuPrepare(int iIndex, QMenu *pMenu);
    198204
    199205    /* "Machine" menu functionality: */
     
    225231    void sltOpenNetworkSettingsDialog();
    226232    void sltOpenSharedFoldersSettingsDialog();
    227     void sltPrepareStorageMenu();
    228233    void sltMountStorageMedium();
    229     void sltPrepareUSBMenu();
    230     void sltPrepareWebCamMenu();
    231234    void sltAttachUSBDevice();
    232235    void sltAttachWebCamDevice();
    233     void sltPrepareSharedClipboardMenu();
    234236    void sltChangeSharedClipboardType(QAction *pAction);
    235     void sltPrepareDragAndDropMenu();
    236     void sltPrepareNetworkMenu();
    237237    void sltToggleNetworkAdapterConnection();
    238238    void sltChangeDragAndDropType(QAction *pAction);
     
    244244#ifdef VBOX_WITH_DEBUGGER_GUI
    245245    /* "Debug" menu functionality: */
    246     void sltPrepareDebugMenu();
    247246    void sltShowDebugStatistics();
    248247    void sltShowDebugCommandLine();
     
    266265
    267266private:
     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 */
    268284
    269285    /** Show Global Preferences on the page defined by @a strCategory and tab defined by @a strControl. */
     
    286302    QActionGroup *m_pSharedClipboardActions;
    287303    QActionGroup *m_pDragAndDropActions;
     304
     305    /** Holds the map of menu update-handlers. */
     306    QMap<int, MenuUpdateHandler> m_menuUpdateHandlers;
    288307
    289308    bool m_fIsWindowsCreated : 1;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette