void AddonMenu::menu_action(MenuItem* item) { if (item->id == MNID_CHECK_ONLINE) // check if "Check Online" was chosen { check_online(); } else if(item->id == MNID_LANGPACK_MODE) { m_language_pack_mode = !m_language_pack_mode; rebuild_menu(); on_window_resize(); return; } 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]); toggle_addon(addon); } } 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]); install_addon(addon); } } } else { log_warning << "Unknown menu item clicked: " << item->id << 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; } }