-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules.h
187 lines (150 loc) · 5.38 KB
/
modules.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifndef MODULES_H
#define MODULES_H
#include <QObject>
#include <QJsonObject>
#include <QMap>
#include <QString>
#include <QJsonArray>
#include "kzp_coroutines.h"
using namespace KZPCoroutines;
class QQmlApplicationEngine;
class QQuickWindow;
namespace Modules{
namespace ModuleUtility{
enum ModuleType{
MODULE = 0, // qml
ANIMATION = 1, // Animation image
IMAGE = 2, // static image
REPO = 3 // modules repo
};
struct ModuleManifest{
QString name;
QString folder;
QString url;
ModuleType type;
quint32 version;
QStringList files;
};
struct ImageManifest{
QString name;
QString entry;
QString reference;
};
struct Repository{
QString name;
QString folder;
QString url;
QStringList images;
QStringList modules;
};
enum ActionType{
DOWNLOAD = 0, // Download using NAM
INSTALL = 1, // Install
FETCH = 2, // Fetch manifest/repo (json)
SEARCH = 3 // Look at HDD for current installed
};
struct Action{
QString source;
QString destination;
QString data;
};
typedef QList<Action> ActionList;
struct InstalledModule{
ModuleManifest manifest;
bool needUpdate = false;
bool inUse = false;
};
typedef QList<InstalledModule> InstalledList;
static ModuleManifest createManifestFromJson(QString json_str);
static ModuleManifest createManifestFromJsObject(QJsonObject obj);
// static Repository createRepositoryFromJson(QString json_str);
// static Repository createRepositoryFromJsObject(QJsonObject obj);
};
/*******************************************************
* Modules Manager controls the coroutines
* used to update and verify the installed Modules
*
*
*
*
*
******************************************************/
class ModuleManager : public QObject
{
Q_OBJECT
Q_PROPERTY(bool moduleManagerOpen READ isManagerOpen WRITE toggleModuleManager NOTIFY moduleManagerToggled)
public:
explicit ModuleManager(QObject *parent = nullptr);
~ModuleManager();
void checkUpdates();
void checkModuleUpdates();
void setRootPath(QString path);
void fetchModuleManifests(QString task, QVector<QString> manifests);
Q_INVOKABLE QJsonArray getInstalledModules();
Q_INVOKABLE QJsonArray getInstalledRepositories();
Q_INVOKABLE QJsonArray getInstalledImages();
Q_INVOKABLE void releaseModulesCache();
Q_INVOKABLE bool isManagerOpen() { return mModuleWindow != nullptr; }
Q_INVOKABLE bool openExplorerAt(QString path);
// repository commands
Q_INVOKABLE void fetchRepoData(QJsonObject repo);
Q_INVOKABLE void addRepo(QJsonObject repo);
Q_INVOKABLE bool removeRepo(QJsonObject repo);
Q_INVOKABLE void testRepo(QString url);
// Q_INVOKABLE QJsonArray getRepoImageManifests(QJsonObject repo);
signals:
//UX signals
void moduleManagerToggled(bool open);
void taskStarted(QString file, KZPCoroutines::TaskType type);
void taskFinished(QString file, KZPCoroutines::TaskType type);
void installedModulesCheck(QVector<QJsonObject> local_manifests);
void moduleManifests(const QVector<ObjectReply>& manifests);
void modulesNeedUpdated(QJsonObject modules);
// from KZP (Local Module Cache)
void startedCacheLocal();
void directoryError(QString error_str);
void moduleFound(QJsonObject module);
void finishedCachingLocal(QJsonArray data);
// Image finder
void lookingForImages();
void imageFound(QJsonObject image);
void foundImagesFinished(QJsonArray imagePaths);
// repo image finder
void repoImageManifestReceived(QJsonObject manifest);
void repoImagesReceived(const QVector<ObjectReply>& manifestFiles);
void repoImageReceived(const QString url, QJsonObject imageManifest);
// repo module finder
void repoModuleManifestReceived(QJsonObject module);
void repoModulesRecieved(QJsonArray modules);
void repoTest(QJsonObject data);
public slots:
void toggleModuleManager(bool open);
protected:
QMap<QString, FetchManifestFiles*> mRequestPool;
QString mRootPath;
QJsonArray mInstalledModules;
CacheLocalModules* mModuleCacher;
FetchImageFiles* mImageFileFetcher;
FetchRepoManifests* mRepoModuleFetcher;
// CheckExamplesThread* mCheckThread;
bool mManagerOpen;
QQmlApplicationEngine* mModuleEngine;
QQuickWindow* mModuleWindow;
bool repoExists(const QJsonArray &repos, QString name, QString url);
bool verifyRepo(QJsonObject &repo, bool &exists);
protected slots:
void createManager();
void failedRepoTest();
void writeRepos(QJsonArray repos);
void verifyFetchedImageManifests();
void verifyFetchedImageManifest(const QString url, QJsonObject data);
void receivedRepoTest();
void releaseManager();
void receivedFiles();
void fetchModulesError(QString error);
void cleanupLocalModuleCache();
void cleanupFetchImageFiles();
//void checkModulesForUpdates();
};
}; // end modules namespace
#endif // MODULES_H