From 53b6cbf7af1cee25f602140ae9534671ff038772 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 22 Aug 2024 18:23:06 -0400 Subject: [PATCH] Re-arrange more code into astra_static and introduce ProfileManagerTest --- autotests/CMakeLists.txt | 6 ++ autotests/profilemanagertest.cpp | 28 +++++++ launcher/CMakeLists.txt | 134 +++++++++++++++--------------- launcher/include/profile.h | 5 +- launcher/include/profilemanager.h | 4 +- launcher/src/launchercore.cpp | 2 +- launcher/src/profile.cpp | 3 +- launcher/src/profilemanager.cpp | 7 +- 8 files changed, 108 insertions(+), 81 deletions(-) create mode 100644 autotests/profilemanagertest.cpp diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 0e92075..ece3d1e 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -13,6 +13,12 @@ ecm_add_test(processwatchertest.cpp NAME_PREFIX "astra-" ) +ecm_add_test(profilemanagertest.cpp + TEST_NAME profilemanagertest + LINK_LIBRARIES astra_static Qt::Test + NAME_PREFIX "astra-" +) + ecm_add_test(utilitytest.cpp TEST_NAME utilitytest LINK_LIBRARIES astra_static Qt::Test diff --git a/autotests/profilemanagertest.cpp b/autotests/profilemanagertest.cpp new file mode 100644 index 0000000..f189cf8 --- /dev/null +++ b/autotests/profilemanagertest.cpp @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2024 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#include + +#include "profilemanager.h" + +class ProfileManagerTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testDummyProfile() + { + ProfileManager profileManager; + + QCOMPARE(profileManager.rowCount({}), 0); + profileManager.load(); + + // the dummy profile + QCOMPARE(profileManager.rowCount({}), 1); + QCOMPARE(profileManager.numProfiles(), 1); + QVERIFY(!profileManager.canDelete(profileManager.getProfile(0))); // the first profile can never be deleted + } +}; + +QTEST_MAIN(ProfileManagerTest) +#include "profilemanagertest.moc" diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 521fd09..010ade3 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -28,26 +28,12 @@ ecm_qt_declare_logging_category(astra_static ) target_sources(astra_static PRIVATE + include/account.h include/patchlist.h include/processwatcher.h + include/profilemanager.h + include/profile.h include/utility.h - src/patchlist.cpp - src/processwatcher.cpp - src/utility.cpp) -target_include_directories(astra_static PUBLIC include) -target_link_libraries(astra_static PUBLIC - Qt6::Core - Qt6::Network - KF6::CoreAddons) - -add_executable(astra) - -qt_add_qml_module(astra - URI zone.xiv.astra - VERSION 1.0) - -target_sources(astra PRIVATE - include/account.h include/accountmanager.h include/assetupdater.h include/benchmarkinstaller.h @@ -59,16 +45,12 @@ target_sources(astra PRIVATE include/headline.h include/launchercore.h include/launchersettings.h - include/logger.h include/patcher.h include/processlogger.h - include/profile.h - include/profilemanager.h include/sapphirelogin.h include/squareenixlogin.h include/steamapi.h - src/account.cpp src/accountmanager.cpp src/assetupdater.cpp src/benchmarkinstaller.cpp @@ -80,15 +62,73 @@ target_sources(astra PRIVATE src/gameinstaller.cpp src/launchercore.cpp src/launchersettings.cpp - src/logger.cpp - src/main.cpp + src/account.cpp + src/patchlist.cpp + src/processwatcher.cpp + src/profilemanager.cpp + src/profile.cpp + src/utility.cpp src/patcher.cpp src/processlogger.cpp - src/profile.cpp - src/profilemanager.cpp src/sapphirelogin.cpp src/squareenixlogin.cpp - src/steamapi.cpp + src/steamapi.cpp) +target_include_directories(astra_static PUBLIC include) +target_link_libraries(astra_static PUBLIC + physis + cotp + Qt6::Core + Qt6::Quick + Qt6::Network + Qt6::Concurrent + Qt6Keychain::Qt6Keychain + KF6::I18n + KF6::CoreAddons + KF6::ConfigCore + KF6::ConfigGui + KF6::Archive + QCoro::Core + QCoro::Network + QCoro::Qml) +kconfig_add_kcfg_files(astra_static GENERATE_MOC config.kcfgc accountconfig.kcfgc profileconfig.kcfgc) +target_include_directories(astra_static PUBLIC include ${CMAKE_BINARY_DIR}) + +if (NOT MSVC) + target_compile_options(astra_static PUBLIC -fexceptions) +endif () + +if (BUILD_FLATPAK) + target_compile_definitions(astra_static PUBLIC FLATPAK) +endif () + +if (ENABLE_GAMEMODE) + target_link_libraries(astra_static PUBLIC ${GAMEMODE_LIBRARIES}) + target_compile_definitions(astra_static PUBLIC ENABLE_GAMEMODE) +endif () + +if (BUILD_SYNC) + target_sources(astra_static PRIVATE + include/charactersync.h + include/syncmanager.h + + src/charactersync.cpp + src/syncmanager.cpp + ) + target_compile_definitions(astra_static PUBLIC BUILD_SYNC) + target_link_libraries(astra_static PRIVATE QuotientQt6) +endif() + +add_executable(astra) + +qt_add_qml_module(astra + URI zone.xiv.astra + VERSION 1.0) + +target_sources(astra PRIVATE + include/logger.h + + src/logger.cpp + src/main.cpp ) qt_target_qml_sources(astra @@ -120,16 +160,6 @@ qt_target_qml_sources(astra ui/Setup/SetupPage.qml ui/Main.qml ) -if (BUILD_SYNC) - target_sources(astra PRIVATE - include/charactersync.h - include/syncmanager.h - - src/charactersync.cpp - src/syncmanager.cpp - ) - target_compile_definitions(astra PRIVATE BUILD_SYNC) -endif() set_source_files_properties(../zone.xiv.astra.svg PROPERTIES QT_RESOURCE_ALIAS /zone.xiv.astra.svg @@ -141,30 +171,13 @@ qt_target_qml_sources(astra ../zone.xiv.astra.svg ) -kconfig_add_kcfg_files(astra GENERATE_MOC config.kcfgc accountconfig.kcfgc profileconfig.kcfgc) -target_include_directories(astra PRIVATE include ${CMAKE_BINARY_DIR}) target_link_libraries(astra PRIVATE astra_static - physis physis-logger - cotp KDAB::kdsingleapplication - Qt6Keychain::Qt6Keychain Qt6::Widgets - Qt6::Quick Qt6::QuickControls2 - Qt6::Concurrent - KF6::Kirigami - KF6::I18n - KF6::ConfigCore - KF6::ConfigGui - KF6::Archive - QCoro::Core - QCoro::Network - QCoro::Qml) -if (BUILD_SYNC) - target_link_libraries(astra PRIVATE QuotientQt6) -endif() + KF6::Kirigami) if (BUILD_WEBVIEW) target_link_libraries(astra PRIVATE @@ -179,19 +192,6 @@ if (WIN32) ) endif () -if (NOT MSVC) - target_compile_options(astra PRIVATE -fexceptions) -endif () - -if (BUILD_FLATPAK) - target_compile_definitions(astra PRIVATE FLATPAK) -endif () - -if (ENABLE_GAMEMODE) - target_link_libraries(astra PRIVATE ${GAMEMODE_LIBRARIES}) - target_compile_definitions(astra PRIVATE ENABLE_GAMEMODE) -endif () - if (WIN32) set_target_properties(astra PROPERTIES WIN32_EXECUTABLE TRUE diff --git a/launcher/include/profile.h b/launcher/include/profile.h index 4acd358..bcd8fe1 100644 --- a/launcher/include/profile.h +++ b/launcher/include/profile.h @@ -9,7 +9,6 @@ class Account; class ProfileConfig; -class LauncherCore; class Profile : public QObject { @@ -45,7 +44,7 @@ class Profile : public QObject Q_PROPERTY(QString subtitle READ subtitle NOTIFY gameInstallChanged) public: - explicit Profile(LauncherCore &launcher, const QString &key, QObject *parent = nullptr); + explicit Profile(const QString &key, QObject *parent = nullptr); enum class WineType { BuiltIn, Custom }; Q_ENUM(WineType) @@ -213,6 +212,4 @@ private: QString m_frontierUrl; bool m_loggedIn = false; - - LauncherCore &m_launcher; }; \ No newline at end of file diff --git a/launcher/include/profilemanager.h b/launcher/include/profilemanager.h index 058eaea..64b6d7c 100644 --- a/launcher/include/profilemanager.h +++ b/launcher/include/profilemanager.h @@ -16,7 +16,7 @@ class ProfileManager : public QAbstractListModel Q_PROPERTY(int numProfiles READ numProfiles NOTIFY profilesChanged) public: - explicit ProfileManager(LauncherCore &launcher, QObject *parent = nullptr); + explicit ProfileManager(QObject *parent = nullptr); void load(); @@ -54,6 +54,4 @@ private: void insertProfile(Profile *profile); QList m_profiles; - - LauncherCore &m_launcher; }; \ No newline at end of file diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 27d8915..d8fed35 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -36,7 +36,7 @@ LauncherCore::LauncherCore() m_mgr = new QNetworkAccessManager(this); m_sapphireLogin = new SapphireLogin(*this, this); m_squareEnixLogin = new SquareEnixLogin(*this, this); - m_profileManager = new ProfileManager(*this, this); + m_profileManager = new ProfileManager(this); m_accountManager = new AccountManager(*this, this); m_runner = new GameRunner(*this, this); diff --git a/launcher/src/profile.cpp b/launcher/src/profile.cpp index 25db98d..961d4d9 100644 --- a/launcher/src/profile.cpp +++ b/launcher/src/profile.cpp @@ -16,11 +16,10 @@ using namespace Qt::StringLiterals; -Profile::Profile(LauncherCore &launcher, const QString &key, QObject *parent) +Profile::Profile(const QString &key, QObject *parent) : QObject(parent) , m_uuid(key) , m_config(new ProfileConfig(key)) - , m_launcher(launcher) { readGameVersion(); readWineInfo(); diff --git a/launcher/src/profilemanager.cpp b/launcher/src/profilemanager.cpp index 656e603..d6071cd 100644 --- a/launcher/src/profilemanager.cpp +++ b/launcher/src/profilemanager.cpp @@ -10,9 +10,8 @@ using namespace Qt::StringLiterals; -ProfileManager::ProfileManager(LauncherCore &launcher, QObject *parent) +ProfileManager::ProfileManager(QObject *parent) : QAbstractListModel(parent) - , m_launcher(launcher) { } @@ -43,7 +42,7 @@ Profile *ProfileManager::getProfileByUUID(const QString &uuid) Profile *ProfileManager::addProfile() { - const auto newProfile = new Profile(m_launcher, QUuid::createUuid().toString(), this); + const auto newProfile = new Profile(QUuid::createUuid().toString(), this); newProfile->setName(QStringLiteral("New Profile")); insertProfile(newProfile); @@ -85,7 +84,7 @@ void ProfileManager::load() if (id.contains("profile-"_L1)) { const QString uuid = QString(id).remove("profile-"_L1); qInfo(ASTRA_LOG) << "Loading profile" << uuid; - const auto profile = new Profile(m_launcher, uuid, this); + const auto profile = new Profile(uuid, this); insertProfile(profile); } }