-
Notifications
You must be signed in to change notification settings - Fork 14
/
profilemanager.h
131 lines (95 loc) · 3.4 KB
/
profilemanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef PROFILEMANAGER_H
#define PROFILEMANAGER_H
#include <QObject>
#include <QList>
#include <QSettings>
#include <QQmlPropertyMap>
class ProfileManager;
class ProfileInfo : public QObject {
Q_OBJECT
Q_PROPERTY(QString name MEMBER name WRITE setName NOTIFY changed)
Q_PROPERTY(bool nameLocked MEMBER nameLocked CONSTANT)
Q_PROPERTY(VersionType versionType MEMBER versionType NOTIFY changed)
Q_PROPERTY(QString versionDirName MEMBER versionDirName NOTIFY changed)
Q_PROPERTY(int versionCode MEMBER versionCode NOTIFY changed)
Q_PROPERTY(bool dataDirCustom MEMBER dataDirCustom NOTIFY changed)
Q_PROPERTY(QString dataDir MEMBER dataDir NOTIFY changed)
Q_PROPERTY(bool windowCustomSize MEMBER windowCustomSize NOTIFY changed)
Q_PROPERTY(int windowWidth MEMBER windowWidth NOTIFY changed)
Q_PROPERTY(int windowHeight MEMBER windowHeight NOTIFY changed)
Q_PROPERTY(QString arch MEMBER arch NOTIFY changed)
Q_PROPERTY(int texturePatch MEMBER texturePatch WRITE setTexturePatch NOTIFY changed)
Q_PROPERTY(QStringList mods MEMBER mods NOTIFY changed)
Q_PROPERTY(QString commandline MEMBER commandline NOTIFY changed)
Q_PROPERTY(QQmlPropertyMap* env MEMBER env NOTIFY changed)
#ifdef __APPLE__
Q_PROPERTY(int graphicsAPI MEMBER graphicsAPI WRITE setGraphicsAPI NOTIFY changed)
#endif
ProfileManager* manager;
public:
enum VersionType {
LATEST_GOOGLE_PLAY, LOCKED_NAME, LOCKED_CODE
};
Q_ENUM(VersionType)
ProfileInfo(ProfileManager* pm = nullptr);
bool nameLocked = false;
QString name;
VersionType versionType = VersionType::LATEST_GOOGLE_PLAY;
QString versionDirName;
int versionCode;
bool dataDirCustom = false;
QString dataDir;
bool windowCustomSize = false;
int windowWidth = 720;
int windowHeight = 480;
#ifdef __APPLE__
int graphicsAPI = 0;
#endif
QString arch;
int texturePatch = 0;
QStringList mods;
QString commandline;
QQmlPropertyMap* env;
public slots:
void setName(QString const& newName);
void save();
void setTexturePatch(int val) {
texturePatch = val;
}
#ifdef __APPLE__
void setGraphicsAPI(int val) {
graphicsAPI = val;
}
#endif
void clearEnv();
signals:
void changed();
};
class ProfileManager : public QObject {
Q_OBJECT
Q_PROPERTY(QList<QObject*> profiles READ profiles NOTIFY profilesChanged)
Q_PROPERTY(ProfileInfo* defaultProfile READ defaultProfile CONSTANT)
Q_PROPERTY(ProfileInfo* activeProfile READ activeProfile WRITE setActiveProfile NOTIFY activeProfileChanged)
private:
QString m_baseDir;
QScopedPointer<QSettings> m_settings;
QList<ProfileInfo*> m_profiles;
ProfileInfo* m_defaultProfile;
ProfileInfo* m_activeProfile;
void loadProfiles();
public:
explicit ProfileManager(QObject *parent = nullptr);
QSettings& settings() { return *m_settings; }
ProfileInfo* defaultProfile() const { return m_defaultProfile; }
QList<QObject*> const& profiles() const { return (QList<QObject*>&) m_profiles; }
ProfileInfo* activeProfile() const { return m_activeProfile; }
void setActiveProfile(ProfileInfo* profile);
public slots:
ProfileInfo* createProfile(QString name);
void deleteProfile(ProfileInfo* profile);
bool validateName(QString const& name);
signals:
void profilesChanged();
void activeProfileChanged();
};
#endif // PROFILEMANAGER_H