VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.cpp@ 74942

Last change on this file since 74942 was 74942, checked in by vboxsync, 6 years ago

FE/Qt: bugref:9261: fixed variable names and doxygen description according to code guidlines

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.0 KB
Line 
1/* $Id: UIProgressDialog.cpp 74942 2018-10-19 12:51:20Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIProgressDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QCloseEvent>
24# include <QEventLoop>
25# include <QProgressBar>
26# include <QTime>
27# include <QTimer>
28# include <QVBoxLayout>
29
30/* GUI includes: */
31# include "QIDialogButtonBox.h"
32# include "QILabel.h"
33# include "UIErrorString.h"
34# include "UIExtraDataManager.h"
35# include "UIMainEventListener.h"
36# include "UIModalWindowManager.h"
37# include "UIProgressDialog.h"
38# include "UISpecialControls.h"
39# include "VBoxGlobal.h"
40# ifdef VBOX_WS_MAC
41# include "VBoxUtils-darwin.h"
42# endif /* VBOX_WS_MAC */
43
44/* COM includes: */
45# include "CEventListener.h"
46# include "CEventSource.h"
47# include "CProgress.h"
48
49#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
50
51
52/** Private QObject extension
53 * providing UIExtraDataManager with the CVirtualBox event-source. */
54class UIProgressEventHandler : public QObject
55{
56 Q_OBJECT;
57
58signals:
59
60 /** Notifies about @a iPercent change for progress with @a uProgressId. */
61 void sigProgressPercentageChange(const QUuid &uProgressId, const int iPercent);
62 /** Notifies about task complete for progress with @a uProgressId. */
63 void sigProgressTaskComplete(const QUuid &uProgressId);
64
65public:
66
67 /** Constructs event proxy object on the basis of passed @a pParent. */
68 UIProgressEventHandler(QObject *pParent, const CProgress &comProgress);
69 /** Destructs event proxy object. */
70 virtual ~UIProgressEventHandler() /* override */;
71
72protected:
73
74 /** @name Prepare/Cleanup cascade.
75 * @{ */
76 /** Prepares all. */
77 void prepare();
78 /** Prepares listener. */
79 void prepareListener();
80 /** Prepares connections. */
81 void prepareConnections();
82
83 /** Cleanups connections. */
84 void cleanupConnections();
85 /** Cleanups listener. */
86 void cleanupListener();
87 /** Cleanups all. */
88 void cleanup();
89 /** @} */
90
91private:
92
93 /** Holds the progress wrapper. */
94 CProgress m_comProgress;
95
96 /** Holds the Qt event listener instance. */
97 ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
98 /** Holds the COM event listener instance. */
99 CEventListener m_comEventListener;
100};
101
102
103/*********************************************************************************************************************************
104* Class UIProgressEventHandler implementation. *
105*********************************************************************************************************************************/
106
107UIProgressEventHandler::UIProgressEventHandler(QObject *pParent, const CProgress &comProgress)
108 : QObject(pParent)
109 , m_comProgress(comProgress)
110{
111 /* Prepare: */
112 prepare();
113}
114
115UIProgressEventHandler::~UIProgressEventHandler()
116{
117 /* Cleanup: */
118 cleanup();
119}
120
121void UIProgressEventHandler::prepare()
122{
123 /* Prepare: */
124 prepareListener();
125 prepareConnections();
126}
127
128void UIProgressEventHandler::prepareListener()
129{
130 /* Create event listener instance: */
131 m_pQtListener.createObject();
132 m_pQtListener->init(new UIMainEventListener, this);
133 m_comEventListener = CEventListener(m_pQtListener);
134
135 /* Get CProgress event source: */
136 CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
137 AssertWrapperOk(comEventSourceProgress);
138
139 /* Enumerate all the required event-types: */
140 QVector<KVBoxEventType> eventTypes;
141 eventTypes
142 << KVBoxEventType_OnProgressPercentageChanged
143 << KVBoxEventType_OnProgressTaskCompleted;
144
145 /* Register event listener for CProgress event source: */
146 comEventSourceProgress.RegisterListener(m_comEventListener, eventTypes,
147 gEDataManager->eventHandlingType() == EventHandlingType_Active ? TRUE : FALSE);
148 AssertWrapperOk(comEventSourceProgress);
149
150 /* If event listener registered as passive one: */
151 if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
152 {
153 /* Register event sources in their listeners as well: */
154 m_pQtListener->getWrapped()->registerSource(comEventSourceProgress, m_comEventListener);
155 }
156}
157
158void UIProgressEventHandler::prepareConnections()
159{
160 /* Create direct (sync) connections for signals of main listener: */
161 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressPercentageChange,
162 this, &UIProgressEventHandler::sigProgressPercentageChange,
163 Qt::DirectConnection);
164 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigProgressTaskComplete,
165 this, &UIProgressEventHandler::sigProgressTaskComplete,
166 Qt::DirectConnection);
167}
168
169void UIProgressEventHandler::cleanupConnections()
170{
171 /* Nothing for now. */
172}
173
174void UIProgressEventHandler::cleanupListener()
175{
176 /* If event listener registered as passive one: */
177 if (gEDataManager->eventHandlingType() == EventHandlingType_Passive)
178 {
179 /* Unregister everything: */
180 m_pQtListener->getWrapped()->unregisterSources();
181 }
182
183 /* Make sure VBoxSVC is available: */
184 if (!vboxGlobal().isVBoxSVCAvailable())
185 return;
186
187 /* Get CProgress event source: */
188 CEventSource comEventSourceProgress = m_comProgress.GetEventSource();
189 AssertWrapperOk(comEventSourceProgress);
190
191 /* Unregister event listener for CProgress event source: */
192 comEventSourceProgress.UnregisterListener(m_comEventListener);
193}
194
195void UIProgressEventHandler::cleanup()
196{
197 /* Cleanup: */
198 cleanupConnections();
199 cleanupListener();
200}
201
202
203/*********************************************************************************************************************************
204* Class UIProgressDialog implementation. *
205*********************************************************************************************************************************/
206
207const char *UIProgressDialog::m_spcszOpDescTpl = "%1 ... (%2/%3)";
208
209UIProgressDialog::UIProgressDialog(CProgress &comProgress,
210 const QString &strTitle,
211 QPixmap *pImage /* = 0 */,
212 int cMinDuration /* = 2000 */,
213 QWidget *pParent /* = 0 */)
214 : QIWithRetranslateUI2<QIDialog>(pParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint)
215 , m_comProgress(comProgress)
216 , m_strTitle(strTitle)
217 , m_pImage(pImage)
218 , m_cMinDuration(cMinDuration)
219 , m_fLegacyHandling(gEDataManager->legacyProgressHandlingRequested())
220 , m_pLabelImage(0)
221 , m_pLabelDescription(0)
222 , m_pProgressBar(0)
223 , m_pButtonCancel(0)
224 , m_pLabelEta(0)
225 , m_cOperations(m_comProgress.GetOperationCount())
226 , m_uCurrentOperation(m_comProgress.GetOperation() + 1)
227 , m_fCancelEnabled(false)
228 , m_fEnded(false)
229 , m_pEventHandler(0)
230{
231 /* Prepare: */
232 prepare();
233}
234
235UIProgressDialog::~UIProgressDialog()
236{
237 /* Cleanup: */
238 cleanup();
239}
240
241void UIProgressDialog::retranslateUi()
242{
243 m_pButtonCancel->setText(tr("&Cancel"));
244 m_pButtonCancel->setToolTip(tr("Cancel the current operation"));
245}
246
247int UIProgressDialog::run(int cRefreshInterval)
248{
249 /* Make sure progress hasn't finished already: */
250 if (!m_comProgress.isOk() || m_comProgress.GetCompleted())
251 {
252 /* Progress completed? */
253 if (m_comProgress.isOk())
254 return Accepted;
255 /* Or aborted? */
256 else
257 return Rejected;
258 }
259
260 /* Start refresh timer (if necessary): */
261 int id = 0;
262 if (m_fLegacyHandling)
263 id = startTimer(cRefreshInterval);
264
265 /* Set busy cursor.
266 * We don't do this on the Mac, cause regarding the design rules of
267 * Apple there is no busy window behavior. A window should always be
268 * responsive and it is in our case (We show the progress dialog bar). */
269#ifndef VBOX_WS_MAC
270 if (m_fCancelEnabled)
271 QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
272 else
273 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
274#endif /* VBOX_WS_MAC */
275
276 /* Create a local event-loop: */
277 {
278 /* Guard ourself for the case
279 * we destroyed ourself in our event-loop: */
280 QPointer<UIProgressDialog> guard = this;
281
282 /* Holds the modal loop, but don't show the window immediately: */
283 execute(false);
284
285 /* Are we still valid? */
286 if (guard.isNull())
287 return Rejected;
288 }
289
290 /* Kill refresh timer (if necessary): */
291 if (m_fLegacyHandling)
292 killTimer(id);
293
294#ifndef VBOX_WS_MAC
295 /* Reset the busy cursor */
296 QApplication::restoreOverrideCursor();
297#endif /* VBOX_WS_MAC */
298
299 return result();
300}
301
302void UIProgressDialog::show()
303{
304 /* We should not show progress-dialog
305 * if it was already finalized but not yet closed.
306 * This could happens in case of some other
307 * modal dialog prevents our event-loop from
308 * being exit overlapping 'this'. */
309 if (!m_fEnded)
310 QIDialog::show();
311}
312
313void UIProgressDialog::reject()
314{
315 if (m_fCancelEnabled)
316 sltCancelOperation();
317}
318
319void UIProgressDialog::timerEvent(QTimerEvent *)
320{
321 /* Call the timer event handling delegate: */
322 handleTimerEvent();
323}
324
325void UIProgressDialog::closeEvent(QCloseEvent *pEvent)
326{
327 if (m_fCancelEnabled)
328 sltCancelOperation();
329 else
330 pEvent->ignore();
331}
332
333void UIProgressDialog::sltHandleProgressPercentageChange(const QUuid &, const int iPercent)
334{
335 /* New mode only: */
336 AssertReturnVoid(!m_fLegacyHandling);
337
338 /* Update progress: */
339 updateProgressState();
340 updateProgressPercentage(iPercent);
341}
342
343void UIProgressDialog::sltHandleProgressTaskComplete(const QUuid &)
344{
345 /* New mode only: */
346 AssertReturnVoid(!m_fLegacyHandling);
347
348 /* If progress-dialog is not yet ended but progress is aborted or completed: */
349 if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted()))
350 {
351 /* Set progress to 100%: */
352 updateProgressPercentage(100);
353
354 /* Try to close the dialog: */
355 closeProgressDialog();
356 }
357}
358
359void UIProgressDialog::sltHandleWindowStackChange()
360{
361 /* If progress-dialog is not yet ended but progress is aborted or completed: */
362 if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted()))
363 {
364 /* Try to close the dialog: */
365 closeProgressDialog();
366 }
367}
368
369void UIProgressDialog::sltCancelOperation()
370{
371 m_pButtonCancel->setEnabled(false);
372 m_comProgress.Cancel();
373}
374
375void UIProgressDialog::prepare()
376{
377 /* Setup dialog: */
378 setWindowTitle(QString("%1: %2").arg(m_strTitle, m_comProgress.GetDescription()));
379 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
380#ifdef VBOX_WS_MAC
381 ::darwinSetHidesAllTitleButtons(this);
382#endif
383
384 /* Make sure dialog is handling window stack changes: */
385 connect(&windowManager(), &UIModalWindowManager::sigStackChanged,
386 this, &UIProgressDialog::sltHandleWindowStackChange);
387
388 /* Prepare: */
389 prepareEventHandler();
390 prepareWidgets();
391}
392
393void UIProgressDialog::prepareEventHandler()
394{
395 if (!m_fLegacyHandling)
396 {
397 /* Create CProgress event handler: */
398 m_pEventHandler = new UIProgressEventHandler(this, m_comProgress);
399 connect(m_pEventHandler, &UIProgressEventHandler::sigProgressPercentageChange,
400 this, &UIProgressDialog::sltHandleProgressPercentageChange);
401 connect(m_pEventHandler, &UIProgressEventHandler::sigProgressTaskComplete,
402 this, &UIProgressDialog::sltHandleProgressTaskComplete);
403 }
404}
405
406void UIProgressDialog::prepareWidgets()
407{
408 /* Create main layout: */
409 QHBoxLayout *pMainLayout = new QHBoxLayout(this);
410 AssertPtrReturnVoid(pMainLayout);
411 {
412 /* Configure layout: */
413#ifdef VBOX_WS_MAC
414 if (m_pImage)
415 pMainLayout->setContentsMargins(30, 15, 30, 15);
416 else
417 pMainLayout->setContentsMargins(6, 6, 6, 6);
418#endif
419
420 /* If there is image: */
421 if (m_pImage)
422 {
423 /* Create image label: */
424 m_pLabelImage = new QLabel;
425 AssertPtrReturnVoid(m_pLabelImage);
426 {
427 /* Configure label: */
428 m_pLabelImage->setPixmap(*m_pImage);
429
430 /* Add into layout: */
431 pMainLayout->addWidget(m_pLabelImage);
432 }
433 }
434
435 /* Create description layout: */
436 QVBoxLayout *pDescriptionLayout = new QVBoxLayout;
437 AssertPtrReturnVoid(pDescriptionLayout);
438 {
439 /* Configure layout: */
440 pDescriptionLayout->setMargin(0);
441
442 /* Add stretch: */
443 pDescriptionLayout->addStretch(1);
444
445 /* Create description label: */
446 m_pLabelDescription = new QILabel;
447 AssertPtrReturnVoid(m_pLabelDescription);
448 {
449 /* Configure label: */
450 if (m_cOperations > 1)
451 m_pLabelDescription->setText(QString(m_spcszOpDescTpl)
452 .arg(m_comProgress.GetOperationDescription())
453 .arg(m_uCurrentOperation).arg(m_cOperations));
454 else
455 m_pLabelDescription->setText(QString("%1 ...")
456 .arg(m_comProgress.GetOperationDescription()));
457
458 /* Add into layout: */
459 pDescriptionLayout->addWidget(m_pLabelDescription, 0, Qt::AlignHCenter);
460 }
461
462 /* Create proggress layout: */
463 QHBoxLayout *pProgressLayout = new QHBoxLayout;
464 AssertPtrReturnVoid(pProgressLayout);
465 {
466 /* Configure layout: */
467 pProgressLayout->setMargin(0);
468
469 /* Create progress-bar: */
470 m_pProgressBar = new QProgressBar;
471 AssertPtrReturnVoid(m_pProgressBar);
472 {
473 /* Configure progress-bar: */
474 m_pProgressBar->setMaximum(100);
475 m_pProgressBar->setValue(0);
476
477 /* Add into layout: */
478 pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter);
479 }
480
481 /* Create cancel button: */
482 m_pButtonCancel = new UIMiniCancelButton;
483 AssertPtrReturnVoid(m_pButtonCancel);
484 {
485 /* Configure cancel button: */
486 m_fCancelEnabled = m_comProgress.GetCancelable();
487 m_pButtonCancel->setEnabled(m_fCancelEnabled);
488 m_pButtonCancel->setFocusPolicy(Qt::ClickFocus);
489 connect(m_pButtonCancel, SIGNAL(clicked()), this, SLOT(sltCancelOperation()));
490
491 /* Add into layout: */
492 pProgressLayout->addWidget(m_pButtonCancel, 0, Qt::AlignVCenter);
493 }
494
495 /* Add into layout: */
496 pDescriptionLayout->addLayout(pProgressLayout);
497 }
498
499 /* Create estimation label: */
500 m_pLabelEta = new QILabel;
501 {
502 /* Add into layout: */
503 pDescriptionLayout->addWidget(m_pLabelEta, 0, Qt::AlignLeft | Qt::AlignVCenter);
504 }
505
506 /* Add stretch: */
507 pDescriptionLayout->addStretch(1);
508
509 /* Add into layout: */
510 pMainLayout->addLayout(pDescriptionLayout);
511 }
512 }
513
514 /* Translate finally: */
515 retranslateUi();
516
517 /* The progress dialog will be shown automatically after
518 * the duration is over if progress is not finished yet. */
519 QTimer::singleShot(m_cMinDuration, this, SLOT(show()));
520}
521
522void UIProgressDialog::cleanupWidgets()
523{
524 /* Nothing for now. */
525}
526
527void UIProgressDialog::cleanupEventHandler()
528{
529 if (!m_fLegacyHandling)
530 {
531 /* Destroy CProgress event handler: */
532 delete m_pEventHandler;
533 m_pEventHandler = 0;
534 }
535}
536
537void UIProgressDialog::cleanup()
538{
539 /* Wait for CProgress to complete: */
540 m_comProgress.WaitForCompletion(-1);
541
542 /* Call the timer event handling delegate: */
543 if (m_fLegacyHandling)
544 handleTimerEvent();
545
546 /* Cleanup: */
547 cleanupEventHandler();
548 cleanupWidgets();
549}
550
551void UIProgressDialog::updateProgressState()
552{
553 /* Mark progress canceled if so: */
554 if (m_comProgress.GetCanceled())
555 m_pLabelEta->setText(tr("Canceling..."));
556 /* Update the progress dialog otherwise: */
557 else
558 {
559 /* Update ETA: */
560 const long iNewTime = m_comProgress.GetTimeRemaining();
561 long iSeconds;
562 long iMinutes;
563 long iHours;
564 long iDays;
565
566 iSeconds = iNewTime < 0 ? 0 : iNewTime;
567 iMinutes = iSeconds / 60;
568 iSeconds -= iMinutes * 60;
569 iHours = iMinutes / 60;
570 iMinutes -= iHours * 60;
571 iDays = iHours / 24;
572 iHours -= iDays * 24;
573
574 const QString strDays = VBoxGlobal::daysToString(iDays);
575 const QString strHours = VBoxGlobal::hoursToString(iHours);
576 const QString strMinutes = VBoxGlobal::minutesToString(iMinutes);
577 const QString strSeconds = VBoxGlobal::secondsToString(iSeconds);
578
579 const QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\"");
580 const QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\"");
581
582 if (iDays > 1 && iHours > 0)
583 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours));
584 else if (iDays > 1)
585 m_pLabelEta->setText(strOneComp.arg(strDays));
586 else if (iDays > 0 && iHours > 0)
587 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours));
588 else if (iDays > 0 && iMinutes > 5)
589 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strMinutes));
590 else if (iDays > 0)
591 m_pLabelEta->setText(strOneComp.arg(strDays));
592 else if (iHours > 2)
593 m_pLabelEta->setText(strOneComp.arg(strHours));
594 else if (iHours > 0 && iMinutes > 0)
595 m_pLabelEta->setText(strTwoComp.arg(strHours).arg(strMinutes));
596 else if (iHours > 0)
597 m_pLabelEta->setText(strOneComp.arg(strHours));
598 else if (iMinutes > 2)
599 m_pLabelEta->setText(strOneComp.arg(strMinutes));
600 else if (iMinutes > 0 && iSeconds > 5)
601 m_pLabelEta->setText(strTwoComp.arg(strMinutes).arg(strSeconds));
602 else if (iMinutes > 0)
603 m_pLabelEta->setText(strOneComp.arg(strMinutes));
604 else if (iSeconds > 5)
605 m_pLabelEta->setText(strOneComp.arg(strSeconds));
606 else if (iSeconds > 0)
607 m_pLabelEta->setText(tr("A few seconds remaining"));
608 else
609 m_pLabelEta->clear();
610
611 /* Then operation text (if changed): */
612 ulong uNewOp = m_comProgress.GetOperation() + 1;
613 if (uNewOp != m_uCurrentOperation)
614 {
615 m_uCurrentOperation = uNewOp;
616 m_pLabelDescription->setText(QString(m_spcszOpDescTpl)
617 .arg(m_comProgress.GetOperationDescription())
618 .arg(m_uCurrentOperation).arg(m_cOperations));
619 }
620
621 /* Then cancel button: */
622 m_fCancelEnabled = m_comProgress.GetCancelable();
623 m_pButtonCancel->setEnabled(m_fCancelEnabled);
624 }
625}
626
627void UIProgressDialog::updateProgressPercentage(int iPercent /* = -1 */)
628{
629 /* Update operation percentage: */
630 if (iPercent == -1)
631 iPercent = m_comProgress.GetPercent();
632 m_pProgressBar->setValue(iPercent);
633
634 /* Notify listeners about the operation progress update: */
635 emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(),
636 m_comProgress.GetOperation() + 1, iPercent);
637}
638
639void UIProgressDialog::closeProgressDialog()
640{
641 /* If window is on the top of the stack: */
642 if (windowManager().isWindowOnTheTopOfTheModalWindowStack(this))
643 {
644 /* Progress completed? */
645 if (m_comProgress.isOk())
646 done(Accepted);
647 /* Or aborted? */
648 else
649 done(Rejected);
650
651 /* Mark progress-dialog finished: */
652 m_fEnded = true;
653 }
654}
655
656void UIProgressDialog::handleTimerEvent()
657{
658 /* Old mode only: */
659 AssertReturnVoid(m_fLegacyHandling);
660
661 /* If progress-dialog is ended: */
662 if (m_fEnded)
663 {
664 // WORKAROUND:
665 // We should hide progress-dialog if it was already ended but not yet closed. This could happen
666 // in case if some other modal dialog prevents our event-loop from being exit overlapping 'this'.
667 /* If window is on the top of the stack and still shown: */
668 if (!isHidden() && windowManager().isWindowOnTheTopOfTheModalWindowStack(this))
669 hide();
670
671 return;
672 }
673
674 /* If progress-dialog is not yet ended but progress is aborted or completed: */
675 if (!m_comProgress.isOk() || m_comProgress.GetCompleted())
676 {
677 /* Set progress to 100%: */
678 updateProgressPercentage(100);
679
680 /* Try to close the dialog: */
681 return closeProgressDialog();
682 }
683
684 /* Update progress: */
685 updateProgressState();
686 updateProgressPercentage();
687}
688
689
690/*********************************************************************************************************************************
691* Class UIProgress implementation. *
692*********************************************************************************************************************************/
693
694UIProgress::UIProgress(CProgress &comProgress, QObject *pParent /* = 0 */)
695 : QObject(pParent)
696 , m_comProgress(comProgress)
697 , m_cOperations(m_comProgress.GetOperationCount())
698 , m_fEnded(false)
699{
700}
701
702void UIProgress::run(int iRefreshInterval)
703{
704 /* Make sure the CProgress still valid: */
705 if (!m_comProgress.isOk())
706 return;
707
708 /* Start the refresh timer: */
709 int id = startTimer(iRefreshInterval);
710
711 /* Create a local event-loop: */
712 {
713 QEventLoop eventLoop;
714 m_pEventLoop = &eventLoop;
715
716 /* Guard ourself for the case
717 * we destroyed ourself in our event-loop: */
718 QPointer<UIProgress> guard = this;
719
720 /* Start the blocking event-loop: */
721 eventLoop.exec();
722
723 /* Are we still valid? */
724 if (guard.isNull())
725 return;
726
727 m_pEventLoop = 0;
728 }
729
730 /* Kill the refresh timer: */
731 killTimer(id);
732}
733
734void UIProgress::timerEvent(QTimerEvent *)
735{
736 /* Make sure the UIProgress still 'running': */
737 if (m_fEnded)
738 return;
739
740 /* If progress had failed or finished: */
741 if (!m_comProgress.isOk() || m_comProgress.GetCompleted())
742 {
743 /* Notify listeners about the operation progress error: */
744 if (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0)
745 emit sigProgressError(UIErrorString::formatErrorInfo(m_comProgress));
746
747 /* Exit from the event-loop if there is any: */
748 if (m_pEventLoop)
749 m_pEventLoop->exit();
750
751 /* Mark UIProgress as 'ended': */
752 m_fEnded = true;
753
754 /* Return early: */
755 return;
756 }
757
758 /* If CProgress was not yet canceled: */
759 if (!m_comProgress.GetCanceled())
760 {
761 /* Notify listeners about the operation progress update: */
762 emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(),
763 m_comProgress.GetOperation() + 1, m_comProgress.GetPercent());
764 }
765}
766
767
768#include "UIProgressDialog.moc"
769
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use