Ref T419, download component style/myself guard

This commit is contained in:
Klaus Basan
2019-03-04 17:51:46 +01:00
committed by Mat Sutcliffe
parent 283b827a7a
commit 162cb3163c

View File

@@ -20,6 +20,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTimer> #include <QTimer>
#include <QPointer>
#include <QDesktopServices> #include <QDesktopServices>
using namespace BlackMisc; using namespace BlackMisc;
@@ -102,7 +103,12 @@ namespace BlackGui
if (!m_waitingForDownload.isEmpty()) { return false; } if (!m_waitingForDownload.isEmpty()) { return false; }
if (delayMs > 0) if (delayMs > 0)
{ {
QTimer::singleShot(delayMs, this, [ = ] { this->triggerDownloadingOfFiles(); }); const QPointer<CDownloadComponent> myself(this);
QTimer::singleShot(delayMs, this, [ = ]
{
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
this->triggerDownloadingOfFiles();
});
return true; return true;
} }
m_waitingForDownload = m_remoteFiles; m_waitingForDownload = m_remoteFiles;
@@ -125,7 +131,7 @@ namespace BlackGui
CDownloadComponent::Mode CDownloadComponent::getMode() const CDownloadComponent::Mode CDownloadComponent::getMode() const
{ {
Mode mode = ui->cb_Shutdown->isChecked() ? ShutdownSwift : JustDownload; Mode mode = ui->cb_Shutdown->isChecked() ? ShutdownSwift : JustDownload;
if (ui->cb_StartAfterDownload) mode |= StartAfterDownload; if (ui->cb_StartAfterDownload) { mode |= StartAfterDownload; }
return mode; return mode;
} }
@@ -228,7 +234,12 @@ namespace BlackGui
void CDownloadComponent::lastFileDownloaded() void CDownloadComponent::lastFileDownloaded()
{ {
QTimer::singleShot(0, this, &CDownloadComponent::allDownloadsCompleted); const QPointer<CDownloadComponent> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
this->allDownloadsCompleted();
});
this->startDownloadedExecutable(); this->startDownloadedExecutable();
} }
@@ -330,8 +341,8 @@ namespace BlackGui
void CDownloadComponent::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) void CDownloadComponent::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
ui->prb_Current->setMaximum(bytesTotal); ui->prb_Current->setMaximum(static_cast<int>(bytesTotal));
ui->prb_Current->setValue(bytesReceived); ui->prb_Current->setValue(static_cast<int>(bytesReceived));
} }
void CDownloadComponent::showFileInfo() void CDownloadComponent::showFileInfo()