VirtualBox

Changeset 83705 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 15, 2020 3:46:18 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137212
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Implementing sltCloudMachineRegistered handler which will be used when corresponding event appears; For now it's directly used when new cloud VMs being added from the GUI side.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp

    r83698 r83705  
    2424#include "UIChooserNodeGlobal.h"
    2525#include "UIChooserNodeMachine.h"
     26#include "UICloudNetworkingStuff.h"
    2627#include "UIExtraDataManager.h"
    2728#include "UIMessageCenter.h"
     
    398399}
    399400
     401void UIChooserAbstractModel::sltCloudMachineRegistered(const QString &strProviderShortName, const QString &strProfileName,
     402                                                       const QUuid &uMachineId, const bool fRegistered)
     403{
     404    /* Existing VM unregistered? */
     405    if (!fRegistered)
     406    {
     407        /* Remove machine-items with passed id: */
     408        invisibleRoot()->removeAllNodes(uMachineId);
     409        /// @todo make sure there is fake item if no real item exist, never wipe out empty groups ..
     410    }
     411    /* New VM registered? */
     412    else
     413    {
     414        /* Add new machine-item: */
     415        const QString strGroupName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
     416        const CCloudMachine comMachine = cloudMachineById(strProviderShortName, strProfileName, uMachineId);
     417        addCloudMachineIntoTheTree(strGroupName, comMachine, true /* make it visible */);
     418        /// @todo make sure there is no fake item if at least one real item exists ..
     419    }
     420}
     421
    400422void UIChooserAbstractModel::sltSessionStateChanged(const QUuid &uMachineId, const KSessionState)
    401423{
     
    552574
    553575    /* Which VM we are loading: */
    554     const QUuid uMachineId = comMachine.GetId();
     576    const QUuid uId = comMachine.GetId();
    555577    LogRelFlow(("UIChooserModel: Loading local VM with ID={%s}...\n",
    556                 toOldStyleUuid(uMachineId).toUtf8().constData()));
     578                toOldStyleUuid(uId).toUtf8().constData()));
    557579    /* Is that machine accessible? */
    558580    if (comMachine.GetAccessible())
     
    578600        }
    579601        /* Update group definitions: */
    580         m_groups[toOldStyleUuid(uMachineId)] = groupList;
     602        m_groups[toOldStyleUuid(uId)] = groupList;
    581603    }
    582604    /* Inaccessible machine: */
     
    585607        /* VM is accessible: */
    586608        LogRelFlow(("UIChooserModel:  Local VM {%s} is inaccessible.\n",
    587                     toOldStyleUuid(uMachineId).toUtf8().constData()));
     609                    toOldStyleUuid(uId).toUtf8().constData()));
    588610        /* Create machine-item with main-root group-item as parent: */
    589611        createLocalMachineNode(invisibleRoot(), comMachine);
    590612    }
     613}
     614
     615void UIChooserAbstractModel::addCloudMachineIntoTheTree(const QString &strGroup,
     616                                                        const CCloudMachine &comMachine,
     617                                                        bool fMakeItVisible /* = false */)
     618{
     619    /* Make sure passed VM is not NULL: */
     620    if (comMachine.isNull())
     621        LogRelFlow(("UIChooserModel: ERROR: Passed cloud VM is NULL!\n"));
     622    AssertReturnVoid(!comMachine.isNull());
     623
     624    /* Which VM we are loading: */
     625    const QUuid uId = comMachine.GetId();
     626    LogRelFlow(("UIChooserModel: Loading cloud VM with ID={%s}...\n",
     627                toOldStyleUuid(uId).toUtf8().constData()));
     628    /* Acquire VM name: */
     629    QString strName = comMachine.GetName();
     630    if (strName.isEmpty())
     631        strName = uId.toString();
     632    LogRelFlow(("UIChooserModel:  Creating node for cloud VM {%s} in group {%s}.\n",
     633                strName.toUtf8().constData(), strGroup.toUtf8().constData()));
     634    /* Create machine-item with found group-item as parent: */
     635    createCloudMachineNode(getCloudGroupNode(strGroup, invisibleRoot(), fMakeItVisible), comMachine);
     636    /* Update group definitions: */
     637    const QStringList groupList(strGroup);
     638    m_groups[toOldStyleUuid(uId)] = groupList;
    591639}
    592640
     
    632680                               fAllGroupsOpened || shouldGroupNodeBeOpened(pParentNode, strSecondSubName));
    633681    return strSecondSuffix.isEmpty() ? pNewGroupNode : getLocalGroupNode(strFirstSuffix, pNewGroupNode, fAllGroupsOpened);
     682}
     683
     684UIChooserNode *UIChooserAbstractModel::getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened)
     685{
     686    /* Check passed stuff: */
     687    if (pParentNode->name() == strName)
     688        return pParentNode;
     689
     690    /* Prepare variables: */
     691    const QString strFirstSubName = strName.section('/', 0, 0);
     692    const QString strFirstSuffix = strName.section('/', 1, -1);
     693    const QString strSecondSubName = strFirstSuffix.section('/', 0, 0);
     694
     695    /* Passed group name equal to first sub-name: */
     696    if (pParentNode->name() == strFirstSubName)
     697    {
     698        /* Make sure first-suffix is NOT empty: */
     699        AssertMsg(!strFirstSuffix.isEmpty(), ("Invalid group name!"));
     700        /* Trying to get group node among our children: */
     701        foreach (UIChooserNode *pGroupNode, pParentNode->nodes(UIChooserNodeType_Group))
     702        {
     703            if (   pGroupNode->toGroupNode()->groupType() != UIChooserNodeGroupType_Local
     704                && pGroupNode->name() == strSecondSubName)
     705            {
     706                UIChooserNode *pFoundNode = getCloudGroupNode(strFirstSuffix, pGroupNode, fAllGroupsOpened);
     707                if (UIChooserNodeGroup *pFoundGroupNode = pFoundNode->toGroupNode())
     708                    if (fAllGroupsOpened && pFoundGroupNode->isClosed())
     709                        pFoundGroupNode->open();
     710                return pFoundNode;
     711            }
     712        }
     713    }
     714
     715    /* Found nothing? Returning parent: */
     716    AssertFailedReturn(pParentNode);
    634717}
    635718
     
    794877void UIChooserAbstractModel::createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine)
    795878{
    796     /* Create machine node: */
    797879    new UIChooserNodeMachine(pParentNode,
    798880                             false /* favorite */,
    799881                             getDesiredNodePosition(pParentNode, UIChooserNodeType_Machine, toOldStyleUuid(comMachine.GetId())),
    800882                             comMachine);
     883}
     884
     885void UIChooserAbstractModel::createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine)
     886{
     887    UIChooserNodeMachine *pNode = new UIChooserNodeMachine(pParentNode,
     888                                                           false /* favorite */,
     889                                                           getDesiredNodePosition(pParentNode,
     890                                                                                  UIChooserNodeType_Machine,
     891                                                                                  toOldStyleUuid(comMachine.GetId())),
     892                                                           comMachine);
     893    /* Request for async node update if necessary: */
     894    if (!comMachine.GetAccessible())
     895        pNode->cache()->toCloud()->updateInfoAsync(false /* delayed? */);
    801896}
    802897
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r83698 r83705  
    3535class UIChooser;
    3636class UIChooserNode;
     37class CCloudMachine;
    3738class CMachine;
    3839#ifdef VBOX_GUI_WITH_CLOUD_VMS
     
    134135        /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
    135136        virtual void sltLocalMachineRegistered(const QUuid &uMachineId, const bool fRegistered);
     137        /** Handles cloud machine registering/unregistering for machine with certain @a uMachineId.
     138          * @param  strProviderShortName  Brings provider short name.
     139          * @param  strProfileName        Brings profile name. */
     140        virtual void sltCloudMachineRegistered(const QString &strProviderShortName, const QString &strProfileName,
     141                                               const QUuid &uMachineId, const bool fRegistered);
    136142        /** Handles session @a enmState change for machine with certain @a uMachineId. */
    137143        virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
     
    176182        /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
    177183        void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
     184        /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
     185        void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
    178186
    179187        /** Acquires local group node, creates one if necessary.
     
    182190          * @param  fAllGroupsOpened  Brings whether we should open all the groups till the required one. */
    183191        UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
     192        /** Acquires cloud group node, never create new, returns root if nothing found.
     193          * @param  strName           Brings the name of group we looking for.
     194          * @param  pParentNode       Brings the parent we starting to look for a group from.
     195          * @param  fAllGroupsOpened  Brings whether we should open all the groups till the required one. */
     196        UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
    184197
    185198        /** Returns whether group node with certain @a strName should be opened, searching starting from the passed @a pParentItem. */
     
    199212        /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
    200213        void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
     214        /** Creates cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
     215        void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
    201216    /** @} */
    202217
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r83698 r83705  
    696696}
    697697
     698void UIChooserModel::sltCloudMachineRegistered(const QString &strProviderName, const QString &strProfileName,
     699                                               const QUuid &uId, const bool fRegistered)
     700{
     701    /* Call to base-class: */
     702    UIChooserAbstractModel::sltCloudMachineRegistered(strProviderName, strProfileName, uId, fRegistered);
     703
     704    /* Existing VM unregistered? */
     705    if (!fRegistered)
     706    {
     707        /* Update tree for main root: */
     708        updateNavigationItemList();
     709        updateLayout();
     710
     711        /* Make sure selected-item present, if possible: */
     712        if (!firstSelectedItem() && !navigationItems().isEmpty())
     713        {
     714            setSelectedItem(navigationItems().first());
     715            emit sigSelectionInvalidated();
     716        }
     717        /* Make sure current-item present, if possible: */
     718        else if (!currentItem() && firstSelectedItem())
     719            setCurrentItem(firstSelectedItem());
     720        /* Notify about selected-item change: */
     721        emit sigSelectionChanged();
     722    }
     723    /* New VM registered? */
     724    else
     725    {
     726        /* Rebuild tree for main root: */
     727        buildTreeForMainRoot();
     728        updateNavigationItemList();
     729        updateLayout();
     730
     731        /* Select newly added item: */
     732        setSelectedItem(root()->searchForItem(uId.toString(),
     733                                              UIChooserItemSearchFlag_Machine |
     734                                              UIChooserItemSearchFlag_ExactId));
     735    }
     736}
     737
    698738void UIChooserModel::sltReloadMachine(const QUuid &uId)
    699739{
     
    940980
    941981        // WORKAROUND:
    942         // Hehey! Now we have to inject created VM nodes and then rebuild tree for the main root node ourselves
    943         // cause there is no corresponding event yet. Later this to be done in corresponding event handler instead.
     982        // Hehey! Now we have to inject created VM nodes and then rebuild tree for the main root node
     983        // ourselves cause there is no corresponding event yet. So we are calling actual handler to do that.
    944984        foreach (const CCloudMachine &comMachine, pWizard->machines())
    945             new UIChooserNodeMachine(pGroup->node(),
    946                                      false /* favorite */,
    947                                      pGroup->node()->nodes().size() /* position */,
    948                                      comMachine);
    949         // Remember first selected item definition:
    950         const QString strDefinition = firstSelectedItem()->definition();
    951         // Rebuild tree for main root:
    952         buildTreeForMainRoot();
    953         updateNavigationItemList();
    954         updateLayout();
    955         // Restore selection:
    956         setSelectedItem(strDefinition);
     985            sltCloudMachineRegistered(pGroup->parentItem()->name() /* provider name */,
     986                                      pGroup->name() /* profile name */,
     987                                      comMachine.GetId() /* machine ID */,
     988                                      true /* registered? */);
    957989
    958990        delete pWizard;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r83698 r83705  
    249249        /** Handles local machine registering/unregistering for machine with certain @a uId. */
    250250        virtual void sltLocalMachineRegistered(const QUuid &uId, const bool fRegistered) /* override */;
     251        /** Handles cloud machine registering/unregistering for machine with certain @a uId.
     252          * @param  strProviderName  Brings provider short name.
     253          * @param  strProfileName   Brings profile name. */
     254        virtual void sltCloudMachineRegistered(const QString &strProviderName, const QString &strProfileName,
     255                                               const QUuid &uId, const bool fRegistered);
    251256    /** @} */
    252257
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