UIProgressDialog.cpp revision 22da799f4b867c09a0929f33ea299b7592a5b986
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIProgressDialog class implementation
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Qt includes: */
#include <QCloseEvent>
#include <QEventLoop>
#include <QProgressBar>
#include <QTime>
#include <QTimer>
#include <QVBoxLayout>
/* GUI includes: */
#include "UIProgressDialog.h"
#include "QIDialogButtonBox.h"
#include "QILabel.h"
#include "UISpecialControls.h"
#include "VBoxGlobal.h"
#ifdef Q_WS_MAC
# include "VBoxUtils-darwin.h"
#endif /* Q_WS_MAC */
/* COM includes: */
#include "CProgress.h"
bool fSheetOnDarwin /* = false */,
int cMinDuration /* = 2000 */,
, m_pImageLbl(0)
, m_fCancelEnabled(false)
, m_fEnded(false)
{
/* Setup dialog: */
setModal(true);
/* Create main layout: */
#ifdef Q_WS_MAC
/* Check if Mac Sheet is allowed: */
{
}
::darwinSetHidesAllTitleButtons(this);
::darwinSetShowsResizeIndicator(this, false);
if (pImage)
else
#else /* Q_WS_MAC */
#endif /* !Q_WS_MAC */
/* Create image: */
if (pImage)
{
m_pImageLbl = new QLabel(this);
}
/* Create description: */
m_pDescriptionLbl = new QILabel(this);
if (m_cOperations > 1)
else
/* Create progress-bar: */
m_pProgressBar = new QProgressBar(this);
m_pProgressBar->setValue(0);
/* Create cancel button: */
m_pCancelBtn = new UIMiniCancelButton(this);
/* Create estimation label: */
/* Create proggress layout: */
pProgressLayout->setMargin(0);
/* Create description layout: */
/* Translate finally: */
/* The progress dialog will be shown automatically after
* the duration is over if progress is not finished yet. */
}
{
#ifdef Q_WS_MAC
/* Check if Mac Sheet was used: */
#endif /* Q_WS_MAC */
}
void UIProgressDialog::retranslateUi()
{
}
{
if (m_progress.isOk())
{
/* Start refresh timer */
/* Set busy cursor.
* We don't do this on the Mac, cause regarding the design rules of
* Apple there is no busy window behavior. A window should always be
* responsive and it is in our case (We show the progress dialog bar). */
#ifndef Q_WS_MAC
if (m_fCancelEnabled)
else
#endif /* Q_WS_MAC */
/* Enter the modal loop, but don't show the window immediately */
exec(false);
/* Kill refresh timer */
#ifndef Q_WS_MAC
/* Reset the busy cursor */
#endif /* Q_WS_MAC */
return result();
}
return Rejected;
}
void UIProgressDialog::reject()
{
if (m_fCancelEnabled)
}
{
/* We should hide progress-dialog
* if it was already finalized but not yet closed.
* This could happens in case of some other
* modal dialog prevents our event-loop from
* being exit overlapping 'this'. */
{
hide();
return;
}
else if (m_fEnded)
return;
{
/* Progress finished: */
if (m_progress.isOk())
{
}
/* Progress is not valid: */
else
/* Request to exit loop: */
m_fEnded = true;
return;
}
if (!m_progress.GetCanceled())
{
/* Update the progress dialog: */
/* First ETA */
long seconds;
long minutes;
long hours;
long days;
QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\"");
QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\"");
else if (days > 1)
else if (days > 0)
else if (hours > 2)
else if (hours > 0)
else if (minutes > 2)
else if (minutes > 0)
else if (seconds > 5)
else if (seconds > 0)
else
/* Then operation text if changed: */
if (newOp != m_iCurrentOperation)
{
}
/* Then cancel button: */
}
else
}
{
if (m_fCancelEnabled)
else
}
void UIProgressDialog::sltShowDialog()
{
/* We should not show progress-dialog
* if it was already finalized but not yet closed.
* This could happens in case of some other
* modal dialog prevents our event-loop from
* being exit overlapping 'this'. */
if (!m_fEnded)
show();
}
void UIProgressDialog::sltCancelOperation()
{
m_pCancelBtn->setEnabled(false);
m_progress.Cancel();
}