2019-04-28 19:01:23 -04: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>
|
2021-04-14 19:07:40 -04:00
|
|
|
#include "common/settings.h"
|
2021-08-12 15:32:53 -04:00
|
|
|
#include "core/core.h"
|
2019-04-28 19:01:23 -04:00
|
|
|
#include "core/hle/service/bcat/backend/boxcat.h"
|
2021-08-12 15:32:53 -04:00
|
|
|
#include "ui_configure_network.h"
|
|
|
|
#include "yuzu/configuration/configure_network.h"
|
2019-04-28 19:01:23 -04:00
|
|
|
|
2021-01-17 17:54:29 -05:00
|
|
|
#ifdef YUZU_ENABLE_BOXCAT
|
2019-04-28 19:01:23 -04:00
|
|
|
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 {
|
2019-10-02 08:35:39 -04:00
|
|
|
for (const auto& event : status.events) {
|
2019-04-28 19:01:23 -04:00
|
|
|
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
|
2021-01-17 17:54:29 -05:00
|
|
|
#endif
|
2019-04-28 19:01:23 -04:00
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
ConfigureNetwork::ConfigureNetwork(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) {
|
2019-04-28 19:01:23 -04:00
|
|
|
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
|
|
|
|
|
2021-08-12 18:34:04 -04:00
|
|
|
ui->network_interface->addItem(tr("None"));
|
2021-08-12 15:32:53 -04:00
|
|
|
for (const auto& interface : Network::GetAvailableNetworkInterfaces()) {
|
|
|
|
ui->network_interface->addItem(QString::fromStdString(interface.name));
|
|
|
|
}
|
|
|
|
|
2019-04-28 19:01:23 -04:00
|
|
|
connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2021-08-12 15:32:53 -04:00
|
|
|
&ConfigureNetwork::OnBCATImplChanged);
|
2019-04-28 19:01:23 -04:00
|
|
|
|
2019-06-20 20:31:17 -04:00
|
|
|
this->SetConfiguration();
|
2019-04-28 19:01:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
ConfigureNetwork::~ConfigureNetwork() = default;
|
2019-04-28 19:01:23 -04:00
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
void ConfigureNetwork::ApplyConfiguration() {
|
2019-04-28 19:01:23 -04:00
|
|
|
Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString();
|
2021-08-12 15:32:53 -04:00
|
|
|
Settings::values.network_interface = ui->network_interface->currentText().toStdString();
|
2019-04-28 19:01:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
void ConfigureNetwork::RetranslateUi() {
|
2019-04-28 19:01:23 -04:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
void ConfigureNetwork::SetConfiguration() {
|
|
|
|
const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
|
|
|
|
|
2019-10-02 08:35:39 -04:00
|
|
|
const int index =
|
2021-06-28 15:58:16 -04:00
|
|
|
ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend.GetValue()));
|
2019-04-28 19:01:23 -04:00
|
|
|
ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index);
|
2021-08-12 15:32:53 -04:00
|
|
|
|
|
|
|
const std::string& network_interface = Settings::values.network_interface.GetValue();
|
|
|
|
|
|
|
|
ui->network_interface->setCurrentText(QString::fromStdString(network_interface));
|
|
|
|
ui->network_interface->setEnabled(runtime_lock);
|
2019-04-28 19:01:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
std::pair<QString, QString> ConfigureNetwork::BCATDownloadEvents() {
|
2020-06-19 08:17:56 -04:00
|
|
|
#ifdef YUZU_ENABLE_BOXCAT
|
2019-04-28 19:01:23 -04:00
|
|
|
std::optional<std::string> global;
|
|
|
|
std::map<std::string, Service::BCAT::EventStatus> map;
|
|
|
|
const auto res = Service::BCAT::Boxcat::GetStatus(global, map);
|
|
|
|
|
|
|
|
switch (res) {
|
2019-10-04 19:33:37 -04:00
|
|
|
case Service::BCAT::Boxcat::StatusResult::Success:
|
|
|
|
break;
|
2019-04-28 19:01:23 -04:00
|
|
|
case Service::BCAT::Boxcat::StatusResult::Offline:
|
2019-10-02 08:35:39 -04:00
|
|
|
return {QString{},
|
2019-06-20 20:31:17 -04:00
|
|
|
tr("The boxcat service is offline or you are not connected to the internet.")};
|
2019-04-28 19:01:23 -04:00
|
|
|
case Service::BCAT::Boxcat::StatusResult::ParseError:
|
2019-10-02 08:35:39 -04:00
|
|
|
return {QString{},
|
2019-04-28 19:01:23 -04:00
|
|
|
tr("There was an error while processing the boxcat event data. Contact the yuzu "
|
|
|
|
"developers.")};
|
|
|
|
case Service::BCAT::Boxcat::StatusResult::BadClientVersion:
|
2019-10-02 08:35:39 -04:00
|
|
|
return {QString{},
|
2019-04-28 19:01:23 -04: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-20 20:31:17 -04:00
|
|
|
|
|
|
|
if (global.has_value()) {
|
|
|
|
out += QStringLiteral("%1<br>").arg(QString::fromStdString(*global));
|
|
|
|
}
|
|
|
|
|
2019-04-28 19:01:23 -04:00
|
|
|
for (const auto& [key, value] : map) {
|
|
|
|
out += QStringLiteral("%1<b>%2</b><br>%3")
|
2019-10-02 08:35:39 -04:00
|
|
|
.arg(out.isEmpty() ? QString{} : QStringLiteral("<br>"))
|
2019-04-28 19:01:23 -04:00
|
|
|
.arg(QString::fromStdString(key))
|
|
|
|
.arg(FormatEventStatusString(value));
|
|
|
|
}
|
2020-06-19 21:57:51 -04:00
|
|
|
return {tr("Current Boxcat Events"), std::move(out)};
|
2020-06-19 08:17:56 -04:00
|
|
|
#else
|
2020-06-19 21:57:51 -04:00
|
|
|
return {tr("Current Boxcat Events"), tr("There are currently no events on boxcat.")};
|
2020-06-19 08:17:56 -04:00
|
|
|
#endif
|
2019-04-28 19:01:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
void ConfigureNetwork::OnBCATImplChanged() {
|
2019-04-28 19:01:23 -04:00
|
|
|
#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-10-02 08:35:39 -04:00
|
|
|
ui->bcat_empty_header->setText(QString{});
|
2019-04-28 19:01:23 -04: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
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:32:53 -04:00
|
|
|
void ConfigureNetwork::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) {
|
2019-04-28 19:01:23 -04:00
|
|
|
#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
|
|
|
|
}
|