VirtualBox

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


Ignore:
Timestamp:
Apr 28, 2020 4:42:35 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137637
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Rework profile group loading to use common cloud stuff; This also required UITaskCloudListMachines to be adjusted accordingly.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
3 edited

Legend:

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

    r83691 r84058  
    2020#include "UITaskCloudListMachines.h"
    2121
     22/* COM includes: */
     23#include "CCloudClient.h"
    2224
    23 UITaskCloudListMachines::UITaskCloudListMachines(const CCloudClient &comCloudClient, UIChooserNode *pParentNode)
     25
     26UITaskCloudListMachines::UITaskCloudListMachines(const QString &strProviderShortName, const QString &strProfileName)
    2427    : UITask(Type_CloudListMachines)
    25     , m_comCloudClient(comCloudClient)
    26     , m_pParentNode(pParentNode)
     28    , m_strProviderShortName(strProviderShortName)
     29    , m_strProfileName(strProfileName)
    2730{
    2831}
     
    4750{
    4851    m_mutex.lock();
    49     m_result = listCloudMachines(m_comCloudClient, m_strErrorInfo);
     52    CCloudClient comCloudClient = cloudClientByName(m_strProviderShortName, m_strProfileName, m_strErrorInfo);
     53    if (m_strErrorInfo.isNull())
     54        m_result = listCloudMachines(comCloudClient, m_strErrorInfo);
    5055    m_mutex.unlock();
    5156}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UITaskCloudListMachines.h

    r83659 r84058  
    3030/* COM includes: */
    3131#include "COMEnums.h"
    32 #include "CCloudClient.h"
    3332#include "CCloudMachine.h"
    34 
    35 /* Forward declaratiuons: */
    36 class UIChooserNode;
    3733
    3834/** UITask extension used to list cloud machines. */
     
    4339public:
    4440
    45     /** Constructs update task taking @a comCloudClient and @a pParentNode as data.
    46       * @param  comCloudClient  Brings the cloud client object.
    47       * @param  m_pParentNode   Brings the parent node reference. */
    48     UITaskCloudListMachines(const CCloudClient &comCloudClient, UIChooserNode *pParentNode);
     41    /** Constructs task taking @a strProviderShortName and @a strProfileName as data.
     42      * @param  strProviderShortName  Brings the provider short name.
     43      * @param  strProfileName        Brings the profile name. */
     44    UITaskCloudListMachines(const QString &strProviderShortName, const QString &strProfileName);
    4945
    50     /** Returns cloud client object. */
    51     CCloudClient cloudClient() const { return m_comCloudClient; }
    52     /** Returns parent node reference. */
    53     UIChooserNode *parentNode() const { return m_pParentNode; }
     46    /** Returns provider short name. */
     47    QString providerShortName() const { return m_strProviderShortName; }
     48    /** Returns profile name. */
     49    QString profileName() const { return m_strProfileName; }
    5450
    5551    /** Returns error info. */
     
    6965    mutable QMutex  m_mutex;
    7066
    71     /** Holds the cloud client object. */
    72     CCloudClient   m_comCloudClient;
    73     /** Holds the parent node reference. */
    74     UIChooserNode *m_pParentNode;
     67    /** Holds the provider short name. */
     68    const QString  m_strProviderShortName;
     69    /** Holds the profile name. */
     70    const QString  m_strProfileName;
    7571
    7672    /** Holds the error info. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp

    r83946 r84058  
    125125        /* Add cloud providers/profiles: */
    126126        LogRelFlow(("UIChooserAbstractModel: Loading cloud providers/profiles...\n"));
    127         /* Acquire cloud provider manager: */
    128         const CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
    129         /* Show error message if necessary: */
    130         if (!comVBox.isOk())
    131             msgCenter().cannotAcquireCloudProviderManager(comVBox);
    132         else
     127        /* Iterate through existing providers: */
     128        foreach (CCloudProvider comCloudProvider, listCloudProviders())
    133129        {
    134             /* Acquire existing providers: */
    135             const QVector<CCloudProvider> providers = comCloudProviderManager.GetProviders();
    136             /* Show error message if necessary: */
    137             if (!comCloudProviderManager.isOk())
    138                 msgCenter().cannotAcquireCloudProviderManagerParameter(comCloudProviderManager);
    139             else
     130            /* Skip if we have nothing to populate: */
     131            if (comCloudProvider.isNull())
     132                continue;
     133
     134            /* Acquire provider short name: */
     135            QString strProviderShortName;
     136            if (!cloudProviderShortName(comCloudProvider, strProviderShortName))
     137                continue;
     138
     139            /* Add provider group node: */
     140            UIChooserNodeGroup *pProviderNode =
     141                new UIChooserNodeGroup(invisibleRoot() /* parent */,
     142                                       false /* favorite */,
     143                                       getDesiredNodePosition(invisibleRoot(),
     144                                                              UIChooserNodeType_Group,
     145                                                              strProviderShortName),
     146                                       strProviderShortName,
     147                                       UIChooserNodeGroupType_Provider,
     148                                       shouldGroupNodeBeOpened(invisibleRoot(),
     149                                                               strProviderShortName));
     150
     151            /* Iterate through provider's profiles: */
     152            foreach (CCloudProfile comCloudProfile, listCloudProfiles(comCloudProvider))
    140153            {
    141                 /* Iterate through existing providers: */
    142                 foreach (CCloudProvider comCloudProvider, providers)
     154                /* Skip if we have nothing to populate: */
     155                if (comCloudProfile.isNull())
     156                    continue;
     157
     158                /* Acquire profile name: */
     159                QString strProfileName;
     160                if (!cloudProfileName(comCloudProfile, strProfileName))
     161                    continue;
     162
     163                /* Add profile sub-group node: */
     164                UIChooserNodeGroup *pProfileNode =
     165                    new UIChooserNodeGroup(pProviderNode /* parent */,
     166                                           false /* favorite */,
     167                                           getDesiredNodePosition(pProviderNode,
     168                                                                  UIChooserNodeType_Group,
     169                                                                  strProfileName),
     170                                           strProfileName,
     171                                           UIChooserNodeGroupType_Profile,
     172                                           shouldGroupNodeBeOpened(pProviderNode,
     173                                                                   strProfileName));
     174
     175                /* Add fake cloud VM item: */
     176                new UIChooserNodeMachine(pProfileNode /* parent */,
     177                                         false /* favorite */,
     178                                         0 /* position */);
     179
     180                /* Create list cloud machines task: */
     181                UITaskCloudListMachines *pTask = new UITaskCloudListMachines(strProviderShortName,
     182                                                                             strProfileName);
     183                if (pTask)
    143184                {
    144                     /* Skip if we have nothing to populate (file missing?): */
    145                     if (comCloudProvider.isNull())
    146                         continue;
    147 
    148                     /* Get profile names: */
    149                     const QVector<QString> profileNames = comCloudProvider.GetProfileNames();
    150                     /* Show error message if necessary: */
    151                     if (!comCloudProvider.isOk())
    152                     {
    153                         msgCenter().cannotAcquireCloudProviderParameter(comCloudProvider);
    154                         continue;
    155                     }
    156 
    157                     /* Skip if we have nothing to populate (profiles missing?): */
    158                     if (profileNames.isEmpty())
    159                         continue;
    160 
    161                     /* Get provider name: */
    162                     const QString strProviderName = comCloudProvider.GetShortName();
    163                     /* Show error message if necessary: */
    164                     if (!comCloudProvider.isOk())
    165                     {
    166                         msgCenter().cannotAcquireCloudProviderParameter(comCloudProvider);
    167                         continue;
    168                     }
    169 
    170                     /* Add provider group node: */
    171                     UIChooserNodeGroup *pProviderNode =
    172                         new UIChooserNodeGroup(invisibleRoot() /* parent */,
    173                                                false /* favorite */,
    174                                                getDesiredNodePosition(invisibleRoot(),
    175                                                                       UIChooserNodeType_Group,
    176                                                                       strProviderName),
    177                                                strProviderName,
    178                                                UIChooserNodeGroupType_Provider,
    179                                                shouldGroupNodeBeOpened(invisibleRoot(),
    180                                                                        strProviderName));
    181 
    182                     /* Iterate through provider's profile names: */
    183                     foreach (const QString &strProfileName, profileNames)
    184                     {
    185                         /* Skip if we have nothing to show (wtf happened?): */
    186                         if (strProfileName.isEmpty())
    187                             continue;
    188 
    189                         /* Acquire cloud profile: */
    190                         CCloudProfile comCloudProfile = comCloudProvider.GetProfileByName(strProfileName);
    191                         /* Show error message if necessary: */
    192                         if (!comCloudProvider.isOk())
    193                         {
    194                             msgCenter().cannotFindCloudProfile(comCloudProvider, strProfileName);
    195                             continue;
    196                         }
    197 
    198                         /* Create cloud client: */
    199                         CCloudClient comCloudClient = comCloudProfile.CreateCloudClient();
    200                         /* Show error message if necessary: */
    201                         if (!comCloudProfile.isOk())
    202                         {
    203                             msgCenter().cannotCreateCloudClient(comCloudProfile);
    204                             continue;
    205                         }
    206 
    207                         /* Add profile sub-group node: */
    208                         UIChooserNodeGroup *pProfileNode =
    209                             new UIChooserNodeGroup(pProviderNode /* parent */,
    210                                                    false /* favorite */,
    211                                                    getDesiredNodePosition(pProviderNode,
    212                                                                           UIChooserNodeType_Group,
    213                                                                           strProfileName),
    214                                                    strProfileName,
    215                                                    UIChooserNodeGroupType_Profile,
    216                                                    shouldGroupNodeBeOpened(pProviderNode,
    217                                                                            strProfileName));
    218                         /* Add fake cloud VM item: */
    219                         new UIChooserNodeMachine(pProfileNode /* parent */,
    220                                                  false /* favorite */,
    221                                                  0 /* position */);
    222 
    223                         /* Create cloud list machines task: */
    224                         UITaskCloudListMachines *pTask = new UITaskCloudListMachines(comCloudClient,
    225                                                                                      pProfileNode);
    226                         if (pTask)
    227                         {
    228                             connect(uiCommon().threadPoolCloud(), &UIThreadPool::sigTaskComplete,
    229                                     this, &UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete);
    230                             uiCommon().threadPoolCloud()->enqueueTask(pTask);
    231                         }
    232                     }
     185                    connect(uiCommon().threadPoolCloud(), &UIThreadPool::sigTaskComplete,
     186                            this, &UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete);
     187                    uiCommon().threadPoolCloud()->enqueueTask(pTask);
    233188                }
    234189            }
     
    502457        return msgCenter().cannotAcquireCloudInstanceList(pAcquiringTask->errorInfo());
    503458
    504     /* Acquire parent node and make sure it has children: */
    505     /// @todo rework task to bring parent by id instead of pointer
    506     ///       to object which maybe deleted to this moment already
    507     UIChooserNode *pParentNode = pAcquiringTask->parentNode();
    508     AssertPtrReturnVoid(pParentNode);
    509     AssertReturnVoid(pParentNode->hasNodes());
    510 
    511     /* Make sure this node have first child: */
    512     UIChooserNode *pFirstChildNode = pParentNode->nodes().first();
    513     AssertPtrReturnVoid(pFirstChildNode);
    514 
    515     /* Which is machine node and has cache of fake-cloud-item type: */
    516     UIChooserNodeMachine *pFirstChildNodeMachine = pFirstChildNode->toMachineNode();
    517     AssertPtrReturnVoid(pFirstChildNodeMachine);
    518     AssertReturnVoid(pFirstChildNodeMachine->cacheType() == UIVirtualMachineItemType_CloudFake);
     459    /* Search for profile node: */
     460    const QString strProfileNodeName = QString("/%1/%2").arg(pAcquiringTask->providerShortName(), pAcquiringTask->profileName());
     461    QList<UIChooserNode*> profileNodes;
     462    invisibleRoot()->searchForNodes(strProfileNodeName, UIChooserItemSearchFlag_Group | UIChooserItemSearchFlag_ExactId, profileNodes);
     463    UIChooserNode *pProfileNode = profileNodes.value(0);
     464    AssertPtrReturnVoid(pProfileNode);
     465
     466    /* Search for fake node: */
     467    QList<UIChooserNode*> fakeNodes;
     468    pProfileNode->searchForNodes(toOldStyleUuid(QUuid()), UIChooserItemSearchFlag_Machine | UIChooserItemSearchFlag_ExactId, fakeNodes);
     469    UIChooserNode *pFakeNode = fakeNodes.value(0);
     470    AssertPtrReturnVoid(pFakeNode);
     471    UIChooserNodeMachine *pFakeMachineNode = pFakeNode->toMachineNode();
     472    AssertPtrReturnVoid(pFakeMachineNode);
     473    AssertReturnVoid(pFakeMachineNode->cacheType() == UIVirtualMachineItemType_CloudFake);
    519474
    520475    /* And if we have at least one cloud machine: */
     
    522477    if (!machines.isEmpty())
    523478    {
    524         /* Remove the "Empty" node: */
    525         delete pFirstChildNodeMachine;
     479        /* Remove fake node: */
     480        delete pFakeMachineNode;
    526481
    527482        /* Add real cloud VM nodes: */
    528483        foreach (const CCloudMachine &comCloudMachine, machines)
    529             createCloudMachineNode(pParentNode, comCloudMachine);
     484            createCloudMachineNode(pProfileNode, comCloudMachine);
    530485    }
    531486    else
    532487    {
    533488        /* Otherwise toggle and update "Empty" node: */
    534         UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFirstChildNodeMachine->cache()->toCloud();
     489        UIVirtualMachineItemCloud *pFakeCloudMachineItem = pFakeMachineNode->cache()->toCloud();
    535490        AssertPtrReturnVoid(pFakeCloudMachineItem);
    536491        pFakeCloudMachineItem->setFakeCloudItemState(UIFakeCloudVirtualMachineItemState_Done);
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