VirtualBox

Ignore:
Timestamp:
Oct 30, 2020 5:48:02 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141170
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Rework UIVirtualMachineItemCloud to use UIProgressTask stuff introuduced in r141169.

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

Legend:

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

    r86773 r86774  
    941941        src/hostnetwork/UIHostNetworkManager.cpp \
    942942        src/manager/UIVirtualBoxManager.cpp \
     943        src/manager/UIVirtualMachineItemCloud.cpp \
    943944        src/manager/UIWelcomePane.cpp \
    944945        src/manager/chooser/UIChooserAbstractModel.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r86772 r86774  
    2727#include "UIIconPool.h"
    2828#include "UIMessageCenter.h"
    29 #include "UIProgressObject.h"
     29#include "UIProgressTask.h"
    3030#include "UIThreadPool.h"
    3131#include "UIVirtualMachineItemCloud.h"
     
    3535#include "CVirtualBoxErrorInfo.h"
    3636
     37
     38/** UIProgressTask extension performing cloud machine refresh task. */
     39class UIProgressTaskRefreshCloudMachine : public UIProgressTask
     40{
     41    Q_OBJECT;
     42
     43public:
     44
     45    /** Constructs @a comCloudMachine refresh task passing @a pParent to the base-class. */
     46    UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine);
     47
     48protected:
     49
     50    /** Creates and returns started progress-wrapper required to init UIProgressObject. */
     51    virtual CProgress createProgress() /* override */;
     52    /** Handles finished @a comProgress wrapper. */
     53    virtual void handleProgressFinished(CProgress &comProgress) /* override */;
     54
     55private:
     56
     57    /** Holds the cloud machine wrapper. */
     58    CCloudMachine  m_comCloudMachine;
     59};
     60
     61
     62/*********************************************************************************************************************************
     63*   Class UIProgressTaskRefreshCloudMachine implementation.                                                                      *
     64*********************************************************************************************************************************/
     65
     66UIProgressTaskRefreshCloudMachine::UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine)
     67    : UIProgressTask(pParent)
     68    , m_comCloudMachine(comCloudMachine)
     69{
     70}
     71
     72CProgress UIProgressTaskRefreshCloudMachine::createProgress()
     73{
     74    CProgress comProgress = m_comCloudMachine.Refresh();
     75    if (!m_comCloudMachine.isOk())
     76        msgCenter().cannotAcquireCloudMachineParameter(m_comCloudMachine);
     77    return comProgress;
     78}
     79
     80void UIProgressTaskRefreshCloudMachine::handleProgressFinished(CProgress &comProgress)
     81{
     82    if (!comProgress.GetCanceled() && (!comProgress.isOk() || comProgress.GetResultCode() != 0))
     83        msgCenter().cannotAcquireCloudMachineParameter(comProgress);
     84}
     85
     86
     87/*********************************************************************************************************************************
     88*   Class UIVirtualMachineItemCloud implementation.                                                                              *
     89*********************************************************************************************************************************/
    3790
    3891UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(UIFakeCloudVirtualMachineItemState enmState)
     
    4194    , m_enmFakeCloudItemState(enmState)
    4295    , m_fRefreshScheduled(false)
    43     , m_pTimer(0)
     96    , m_pProgressTaskRefresh(0)
    4497{
    4598    prepare();
     
    52105    , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable)
    53106    , m_fRefreshScheduled(false)
    54     , m_pTimer(0)
     107    , m_pProgressTaskRefresh(0)
    55108{
    56109    prepare();
     
    76129void UIVirtualMachineItemCloud::updateInfoAsync(bool fDelayed, bool fSubscribe /* = false */)
    77130{
     131    /* Ignore refresh request if progress-task is absent: */
     132    if (!m_pProgressTaskRefresh)
     133        return;
     134
    78135    /* Mark update scheduled if requested: */
    79136    if (fSubscribe)
    80137        m_fRefreshScheduled = true;
    81138
    82     /* Ignore refresh request if timer or progress is already running: */
    83     if (m_pTimer->isActive() || m_pProgressHandler)
     139    /* Schedule refresh request in a 10 or 0 seconds
     140     * if progress-task isn't already scheduled or running: */
     141    if (   !m_pProgressTaskRefresh->isScheduled()
     142        && !m_pProgressTaskRefresh->isRunning())
     143        m_pProgressTaskRefresh->schedule(fDelayed ? 10000 : 0);
     144}
     145
     146void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished()
     147{
     148    /* Ignore cancel request if progress-task is absent: */
     149    if (!m_pProgressTaskRefresh)
    84150        return;
    85151
    86     /* Schedule refresh request in a 10 or 0 seconds: */
    87     m_pTimer->setInterval(fDelayed ? 10000 : 0);
    88     m_pTimer->start();
    89 }
    90 
    91 void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished()
    92 {
    93152    /* Mark update canceled in any case: */
    94153    m_fRefreshScheduled = false;
    95154
    96     /* Cancel the progress-handler if any: */
    97     if (m_pProgressHandler)
    98         m_pProgressHandler->cancel();
     155    /* Cancel refresh request
     156     * if progress-task already running: */
     157    if (m_pProgressTaskRefresh->isRunning())
     158        m_pProgressTaskRefresh->cancel();
    99159}
    100160
     
    298358}
    299359
    300 void UIVirtualMachineItemCloud::sltRefreshCloudMachineInfo()
    301 {
    302     /* Make sure item is of real cloud type and is initialized: */
    303     AssertReturnVoid(itemType() == UIVirtualMachineItemType_CloudReal);
    304 
    305     /* Ignore refresh request if there is progress already: */
    306     if (m_pProgressHandler)
    307         return;
    308 
    309     /* Create 'Refresh' progress: */
    310     m_comProgress = m_comCloudMachine.Refresh();
    311     if (!m_comCloudMachine.isOk())
    312         msgCenter().cannotAcquireCloudMachineParameter(m_comCloudMachine);
    313     else
    314     {
    315         /* Prepare 'Refresh' progress handler: */
    316         m_pProgressHandler = new UIProgressObject(m_comProgress, this);
    317         if (m_pProgressHandler)
    318         {
    319             connect(m_pProgressHandler.data(), &UIProgressObject::sigProgressEventHandlingFinished,
    320                     this, &UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone);
    321             emit sigRefreshStarted();
    322         }
    323     }
    324 }
    325 
    326360void UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone()
    327361{
    328     /* Was the progress canceled? */
    329     const bool fCanceled = m_comProgress.GetCanceled();
    330 
    331     /* If not canceled => check progress result: */
    332     if (!fCanceled && (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0))
    333         msgCenter().cannotAcquireCloudMachineParameter(m_comProgress);
    334 
    335362    /* Recache: */
    336363    recache();
    337364
    338     /* Cleanup the handler and the progress: */
    339     delete m_pProgressHandler;
    340     m_comProgress = CProgress();
    341 
    342     /* If not canceled => notify listeners: */
    343     if (!fCanceled)
    344         emit sigRefreshFinished();
     365    /* Notify listeners: */
     366    emit sigRefreshFinished();
    345367
    346368    /* Refresh again if scheduled: */
     
    351373void UIVirtualMachineItemCloud::prepare()
    352374{
    353     /* Prepare timer: */
    354     m_pTimer = new QTimer(this);
    355     if (m_pTimer)
     375    /* Prepare progress-task if necessary: */
     376    if (itemType() == UIVirtualMachineItemType_CloudReal)
    356377    {
    357         m_pTimer->setSingleShot(true);
    358         connect(m_pTimer, &QTimer::timeout,
    359                 this, &UIVirtualMachineItemCloud::sltRefreshCloudMachineInfo);
     378        m_pProgressTaskRefresh = new UIProgressTaskRefreshCloudMachine(this, machine());
     379        if (m_pProgressTaskRefresh)
     380        {
     381            connect(m_pProgressTaskRefresh, &UIProgressTaskRefreshCloudMachine::sigProgressStarted,
     382                    this, &UIVirtualMachineItemCloud::sigRefreshStarted);
     383            connect(m_pProgressTaskRefresh, &UIProgressTaskRefreshCloudMachine::sigProgressFinished,
     384                    this, &UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone);
     385        }
    360386    }
    361387
     
    366392void UIVirtualMachineItemCloud::cleanup()
    367393{
    368     /* Cleanup timer: */
    369     delete m_pTimer;
    370     m_pTimer = 0;
    371 }
     394    /* Cleanup progress-task: */
     395    delete m_pProgressTaskRefresh;
     396    m_pProgressTaskRefresh = 0;
     397}
     398
     399
     400#include "UIVirtualMachineItemCloud.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r86772 r86774  
    2222#endif
    2323
    24 /* Qt includes: */
    25 #include <QPointer>
    26 
    2724/* GUI includes: */
    2825#include "UIVirtualMachineItem.h"
     
    3128#include "COMEnums.h"
    3229#include "CCloudMachine.h"
    33 #include "CProgress.h"
    3430
    3531/* Forward declarations: */
    36 class QTimer;
    37 class UIProgressObject;
     32class UIProgressTask;
    3833
    3934/** UIVirtualMachineItem sub-class used as cloud Virtual Machine item interface. */
     
    5651    UIVirtualMachineItemCloud(const CCloudMachine &comCloudMachine);
    5752    /** Destructs cloud VM item. */
    58     virtual ~UIVirtualMachineItemCloud();
     53    virtual ~UIVirtualMachineItemCloud() /* override */;
    5954
    6055    /** @name Arguments.
     
    129124private slots:
    130125
    131         /** Starts cloud VM info refresh progress. */
    132         void sltRefreshCloudMachineInfo();
    133126        /** Handles signal about cloud VM info refresh progress is done. */
    134127        void sltHandleRefreshCloudMachineInfoDone();
     
    160153        QString                             m_strFakeCloudItemErrorMessage;
    161154
    162         /** Holds whether we should update info. */
    163         bool                        m_fRefreshScheduled;
    164         /** Holds the machine refresh timer instance. */
    165         QTimer                     *m_pTimer;
    166         /** Holds the machine refresh progress object instance. */
    167         CProgress                   m_comProgress;
    168         /** Holds the machine refresh progress handler instance. */
    169         QPointer<UIProgressObject>  m_pProgressHandler;
     155        /** Holds whether we plan to refresh info. */
     156        bool            m_fRefreshScheduled;
     157        /** Holds the refresh progress-task instance. */
     158        UIProgressTask *m_pProgressTaskRefresh;
    170159    /** @} */
    171160};
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette