From: Ingo Ruhnke Date: Tue, 26 Aug 2014 07:07:52 +0000 (+0200) Subject: Made AddonDialog output some prettier text, installation of Addons now seem to work X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9358ddb3f0036c213ee212621bf56d962541b77d;p=supertux.git Made AddonDialog output some prettier text, installation of Addons now seem to work Error handling is still largely missing for failed downloads and such --- diff --git a/src/supertux/menu/addon_dialog.cpp b/src/supertux/menu/addon_dialog.cpp index 92bb812c5..d4f47ec38 100644 --- a/src/supertux/menu/addon_dialog.cpp +++ b/src/supertux/menu/addon_dialog.cpp @@ -22,7 +22,8 @@ #include "util/gettext.hpp" AddonDialog::AddonDialog(AddonManager::InstallStatusPtr status) : - m_status(status) + m_status(status), + m_title() { add_button(_("Abort Download"), [this]{ on_abort(); @@ -35,21 +36,31 @@ void AddonDialog::update() { AddonManager::current()->update(); - update_text(); +} - if (m_status->done) - { - MenuManager::instance().set_dialog({}); - } +void +AddonDialog::set_title(const std::string& title) +{ + m_title = title; } void AddonDialog::update_text() { std::ostringstream out; - out << "Downloading in Progress:\n" - << m_status->now << "/" << m_status->total; + out << m_title << "\n"; + + if (m_status->total == 0) + { + out << "---\n---"; + } + else + { + int percent = 100 * m_status->now / m_status->total; + out << m_status->now/1000 << "/" << m_status->total/1000 << " kB\n" << percent << "%"; + } + set_text(out.str()); } diff --git a/src/supertux/menu/addon_dialog.hpp b/src/supertux/menu/addon_dialog.hpp index a45087617..1710ff8a1 100644 --- a/src/supertux/menu/addon_dialog.hpp +++ b/src/supertux/menu/addon_dialog.hpp @@ -24,14 +24,17 @@ class AddonDialog : public Dialog { private: AddonManager::InstallStatusPtr m_status; + std::string m_title; public: AddonDialog(AddonManager::InstallStatusPtr status); + void set_title(const std::string& title); void update() override; private: void on_abort(); + void update_text(); private: diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index 2abbe7bff..86776f550 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -218,29 +218,31 @@ 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()); + auto addon_id = addon.get_id(); + AddonManager::InstallStatusPtr status = m_addon_manager.request_install_addon(addon_id); + + status->then([this, addon_id]{ + try + { + m_addon_manager.enable_addon(addon_id); + } + catch(const std::exception& err) + { + log_warning << "Enabling addon failed: " << err.what() << std::endl; + } + MenuManager::instance().set_dialog({}); + refresh(); + }); std::unique_ptr dialog(new AddonDialog(status)); + dialog->set_title("Downloading " + generate_menu_item_text(addon)); MenuManager::instance().set_dialog(std::move(dialog)); -#ifdef GRUMBEL - try - { - m_addon_manager.install_addon(addon.get_id()); - m_addon_manager.enable_addon(addon.get_id()); - } - catch(const std::exception& err) - { - log_warning << "Enabling addon failed: " << err.what() << std::endl; - } - refresh(); -#endif } } } else { - log_warning << "Unknown menu item clicked: " << item->id << std::endl; + log_warning << "Unknown menu item clicked: " << item->id << std::endl; } }