Changeset 55277 in vbox for trunk/src/VBox
- Timestamp:
- Apr 15, 2015 11:14:41 AM (10 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.cpp
r52730 r55277 328 328 } 329 329 330 331 UIProgress::UIProgress(CProgress &progress, QObject *pParent /* = 0 */) 332 : QObject(pParent) 333 , m_progress(progress) 334 , m_cOperations(m_progress.GetOperationCount()) 335 , m_fEnded(false) 336 { 337 } 338 339 void UIProgress::run(int iRefreshInterval) 340 { 341 /* Make sure the CProgress still valid: */ 342 if (!m_progress.isOk()) 343 return; 344 345 /* Start the refresh timer: */ 346 int id = startTimer(iRefreshInterval); 347 348 /* Create a local event-loop: */ 349 { 350 QEventLoop eventLoop; 351 m_pEventLoop = &eventLoop; 352 353 /* Guard ourself for the case 354 * we destroyed ourself in our event-loop: */ 355 QPointer<UIProgress> guard = this; 356 357 /* Start the blocking event-loop: */ 358 eventLoop.exec(); 359 360 /* Are we still valid? */ 361 if (guard.isNull()) 362 return; 363 364 m_pEventLoop = 0; 365 } 366 367 /* Kill the refresh timer: */ 368 killTimer(id); 369 } 370 371 void UIProgress::timerEvent(QTimerEvent*) 372 { 373 /* Make sure the UIProgress still 'running': */ 374 if (m_fEnded) 375 return; 376 377 /* If progress had failed or finished: */ 378 if (!m_progress.isOk() || m_progress.GetCompleted()) 379 { 380 /* Exit from the event-loop if there is any: */ 381 if (m_pEventLoop) 382 m_pEventLoop->exit(); 383 384 /* Mark UIProgress as 'ended': */ 385 m_fEnded = true; 386 387 /* Return early: */ 388 return; 389 } 390 391 /* If CProgress was not yet canceled: */ 392 if (!m_progress.GetCanceled()) 393 { 394 /* Notify listeners about the operation progress update: */ 395 emit sigProgressChange(m_cOperations, m_progress.GetOperationDescription(), 396 m_progress.GetOperation() + 1, m_progress.GetPercent()); 397 } 398 } 399 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h
r52727 r55277 95 95 }; 96 96 97 /** QObject reimplementation allowing to effectively track the CProgress object completion 98 * (w/o using CProgress::waitForCompletion() and w/o blocking the calling thread in any other way for too long). 99 * @note The CProgress instance is passed as a non-const reference to the constructor 100 * (to memorize COM errors if they happen), and therefore must not be destroyed 101 * before the created UIProgress instance is destroyed. 102 * @todo To be moved to separate files. */ 103 class UIProgress : public QObject 104 { 105 Q_OBJECT; 106 107 signals: 108 109 /** Notifies listeners about wrapped CProgress change. 110 * @param iOperations holds the number of operations CProgress have, 111 * @param strOperation holds the description of the current CProgress operation, 112 * @param iOperation holds the index of the current CProgress operation, 113 * @param iPercent holds the percentage of the current CProgress operation. */ 114 void sigProgressChange(ulong iOperations, QString strOperation, 115 ulong iOperation, ulong iPercent); 116 117 public: 118 119 /** Constructor passing @a pParent to the base-class. 120 * @param progress holds the CProgress to be wrapped. */ 121 UIProgress(CProgress &progress, QObject *pParent = 0); 122 123 /** Starts the UIProgress by entering the personal event-loop. 124 * @param iRefreshInterval holds the refresh interval to check 125 * for the CProgress updates with. */ 126 void run(int iRefreshInterval); 127 128 private: 129 130 /** Timer @a pEvent reimplementation. */ 131 virtual void timerEvent(QTimerEvent *pEvent); 132 133 /** Holds the wrapped CProgress reference. */ 134 CProgress &m_progress; 135 /** Holds the number of operations wrapped CProgress have. */ 136 const ulong m_cOperations; 137 /** Holds whether the UIProgress ended. */ 138 bool m_fEnded; 139 140 /** Holds the personal event-loop. */ 141 QPointer<QEventLoop> m_pEventLoop; 142 }; 143 97 144 #endif /* __UIProgressDialog_h__ */ 98 145
Note:
See TracChangeset
for help on using the changeset viewer.