2018-09-16 18:05:51 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
|
|
|
#include "core/settings.h"
|
|
|
|
#include "core/telemetry_session.h"
|
|
|
|
#include "ui_configure_web.h"
|
|
|
|
#include "yuzu/configuration/configure_web.h"
|
2019-07-29 20:06:33 +00:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-09-16 18:05:51 +00:00
|
|
|
|
2019-11-09 04:18:56 +00:00
|
|
|
static constexpr char token_delimiter{':'};
|
|
|
|
|
|
|
|
static std::string GenerateDisplayToken(const std::string& username, const std::string& token) {
|
|
|
|
if (username.empty() || token.empty()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string unencoded_display_token{username + token_delimiter + token};
|
|
|
|
QByteArray b{unencoded_display_token.c_str()};
|
|
|
|
QByteArray b64 = b.toBase64();
|
|
|
|
return b64.toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string UsernameFromDisplayToken(const std::string& display_token) {
|
|
|
|
const std::string unencoded_display_token{
|
|
|
|
QByteArray::fromBase64(display_token.c_str()).toStdString()};
|
|
|
|
return unencoded_display_token.substr(0, unencoded_display_token.find(token_delimiter));
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string TokenFromDisplayToken(const std::string& display_token) {
|
|
|
|
const std::string unencoded_display_token{
|
|
|
|
QByteArray::fromBase64(display_token.c_str()).toStdString()};
|
|
|
|
return unencoded_display_token.substr(unencoded_display_token.find(token_delimiter) + 1);
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:05:51 +00:00
|
|
|
ConfigureWeb::ConfigureWeb(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this,
|
|
|
|
&ConfigureWeb::RefreshTelemetryID);
|
|
|
|
connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin);
|
|
|
|
connect(&verify_watcher, &QFutureWatcher<bool>::finished, this, &ConfigureWeb::OnLoginVerified);
|
|
|
|
|
|
|
|
#ifndef USE_DISCORD_PRESENCE
|
|
|
|
ui->discord_group->setVisible(false);
|
|
|
|
#endif
|
2019-06-05 22:39:46 +00:00
|
|
|
|
2019-05-26 04:39:23 +00:00
|
|
|
SetConfiguration();
|
2019-06-05 22:39:46 +00:00
|
|
|
RetranslateUI();
|
2018-09-16 18:05:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 15:16:01 +00:00
|
|
|
ConfigureWeb::~ConfigureWeb() = default;
|
2018-09-16 18:05:51 +00:00
|
|
|
|
2019-06-05 22:39:46 +00:00
|
|
|
void ConfigureWeb::changeEvent(QEvent* event) {
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
|
2018-10-02 14:04:10 +00:00
|
|
|
ui->telemetry_learn_more->setText(
|
2018-10-06 07:15:27 +00:00
|
|
|
tr("<a href='https://yuzu-emu.org/help/feature/telemetry/'><span style=\"text-decoration: "
|
2018-10-02 14:04:10 +00:00
|
|
|
"underline; color:#039be5;\">Learn more</span></a>"));
|
2018-09-16 18:05:51 +00:00
|
|
|
|
|
|
|
ui->web_signup_link->setText(
|
2018-09-19 18:04:45 +00:00
|
|
|
tr("<a href='https://profile.yuzu-emu.org/'><span style=\"text-decoration: underline; "
|
2018-09-16 18:05:51 +00:00
|
|
|
"color:#039be5;\">Sign up</span></a>"));
|
2019-06-05 22:39:46 +00:00
|
|
|
|
2018-09-16 18:05:51 +00:00
|
|
|
ui->web_token_info_link->setText(
|
2018-09-19 18:04:45 +00:00
|
|
|
tr("<a href='https://yuzu-emu.org/wiki/yuzu-web-service/'><span style=\"text-decoration: "
|
2018-09-16 18:05:51 +00:00
|
|
|
"underline; color:#039be5;\">What is my token?</span></a>"));
|
|
|
|
|
2019-06-05 22:39:46 +00:00
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(Core::GetTelemetryId(), 16).toUpper()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::SetConfiguration() {
|
|
|
|
ui->web_credentials_disclaimer->setWordWrap(true);
|
|
|
|
|
|
|
|
ui->telemetry_learn_more->setOpenExternalLinks(true);
|
|
|
|
ui->web_signup_link->setOpenExternalLinks(true);
|
|
|
|
ui->web_token_info_link->setOpenExternalLinks(true);
|
|
|
|
|
2019-11-09 04:18:56 +00:00
|
|
|
if (Settings::values.yuzu_username.empty()) {
|
|
|
|
ui->username->setText(tr("Unspecified"));
|
|
|
|
} else {
|
|
|
|
ui->username->setText(QString::fromStdString(Settings::values.yuzu_username));
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:05:51 +00:00
|
|
|
ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry);
|
2019-11-09 04:18:56 +00:00
|
|
|
ui->edit_token->setText(QString::fromStdString(
|
|
|
|
GenerateDisplayToken(Settings::values.yuzu_username, Settings::values.yuzu_token)));
|
2019-06-05 22:39:46 +00:00
|
|
|
|
2018-09-16 18:05:51 +00:00
|
|
|
// Connect after setting the values, to avoid calling OnLoginChanged now
|
|
|
|
connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged);
|
2019-06-05 22:39:46 +00:00
|
|
|
|
2018-09-16 18:05:51 +00:00
|
|
|
user_verified = true;
|
|
|
|
|
|
|
|
ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence);
|
|
|
|
}
|
|
|
|
|
2019-05-26 04:39:23 +00:00
|
|
|
void ConfigureWeb::ApplyConfiguration() {
|
2018-09-16 18:05:51 +00:00
|
|
|
Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked();
|
|
|
|
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
|
|
|
|
if (user_verified) {
|
2019-11-09 04:18:56 +00:00
|
|
|
Settings::values.yuzu_username =
|
|
|
|
UsernameFromDisplayToken(ui->edit_token->text().toStdString());
|
|
|
|
Settings::values.yuzu_token = TokenFromDisplayToken(ui->edit_token->text().toStdString());
|
2018-09-16 18:05:51 +00:00
|
|
|
} else {
|
2019-11-09 04:18:56 +00:00
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Token not verified"),
|
|
|
|
tr("Token was not verified. The change to your token has not been saved."));
|
2018-09-16 18:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::RefreshTelemetryID() {
|
|
|
|
const u64 new_telemetry_id{Core::RegenerateTelemetryId()};
|
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(new_telemetry_id, 16).toUpper()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginChanged() {
|
2019-11-09 04:18:56 +00:00
|
|
|
if (ui->edit_token->text().isEmpty()) {
|
2018-09-16 18:05:51 +00:00
|
|
|
user_verified = true;
|
2019-05-19 17:05:06 +00:00
|
|
|
|
|
|
|
const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
|
|
|
|
ui->label_token_verified->setPixmap(pixmap);
|
2018-09-16 18:05:51 +00:00
|
|
|
} else {
|
|
|
|
user_verified = false;
|
2019-05-19 17:05:06 +00:00
|
|
|
|
|
|
|
const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
|
|
|
|
ui->label_token_verified->setPixmap(pixmap);
|
2018-09-16 18:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::VerifyLogin() {
|
|
|
|
ui->button_verify_login->setDisabled(true);
|
2019-01-17 16:35:55 +00:00
|
|
|
ui->button_verify_login->setText(tr("Verifying..."));
|
2019-11-09 04:18:56 +00:00
|
|
|
verify_watcher.setFuture(QtConcurrent::run(
|
|
|
|
[username = UsernameFromDisplayToken(ui->edit_token->text().toStdString()),
|
|
|
|
token = TokenFromDisplayToken(ui->edit_token->text().toStdString())] {
|
|
|
|
return Core::VerifyLogin(username, token);
|
|
|
|
}));
|
2018-09-16 18:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginVerified() {
|
|
|
|
ui->button_verify_login->setEnabled(true);
|
|
|
|
ui->button_verify_login->setText(tr("Verify"));
|
|
|
|
if (verify_watcher.result()) {
|
|
|
|
user_verified = true;
|
2019-05-19 17:05:06 +00:00
|
|
|
|
|
|
|
const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
|
|
|
|
ui->label_token_verified->setPixmap(pixmap);
|
2019-11-09 04:18:56 +00:00
|
|
|
ui->username->setText(
|
|
|
|
QString::fromStdString(UsernameFromDisplayToken(ui->edit_token->text().toStdString())));
|
2018-09-16 18:05:51 +00:00
|
|
|
} else {
|
2019-05-19 17:05:06 +00:00
|
|
|
const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
|
|
|
|
ui->label_token_verified->setPixmap(pixmap);
|
2019-11-09 04:18:56 +00:00
|
|
|
ui->username->setText(tr("Unspecified"));
|
|
|
|
QMessageBox::critical(this, tr("Verification failed"),
|
|
|
|
tr("Verification failed. Check that you have entered your token "
|
|
|
|
"correctly, and that your internet connection is working."));
|
2018-09-16 18:05:51 +00:00
|
|
|
}
|
|
|
|
}
|