45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <QObject>
|
||
|
|
#include <QStringList>
|
||
|
|
#include <QQmlEngine>
|
||
|
|
|
||
|
|
class LauncherBackend : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
QML_ELEMENT
|
||
|
|
|
||
|
|
Q_PROPERTY(QStringList profileNames READ profileNames NOTIFY profilesChanged)
|
||
|
|
Q_PROPERTY(QStringList versionNames READ versionNames NOTIFY versionsChanged)
|
||
|
|
|
||
|
|
public:
|
||
|
|
explicit LauncherBackend(QObject *parent = nullptr);
|
||
|
|
|
||
|
|
QStringList profileNames() const;
|
||
|
|
QStringList versionNames() const;
|
||
|
|
|
||
|
|
Q_INVOKABLE void addProfile(const QString &name, const QString &login, const QString &password);
|
||
|
|
Q_INVOKABLE void addVersion(const QString &name, const QString &serverUrl);
|
||
|
|
Q_INVOKABLE void launchGame(int profileIndex, int versionIndex);
|
||
|
|
|
||
|
|
signals:
|
||
|
|
void profilesChanged();
|
||
|
|
void versionsChanged();
|
||
|
|
void launched(const QString &profileName, const QString &versionName, const QString &serverUrl);
|
||
|
|
void launchError(const QString &message);
|
||
|
|
|
||
|
|
private:
|
||
|
|
struct Profile { int id; QString name, login, password; };
|
||
|
|
struct Version { int id; QString name, serverUrl; };
|
||
|
|
|
||
|
|
void loadData();
|
||
|
|
void saveProfiles();
|
||
|
|
void saveVersions();
|
||
|
|
|
||
|
|
QList<Profile> m_profiles;
|
||
|
|
QList<Version> m_versions;
|
||
|
|
QString m_dataDir;
|
||
|
|
int m_nextProfileId = 1;
|
||
|
|
int m_nextVersionId = 1;
|
||
|
|
};
|