1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-25 05:47:45 +00:00

Port to declarative type registration

This commit is contained in:
Joshua Goins 2023-09-16 18:01:02 -04:00
parent f4a8b9ac78
commit 3e7139c216
9 changed files with 35 additions and 26 deletions

View file

@ -5,6 +5,7 @@
#include <QDir>
#include <QObject>
#include <QtQml/qqmlregistration.h>
#include "accountconfig.h"
@ -13,6 +14,8 @@ class LauncherCore;
class Account : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use from AccountManager")
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(int language READ language WRITE setLanguage NOTIFY languageChanged)

View file

@ -4,12 +4,15 @@
#pragma once
#include <QAbstractListModel>
#include <QtQml/qqmlregistration.h>
#include "account.h"
class AccountManager : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use LauncherCore.accountManager")
public:
explicit AccountManager(LauncherCore &launcher, QObject *parent = nullptr);

View file

@ -5,12 +5,16 @@
#include <QObject>
#include <QString>
#include <QtQml/qqmlregistration.h>
class LauncherCore;
class CompatibilityToolInstaller : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use LauncherCore.createCompatInstaller")
public:
CompatibilityToolInstaller(LauncherCore &launcher, QObject *parent = nullptr);

View file

@ -5,6 +5,7 @@
#include <QObject>
#include <QString>
#include <QtQml/qqmlregistration.h>
class LauncherCore;
class Profile;
@ -12,6 +13,9 @@ class Profile;
class GameInstaller : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use Launchercore.createInstaller")
public:
GameInstaller(LauncherCore &launcher, Profile &profile, QObject *parent = nullptr);

View file

@ -54,6 +54,8 @@ struct LoginAuth {
class LauncherCore : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(bool loadingFinished READ isLoadingFinished NOTIFY loadingFinished)
Q_PROPERTY(bool hasAccount READ hasAccount NOTIFY accountChanged)
@ -72,13 +74,15 @@ class LauncherCore : public QObject
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
public:
explicit LauncherCore(bool isSteam);
LauncherCore();
QNetworkAccessManager *mgr;
ProfileManager *profileManager();
AccountManager *accountManager();
void setIsSteam(bool isSteam);
/*
* Begins the login process, and may call SquareBoot or SapphireLauncher depending on the profile type.
* It's designed to be opaque as possible to the caller.

View file

@ -4,6 +4,7 @@
#pragma once
#include <QObject>
#include <QtQml/qqmlregistration.h>
#include "squareboot.h"
@ -13,6 +14,8 @@ class ProfileConfig;
class Profile : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use from ProfileManager")
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString gamePath READ gamePath WRITE setGamePath NOTIFY gamePathChanged)

View file

@ -4,12 +4,15 @@
#pragma once
#include <QAbstractListModel>
#include <QtQml/qqmlregistration.h>
#include "profile.h"
class ProfileManager : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use LauncherCore.profileManager")
public:
explicit ProfileManager(LauncherCore &launcher, QObject *parent = nullptr);

View file

@ -371,8 +371,7 @@ void LauncherCore::readInitialInformation()
Q_EMIT loadingFinished();
}
LauncherCore::LauncherCore(bool isSteam)
: m_isSteam(isSteam)
LauncherCore::LauncherCore()
{
mgr = new QNetworkAccessManager(this);
sapphireLauncher = new SapphireLauncher(*this, this);
@ -704,3 +703,8 @@ bool LauncherCore::isSteamDeck() const
{
return steamApi->isDeck();
}
void LauncherCore::setIsSteam(bool isSteam)
{
m_isSteam = isSteam;
}

View file

@ -65,32 +65,13 @@ int main(int argc, char *argv[])
return 0;
}
}
LauncherCore c(parser.isSet(steamOption));
#else
LauncherCore c(false);
#endif
qmlRegisterSingletonInstance("zone.xiv.astra", 1, 0, "LauncherCore", &c);
qmlRegisterUncreatableType<GameInstaller>("zone.xiv.astra", 1, 0, "GameInstaller", QStringLiteral("Use LauncherCore::createInstaller"));
qmlRegisterUncreatableType<CompatibilityToolInstaller>("zone.xiv.astra",
1,
0,
"CompatibilityToolInstaller",
QStringLiteral("Use LauncherCore::createCompatInstaller"));
qmlRegisterUncreatableType<AccountManager>("zone.xiv.astra", 1, 0, "AccountManager", QStringLiteral("Use LauncherCore::accountManager"));
qmlRegisterUncreatableType<ProfileManager>("zone.xiv.astra", 1, 0, "ProfileManager", QStringLiteral("Use LauncherCore::profileManager"));
qmlRegisterUncreatableType<Profile>("zone.xiv.astra", 1, 0, "Profile", QStringLiteral("Use from ProfileManager"));
qmlRegisterUncreatableType<Account>("zone.xiv.astra", 1, 0, "Account", QStringLiteral("Use from AccountManager"));
qmlRegisterSingletonType("zone.xiv.astra", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue {
return engine->toScriptValue(KAboutData::applicationData());
});
qmlRegisterUncreatableType<Headline>("zone.xiv.astra", 1, 0, "Headline", QStringLiteral("Use from AccountManager"));
qRegisterMetaType<Banner>("Banner");
qRegisterMetaType<QList<Banner>>("QList<Banner>");
qRegisterMetaType<QList<News>>("QList<News>");
QQmlApplicationEngine engine;
auto core = engine.singletonInstance<LauncherCore *>("zone.xiv.astra", "LauncherCore");
core->setIsSteam(parser.isSet(steamOption));
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit);