2020-09-21 20:36:46 +02:00
|
|
|
#include "download_payload_page.hpp"
|
2021-09-11 15:48:13 +02:00
|
|
|
|
2021-02-10 17:28:47 +01:00
|
|
|
#include "confirm_page.hpp"
|
|
|
|
#include "download.hpp"
|
2021-03-16 15:56:46 +01:00
|
|
|
#include "fs.hpp"
|
2021-09-11 15:48:13 +02:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include "worker_page.hpp"
|
2021-03-16 15:56:46 +01:00
|
|
|
|
2020-10-06 00:53:12 +02:00
|
|
|
namespace i18n = brls::i18n;
|
|
|
|
using namespace i18n::literals;
|
2021-09-15 17:23:37 +02:00
|
|
|
DownloadPayloadPage::DownloadPayloadPage(const nlohmann::ordered_json& payloads) : AppletFrame(true, true)
|
2020-09-21 20:36:46 +02:00
|
|
|
{
|
2021-03-10 21:54:17 +01:00
|
|
|
this->setTitle("menus/payloads/dl_payloads"_i18n);
|
2020-09-21 20:36:46 +02:00
|
|
|
list = new brls::List();
|
|
|
|
label = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
2021-09-11 15:48:13 +02:00
|
|
|
"menus/payloads/select"_i18n + std::string(BOOTLOADER_PL_PATH) + ".",
|
|
|
|
true);
|
2020-09-21 20:36:46 +02:00
|
|
|
list->addView(label);
|
2021-09-11 15:48:13 +02:00
|
|
|
|
2021-09-15 17:23:37 +02:00
|
|
|
auto links = download::getLinksFromJson(payloads);
|
2021-09-11 15:48:13 +02:00
|
|
|
if (links.size()) {
|
|
|
|
for (const auto& link : links) {
|
2021-03-16 15:56:46 +01:00
|
|
|
std::string url = link.second;
|
|
|
|
std::string path = std::string(BOOTLOADER_PL_PATH) + link.first;
|
|
|
|
std::string text("menus/common/download"_i18n + link.first + "menus/common/from"_i18n + url);
|
|
|
|
listItem = new brls::ListItem(link.first);
|
2021-10-03 19:54:09 +02:00
|
|
|
listItem->getClickEvent()->subscribe([text, url, path](brls::View* view) {
|
2021-03-16 15:56:46 +01:00
|
|
|
fs::createTree(BOOTLOADER_PL_PATH);
|
2020-09-21 20:36:46 +02:00
|
|
|
brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame();
|
2021-05-21 18:12:58 +02:00
|
|
|
stagedFrame->setTitle("menus/tools/getting_payload"_i18n);
|
2020-09-21 20:36:46 +02:00
|
|
|
stagedFrame->addStage(
|
2021-09-11 15:48:13 +02:00
|
|
|
new ConfirmPage(stagedFrame, text));
|
2020-09-21 20:36:46 +02:00
|
|
|
stagedFrame->addStage(
|
2021-09-27 21:56:41 +02:00
|
|
|
new WorkerPage(stagedFrame, "menus/common/downloading"_i18n, [url, path]() { download::downloadFile(url, path, OFF); }));
|
2020-09-21 20:36:46 +02:00
|
|
|
stagedFrame->addStage(
|
2021-09-11 15:48:13 +02:00
|
|
|
new ConfirmPage(stagedFrame, "menus/common/all_done"_i18n, true));
|
2020-09-21 20:36:46 +02:00
|
|
|
brls::Application::pushView(stagedFrame);
|
|
|
|
});
|
2021-02-08 21:30:58 +01:00
|
|
|
list->addView(listItem);
|
2020-09-21 20:36:46 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-11 15:48:13 +02:00
|
|
|
else {
|
2020-09-21 20:36:46 +02:00
|
|
|
notFound = new brls::Label(
|
|
|
|
brls::LabelStyle::DESCRIPTION,
|
2022-05-16 16:35:42 +02:00
|
|
|
"menus/main/links_not_found"_i18n,
|
2021-09-11 15:48:13 +02:00
|
|
|
true);
|
2020-09-21 20:36:46 +02:00
|
|
|
notFound->setHorizontalAlign(NVG_ALIGN_CENTER);
|
|
|
|
list->addView(notFound);
|
2021-03-10 21:54:17 +01:00
|
|
|
brls::ListItem* back = new brls::ListItem("menus/common/back"_i18n);
|
2021-10-01 19:22:52 +02:00
|
|
|
back->getClickEvent()->subscribe([](brls::View* view) {
|
2020-09-23 13:21:05 +02:00
|
|
|
brls::Application::popView();
|
|
|
|
});
|
2021-09-11 15:48:13 +02:00
|
|
|
list->addView(back);
|
2020-09-21 20:36:46 +02:00
|
|
|
}
|
|
|
|
this->setContentView(list);
|
|
|
|
}
|