void AddonMenu::install_addon(const Addon& addon) { auto addon_id = addon.get_id(); TransferStatusPtr status = m_addon_manager.request_install_addon(addon_id); std::unique_ptr<DownloadDialog> dialog(new DownloadDialog(status, false, m_auto_install_langpack)); dialog->set_title(str(boost::format( _("Downloading %s") ) % generate_menu_item_text(addon))); status->then([this, addon_id](bool success) { if (success) { try { m_addon_manager.enable_addon(addon_id); if(m_auto_install_langpack) { MenuManager::instance().set_dialog({}); MenuManager::instance().clear_menu_stack(); return; } } catch(const std::exception& err) { log_warning << "Enabling add-on failed: " << err.what() << std::endl; } refresh(); } else { if(m_auto_install_langpack) { MenuManager::instance().set_dialog({}); MenuManager::instance().clear_menu_stack(); } } }); MenuManager::instance().set_dialog(std::move(dialog)); }
void AddonMenu::check_online() { try { TransferStatusPtr status = m_addon_manager.request_check_online(); status->then([this](bool success) { if (success) { if(m_auto_install_langpack) { const std::string& langpack_id = "langpack-" + g_dictionary_manager->get_language().get_language(); install_addon(m_addon_manager.get_repository_addon(langpack_id)); } else { refresh(); } } else { if(m_auto_install_langpack) { MenuManager::instance().set_dialog({}); MenuManager::instance().clear_menu_stack(); } } }); std::unique_ptr<DownloadDialog> dialog(new DownloadDialog(status, false, m_auto_install_langpack)); dialog->set_title(_("Downloading Add-On Repository Index")); MenuManager::instance().set_dialog(std::move(dialog)); } catch (std::exception& e) { log_warning << "Check for available Add-ons failed: " << e.what() << std::endl; } }
void AddonMenu::menu_action(MenuItem* item) { if (item->id == MNID_CHECK_ONLINE) // check if "Check Online" was chosen { try { TransferStatusPtr status = m_addon_manager.request_check_online(); status->then( [this](bool success) { if (success) { refresh(); } }); std::unique_ptr<DownloadDialog> dialog(new DownloadDialog(status)); dialog->set_title(_("Downloading Add-On Repository Index")); MenuManager::instance().set_dialog(std::move(dialog)); } catch (std::exception& e) { log_warning << "Check for available Add-ons failed: " << e.what() << std::endl; } } else if (MNID_ADDON_LIST_START <= item->id) { if (IS_INSTALLED_MENU_ID(item->id)) { int idx = UNPACK_INSTALLED_MENU_ID(item->id); if (0 <= idx && idx < static_cast<int>(m_installed_addons.size())) { const Addon& addon = m_addon_manager.get_installed_addon(m_installed_addons[idx]); if(addon.is_enabled()) { m_addon_manager.disable_addon(addon.get_id()); set_toggled(item->id, addon.is_enabled()); } else { m_addon_manager.enable_addon(addon.get_id()); set_toggled(item->id, addon.is_enabled()); } } } else if (IS_REPOSITORY_MENU_ID(item->id)) { int idx = UNPACK_REPOSITORY_MENU_ID(item->id); if (0 <= idx && idx < static_cast<int>(m_repository_addons.size())) { const Addon& addon = m_addon_manager.get_repository_addon(m_repository_addons[idx]); auto addon_id = addon.get_id(); TransferStatusPtr status = m_addon_manager.request_install_addon(addon_id); status->then( [this, addon_id](bool success) { if (success) { try { m_addon_manager.enable_addon(addon_id); } catch(const std::exception& err) { log_warning << "Enabling addon failed: " << err.what() << std::endl; } refresh(); } }); std::unique_ptr<DownloadDialog> dialog(new DownloadDialog(status)); dialog->set_title(str(boost::format( _("Downloading %s") ) % generate_menu_item_text(addon))); MenuManager::instance().set_dialog(std::move(dialog)); } } } else { log_warning << "Unknown menu item clicked: " << item->id << std::endl; } }