VirtualBox

Changeset 86611 in vbox


Ignore:
Timestamp:
Oct 16, 2020 2:47:32 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Rework List Cloud Machines task handler to determine which VMs were [un]registered; This behavior have to replace missed cloud machine registration event.

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

    r86609 r86611  
    713713}
    714714
    715 void UIChooserAbstractModel::sltCloudMachineRegistered(const QString &strProviderShortName,
    716                                                        const QString &strProfileName,
    717                                                        const CCloudMachine &comMachine)
     715void UIChooserAbstractModel::sltCloudMachinesUnregistered(const QString &strProviderShortName,
     716                                                          const QString &strProfileName,
     717                                                          const QList<QUuid> &ids)
    718718{
    719719    /* Search for profile node: */
     
    725725        return;
    726726
     727    /* Remove machine-items with passed id: */
     728    foreach (const QUuid &uId, ids)
     729        pProfileNode->removeAllNodes(uId);
     730
     731    /* If there are no items left => add fake cloud VM node: */
     732    if (pProfileNode->nodes(UIChooserNodeType_Machine).isEmpty())
     733        new UIChooserNodeMachine(pProfileNode /* parent */,
     734                                 0 /* position */,
     735                                 UIFakeCloudVirtualMachineItemState_Done);
     736}
     737
     738void UIChooserAbstractModel::sltCloudMachineRegistered(const QString &strProviderShortName,
     739                                                       const QString &strProfileName,
     740                                                       const CCloudMachine &comMachine)
     741{
     742    /* Search for profile node: */
     743    const QString strProfileNodeName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
     744    QList<UIChooserNode*> profileNodes;
     745    invisibleRoot()->searchForNodes(strProfileNodeName, UIChooserItemSearchFlag_CloudProfile | UIChooserItemSearchFlag_ExactId, profileNodes);
     746    UIChooserNode *pProfileNode = profileNodes.value(0);
     747    if (!pProfileNode)
     748        return;
     749
    727750    /* Add new machine-item: */
    728751    addCloudMachineIntoTheTree(strProfileNodeName, comMachine, true /* make it visible? */);
     752
     753    /* Search for possible fake node: */
     754    QList<UIChooserNode*> fakeNodes;
     755    pProfileNode->searchForNodes(QUuid().toString(), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
     756    /* Delete fake node if present: */
     757    delete fakeNodes.value(0);
     758}
     759
     760void UIChooserAbstractModel::sltCloudMachinesRegistered(const QString &strProviderShortName,
     761                                                        const QString &strProfileName,
     762                                                        const QVector<CCloudMachine> &machines)
     763{
     764    /* Search for profile node: */
     765    const QString strProfileNodeName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
     766    QList<UIChooserNode*> profileNodes;
     767    invisibleRoot()->searchForNodes(strProfileNodeName, UIChooserItemSearchFlag_CloudProfile | UIChooserItemSearchFlag_ExactId, profileNodes);
     768    UIChooserNode *pProfileNode = profileNodes.value(0);
     769    if (!pProfileNode)
     770        return;
     771
     772    /* Add new machine-items: */
     773    foreach (const CCloudMachine &comMachine, machines)
     774        addCloudMachineIntoTheTree(strProfileNodeName, comMachine, false /* make it visible? */);
    729775
    730776    /* Search for possible fake node: */
     
    752798        return;
    753799
    754     /* Search for fake node: */
    755     QList<UIChooserNode*> fakeNodes;
    756     pProfileNode->searchForNodes(QUuid().toString(), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
    757     UIChooserNode *pFakeNode = fakeNodes.value(0);
    758     if (!pFakeNode)
    759         return;
    760 
    761     /* And if we have at least one cloud machine: */
    762     const QVector<CCloudMachine> machines = pAcquiringTask->result();
    763     if (!machines.isEmpty())
    764     {
    765         /* Remove fake node: */
    766         delete pFakeNode;
    767 
    768         /* Add real cloud VM nodes: */
    769         foreach (const CCloudMachine &comCloudMachine, machines)
    770             createCloudMachineNode(pProfileNode, comCloudMachine);
    771     }
    772     else
    773     {
    774         /* Otherwise toggle and update "Empty" node: */
    775         UIChooserNodeMachine *pFakeMachineNode = pFakeNode->toMachineNode();
    776         AssertReturnVoid(pFakeMachineNode && pFakeMachineNode->cacheType() == UIVirtualMachineItemType_CloudFake);
    777         UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFakeMachineNode->cache()->toCloud();
    778         AssertPtrReturnVoid(pFakeCloudMachineItem);
    779         pFakeCloudMachineItem->setFakeCloudItemState(UIFakeCloudVirtualMachineItemState_Done);
    780         pFakeCloudMachineItem->setFakeCloudItemErrorMessage(pAcquiringTask->errorInfo());
    781     }
     800    /* Compose old set of machine IDs: */
     801    QSet<QUuid> oldIDs;
     802    foreach (UIChooserNode *pNode, pProfileNode->nodes(UIChooserNodeType_Machine))
     803    {
     804        AssertPtrReturnVoid(pNode);
     805        UIChooserNodeMachine *pNodeMachine = pNode->toMachineNode();
     806        AssertPtrReturnVoid(pNodeMachine);
     807        if (pNodeMachine->cacheType() != UIVirtualMachineItemType_CloudReal)
     808            continue;
     809        oldIDs << pNodeMachine->id();
     810    }
     811    /* Compose new set of machine IDs and map of machines: */
     812    QSet<QUuid> newIDs;
     813    QMap<QUuid, CCloudMachine> newMachines;
     814    foreach (const CCloudMachine &comMachine, pAcquiringTask->result())
     815    {
     816        QUuid uId;
     817        AssertReturnVoid(cloudMachineId(comMachine, uId));
     818        newMachines[uId] = comMachine;
     819        newIDs << uId;
     820    }
     821
     822    /* Calculate set of unregistered/registered IDs: */
     823    const QSet<QUuid> unregisteredIDs = oldIDs - newIDs;
     824    const QSet<QUuid> registeredIDs = newIDs - oldIDs;
     825    QVector<CCloudMachine> registeredMachines;
     826    foreach (const QUuid &uId, registeredIDs)
     827        registeredMachines << newMachines.value(uId);
     828
     829    /* Remove unregistered cloud VM nodes: */
     830    if (!unregisteredIDs.isEmpty())
     831        sltCloudMachinesUnregistered(pAcquiringTask->providerShortName(), pAcquiringTask->profileName(), unregisteredIDs.toList());
     832    /* Add registered cloud VM nodes: */
     833    if (!registeredMachines.isEmpty())
     834        sltCloudMachinesRegistered(pAcquiringTask->providerShortName(), pAcquiringTask->profileName(), registeredMachines);
    782835}
    783836
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r86608 r86611  
    172172                                                 const QString &strProfileName,
    173173                                                 const QUuid &uId);
     174        /** Handles cloud machine unregistering for a list of @a ids.
     175          * @param  strProviderShortName  Brings provider short name.
     176          * @param  strProfileName        Brings profile name. */
     177        virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
     178                                                  const QString &strProfileName,
     179                                                  const QList<QUuid> &ids);
    174180        /** Handles cloud machine registering for @a comMachine.
    175181          * @param  strProviderShortName  Brings provider short name.
     
    178184                                               const QString &strProfileName,
    179185                                               const CCloudMachine &comMachine);
     186        /** Handles cloud machine registering for a list of @a machines.
     187          * @param  strProviderShortName  Brings provider short name.
     188          * @param  strProfileName        Brings profile name. */
     189        virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
     190                                                const QString &strProfileName,
     191                                                const QVector<CCloudMachine> &machines);
    180192
    181193        /** Handles list cloud machines task complete signal. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r86609 r86611  
    11691169}
    11701170
     1171void UIChooserModel::sltCloudMachinesUnregistered(const QString &strProviderShortName,
     1172                                                  const QString &strProfileName,
     1173                                                  const QList<QUuid> &ids)
     1174{
     1175    /* Make sure no item with one of passed ids is selected: */
     1176    foreach (const QUuid &uId, ids)
     1177        makeSureNoItemWithCertainIdSelected(uId);
     1178
     1179    /* Call to base-class: */
     1180    UIChooserAbstractModel::sltCloudMachinesUnregistered(strProviderShortName, strProfileName, ids);
     1181
     1182    /* Rebuild tree for main root: */
     1183    buildTreeForMainRoot(true /* preserve selection */);
     1184}
     1185
    11711186void UIChooserModel::sltCloudMachineRegistered(const QString &strProviderShortName,
    11721187                                               const QString &strProfileName,
     
    11851200                                              UIChooserItemSearchFlag_Machine |
    11861201                                              UIChooserItemSearchFlag_ExactId));
     1202}
     1203
     1204void UIChooserModel::sltCloudMachinesRegistered(const QString &strProviderShortName,
     1205                                                const QString &strProfileName,
     1206                                                const QVector<CCloudMachine> &machines)
     1207{
     1208    /* Call to base-class: */
     1209    UIChooserAbstractModel::sltCloudMachinesRegistered(strProviderShortName, strProfileName, machines);
     1210
     1211    /* Rebuild tree for main root: */
     1212    buildTreeForMainRoot(true /* preserve selection */);
    11871213}
    11881214
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r86608 r86611  
    282282                                                 const QString &strProfileName,
    283283                                                 const QUuid &uId) /* override */;
     284        /** Handles cloud machine unregistering for a list of @a ids.
     285          * @param  strProviderShortName  Brings provider short name.
     286          * @param  strProfileName        Brings profile name. */
     287        virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
     288                                                  const QString &strProfileName,
     289                                                  const QList<QUuid> &ids) /* override */;
    284290        /** Handles cloud machine registering for @a comMachine.
    285291          * @param  strProviderShortName  Brings provider short name.
     
    288294                                               const QString &strProfileName,
    289295                                               const CCloudMachine &comMachine) /* override */;
     296        /** Handles cloud machine registering for a list of @a machines.
     297          * @param  strProviderShortName  Brings provider short name.
     298          * @param  strProfileName        Brings profile name. */
     299        virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
     300                                                const QString &strProfileName,
     301                                                const QVector<CCloudMachine> &machines) /* override */;
    290302
    291303        /** Handles list cloud machines task complete signal. */
Note: See TracChangeset for help on using the changeset viewer.

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