Cancel update checker thread when user presses Esc button.

This commit is contained in:
LoRd_MuldeR 2017-03-28 21:12:02 +02:00
parent f5e0cefc9b
commit a3ffa83971
3 changed files with 32 additions and 2 deletions

View File

@ -564,6 +564,19 @@
<property name="margin"> <property name="margin">
<number>10</number> <number>10</number>
</property> </property>
<item>
<widget class="QLabel" name="cancelLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Press Esc button to cancel update check...</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 5 #define VER_LAMEXP_MINOR_LO 5
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 1 #define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 1960 #define VER_LAMEXP_BUILD 1964
#define VER_LAMEXP_CONFG 1934 #define VER_LAMEXP_CONFG 1934
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -173,6 +173,7 @@ void UpdateDialog::showEvent(QShowEvent *event)
ui->hintLabel->hide(); ui->hintLabel->hide();
ui->hintIcon->hide(); ui->hintIcon->hide();
ui->frameAnimation->hide(); ui->frameAnimation->hide();
ui->cancelLabel->hide();
ui->progressBar->setMaximum(m_thread->getMaximumProgress()); ui->progressBar->setMaximum(m_thread->getMaximumProgress());
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
@ -199,7 +200,16 @@ void UpdateDialog::closeEvent(QCloseEvent *event)
void UpdateDialog::keyPressEvent(QKeyEvent *e) void UpdateDialog::keyPressEvent(QKeyEvent *e)
{ {
if(e->key() == Qt::Key_F11) if (e->key() == Qt::Key_Escape)
{
if (!m_thread.isNull() && m_thread->isRunning())
{
ui->cancelLabel->hide();
ui->statusLabel->setText(tr("Stopping update check, please wait..."));
m_thread->cancel();
}
}
else if(e->key() == Qt::Key_F11)
{ {
if(ui->closeButton->isEnabled()) logButtonClicked(); if(ui->closeButton->isEnabled()) logButtonClicked();
} }
@ -260,6 +270,7 @@ void UpdateDialog::checkForUpdates(void)
if(ui->infoLabel->isVisible()) ui->infoLabel->hide(); if(ui->infoLabel->isVisible()) ui->infoLabel->hide();
if(ui->hintLabel->isVisible()) ui->hintLabel->hide(); if(ui->hintLabel->isVisible()) ui->hintLabel->hide();
if(ui->hintIcon->isVisible()) ui->hintIcon->hide(); if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
ui->cancelLabel->show();
ui->frameAnimation->show(); ui->frameAnimation->show();
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@ -312,6 +323,11 @@ void UpdateDialog::threadStatusChanged(const int status)
SHOW_HINT(tr("Sorry, the update server might be busy at this time. Plase try again later."), ":/icons/server_error.png"); SHOW_HINT(tr("Sorry, the update server might be busy at this time. Plase try again later."), ":/icons/server_error.png");
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png"); UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
break; break;
case MUtils::UpdateChecker::UpdateStatus_CancelledByUser:
ui->statusLabel->setText(tr("Update check has been cancelled!"));
SHOW_HINT(tr("The update check has been cancelled by the user. Please try again later."), ":/icons/server_error.png");
UPDATE_TASKBAR(MUtils::Taskbar7::TASKBAR_STATE_NORMAL, ":/icons/exclamation.png");
break;
default: default:
qWarning("Unknown status %d !!!", int(status)); qWarning("Unknown status %d !!!", int(status));
} }
@ -332,6 +348,7 @@ void UpdateDialog::threadFinished(void)
const bool bSuccess = m_thread->getSuccess(); const bool bSuccess = m_thread->getSuccess();
ui->closeButton->setEnabled(true); ui->closeButton->setEnabled(true);
ui->cancelLabel->hide();
if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide(); if(ui->frameAnimation->isVisible()) ui->frameAnimation->hide();
ui->progressBar->setValue(ui->progressBar->maximum()); ui->progressBar->setValue(ui->progressBar->maximum());