VirtualBox

Changeset 86207 in vbox


Ignore:
Timestamp:
Sep 21, 2020 7:49:36 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: Rework UIVirtualMachineItemCloud to create cloud machine refresh progress and corresponding handler directly in the GUI thread instead of another thread executing UITaskCloudRefreshMachineInfo; Creating QObjects in other than the GUI thread seems to be restricted in latest Qt versions.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 deleted
3 edited

Legend:

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

    r86154 r86207  
    582582        src/manager/UITaskCloudGetSettingsForm.h \
    583583        src/manager/UITaskCloudListMachines.h \
    584         src/manager/UITaskCloudRefreshMachineInfo.h \
    585584        src/manager/UIToolPaneGlobal.h \
    586585        src/manager/UIToolPaneMachine.h \
     
    10561055        src/manager/UITaskCloudGetSettingsForm.cpp \
    10571056        src/manager/UITaskCloudListMachines.cpp \
    1058         src/manager/UITaskCloudRefreshMachineInfo.cpp \
    10591057        src/manager/UIToolPaneGlobal.cpp \
    10601058        src/manager/UIToolPaneMachine.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r86201 r86207  
    2727#include "UIIconPool.h"
    2828#include "UIMessageCenter.h"
    29 #include "UITaskCloudRefreshMachineInfo.h"
     29#include "UIProgressDialog.h"
    3030#include "UIThreadPool.h"
    3131#include "UIVirtualMachineItemCloud.h"
     
    4040    , m_enmMachineState(KCloudMachineState_Invalid)
    4141    , m_enmFakeCloudItemState(enmState)
    42     , m_pTask(0)
    43     , m_pEventLoop(0)
    4442{
    4543    recache();
     
    5149    , m_enmMachineState(KCloudMachineState_Invalid)
    5250    , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable)
    53     , m_pTask(0)
    54     , m_pEventLoop(0)
    5551{
    5652    recache();
     
    7571void UIVirtualMachineItemCloud::updateInfoAsync(bool fDelayed)
    7672{
    77     QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceInfoTask()));
     73    QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltRefreshCloudMachineInfo()));
    7874}
    7975
    8076void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished()
    8177{
    82     /* Make sure task is really created: */
    83     if (!m_pTask)
    84         return;
    85 
    86     /* Cancel the task: */
    87     m_pTask->cancel();
    88 
    89     /* We are creating a locally-scoped event-loop object,
    90      * but holding a pointer to it for a control needs: */
    91     QEventLoop eventLoop;
    92     m_pEventLoop = &eventLoop;
    93 
    94     /* Guard ourself for the case
    95      * we self-destroyed in our event-loop: */
    96     QPointer<UIVirtualMachineItemCloud> guard = this;
    97 
    98     /* Start the blocking event-loop: */
    99     eventLoop.exec();
    100 
    101     /* Event-loop object unblocked,
    102      * Are we still valid? */
    103     if (guard.isNull())
    104         return;
    105 
    106     /* Cleanup the pointer finally: */
    107     m_pEventLoop = 0;
     78    /* Cancel the progress-handler if any: */
     79    if (m_pProgressHandler)
     80        m_pProgressHandler->cancel();
    10881}
    10982
     
    307280}
    308281
    309 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceInfoTask()
     282void UIVirtualMachineItemCloud::sltRefreshCloudMachineInfo()
    310283{
    311284    /* Make sure item is of real cloud type and is initialized: */
    312285    AssertReturnVoid(itemType() == UIVirtualMachineItemType_CloudReal);
    313286
    314     /* Create and start task to refresh info async way only if there is no task yet: */
    315     if (!m_pTask)
     287    /* Ignore refresh request if there is progress already: */
     288    if (m_pProgressHandler)
     289        return;
     290
     291    /* Create 'Refresh' progress: */
     292    m_comProgress = m_comCloudMachine.Refresh();
     293    if (!m_comCloudMachine.isOk())
     294        msgCenter().cannotAcquireCloudMachineParameter(m_comCloudMachine);
     295    else
    316296    {
    317         m_pTask = new UITaskCloudRefreshMachineInfo(m_comCloudMachine);
    318         connect(uiCommon().threadPoolCloud(), &UIThreadPool::sigTaskComplete,
    319                 this, &UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone);
    320         uiCommon().threadPoolCloud()->enqueueTask(m_pTask);
     297        /* Prepare 'Refresh' progress handler: */
     298        m_pProgressHandler = new UIProgress(m_comProgress, this);
     299        if (m_pProgressHandler)
     300            connect(m_pProgressHandler, &UIProgress::sigProgressComplete,
     301                    this, &UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone);
    321302    }
    322303}
    323304
    324 void UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone(UITask *pTask)
    325 {
    326     /* Skip unrelated tasks: */
    327     if (!m_pTask || pTask != m_pTask)
    328         return;
    329 
    330     /* Mark our task handled: */
    331     m_pTask = 0;
     305void UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone()
     306{
     307    /* If not canceled => check progress result: */
     308    if (   !m_comProgress.GetCanceled()
     309        && (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0))
     310            msgCenter().cannotAcquireCloudMachineParameter(m_comProgress);
    332311
    333312    /* Recache: */
    334313    recache();
    335314
    336     /* Exit from the event-loop if there is any: */
    337     if (m_pEventLoop)
    338         m_pEventLoop->exit();
    339     /* Notify listeners otherwise: */
    340     else
     315    /* If not canceled => notify listeners: */
     316    if (!m_comProgress.GetCanceled())
    341317        emit sigStateChange();
    342 }
     318
     319    /* Cleanup the handler and the progress: */
     320    delete m_pProgressHandler;
     321    m_pProgressHandler = 0;
     322    m_comProgress = CProgress();
     323}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r86201 r86207  
    2222#endif
    2323
     24/* Qt includes: */
     25#include <QPointer>
     26
    2427/* GUI includes: */
    2528#include "UIVirtualMachineItem.h"
     
    2831#include "COMEnums.h"
    2932#include "CCloudMachine.h"
     33#include "CProgress.h"
    3034
    3135/* Forward declarations: */
    32 class UITask;
    33 class UITaskCloudRefreshMachineInfo;
     36class UIProgress;
    3437
    3538/** UIVirtualMachineItem sub-class used as cloud Virtual Machine item interface. */
     
    123126private slots:
    124127
    125         /** Create cloud VM info acquire task. */
    126         void sltCreateGetCloudInstanceInfoTask();
    127         /** Handles signal about cloud VM info refresh task is done. */
    128         void sltHandleRefreshCloudMachineInfoDone(UITask *pTask);
     128        /** Starts cloud VM info refresh progress. */
     129        void sltRefreshCloudMachineInfo();
     130        /** Handles signal about cloud VM info refresh progress is done. */
     131        void sltHandleRefreshCloudMachineInfoDone();
    129132
    130133private:
     
    146149        QString                             m_strFakeCloudItemErrorMessage;
    147150
    148         /** Holds the info acquire task instance. */
    149         UITaskCloudRefreshMachineInfo *m_pTask;
    150         /** Holds the task waiting loop instance. */
    151         QEventLoop                    *m_pEventLoop;
     151        /** Holds the machine refresh progress object instance. */
     152        CProgress             m_comProgress;
     153        /** Holds the machine refresh progress handler instance. */
     154        QPointer<UIProgress>  m_pProgressHandler;
    152155    /** @} */
    153156};
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