|
1 | 1 | #include "views/game_view.hpp" |
2 | 2 | #include "activity/main_activity.hpp" |
3 | 3 |
|
| 4 | +#include <iomanip> |
| 5 | + |
4 | 6 | using namespace brls::literals; |
5 | 7 |
|
| 8 | +std::string convertSizeToString(const int size) { |
| 9 | + const int kio = 1024; |
| 10 | + const int mio = kio * kio; |
| 11 | + const int gio = mio * kio; |
| 12 | + |
| 13 | + std::string string_size; |
| 14 | + |
| 15 | + if (size < kio) { |
| 16 | + string_size = std::to_string(size) + " octets"; |
| 17 | + } else if (size < mio) { |
| 18 | + string_size = std::to_string(static_cast<double>(size) / kio) + " Ko"; |
| 19 | + } else if (size < gio) { |
| 20 | + string_size = std::to_string(static_cast<double>(size) / mio) + " Mo"; |
| 21 | + } else { |
| 22 | + string_size = std::to_string(static_cast<double>(size) / gio) + " Go"; |
| 23 | + } |
| 24 | + |
| 25 | + return string_size; |
| 26 | +} |
| 27 | + |
6 | 28 | GameView::GameView(Game game) : game(game) |
7 | 29 | { |
8 | 30 | this->inflateFromXMLRes("xml/views/game.xml"); |
@@ -36,8 +58,10 @@ GameView::GameView(Game game) : game(game) |
36 | 58 | publisher->setText(fmt::format("{} : N/A", "app/game/publisher"_i18n)); |
37 | 59 |
|
38 | 60 | //SIZE |
39 | | - if(game.getSize() > 0) |
40 | | - size->setText(fmt::format("{} : {}", "app/game/size"_i18n, game.getSize())); |
| 61 | + if(game.getSize() > 0) { |
| 62 | + std::string size_str = convertSizeToString(game.getSize()); |
| 63 | + size->setText(fmt::format("{} : {}", "app/game/size"_i18n, size_str)); |
| 64 | + } |
41 | 65 | else |
42 | 66 | size->setText(fmt::format("{} : N/A", "app/game/size"_i18n)); |
43 | 67 |
|
|
0 commit comments