From 0728722f37f25e3e41044023c6aaad04a2f49cc7 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 6 Dec 2019 20:53:43 +0800 Subject: [PATCH] Stop download too if dismiss dialog This can happen if other place calls dismiss dialog For example screen pushing by network protocols --- src/states_screens/dialogs/addons_loading.cpp | 5 ++--- src/states_screens/dialogs/addons_pack.cpp | 8 ++++++-- src/states_screens/dialogs/addons_pack.hpp | 1 + src/states_screens/dialogs/download_assets.cpp | 8 ++++++-- src/states_screens/dialogs/download_assets.hpp | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/states_screens/dialogs/addons_loading.cpp b/src/states_screens/dialogs/addons_loading.cpp index 484d27eaa..b49ed00ac 100644 --- a/src/states_screens/dialogs/addons_loading.cpp +++ b/src/states_screens/dialogs/addons_loading.cpp @@ -79,6 +79,7 @@ AddonsLoading::AddonsLoading(const std::string &id) */ AddonsLoading::~AddonsLoading() { + stopDownload(); // Select the last selected item in the addons_screen, so that // users can keep on installing from the last selected item. // This dialog can be called in network lobby screen atm for live addon @@ -191,7 +192,6 @@ void AddonsLoading::init() // ---------------------------------------------------------------------------- bool AddonsLoading::onEscapePressed() { - stopDownload(); ModalDialog::dismiss(); return true; } // onEscapePressed @@ -229,7 +229,6 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event if(selection == "back") { - stopDownload(); dismiss(); return GUIEngine::EVENT_BLOCK; } @@ -345,7 +344,7 @@ void AddonsLoading::stopDownload() { m_download_request->cancel(); m_download_request = nullptr; - }; + } } // startDownload diff --git a/src/states_screens/dialogs/addons_pack.cpp b/src/states_screens/dialogs/addons_pack.cpp index 2972722bb..227664721 100644 --- a/src/states_screens/dialogs/addons_pack.cpp +++ b/src/states_screens/dialogs/addons_pack.cpp @@ -116,6 +116,12 @@ AddonsPack::AddonsPack(const std::string& url) : ModalDialog(0.8f, 0.8f) m_download_request->queue(); } // AddonsPack +// ---------------------------------------------------------------------------- +AddonsPack::~AddonsPack() +{ + stopDownload(); +} // ~AddonsPack + // ---------------------------------------------------------------------------- void AddonsPack::beforeAddingWidgets() { @@ -131,7 +137,6 @@ void AddonsPack::init() // ---------------------------------------------------------------------------- bool AddonsPack::onEscapePressed() { - stopDownload(); ModalDialog::dismiss(); return true; } // onEscapePressed @@ -148,7 +153,6 @@ GUIEngine::EventPropagation AddonsPack::processEvent(const std::string& event_so actions_ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); if (selection == "back") { - stopDownload(); dismiss(); return GUIEngine::EVENT_BLOCK; } diff --git a/src/states_screens/dialogs/addons_pack.hpp b/src/states_screens/dialogs/addons_pack.hpp index 6c27abe15..0aa8a0656 100644 --- a/src/states_screens/dialogs/addons_pack.hpp +++ b/src/states_screens/dialogs/addons_pack.hpp @@ -41,6 +41,7 @@ private: * to the progress of a download. */ std::shared_ptr m_download_request; AddonsPack(const std::string& url); + ~AddonsPack(); public: virtual GUIEngine::EventPropagation processEvent(const std::string& event_source) OVERRIDE; virtual void beforeAddingWidgets() OVERRIDE; diff --git a/src/states_screens/dialogs/download_assets.cpp b/src/states_screens/dialogs/download_assets.cpp index 10acde8aa..721d7efe8 100644 --- a/src/states_screens/dialogs/download_assets.cpp +++ b/src/states_screens/dialogs/download_assets.cpp @@ -110,6 +110,12 @@ DownloadAssets::DownloadAssets() getWidget("description")->setText(msg); } // DownloadAssets +// ---------------------------------------------------------------------------- +DownloadAssets::~DownloadAssets() +{ + stopDownload(); +} // ~DownloadAssets + // ---------------------------------------------------------------------------- void DownloadAssets::beforeAddingWidgets() { @@ -125,7 +131,6 @@ void DownloadAssets::init() // ---------------------------------------------------------------------------- bool DownloadAssets::onEscapePressed() { - stopDownload(); ModalDialog::dismiss(); return true; } // onEscapePressed @@ -142,7 +147,6 @@ GUIEngine::EventPropagation DownloadAssets::processEvent(const std::string& even actions_ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); if (selection == "back") { - stopDownload(); dismiss(); return GUIEngine::EVENT_BLOCK; } diff --git a/src/states_screens/dialogs/download_assets.hpp b/src/states_screens/dialogs/download_assets.hpp index 49c813d72..98b8ace97 100644 --- a/src/states_screens/dialogs/download_assets.hpp +++ b/src/states_screens/dialogs/download_assets.hpp @@ -45,6 +45,7 @@ private: public: DownloadAssets(); + ~DownloadAssets(); virtual GUIEngine::EventPropagation processEvent(const std::string& event_source) OVERRIDE; virtual void beforeAddingWidgets() OVERRIDE;