2019-04-28 23:01:23 +00:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QtConcurrent/QtConcurrent>
|
|
|
|
#include "core/hle/service/bcat/backend/boxcat.h"
|
|
|
|
#include "core/settings.h"
|
|
|
|
#include "ui_configure_service.h"
|
|
|
|
#include "yuzu/configuration/configure_service.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
QString FormatEventStatusString(const Service::BCAT::EventStatus& status) {
|
|
|
|
QString out;
|
|
|
|
|
|
|
|
if (status.header.has_value()) {
|
|
|
|
out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.header));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.events.size() == 1) {
|
|
|
|
out += QStringLiteral("%1<br>").arg(QString::fromStdString(status.events.front()));
|
|
|
|
} else {
|
|
|
|
for (const auto event : status.events) {
|
|
|
|
out += QStringLiteral("- %1<br>").arg(QString::fromStdString(event));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.footer.has_value()) {
|
|
|
|
out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.footer));
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
ConfigureService::ConfigureService(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureService>()), watcher(this) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->bcat_source->addItem(QStringLiteral("None"));
|
|
|
|
ui->bcat_empty_label->setHidden(true);
|
|
|
|
ui->bcat_empty_header->setHidden(true);
|
|
|
|
|
|
|
|
#ifdef YUZU_ENABLE_BOXCAT
|
|
|
|
ui->bcat_source->addItem(QStringLiteral("Boxcat"), QStringLiteral("boxcat"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConfigureService::OnBCATImplChanged);
|
|
|
|
|
2019-06-21 00:31:17 +00:00
|
|
|
this->SetConfiguration();
|
2019-04-28 23:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureService::~ConfigureService() = default;
|
|
|
|
|
2019-06-21 00:31:17 +00:00
|
|
|
void ConfigureService::ApplyConfiguration() {
|
2019-04-28 23:01:23 +00:00
|
|
|
Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString();
|
|
|
|
}
|
|
|
|
|
2019-06-21 00:31:17 +00:00
|
|
|
void ConfigureService::RetranslateUi() {
|
2019-04-28 23:01:23 +00:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2019-06-21 00:31:17 +00:00
|
|
|
void ConfigureService::SetConfiguration() {
|
2019-04-28 23:01:23 +00:00
|
|
|
int index = ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend));
|
|
|
|
ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<QString, QString> ConfigureService::BCATDownloadEvents() {
|
|
|
|
std::optional<std::string> global;
|
|
|
|
std::map<std::string, Service::BCAT::EventStatus> map;
|
|
|
|
const auto res = Service::BCAT::Boxcat::GetStatus(global, map);
|
|
|
|
|
|
|
|
switch (res) {
|
|
|
|
case Service::BCAT::Boxcat::StatusResult::Offline:
|
2019-06-21 00:31:17 +00:00
|
|
|
return {QStringLiteral(""),
|
|
|
|
tr("The boxcat service is offline or you are not connected to the internet.")};
|
2019-04-28 23:01:23 +00:00
|
|
|
case Service::BCAT::Boxcat::StatusResult::ParseError:
|
2019-06-21 00:31:17 +00:00
|
|
|
return {QStringLiteral(""),
|
2019-04-28 23:01:23 +00:00
|
|
|
tr("There was an error while processing the boxcat event data. Contact the yuzu "
|
|
|
|
"developers.")};
|
|
|
|
case Service::BCAT::Boxcat::StatusResult::BadClientVersion:
|
2019-06-21 00:31:17 +00:00
|
|
|
return {QStringLiteral(""),
|
2019-04-28 23:01:23 +00:00
|
|
|
tr("The version of yuzu you are using is either too new or too old for the server. "
|
|
|
|
"Try updating to the latest official release of yuzu.")};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map.empty()) {
|
|
|
|
return {QStringLiteral("Current Boxcat Events"),
|
|
|
|
tr("There are currently no events on boxcat.")};
|
|
|
|
}
|
|
|
|
|
|
|
|
QString out;
|
2019-06-21 00:31:17 +00:00
|
|
|
|
|
|
|
if (global.has_value()) {
|
|
|
|
out += QStringLiteral("%1<br>").arg(QString::fromStdString(*global));
|
|
|
|
}
|
|
|
|
|
2019-04-28 23:01:23 +00:00
|
|
|
for (const auto& [key, value] : map) {
|
|
|
|
out += QStringLiteral("%1<b>%2</b><br>%3")
|
2019-06-21 00:31:17 +00:00
|
|
|
.arg(out.isEmpty() ? QStringLiteral("") : QStringLiteral("<br>"))
|
2019-04-28 23:01:23 +00:00
|
|
|
.arg(QString::fromStdString(key))
|
|
|
|
.arg(FormatEventStatusString(value));
|
|
|
|
}
|
|
|
|
return {QStringLiteral("Current Boxcat Events"), out};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureService::OnBCATImplChanged() {
|
|
|
|
#ifdef YUZU_ENABLE_BOXCAT
|
|
|
|
const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat");
|
|
|
|
ui->bcat_empty_header->setHidden(!boxcat);
|
|
|
|
ui->bcat_empty_label->setHidden(!boxcat);
|
2019-06-21 00:31:17 +00:00
|
|
|
ui->bcat_empty_header->setText(QStringLiteral(""));
|
2019-04-28 23:01:23 +00:00
|
|
|
ui->bcat_empty_label->setText(tr("Yuzu is retrieving the latest boxcat status..."));
|
|
|
|
|
|
|
|
if (!boxcat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto future = QtConcurrent::run([this] { return BCATDownloadEvents(); });
|
|
|
|
|
|
|
|
watcher.setFuture(future);
|
|
|
|
connect(&watcher, &QFutureWatcher<std::pair<QString, QString>>::finished, this,
|
|
|
|
[this] { OnUpdateBCATEmptyLabel(watcher.result()); });
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureService::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) {
|
|
|
|
#ifdef YUZU_ENABLE_BOXCAT
|
|
|
|
const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat");
|
|
|
|
if (boxcat) {
|
|
|
|
ui->bcat_empty_header->setText(string.first);
|
|
|
|
ui->bcat_empty_label->setText(string.second);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|