Changeset 68999 in vbox
- Timestamp:
- Oct 6, 2017 10:06:04 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
-
UIProgressDialog.cpp (modified) (11 diffs)
-
UIProgressDialog.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.cpp
r68998 r68999 54 54 QWidget *pParent /* = 0 */) 55 55 : QIWithRetranslateUI2<QIDialog>(pParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint) 56 , m_progress(progress) 57 , m_pImageLbl(0) 56 , m_comProgress(progress) 57 , m_pLabelImage(0) 58 , m_pLabelDescription(0) 59 , m_pProgressBar(0) 60 , m_pButtonCancel(0) 61 , m_pLabelEta(0) 58 62 , m_fCancelEnabled(false) 59 , m_cOperations(m_ progress.GetOperationCount())60 , m_ iCurrentOperation(m_progress.GetOperation() + 1)63 , m_cOperations(m_comProgress.GetOperationCount()) 64 , m_uCurrentOperation(m_comProgress.GetOperation() + 1) 61 65 , m_fEnded(false) 62 66 { 63 67 /* Setup dialog: */ 64 setWindowTitle(QString("%1: %2").arg(strTitle, m_ progress.GetDescription()));68 setWindowTitle(QString("%1: %2").arg(strTitle, m_comProgress.GetDescription())); 65 69 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 70 #ifdef VBOX_WS_MAC 71 ::darwinSetHidesAllTitleButtons(this); 72 #endif 66 73 67 74 /* Create main layout: */ 68 75 QHBoxLayout *pMainLayout = new QHBoxLayout(this); 69 /* Configure layout: */ 76 { 77 /* Configure layout: */ 70 78 #ifdef VBOX_WS_MAC 71 ::darwinSetHidesAllTitleButtons(this); 72 if (pImage) 73 pMainLayout->setContentsMargins(30, 15, 30, 15); 74 else 75 pMainLayout->setContentsMargins(6, 6, 6, 6); 79 if (pImage) 80 pMainLayout->setContentsMargins(30, 15, 30, 15); 81 else 82 pMainLayout->setContentsMargins(6, 6, 6, 6); 76 83 #endif 77 84 78 /* If there is image: */ 79 if (pImage) 80 { 81 /* Create image label: */ 82 m_pImageLbl = new QLabel(this); 83 /* Configure label: */ 84 m_pImageLbl->setPixmap(*pImage); 85 /* Add into layout: */ 86 pMainLayout->addWidget(m_pImageLbl); 87 } 88 89 /* Create description label: */ 90 m_pDescriptionLbl = new QILabel(this); 91 /* Configure label: */ 92 if (m_cOperations > 1) 93 m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl) 94 .arg(m_progress.GetOperationDescription()) 95 .arg(m_iCurrentOperation).arg(m_cOperations)); 96 else 97 m_pDescriptionLbl->setText(QString("%1 ...") 98 .arg(m_progress.GetOperationDescription())); 99 100 /* Create progress-bar: */ 101 m_pProgressBar = new QProgressBar(this); 102 /* Configure progress-bar: */ 103 m_pProgressBar->setMaximum(100); 104 m_pProgressBar->setValue(0); 105 106 /* Create cancel button: */ 107 m_fCancelEnabled = m_progress.GetCancelable(); 108 m_pCancelBtn = new UIMiniCancelButton(this); 109 /* Configure cancel button: */ 110 m_pCancelBtn->setEnabled(m_fCancelEnabled); 111 m_pCancelBtn->setFocusPolicy(Qt::ClickFocus); 112 connect(m_pCancelBtn, SIGNAL(clicked()), this, SLOT(sltCancelOperation())); 113 114 /* Create estimation label: */ 115 m_pEtaLbl = new QILabel(this); 116 117 /* Create proggress layout: */ 118 QHBoxLayout *pProgressLayout = new QHBoxLayout; 119 /* Configure layout: */ 120 pProgressLayout->setMargin(0); 121 /* Add into layout: */ 122 pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter); 123 pProgressLayout->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter); 124 125 /* Create description layout: */ 126 QVBoxLayout *pDescriptionLayout = new QVBoxLayout; 127 /* Configure layout: */ 128 pDescriptionLayout->setMargin(0); 129 /* Add stretch: */ 130 pDescriptionLayout->addStretch(1); 131 /* Add into layout: */ 132 pDescriptionLayout->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter); 133 pDescriptionLayout->addLayout(pProgressLayout); 134 pDescriptionLayout->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter); 135 /* Add stretch: */ 136 pDescriptionLayout->addStretch(1); 137 /* Add into layout: */ 138 pMainLayout->addLayout(pDescriptionLayout); 85 /* If there is image: */ 86 if (pImage) 87 { 88 /* Create image label: */ 89 m_pLabelImage = new QLabel; 90 { 91 /* Configure label: */ 92 m_pLabelImage->setPixmap(*pImage); 93 94 /* Add into layout: */ 95 pMainLayout->addWidget(m_pLabelImage); 96 } 97 } 98 99 /* Create description layout: */ 100 QVBoxLayout *pDescriptionLayout = new QVBoxLayout; 101 { 102 /* Configure layout: */ 103 pDescriptionLayout->setMargin(0); 104 105 /* Add stretch: */ 106 pDescriptionLayout->addStretch(1); 107 108 /* Create description label: */ 109 m_pLabelDescription = new QILabel; 110 { 111 /* Configure label: */ 112 if (m_cOperations > 1) 113 m_pLabelDescription->setText(QString(m_spcszOpDescTpl) 114 .arg(m_comProgress.GetOperationDescription()) 115 .arg(m_uCurrentOperation).arg(m_cOperations)); 116 else 117 m_pLabelDescription->setText(QString("%1 ...") 118 .arg(m_comProgress.GetOperationDescription())); 119 120 /* Add into layout: */ 121 pDescriptionLayout->addWidget(m_pLabelDescription, 0, Qt::AlignHCenter); 122 } 123 124 /* Create proggress layout: */ 125 QHBoxLayout *pProgressLayout = new QHBoxLayout; 126 { 127 /* Configure layout: */ 128 pProgressLayout->setMargin(0); 129 130 /* Create progress-bar: */ 131 m_pProgressBar = new QProgressBar; 132 { 133 /* Configure progress-bar: */ 134 m_pProgressBar->setMaximum(100); 135 m_pProgressBar->setValue(0); 136 137 /* Add into layout: */ 138 pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter); 139 } 140 141 /* Create cancel button: */ 142 m_pButtonCancel = new UIMiniCancelButton; 143 { 144 /* Configure cancel button: */ 145 m_fCancelEnabled = m_comProgress.GetCancelable(); 146 m_pButtonCancel->setEnabled(m_fCancelEnabled); 147 m_pButtonCancel->setFocusPolicy(Qt::ClickFocus); 148 connect(m_pButtonCancel, SIGNAL(clicked()), this, SLOT(sltCancelOperation())); 149 150 /* Add into layout: */ 151 pProgressLayout->addWidget(m_pButtonCancel, 0, Qt::AlignVCenter); 152 } 153 154 /* Add into layout: */ 155 pDescriptionLayout->addLayout(pProgressLayout); 156 } 157 158 /* Create estimation label: */ 159 m_pLabelEta = new QILabel; 160 { 161 /* Add into layout: */ 162 pDescriptionLayout->addWidget(m_pLabelEta, 0, Qt::AlignLeft | Qt::AlignVCenter); 163 } 164 165 /* Add stretch: */ 166 pDescriptionLayout->addStretch(1); 167 168 /* Add into layout: */ 169 pMainLayout->addLayout(pDescriptionLayout); 170 } 171 } 139 172 140 173 /* Translate finally: */ … … 149 182 { 150 183 /* Wait for CProgress to complete: */ 151 m_ progress.WaitForCompletion(-1);184 m_comProgress.WaitForCompletion(-1); 152 185 153 186 /* Call the timer event handling delegate: */ … … 157 190 void UIProgressDialog::retranslateUi() 158 191 { 159 m_strCancel = tr("Canceling..."); 160 m_pCancelBtn->setText(tr("&Cancel")); 161 m_pCancelBtn->setToolTip(tr("Cancel the current operation")); 192 m_pButtonCancel->setText(tr("&Cancel")); 193 m_pButtonCancel->setToolTip(tr("Cancel the current operation")); 162 194 } 163 195 164 196 int UIProgressDialog::run(int cRefreshInterval) 165 197 { 166 if (m_ progress.isOk())198 if (m_comProgress.isOk()) 167 199 { 168 200 /* Start refresh timer: */ … … 240 272 void UIProgressDialog::sltCancelOperation() 241 273 { 242 m_p CancelBtn->setEnabled(false);243 m_ progress.Cancel();274 m_pButtonCancel->setEnabled(false); 275 m_comProgress.Cancel(); 244 276 } 245 277 … … 259 291 return; 260 292 261 if (!m_fEnded && (!m_ progress.isOk() || m_progress.GetCompleted()))293 if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted())) 262 294 { 263 295 /* Is this progress-dialog a top-level modal-dialog now? */ … … 265 297 { 266 298 /* Progress finished: */ 267 if (m_ progress.isOk())299 if (m_comProgress.isOk()) 268 300 { 269 301 m_pProgressBar->setValue(100); … … 284 316 285 317 /* Update the progress dialog: */ 286 if (!m_ progress.GetCanceled())318 if (!m_comProgress.GetCanceled()) 287 319 { 288 320 /* Update ETA: */ 289 long newTime = m_progress.GetTimeRemaining();290 long seconds;291 long minutes;292 long hours;293 long days;294 295 seconds = newTime < 0 ? 0 : newTime;296 minutes = seconds / 60;297 seconds -= minutes * 60;298 hours = minutes / 60;299 minutes -= hours * 60;300 days = hours / 24;301 hours -= days * 24;302 303 QString strDays = VBoxGlobal::daysToString(days);304 QString strHours = VBoxGlobal::hoursToString(hours);305 QString strMinutes = VBoxGlobal::minutesToString(minutes);306 QString strSeconds = VBoxGlobal::secondsToString(seconds);307 308 QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\"");309 QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\"");310 311 if ( days > 1 && hours > 0)312 m_p EtaLbl->setText(strTwoComp.arg(strDays).arg(strHours));313 else if ( days > 1)314 m_p EtaLbl->setText(strOneComp.arg(strDays));315 else if ( days > 0 && hours > 0)316 m_p EtaLbl->setText(strTwoComp.arg(strDays).arg(strHours));317 else if ( days > 0 && minutes > 5)318 m_p EtaLbl->setText(strTwoComp.arg(strDays).arg(strMinutes));319 else if ( days > 0)320 m_p EtaLbl->setText(strOneComp.arg(strDays));321 else if ( hours > 2)322 m_p EtaLbl->setText(strOneComp.arg(strHours));323 else if ( hours > 0 && minutes > 0)324 m_p EtaLbl->setText(strTwoComp.arg(strHours).arg(strMinutes));325 else if ( hours > 0)326 m_p EtaLbl->setText(strOneComp.arg(strHours));327 else if ( minutes > 2)328 m_p EtaLbl->setText(strOneComp.arg(strMinutes));329 else if ( minutes > 0 && seconds > 5)330 m_p EtaLbl->setText(strTwoComp.arg(strMinutes).arg(strSeconds));331 else if ( minutes > 0)332 m_p EtaLbl->setText(strOneComp.arg(strMinutes));333 else if ( seconds > 5)334 m_p EtaLbl->setText(strOneComp.arg(strSeconds));335 else if ( seconds > 0)336 m_p EtaLbl->setText(tr("A few seconds remaining"));321 const long iNewTime = m_comProgress.GetTimeRemaining(); 322 long iSeconds; 323 long iMinutes; 324 long iHours; 325 long iDays; 326 327 iSeconds = iNewTime < 0 ? 0 : iNewTime; 328 iMinutes = iSeconds / 60; 329 iSeconds -= iMinutes * 60; 330 iHours = iMinutes / 60; 331 iMinutes -= iHours * 60; 332 iDays = iHours / 24; 333 iHours -= iDays * 24; 334 335 const QString strDays = VBoxGlobal::daysToString(iDays); 336 const QString strHours = VBoxGlobal::hoursToString(iHours); 337 const QString strMinutes = VBoxGlobal::minutesToString(iMinutes); 338 const QString strSeconds = VBoxGlobal::secondsToString(iSeconds); 339 340 const QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\""); 341 const QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\""); 342 343 if (iDays > 1 && iHours > 0) 344 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours)); 345 else if (iDays > 1) 346 m_pLabelEta->setText(strOneComp.arg(strDays)); 347 else if (iDays > 0 && iHours > 0) 348 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours)); 349 else if (iDays > 0 && iMinutes > 5) 350 m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strMinutes)); 351 else if (iDays > 0) 352 m_pLabelEta->setText(strOneComp.arg(strDays)); 353 else if (iHours > 2) 354 m_pLabelEta->setText(strOneComp.arg(strHours)); 355 else if (iHours > 0 && iMinutes > 0) 356 m_pLabelEta->setText(strTwoComp.arg(strHours).arg(strMinutes)); 357 else if (iHours > 0) 358 m_pLabelEta->setText(strOneComp.arg(strHours)); 359 else if (iMinutes > 2) 360 m_pLabelEta->setText(strOneComp.arg(strMinutes)); 361 else if (iMinutes > 0 && iSeconds > 5) 362 m_pLabelEta->setText(strTwoComp.arg(strMinutes).arg(strSeconds)); 363 else if (iMinutes > 0) 364 m_pLabelEta->setText(strOneComp.arg(strMinutes)); 365 else if (iSeconds > 5) 366 m_pLabelEta->setText(strOneComp.arg(strSeconds)); 367 else if (iSeconds > 0) 368 m_pLabelEta->setText(tr("A few seconds remaining")); 337 369 else 338 m_p EtaLbl->clear();370 m_pLabelEta->clear(); 339 371 340 372 /* Then operation text (if changed): */ 341 ulong newOp = m_progress.GetOperation() + 1;342 if ( newOp != m_iCurrentOperation)373 ulong uNewOp = m_comProgress.GetOperation() + 1; 374 if (uNewOp != m_uCurrentOperation) 343 375 { 344 m_ iCurrentOperation = newOp;345 m_p DescriptionLbl->setText(QString(m_spcszOpDescTpl)346 .arg(m_ progress.GetOperationDescription())347 .arg(m_ iCurrentOperation).arg(m_cOperations));376 m_uCurrentOperation = uNewOp; 377 m_pLabelDescription->setText(QString(m_spcszOpDescTpl) 378 .arg(m_comProgress.GetOperationDescription()) 379 .arg(m_uCurrentOperation).arg(m_cOperations)); 348 380 } 349 381 /* Update operation percentage: */ 350 m_pProgressBar->setValue(m_ progress.GetPercent());382 m_pProgressBar->setValue(m_comProgress.GetPercent()); 351 383 352 384 /* Then cancel button: */ 353 m_fCancelEnabled = m_ progress.GetCancelable();354 m_p CancelBtn->setEnabled(m_fCancelEnabled);385 m_fCancelEnabled = m_comProgress.GetCancelable(); 386 m_pButtonCancel->setEnabled(m_fCancelEnabled); 355 387 356 388 /* Notify listeners about the operation progress update: */ 357 emit sigProgressChange(m_cOperations, m_ progress.GetOperationDescription(),358 m_ progress.GetOperation() + 1, m_progress.GetPercent());389 emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(), 390 m_comProgress.GetOperation() + 1, m_comProgress.GetPercent()); 359 391 } 360 392 /* Mark progress canceled if so: */ 361 393 else 362 m_p EtaLbl->setText(m_strCancel);394 m_pLabelEta->setText(tr("Canceling...")); 363 395 } 364 396 … … 366 398 UIProgress::UIProgress(CProgress &progress, QObject *pParent /* = 0 */) 367 399 : QObject(pParent) 368 , m_ progress(progress)369 , m_cOperations(m_ progress.GetOperationCount())400 , m_comProgress(progress) 401 , m_cOperations(m_comProgress.GetOperationCount()) 370 402 , m_fEnded(false) 371 403 { … … 375 407 { 376 408 /* Make sure the CProgress still valid: */ 377 if (!m_ progress.isOk())409 if (!m_comProgress.isOk()) 378 410 return; 379 411 … … 411 443 412 444 /* If progress had failed or finished: */ 413 if (!m_ progress.isOk() || m_progress.GetCompleted())445 if (!m_comProgress.isOk() || m_comProgress.GetCompleted()) 414 446 { 415 447 /* Notify listeners about the operation progress error: */ 416 if (!m_ progress.isOk() || m_progress.GetResultCode() != 0)417 emit sigProgressError(UIErrorString::formatErrorInfo(m_ progress));448 if (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0) 449 emit sigProgressError(UIErrorString::formatErrorInfo(m_comProgress)); 418 450 419 451 /* Exit from the event-loop if there is any: */ … … 429 461 430 462 /* If CProgress was not yet canceled: */ 431 if (!m_ progress.GetCanceled())463 if (!m_comProgress.GetCanceled()) 432 464 { 433 465 /* Notify listeners about the operation progress update: */ 434 emit sigProgressChange(m_cOperations, m_ progress.GetOperationDescription(),435 m_ progress.GetOperation() + 1, m_progress.GetPercent());436 } 437 } 438 466 emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(), 467 m_comProgress.GetOperation() + 1, m_comProgress.GetPercent()); 468 } 469 } 470 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h
r68998 r68999 16 16 */ 17 17 18 #ifndef __ UIProgressDialog_h__19 #define __ UIProgressDialog_h__18 #ifndef ___UIProgressDialog_h___ 19 #define ___UIProgressDialog_h___ 20 20 21 21 /* GUI includes: */ … … 37 37 * @note The CProgress instance is passed as a non-const reference to the constructor (to memorize COM errors if they happen), 38 38 * and therefore must not be destroyed before the created UIProgressDialog instance is destroyed. */ 39 class UIProgressDialog : public QIWithRetranslateUI2<QIDialog>39 class UIProgressDialog : public QIWithRetranslateUI2<QIDialog> 40 40 { 41 41 Q_OBJECT; … … 44 44 45 45 /** Constructs progress-dialog passing @a pParent to the base-class. 46 * @param progress Brings the progress reference.46 * @param comProgress Brings the progress reference. 47 47 * @param strTitle Brings the progress-dialog title. 48 48 * @param pImage Brings the progress-dialog image. 49 49 * @param cMinDuration Brings the minimum duration before the progress-dialog is shown. */ 50 UIProgressDialog(CProgress & progress, const QString &strTitle,50 UIProgressDialog(CProgress &comProgress, const QString &strTitle, 51 51 QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0); 52 52 /** Destructs progress-dialog. */ 53 ~UIProgressDialog();53 virtual ~UIProgressDialog() /* override */; 54 54 55 55 /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */ 56 int run(int aRefreshInterval);56 int run(int iRefreshInterval); 57 57 58 58 signals: … … 74 74 75 75 /** Handles translation event. */ 76 v oid retranslateUi();76 virtual void retranslateUi() /* override */; 77 77 78 78 /** Rejects dialog. */ 79 v oid reject();79 virtual void reject() /* override */; 80 80 81 81 /** Handles timer @a pEvent. */ 82 virtual void timerEvent(QTimerEvent *pEvent) ;82 virtual void timerEvent(QTimerEvent *pEvent) /* override */; 83 83 /** Handles close @a pEvent. */ 84 virtual void closeEvent(QCloseEvent *pEvent) ;84 virtual void closeEvent(QCloseEvent *pEvent) /* override */; 85 85 86 86 private slots: … … 95 95 96 96 /** Holds the progress reference. */ 97 CProgress &m_ progress;97 CProgress &m_comProgress; 98 98 99 99 /** Holds the image label instance. */ 100 QLabel *m_p ImageLbl;100 QLabel *m_pLabelImage; 101 101 /** Holds the description label instance. */ 102 QILabel *m_p DescriptionLbl;102 QILabel *m_pLabelDescription; 103 103 /** Holds the progress-bar instance. */ 104 104 QProgressBar *m_pProgressBar; 105 105 /** Holds the cancel button instance. */ 106 UIMiniCancelButton *m_p CancelBtn;106 UIMiniCancelButton *m_pButtonCancel; 107 107 /** Holds the ETA label instance. */ 108 QILabel *m_p EtaLbl;108 QILabel *m_pLabelEta; 109 109 110 110 /** Holds whether progress cancel is enabled. */ 111 111 bool m_fCancelEnabled; 112 /** Holds the translated canceling tag. */113 QString m_strCancel;114 112 /** Holds the amount of operations. */ 115 113 const ulong m_cOperations; 116 114 /** Holds the number of current operation. */ 117 ulong m_ iCurrentOperation;115 ulong m_uCurrentOperation; 118 116 /** Holds whether the progress has ended. */ 119 117 bool m_fEnded; … … 151 149 152 150 /** Constructs progress handler passing @a pParent to the base-class. 153 * @param progress Brings the progress reference. */154 UIProgress(CProgress & progress, QObject *pParent = 0);151 * @param comProgress Brings the progress reference. */ 152 UIProgress(CProgress &comProgress, QObject *pParent = 0); 155 153 156 154 /** Executes the progress-handler within its loop with passed @a iRefreshInterval. */ … … 160 158 161 159 /** Handles timer @a pEvent. */ 162 virtual void timerEvent(QTimerEvent *pEvent) ;160 virtual void timerEvent(QTimerEvent *pEvent) /* override */; 163 161 164 162 /** Holds the progress reference. */ 165 CProgress &m_ progress;163 CProgress &m_comProgress; 166 164 167 165 /** Holds the amount of operations. */ … … 174 172 }; 175 173 176 #endif /* !__ UIProgressDialog_h__ */174 #endif /* !___UIProgressDialog_h___ */ 177 175
Note:
See TracChangeset
for help on using the changeset viewer.

