#include "util/gettext.hpp"
AddonDialog::AddonDialog(AddonManager::InstallStatusPtr status) :
- m_status(status)
+ m_status(status),
+ m_title()
{
add_button(_("Abort Download"), [this]{
on_abort();
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());
}
if (0 <= idx && idx < static_cast<int>(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<AddonDialog> 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;
}
}