mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-22 12:47:44 +00:00
Re-arrange more code into astra_static and introduce ProfileManagerTest
This commit is contained in:
parent
9d9ab245da
commit
53b6cbf7af
8 changed files with 108 additions and 81 deletions
|
@ -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
|
||||
|
|
28
autotests/profilemanagertest.cpp
Normal file
28
autotests/profilemanagertest.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#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"
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
|
@ -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<Profile *> m_profiles;
|
||||
|
||||
LauncherCore &m_launcher;
|
||||
};
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue