Make curl a required dependency, compilation fails without it
[supertux.git] / src / supertux / menu / addon_menu.cpp
index 86776f5..7099296 100644 (file)
@@ -25,7 +25,7 @@
 #include "gui/menu.hpp"
 #include "gui/menu_item.hpp"
 #include "gui/menu_manager.hpp"
-#include "supertux/menu/addon_dialog.hpp"
+#include "supertux/menu/download_dialog.hpp"
 #include "util/gettext.hpp"
 
 namespace {
@@ -144,7 +144,7 @@ AddonMenu::rebuild_menu()
                     << installed_addon.get_version() << "' vs '" << addon.get_version() << "'"
                     << std::endl;
           std::string text = generate_menu_item_text(addon);
-          add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text + " *NEW*");
+          add_entry(MAKE_REPOSITORY_MENU_ID(idx), str(boost::format( _("Install %s *NEW*") ) % text));
           have_new_stuff = true;
         }
       }
@@ -152,7 +152,7 @@ AddonMenu::rebuild_menu()
       {
         // addon is not installed
         std::string text = generate_menu_item_text(addon);
-        add_entry(MAKE_REPOSITORY_MENU_ID(idx), "Install " + text);
+        add_entry(MAKE_REPOSITORY_MENU_ID(idx), str(boost::format( _("Install %s") ) % text));
         have_new_stuff = true;
       }
       idx += 1;
@@ -184,8 +184,18 @@ AddonMenu::menu_action(MenuItem* item)
   {
     try
     {
-      m_addon_manager.check_online();
-      refresh();
+      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)
     {
@@ -219,22 +229,26 @@ AddonMenu::menu_action(MenuItem* item)
       {
         const Addon& addon = m_addon_manager.get_repository_addon(m_repository_addons[idx]);
         auto addon_id = addon.get_id();
-        AddonManager::InstallStatusPtr status = m_addon_manager.request_install_addon(addon_id);
+        TransferStatusPtr status = m_addon_manager.request_install_addon(addon_id);
 
-        status->then([this, addon_id]{
-            try
+        status->then(
+          [this, addon_id](bool success)
+          {
+            if (success)
             {
-              m_addon_manager.enable_addon(addon_id);
+              try
+              {
+                m_addon_manager.enable_addon(addon_id);
+              }
+              catch(const std::exception& err)
+              {
+                log_warning << "Enabling addon failed: " << err.what() << std::endl;
+              }
+              refresh();
             }
-            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));
+        std::unique_ptr<DownloadDialog> dialog(new DownloadDialog(status));
         dialog->set_title("Downloading " + generate_menu_item_text(addon));
         MenuManager::instance().set_dialog(std::move(dialog));
       }