VirtualBox

Changeset 86925 in vbox


Ignore:
Timestamp:
Nov 19, 2020 6:19:19 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141407
Message:

FE/Qt: bugref:9866: VirtualBox Manager: Extending Close menu with Terminate functionality for cloud VMs.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolManager.cpp

    r86922 r86925  
    15071507        setName(QApplication::translate("UIActionPool", "&Save State"));
    15081508        setStatusTip(QApplication::translate("UIActionPool", "Save state of selected virtual machines"));
     1509    }
     1510};
     1511
     1512/** Simple action extension, used as 'Perform Terminate' action class. */
     1513class UIActionSimpleManagerClosePerformTerminate : public UIActionSimple
     1514{
     1515    Q_OBJECT;
     1516
     1517public:
     1518
     1519    /** Constructs action passing @a pParent to the base-class. */
     1520    UIActionSimpleManagerClosePerformTerminate(UIActionPool *pParent)
     1521        : UIActionSimple(pParent, ":/vm_discard_16px.png", ":/vm_discard_disabled_16px.png")
     1522    {}
     1523
     1524protected:
     1525
     1526    /** Returns shortcut extra-data ID. */
     1527    virtual QString shortcutExtraDataID() const /* override */
     1528    {
     1529        return QString("TerminateVM");
     1530    }
     1531
     1532    /** Handles translation event. */
     1533    virtual void retranslateUi() /* override */
     1534    {
     1535        setIconText(QApplication::translate("UIActionPool", "Terminate"));
     1536        setName(QApplication::translate("UIActionPool", "&Terminate Cloud Instance..."));
     1537        setStatusTip(QApplication::translate("UIActionPool", "Terminate cloud instance of selected virtual machines"));
     1538        setToolTip(simplifyText(text()) + (shortcut().isEmpty() ? QString() : QString(" (%1)").arg(shortcut().toString())));
    15091539    }
    15101540};
     
    33883418    m_pool[UIActionIndexMN_M_Group_M_Close_S_Detach] = new UIActionSimpleManagerClosePerformDetach(this);
    33893419    m_pool[UIActionIndexMN_M_Group_M_Close_S_SaveState] = new UIActionSimpleManagerClosePerformSave(this);
     3420    m_pool[UIActionIndexMN_M_Group_M_Close_S_Terminate] = new UIActionSimpleManagerClosePerformTerminate(this);
    33903421    m_pool[UIActionIndexMN_M_Group_M_Close_S_Shutdown] = new UIActionSimpleManagerClosePerformShutdown(this);
    33913422    m_pool[UIActionIndexMN_M_Group_M_Close_S_PowerOff] = new UIActionSimpleManagerClosePerformPowerOff(this);
     
    34323463    m_pool[UIActionIndexMN_M_Machine_M_Close_S_Detach] = new UIActionSimpleManagerClosePerformDetach(this);
    34333464    m_pool[UIActionIndexMN_M_Machine_M_Close_S_SaveState] = new UIActionSimpleManagerClosePerformSave(this);
     3465    m_pool[UIActionIndexMN_M_Machine_M_Close_S_Terminate] = new UIActionSimpleManagerClosePerformTerminate(this);
    34343466    m_pool[UIActionIndexMN_M_Machine_M_Close_S_Shutdown] = new UIActionSimpleManagerClosePerformShutdown(this);
    34353467    m_pool[UIActionIndexMN_M_Machine_M_Close_S_PowerOff] = new UIActionSimpleManagerClosePerformPowerOff(this);
     
    36803712                    // << action(UIActionIndexMN_M_Group_M_Close_S_Detach)
    36813713                    << action(UIActionIndexMN_M_Group_M_Close_S_SaveState)
     3714                    << action(UIActionIndexMN_M_Group_M_Close_S_Terminate)
    36823715                    << action(UIActionIndexMN_M_Group_M_Close_S_Shutdown)
    36833716                    << action(UIActionIndexMN_M_Group_M_Close_S_PowerOff)
     
    37203753                    // << action(UIActionIndexMN_M_Machine_M_Close_S_Detach)
    37213754                    << action(UIActionIndexMN_M_Machine_M_Close_S_SaveState)
     3755                    << action(UIActionIndexMN_M_Machine_M_Close_S_Terminate)
    37223756                    << action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown)
    37233757                    << action(UIActionIndexMN_M_Machine_M_Close_S_PowerOff)
     
    39814015    pMenu->clear();
    39824016
    3983     /* Populate 'Group' / 'Close' menu: */
    3984     // pMenu->addAction(action(UIActionIndexMN_M_Group_M_Close_S_Detach));
    3985     pMenu->addAction(action(UIActionIndexMN_M_Group_M_Close_S_SaveState));
    3986     pMenu->addAction(action(UIActionIndexMN_M_Group_M_Close_S_Shutdown));
     4017#ifdef VBOX_WS_MAC
     4018    // WORKAROUND:
     4019    // On macOS you can't leave menu empty and still have it in
     4020    // the menu-bar, you have to leave there at least something.
     4021    // Remaining stuff will be appended from UIVirtualBoxManager.
    39874022    pMenu->addAction(action(UIActionIndexMN_M_Group_M_Close_S_PowerOff));
    3988 
    3989     /* Mark menu as valid: */
    3990     m_invalidations.remove(UIActionIndexMN_M_Group_M_Close);
     4023#endif
     4024
     4025    /* This menu always remains invalid.. */
    39914026}
    39924027
     
    39994034    pMenu->clear();
    40004035
    4001     /* Populate 'Machine' / 'Close' menu: */
    4002     // pMenu->addAction(action(UIActionIndexMN_M_Machine_M_Close_S_Detach));
    4003     pMenu->addAction(action(UIActionIndexMN_M_Machine_M_Close_S_SaveState));
    4004     pMenu->addAction(action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown));
     4036#ifdef VBOX_WS_MAC
     4037    // WORKAROUND:
     4038    // On macOS you can't leave menu empty and still have it in
     4039    // the menu-bar, you have to leave there at least something.
     4040    // Remaining stuff will be appended from UIVirtualBoxManager.
    40054041    pMenu->addAction(action(UIActionIndexMN_M_Machine_M_Close_S_PowerOff));
    4006 
    4007     /* Mark menu as valid: */
    4008     m_invalidations.remove(UIActionIndexMN_M_Machine_M_Close);
     4042#endif
     4043
     4044    /* This menu always remains invalid.. */
    40094045}
    40104046
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolManager.h

    r86344 r86925  
    7272    UIActionIndexMN_M_Group_M_Close_S_Detach,
    7373    UIActionIndexMN_M_Group_M_Close_S_SaveState,
     74    UIActionIndexMN_M_Group_M_Close_S_Terminate,
    7475    UIActionIndexMN_M_Group_M_Close_S_Shutdown,
    7576    UIActionIndexMN_M_Group_M_Close_S_PowerOff,
     
    115116    UIActionIndexMN_M_Machine_M_Close_S_Detach,
    116117    UIActionIndexMN_M_Machine_M_Close_S_SaveState,
     118    UIActionIndexMN_M_Machine_M_Close_S_Terminate,
    117119    UIActionIndexMN_M_Machine_M_Close_S_Shutdown,
    118120    UIActionIndexMN_M_Machine_M_Close_S_PowerOff,
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r86922 r86925  
    17761776}
    17771777
     1778void UIVirtualBoxManager::sltPerformTerminateMachine()
     1779{
     1780    /* Get selected items: */
     1781    QList<UIVirtualMachineItem*> items = currentItems();
     1782    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
     1783
     1784    /* Prepare the list of the machines to be terminated: */
     1785    QStringList machinesToTerminate;
     1786    QList<UIVirtualMachineItem*> itemsToTerminate;
     1787    foreach (UIVirtualMachineItem *pItem, items)
     1788    {
     1789        if (isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_Terminate, QList<UIVirtualMachineItem*>() << pItem))
     1790        {
     1791            machinesToTerminate << pItem->name();
     1792            itemsToTerminate << pItem;
     1793        }
     1794    }
     1795    AssertMsg(!machinesToTerminate.isEmpty(), ("This action should not be allowed!"));
     1796
     1797    /* Confirm terminating: */
     1798    if (   machinesToTerminate.isEmpty()
     1799        || !msgCenter().confirmTerminateCloudInstance(machinesToTerminate.join(", ")))
     1800        return;
     1801
     1802    /* For every confirmed item to terminate: */
     1803    foreach (UIVirtualMachineItem *pItem, itemsToTerminate)
     1804    {
     1805        /* Get cloud machine: */
     1806        AssertPtrReturnVoid(pItem);
     1807        UIVirtualMachineItemCloud *pCloudItem = pItem->toCloud();
     1808        AssertPtrReturnVoid(pCloudItem);
     1809        CCloudMachine comMachine = pCloudItem->machine();
     1810
     1811        /* Acquire machine name: */
     1812        QString strName;
     1813        if (!cloudMachineName(comMachine, strName))
     1814            continue;
     1815
     1816        /* Prepare terminate cloud instance progress: */
     1817        CProgress comProgress = comMachine.Terminate();
     1818        if (!comMachine.isOk())
     1819        {
     1820            msgCenter().cannotTerminateCloudInstance(comMachine);
     1821            continue;
     1822        }
     1823
     1824        /* Show terminate cloud instance progress: */
     1825        msgCenter().showModalProgressDialog(comProgress, strName, ":/progress_media_delete_90px.png", 0, 0); /// @todo use proper icon
     1826        if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
     1827            msgCenter().cannotTerminateCloudInstance(comProgress, strName);
     1828    }
     1829}
     1830
    17781831void UIVirtualBoxManager::sltPerformShutdownMachine()
    17791832{
     
    23972450    connect(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_SaveState), &UIAction::triggered,
    23982451            this, &UIVirtualBoxManager::sltPerformSaveMachineState);
     2452    connect(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Terminate), &UIAction::triggered,
     2453            this, &UIVirtualBoxManager::sltPerformTerminateMachine);
    23992454    connect(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Shutdown), &UIAction::triggered,
    24002455            this, &UIVirtualBoxManager::sltPerformShutdownMachine);
     
    24072462    connect(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_SaveState), &UIAction::triggered,
    24082463            this, &UIVirtualBoxManager::sltPerformSaveMachineState);
     2464    connect(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Terminate), &UIAction::triggered,
     2465            this, &UIVirtualBoxManager::sltPerformTerminateMachine);
    24092466    connect(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown), &UIAction::triggered,
    24102467            this, &UIVirtualBoxManager::sltPerformShutdownMachine);
     
    28792936}
    28802937
    2881 void UIVirtualBoxManager::updateMenuGroupClose(QMenu *)
    2882 {
     2938void UIVirtualBoxManager::updateMenuGroupClose(QMenu *pMenu)
     2939{
     2940    /* Get first selected item: */
     2941    UIVirtualMachineItem *pItem = currentItem();
     2942    AssertPtrReturnVoid(pItem);
    28832943    /* Get selected items: */
    28842944    QList<UIVirtualMachineItem*> items = currentItems();
    28852945    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    28862946
     2947    /* For local machine: */
     2948    if (pItem->itemType() == UIVirtualMachineItemType_Local)
     2949    {
     2950        // pMenu->addAction(action(UIActionIndexMN_M_Group_M_Close_S_Detach));
     2951        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_SaveState));
     2952        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Shutdown));
     2953        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_PowerOff));
     2954    }
     2955    else
     2956    {
     2957        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Terminate));
     2958        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Shutdown));
     2959        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_PowerOff));
     2960    }
     2961
     2962    /* Configure 'Group' / 'Close' menu: */
    28872963    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_Shutdown, items));
    28882964}
     
    30023078}
    30033079
    3004 void UIVirtualBoxManager::updateMenuMachineClose(QMenu *)
    3005 {
     3080void UIVirtualBoxManager::updateMenuMachineClose(QMenu *pMenu)
     3081{
     3082    /* Get first selected item: */
     3083    UIVirtualMachineItem *pItem = currentItem();
     3084    AssertPtrReturnVoid(pItem);
    30063085    /* Get selected items: */
    30073086    QList<UIVirtualMachineItem*> items = currentItems();
    30083087    AssertMsgReturnVoid(!items.isEmpty(), ("At least one item should be selected!\n"));
    30093088
     3089    /* For local machine: */
     3090    if (pItem->itemType() == UIVirtualMachineItemType_Local)
     3091    {
     3092        // pMenu->addAction(action(UIActionIndexMN_M_Machine_M_Close_S_Detach));
     3093        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_SaveState));
     3094        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown));
     3095        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_PowerOff));
     3096    }
     3097    else
     3098    {
     3099        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Terminate));
     3100        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown));
     3101        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_PowerOff));
     3102    }
     3103
     3104    /* Configure 'Machine' / 'Close' menu: */
    30103105    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_Shutdown, items));
    30113106}
     
    31443239    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Detach)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_Detach, items));
    31453240    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_SaveState)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_SaveState, items));
     3241    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Terminate)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_Terminate, items));
    31463242    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_Shutdown, items));
    31473243    actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_PowerOff)->setEnabled(isActionEnabled(UIActionIndexMN_M_Group_M_Close_S_PowerOff, items));
     
    31513247    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Detach)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_Detach, items));
    31523248    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_SaveState)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_SaveState, items));
     3249    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Terminate)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_Terminate, items));
    31533250    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Shutdown)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_Shutdown, items));
    31543251    actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_PowerOff)->setEnabled(isActionEnabled(UIActionIndexMN_M_Machine_M_Close_S_PowerOff, items));
     
    34083505        case UIActionIndexMN_M_Machine_M_Close:
    34093506        {
    3410             return isAtLeastOneItemStarted(items);
     3507            return    (isItemsLocal(items) && isAtLeastOneItemStarted(items))
     3508                   || (isItemsCloud(items) && isAtLeastOneItemDiscardable(items));
    34113509        }
    34123510        case UIActionIndexMN_M_Group_M_Close_S_Detach:
     
    34183516                   && isItemsLocal(items);
    34193517        }
     3518        case UIActionIndexMN_M_Group_M_Close_S_Terminate:
     3519        case UIActionIndexMN_M_Machine_M_Close_S_Terminate:
     3520        {
     3521            return    isActionEnabled(UIActionIndexMN_M_Machine_M_Close, items)
     3522                   && isAtLeastOneItemDiscardable(items);
     3523        }
    34203524        case UIActionIndexMN_M_Group_M_Close_S_Shutdown:
    34213525        case UIActionIndexMN_M_Machine_M_Close_S_Shutdown:
     
    34433547    foreach (UIVirtualMachineItem *pItem, items)
    34443548        if (!pItem->toLocal())
     3549            return false;
     3550    return true;
     3551}
     3552
     3553/* static */
     3554bool UIVirtualBoxManager::isItemsCloud(const QList<UIVirtualMachineItem*> &items)
     3555{
     3556    foreach (UIVirtualMachineItem *pItem, items)
     3557        if (!pItem->toCloud())
    34453558            return false;
    34463559    return true;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r86734 r86925  
    274274        /** Handles call to save machine state. */
    275275        void sltPerformSaveMachineState();
     276        /** Handles call to terminate machine. */
     277        void sltPerformTerminateMachine();
    276278        /** Handles call to ask machine for shutdown. */
    277279        void sltPerformShutdownMachine();
     
    411413        /** Returns whether all passed @a items are local. */
    412414        static bool isItemsLocal(const QList<UIVirtualMachineItem*> &items);
     415        /** Returns whether all passed @a items are cloud. */
     416        static bool isItemsCloud(const QList<UIVirtualMachineItem*> &items);
    413417        /** Returns whether all passed @a items are powered off. */
    414418        static bool isItemsPoweredOff(const QList<UIVirtualMachineItem*> &items);
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp

    r86923 r86925  
    838838                        m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Group_S_Add));
    839839                        m_pToolBar->addSeparator();
    840                         m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Group_S_Discard));
     840                        if (isSingleLocalGroupSelected())
     841                            m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Group_S_Discard));
     842                        else if (   isSingleCloudProviderGroupSelected()
     843                                 || isSingleCloudProfileGroupSelected())
     844                            m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_Close_S_Terminate));
    841845                        m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Group_M_StartOrShow));
    842846                    }
     
    847851                        m_pToolBar->addSeparator();
    848852                        m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Settings));
    849                         m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Discard));
     853                        if (isLocalMachineItemSelected())
     854                            m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Discard));
     855                        else if (isCloudMachineItemSelected())
     856                            m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_Close_S_Terminate));
    850857                        m_pToolBar->addAction(actionPool()->action(UIActionIndexMN_M_Machine_M_StartOrShow));
    851858                    }
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