From f0551aef0912c02e273021fd5186f49283ebcb14 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 28 Apr 2019 19:01:23 -0400 Subject: [PATCH] yuzu: Add UI tab to configure BCAT services Also displays current events if boxcat is selected. --- src/yuzu/CMakeLists.txt | 6 + src/yuzu/configuration/configure.ui | 11 ++ src/yuzu/configuration/configure_dialog.cpp | 1 + src/yuzu/configuration/configure_service.cpp | 129 +++++++++++++++++++ src/yuzu/configuration/configure_service.h | 34 +++++ src/yuzu/configuration/configure_service.ui | 121 +++++++++++++++++ 6 files changed, 302 insertions(+) create mode 100644 src/yuzu/configuration/configure_service.cpp create mode 100644 src/yuzu/configuration/configure_service.h create mode 100644 src/yuzu/configuration/configure_service.ui diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index dc6fa07fc2..fffb202204 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -66,6 +66,8 @@ add_executable(yuzu configuration/configure_profile_manager.cpp configuration/configure_profile_manager.h configuration/configure_profile_manager.ui + configuration/configure_service.cpp + configuration/configure_service.h configuration/configure_system.cpp configuration/configure_system.h configuration/configure_system.ui @@ -186,6 +188,10 @@ if (YUZU_USE_QT_WEB_ENGINE) target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE) endif () +if (YUZU_ENABLE_BOXCAT) + target_compile_definitions(yuzu PRIVATE -DYUZU_ENABLE_BOXCAT) +endif () + if(UNIX AND NOT APPLE) install(TARGETS yuzu RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") endif() diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index 49fadd0ef7..372427ae20 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui @@ -98,6 +98,11 @@ Web + + + Services + + @@ -178,6 +183,12 @@
configuration/configure_hotkeys.h
1 + + ConfigureService + QWidget +
configuration/configure_service.h
+ 1 +
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 7c875ae870..520b7e1938 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -44,6 +44,7 @@ void ConfigureDialog::ApplyConfiguration() { ui->audioTab->ApplyConfiguration(); ui->debugTab->ApplyConfiguration(); ui->webTab->ApplyConfiguration(); + ui->serviceTab->ApplyConfiguration(); Settings::Apply(); Settings::LogSettings(); } diff --git a/src/yuzu/configuration/configure_service.cpp b/src/yuzu/configuration/configure_service.cpp new file mode 100644 index 0000000000..fca785d0ea --- /dev/null +++ b/src/yuzu/configuration/configure_service.cpp @@ -0,0 +1,129 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#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("%1
").arg(QString::fromStdString(*status.header)); + } + + if (status.events.size() == 1) { + out += QStringLiteral("%1
").arg(QString::fromStdString(status.events.front())); + } else { + for (const auto event : status.events) { + out += QStringLiteral("- %1
").arg(QString::fromStdString(event)); + } + } + + if (status.footer.has_value()) { + out += QStringLiteral("%1
").arg(QString::fromStdString(*status.footer)); + } + + return out; +} +} // Anonymous namespace + +ConfigureService::ConfigureService(QWidget* parent) + : QWidget(parent), ui(std::make_unique()), 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::of(&QComboBox::currentIndexChanged), this, + &ConfigureService::OnBCATImplChanged); + + this->setConfiguration(); +} + +ConfigureService::~ConfigureService() = default; + +void ConfigureService::applyConfiguration() { + Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString(); +} + +void ConfigureService::retranslateUi() { + ui->retranslateUi(this); +} + +void ConfigureService::setConfiguration() { + int index = ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend)); + ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index); +} + +std::pair ConfigureService::BCATDownloadEvents() { + std::optional global; + std::map map; + const auto res = Service::BCAT::Boxcat::GetStatus(global, map); + + switch (res) { + case Service::BCAT::Boxcat::StatusResult::Offline: + return {"", tr("The boxcat service is offline or you are not connected to the internet.")}; + case Service::BCAT::Boxcat::StatusResult::ParseError: + return {"", + tr("There was an error while processing the boxcat event data. Contact the yuzu " + "developers.")}; + case Service::BCAT::Boxcat::StatusResult::BadClientVersion: + return {"", + 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; + for (const auto& [key, value] : map) { + out += QStringLiteral("%1%2
%3") + .arg(out.isEmpty() ? "" : "
") + .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); + ui->bcat_empty_header->setText(""); + 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>::finished, this, + [this] { OnUpdateBCATEmptyLabel(watcher.result()); }); +#endif +} + +void ConfigureService::OnUpdateBCATEmptyLabel(std::pair 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 +} diff --git a/src/yuzu/configuration/configure_service.h b/src/yuzu/configuration/configure_service.h new file mode 100644 index 0000000000..ee50d5a799 --- /dev/null +++ b/src/yuzu/configuration/configure_service.h @@ -0,0 +1,34 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +namespace Ui { +class ConfigureService; +} + +class ConfigureService : public QWidget { + Q_OBJECT + +public: + explicit ConfigureService(QWidget* parent = nullptr); + ~ConfigureService() override; + + void applyConfiguration(); + void retranslateUi(); + +private: + void setConfiguration(); + + std::pair BCATDownloadEvents(); + void OnBCATImplChanged(); + void OnUpdateBCATEmptyLabel(std::pair string); + + std::unique_ptr ui; + QFutureWatcher> watcher; +}; diff --git a/src/yuzu/configuration/configure_service.ui b/src/yuzu/configuration/configure_service.ui new file mode 100644 index 0000000000..f5b683d25e --- /dev/null +++ b/src/yuzu/configuration/configure_service.ui @@ -0,0 +1,121 @@ + + + ConfigureService + + + + 0 + 0 + 433 + 561 + + + + Form + + + + + + + + BCAT + + + + + + + 260 + 16777215 + + + + BCAT is Nintendo's way of sending data to games to engage its community and unlock additional content. + + + true + + + + + + + + 16777215 + 16777215 + + + + BCAT Backend + + + + + + + true + + + + 260 + 16777215 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + <html><head/><body><p><a href="https://yuzu-emu.org/help/feature/boxcat"><span style=" text-decoration: underline; color:#0000ff;">Learn more about BCAT, Boxcat, and Current Events</span></a></p></body></html> + + + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +