2017-08-23 05:36:57 +02:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-03-27 13:11:04 +02:00
|
|
|
#include <QIcon>
|
2017-09-19 03:18:26 +02:00
|
|
|
#include <QMessageBox>
|
2018-09-12 18:22:48 +02:00
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
2017-08-23 05:36:57 +02:00
|
|
|
#include "citra_qt/configuration/configure_web.h"
|
2018-08-20 11:20:33 +02:00
|
|
|
#include "citra_qt/ui_settings.h"
|
2017-08-23 05:36:57 +02:00
|
|
|
#include "core/settings.h"
|
2017-08-23 06:08:07 +02:00
|
|
|
#include "core/telemetry_session.h"
|
2017-08-23 05:36:57 +02:00
|
|
|
#include "ui_configure_web.h"
|
|
|
|
|
|
|
|
ConfigureWeb::ConfigureWeb(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
|
|
|
|
ui->setupUi(this);
|
2017-08-23 06:08:07 +02:00
|
|
|
connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this,
|
2017-09-19 03:18:26 +02:00
|
|
|
&ConfigureWeb::RefreshTelemetryID);
|
|
|
|
connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin);
|
2018-09-12 18:22:48 +02:00
|
|
|
connect(&verify_watcher, &QFutureWatcher<bool>::finished, this, &ConfigureWeb::OnLoginVerified);
|
2017-08-23 06:08:07 +02:00
|
|
|
|
2018-08-20 11:20:33 +02:00
|
|
|
#ifndef USE_DISCORD_PRESENCE
|
|
|
|
ui->discord_group->setVisible(false);
|
|
|
|
#endif
|
2019-05-26 06:39:23 +02:00
|
|
|
SetConfiguration();
|
2017-08-23 05:36:57 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 17:16:01 +02:00
|
|
|
ConfigureWeb::~ConfigureWeb() = default;
|
2017-08-23 05:36:57 +02:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureWeb::SetConfiguration() {
|
2017-08-23 05:36:57 +02:00
|
|
|
ui->web_credentials_disclaimer->setWordWrap(true);
|
|
|
|
ui->telemetry_learn_more->setOpenExternalLinks(true);
|
2017-09-24 16:52:11 +02:00
|
|
|
ui->telemetry_learn_more->setText(tr("<a "
|
|
|
|
"href='https://citra-emu.org/entry/"
|
2018-05-23 02:51:19 +02:00
|
|
|
"telemetry-and-why-thats-a-good-thing/'><span "
|
|
|
|
"style=\"text-decoration: underline; "
|
|
|
|
"color:#039be5;\">Learn more</span></a>"));
|
2017-08-23 05:36:57 +02:00
|
|
|
|
|
|
|
ui->web_signup_link->setOpenExternalLinks(true);
|
2018-05-23 02:51:19 +02:00
|
|
|
ui->web_signup_link->setText(
|
2018-09-19 20:04:45 +02:00
|
|
|
tr("<a href='https://profile.citra-emu.org/'><span style=\"text-decoration: underline; "
|
2018-05-23 02:51:19 +02:00
|
|
|
"color:#039be5;\">Sign up</span></a>"));
|
2017-08-23 05:36:57 +02:00
|
|
|
ui->web_token_info_link->setOpenExternalLinks(true);
|
|
|
|
ui->web_token_info_link->setText(
|
2018-05-23 02:51:19 +02:00
|
|
|
tr("<a href='https://citra-emu.org/wiki/citra-web-service/'><span style=\"text-decoration: "
|
|
|
|
"underline; color:#039be5;\">What is my token?</span></a>"));
|
2017-08-23 05:36:57 +02:00
|
|
|
|
|
|
|
ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry);
|
|
|
|
ui->edit_username->setText(QString::fromStdString(Settings::values.citra_username));
|
|
|
|
ui->edit_token->setText(QString::fromStdString(Settings::values.citra_token));
|
2017-09-19 03:18:26 +02:00
|
|
|
// Connect after setting the values, to avoid calling OnLoginChanged now
|
|
|
|
connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged);
|
|
|
|
connect(ui->edit_username, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged);
|
2017-09-24 16:52:11 +02:00
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(Core::GetTelemetryId(), 16).toUpper()));
|
2017-09-19 03:18:26 +02:00
|
|
|
user_verified = true;
|
2018-08-20 11:20:33 +02:00
|
|
|
|
|
|
|
ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence);
|
2017-08-23 05:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureWeb::ApplyConfiguration() {
|
2017-08-23 05:36:57 +02:00
|
|
|
Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked();
|
2018-08-20 11:20:33 +02:00
|
|
|
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
|
2017-09-19 03:18:26 +02:00
|
|
|
if (user_verified) {
|
|
|
|
Settings::values.citra_username = ui->edit_username->text().toStdString();
|
|
|
|
Settings::values.citra_token = ui->edit_token->text().toStdString();
|
|
|
|
} else {
|
2018-01-18 21:08:33 +01:00
|
|
|
QMessageBox::warning(this, tr("Username and token not verified"),
|
2017-09-19 03:18:26 +02:00
|
|
|
tr("Username and token were not verified. The changes to your "
|
|
|
|
"username and/or token have not been saved."));
|
|
|
|
}
|
2017-08-23 05:36:57 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 03:18:26 +02:00
|
|
|
void ConfigureWeb::RefreshTelemetryID() {
|
2017-08-23 06:08:07 +02:00
|
|
|
const u64 new_telemetry_id{Core::RegenerateTelemetryId()};
|
2017-09-24 16:52:11 +02:00
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(new_telemetry_id, 16).toUpper()));
|
2017-08-23 06:08:07 +02:00
|
|
|
}
|
2017-09-19 03:18:26 +02:00
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginChanged() {
|
|
|
|
if (ui->edit_username->text().isEmpty() && ui->edit_token->text().isEmpty()) {
|
|
|
|
user_verified = true;
|
2018-03-27 13:11:04 +02:00
|
|
|
ui->label_username_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
|
|
|
|
ui->label_token_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
|
2017-09-19 03:18:26 +02:00
|
|
|
} else {
|
|
|
|
user_verified = false;
|
2018-03-27 13:11:04 +02:00
|
|
|
ui->label_username_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16));
|
|
|
|
ui->label_token_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16));
|
2017-09-19 03:18:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::VerifyLogin() {
|
|
|
|
ui->button_verify_login->setDisabled(true);
|
2019-01-17 17:35:55 +01:00
|
|
|
ui->button_verify_login->setText(tr("Verifying..."));
|
2019-01-17 17:39:46 +01:00
|
|
|
verify_watcher.setFuture(QtConcurrent::run([username = ui->edit_username->text().toStdString(),
|
|
|
|
token = ui->edit_token->text().toStdString()] {
|
|
|
|
return Core::VerifyLogin(username, token);
|
|
|
|
}));
|
2017-09-19 03:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginVerified() {
|
|
|
|
ui->button_verify_login->setEnabled(true);
|
|
|
|
ui->button_verify_login->setText(tr("Verify"));
|
2018-09-12 18:22:48 +02:00
|
|
|
if (verify_watcher.result()) {
|
2017-09-19 03:18:26 +02:00
|
|
|
user_verified = true;
|
2018-03-27 13:11:04 +02:00
|
|
|
ui->label_username_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
|
|
|
|
ui->label_token_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
|
2017-09-19 03:18:26 +02:00
|
|
|
} else {
|
2018-03-27 13:11:04 +02:00
|
|
|
ui->label_username_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16));
|
|
|
|
ui->label_token_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16));
|
2017-09-19 03:18:26 +02:00
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Verification failed"),
|
|
|
|
tr("Verification failed. Check that you have entered your username and token "
|
|
|
|
"correctly, and that your internet connection is working."));
|
|
|
|
}
|
|
|
|
}
|
2017-09-23 15:13:59 +02:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureWeb::RetranslateUI() {
|
2017-09-23 15:13:59 +02:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
2019-04-20 04:42:20 +02:00
|
|
|
|
|
|
|
void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) {
|
|
|
|
ui->label_disable_info->setVisible(!enabled);
|
|
|
|
ui->groupBoxWebConfig->setEnabled(enabled);
|
|
|
|
}
|