VirtualBox

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


Ignore:
Timestamp:
Apr 22, 2020 11:27:59 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Add/remove fake profile nodes when (un)registering cloud machines to make sure profile is never empty.

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

Legend:

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

    r83900 r83920  
    409409                                                       const QUuid &uMachineId, const bool fRegistered)
    410410{
     411    /* Compose full group name: */
     412    const QString strGroupName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
     413
    411414    /* Existing VM unregistered? */
    412415    if (!fRegistered)
     
    414417        /* Remove machine-items with passed id: */
    415418        invisibleRoot()->removeAllNodes(uMachineId);
    416         /// @todo make sure there is fake item if no real item exist, never wipe out empty groups ..
    417419    }
    418420    /* New VM registered? */
     
    420422    {
    421423        /* Add new machine-item: */
    422         const QString strGroupName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
    423424        const CCloudMachine comMachine = cloudMachineById(strProviderShortName, strProfileName, uMachineId);
    424425        addCloudMachineIntoTheTree(strGroupName, comMachine, true /* make it visible */);
    425         /// @todo make sure there is no fake item if at least one real item exists ..
     426    }
     427
     428    /* Search for corresponding profile node: */
     429    QList<UIChooserNode*> profileNodes;
     430    invisibleRoot()->searchForNodes(strGroupName, UIChooserItemSearchFlag_Group | UIChooserItemSearchFlag_ExactId, profileNodes);
     431    if (!profileNodes.isEmpty())
     432    {
     433        /* Acquire corresponding profile node: */
     434        UIChooserNodeGroup *pProfileNode = profileNodes.first()->toGroupNode();
     435        if (pProfileNode)
     436        {
     437            /* Add fake cloud VM item if necessary: */
     438            if (!fRegistered && pProfileNode->nodes(UIChooserNodeType_Machine).isEmpty())
     439            {
     440                UIChooserNodeMachine *pFakeNode = new UIChooserNodeMachine(pProfileNode /* parent */,
     441                                                                           false /* favorite */,
     442                                                                           0 /* position */);
     443                pFakeNode->toMachineNode()->cache()->toCloud()->setFakeCloudItemState(UIVirtualMachineItemCloud::FakeCloudItemState_Done);
     444                pFakeNode->toMachineNode()->cache()->toCloud()->recache();
     445            }
     446            /* Remove fake cloud VM item otherwise: */
     447            else if (fRegistered && !pProfileNode->nodes(UIChooserNodeType_Machine).isEmpty())
     448            {
     449                /* Search for corresponding fake node: */
     450                QList<UIChooserNode*> fakeNodes;
     451                pProfileNode->searchForNodes(toOldStyleUuid(QUuid()), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
     452                if (!fakeNodes.isEmpty())
     453                    delete fakeNodes.first();
     454            }
     455        }
    426456    }
    427457}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r83906 r83920  
    686686    if (!fRegistered)
    687687    {
    688         /* Update tree for main root: */
    689         updateTreeForMainRoot();
     688        /* Rebuild tree for main root: */
     689        buildTreeForMainRoot();
    690690    }
    691691    /* New VM registered? */
     
    17351735        // Hehey! Now we have to remove deleted VM nodes and then update tree for the main root node
    17361736        // ourselves cause there is no corresponding event yet. So we are calling actual handler to do that.
    1737         sltCloudMachineRegistered(QString() /* provider name */,
    1738                                   QString() /* profile name */,
     1737        UIChooserItem *pItem = root()->searchForItem(uId.toString(),
     1738                                                     UIChooserItemSearchFlag_Machine |
     1739                                                     UIChooserItemSearchFlag_ExactId);
     1740        AssertPtrReturnVoid(pItem);
     1741        AssertReturnVoid(pItem->node()->toMachineNode()->cache()->itemType() == UIVirtualMachineItem::ItemType_CloudReal);
     1742        AssertPtrReturnVoid(pItem->parentItem());
     1743        AssertPtrReturnVoid(pItem->parentItem()->parentItem());
     1744        const QString strProviderShortName = pItem->parentItem()->parentItem()->name();
     1745        const QString strProfileName = pItem->parentItem()->name();
     1746        sltCloudMachineRegistered(strProviderShortName,
     1747                                  strProfileName,
    17391748                                  uId /* machine ID */,
    17401749                                  false /* registered? */);
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