-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkzp_controller.h
188 lines (156 loc) · 6.43 KB
/
kzp_controller.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
188
#ifndef KZPCONTROLLER_H
#define KZPCONTROLLER_H
#include <QObject>
#include <QJsonObject>
#include "krakenz_driver.h"
#include <QIcon>
#include <QVector>
#include "modules.h"
#include "system_monitor.h"
#include <QTimer>
using namespace Modules;
class QApplication;
class QQuickItem;
class QQuickWindow;
class QQmlApplicationEngine;
class QQmlComponent;
class KrakenAppController;
class KrakenImageProvider;
class SystemTray;
enum class ApplicationState;
constexpr char APP_VERSION[] = "v1.2RC2";
struct AppSettings{
bool autoUpdate{false};
bool autoUpdateModules{false};
// main window
int windowX{0};
int windowY{0};
};
// KZPController takes the UX logic from main.qml and the backend logic from main.cpp and puts them into a class.
// The goal, this object is on the stack in main and controlls the logic on the main thread
// This should improve the maintainability and readability of the main control logic.
// In a single C++ class the application state drives the UX instead of the UX controlling the
// application state. This flips the anti-pattern paradigm of main.qml exploding with lots of qml state logic (great for prototyping)
// Goal of KZP is to be minimal at all times until requested to be more. This means the resting state is in the system tray (background).
// When the user requests to do more, the system tray can notify KZPController of profile changes and the such without needing a window.
// If the user wants to adjust the profile, the main window will be created and shown.
// when moving back to background mode, KZP will clean up to maintain a clean footprint.
#include "preview_window.h"
class KZPController : public QObject
{
Q_OBJECT
Q_PROPERTY(ApplicationState state READ state NOTIFY stateChanged MEMBER mState)
Q_PROPERTY(QString activeProfile READ activeProfile NOTIFY profileChanged MEMBER mActiveProfile)
Q_PROPERTY(QString version READ applicationVersion CONSTANT)
public:
enum ApplicationState{
STARTING = -1, // before settings is loaded
FIRST_TIME = 0, // settings didnt exist, exit is close
CONFIGURE_DRIVER = 1, // Made it to configuration close now is like accept and exit
BACKGROUND = 2, // If everything went well, we made it here, enable systray
FOREGROUND = 3, // Showing settings and preview (main window)
DETACHED = 4, // Showing preview detached on desktop
ERROR_PERMISSION = 5,
ERROR_DEVICE_NF = 6, // show option for software driver
ERROR_SETTINGS_NF = 7, // profile specified doesn't exist
ERROR_PROFILE_NF = 8, // profile specified doesn't exist
ERROR_PROFILES = 9, // profile specified doesn't exist
ERROR_PARSE_SETTINGS = 10 // check json in file
};
Q_ENUM(ApplicationState)
explicit KZPController(QApplication *parent);
~KZPController();
ApplicationState state() { return mState; }
Q_INVOKABLE void acceptUserAgreement();
Q_INVOKABLE void configured();
Q_INVOKABLE void selectSoftwareDriver();
const QString activeProfile() { return mActiveProfile; }
const QString applicationVersion() { return APP_VERSION; }
void setSettingsConfiguration(QString directory, QString profile_name, bool userDirectory);
Q_INVOKABLE void setPreviewWindow(QObject* window);
Q_INVOKABLE void loadManifest(QString manifest_file);
Q_INVOKABLE void loadManifest(QJsonObject manifest_obj);
static SystemMonitor* getSystemMonitor(); // Todo: return static global
signals:
void containerChanged(QQuickItem* container);
void errorOccurred(QString error_message);
// Settings UX Signals
void profileAdded(QString name);
void profileDataChanged(QString name, QJsonObject data);
void profileRemoved(QString name);
void profileChanged(QString profile);
void stateChanged(KZPController::ApplicationState state);
public slots:
// Settings Methods
// void addProfile(QString name);
// void applyStartupProfile();
// void selectProfile(QString name);
// void removeProfile(QString name);
// void writeSettingsOnExit(QJsonObject current_settings);
// Handle QApplication logic
void applicationInitialize();
void applicationQuiting();
void detachPreview(bool detach);
protected:
// Settings Members
QString mSettingsDir;
QString mRootDir;
QString mActiveProfile;
QJsonObject mError;
QJsonObject mProfile;
AppSettings mSettings;
bool mAppliedSettings;
void loadProfile();
void writeSettingsFile();
QQmlApplicationEngine* mUxEngine;
ApplicationState mState;
ApplicationState mStateBeforeLastError;
void setUxObjects();
// Backend Device Interface
KrakenZInterface* mController;
bool createDeviceController();
bool setSoftwareController();
// Background Application (Qml on Kraken Device)
KrakenAppController* mKrakenAppController;
bool createKrakenApplicationController();
// System Tray controller widget
QIcon mApplicationIcon;
SystemTray* mSystemTray;
void createSystemTray();
void cleanUp(); // clean it all up
// Preview Window
QQuickWindow* mPreviewWindow;
PreviewWindow mPreview;
// Module Manager downloads, and installs modules
ModuleManager mModuleManager;
void connectModuleManager();
SystemMonitor* mHWMonitor;
void initializeHWMonitor();
protected slots:
// When the UX is changed, this method will control what to do
// void componentReady();
void connectToWindow();
void cleanUpWindow();
void processBackgroundFrame(QImage frame);
void moveToBackground();
void setProfile(QString name);
bool initializeBackend();
bool initializeMainWindow();
void showMainWindow();
void setMainWindow();
void receivedInstalledManifests(QVector<QJsonObject>);
void receivedModuleManifests(QVector<ObjectReply>);
void releaseMainWindow();
// module slots
protected:
static SystemMonitor* mSystemMonitor; // TODO: finish connecting in
QString getSensorPath() {
#ifdef Q_OS_WIN
return SharedKeys::LHWMSensors;
#else
return SharedKeys::LMSensors;
#endif
return QString{};
}
};
#endif // KZPCONTROLLER_H