}
}
+void
+AddonManager::abort_install()
+{
+ log_info << "addon install aborted" << std::endl;
+
+ m_downloader.abort(m_transfer_status->id);
+
+ m_install_request = {};
+ m_install_status = {};
+ m_transfer_status = {};
+}
+
/* EOF */
Addon& get_installed_addon(const AddonId& addon);
InstallStatusPtr request_install_addon(const AddonId& addon_id);
+ void abort_install();
void install_addon(const AddonId& addon_id);
void uninstall_addon(const AddonId& addon_id);
size_t on_data(void* ptr, size_t size, size_t nmemb)
{
- return 0;
+ return size * nmemb;;
}
void on_progress(curl_off_t dltotal, curl_off_t dlnow,
CURLMcode ret;
int running_handles;
while((ret = curl_multi_perform(m_multi_handle, &running_handles)) == CURLM_CALL_MULTI_PERFORM)
- {}
+ {
+ log_debug << "updating" << std::endl;
+ }
// check if any downloads got finished
int msgs_in_queue;
void event(const SDL_Event& event);
void process_input(const Controller& controller);
void draw(DrawingContext& context);
+ virtual void update() {}
private:
void on_button_click(int button) const;
{
if (m_dialog)
{
+ m_dialog->update();
m_dialog->draw(context);
}
else if (current_menu())
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "supertux/menu/addon_dialog.hpp"
+
+#include <sstream>
+
+#include "gui/menu_manager.hpp"
+#include "util/gettext.hpp"
+
+AddonDialog::AddonDialog(AddonManager::InstallStatusPtr status) :
+ m_status(status)
+{
+ add_button(_("Abort Download"), [this]{
+ on_abort();
+ });
+
+ update_text();
+}
+
+void
+AddonDialog::update()
+{
+ AddonManager::current()->update();
+
+ if (m_status->done)
+ {
+ MenuManager::instance().set_dialog({});
+ }
+}
+
+void
+AddonDialog::update_text()
+{
+ std::ostringstream out;
+ out << "Downloading in Progress:\n"
+ << m_status->now << "/" << m_status->total;
+ set_text(out.str());
+}
+
+void
+AddonDialog::on_abort()
+{
+ AddonManager::current()->abort_install();
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_SUPERTUX_MENU_ADDON_DIALOG_HPP
+#define HEADER_SUPERTUX_SUPERTUX_MENU_ADDON_DIALOG_HPP
+
+#include "addon/addon_manager.hpp"
+#include "gui/dialog.hpp"
+
+class AddonDialog : public Dialog
+{
+private:
+ AddonManager::InstallStatusPtr m_status;
+
+public:
+ AddonDialog(AddonManager::InstallStatusPtr status);
+
+ void update() override;
+
+private:
+ void on_abort();
+ void update_text();
+
+private:
+ AddonDialog(const AddonDialog&) = delete;
+ AddonDialog& operator=(const AddonDialog&) = delete;
+};
+
+#endif
+
+/* EOF */
#include "addon/addon_manager.hpp"
#include "gui/menu.hpp"
#include "gui/menu_item.hpp"
+#include "gui/menu_manager.hpp"
+#include "supertux/menu/addon_dialog.hpp"
#include "util/gettext.hpp"
namespace {
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());
+
+ std::unique_ptr<AddonDialog> dialog(new AddonDialog(status));
+ MenuManager::instance().set_dialog(std::move(dialog));
+#ifdef GRUMBEL
try
{
m_addon_manager.install_addon(addon.get_id());
log_warning << "Enabling addon failed: " << err.what() << std::endl;
}
refresh();
+#endif
}
}
}