VirtualBox

Changeset 83689 in vbox


Ignore:
Timestamp:
Apr 14, 2020 1:33:57 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: A bit of cleanup for abstract model init procedure.

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

    r83682 r83689  
    6262void UIChooserAbstractModel::init()
    6363{
    64     /* Load tree: */
    65     loadTree();
    66 }
    67 
    68 void UIChooserAbstractModel::deinit()
    69 {
    70     // WORKAROUND:
    71     // Currently we are not saving group descriptors
    72     // (which reflecting group toggle-state) on-the-fly,
    73     // so for now we are additionally save group orders
    74     // when exiting application:
    75     saveGroupOrders();
    76 
    77     /* Make sure all saving steps complete: */
    78     makeSureGroupDefinitionsSaveIsFinished();
    79     makeSureGroupOrdersSaveIsFinished();
    80 
    81     /* Delete tree: */
    82     delete m_pInvisibleRootNode;
    83     m_pInvisibleRootNode = 0;
    84 }
    85 
    86 UIChooserNode *UIChooserAbstractModel::invisibleRoot() const
    87 {
    88     return m_pInvisibleRootNode;
    89 }
    90 
    91 void UIChooserAbstractModel::wipeOutEmptyGroups()
    92 {
    93     wipeOutEmptyGroupsStartingFrom(invisibleRoot());
    94 }
    95 
    96 /* static */
    97 QString UIChooserAbstractModel::uniqueGroupName(UIChooserNode *pRoot)
    98 {
    99     /* Enumerate all the group names: */
    100     QStringList groupNames;
    101     foreach (UIChooserNode *pNode, pRoot->nodes(UIChooserNodeType_Group))
    102         groupNames << pNode->name();
    103 
    104     /* Prepare reg-exp: */
    105     const QString strMinimumName = tr("New group");
    106     const QString strShortTemplate = strMinimumName;
    107     const QString strFullTemplate = strShortTemplate + QString(" (\\d+)");
    108     const QRegExp shortRegExp(strShortTemplate);
    109     const QRegExp fullRegExp(strFullTemplate);
    110 
    111     /* Search for the maximum index: */
    112     int iMinimumPossibleNumber = 0;
    113     foreach (const QString &strName, groupNames)
    114     {
    115         if (shortRegExp.exactMatch(strName))
    116             iMinimumPossibleNumber = qMax(iMinimumPossibleNumber, 2);
    117         else if (fullRegExp.exactMatch(strName))
    118             iMinimumPossibleNumber = qMax(iMinimumPossibleNumber, fullRegExp.cap(1).toInt() + 1);
    119     }
    120 
    121     /* Prepare/return result: */
    122     QString strResult = strMinimumName;
    123     if (iMinimumPossibleNumber)
    124         strResult += " " + QString::number(iMinimumPossibleNumber);
    125     return strResult;
    126 }
    127 
    128 void UIChooserAbstractModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags)
    129 {
    130     /* Make sure invisible root exists: */
    131     AssertPtrReturnVoid(invisibleRoot());
    132 
    133     /* Currently we perform the search only for machines, when this to be changed make
    134      * sure the disabled flags of the other item types are also managed correctly. */
    135 
    136     /* Reset the search first to erase the disabled flag,
    137      * this also returns a full list of all machine nodes: */
    138     const QList<UIChooserNode*> nodes = resetSearch();
    139 
    140     /* Stop here if no search conditions specified: */
    141     if (strSearchTerm.isEmpty())
    142         return;
    143 
    144     /* Search for all the nodes matching required condition: */
    145     invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults);
    146 
    147     /* Assign/reset the disabled flag for required nodes: */
    148     foreach (UIChooserNode *pNode, nodes)
    149     {
    150         if (!pNode)
    151             continue;
    152         pNode->setDisabled(!m_searchResults.contains(pNode));
    153     }
    154 }
    155 
    156 QList<UIChooserNode*> UIChooserAbstractModel::resetSearch()
    157 {
    158     /* Prepare resulting nodes: */
    159     QList<UIChooserNode*> nodes;
    160 
    161     /* Make sure invisible root exists: */
    162     AssertPtrReturn(invisibleRoot(), nodes);
    163 
    164     /* Calling UIChooserNode::searchForNodes with an empty search string
    165      * returns a list all nodes (of the whole tree) of the required type: */
    166     invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes);
    167 
    168     /* Reset the disabled flag of the nodes first: */
    169     foreach (UIChooserNode *pNode, nodes)
    170     {
    171         if (!pNode)
    172             continue;
    173         pNode->setDisabled(false);
    174     }
    175 
    176     /* Reset the search result related data: */
    177     m_searchResults.clear();
    178 
    179     /* Return  nodes: */
    180     return nodes;
    181 }
    182 
    183 QList<UIChooserNode*> UIChooserAbstractModel::searchResult() const
    184 {
    185     return m_searchResults;
    186 }
    187 
    188 void UIChooserAbstractModel::saveGroupSettings()
    189 {
    190     emit sigStartGroupSaving();
    191 }
    192 
    193 bool UIChooserAbstractModel::isGroupSavingInProgress() const
    194 {
    195     return    UIThreadGroupDefinitionSave::instance()
    196            || UIThreadGroupOrderSave::instance();
    197 }
    198 
    199 void UIChooserAbstractModel::sltMachineStateChanged(const QUuid &uMachineId, const KMachineState)
    200 {
    201     /* Update machine-nodes with passed id: */
    202     invisibleRoot()->updateAllNodes(uMachineId);
    203 }
    204 
    205 void UIChooserAbstractModel::sltMachineDataChanged(const QUuid &uMachineId)
    206 {
    207     /* Update machine-nodes with passed id: */
    208     invisibleRoot()->updateAllNodes(uMachineId);
    209 }
    210 
    211 void UIChooserAbstractModel::sltMachineRegistered(const QUuid &uMachineId, const bool fRegistered)
    212 {
    213     /* Existing VM unregistered? */
    214     if (!fRegistered)
    215     {
    216         /* Remove machine-items with passed id: */
    217         invisibleRoot()->removeAllNodes(uMachineId);
    218         /* Wipe out empty groups: */
    219         wipeOutEmptyGroups();
    220     }
    221     /* New VM registered? */
    222     else
    223     {
    224         /* Should we show this VM? */
    225         if (gEDataManager->showMachineInVirtualBoxManagerChooser(uMachineId))
    226         {
    227             /* Add new machine-item: */
    228             const CMachine comMachine = uiCommon().virtualBox().FindMachine(uMachineId.toString());
    229             addMachineIntoTheTree(comMachine, true /* make it visible */);
    230         }
    231     }
    232 }
    233 
    234 void UIChooserAbstractModel::sltSessionStateChanged(const QUuid &uMachineId, const KSessionState)
    235 {
    236     /* Update machine-nodes with passed id: */
    237     invisibleRoot()->updateAllNodes(uMachineId);
    238 }
    239 
    240 void UIChooserAbstractModel::sltSnapshotChanged(const QUuid &uMachineId, const QUuid &)
    241 {
    242     /* Update machine-nodes with passed id: */
    243     invisibleRoot()->updateAllNodes(uMachineId);
    244 }
    245 
    246 void UIChooserAbstractModel::sltReloadMachine(const QUuid &uMachineId)
    247 {
    248     /* Remove machine-items with passed id: */
    249     invisibleRoot()->removeAllNodes(uMachineId);
    250     /* Wipe out empty groups: */
    251     wipeOutEmptyGroups();
    252 
    253     /* Should we show this VM? */
    254     if (gEDataManager->showMachineInVirtualBoxManagerChooser(uMachineId))
    255     {
    256         /* Add new machine-item: */
    257         const CMachine comMachine = uiCommon().virtualBox().FindMachine(uMachineId.toString());
    258         addMachineIntoTheTree(comMachine, true /* make it visible */);
    259     }
    260 }
    261 
    262 void UIChooserAbstractModel::sltStartGroupSaving()
    263 {
    264     saveGroupDefinitions();
    265     saveGroupOrders();
    266 }
    267 
    268 #ifdef VBOX_GUI_WITH_CLOUD_VMS
    269 void UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete(UITask *pTask)
    270 {
    271     /* Skip unrelated tasks: */
    272     if (!pTask || pTask->type() != UITask::Type_CloudAcquireInstances)
    273         return;
    274 
    275     /* Cast task to corresponding sub-class: */
    276     UITaskCloudListMachines *pAcquiringTask = static_cast<UITaskCloudListMachines*>(pTask);
    277 
    278     /* Make sure there were no errors: */
    279     if (!pAcquiringTask->errorInfo().isNull())
    280         return msgCenter().cannotAcquireCloudInstanceList(pAcquiringTask->errorInfo());
    281 
    282     /* Acquire parent node and make sure it has children: */
    283     /// @todo rework task to bring parent by id instead of pointer
    284     ///       to object which maybe deleted to this moment already
    285     UIChooserNode *pParentNode = pAcquiringTask->parentNode();
    286     AssertPtrReturnVoid(pParentNode);
    287     AssertReturnVoid(pParentNode->hasNodes());
    288 
    289     /* Make sure this node have first child: */
    290     UIChooserNode *pFirstChildNode = pParentNode->nodes().first();
    291     AssertPtrReturnVoid(pFirstChildNode);
    292 
    293     /* Which is machine node and has cache of fake-cloud-item type: */
    294     UIChooserNodeMachine *pFirstChildNodeMachine = pFirstChildNode->toMachineNode();
    295     AssertPtrReturnVoid(pFirstChildNodeMachine);
    296     AssertPtrReturnVoid(pFirstChildNodeMachine->cache());
    297     AssertReturnVoid(pFirstChildNodeMachine->cache()->itemType() == UIVirtualMachineItem::ItemType_CloudFake);
    298 
    299     /* And if we have at least one cloud machine: */
    300     const QVector<CCloudMachine> machines = pAcquiringTask->result();
    301     if (!machines.isEmpty())
    302     {
    303         /* Remove the "Empty" node: */
    304         delete pFirstChildNodeMachine;
    305 
    306         /* Add real cloud VM nodes: */
    307         int iPosition = 0;
    308         foreach (const CCloudMachine &comCloudMachine, machines)
    309             new UIChooserNodeMachine(pParentNode,
    310                                      false /* favorite */,
    311                                      iPosition++ /* position */,
    312                                      comCloudMachine);
    313     }
    314     else
    315     {
    316         /* Otherwise toggle and update "Empty" node: */
    317         UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFirstChildNodeMachine->cache()->toCloud();
    318         AssertPtrReturnVoid(pFakeCloudMachineItem);
    319         pFakeCloudMachineItem->setFakeCloudItemState(UIVirtualMachineItemCloud::FakeCloudItemState_Done);
    320         pFakeCloudMachineItem->recache();
    321     }
    322 }
    323 #endif /* VBOX_GUI_WITH_CLOUD_VMS */
    324 
    325 void UIChooserAbstractModel::sltHandleCloudMachineStateChange()
    326 {
    327     UIVirtualMachineItem *pCache = qobject_cast<UIVirtualMachineItem*>(sender());
    328     AssertPtrReturnVoid(pCache);
    329     emit sigCloudMachineStateChange(pCache->id());
    330 }
    331 
    332 void UIChooserAbstractModel::sltGroupDefinitionsSaveComplete()
    333 {
    334     makeSureGroupDefinitionsSaveIsFinished();
    335     emit sigGroupSavingStateChanged();
    336 }
    337 
    338 void UIChooserAbstractModel::sltGroupOrdersSaveComplete()
    339 {
    340     makeSureGroupOrdersSaveIsFinished();
    341     emit sigGroupSavingStateChanged();
    342 }
    343 
    344 void UIChooserAbstractModel::prepare()
    345 {
    346     prepareConnections();
    347 }
    348 
    349 void UIChooserAbstractModel::prepareConnections()
    350 {
    351     /* Setup parent connections: */
    352     connect(this, &UIChooserAbstractModel::sigGroupSavingStateChanged,
    353             m_pParent, &UIChooser::sigGroupSavingStateChanged);
    354 
    355     /* Setup global connections: */
    356     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
    357             this, &UIChooserAbstractModel::sltMachineStateChanged);
    358     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange,
    359             this, &UIChooserAbstractModel::sltMachineDataChanged);
    360     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineRegistered,
    361             this, &UIChooserAbstractModel::sltMachineRegistered);
    362     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSessionStateChange,
    363             this, &UIChooserAbstractModel::sltSessionStateChanged);
    364     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotTake,
    365             this, &UIChooserAbstractModel::sltSnapshotChanged);
    366     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotDelete,
    367             this, &UIChooserAbstractModel::sltSnapshotChanged);
    368     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotChange,
    369             this, &UIChooserAbstractModel::sltSnapshotChanged);
    370     connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotRestore,
    371             this, &UIChooserAbstractModel::sltSnapshotChanged);
    372 
    373     /* Setup group saving connections: */
    374     connect(this, &UIChooserAbstractModel::sigStartGroupSaving,
    375             this, &UIChooserAbstractModel::sltStartGroupSaving,
    376             Qt::QueuedConnection);
    377 }
    378 
    379 void UIChooserAbstractModel::loadTree()
    380 {
    38164    /* Create invisible root group node: */
    38265    m_pInvisibleRootNode = new UIChooserNodeGroup(0 /* parent */,
     
    38972    {
    39073        /* Link root to this model: */
    391         m_pInvisibleRootNode->setModel(this);
     74        invisibleRoot()->setModel(this);
    39275
    39376        /* Create global node: */
    394         new UIChooserNodeGlobal(m_pInvisibleRootNode,
    395                                 isGlobalNodeFavorite(m_pInvisibleRootNode),
     77        new UIChooserNodeGlobal(invisibleRoot(),
     78                                isGlobalNodeFavorite(invisibleRoot()),
    39679                                0 /* position */,
    39780                                QString() /* tip */);
     
    446129                        /* Add provider group node: */
    447130                        UIChooserNodeGroup *pProviderNode =
    448                             new UIChooserNodeGroup(m_pInvisibleRootNode,
     131                            new UIChooserNodeGroup(invisibleRoot(),
    449132                                                   false /* favorite */,
    450                                                    getDesiredNodePosition(m_pInvisibleRootNode,
     133                                                   getDesiredNodePosition(invisibleRoot(),
    451134                                                                          UIChooserNodeType_Group,
    452135                                                                          strProviderName),
     
    512195}
    513196
     197void UIChooserAbstractModel::deinit()
     198{
     199    // WORKAROUND:
     200    // Currently we are not saving group descriptors
     201    // (which reflecting group toggle-state) on-the-fly,
     202    // so for now we are additionally save group orders
     203    // when exiting application:
     204    saveGroupOrders();
     205
     206    /* Make sure all saving steps complete: */
     207    makeSureGroupDefinitionsSaveIsFinished();
     208    makeSureGroupOrdersSaveIsFinished();
     209
     210    /* Delete tree: */
     211    delete m_pInvisibleRootNode;
     212    m_pInvisibleRootNode = 0;
     213}
     214
     215void UIChooserAbstractModel::wipeOutEmptyGroups()
     216{
     217    wipeOutEmptyGroupsStartingFrom(invisibleRoot());
     218}
     219
     220/* static */
     221QString UIChooserAbstractModel::uniqueGroupName(UIChooserNode *pRoot)
     222{
     223    /* Enumerate all the group names: */
     224    QStringList groupNames;
     225    foreach (UIChooserNode *pNode, pRoot->nodes(UIChooserNodeType_Group))
     226        groupNames << pNode->name();
     227
     228    /* Prepare reg-exp: */
     229    const QString strMinimumName = tr("New group");
     230    const QString strShortTemplate = strMinimumName;
     231    const QString strFullTemplate = strShortTemplate + QString(" (\\d+)");
     232    const QRegExp shortRegExp(strShortTemplate);
     233    const QRegExp fullRegExp(strFullTemplate);
     234
     235    /* Search for the maximum index: */
     236    int iMinimumPossibleNumber = 0;
     237    foreach (const QString &strName, groupNames)
     238    {
     239        if (shortRegExp.exactMatch(strName))
     240            iMinimumPossibleNumber = qMax(iMinimumPossibleNumber, 2);
     241        else if (fullRegExp.exactMatch(strName))
     242            iMinimumPossibleNumber = qMax(iMinimumPossibleNumber, fullRegExp.cap(1).toInt() + 1);
     243    }
     244
     245    /* Prepare/return result: */
     246    QString strResult = strMinimumName;
     247    if (iMinimumPossibleNumber)
     248        strResult += " " + QString::number(iMinimumPossibleNumber);
     249    return strResult;
     250}
     251
     252void UIChooserAbstractModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags)
     253{
     254    /* Make sure invisible root exists: */
     255    AssertPtrReturnVoid(invisibleRoot());
     256
     257    /* Currently we perform the search only for machines, when this to be changed make
     258     * sure the disabled flags of the other item types are also managed correctly. */
     259
     260    /* Reset the search first to erase the disabled flag,
     261     * this also returns a full list of all machine nodes: */
     262    const QList<UIChooserNode*> nodes = resetSearch();
     263
     264    /* Stop here if no search conditions specified: */
     265    if (strSearchTerm.isEmpty())
     266        return;
     267
     268    /* Search for all the nodes matching required condition: */
     269    invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults);
     270
     271    /* Assign/reset the disabled flag for required nodes: */
     272    foreach (UIChooserNode *pNode, nodes)
     273    {
     274        if (!pNode)
     275            continue;
     276        pNode->setDisabled(!m_searchResults.contains(pNode));
     277    }
     278}
     279
     280QList<UIChooserNode*> UIChooserAbstractModel::resetSearch()
     281{
     282    /* Prepare resulting nodes: */
     283    QList<UIChooserNode*> nodes;
     284
     285    /* Make sure invisible root exists: */
     286    AssertPtrReturn(invisibleRoot(), nodes);
     287
     288    /* Calling UIChooserNode::searchForNodes with an empty search string
     289     * returns a list all nodes (of the whole tree) of the required type: */
     290    invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes);
     291
     292    /* Reset the disabled flag of the nodes first: */
     293    foreach (UIChooserNode *pNode, nodes)
     294    {
     295        if (!pNode)
     296            continue;
     297        pNode->setDisabled(false);
     298    }
     299
     300    /* Reset the search result related data: */
     301    m_searchResults.clear();
     302
     303    /* Return  nodes: */
     304    return nodes;
     305}
     306
     307QList<UIChooserNode*> UIChooserAbstractModel::searchResult() const
     308{
     309    return m_searchResults;
     310}
     311
     312void UIChooserAbstractModel::saveGroupSettings()
     313{
     314    emit sigStartGroupSaving();
     315}
     316
     317bool UIChooserAbstractModel::isGroupSavingInProgress() const
     318{
     319    return    UIThreadGroupDefinitionSave::instance()
     320           || UIThreadGroupOrderSave::instance();
     321}
     322
     323void UIChooserAbstractModel::sltMachineStateChanged(const QUuid &uMachineId, const KMachineState)
     324{
     325    /* Update machine-nodes with passed id: */
     326    invisibleRoot()->updateAllNodes(uMachineId);
     327}
     328
     329void UIChooserAbstractModel::sltMachineDataChanged(const QUuid &uMachineId)
     330{
     331    /* Update machine-nodes with passed id: */
     332    invisibleRoot()->updateAllNodes(uMachineId);
     333}
     334
     335void UIChooserAbstractModel::sltMachineRegistered(const QUuid &uMachineId, const bool fRegistered)
     336{
     337    /* Existing VM unregistered? */
     338    if (!fRegistered)
     339    {
     340        /* Remove machine-items with passed id: */
     341        invisibleRoot()->removeAllNodes(uMachineId);
     342        /* Wipe out empty groups: */
     343        wipeOutEmptyGroups();
     344    }
     345    /* New VM registered? */
     346    else
     347    {
     348        /* Should we show this VM? */
     349        if (gEDataManager->showMachineInVirtualBoxManagerChooser(uMachineId))
     350        {
     351            /* Add new machine-item: */
     352            const CMachine comMachine = uiCommon().virtualBox().FindMachine(uMachineId.toString());
     353            addMachineIntoTheTree(comMachine, true /* make it visible */);
     354        }
     355    }
     356}
     357
     358void UIChooserAbstractModel::sltSessionStateChanged(const QUuid &uMachineId, const KSessionState)
     359{
     360    /* Update machine-nodes with passed id: */
     361    invisibleRoot()->updateAllNodes(uMachineId);
     362}
     363
     364void UIChooserAbstractModel::sltSnapshotChanged(const QUuid &uMachineId, const QUuid &)
     365{
     366    /* Update machine-nodes with passed id: */
     367    invisibleRoot()->updateAllNodes(uMachineId);
     368}
     369
     370void UIChooserAbstractModel::sltReloadMachine(const QUuid &uMachineId)
     371{
     372    /* Remove machine-items with passed id: */
     373    invisibleRoot()->removeAllNodes(uMachineId);
     374    /* Wipe out empty groups: */
     375    wipeOutEmptyGroups();
     376
     377    /* Should we show this VM? */
     378    if (gEDataManager->showMachineInVirtualBoxManagerChooser(uMachineId))
     379    {
     380        /* Add new machine-item: */
     381        const CMachine comMachine = uiCommon().virtualBox().FindMachine(uMachineId.toString());
     382        addMachineIntoTheTree(comMachine, true /* make it visible */);
     383    }
     384}
     385
     386void UIChooserAbstractModel::sltStartGroupSaving()
     387{
     388    saveGroupDefinitions();
     389    saveGroupOrders();
     390}
     391
     392#ifdef VBOX_GUI_WITH_CLOUD_VMS
     393void UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete(UITask *pTask)
     394{
     395    /* Skip unrelated tasks: */
     396    if (!pTask || pTask->type() != UITask::Type_CloudAcquireInstances)
     397        return;
     398
     399    /* Cast task to corresponding sub-class: */
     400    UITaskCloudListMachines *pAcquiringTask = static_cast<UITaskCloudListMachines*>(pTask);
     401
     402    /* Make sure there were no errors: */
     403    if (!pAcquiringTask->errorInfo().isNull())
     404        return msgCenter().cannotAcquireCloudInstanceList(pAcquiringTask->errorInfo());
     405
     406    /* Acquire parent node and make sure it has children: */
     407    /// @todo rework task to bring parent by id instead of pointer
     408    ///       to object which maybe deleted to this moment already
     409    UIChooserNode *pParentNode = pAcquiringTask->parentNode();
     410    AssertPtrReturnVoid(pParentNode);
     411    AssertReturnVoid(pParentNode->hasNodes());
     412
     413    /* Make sure this node have first child: */
     414    UIChooserNode *pFirstChildNode = pParentNode->nodes().first();
     415    AssertPtrReturnVoid(pFirstChildNode);
     416
     417    /* Which is machine node and has cache of fake-cloud-item type: */
     418    UIChooserNodeMachine *pFirstChildNodeMachine = pFirstChildNode->toMachineNode();
     419    AssertPtrReturnVoid(pFirstChildNodeMachine);
     420    AssertPtrReturnVoid(pFirstChildNodeMachine->cache());
     421    AssertReturnVoid(pFirstChildNodeMachine->cache()->itemType() == UIVirtualMachineItem::ItemType_CloudFake);
     422
     423    /* And if we have at least one cloud machine: */
     424    const QVector<CCloudMachine> machines = pAcquiringTask->result();
     425    if (!machines.isEmpty())
     426    {
     427        /* Remove the "Empty" node: */
     428        delete pFirstChildNodeMachine;
     429
     430        /* Add real cloud VM nodes: */
     431        int iPosition = 0;
     432        foreach (const CCloudMachine &comCloudMachine, machines)
     433            new UIChooserNodeMachine(pParentNode,
     434                                     false /* favorite */,
     435                                     iPosition++ /* position */,
     436                                     comCloudMachine);
     437    }
     438    else
     439    {
     440        /* Otherwise toggle and update "Empty" node: */
     441        UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFirstChildNodeMachine->cache()->toCloud();
     442        AssertPtrReturnVoid(pFakeCloudMachineItem);
     443        pFakeCloudMachineItem->setFakeCloudItemState(UIVirtualMachineItemCloud::FakeCloudItemState_Done);
     444        pFakeCloudMachineItem->recache();
     445    }
     446}
     447#endif /* VBOX_GUI_WITH_CLOUD_VMS */
     448
     449void UIChooserAbstractModel::sltHandleCloudMachineStateChange()
     450{
     451    UIVirtualMachineItem *pCache = qobject_cast<UIVirtualMachineItem*>(sender());
     452    AssertPtrReturnVoid(pCache);
     453    emit sigCloudMachineStateChange(pCache->id());
     454}
     455
     456void UIChooserAbstractModel::sltGroupDefinitionsSaveComplete()
     457{
     458    makeSureGroupDefinitionsSaveIsFinished();
     459    emit sigGroupSavingStateChanged();
     460}
     461
     462void UIChooserAbstractModel::sltGroupOrdersSaveComplete()
     463{
     464    makeSureGroupOrdersSaveIsFinished();
     465    emit sigGroupSavingStateChanged();
     466}
     467
     468void UIChooserAbstractModel::prepare()
     469{
     470    prepareConnections();
     471}
     472
     473void UIChooserAbstractModel::prepareConnections()
     474{
     475    /* Setup parent connections: */
     476    connect(this, &UIChooserAbstractModel::sigGroupSavingStateChanged,
     477            m_pParent, &UIChooser::sigGroupSavingStateChanged);
     478
     479    /* Setup global connections: */
     480    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange,
     481            this, &UIChooserAbstractModel::sltMachineStateChanged);
     482    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange,
     483            this, &UIChooserAbstractModel::sltMachineDataChanged);
     484    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineRegistered,
     485            this, &UIChooserAbstractModel::sltMachineRegistered);
     486    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSessionStateChange,
     487            this, &UIChooserAbstractModel::sltSessionStateChanged);
     488    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotTake,
     489            this, &UIChooserAbstractModel::sltSnapshotChanged);
     490    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotDelete,
     491            this, &UIChooserAbstractModel::sltSnapshotChanged);
     492    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotChange,
     493            this, &UIChooserAbstractModel::sltSnapshotChanged);
     494    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigSnapshotRestore,
     495            this, &UIChooserAbstractModel::sltSnapshotChanged);
     496
     497    /* Setup group saving connections: */
     498    connect(this, &UIChooserAbstractModel::sigStartGroupSaving,
     499            this, &UIChooserAbstractModel::sltStartGroupSaving,
     500            Qt::QueuedConnection);
     501}
     502
    514503void UIChooserAbstractModel::addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible /* = false */)
    515504{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r83672 r83689  
    8080      * @{ */
    8181        /** Returns invisible root node instance. */
    82         UIChooserNode *invisibleRoot() const;
     82        UIChooserNode *invisibleRoot() const { return m_pInvisibleRootNode; }
    8383
    8484        /** Wipes out empty groups. */
     
    174174    /** @name Children stuff.
    175175      * @{ */
    176         /** Loads tree. */
    177         void loadTree();
    178176        /** Adds machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
    179177        void addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
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