Adapted "update" dialog for recent MUtils changes + allow user to cancel the update checker thread by pressing Esc button.

This commit is contained in:
LoRd_MuldeR 2017-03-29 21:43:01 +02:00
parent 452c518605
commit 9e5cf62209
3 changed files with 74 additions and 12 deletions

View File

@ -598,6 +598,28 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="labelCancel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="baseSize">
<size>
<width>1</width>
<height>1</height>
</size>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="text">
<string>Press Esc button to cancel...</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">

View File

@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 7 #define VER_X264_MINOR 7
#define VER_X264_PATCH 9 #define VER_X264_PATCH 9
#define VER_X264_BUILD 1090 #define VER_X264_BUILD 1094
#define VER_X264_PORTABLE_EDITION (0) #define VER_X264_PORTABLE_EDITION (0)

View File

@ -112,6 +112,7 @@ UpdaterDialog::UpdaterDialog(QWidget *parent, const SysinfoModel *sysinfo, const
ui->buttonCancel->setEnabled(false); ui->buttonCancel->setEnabled(false);
ui->buttonRetry->hide(); ui->buttonRetry->hide();
ui->buttonDownload->hide(); ui->buttonDownload->hide();
ui->labelCancel->hide();
//Start animation //Start animation
SHOW_ANIMATION(true); SHOW_ANIMATION(true);
@ -170,24 +171,44 @@ void UpdaterDialog::closeEvent(QCloseEvent *e)
void UpdaterDialog::keyPressEvent(QKeyEvent *event) void UpdaterDialog::keyPressEvent(QKeyEvent *event)
{ {
if(event->key() == Qt::Key_F11) switch (event->key())
{ {
const QString logFilePath = MUtils::make_temp_file(MUtils::temp_folder(), "log", true); case Qt::Key_Escape:
if (!logFilePath.isEmpty()) if ((!m_thread.isNull()) && m_thread->isRunning())
{ {
QFile logFile(logFilePath); if (m_status >= MUtils::UpdateChecker::UpdateStatus_FetchingUpdates)
if (logFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{ {
logFile.write("\xEF\xBB\xBF"); UPDATE_TEXT(2, tr("Cancellation requested..."));
for (QStringList::ConstIterator iter = m_logFile.constBegin(); iter != m_logFile.constEnd(); iter++) }
else
{
UPDATE_TEXT(1, tr("Cancellation requested..."));
}
m_thread->cancel();
}
break;
case Qt::Key_F11:
{
const QString logFilePath = MUtils::make_temp_file(MUtils::temp_folder(), "log", true);
if (!logFilePath.isEmpty())
{
QFile logFile(logFilePath);
if (logFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{ {
logFile.write(iter->toUtf8()); logFile.write("\xEF\xBB\xBF");
logFile.write("\r\n"); for (QStringList::ConstIterator iter = m_logFile.constBegin(); iter != m_logFile.constEnd(); iter++)
{
logFile.write(iter->toUtf8());
logFile.write("\r\n");
}
logFile.close();
QDesktopServices::openUrl(QUrl::fromLocalFile(logFile.fileName()));
} }
logFile.close();
QDesktopServices::openUrl(QUrl::fromLocalFile(logFile.fileName()));
} }
} }
break;
default:
QDialog::keyPressEvent(event);
} }
} }
@ -262,6 +283,7 @@ void UpdaterDialog::checkForUpdates(void)
//Hide labels //Hide labels
ui->labelInfo->hide(); ui->labelInfo->hide();
ui->labelUrl->hide(); ui->labelUrl->hide();
ui->labelCancel->show();
//Update status //Update status
threadStatusChanged(MUtils::UpdateChecker::UpdateStatus_NotStartedYet); threadStatusChanged(MUtils::UpdateChecker::UpdateStatus_NotStartedYet);
@ -282,6 +304,7 @@ void UpdaterDialog::checkForUpdates(void)
void UpdaterDialog::threadStatusChanged(int status) void UpdaterDialog::threadStatusChanged(int status)
{ {
const int prevStatus = m_status;
switch(m_status = status) switch(m_status = status)
{ {
case MUtils::UpdateChecker::UpdateStatus_NotStartedYet: case MUtils::UpdateChecker::UpdateStatus_NotStartedYet:
@ -321,6 +344,21 @@ void UpdaterDialog::threadStatusChanged(int status)
UPDATE_TEXT(2, tr("Update information received successfully.")); UPDATE_TEXT(2, tr("Update information received successfully."));
UPDATE_ICON(3, "play"); UPDATE_ICON(3, "play");
break; break;
case MUtils::UpdateChecker::UpdateStatus_CancelledByUser:
if (prevStatus >= MUtils::UpdateChecker::UpdateStatus_FetchingUpdates)
{
UPDATE_ICON(2, "shield_error");
UPDATE_TEXT(2, tr("Operation was cancelled by the user!"));
UPDATE_ICON(3, "shield_grey");
}
else
{
UPDATE_ICON(1, "shield_error");
UPDATE_TEXT(1, tr("Operation was cancelled by the user!"));
UPDATE_ICON(2, "shield_grey");
UPDATE_ICON(3, "shield_grey");
}
break;
default: default:
MUTILS_THROW("Unknown status code!"); MUTILS_THROW("Unknown status code!");
} }
@ -330,6 +368,7 @@ void UpdaterDialog::threadFinished(void)
{ {
m_success = m_thread->getSuccess(); m_success = m_thread->getSuccess();
QTimer::singleShot((m_success ? 1000 : 0), this, SLOT(updateFinished())); QTimer::singleShot((m_success ? 1000 : 0), this, SLOT(updateFinished()));
ui->labelCancel->hide();
} }
void UpdaterDialog::updateFinished(void) void UpdaterDialog::updateFinished(void)
@ -373,6 +412,7 @@ void UpdaterDialog::updateFinished(void)
case MUtils::UpdateChecker::UpdateStatus_ErrorNoConnection: case MUtils::UpdateChecker::UpdateStatus_ErrorNoConnection:
case MUtils::UpdateChecker::UpdateStatus_ErrorConnectionTestFailed: case MUtils::UpdateChecker::UpdateStatus_ErrorConnectionTestFailed:
case MUtils::UpdateChecker::UpdateStatus_ErrorFetchUpdateInfo: case MUtils::UpdateChecker::UpdateStatus_ErrorFetchUpdateInfo:
case MUtils::UpdateChecker::UpdateStatus_CancelledByUser:
m_animator->stop(); m_animator->stop();
ui->buttonRetry->show(); ui->buttonRetry->show();
break; break;