92bb812c50751f662faf2f2537dbc8ccaafaa43a
[supertux.git] / src / supertux / menu / addon_dialog.cpp
1 //  SuperTux
2 //  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "supertux/menu/addon_dialog.hpp"
18
19 #include <sstream>
20
21 #include "gui/menu_manager.hpp"
22 #include "util/gettext.hpp"
23
24 AddonDialog::AddonDialog(AddonManager::InstallStatusPtr status) :
25   m_status(status)
26 {
27   add_button(_("Abort Download"), [this]{
28       on_abort();
29     });
30
31   update_text();
32 }
33
34 void
35 AddonDialog::update()
36 {
37   AddonManager::current()->update();
38
39   update_text();
40
41   if (m_status->done)
42   {
43     MenuManager::instance().set_dialog({});
44   }
45 }
46
47 void
48 AddonDialog::update_text()
49 {
50   std::ostringstream out;
51   out << "Downloading in Progress:\n"
52       << m_status->now << "/" << m_status->total;
53   set_text(out.str());
54 }
55
56 void
57 AddonDialog::on_abort()
58 {
59   AddonManager::current()->abort_install();
60 }
61
62 /* EOF */