mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-16 03:57:01 +02:00
[qt_common] reorg + checkstate abstraction (#2735)
no diff. in functionality, just confirm builds on ubuntu 24.04/debian 12 Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2735
This commit is contained in:
parent
5f9dba40a0
commit
fff8e2026f
77 changed files with 174 additions and 129 deletions
|
|
@ -1,36 +1,45 @@
|
|||
# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
add_library(qt_common STATIC
|
||||
qt_common.h
|
||||
qt_common.cpp
|
||||
|
||||
uisettings.cpp
|
||||
uisettings.h
|
||||
config/uisettings.cpp
|
||||
config/uisettings.h
|
||||
config/qt_config.cpp
|
||||
config/qt_config.h
|
||||
config/shared_translation.cpp
|
||||
config/shared_translation.h
|
||||
|
||||
qt_config.cpp
|
||||
qt_config.h
|
||||
util/path.h util/path.cpp
|
||||
util/game.h util/game.cpp
|
||||
util/meta.h util/meta.cpp
|
||||
util/content.h util/content.cpp
|
||||
util/rom.h util/rom.cpp
|
||||
util/applet.h util/applet.cpp
|
||||
util/compress.h util/compress.cpp
|
||||
|
||||
abstract/qt_frontend_util.h abstract/qt_frontend_util.cpp
|
||||
abstract/qt_progress_dialog.h abstract/qt_progress_dialog.cpp
|
||||
|
||||
shared_translation.cpp
|
||||
shared_translation.h
|
||||
qt_path_util.h qt_path_util.cpp
|
||||
qt_game_util.h qt_game_util.cpp
|
||||
qt_frontend_util.h qt_frontend_util.cpp
|
||||
qt_meta.h qt_meta.cpp
|
||||
qt_content_util.h qt_content_util.cpp
|
||||
qt_rom_util.h qt_rom_util.cpp
|
||||
qt_applet_util.h qt_applet_util.cpp
|
||||
qt_progress_dialog.h qt_progress_dialog.cpp
|
||||
qt_string_lookup.h
|
||||
qt_compress.h qt_compress.cpp
|
||||
qt_compat.h
|
||||
|
||||
discord/discord.h
|
||||
)
|
||||
|
||||
create_target_directory_groups(qt_common)
|
||||
|
||||
if (USE_DISCORD_PRESENCE)
|
||||
target_sources(qt_common PRIVATE
|
||||
discord/discord_impl.cpp
|
||||
discord/discord_impl.h
|
||||
)
|
||||
target_link_libraries(qt_common PUBLIC DiscordRPC::discord-rpc Qt6::Network)
|
||||
target_compile_definitions(qt_common PUBLIC USE_DISCORD_PRESENCE)
|
||||
endif()
|
||||
|
||||
# TODO(crueter)
|
||||
if (ENABLE_QT)
|
||||
target_link_libraries(qt_common PRIVATE Qt6::Widgets)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "common/settings_enums.h"
|
||||
#include "common/settings_setting.h"
|
||||
#include "common/time_zone.h"
|
||||
#include "qt_common/uisettings.h"
|
||||
#include "qt_common/config/uisettings.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <QSettings>
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "qt_common/uisettings.h"
|
||||
#include "qt_common/config/uisettings.h"
|
||||
|
||||
#ifndef CANNOT_EXPLICITLY_INSTANTIATE
|
||||
namespace Settings {
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
#include "common/common_types.h"
|
||||
#include "common/settings.h"
|
||||
#include "common/settings_enums.h"
|
||||
#include "qt_common/qt_config.h"
|
||||
#include "qt_common/config/qt_config.h"
|
||||
|
||||
using Settings::Category;
|
||||
using Settings::ConfirmStop;
|
||||
27
src/qt_common/discord/discord.h
Normal file
27
src/qt_common/discord/discord.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace DiscordRPC {
|
||||
|
||||
class DiscordInterface {
|
||||
public:
|
||||
virtual ~DiscordInterface() = default;
|
||||
|
||||
virtual void Pause() = 0;
|
||||
virtual void Update() = 0;
|
||||
};
|
||||
|
||||
class NullImpl : public DiscordInterface {
|
||||
public:
|
||||
~NullImpl() = default;
|
||||
|
||||
void Pause() override {}
|
||||
void Update() override {}
|
||||
};
|
||||
|
||||
} // namespace DiscordRPC
|
||||
124
src/qt_common/discord/discord_impl.cpp
Normal file
124
src/qt_common/discord/discord_impl.cpp
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include <discord_rpc.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "qt_common/discord/discord_impl.h"
|
||||
|
||||
namespace DiscordRPC {
|
||||
|
||||
DiscordImpl::DiscordImpl(Core::System& system_) : system{system_} {
|
||||
DiscordEventHandlers handlers{};
|
||||
// The number is the client ID for Eden, it's used for images and the
|
||||
// application name
|
||||
Discord_Initialize("1397286652128264252", &handlers, 1, nullptr);
|
||||
}
|
||||
|
||||
DiscordImpl::~DiscordImpl() {
|
||||
Discord_ClearPresence();
|
||||
Discord_Shutdown();
|
||||
}
|
||||
|
||||
void DiscordImpl::Pause() {
|
||||
Discord_ClearPresence();
|
||||
}
|
||||
|
||||
std::string DiscordImpl::GetGameString(const std::string& title) {
|
||||
// Convert to lowercase
|
||||
std::string icon_name = Common::ToLower(title);
|
||||
|
||||
// Replace spaces with dashes
|
||||
std::replace(icon_name.begin(), icon_name.end(), ' ', '-');
|
||||
|
||||
// Remove non-alphanumeric characters but keep dashes
|
||||
std::erase_if(icon_name, [](char c) { return !std::isalnum(c) && c != '-'; });
|
||||
|
||||
// Remove dashes from the start and end of the string
|
||||
icon_name.erase(icon_name.begin(), std::find_if(icon_name.begin(), icon_name.end(),
|
||||
[](int ch) { return ch != '-'; }));
|
||||
icon_name.erase(
|
||||
std::find_if(icon_name.rbegin(), icon_name.rend(), [](int ch) { return ch != '-'; }).base(),
|
||||
icon_name.end());
|
||||
|
||||
// Remove double dashes
|
||||
icon_name.erase(std::unique(icon_name.begin(), icon_name.end(),
|
||||
[](char a, char b) { return a == '-' && b == '-'; }),
|
||||
icon_name.end());
|
||||
|
||||
return icon_name;
|
||||
}
|
||||
|
||||
void DiscordImpl::UpdateGameStatus(bool use_default) {
|
||||
const std::string default_text = "Eden is an emulator for the Nintendo Switch";
|
||||
const std::string default_image = "https://git.eden-emu.dev/eden-emu/eden/raw/branch/master/"
|
||||
"dist/qt_themes/default/icons/256x256/eden_named.png";
|
||||
const std::string url = use_default ? default_image : game_url;
|
||||
s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
DiscordRichPresence presence{};
|
||||
|
||||
presence.largeImageKey = url.c_str();
|
||||
presence.largeImageText = game_title.c_str();
|
||||
presence.smallImageKey = default_image.c_str();
|
||||
presence.smallImageText = default_text.c_str();
|
||||
presence.state = game_title.c_str();
|
||||
presence.details = "Currently in game";
|
||||
presence.startTimestamp = start_time;
|
||||
Discord_UpdatePresence(&presence);
|
||||
}
|
||||
|
||||
void DiscordImpl::Update() {
|
||||
const std::string default_text = "Eden is an emulator for the Nintendo Switch";
|
||||
const std::string default_image = "https://git.eden-emu.dev/eden-emu/eden/raw/branch/master/"
|
||||
"dist/qt_themes/default/icons/256x256/eden_named.png";
|
||||
|
||||
if (system.IsPoweredOn()) {
|
||||
system.GetAppLoader().ReadTitle(game_title);
|
||||
|
||||
// Used to format Icon URL for yuzu website game compatibility page
|
||||
std::string icon_name = GetGameString(game_title);
|
||||
game_url = fmt::format(
|
||||
"https://raw.githubusercontent.com/eden-emulator/boxart/refs/heads/master/img/{}.png",
|
||||
icon_name);
|
||||
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(QString::fromStdString(game_url)));
|
||||
request.setTransferTimeout(3000);
|
||||
QNetworkReply* reply = manager.head(request);
|
||||
QEventLoop request_event_loop;
|
||||
reply->connect(reply, &QNetworkReply::finished, &request_event_loop, &QEventLoop::quit);
|
||||
request_event_loop.exec();
|
||||
UpdateGameStatus(reply->error());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
s64 start_time = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
|
||||
DiscordRichPresence presence{};
|
||||
presence.largeImageKey = default_image.c_str();
|
||||
presence.largeImageText = default_text.c_str();
|
||||
presence.details = "Currently not in game";
|
||||
presence.startTimestamp = start_time;
|
||||
Discord_UpdatePresence(&presence);
|
||||
}
|
||||
} // namespace DiscordRPC
|
||||
37
src/qt_common/discord/discord_impl.h
Normal file
37
src/qt_common/discord/discord_impl.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "discord.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace DiscordRPC {
|
||||
|
||||
class DiscordImpl : public DiscordInterface {
|
||||
public:
|
||||
DiscordImpl(Core::System& system_);
|
||||
~DiscordImpl() override;
|
||||
|
||||
void Pause() override;
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
std::string GetGameString(const std::string& title);
|
||||
void UpdateGameStatus(bool use_default);
|
||||
|
||||
std::string game_url{};
|
||||
std::string game_title{};
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
|
||||
} // namespace DiscordRPC
|
||||
14
src/qt_common/qt_compat.h
Normal file
14
src/qt_common/qt_compat.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtVersionChecks>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
|
||||
#define STATE_CHANGED stateChanged
|
||||
#define CHECKSTATE_TYPE int
|
||||
#else
|
||||
#define STATE_CHANGED checkStateChanged
|
||||
#define CHECKSTATE_TYPE Qt::CheckState
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_applet_util.h"
|
||||
#include "qt_common/util/applet.h"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_compress.h"
|
||||
#include "compress.h"
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
#include <QDirIterator>
|
||||
|
|
@ -24,7 +24,7 @@ bool compressDir(QString fileCompressed,
|
|||
|
||||
// See how big the overall fs structure is
|
||||
// good approx. of total progress
|
||||
// TODO(crueter): QDirListing impl
|
||||
// TODO(crueter): QDirListing impl... or fs::recursive_dir_iterator
|
||||
QDirIterator iter(dir,
|
||||
QDir::NoDotAndDotDot | QDir::Hidden | QDir::Files,
|
||||
QDirIterator::Subdirectories);
|
||||
|
|
@ -1,22 +1,24 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_content_util.h"
|
||||
#include "qt_common/util/content.h"
|
||||
#include "qt_common/util/game.h"
|
||||
|
||||
#include "common/fs/fs.h"
|
||||
#include "core/hle/service/acc/profile_manager.h"
|
||||
#include "frontend_common/content_manager.h"
|
||||
#include "frontend_common/data_manager.h"
|
||||
#include "frontend_common/firmware_manager.h"
|
||||
|
||||
#include "qt_common/qt_common.h"
|
||||
#include "qt_common/qt_compress.h"
|
||||
#include "qt_common/qt_game_util.h"
|
||||
#include "qt_common/qt_progress_dialog.h"
|
||||
#include "qt_frontend_util.h"
|
||||
#include "compress.h"
|
||||
#include "qt_common/abstract/qt_progress_dialog.h"
|
||||
#include "qt_common/abstract/qt_frontend_util.h"
|
||||
|
||||
#include <QFuture>
|
||||
#include <QtConcurrentRun>
|
||||
#include <JlCompress.h>
|
||||
#include <qfuturewatcher.h>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
namespace QtCommon::Content {
|
||||
|
||||
|
|
@ -208,6 +210,7 @@ QString UnzipFirmwareToTmp(const QString& location)
|
|||
|
||||
QFile zip(location);
|
||||
|
||||
// TODO(crueter): use QtCompress
|
||||
QStringList result = JlCompress::extractDir(&zip, qCacheDir);
|
||||
if (result.isEmpty()) {
|
||||
return QString();
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_game_util.h"
|
||||
#include "qt_common/util/game.h"
|
||||
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/hle/service/am/am_types.h"
|
||||
#include "frontend_common/content_manager.h"
|
||||
#include "qt_common.h"
|
||||
#include "qt_common/uisettings.h"
|
||||
#include "qt_frontend_util.h"
|
||||
#include "qt_common/qt_common.h"
|
||||
#include "qt_common/config/uisettings.h"
|
||||
#include "qt_common/abstract/qt_frontend_util.h"
|
||||
#include "yuzu/util/util.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_meta.h"
|
||||
#include "qt_common/util/meta.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/core.h"
|
||||
#include "core/frontend/applets/cabinet.h"
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_path_util.h"
|
||||
#include "qt_common/util/path.h"
|
||||
#include <QDesktopServices>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "qt_common/qt_frontend_util.h"
|
||||
#include "qt_common/abstract/qt_frontend_util.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace QtCommon::Path {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_rom_util.h"
|
||||
#include "qt_common/util/rom.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue