eden/src/yuzu/configuration/configure_web.cpp

132 lines
4.3 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
chore: make yuzu REUSE compliant [REUSE] is a specification that aims at making file copyright information consistent, so that it can be both human and machine readable. It basically requires that all files have a header containing copyright and licensing information. When this isn't possible, like when dealing with binary assets, generated files or embedded third-party dependencies, it is permitted to insert copyright information in the `.reuse/dep5` file. Oh, and it also requires that all the licenses used in the project are present in the `LICENSES` folder, that's why the diff is so huge. This can be done automatically with `reuse download --all`. The `reuse` tool also contains a handy subcommand that analyzes the project and tells whether or not the project is (still) compliant, `reuse lint`. Following REUSE has a few advantages over the current approach: - Copyright information is easy to access for users / downstream - Files like `dist/license.md` do not need to exist anymore, as `.reuse/dep5` is used instead - `reuse lint` makes it easy to ensure that copyright information of files like binary assets / images is always accurate and up to date To add copyright information of files that didn't have it I looked up who committed what and when, for each file. As yuzu contributors do not have to sign a CLA or similar I couldn't assume that copyright ownership was of the "yuzu Emulator Project", so I used the name and/or email of the commit author instead. [REUSE]: https://reuse.software Follow-up to b2eb10382941bef0914f4a0a4685b9033440aa9f
2022-05-15 02:06:02 +02:00
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2018-09-16 20:05:51 +02:00
#include "yuzu/configuration/configure_web.h"
2018-09-16 20:05:51 +02:00
#include <QIcon>
#include <QMessageBox>
#if QT_VERSION_MAJOR >= 6
#include <QRegularExpressionValidator>
#else
#include <QRegExpValidator>
#endif
2018-09-16 20:05:51 +02:00
#include <QtConcurrent/QtConcurrentRun>
#include "common/settings.h"
2018-09-16 20:05:51 +02:00
#include "ui_configure_web.h"
#include "qt_common/uisettings.h"
2018-09-16 20:05:51 +02:00
ConfigureWeb::ConfigureWeb(QWidget* parent)
: QWidget(parent)
, ui(std::make_unique<Ui::ConfigureWeb>())
, m_rng{QRandomGenerator::system()}
{
ui->setupUi(this);
QString user_regex = QStringLiteral(".{4,20}");
QString token_regex = QStringLiteral("[a-z]{48}");
#if QT_VERSION_MAJOR >= 6
QRegularExpressionValidator *username_validator = new QRegularExpressionValidator(this);
QRegularExpressionValidator *token_validator = new QRegularExpressionValidator(this);
username_validator->setRegularExpression(QRegularExpression(user_regex));
token_validator->setRegularExpression(QRegularExpression(token_regex));
#else
QRegExpValidator *username_validator = new QRegExpValidator(this);
QRegExpValidator *token_validator = new QRegExpValidator(this);
username_validator->setRegExp(QRegExp(user_regex));
token_validator->setRegExp(QRegExp(token_regex));
#endif
ui->edit_username->setValidator(username_validator);
ui->edit_token->setValidator(token_validator);
connect(ui->button_generate, &QPushButton::clicked, this, &ConfigureWeb::GenerateToken);
2018-09-16 20:05:51 +02:00
#ifndef USE_DISCORD_PRESENCE
ui->discord_group->setVisible(false);
#endif
SetConfiguration();
RetranslateUI();
2018-09-16 20:05:51 +02:00
}
2018-09-17 17:16:01 +02:00
ConfigureWeb::~ConfigureWeb() = default;
2018-09-16 20:05:51 +02:00
void ConfigureWeb::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureWeb::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureWeb::SetConfiguration() {
connect(ui->edit_username, &QLineEdit::textChanged, this, &ConfigureWeb::VerifyLogin);
connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::VerifyLogin);
ui->edit_username->setText(QString::fromStdString(Settings::values.eden_username.GetValue()));
ui->edit_token->setText(QString::fromStdString(Settings::values.eden_token.GetValue()));
VerifyLogin();
ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence.GetValue());
}
void ConfigureWeb::GenerateToken() {
constexpr size_t length = 48;
QString set = QStringLiteral("abcdefghijklmnopqrstuvwxyz");
QString result;
2018-09-16 20:05:51 +02:00
for (size_t i = 0; i < length; ++i) {
size_t idx = m_rng->bounded(set.length());
result.append(set.at(idx));
}
ui->edit_token->setText(result);
2018-09-16 20:05:51 +02:00
}
void ConfigureWeb::ApplyConfiguration() {
2018-09-16 20:05:51 +02:00
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
Settings::values.eden_username = ui->edit_username->text().toStdString();
Settings::values.eden_token = ui->edit_token->text().toStdString();
2018-09-16 20:05:51 +02:00
}
void ConfigureWeb::VerifyLogin() {
const QPixmap checked = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
const QPixmap failed = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
const bool username_good = ui->edit_username->hasAcceptableInput();
const bool token_good = ui->edit_token->hasAcceptableInput();
2018-09-16 20:05:51 +02:00
if (username_good) {
ui->label_username_verified->setPixmap(checked);
ui->label_username_verified->setToolTip(tr("All Good", "Tooltip"));
} else {
ui->label_username_verified->setPixmap(failed);
ui->label_username_verified->setToolTip(tr("Must be between 4-20 characters", "Tooltip"));
}
2018-09-16 20:05:51 +02:00
if (token_good) {
ui->label_token_verified->setPixmap(checked);
ui->label_token_verified->setToolTip(tr("All Good", "Tooltip"));
} else {
ui->label_token_verified->setPixmap(failed);
ui->label_token_verified->setToolTip(tr("Must be 48 characters, and lowercase a-z", "Tooltip"));
}
2018-09-16 20:05:51 +02:00
}
void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) {
ui->label_disable_info->setVisible(!enabled);
ui->groupBoxWebConfig->setEnabled(enabled);
}