Changeset 86774 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 30, 2020 5:48:02 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141170
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r86773 r86774 941 941 src/hostnetwork/UIHostNetworkManager.cpp \ 942 942 src/manager/UIVirtualBoxManager.cpp \ 943 src/manager/UIVirtualMachineItemCloud.cpp \ 943 944 src/manager/UIWelcomePane.cpp \ 944 945 src/manager/chooser/UIChooserAbstractModel.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp
r86772 r86774 27 27 #include "UIIconPool.h" 28 28 #include "UIMessageCenter.h" 29 #include "UIProgress Object.h"29 #include "UIProgressTask.h" 30 30 #include "UIThreadPool.h" 31 31 #include "UIVirtualMachineItemCloud.h" … … 35 35 #include "CVirtualBoxErrorInfo.h" 36 36 37 38 /** UIProgressTask extension performing cloud machine refresh task. */ 39 class UIProgressTaskRefreshCloudMachine : public UIProgressTask 40 { 41 Q_OBJECT; 42 43 public: 44 45 /** Constructs @a comCloudMachine refresh task passing @a pParent to the base-class. */ 46 UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine); 47 48 protected: 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 55 private: 56 57 /** Holds the cloud machine wrapper. */ 58 CCloudMachine m_comCloudMachine; 59 }; 60 61 62 /********************************************************************************************************************************* 63 * Class UIProgressTaskRefreshCloudMachine implementation. * 64 *********************************************************************************************************************************/ 65 66 UIProgressTaskRefreshCloudMachine::UIProgressTaskRefreshCloudMachine(QObject *pParent, const CCloudMachine &comCloudMachine) 67 : UIProgressTask(pParent) 68 , m_comCloudMachine(comCloudMachine) 69 { 70 } 71 72 CProgress UIProgressTaskRefreshCloudMachine::createProgress() 73 { 74 CProgress comProgress = m_comCloudMachine.Refresh(); 75 if (!m_comCloudMachine.isOk()) 76 msgCenter().cannotAcquireCloudMachineParameter(m_comCloudMachine); 77 return comProgress; 78 } 79 80 void 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 *********************************************************************************************************************************/ 37 90 38 91 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(UIFakeCloudVirtualMachineItemState enmState) … … 41 94 , m_enmFakeCloudItemState(enmState) 42 95 , m_fRefreshScheduled(false) 43 , m_p Timer(0)96 , m_pProgressTaskRefresh(0) 44 97 { 45 98 prepare(); … … 52 105 , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable) 53 106 , m_fRefreshScheduled(false) 54 , m_p Timer(0)107 , m_pProgressTaskRefresh(0) 55 108 { 56 109 prepare(); … … 76 129 void UIVirtualMachineItemCloud::updateInfoAsync(bool fDelayed, bool fSubscribe /* = false */) 77 130 { 131 /* Ignore refresh request if progress-task is absent: */ 132 if (!m_pProgressTaskRefresh) 133 return; 134 78 135 /* Mark update scheduled if requested: */ 79 136 if (fSubscribe) 80 137 m_fRefreshScheduled = true; 81 138 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 146 void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished() 147 { 148 /* Ignore cancel request if progress-task is absent: */ 149 if (!m_pProgressTaskRefresh) 84 150 return; 85 151 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 {93 152 /* Mark update canceled in any case: */ 94 153 m_fRefreshScheduled = false; 95 154 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(); 99 159 } 100 160 … … 298 358 } 299 359 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 else314 {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 326 360 void UIVirtualMachineItemCloud::sltHandleRefreshCloudMachineInfoDone() 327 361 { 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 335 362 /* Recache: */ 336 363 recache(); 337 364 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(); 345 367 346 368 /* Refresh again if scheduled: */ … … 351 373 void UIVirtualMachineItemCloud::prepare() 352 374 { 353 /* Prepare timer: */ 354 m_pTimer = new QTimer(this); 355 if (m_pTimer) 375 /* Prepare progress-task if necessary: */ 376 if (itemType() == UIVirtualMachineItemType_CloudReal) 356 377 { 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 } 360 386 } 361 387 … … 366 392 void UIVirtualMachineItemCloud::cleanup() 367 393 { 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 22 22 #endif 23 23 24 /* Qt includes: */25 #include <QPointer>26 27 24 /* GUI includes: */ 28 25 #include "UIVirtualMachineItem.h" … … 31 28 #include "COMEnums.h" 32 29 #include "CCloudMachine.h" 33 #include "CProgress.h"34 30 35 31 /* Forward declarations: */ 36 class QTimer; 37 class UIProgressObject; 32 class UIProgressTask; 38 33 39 34 /** UIVirtualMachineItem sub-class used as cloud Virtual Machine item interface. */ … … 56 51 UIVirtualMachineItemCloud(const CCloudMachine &comCloudMachine); 57 52 /** Destructs cloud VM item. */ 58 virtual ~UIVirtualMachineItemCloud() ;53 virtual ~UIVirtualMachineItemCloud() /* override */; 59 54 60 55 /** @name Arguments. … … 129 124 private slots: 130 125 131 /** Starts cloud VM info refresh progress. */132 void sltRefreshCloudMachineInfo();133 126 /** Handles signal about cloud VM info refresh progress is done. */ 134 127 void sltHandleRefreshCloudMachineInfoDone(); … … 160 153 QString m_strFakeCloudItemErrorMessage; 161 154 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; 170 159 /** @} */ 171 160 };
Note:
See TracChangeset
for help on using the changeset viewer.