blob: 1cdf0f5a90773c6b7a0ee7b8fac1310c7e5cb326 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// SPDX-FileCopyrightText: 2017 Citra Emulator Project & 2025 Citron Homebrew Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <QIcon>
#include <QMessageBox>
#include <QtConcurrent/QtConcurrentRun>
#include "common/settings.h"
#include "common/uuid.h"
#include "ui_configure_web.h"
#include "citron/configuration/configure_web.h"
#include "citron/uisettings.h"
ConfigureWeb::ConfigureWeb(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
ui->setupUi(this);
connect(ui->button_reset_token, &QPushButton::clicked, this, &ConfigureWeb::ResetToken);
#ifndef USE_DISCORD_PRESENCE
ui->discord_group->setVisible(false);
#endif
SetConfiguration();
RetranslateUI();
}
ConfigureWeb::~ConfigureWeb() = default;
void ConfigureWeb::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureWeb::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureWeb::SetConfiguration() {
ui->web_credentials_disclaimer->setWordWrap(true);
if (Settings::values.citron_username.GetValue().empty()) {
ui->username->setText(tr("Unspecified"));
} else {
ui->username->setText(QString::fromStdString(Settings::values.citron_username.GetValue()));
}
ui->edit_token->setText(QString::fromStdString(Settings::values.citron_token.GetValue()));
ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence.GetValue());
}
void ConfigureWeb::ApplyConfiguration() {
UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked();
if (Settings::values.citron_username.GetValue().empty()) {
// Backup: default name should already be set by ConfigureProfileManager::UpdateCurrentUser()
Settings::values.citron_username = "torzu";
} else {
// If a name already exist, reassign it to itself (needed for change set with a profile switch)
Settings::values.citron_username = Settings::values.citron_username.GetValue();
}
if (ui->edit_token->text().isEmpty()) {
// If no token specified, automatically generate one
Settings::values.citron_token = Common::UUID::MakeRandom().FormattedString();
} else {
// Otherwise use user-specified value
Settings::values.citron_token = ui->edit_token->text().toStdString();
}
}
void ConfigureWeb::ResetToken() {
// Generate and set token
const auto token = Common::UUID::MakeRandom().FormattedString();
Settings::values.citron_token = token;
// Just to display the label_token_icon pic and tooltip for visual confirmation
ui->label_token_icon->setPixmap(QIcon::fromTheme(QStringLiteral("checked")).pixmap(16));
ui->label_token_icon->setToolTip(tr("Token Changed", "Tooltip"));
ui->username->setText(QString::fromStdString(token));
// Apply the changes
SetConfiguration();
}
void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) {
ui->label_disable_info->setVisible(!enabled);
ui->groupBoxWebConfig->setEnabled(enabled);
}
|