-
-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathProfileManager.h
More file actions
185 lines (143 loc) · 9.64 KB
/
Copy pathProfileManager.h
File metadata and controls
185 lines (143 loc) · 9.64 KB
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
/*---------------------------------------------------------*\
| ProfileManager.h |
| |
| OpenRGB profile manager |
| |
| Adam Honse <calcprogrammer1@gmail.com> 09 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "filesystem.h"
/*---------------------------------------------------------*\
| Callback Types |
\*---------------------------------------------------------*/
typedef void (*ProfileManagerCallback)(void *, unsigned int);
/*---------------------------------------------------------*\
| ProfileManager Update Reason Codes |
\*---------------------------------------------------------*/
enum
{
PROFILEMANAGER_UPDATE_REASON_PROFILE_LIST_UPDATED, /* Profile list updated */
PROFILEMANAGER_UPDATE_REASON_ACTIVE_PROFILE_CHANGED, /* Active profile changed */
PROFILEMANAGER_UPDATE_REASON_PROFILE_ABOUT_TO_LOAD, /* Profile about to load */
};
class ProfileManagerInterface
{
public:
virtual void ClearActiveProfile() = 0;
virtual void DeleteProfile(std::string profile_name) = 0;
virtual std::string GetActiveProfile() = 0;
virtual std::vector<RGBController*> GetControllerListFromProfileJson(nlohmann::json profile_json) = 0;
virtual std::vector<RGBController*> GetControllerListFromProfileName(std::string profile_name) = 0;
virtual std::vector<RGBController*> GetControllerListFromSavedConfiguration() = 0;
virtual std::vector<std::string> GetProfileList() = 0;
virtual unsigned char * GetProfileListDescription() = 0;
virtual bool LoadControllerFromListWithOptions
(
std::vector<RGBController*>& temp_controllers,
RGBController* load_controller,
bool load_configuration,
bool load_state
) = 0;
virtual bool LoadControllerActiveProfile(RGBController* load_controller) = 0;
virtual bool LoadControllerConfiguration(RGBController* load_controller) = 0;
virtual bool LoadProfile(std::string profile_name) = 0;
virtual nlohmann::json ReadProfileJSON(std::string profile_name) = 0;
virtual bool SaveProfile(std::string profile_name) = 0;
virtual bool SaveProfileFromJSON(nlohmann::json profile_json) = 0;
virtual bool SaveConfiguration() = 0;
virtual void SetConfigurationDirectory(const filesystem::path& directory) = 0;
virtual void SetProfileListFromDescription(unsigned int data_size, char * data_buf) = 0;
virtual void UpdateProfileList() = 0;
protected:
virtual ~ProfileManagerInterface() {};
};
class ProfileManager: public ProfileManagerInterface
{
public:
ProfileManager(const filesystem::path& config_dir);
~ProfileManager();
void ClearActiveProfile();
void DeleteProfile(std::string profile_name);
std::string GetActiveProfile();
std::vector<RGBController*> GetControllerListFromProfileJson(nlohmann::json profile_json);
std::vector<RGBController*> GetControllerListFromProfileName(std::string profile_name);
std::vector<RGBController*> GetControllerListFromSavedConfiguration();
std::vector<std::string> GetProfileList();
unsigned char * GetProfileListDescription();
bool LoadAutoProfileExit();
bool LoadAutoProfileOpen();
bool LoadAutoProfileResume();
bool LoadAutoProfileSuspend();
bool LoadControllerFromListWithOptions
(
std::vector<RGBController*>& temp_controllers,
RGBController* load_controller,
bool load_configuration,
bool load_state
);
bool LoadControllerActiveProfile(RGBController* load_controller);
bool LoadControllerConfiguration(RGBController* load_controller);
bool LoadProfile(std::string profile_name);
void OnProfileAboutToLoad();
void OnProfileLoaded(std::string profile_json_string);
/*-----------------------------------------------------*\
| Callback Registration Functions |
\*-----------------------------------------------------*/
void RegisterProfileManagerCallback(ProfileManagerCallback new_callback, void * new_callback_arg);
void UnregisterProfileManagerCallback(ProfileManagerCallback callback, void * callback_arg);
nlohmann::json ReadProfileJSON(std::string profile_name);
bool SaveProfile(std::string profile_name);
bool SaveProfileCustom(std::string profile_name, std::vector<RGBController*> controllers, RGBColor base_color, bool base_color_enabled, std::vector<std::string> enabled_plugins);
bool SaveProfileFromJSON(nlohmann::json profile_json);
bool SaveConfiguration();
void SetActiveProfile(std::string profile_name);
void SetConfigurationDirectory(const filesystem::path& directory);
void SetProfileListFromDescription(unsigned int data_size, char * data_buf);
void SignalProfileManagerUpdate(unsigned int update_reason);
void UpdateProfileList();
private:
/*-----------------------------------------------------*\
| List of available profiles |
\*-----------------------------------------------------*/
std::vector<std::string> profile_list;
/*-----------------------------------------------------*\
| Active profile string |
\*-----------------------------------------------------*/
std::string active_profile;
/*-----------------------------------------------------*\
| Profile paths |
\*-----------------------------------------------------*/
filesystem::path configuration_directory;
filesystem::path profile_directory;
/*-----------------------------------------------------*\
| ProfileManager Callbacks |
\*-----------------------------------------------------*/
std::vector<ProfileManagerCallback> ProfileManagerCallbacks;
std::vector<void *> ProfileManagerCallbackArgs;
std::mutex ProfileManagerCallbackMutex;
/*-----------------------------------------------------*\
| Active profile data |
\*-----------------------------------------------------*/
bool active_base_color_enabled;
RGBColor active_base_color;
std::vector<RGBController*> active_rgb_controllers;
/*-----------------------------------------------------*\
| Manual controller configuration data |
\*-----------------------------------------------------*/
std::vector<RGBController*> manually_configured_rgb_controllers;
/*-----------------------------------------------------*\
| Private functions |
\*-----------------------------------------------------*/
bool LoadAutoProfile(std::string setting_name);
bool LoadProfileWithOptions
(
std::string profile_name,
bool load_configuration,
bool load_state
);
nlohmann::json ReadProfileFileJSON(filesystem::path profile_filepath);
};