Qt: hotfix for downloader

I accidentally broke the download progress bar in the last related PR.
I should've put more trust in the sanity of the younger version of myself.
This should fix it.
This commit is contained in:
Megamouse 2021-01-18 22:01:13 +01:00
parent f9bc682115
commit 62cb532460

View file

@ -21,14 +21,13 @@ downloader::downloader(QWidget* parent)
, m_parent(parent) , m_parent(parent)
, m_curl(new curl_handle(this)) , m_curl(new curl_handle(this))
{ {
connect(this, &downloader::signal_buffer_update, this, &downloader::handle_buffer_update);
} }
downloader::~downloader() downloader::~downloader()
{ {
m_curl_abort = true;
if (m_thread && m_thread->isRunning()) if (m_thread && m_thread->isRunning())
{ {
m_curl_abort = true;
m_thread->wait(); m_thread->wait();
} }
} }
@ -37,9 +36,9 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
{ {
if (m_thread) if (m_thread)
{ {
m_curl_abort = true;
if (m_thread->isRunning()) if (m_thread->isRunning())
{ {
m_curl_abort = true;
m_thread->wait(); m_thread->wait();
} }
m_thread->deleteLater(); m_thread->deleteLater();
@ -86,6 +85,10 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
} }
}); });
// The downloader's signals are expected to be disconnected and customized before start is called.
// Therefore we need to (re)connect its signal(s) here and not in the constructor.
connect(this, &downloader::signal_buffer_update, this, &downloader::handle_buffer_update);
if (show_progress_dialog) if (show_progress_dialog)
{ {
const int maximum = exptected_size > 0 ? exptected_size : 100; const int maximum = exptected_size > 0 ? exptected_size : 100;