diff --git a/OpenRGBPluginAPI.cpp b/OpenRGBPluginAPI.cpp index 263752ad5..3be1ce8c1 100644 --- a/OpenRGBPluginAPI.cpp +++ b/OpenRGBPluginAPI.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "OpenRGBPluginAPI.h" +#include "RGBController_Dummy.h" #include "RGBController_Virtual.h" OpenRGBPluginAPI::OpenRGBPluginAPI() @@ -185,6 +186,11 @@ bool OpenRGBPluginAPI::LoadProfile(std::string profile_name) return(profile_manager->LoadProfile(profile_name)); } +bool OpenRGBPluginAPI::SaveProfileFromPlugin(std::string profile_name, std::string plugin_name, nlohmann::json plugin_data) +{ + return(profile_manager->SaveProfileFromPlugin(profile_name, plugin_name, plugin_data)); +} + /*---------------------------------------------------------*\ | ResourceManager APIs | \*---------------------------------------------------------*/ @@ -223,6 +229,87 @@ std::vector OpenRGBPluginAPI::GetRGBControllers() return(resource_manager->GetRGBControllerInterfaces()); } +/*---------------------------------------------------------*\ +| RGBController APIs | +\*---------------------------------------------------------*/ +nlohmann::json OpenRGBPluginAPI::GetDeviceDescriptionJSON(RGBControllerInterface* controller) +{ + return(RGBController::GetDeviceDescriptionJSON((RGBController*)controller)); +} + +nlohmann::json OpenRGBPluginAPI::GetLEDDescriptionJSON(led led) +{ + return(RGBController::GetLEDDescriptionJSON(led)); +} + +nlohmann::json OpenRGBPluginAPI::GetMatrixMapDescriptionJSON(matrix_map_type matrix_map) +{ + return(RGBController::GetMatrixMapDescriptionJSON(matrix_map)); +} + +nlohmann::json OpenRGBPluginAPI::GetModeDescriptionJSON(mode mode) +{ + return(RGBController::GetModeDescriptionJSON(mode)); +} + +nlohmann::json OpenRGBPluginAPI::GetSegmentDescriptionJSON(segment segment) +{ + return(RGBController::GetSegmentDescriptionJSON(segment)); +} + +nlohmann::json OpenRGBPluginAPI::GetZoneDescriptionJSON(zone zone) +{ + return(RGBController::GetZoneDescriptionJSON(zone)); +} + +RGBControllerInterface* OpenRGBPluginAPI::SetDeviceDescriptionJSON(nlohmann::json controller_json) +{ + RGBController_Dummy* new_controller = new RGBController_Dummy(); + RGBController::SetDeviceDescriptionJSON(controller_json, (RGBController*)new_controller); + + return(new_controller); +} + +led OpenRGBPluginAPI::SetLEDDescriptionJSON(nlohmann::json led_json) +{ + return(RGBController::SetLEDDescriptionJSON(led_json)); +} + +matrix_map_type OpenRGBPluginAPI::SetMatrixMapDescriptionJSON(nlohmann::json matrix_map_json) +{ + return(RGBController::SetMatrixMapDescriptionJSON(matrix_map_json)); +} + +mode OpenRGBPluginAPI::SetModeDescriptionJSON(nlohmann::json mode_json) +{ + return(RGBController::SetModeDescriptionJSON(mode_json)); +} + +segment OpenRGBPluginAPI::SetSegmentDescriptionJSON(nlohmann::json segment_json) +{ + return(RGBController::SetSegmentDescriptionJSON(segment_json)); +} + +zone OpenRGBPluginAPI::SetZoneDescriptionJSON(nlohmann::json zone_json) +{ + return(RGBController::SetZoneDescriptionJSON(zone_json)); +} + +bool OpenRGBPluginAPI::CompareControllers(RGBControllerInterface* controller_1, RGBControllerInterface* controller_2) +{ + return(RGBController::CompareControllers((RGBController*)controller_1, (RGBController*)controller_2)); +} + +std::string OpenRGBPluginAPI::DeviceTypeToString(device_type type) +{ + return(RGBController::DeviceTypeToString(type)); +} + +bool OpenRGBPluginAPI::SetModeValuesFromMode(mode& destination, mode& source) +{ + return(RGBController::SetModeValuesFromMode(destination, source)); +} + /*---------------------------------------------------------*\ | SettingsManager APIs | \*---------------------------------------------------------*/ diff --git a/OpenRGBPluginAPI.h b/OpenRGBPluginAPI.h index 4ec2a86fb..066310795 100644 --- a/OpenRGBPluginAPI.h +++ b/OpenRGBPluginAPI.h @@ -45,6 +45,7 @@ public: void ClearActiveProfile(); std::vector GetProfileList(); bool LoadProfile(std::string profile_name); + bool SaveProfileFromPlugin(std::string profile_name, std::string plugin_name, nlohmann::json plugin_data); /*-----------------------------------------------------*\ | ResourceManager APIs | @@ -57,6 +58,27 @@ public: void WaitForDetection(); std::vector GetRGBControllers(); + /*-----------------------------------------------------*\ + | RGBController APIs | + \*-----------------------------------------------------*/ + nlohmann::json GetDeviceDescriptionJSON(RGBControllerInterface* controller); + nlohmann::json GetLEDDescriptionJSON(led led); + nlohmann::json GetMatrixMapDescriptionJSON(matrix_map_type matrix_map); + nlohmann::json GetModeDescriptionJSON(mode mode); + nlohmann::json GetSegmentDescriptionJSON(segment segment); + nlohmann::json GetZoneDescriptionJSON(zone zone); + + RGBControllerInterface* SetDeviceDescriptionJSON(nlohmann::json controller_json); + led SetLEDDescriptionJSON(nlohmann::json led_json); + matrix_map_type SetMatrixMapDescriptionJSON(nlohmann::json matrix_map_json); + mode SetModeDescriptionJSON(nlohmann::json mode_json); + segment SetSegmentDescriptionJSON(nlohmann::json segment_json); + zone SetZoneDescriptionJSON(nlohmann::json zone_json); + + bool CompareControllers(RGBControllerInterface* controller_1, RGBControllerInterface* controller_2); + std::string DeviceTypeToString(device_type type); + bool SetModeValuesFromMode(mode& destination, mode& source); + /*-----------------------------------------------------*\ | SettingsManager APIs | \*-----------------------------------------------------*/ diff --git a/OpenRGBPluginInterface.h b/OpenRGBPluginInterface.h index 6ea8492b3..de3c2cc04 100644 --- a/OpenRGBPluginInterface.h +++ b/OpenRGBPluginInterface.h @@ -77,43 +77,65 @@ public: /*-----------------------------------------------------*\ | LogManager APIs | \*-----------------------------------------------------*/ - virtual void LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...) = 0; + virtual void LogEntry(const char* filename, int line, unsigned int level, const char* fmt, ...) = 0; /*-----------------------------------------------------*\ | PluginManager APIs | \*-----------------------------------------------------*/ - virtual RGBControllerInterface* CreateVirtualRGBController(RGBController_Setup* setup) = 0; - virtual void DeleteVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; - virtual void RegisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; - virtual void RegisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0; - virtual void UnregisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; - virtual void UpdateVirtualRGBController(RGBControllerInterface* rgb_controller, RGBController_Setup* setup) = 0; - virtual void UnregisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0; + virtual RGBControllerInterface* CreateVirtualRGBController(RGBController_Setup* setup) = 0; + virtual void DeleteVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; + virtual void RegisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; + virtual void RegisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0; + virtual void UnregisterVirtualRGBController(RGBControllerInterface* rgb_controller) = 0; + virtual void UpdateVirtualRGBController(RGBControllerInterface* rgb_controller, RGBController_Setup* setup) = 0; + virtual void UnregisterVirtualRGBControllerInThread(RGBControllerInterface* rgb_controller) = 0; /*-----------------------------------------------------*\ | ProfileManager APIs | \*-----------------------------------------------------*/ - virtual void ClearActiveProfile() = 0; - virtual std::vector GetProfileList() = 0; - virtual bool LoadProfile(std::string profile_name) = 0; + virtual void ClearActiveProfile() = 0; + virtual std::vector GetProfileList() = 0; + virtual bool LoadProfile(std::string profile_name) = 0; + virtual bool SaveProfileFromPlugin(std::string profile_name, std::string plugin_name, nlohmann::json plugin_data) = 0; /*-----------------------------------------------------*\ | ResourceManager APIs | \*-----------------------------------------------------*/ - virtual filesystem::path GetConfigurationDirectory() = 0; - virtual bool GetDetectionEnabled() = 0; - virtual unsigned int GetDetectionPercent() = 0; - virtual std::string GetDetectionString() = 0; - virtual void RescanDevices() = 0; - virtual void WaitForDetection() = 0; - virtual std::vector GetRGBControllers() = 0; + virtual filesystem::path GetConfigurationDirectory() = 0; + virtual bool GetDetectionEnabled() = 0; + virtual unsigned int GetDetectionPercent() = 0; + virtual std::string GetDetectionString() = 0; + virtual void RescanDevices() = 0; + virtual void WaitForDetection() = 0; + virtual std::vector GetRGBControllers() = 0; + + /*-----------------------------------------------------*\ + | RGBController APIs | + \*-----------------------------------------------------*/ + virtual nlohmann::json GetDeviceDescriptionJSON(RGBControllerInterface* controller) = 0; + virtual nlohmann::json GetLEDDescriptionJSON(led led) = 0; + virtual nlohmann::json GetMatrixMapDescriptionJSON(matrix_map_type matrix_map) = 0; + virtual nlohmann::json GetModeDescriptionJSON(mode mode) = 0; + virtual nlohmann::json GetSegmentDescriptionJSON(segment segment) = 0; + virtual nlohmann::json GetZoneDescriptionJSON(zone zone) = 0; + + virtual RGBControllerInterface* SetDeviceDescriptionJSON(nlohmann::json controller_json) = 0; + virtual led SetLEDDescriptionJSON(nlohmann::json led_json) = 0; + virtual matrix_map_type SetMatrixMapDescriptionJSON(nlohmann::json matrix_map_json) = 0; + virtual mode SetModeDescriptionJSON(nlohmann::json mode_json) = 0; + virtual segment SetSegmentDescriptionJSON(nlohmann::json segment_json) = 0; + virtual zone SetZoneDescriptionJSON(nlohmann::json zone_json) = 0; + + virtual bool CompareControllers(RGBControllerInterface* controller_1, RGBControllerInterface* controller_2) = 0; + virtual std::string DeviceTypeToString(device_type type) = 0; + virtual bool SetModeValuesFromMode(mode& destination, mode& source) = 0; /*-----------------------------------------------------*\ | SettingsManager APIs | \*-----------------------------------------------------*/ - virtual nlohmann::json GetSettings(std::string settings_key) = 0; - virtual void SaveSettings() = 0; - virtual void SetSettings(std::string settings_key, nlohmann::json new_settings) = 0; + virtual nlohmann::json GetSettings(std::string settings_key) = 0; + virtual void SaveSettings() = 0; + virtual void SetSettings(std::string settings_key, nlohmann::json new_settings) = 0; }; class OpenRGBPluginInterface diff --git a/ProfileManager.cpp b/ProfileManager.cpp index b007b5b6d..c102bb74d 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -789,6 +789,45 @@ bool ProfileManager::SaveProfileFromJSON(nlohmann::json profile_json) } } +bool ProfileManager::SaveProfileFromPlugin(std::string profile_name, std::string plugin_name, nlohmann::json plugin_data) +{ + /*-----------------------------------------------------*\ + | If a name was entered, save the profile file | + \*-----------------------------------------------------*/ + if(profile_name != "") + { + /*-------------------------------------------------*\ + | Start filling in profile json data | + \*-------------------------------------------------*/ + nlohmann::json profile_json; + + profile_json["profile_version"] = OPENRGB_PROFILE_VERSION; + profile_json["profile_name"] = profile_name; + profile_json["plugins"][plugin_name] = plugin_data; + + if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI())) + { + /*---------------------------------------------*\ + | Upload the profile to the server | + \*---------------------------------------------*/ + ResourceManager::get()->GetLocalClient()->ProfileManager_UploadProfile(profile_json.dump()); + } + else + { + /*---------------------------------------------*\ + | Save the profile to file from the JSON | + \*---------------------------------------------*/ + SaveProfileFromJSON(profile_json); + } + + return(true); + } + else + { + return(false); + } +} + bool ProfileManager::SaveConfiguration() { /*-----------------------------------------------------*\ diff --git a/ProfileManager.h b/ProfileManager.h index c012cfbb2..b9e4b2c3d 100644 --- a/ProfileManager.h +++ b/ProfileManager.h @@ -125,6 +125,7 @@ public: bool SaveProfile(std::string profile_name); bool SaveProfileCustom(std::string profile_name, std::vector controllers, RGBColor base_color, bool base_color_enabled, std::vector enabled_plugins); bool SaveProfileFromJSON(nlohmann::json profile_json); + bool SaveProfileFromPlugin(std::string profile_name, std::string plugin_name, nlohmann::json plugin_data); bool SaveConfiguration(); void SetActiveProfile(std::string profile_name);