From: Ingo Ruhnke Date: Tue, 26 Aug 2014 04:59:30 +0000 (+0200) Subject: Added AddonDialog and connected it into the whole non-blocking update stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=140e8eab7d0732663de2c1f0a0f2edcc5bc1749f;p=supertux.git Added AddonDialog and connected it into the whole non-blocking update stuff --- diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index 866509302..62e8a7c44 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -571,4 +571,16 @@ AddonManager::update() } } +void +AddonManager::abort_install() +{ + log_info << "addon install aborted" << std::endl; + + m_downloader.abort(m_transfer_status->id); + + m_install_request = {}; + m_install_status = {}; + m_transfer_status = {}; +} + /* EOF */ diff --git a/src/addon/addon_manager.hpp b/src/addon/addon_manager.hpp index c5e65f8f9..a58f38cee 100644 --- a/src/addon/addon_manager.hpp +++ b/src/addon/addon_manager.hpp @@ -97,6 +97,7 @@ public: Addon& get_installed_addon(const AddonId& addon); InstallStatusPtr request_install_addon(const AddonId& addon_id); + void abort_install(); void install_addon(const AddonId& addon_id); void uninstall_addon(const AddonId& addon_id); diff --git a/src/addon/downloader.cpp b/src/addon/downloader.cpp index f1378bfc3..f40a14158 100644 --- a/src/addon/downloader.cpp +++ b/src/addon/downloader.cpp @@ -130,7 +130,7 @@ public: size_t on_data(void* ptr, size_t size, size_t nmemb) { - return 0; + return size * nmemb;; } void on_progress(curl_off_t dltotal, curl_off_t dlnow, @@ -244,7 +244,9 @@ Downloader::update() CURLMcode ret; int running_handles; while((ret = curl_multi_perform(m_multi_handle, &running_handles)) == CURLM_CALL_MULTI_PERFORM) - {} + { + log_debug << "updating" << std::endl; + } // check if any downloads got finished int msgs_in_queue; diff --git a/src/gui/dialog.hpp b/src/gui/dialog.hpp index 736614188..bb379c137 100644 --- a/src/gui/dialog.hpp +++ b/src/gui/dialog.hpp @@ -53,6 +53,7 @@ public: void event(const SDL_Event& event); void process_input(const Controller& controller); void draw(DrawingContext& context); + virtual void update() {} private: void on_button_click(int button) const; diff --git a/src/gui/menu_manager.cpp b/src/gui/menu_manager.cpp index 1bd6330aa..b493ba651 100644 --- a/src/gui/menu_manager.cpp +++ b/src/gui/menu_manager.cpp @@ -199,6 +199,7 @@ MenuManager::draw(DrawingContext& context) { if (m_dialog) { + m_dialog->update(); m_dialog->draw(context); } else if (current_menu()) diff --git a/src/supertux/menu/addon_dialog.cpp b/src/supertux/menu/addon_dialog.cpp new file mode 100644 index 000000000..bf0e00574 --- /dev/null +++ b/src/supertux/menu/addon_dialog.cpp @@ -0,0 +1,60 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "supertux/menu/addon_dialog.hpp" + +#include + +#include "gui/menu_manager.hpp" +#include "util/gettext.hpp" + +AddonDialog::AddonDialog(AddonManager::InstallStatusPtr status) : + m_status(status) +{ + add_button(_("Abort Download"), [this]{ + on_abort(); + }); + + update_text(); +} + +void +AddonDialog::update() +{ + AddonManager::current()->update(); + + if (m_status->done) + { + MenuManager::instance().set_dialog({}); + } +} + +void +AddonDialog::update_text() +{ + std::ostringstream out; + out << "Downloading in Progress:\n" + << m_status->now << "/" << m_status->total; + set_text(out.str()); +} + +void +AddonDialog::on_abort() +{ + AddonManager::current()->abort_install(); +} + +/* EOF */ diff --git a/src/supertux/menu/addon_dialog.hpp b/src/supertux/menu/addon_dialog.hpp new file mode 100644 index 000000000..a45087617 --- /dev/null +++ b/src/supertux/menu/addon_dialog.hpp @@ -0,0 +1,44 @@ +// SuperTux +// Copyright (C) 2014 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_ADDON_DIALOG_HPP +#define HEADER_SUPERTUX_SUPERTUX_MENU_ADDON_DIALOG_HPP + +#include "addon/addon_manager.hpp" +#include "gui/dialog.hpp" + +class AddonDialog : public Dialog +{ +private: + AddonManager::InstallStatusPtr m_status; + +public: + AddonDialog(AddonManager::InstallStatusPtr status); + + void update() override; + +private: + void on_abort(); + void update_text(); + +private: + AddonDialog(const AddonDialog&) = delete; + AddonDialog& operator=(const AddonDialog&) = delete; +}; + +#endif + +/* EOF */ diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index 91636f235..fa76a493b 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -24,6 +24,8 @@ #include "addon/addon_manager.hpp" #include "gui/menu.hpp" #include "gui/menu_item.hpp" +#include "gui/menu_manager.hpp" +#include "supertux/menu/addon_dialog.hpp" #include "util/gettext.hpp" namespace { @@ -224,6 +226,12 @@ AddonMenu::menu_action(MenuItem* item) if (0 <= idx && idx < static_cast(m_repository_addons.size())) { const Addon& addon = m_addon_manager.get_repository_addon(m_repository_addons[idx]); + + AddonManager::InstallStatusPtr status = m_addon_manager.request_install_addon(addon.get_id()); + + std::unique_ptr dialog(new AddonDialog(status)); + MenuManager::instance().set_dialog(std::move(dialog)); +#ifdef GRUMBEL try { m_addon_manager.install_addon(addon.get_id()); @@ -234,6 +242,7 @@ AddonMenu::menu_action(MenuItem* item) log_warning << "Enabling addon failed: " << err.what() << std::endl; } refresh(); +#endif } } }