VirtualBox

Changeset 86795 in vbox


Ignore:
Timestamp:
Nov 3, 2020 12:29:09 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Now that's the heavy one, switching cloud profile update logic from UITask to UIProgressTask; That's more flexible since we are able to control the IProgress interface directly in such case.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r86783 r86795  
    580580        src/hostnetwork/UIHostNetworkManager.h \
    581581        src/manager/UIErrorPane.h \
     582        src/manager/UIProgressTaskReadCloudMachineList.h \
    582583        src/manager/UITaskCloudGetSettingsForm.h \
    583         src/manager/UITaskCloudListMachines.h \
    584584        src/manager/UIToolPaneGlobal.h \
    585585        src/manager/UIToolPaneMachine.h \
     
    10601060        src/manager/UICloudEntityKey.cpp \
    10611061        src/manager/UIErrorPane.cpp \
     1062        src/manager/UIProgressTaskReadCloudMachineList.cpp \
    10621063        src/manager/UITaskCloudGetSettingsForm.cpp \
    1063         src/manager/UITaskCloudListMachines.cpp \
    10641064        src/manager/UIToolPaneGlobal.cpp \
    10651065        src/manager/UIToolPaneMachine.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIProgressTaskReadCloudMachineList.cpp

    r86794 r86795  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UITaskCloudListMachines class implementation.
     3 * VBox Qt GUI - UIProgressTaskReadCloudMachineList class implementation.
    44 */
    55
     
    1818/* GUI includes: */
    1919#include "UICloudNetworkingStuff.h"
    20 #include "UITaskCloudListMachines.h"
    21 
    22 /* COM includes: */
    23 #include "CCloudClient.h"
     20#include "UIMessageCenter.h"
     21#include "UIProgressTaskReadCloudMachineList.h"
    2422
    2523
    26 UITaskCloudListMachines::UITaskCloudListMachines(const QString &strProviderShortName,
    27                                                  const QString &strProfileName,
    28                                                  bool fWithRefresh)
    29     : UITask(Type_CloudListMachines)
    30     , m_strProviderShortName(strProviderShortName)
    31     , m_strProfileName(strProfileName)
     24UIProgressTaskReadCloudMachineList::UIProgressTaskReadCloudMachineList(QObject *pParent,
     25                                                                       const UICloudEntityKey &guiCloudProfileKey,
     26                                                                       bool fWithRefresh)
     27    : UIProgressTask(pParent)
     28    , m_guiCloudProfileKey(guiCloudProfileKey)
    3229    , m_fWithRefresh(fWithRefresh)
    3330{
    3431}
    3532
    36 QVector<CCloudMachine> UITaskCloudListMachines::result() const
     33UICloudEntityKey UIProgressTaskReadCloudMachineList::cloudProfileKey() const
    3734{
    38     m_mutex.lock();
    39     const QVector<CCloudMachine> resultVector = m_result;
    40     m_mutex.unlock();
    41     return resultVector;
     35    return m_guiCloudProfileKey;
    4236}
    4337
    44 QString UITaskCloudListMachines::errorInfo() const
     38QVector<CCloudMachine> UIProgressTaskReadCloudMachineList::machines() const
    4539{
    46     m_mutex.lock();
    47     QString strErrorInfo = m_strErrorInfo;
    48     m_mutex.unlock();
    49     return strErrorInfo;
     40    return m_machines;
    5041}
    5142
    52 void UITaskCloudListMachines::run()
     43CProgress UIProgressTaskReadCloudMachineList::createProgress()
    5344{
    54     m_mutex.lock();
    55     CCloudClient comCloudClient = cloudClientByName(m_strProviderShortName, m_strProfileName, m_strErrorInfo);
    56     if (m_strErrorInfo.isNull())
    57         m_result = m_fWithRefresh
    58                  ? listCloudMachines(comCloudClient, m_strErrorInfo)
    59                  : listCloudMachineStubs(comCloudClient, m_strErrorInfo);
    60     m_mutex.unlock();
     45    /* Create cloud client: */
     46    m_comCloudClient = cloudClientByName(m_guiCloudProfileKey.m_strProviderShortName,
     47                                         m_guiCloudProfileKey.m_strProfileName);
     48
     49    /* Prepare resulting progress-wrapper: */
     50    CProgress comResult;
     51
     52    /* Initialize actual progress-wrapper: */
     53    if (m_fWithRefresh)
     54    {
     55        CProgress comProgress = m_comCloudClient.ReadCloudMachineList();
     56        if (!m_comCloudClient.isOk())
     57            msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
     58        else
     59            comResult = comProgress;
     60    }
     61    else
     62    {
     63        CProgress comProgress = m_comCloudClient.ReadCloudMachineStubList();
     64        if (!m_comCloudClient.isOk())
     65            msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
     66        else
     67            comResult = comProgress;
     68    }
     69
     70    /* Return progress-wrapper in any case: */
     71    return comResult;
    6172}
     73
     74void UIProgressTaskReadCloudMachineList::handleProgressFinished(CProgress &comProgress)
     75{
     76    /* Handle progress-wrapper errors: */
     77    if (!comProgress.GetCanceled() && (!comProgress.isOk() || comProgress.GetResultCode() != 0))
     78        msgCenter().cannotAcquireCloudClientParameter(comProgress);
     79    {
     80        /* Fill the result: */
     81        m_machines = m_fWithRefresh ? m_comCloudClient.GetCloudMachineList() : m_comCloudClient.GetCloudMachineStubList();
     82        if (!m_comCloudClient.isOk())
     83            msgCenter().cannotAcquireCloudClientParameter(m_comCloudClient);
     84    }
     85}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIProgressTaskReadCloudMachineList.h

    r86794 r86795  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UITaskCloudListMachines class declaration.
     3 * VBox Qt GUI - UIProgressTaskReadCloudMachineList class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_manager_UITaskCloudListMachines_h
    19 #define FEQT_INCLUDED_SRC_manager_UITaskCloudListMachines_h
     18#ifndef FEQT_INCLUDED_SRC_manager_UIProgressTaskReadCloudMachineList_h
     19#define FEQT_INCLUDED_SRC_manager_UIProgressTaskReadCloudMachineList_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
    2222#endif
    2323
    24 /* Qt includes: */
    25 #include <QMutex>
    26 
    2724/* GUI includes: */
    28 #include "UITask.h"
     25#include "UICloudEntityKey.h"
     26#include "UIProgressTask.h"
    2927
    3028/* COM includes: */
    3129#include "COMEnums.h"
     30#include "CCloudClient.h"
    3231#include "CCloudMachine.h"
    3332
    34 /** UITask extension used to list cloud machines. */
    35 class UITaskCloudListMachines : public UITask
     33/** UIProgressTask extension performing read cloud machine list task. */
     34class UIProgressTaskReadCloudMachineList : public UIProgressTask
    3635{
    3736    Q_OBJECT;
     
    3938public:
    4039
    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       * @param  fWithRefresh          Brings whether the task includes refresh. */
    45     UITaskCloudListMachines(const QString &strProviderShortName,
    46                             const QString &strProfileName,
    47                             bool fWithRefresh);
     40    /** Constructs read cloud machine list task passing @a pParent to the base-class.
     41      * @param  guiCloudProfileKey  Brings cloud profile description key.
     42      * @param  fWithRefresh        Brings whether cloud machine should be refreshed as well. */
     43    UIProgressTaskReadCloudMachineList(QObject *pParent, const UICloudEntityKey &guiCloudProfileKey, bool fWithRefresh);
    4844
    49     /** Returns provider short name. */
    50     QString providerShortName() const { return m_strProviderShortName; }
    51     /** Returns profile name. */
    52     QString profileName() const { return m_strProfileName; }
    53     /** Returns whether the task includes refresh. */
    54     bool withRefresh() const { return m_fWithRefresh; }
     45    /** Returns cloud profile description key. */
     46    UICloudEntityKey cloudProfileKey() const;
    5547
    56     /** Returns error info. */
    57     QString errorInfo() const;
    58 
    59     /** Returns the task result. */
    60     QVector<CCloudMachine> result() const;
     48    /** Returns resulting cloud machine-wrapper vector. */
     49    QVector<CCloudMachine> machines() const;
    6150
    6251protected:
    6352
    64     /** Contains the task body. */
    65     virtual void run() /* override */;
     53    /** Creates and returns started progress-wrapper required to init UIProgressObject. */
     54    virtual CProgress createProgress() /* override */;
     55    /** Handles finished @a comProgress wrapper. */
     56    virtual void handleProgressFinished(CProgress &comProgress) /* override */;
    6657
    6758private:
    6859
    69     /** Holds the mutex to access result. */
    70     mutable QMutex  m_mutex;
     60    /** Holds the cloud profile description key. */
     61    UICloudEntityKey  m_guiCloudProfileKey;
     62    /** Holds whether cloud machine should be refreshed as well. */
     63    bool              m_fWithRefresh;
    7164
    72     /** Holds the provider short name. */
    73     const QString  m_strProviderShortName;
    74     /** Holds the profile name. */
    75     const QString  m_strProfileName;
    76     /** Holds whether the task includes refresh. */
    77     const bool     m_fWithRefresh;
    78 
    79     /** Holds the error info. */
    80     QString  m_strErrorInfo;
    81 
    82     /** Holds the task result. */
    83     QVector<CCloudMachine>  m_result;
     65    /** Holds the cloud client-wrapper. */
     66    CCloudClient            m_comCloudClient;
     67    /** Holds the resulting cloud machine-wrapper vector. */
     68    QVector<CCloudMachine>  m_machines;
    8469};
    8570
    86 #endif /* !FEQT_INCLUDED_SRC_manager_UITaskCloudListMachines_h */
     71#endif /* !FEQT_INCLUDED_SRC_manager_UIProgressTaskReadCloudMachineList_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp

    r86788 r86795  
    3030#include "UIExtraDataManager.h"
    3131#include "UIMessageCenter.h"
    32 #include "UITaskCloudListMachines.h"
    33 #include "UIThreadPool.h"
     32#include "UIProgressTaskReadCloudMachineList.h"
    3433#include "UIVirtualBoxEventHandler.h"
    3534#include "UIVirtualMachineItemCloud.h"
     
    590589void UIChooserAbstractModel::insertCloudEntityKey(const UICloudEntityKey &key)
    591590{
    592 //    printf("Cloud entity with key %s being updated..\n", key.toString().toUtf8().constData());
     591    printf("Cloud entity with key %s being updated..\n", key.toString().toUtf8().constData());
    593592    m_cloudEntityKeysBeingUpdated.insert(key);
    594593    emit sigCloudUpdateStateChanged();
     
    597596void UIChooserAbstractModel::removeCloudEntityKey(const UICloudEntityKey &key)
    598597{
    599 //    printf("Cloud entity with key %s is updated!\n", key.toString().toUtf8().constData());
     598    printf("Cloud entity with key %s is updated!\n", key.toString().toUtf8().constData());
    600599    m_cloudEntityKeysBeingUpdated.remove(key);
    601600    emit sigCloudUpdateStateChanged();
     
    848847}
    849848
    850 void UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete(UITask *pTask)
    851 {
    852     /* Skip unrelated tasks: */
    853     AssertPtrReturnVoid(pTask);
    854     if (pTask->type() != UITask::Type_CloudListMachines)
     849void UIChooserAbstractModel::sltHandleReadCloudMachineListTaskComplete()
     850{
     851    /* Parse task result: */
     852    UIProgressTaskReadCloudMachineList *pSender = qobject_cast<UIProgressTaskReadCloudMachineList*>(sender());
     853    AssertPtrReturnVoid(pSender);
     854    const UICloudEntityKey guiCloudProfileKey = pSender->cloudProfileKey();
     855    const QVector<CCloudMachine> machines = pSender->machines();
     856
     857    /* Delete task: */
     858    delete pSender;
     859
     860    /* Check whether this task was expected: */
     861    if (!containsCloudEntityKey(guiCloudProfileKey))
    855862        return;
    856     UITaskCloudListMachines *pAcquiringTask = qobject_cast<UITaskCloudListMachines*>(pTask);
    857     AssertPtrReturnVoid(pAcquiringTask);
    858     const QString strProviderShortName = pAcquiringTask->providerShortName();
    859     const QString strProfileName = pAcquiringTask->profileName();
    860863
    861864    /* Search for profile node: */
    862     UIChooserNode *pProfileNode = searchProfileNode(strProviderShortName, strProfileName);
     865    UIChooserNode *pProfileNode = searchProfileNode(guiCloudProfileKey.m_strProviderShortName,
     866                                                    guiCloudProfileKey.m_strProfileName);
    863867    if (!pProfileNode)
    864868        return;
     
    878882    QSet<QUuid> newIDs;
    879883    QMap<QUuid, CCloudMachine> newMachines;
    880     foreach (const CCloudMachine &comMachine, pAcquiringTask->result())
     884    foreach (const CCloudMachine &comMachine, machines)
    881885    {
    882886        QUuid uId;
     
    895899    /* Remove unregistered cloud VM nodes: */
    896900    if (!unregisteredIDs.isEmpty())
    897         sltCloudMachinesUnregistered(strProviderShortName, strProfileName, unregisteredIDs.toList());
     901        sltCloudMachinesUnregistered(guiCloudProfileKey.m_strProviderShortName,
     902                                     guiCloudProfileKey.m_strProfileName,
     903                                     unregisteredIDs.toList());
    898904    /* Add registered cloud VM nodes: */
    899905    if (!registeredMachines.isEmpty())
    900         sltCloudMachinesRegistered(strProviderShortName, strProfileName, registeredMachines);
     906        sltCloudMachinesRegistered(guiCloudProfileKey.m_strProviderShortName,
     907                                   guiCloudProfileKey.m_strProfileName,
     908                                   registeredMachines);
    901909    /* If we changed nothing and have nothing currently: */
    902910    if (unregisteredIDs.isEmpty() && newIDs.isEmpty())
     
    910918
    911919    /* Remove cloud entity key from the list of keys currently being updated: */
    912     const UICloudEntityKey guiCloudEntityKey = UICloudEntityKey(strProviderShortName, strProfileName);
    913     removeCloudEntityKey(guiCloudEntityKey);
     920    removeCloudEntityKey(guiCloudProfileKey);
    914921}
    915922
     
    922929void UIChooserAbstractModel::createReadCloudMachineListTask(const UICloudEntityKey &guiCloudProfileKey, bool fWithRefresh)
    923930{
    924     /* Create list cloud machines task: */
    925     UITaskCloudListMachines *pTask = new UITaskCloudListMachines(guiCloudProfileKey.m_strProviderShortName,
    926                                                                  guiCloudProfileKey.m_strProfileName,
    927                                                                  fWithRefresh);
    928     AssertPtrReturnVoid(pTask);
    929     uiCommon().threadPoolCloud()->enqueueTask(pTask);
     931    /* Do not create task if already registered: */
     932    if (containsCloudEntityKey(guiCloudProfileKey))
     933        return;
     934
     935    /* Create task: */
     936    UIProgressTaskReadCloudMachineList *pTask = new UIProgressTaskReadCloudMachineList(this,
     937                                                                                       guiCloudProfileKey,
     938                                                                                       fWithRefresh);
     939    if (pTask)
     940    {
     941        /* Insert cloud profile key into a list of keys currently being updated: */
     942        insertCloudEntityKey(guiCloudProfileKey);
     943
     944        /* Connect and start it finally: */
     945        connect(pTask, &UIProgressTaskReadCloudMachineList::sigProgressFinished,
     946                this, &UIChooserAbstractModel::sltHandleReadCloudMachineListTaskComplete);
     947        pTask->start();
     948    }
    930949}
    931950
     
    943962void UIChooserAbstractModel::prepareConnections()
    944963{
    945     /* Cloud thread-pool connections: */
    946     connect(uiCommon().threadPoolCloud(), &UIThreadPool::sigTaskComplete,
    947             this, &UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete);
    948 
    949964    /* Cloud VM registration connections: */
    950965    connect(&uiCommon(), &UICommon::sigCloudMachineUnregistered,
     
    9891004}
    9901005
     1006void UIChooserAbstractModel::cleanupTasks()
     1007{
     1008    foreach (UIProgressTaskReadCloudMachineList *pTask, findChildren<UIProgressTaskReadCloudMachineList*>())
     1009        delete pTask;
     1010}
     1011
    9911012void UIChooserAbstractModel::cleanupConnections()
    9921013{
    993     /* Cloud thread-pool connections: */
    994     disconnect(uiCommon().threadPoolCloud(), &UIThreadPool::sigTaskComplete,
    995                this, &UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete);
    996 
    9971014    /* Cloud VM registration connections: */
    9981015    disconnect(&uiCommon(), &UICommon::sigCloudMachineUnregistered,
     
    10381055void UIChooserAbstractModel::cleanup()
    10391056{
     1057    cleanupTasks();
    10401058    cleanupConnections();
    10411059}
     
    11781196            createCloudMachineNode(pProfileNode, UIFakeCloudVirtualMachineItemState_Loading);
    11791197
    1180             /* Insert cloud profile key into a list of keys currently being updated: */
     1198            /* Create read cloud machine list task: */
    11811199            const UICloudEntityKey guiCloudProfileKey = UICloudEntityKey(strProviderShortName, strProfileName);
    1182             insertCloudEntityKey(guiCloudProfileKey);
    1183 
    1184             /* Create list cloud machines task: */
    11851200            createReadCloudMachineListTask(guiCloudProfileKey, true /* with refresh? */);
    11861201        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r86788 r86795  
    3737class UIChooser;
    3838class UIChooserNode;
    39 class UITask;
    4039class CCloudMachine;
    4140class CMachine;
     
    217216                                                const QVector<CCloudMachine> &machines);
    218217
    219         /** Handles list cloud machines task complete signal. */
    220         virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask);
     218        /** Handles read cloud machine list task complete signal. */
     219        virtual void sltHandleReadCloudMachineListTaskComplete();
    221220
    222221        /** Handles Cloud Profile Manager cumulative change. */
     
    250249        void prepareConnections();
    251250
     251        /** Cleanups tasks. */
     252        void cleanupTasks();
    252253        /** Cleanups connections. */
    253254        void cleanupConnections();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r86787 r86795  
    4444#include "UIMessageCenter.h"
    4545#include "UIModalWindowManager.h"
    46 #include "UITaskCloudListMachines.h"
    47 #include "UIThreadPool.h"
    4846#include "UIVirtualBoxManagerWidget.h"
    4947#include "UIVirtualMachineItemCloud.h"
     
    940938                AssertPtrReturnVoid(pParentOfParent);
    941939
    942                 /* Insert cloud profile key into a list of keys currently being updated: */
     940                /* Create read cloud machine list task: */
    943941                const UICloudEntityKey guiCloudProfileKey = UICloudEntityKey(pParentOfParent->name(), pParent->name());
    944                 insertCloudEntityKey(guiCloudProfileKey);
    945 
    946                 /* Create list cloud machines task: */
    947942                createReadCloudMachineListTask(guiCloudProfileKey, true /* with refresh? */);
    948943
     
    12191214}
    12201215
    1221 void UIChooserModel::sltHandleCloudListMachinesTaskComplete(UITask *pTask)
    1222 {
    1223     /* Skip unrelated tasks: */
    1224     if (!pTask || pTask->type() != UITask::Type_CloudListMachines)
    1225         return;
    1226 
     1216void UIChooserModel::sltHandleReadCloudMachineListTaskComplete()
     1217{
    12271218    /* Call to base-class: */
    1228     UIChooserAbstractModel::sltHandleCloudListMachinesTaskComplete(pTask);
     1219    UIChooserAbstractModel::sltHandleReadCloudMachineListTaskComplete();
    12291220
    12301221    /* Restart cloud profile update timer: */
     
    13571348    /* Restart List Cloud Machines task for selected profile keys: */
    13581349    foreach (const UICloudEntityKey &guiCloudProfileKey, selectedCloudProfileKeys)
    1359     {
    1360         /* Skip cloud profile keys already being updated: */
    1361         if (containsCloudEntityKey(guiCloudProfileKey))
    1362             continue;
    1363         insertCloudEntityKey(guiCloudProfileKey);
    1364 
    1365         /* Create a task for particular cloud entity key: */
    13661350        createReadCloudMachineListTask(guiCloudProfileKey, false /* with refresh? */);
    1367     }
    13681351}
    13691352
     
    19521935    /* Restart List Cloud Machines task for required profile keys: */
    19531936    foreach (const UICloudEntityKey &guiCloudProfileKey, changedCloudEntityKeys)
    1954     {
    1955         /* Skip cloud profile keys already being updated: */
    1956         if (containsCloudEntityKey(guiCloudProfileKey))
    1957             continue;
    1958         insertCloudEntityKey(guiCloudProfileKey);
    1959 
    1960         /* Create a task for particular cloud entity key: */
    19611937        createReadCloudMachineListTask(guiCloudProfileKey, false /* with refresh? */);
    1962     }
    19631938}
    19641939
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r86705 r86795  
    304304                                                const QVector<CCloudMachine> &machines) /* override */;
    305305
    306         /** Handles list cloud machines task complete signal. */
    307         virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask) /* override */;
     306        /** Handles read cloud machine list task complete signal. */
     307        virtual void sltHandleReadCloudMachineListTaskComplete() /* override */;
    308308
    309309        /** Handles Cloud Profile Manager cumulative changes. */
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