2017-08-23 03:36:57 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-09-19 01:18:26 +00:00
|
|
|
#include <QMessageBox>
|
2017-08-23 03:36:57 +00:00
|
|
|
#include "citra_qt/configuration/configure_web.h"
|
|
|
|
#include "core/settings.h"
|
2017-08-23 04:08:07 +00:00
|
|
|
#include "core/telemetry_session.h"
|
2017-08-23 03:36:57 +00:00
|
|
|
#include "ui_configure_web.h"
|
|
|
|
|
|
|
|
ConfigureWeb::ConfigureWeb(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
|
|
|
|
ui->setupUi(this);
|
2017-08-23 04:08:07 +00:00
|
|
|
connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this,
|
2017-09-19 01:18:26 +00:00
|
|
|
&ConfigureWeb::RefreshTelemetryID);
|
|
|
|
connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin);
|
|
|
|
connect(this, &ConfigureWeb::LoginVerified, this, &ConfigureWeb::OnLoginVerified);
|
2017-08-23 04:08:07 +00:00
|
|
|
|
2017-08-23 03:36:57 +00:00
|
|
|
this->setConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureWeb::~ConfigureWeb() {}
|
|
|
|
|
|
|
|
void ConfigureWeb::setConfiguration() {
|
|
|
|
ui->web_credentials_disclaimer->setWordWrap(true);
|
|
|
|
ui->telemetry_learn_more->setOpenExternalLinks(true);
|
2017-09-24 14:52:11 +00:00
|
|
|
ui->telemetry_learn_more->setText(tr("<a "
|
|
|
|
"href='https://citra-emu.org/entry/"
|
|
|
|
"telemetry-and-why-thats-a-good-thing/'>Learn more</a>"));
|
2017-08-23 03:36:57 +00:00
|
|
|
|
|
|
|
ui->web_signup_link->setOpenExternalLinks(true);
|
2017-09-24 14:52:11 +00:00
|
|
|
ui->web_signup_link->setText(tr("<a href='https://services.citra-emu.org/'>Sign up</a>"));
|
2017-08-23 03:36:57 +00:00
|
|
|
ui->web_token_info_link->setOpenExternalLinks(true);
|
|
|
|
ui->web_token_info_link->setText(
|
2017-09-24 14:52:11 +00:00
|
|
|
tr("<a href='https://citra-emu.org/wiki/citra-web-service/'>What is my token?</a>"));
|
2017-08-23 03:36:57 +00: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 01:18:26 +00: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 14:52:11 +00:00
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(Core::GetTelemetryId(), 16).toUpper()));
|
2017-09-19 01:18:26 +00:00
|
|
|
user_verified = true;
|
2017-08-23 03:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::applyConfiguration() {
|
|
|
|
Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked();
|
2017-09-19 01:18:26 +00:00
|
|
|
if (user_verified) {
|
|
|
|
Settings::values.citra_username = ui->edit_username->text().toStdString();
|
|
|
|
Settings::values.citra_token = ui->edit_token->text().toStdString();
|
|
|
|
} else {
|
|
|
|
QMessageBox::warning(this, tr("Username and token not verfied"),
|
|
|
|
tr("Username and token were not verified. The changes to your "
|
|
|
|
"username and/or token have not been saved."));
|
|
|
|
}
|
2017-08-23 03:36:57 +00:00
|
|
|
Settings::Apply();
|
|
|
|
}
|
|
|
|
|
2017-09-19 01:18:26 +00:00
|
|
|
void ConfigureWeb::RefreshTelemetryID() {
|
2017-08-23 04:08:07 +00:00
|
|
|
const u64 new_telemetry_id{Core::RegenerateTelemetryId()};
|
2017-09-24 14:52:11 +00:00
|
|
|
ui->label_telemetry_id->setText(
|
|
|
|
tr("Telemetry ID: 0x%1").arg(QString::number(new_telemetry_id, 16).toUpper()));
|
2017-08-23 04:08:07 +00:00
|
|
|
}
|
2017-09-19 01:18:26 +00:00
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginChanged() {
|
|
|
|
if (ui->edit_username->text().isEmpty() && ui->edit_token->text().isEmpty()) {
|
|
|
|
user_verified = true;
|
|
|
|
ui->label_username_verified->setPixmap(QPixmap(":/icons/checked.png"));
|
|
|
|
ui->label_token_verified->setPixmap(QPixmap(":/icons/checked.png"));
|
|
|
|
} else {
|
|
|
|
user_verified = false;
|
|
|
|
ui->label_username_verified->setPixmap(QPixmap(":/icons/failed.png"));
|
|
|
|
ui->label_token_verified->setPixmap(QPixmap(":/icons/failed.png"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::VerifyLogin() {
|
|
|
|
verified =
|
|
|
|
Core::VerifyLogin(ui->edit_username->text().toStdString(),
|
|
|
|
ui->edit_token->text().toStdString(), [&]() { emit LoginVerified(); });
|
|
|
|
ui->button_verify_login->setDisabled(true);
|
|
|
|
ui->button_verify_login->setText(tr("Verifying"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureWeb::OnLoginVerified() {
|
|
|
|
ui->button_verify_login->setEnabled(true);
|
|
|
|
ui->button_verify_login->setText(tr("Verify"));
|
|
|
|
if (verified.get()) {
|
|
|
|
user_verified = true;
|
|
|
|
ui->label_username_verified->setPixmap(QPixmap(":/icons/checked.png"));
|
|
|
|
ui->label_token_verified->setPixmap(QPixmap(":/icons/checked.png"));
|
|
|
|
} else {
|
|
|
|
ui->label_username_verified->setPixmap(QPixmap(":/icons/failed.png"));
|
|
|
|
ui->label_token_verified->setPixmap(QPixmap(":/icons/failed.png"));
|
|
|
|
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."));
|
|
|
|
}
|
|
|
|
}
|