+ AddonManager& adm = AddonManager::get_instance();
+
+ // refresh list of installed addons
+ installed_addons = adm.get_installed_addons();
+
+ // build new Add-on list
+ addons.clear();
+
+ // add installed addons to list
+ addons.insert(addons.end(), installed_addons.begin(), installed_addons.end());
+
+ // add available addons to list
+ addons.insert(addons.end(), available_addons.begin(), available_addons.end());
+
+ // sort list
+ std::sort(addons.begin(), addons.end(), generate_addons_menu_sorter);
+
+ // remove available addons that are already installed
+ std::vector<Addon>::iterator it2 = addons.begin();
+ while (it2 != addons.end()) {
+ Addon addon = *it2;
+ if (addon.isInstalled) {
+ bool restart = false;
+ for (std::vector<Addon>::iterator it = addons.begin(); it != addons.end(); ++it) {
+ Addon addon2 = *it;
+ if ((addon2.equals(addon)) && (!addon2.isInstalled)) {
+ addons.erase(it);
+ restart = true;
+ break;
+ }
+ }
+ if (restart) {
+ it2 = addons.begin();
+ continue;
+ }
+ }
+ it2++;
+ }
+
+ // (re)generate menu
+ free_addons_menu();
+ addons_menu.reset(new Menu());
+
+ addons_menu->add_label(_("Add-ons"));
+ addons_menu->add_hl();
+
+#ifdef HAVE_LIBCURL
+ addons_menu->add_entry(0, std::string(_("Check Online")));
+#else
+ addons_menu->add_deactive(0, std::string(_("Check Online (disabled)")));
+#endif
+
+ //addons_menu->add_hl();
+
+ for (unsigned int i = 0; i < addons.size(); i++) {
+ Addon addon = addons[i];
+ std::string text = "";
+ if (addon.kind != "") text += addon.kind + " ";
+ text += std::string("\"") + addon.title + "\"";
+ if (addon.author != "") text += " by \"" + addon.author + "\"";
+ addons_menu->add_toggle(ADDON_LIST_START_ID + i, text, addon.isInstalled);
+ }
+
+ addons_menu->add_hl();
+ addons_menu->add_back(_("Back"));
+}
+
+void
+TitleScreen::check_addons_menu()
+{
+ int index = addons_menu->check();
+ if (index == -1) return;
+
+ // check if "Check Online" was chosen
+ if (index == 0) {
+ try {
+ available_addons = AddonManager::get_instance().get_available_addons();
+ generate_addons_menu();
+ Menu::set_current(addons_menu.get());
+ addons_menu->set_active_item(index);
+ }
+ catch (std::runtime_error e) {
+ log_warning << "Check for available Add-ons failed: " << e.what() << std::endl;
+ }
+ return;
+ }
+
+ // if one of the Addons listed was chosen, take appropriate action
+ if ((index >= ADDON_LIST_START_ID) && (index < ADDON_LIST_START_ID) + addons.size()) {
+ Addon addon = addons[index - ADDON_LIST_START_ID];
+ if (!addon.isInstalled) {
+ try {
+ addon.install();
+ generate_addons_menu();
+ Menu::set_current(addons_menu.get());
+ addons_menu->set_active_item(index);
+ }
+ catch (std::runtime_error e) {
+ log_warning << "Installation of Add-on failed: " << e.what() << std::endl;
+ }
+ } else {
+ try {
+ addon.remove();
+ generate_addons_menu();
+ Menu::set_current(addons_menu.get());
+ addons_menu->set_active_item(index);
+ }
+ catch (std::runtime_error e) {
+ log_warning << "Removal of Add-on failed: " << e.what() << std::endl;
+ }
+ }
+ }
+
+}
+
+void
+TitleScreen::free_addons_menu()
+{
+}