Index: trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp	(revision 84596)
+++ trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp	(revision 84598)
@@ -82,5 +82,5 @@
 
     /** Contains a thread task to be executed. */
-    void run();
+    virtual void run() /* override */;
 
     /** Holds the singleton instance. */
@@ -339,5 +339,5 @@
     /* For every particular group definition: */
     foreach (const QString &strId, m_lists.keys())
-        gEDataManager->setSelectorWindowGroupsDefinitions(strId, m_lists[strId]);
+        gEDataManager->setSelectorWindowGroupsDefinitions(strId, m_lists.value(strId));
 
     /* Notify listeners about completeness: */
@@ -525,5 +525,5 @@
     /* Search for all the machine nodes with passed ID: */
     QList<UIChooserNode*> machineNodes;
-    invisibleRoot()->searchForNodes(toOldStyleUuid(uId),
+    invisibleRoot()->searchForNodes(uId.toString(),
                                     UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId,
                                     machineNodes);
@@ -660,7 +660,7 @@
     {
         /* Global nodes: */
-        case UIChooserNodeDataPrefixType_Global:        return "n";
+        case UIChooserNodeDataPrefixType_Global:   return "n";
         /* Machine nodes: */
-        case UIChooserNodeDataPrefixType_Machine:       return "m";
+        case UIChooserNodeDataPrefixType_Machine:  return "m";
         /* Group nodes: */
         case UIChooserNodeDataPrefixType_Local:    return "g";
@@ -695,4 +695,23 @@
 }
 
+void UIChooserAbstractModel::sltHandleCloudMachineStateChange()
+{
+    UIVirtualMachineItem *pCache = qobject_cast<UIVirtualMachineItem*>(sender());
+    AssertPtrReturnVoid(pCache);
+    emit sigCloudMachineStateChange(pCache->id());
+}
+
+void UIChooserAbstractModel::sltGroupSettingsSaveComplete()
+{
+    makeSureGroupSettingsSaveIsFinished();
+    emit sigGroupSavingStateChanged();
+}
+
+void UIChooserAbstractModel::sltGroupDefinitionsSaveComplete()
+{
+    makeSureGroupDefinitionsSaveIsFinished();
+    emit sigGroupSavingStateChanged();
+}
+
 void UIChooserAbstractModel::sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState)
 {
@@ -733,12 +752,10 @@
                                                        const QUuid &uMachineId, const bool fRegistered)
 {
-    /* Compose full group name: */
-    const QString strGroupName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
-    /* Search for corresponding profile node: */
+    /* Search for profile node: */
+    const QString strProfileNodeName = QString("/%1/%2").arg(strProviderShortName, strProfileName);
     QList<UIChooserNode*> profileNodes;
-    invisibleRoot()->searchForNodes(strGroupName, UIChooserItemSearchFlag_CloudProfile | UIChooserItemSearchFlag_ExactId, profileNodes);
-    /* Acquire corresponding profile node: */
+    invisibleRoot()->searchForNodes(strProfileNodeName, UIChooserItemSearchFlag_CloudProfile | UIChooserItemSearchFlag_ExactId, profileNodes);
     AssertReturnVoid(!profileNodes.isEmpty());
-    UIChooserNodeGroup *pProfileNode = profileNodes.first()->toGroupNode();
+    UIChooserNode *pProfileNode = profileNodes.first();
     AssertPtrReturnVoid(pProfileNode);
 
@@ -747,5 +764,5 @@
     {
         /* Remove machine-items with passed id: */
-        invisibleRoot()->removeAllNodes(uMachineId);
+        pProfileNode->removeAllNodes(uMachineId);
 
         /* If there are no items left: */
@@ -766,12 +783,11 @@
         /* Add new machine-item: */
         const CCloudMachine comMachine = cloudMachineById(strProviderShortName, strProfileName, uMachineId);
-        addCloudMachineIntoTheTree(strGroupName, comMachine, true /* make it visible */);
+        addCloudMachineIntoTheTree(strProfileNodeName, comMachine, true /* make it visible */);
 
         /* Search for possible fake node: */
         QList<UIChooserNode*> fakeNodes;
-        pProfileNode->searchForNodes(toOldStyleUuid(QUuid()), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
+        pProfileNode->searchForNodes(QUuid().toString(), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
         /* Delete fake node if present: */
-        if (!fakeNodes.isEmpty())
-            delete fakeNodes.first();
+        delete fakeNodes.value(0);
     }
 }
@@ -824,15 +840,13 @@
     QList<UIChooserNode*> profileNodes;
     invisibleRoot()->searchForNodes(strProfileNodeName, UIChooserItemSearchFlag_CloudProfile | UIChooserItemSearchFlag_ExactId, profileNodes);
-    UIChooserNode *pProfileNode = profileNodes.value(0);
+    AssertReturnVoid(!profileNodes.isEmpty());
+    UIChooserNode *pProfileNode = profileNodes.first();
     AssertPtrReturnVoid(pProfileNode);
 
     /* Search for fake node: */
     QList<UIChooserNode*> fakeNodes;
-    pProfileNode->searchForNodes(toOldStyleUuid(QUuid()), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
+    pProfileNode->searchForNodes(QUuid().toString(), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
     UIChooserNode *pFakeNode = fakeNodes.value(0);
     AssertPtrReturnVoid(pFakeNode);
-    UIChooserNodeMachine *pFakeMachineNode = pFakeNode->toMachineNode();
-    AssertPtrReturnVoid(pFakeMachineNode);
-    AssertReturnVoid(pFakeMachineNode->cacheType() == UIVirtualMachineItemType_CloudFake);
 
     /* And if we have at least one cloud machine: */
@@ -841,5 +855,5 @@
     {
         /* Remove fake node: */
-        delete pFakeMachineNode;
+        delete pFakeNode;
 
         /* Add real cloud VM nodes: */
@@ -850,4 +864,6 @@
     {
         /* Otherwise toggle and update "Empty" node: */
+        UIChooserNodeMachine *pFakeMachineNode = pFakeNode->toMachineNode();
+        AssertReturnVoid(pFakeMachineNode && pFakeMachineNode->cacheType() == UIVirtualMachineItemType_CloudFake);
         UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFakeMachineNode->cache()->toCloud();
         AssertPtrReturnVoid(pFakeCloudMachineItem);
@@ -855,23 +871,4 @@
         pFakeCloudMachineItem->setFakeCloudItemErrorMessage(pAcquiringTask->errorInfo());
     }
-}
-
-void UIChooserAbstractModel::sltHandleCloudMachineStateChange()
-{
-    UIVirtualMachineItem *pCache = qobject_cast<UIVirtualMachineItem*>(sender());
-    AssertPtrReturnVoid(pCache);
-    emit sigCloudMachineStateChange(pCache->id());
-}
-
-void UIChooserAbstractModel::sltGroupSettingsSaveComplete()
-{
-    makeSureGroupSettingsSaveIsFinished();
-    emit sigGroupSavingStateChanged();
-}
-
-void UIChooserAbstractModel::sltGroupDefinitionsSaveComplete()
-{
-    makeSureGroupDefinitionsSaveIsFinished();
-    emit sigGroupSavingStateChanged();
 }
 
@@ -929,4 +926,5 @@
     LogRelFlow(("UIChooserModel: Loading local VM with ID={%s}...\n",
                 toOldStyleUuid(uId).toUtf8().constData()));
+
     /* Is that machine accessible? */
     if (comMachine.GetAccessible())
@@ -978,4 +976,5 @@
     LogRelFlow(("UIChooserModel: Loading cloud VM with ID={%s}...\n",
                 toOldStyleUuid(uId).toUtf8().constData()));
+
     /* Acquire VM name: */
     QString strName = comMachine.GetName();
@@ -1145,16 +1144,12 @@
 void UIChooserAbstractModel::wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParent)
 {
-    /* Cleanup all the group-items recursively first: */
+    /* Cleanup all the group children recursively first: */
     foreach (UIChooserNode *pNode, pParent->nodes(UIChooserNodeType_Group))
         wipeOutEmptyGroupsStartingFrom(pNode);
-    /* If parent has no nodes: */
-    if (!pParent->hasNodes())
-    {
-        /* If that is non-root item: */
-        if (!pParent->isRoot())
-        {
-            /* Delete parent node and item: */
-            delete pParent;
-        }
+    /* If parent isn't root and has no nodes: */
+    if (!pParent->isRoot() && !pParent->hasNodes())
+    {
+        /* Delete parent node and item: */
+        delete pParent;
     }
 }
@@ -1169,5 +1164,5 @@
     const int iNewNodeDefinitionPosition = getDefinedNodePosition(pParentNode, enmDataType, strName);
 
-    /* If some position wanted: */
+    /* If some position defined: */
     if (iNewNodeDefinitionPosition != -1)
     {
@@ -1219,6 +1214,6 @@
                     break;
             }
+            /* If some position defined: */
             const int iNodeDefinitionPosition = getDefinedNodePosition(pParentNode, enmNodeDataType, strDefinitionName);
-            /* If some position wanted: */
             if (iNodeDefinitionPosition != -1)
             {
@@ -1323,6 +1318,5 @@
     if (!comMachine.GetAccessible())
     {
-        AssertPtrReturnVoid(pNode);
-        AssertReturnVoid(pNode->cacheType() == UIVirtualMachineItemType_CloudReal);
+        AssertReturnVoid(pNode && pNode->cacheType() == UIVirtualMachineItemType_CloudReal);
         pNode->cache()->toCloud()->updateInfoAsync(false /* delayed? */);
     }
