2026-03-10 06:51:08 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
2025-08-30 23:08:04 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2015 Citra Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-08-19 17:00:56 -03:00
|
|
|
|
2015-08-31 21:35:33 -07:00
|
|
|
#include <cmath>
|
2018-08-29 15:42:53 +02:00
|
|
|
#include <QPainter>
|
2023-11-19 11:49:51 -05:00
|
|
|
|
2025-11-09 18:07:38 +01:00
|
|
|
#include "applets/qt_profile_select.h"
|
2026-03-12 18:29:15 +01:00
|
|
|
#include "common/logging.h"
|
2025-11-09 18:07:38 +01:00
|
|
|
#include "core/frontend/applets/profile_select.h"
|
|
|
|
|
#include "core/hle/service/acc/profile_manager.h"
|
2025-12-07 00:29:37 +01:00
|
|
|
#include "frontend_common/data_manager.h"
|
2025-11-09 18:07:38 +01:00
|
|
|
#include "qt_common/qt_common.h"
|
2018-01-11 20:33:56 -07:00
|
|
|
#include "yuzu/util/util.h"
|
2023-11-19 11:49:51 -05:00
|
|
|
|
2023-10-07 17:26:04 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include "common/fs/file.h"
|
|
|
|
|
#endif
|
2015-08-31 21:35:33 -07:00
|
|
|
|
2015-08-19 17:00:56 -03:00
|
|
|
QFont GetMonospaceFont() {
|
2019-05-20 14:44:13 -04:00
|
|
|
QFont font(QStringLiteral("monospace"));
|
2015-08-19 17:00:56 -03:00
|
|
|
// Automatic fallback to a monospace font on on platforms without a font called "monospace"
|
|
|
|
|
font.setStyleHint(QFont::Monospace);
|
|
|
|
|
font.setFixedPitch(true);
|
|
|
|
|
return font;
|
|
|
|
|
}
|
2015-08-31 21:35:33 -07:00
|
|
|
|
|
|
|
|
QString ReadableByteSize(qulonglong size) {
|
2025-12-07 00:29:37 +01:00
|
|
|
return QString::fromStdString(FrontendCommon::DataManager::ReadableBytesSize(size));
|
2015-08-31 21:35:33 -07:00
|
|
|
}
|
2018-08-29 15:42:53 +02:00
|
|
|
|
|
|
|
|
QPixmap CreateCirclePixmapFromColor(const QColor& color) {
|
|
|
|
|
QPixmap circle_pixmap(16, 16);
|
|
|
|
|
circle_pixmap.fill(Qt::transparent);
|
|
|
|
|
QPainter painter(&circle_pixmap);
|
2018-09-17 05:57:23 -04:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2018-08-29 15:42:53 +02:00
|
|
|
painter.setPen(color);
|
|
|
|
|
painter.setBrush(color);
|
2018-09-17 05:57:23 -04:00
|
|
|
painter.drawEllipse({circle_pixmap.width() / 2.0, circle_pixmap.height() / 2.0}, 7.0, 7.0);
|
2018-08-29 15:42:53 +02:00
|
|
|
return circle_pixmap;
|
|
|
|
|
}
|
2023-10-07 17:26:04 +02:00
|
|
|
|
2025-11-09 18:07:38 +01:00
|
|
|
const std::optional<Common::UUID> GetProfileID() {
|
|
|
|
|
// if there's only a single profile, the user probably wants to use that... right?
|
|
|
|
|
const auto& profiles = QtCommon::system->GetProfileManager().FindExistingProfileUUIDs();
|
|
|
|
|
if (profiles.size() == 1) {
|
|
|
|
|
return profiles[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto select_profile = [] {
|
|
|
|
|
const Core::Frontend::ProfileSelectParameters parameters{
|
2026-03-10 06:51:08 +01:00
|
|
|
.mode = Service::AM::Frontend::UiMode::UserSelector,
|
|
|
|
|
.invalid_uid_list = {},
|
|
|
|
|
.display_options = {},
|
|
|
|
|
.purpose = Service::AM::Frontend::UserSelectionPurpose::General,
|
|
|
|
|
};
|
2025-11-09 18:07:38 +01:00
|
|
|
QtProfileSelectionDialog dialog(*QtCommon::system, QtCommon::rootObject, parameters);
|
|
|
|
|
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
|
|
|
|
|
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dialog.GetIndex();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto index = select_profile();
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto uuid =
|
|
|
|
|
QtCommon::system->GetProfileManager().GetUser(static_cast<std::size_t>(index));
|
|
|
|
|
ASSERT(uuid);
|
|
|
|
|
|
|
|
|
|
return uuid;
|
|
|
|
|
}
|
|
|
|
|
std::string GetProfileIDString() {
|
|
|
|
|
const auto uuid = GetProfileID();
|
|
|
|
|
if (!uuid)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
auto user_id = uuid->AsU128();
|
|
|
|
|
|
|
|
|
|
return fmt::format("{:016X}{:016X}", user_id[1], user_id[0]);
|
|
|
|
|
}
|