diff --git a/NetworkServer.cpp b/NetworkServer.cpp index ce982e554..78879a285 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -704,7 +704,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) memcpy(&new_size, data + sizeof(int), sizeof(int)); controllers[header.pkt_dev_idx]->ResizeZone(zone, new_size); - profile_manager->SaveProfile("sizes", true); + profile_manager->SaveSizes(); } break; @@ -909,11 +909,6 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) profile_manager->LoadProfile(profile_name); } - for(RGBController* controller : controllers) - { - controller->UpdateLEDs(); - } - break; case NET_PACKET_ID_REQUEST_DELETE_PROFILE: @@ -964,7 +959,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) memcpy(&zone, data, sizeof(int)); controllers[header.pkt_dev_idx]->ClearSegments(zone); - profile_manager->SaveProfile("sizes", true); + profile_manager->SaveSizes(); } break; @@ -979,7 +974,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) if(header.pkt_dev_idx < controllers.size()) { controllers[header.pkt_dev_idx]->SetSegmentDescription((unsigned char *)data); - profile_manager->SaveProfile("sizes", true); + profile_manager->SaveSizes(); } } } diff --git a/OpenRGBPluginInterface.h b/OpenRGBPluginInterface.h index 44b9d4c3f..a32084ac7 100644 --- a/OpenRGBPluginInterface.h +++ b/OpenRGBPluginInterface.h @@ -15,6 +15,7 @@ #include #include #include +#include "nlohmann/json.hpp" #include "ResourceManagerInterface.h" #define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface" @@ -87,6 +88,9 @@ public: virtual QWidget* GetWidget() = 0; virtual QMenu* GetTrayMenu() = 0; virtual void Unload() = 0; + virtual void OnProfileAboutToLoad() = 0; + virtual void OnProfileLoad(nlohmann::json profile_data) = 0; + virtual nlohmann::json OnProfileSave() = 0; virtual unsigned char* OnSDKCommand(unsigned int pkt_id, unsigned char * pkt_data, unsigned int *pkt_size) = 0; }; diff --git a/PluginManager.cpp b/PluginManager.cpp index a758740cc..950085c29 100644 --- a/PluginManager.cpp +++ b/PluginManager.cpp @@ -533,6 +533,58 @@ void PluginManager::UnloadPlugins() } } +void PluginManager::OnProfileAboutToLoad() +{ + /*-----------------------------------------------------*\ + | Loop through all plugins and signal profile about to | + | load | + \*-----------------------------------------------------*/ + for(std::size_t plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) + { + if(ActivePlugins[plugin_idx].enabled && ActivePlugins[plugin_idx].loader->isLoaded()) + { + ActivePlugins[plugin_idx].plugin->OnProfileAboutToLoad(); + } + } +} + +void PluginManager::OnProfileLoad(nlohmann::json profile_data) +{ + /*-----------------------------------------------------*\ + | Loop through all plugins call their OnProfileLoad if | + | the profile data contains an entry for that plugin | + \*-----------------------------------------------------*/ + for(std::size_t plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) + { + if(ActivePlugins[plugin_idx].enabled && ActivePlugins[plugin_idx].loader->isLoaded()) + { + if(profile_data.contains(ActivePlugins[plugin_idx].plugin->GetPluginInfo().Name)) + { + ActivePlugins[plugin_idx].plugin->OnProfileLoad(profile_data[ActivePlugins[plugin_idx].plugin->GetPluginInfo().Name]); + } + } + } +} + +nlohmann::json PluginManager::OnProfileSave() +{ + nlohmann::json plugin_json; + + /*-----------------------------------------------------*\ + | Loop through all plugins and gather their profile | + | data | + \*-----------------------------------------------------*/ + for(std::size_t plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) + { + if(ActivePlugins[plugin_idx].enabled && ActivePlugins[plugin_idx].loader->isLoaded()) + { + plugin_json[ActivePlugins[plugin_idx].plugin->GetPluginInfo().Name] = ActivePlugins[plugin_idx].plugin->OnProfileSave(); + } + } + + return(plugin_json); +} + unsigned char * PluginManager::OnSDKCommand(unsigned int plugin_idx, unsigned int pkt_id, unsigned char * pkt_data, unsigned int * pkt_size) { unsigned char * out_data = NULL; diff --git a/PluginManager.h b/PluginManager.h index 6fdd177ad..081938637 100644 --- a/PluginManager.h +++ b/PluginManager.h @@ -60,6 +60,9 @@ public: void LoadPlugins(); void UnloadPlugins(); + void OnProfileAboutToLoad(); + void OnProfileLoad(nlohmann::json profile_data); + nlohmann::json OnProfileSave(); unsigned char * OnSDKCommand(unsigned int plugin_idx, unsigned int pkt_id, unsigned char * pkt_data, unsigned int * pkt_size); std::vector ActivePlugins; diff --git a/PluginManagerInterface.h b/PluginManagerInterface.h index 1ec748877..f61858cb5 100644 --- a/PluginManagerInterface.h +++ b/PluginManagerInterface.h @@ -12,6 +12,7 @@ #pragma once #include +#include "nlohmann/json.hpp" class PluginManagerInterface { @@ -25,5 +26,8 @@ public: virtual void LoadPlugins() = 0; virtual void UnloadPlugins() = 0; + virtual void OnProfileAboutToLoad() = 0; + virtual void OnProfileLoad(nlohmann::json profile_data) = 0; + virtual nlohmann::json OnProfileSave() = 0; virtual unsigned char * OnSDKCommand(unsigned int plugin_idx, unsigned int pkt_id, unsigned char * pkt_data, unsigned int * pkt_size) = 0; }; diff --git a/ProfileManager.cpp b/ProfileManager.cpp index bc556e948..6144051ed 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -3,6 +3,8 @@ | | | OpenRGB profile manager | | | +| Adam Honse 09 Nov 2025 | +| | | This file is part of the OpenRGB project | | SPDX-License-Identifier: GPL-2.0-or-later | \*---------------------------------------------------------*/ @@ -10,12 +12,15 @@ #include #include #include +#include "filesystem.h" +#include "LogManager.h" +#include "NetworkClient.h" +#include "NetworkProtocol.h" +#include "PluginManagerInterface.h" #include "ProfileManager.h" #include "ResourceManager.h" #include "RGBController_Dummy.h" -#include "LogManager.h" -#include "NetworkProtocol.h" -#include "filesystem.h" +#include "SettingsManager.h" #include "StringUtils.h" #define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE" @@ -23,8 +28,66 @@ ProfileManager::ProfileManager(const filesystem::path& config_dir) { - configuration_directory = config_dir; + /*-----------------------------------------------------*\ + | Initialize configuration directory and update profile | + | list | + \*-----------------------------------------------------*/ + SetConfigurationDirectory(config_dir); UpdateProfileList(); + + /*-----------------------------------------------------*\ + | Read in profile manager settings and initialize any | + | missing settings to defaults | + \*-----------------------------------------------------*/ + SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager(); + json profilemanager_settings = settings_manager->GetSettings("ProfileManager"); + bool new_settings_keys = false; + + if(!profilemanager_settings.contains("open_profile")) + { + json profile;; + profile["enabled"] = false; + profile["name"] = ""; + profilemanager_settings["open_profile"] = profile; + new_settings_keys = true; + } + + if(!profilemanager_settings.contains("exit_profile")) + { + json profile; + profile["enabled"] = false; + profile["name"] = ""; + profilemanager_settings["exit_profile"] = profile; + new_settings_keys = true; + } + + if(!profilemanager_settings.contains("resume_profile")) + { + json profile; + profile["enabled"] = false; + profile["name"] = ""; + profilemanager_settings["resume_profile"] = profile; + new_settings_keys = true; + } + + if(!profilemanager_settings.contains("suspend_profile")) + { + json profile; + profile["enabled"] = false; + profile["name"] = ""; + profilemanager_settings["suspend_profile"] = profile; + new_settings_keys = true; + } + + /*-----------------------------------------------------*\ + | Save the settings if new default values have been | + | inserted | + \*-----------------------------------------------------*/ + if(new_settings_keys) + { + settings_manager->SetSettings("ProfileManager", profilemanager_settings); + settings_manager->SaveSettings(); + } } ProfileManager::~ProfileManager() @@ -32,85 +95,218 @@ ProfileManager::~ProfileManager() } -bool ProfileManager::SaveProfile(std::string profile_name, bool sizes) +void ProfileManager::DeleteProfile(std::string profile_name) { profile_name = StringUtils::remove_null_terminating_chars(profile_name); - /*---------------------------------------------------------*\ - | Get the list of controllers from the resource manager | - \*---------------------------------------------------------*/ - std::vector controllers = ResourceManager::get()->GetRGBControllers(); + filesystem::path filename = profile_directory / profile_name; + filename.concat(".json"); - /*---------------------------------------------------------*\ - | If a name was entered, save the profile file | - \*---------------------------------------------------------*/ + filesystem::remove(filename); + + UpdateProfileList(); +} + +std::string ProfileManager::GetActiveProfile() +{ + return(active_profile); +} + +std::vector ProfileManager::GetControllerListFromProfile(nlohmann::json profile_json) +{ + std::vector temp_controllers; + + /*-----------------------------------------------------*\ + | Read list of controllers from profile | + \*-----------------------------------------------------*/ + if(profile_json.contains("controllers")) + { + for(std::size_t controller_idx = 0; controller_idx < profile_json["controllers"].size(); controller_idx++) + { + RGBController_Dummy * temp_controller = new RGBController_Dummy(); + + temp_controller->SetDeviceDescriptionJSON(profile_json["controllers"][controller_idx]); + + temp_controllers.push_back(temp_controller); + } + } + + return(temp_controllers); +} + +std::vector ProfileManager::GetControllerListFromSizes() +{ + /*-----------------------------------------------------*\ + | Read the sizes JSON from the file | + \*-----------------------------------------------------*/ + filesystem::path filename = configuration_directory / "Sizes.json"; + nlohmann::json sizes_json = ReadProfileFileJSON(filename); + + return(GetControllerListFromProfile(sizes_json)); +} + +std::vector ProfileManager::GetProfileList() +{ + return(profile_list); +} + +unsigned char * ProfileManager::GetProfileListDescription() +{ + unsigned int data_ptr = 0; + unsigned int data_size = 0; + + /*-----------------------------------------------------*\ + | Calculate data size | + \*-----------------------------------------------------*/ + unsigned short num_profiles = (unsigned short)profile_list.size(); + + data_size += sizeof(data_size); + data_size += sizeof(num_profiles); + + for(unsigned int i = 0; i < num_profiles; i++) + { + data_size += sizeof (unsigned short); + data_size += (unsigned int)strlen(profile_list[i].c_str()) + 1; + } + + /*-----------------------------------------------------*\ + | Create data buffer | + \*-----------------------------------------------------*/ + unsigned char *data_buf = new unsigned char[data_size]; + + /*-----------------------------------------------------*\ + | Copy in data size | + \*-----------------------------------------------------*/ + memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size)); + data_ptr += sizeof(data_size); + + /*-----------------------------------------------------*\ + | Copy in num_profiles | + \*-----------------------------------------------------*/ + memcpy(&data_buf[data_ptr], &num_profiles, sizeof(num_profiles)); + data_ptr += sizeof(num_profiles); + + /*-----------------------------------------------------*\ + | Copy in profile names (size+data) | + \*-----------------------------------------------------*/ + for(unsigned int i = 0; i < num_profiles; i++) + { + unsigned short name_len = (unsigned short)strlen(profile_list[i].c_str()) + 1; + + memcpy(&data_buf[data_ptr], &name_len, sizeof(name_len)); + data_ptr += sizeof(name_len); + + strcpy((char *)&data_buf[data_ptr], profile_list[i].c_str()); + data_ptr += name_len; + } + + return(data_buf); +} + +bool ProfileManager::LoadAutoProfileExit() +{ + return(LoadAutoProfile("exit_profile")); +} + +bool ProfileManager::LoadAutoProfileOpen() +{ + return(LoadAutoProfile("open_profile")); +} + +bool ProfileManager::LoadAutoProfileResume() +{ + return(LoadAutoProfile("resume_profile")); +} + +bool ProfileManager::LoadAutoProfileSuspend() +{ + return(LoadAutoProfile("suspend_profile")); +} + +bool ProfileManager::LoadProfile(std::string profile_name) +{ + return(LoadProfileWithOptions(profile_name, false, true)); +} + +nlohmann::json ProfileManager::ReadProfileJSON(std::string profile_name) +{ + /*-----------------------------------------------------*\ + | Clean up the profile name | + \*-----------------------------------------------------*/ + profile_name = StringUtils::remove_null_terminating_chars(profile_name); + + /*-----------------------------------------------------*\ + | File extension for v6+ profiles is .json | + \*-----------------------------------------------------*/ + profile_name += ".json"; + + /*-----------------------------------------------------*\ + | Read the profile JSON from the file | + \*-----------------------------------------------------*/ + filesystem::path profile_path = profile_directory / filesystem::u8path(profile_name); + + nlohmann::json profile_json = ReadProfileFileJSON(profile_path); + + return(profile_json); +} + +bool ProfileManager::SaveProfile(std::string profile_name) +{ + /*-----------------------------------------------------*\ + | Clean up the profile name | + \*-----------------------------------------------------*/ + profile_name = StringUtils::remove_null_terminating_chars(profile_name); + + /*-----------------------------------------------------*\ + | If a name was entered, save the profile file | + \*-----------------------------------------------------*/ if(profile_name != "") { - /*---------------------------------------------------------*\ - | Extension .orp - OpenRgb Profile | - \*---------------------------------------------------------*/ - std::string filename = profile_name; + /*-------------------------------------------------*\ + | Get the list of controllers from the resource | + | manager | + \*-------------------------------------------------*/ + std::vector controllers = ResourceManager::get()->GetRGBControllers(); - /*---------------------------------------------------------*\ - | Determine file extension | - \*---------------------------------------------------------*/ - if(sizes) - { - filename += ".ors"; - } - else - { - filename += ".orp"; - } + /*-------------------------------------------------*\ + | Start filling in profile json data | + \*-------------------------------------------------*/ + nlohmann::json profile_json; - /*---------------------------------------------------------*\ - | Open an output file in binary mode | - \*---------------------------------------------------------*/ - filesystem::path profile_path = configuration_directory / filesystem::u8path(filename); - std::ofstream controller_file(profile_path, std::ios::out | std::ios::binary | std::ios::trunc); + profile_json["profile_version"] = OPENRGB_PROFILE_VERSION; + profile_json["profile_name"] = profile_name; - /*---------------------------------------------------------*\ - | Write header | - | 16 bytes - "OPENRGB_PROFILE" | - | 4 bytes - Version, unsigned int | - \*---------------------------------------------------------*/ - unsigned int profile_version = OPENRGB_PROFILE_VERSION; - controller_file.write(OPENRGB_PROFILE_HEADER, 16); - controller_file.write((char *)&profile_version, sizeof(unsigned int)); - - /*---------------------------------------------------------*\ - | Write controller data for each controller | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Write controller data for each controller | + \*-------------------------------------------------*/ for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++) { - /*-----------------------------------------------------*\ - | Ignore remote and virtual controllers when saving | - | sizes | - \*-----------------------------------------------------*/ - if(sizes && (controllers[controller_index]->GetFlags() & CONTROLLER_FLAG_REMOTE - || controllers[controller_index]->GetFlags() & CONTROLLER_FLAG_VIRTUAL)) - { - break; - } - - unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription(profile_version); - unsigned int controller_size; - - memcpy(&controller_size, controller_data, sizeof(controller_size)); - - controller_file.write((const char *)controller_data, controller_size); - - delete[] controller_data; + /*---------------------------------------------*\ + | Read the controller data for this controller | + | into the profile json | + \*---------------------------------------------*/ + profile_json["controllers"][controller_index] = controllers[controller_index]->GetDeviceDescriptionJSON(); } - /*---------------------------------------------------------*\ - | Close the file when done | - \*---------------------------------------------------------*/ - controller_file.close(); + /*-------------------------------------------------*\ + | Get plugin profile data if the plugin manager is | + | available | + \*-------------------------------------------------*/ + PluginManagerInterface* plugin_manager = ResourceManager::get()->GetPluginManager(); - /*---------------------------------------------------------*\ - | Update the profile list | - \*---------------------------------------------------------*/ + if(plugin_manager != NULL) + { + profile_json["plugins"] = plugin_manager->OnProfileSave(); + } + + /*-------------------------------------------------*\ + | Save the profile to file from the JSON | + \*-------------------------------------------------*/ + SaveProfileFromJSON(profile_json); + + /*-------------------------------------------------*\ + | Update the profile list | + \*-------------------------------------------------*/ UpdateProfileList(); return(true); @@ -121,113 +317,198 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes) } } -void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory) +bool ProfileManager::SaveProfileFromJSON(nlohmann::json profile_json) { - configuration_directory = directory; - UpdateProfileList(); -} - -bool ProfileManager::LoadProfile(std::string profile_name) -{ - profile_name = StringUtils::remove_null_terminating_chars(profile_name); - return(LoadProfileWithOptions(profile_name, false, true)); -} - -bool ProfileManager::LoadSizeFromProfile(std::string profile_name) -{ - profile_name = StringUtils::remove_null_terminating_chars(profile_name); - return(LoadProfileWithOptions(profile_name, true, false)); -} - -std::vector ProfileManager::LoadProfileToList - ( - std::string profile_name, - bool sizes - ) -{ - std::vector temp_controllers; - unsigned int controller_size; - unsigned int controller_offset = 0; - - filesystem::path filename = configuration_directory / filesystem::u8path(profile_name); - - /*---------------------------------------------------------*\ - | Determine file extension | - \*---------------------------------------------------------*/ - if(sizes) + if(profile_json.contains("profile_name")) { - filename.concat(".ors"); + std::string profile_filename = profile_json["profile_name"]; + + profile_filename.append(".json"); + + /*-------------------------------------------------*\ + | Open an output file in the profile directory | + \*-------------------------------------------------*/ + filesystem::path profile_path = profile_directory / profile_filename; + std::ofstream profile_file(profile_path, std::ios::out ); + + /*-------------------------------------------------*\ + | Write the JSON data to the file | + \*-------------------------------------------------*/ + profile_file << std::setw(4) << profile_json << std::endl; + + /*-------------------------------------------------*\ + | Close the file when done | + \*-------------------------------------------------*/ + profile_file.close(); + + return(true); } else { - if(filename.extension() != ".orp") + return(false); + } +} + +bool ProfileManager::SaveSizes() +{ + /*-----------------------------------------------------*\ + | Get the list of controllers from the resource manager | + \*-----------------------------------------------------*/ + std::vector controllers = ResourceManager::get()->GetRGBControllers(); + + /*-----------------------------------------------------*\ + | Open an output file in the profile directory | + \*-----------------------------------------------------*/ + filesystem::path profile_path = configuration_directory / "Sizes.json"; + std::ofstream controller_file(profile_path, std::ios::out ); + + /*-----------------------------------------------------*\ + | Start filling in profile json data | + \*-----------------------------------------------------*/ + nlohmann::json profile_json; + + profile_json["profile_version"] = OPENRGB_PROFILE_VERSION; + profile_json["profile_name"] = "Sizes"; + + /*-----------------------------------------------------*\ + | Write controller data for each controller | + \*-----------------------------------------------------*/ + for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++) + { + /*-------------------------------------------------*\ + | Ignore remote and virtual controllers when saving | + | sizes | + \*-------------------------------------------------*/ + if(controllers[controller_index]->GetFlags() & CONTROLLER_FLAG_REMOTE + || controllers[controller_index]->GetFlags() & CONTROLLER_FLAG_VIRTUAL) { - filename.concat(".orp"); + break; } + + /*-------------------------------------------------*\ + | Read the controller data for this controller into | + | the profile json | + \*-------------------------------------------------*/ + profile_json["controllers"][controller_index] = controllers[controller_index]->GetDeviceDescriptionJSON(); } - /*---------------------------------------------------------*\ - | Open input file in binary mode | - \*---------------------------------------------------------*/ - std::ifstream controller_file(filename, std::ios::in | std::ios::binary); + controller_file << std::setw(4) << profile_json << std::endl; - /*---------------------------------------------------------*\ - | Read and verify file header | - \*---------------------------------------------------------*/ - char profile_string[16] = ""; - unsigned int profile_version = 0; + /*-----------------------------------------------------*\ + | Close the file when done | + \*-----------------------------------------------------*/ + controller_file.close(); - controller_file.read(profile_string, 16); - controller_file.read((char *)&profile_version, sizeof(unsigned int)); + return(true); +} - /*---------------------------------------------------------*\ - | Profile version started at 1 and protocol version started | - | at 0. Version 1 profiles should use protocol 0, but 2 or | - | greater should be synchronized | - \*---------------------------------------------------------*/ - if(profile_version == 1) +void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory) +{ + configuration_directory = directory; + profile_directory = configuration_directory / filesystem::u8path("profiles"); + + filesystem::create_directories(profile_directory); + + UpdateProfileList(); +} + +void ProfileManager::SetProfileListFromDescription(char * data_buf) +{ + unsigned int data_ptr = sizeof(unsigned int); + unsigned short num_profiles = 0; + + /*-----------------------------------------------------*\ + | Clear the profile list | + \*-----------------------------------------------------*/ + profile_list.clear(); + + /*-----------------------------------------------------*\ + | Copy in num_profiles | + \*-----------------------------------------------------*/ + memcpy(&num_profiles, &data_buf[data_ptr], sizeof(num_profiles)); + data_ptr += sizeof(num_profiles); + + /*-----------------------------------------------------*\ + | Copy in profile names (size+data) | + \*-----------------------------------------------------*/ + for(unsigned int i = 0; i < num_profiles; i++) { - profile_version = 0; + unsigned short name_len = 0; + + memcpy(&name_len, &data_buf[data_ptr], sizeof(name_len)); + data_ptr += sizeof(name_len); + + profile_list.push_back((char *)&data_buf[data_ptr]); + data_ptr += name_len; } +} - controller_offset += 16 + sizeof(unsigned int); - controller_file.seekg(controller_offset); +void ProfileManager::UpdateProfileList() +{ + profile_list.clear(); - if(strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0) + /*-----------------------------------------------------*\ + | Load profiles by looking for .json files in profile | + | directory | + \*-----------------------------------------------------*/ + for(const filesystem::directory_entry &entry : filesystem::directory_iterator(profile_directory)) { - if(profile_version <= OPENRGB_PROFILE_VERSION) + std::string filename = entry.path().filename().string(); + + if(filename.find(".json") != std::string::npos) { - /*---------------------------------------------------------*\ - | Read controller data from file until EOF | - \*---------------------------------------------------------*/ - while(!(controller_file.peek() == EOF)) + LOG_INFO("[ProfileManager] Found file: %s attempting to validate header", filename.c_str()); + + /*---------------------------------------------*\ + | Open input file in binary mode | + \*---------------------------------------------*/ + filesystem::path file_path = profile_directory; + file_path.append(filename); + + nlohmann::json profile_json = ReadProfileFileJSON(file_path); + + if(!profile_json.empty()) { - controller_file.read((char *)&controller_size, sizeof(controller_size)); - - unsigned char *controller_data = new unsigned char[controller_size]; - - controller_file.seekg(controller_offset); - - controller_file.read((char *)controller_data, controller_size); - - RGBController_Dummy *temp_controller = new RGBController_Dummy(); - - temp_controller->ReadDeviceDescription(controller_data, profile_version); - - temp_controllers.push_back(temp_controller); - - delete[] controller_data; - - controller_offset += controller_size; - controller_file.seekg(controller_offset); + profile_list.push_back(filename.erase(filename.length() - 5)); } } } - - return(temp_controllers); } -bool ProfileManager::LoadDeviceFromListWithOptions +/*---------------------------------------------------------*\ +| Private functions | +\*---------------------------------------------------------*/ +bool ProfileManager::LoadAutoProfile(std::string setting_name) +{ + /*-----------------------------------------------------*\ + | Read in profile manager settings and check for the | + | given setting name | + \*-----------------------------------------------------*/ + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + std::string profile_name; + + if(profilemanager_settings.contains(setting_name)) + { + if(profilemanager_settings[setting_name].contains("name") && profilemanager_settings[setting_name].contains("enabled") && profilemanager_settings[setting_name]["enabled"] == true) + { + profile_name = profilemanager_settings[setting_name]["name"]; + } + } + + /*-----------------------------------------------------*\ + | Load the profile if it is valid | + \*-----------------------------------------------------*/ + if(!profile_name.empty()) + { + return(LoadProfile(profile_name)); + } + else + { + return(false); + } +} + +bool ProfileManager::LoadControllerFromListWithOptions ( std::vector& temp_controllers, std::vector& temp_controller_used, @@ -271,9 +552,10 @@ bool ProfileManager::LoadDeviceFromListWithOptions location_check = temp_controller->GetLocation() == load_controller->GetLocation(); } - /*---------------------------------------------------------*\ - | Test if saved controller data matches this controller | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Test if saved controller data matches this | + | controller | + \*-------------------------------------------------*/ if((temp_controller_used[temp_index] == false ) &&(temp_controller->GetDeviceType() == load_controller->GetDeviceType() ) &&(temp_controller->GetName() == load_controller->GetName() ) @@ -282,14 +564,14 @@ bool ProfileManager::LoadDeviceFromListWithOptions &&(temp_controller->GetSerial() == load_controller->GetSerial() ) &&(location_check == true )) { - /*---------------------------------------------------------*\ - | Set used flag for this temp device | - \*---------------------------------------------------------*/ + /*---------------------------------------------*\ + | Set used flag for this temp device | + \*---------------------------------------------*/ temp_controller_used[temp_index] = true; - /*---------------------------------------------------------*\ - | Update zone sizes if requested | - \*---------------------------------------------------------*/ + /*---------------------------------------------*\ + | Update zone sizes if requested | + \*---------------------------------------------*/ if(load_size) { if(temp_controller->zones.size() == load_controller->zones.size()) @@ -320,14 +602,14 @@ bool ProfileManager::LoadDeviceFromListWithOptions } } - /*---------------------------------------------------------*\ - | Update settings if requested | - \*---------------------------------------------------------*/ + /*---------------------------------------------*\ + | Update settings if requested | + \*---------------------------------------------*/ if(load_settings) { - /*---------------------------------------------------------*\ - | Update all modes | - \*---------------------------------------------------------*/ + /*-----------------------------------------*\ + | If mode list matches, load all modes | + \*-----------------------------------------*/ if(temp_controller->modes.size() == load_controller->modes.size()) { for(std::size_t mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++) @@ -337,8 +619,8 @@ bool ProfileManager::LoadDeviceFromListWithOptions &&(temp_controller->GetModeFlags(mode_index) == load_controller->GetModeFlags(mode_index) ) &&(temp_controller->GetModeSpeedMin(mode_index) == load_controller->GetModeSpeedMin(mode_index) ) &&(temp_controller->GetModeSpeedMax(mode_index) == load_controller->GetModeSpeedMax(mode_index) ) - //&&(temp_controller->GetModeBrightnessMin(mode_index) == load_controller->GetModeBrightnessMin(mode_index)) - //&&(temp_controller->GetModeBrightnessMax(mode_index) == load_controller->GetModeBrightnessMax(mode_index)) + &&(temp_controller->GetModeBrightnessMin(mode_index) == load_controller->GetModeBrightnessMin(mode_index)) + &&(temp_controller->GetModeBrightnessMax(mode_index) == load_controller->GetModeBrightnessMax(mode_index)) &&(temp_controller->GetModeColorsMin(mode_index) == load_controller->GetModeColorsMin(mode_index) ) &&(temp_controller->GetModeColorsMax(mode_index) == load_controller->GetModeColorsMax(mode_index) )) { @@ -354,21 +636,69 @@ bool ProfileManager::LoadDeviceFromListWithOptions load_controller->modes[mode_index].colors[mode_color_index] = temp_controller->modes[mode_index].colors[mode_color_index]; } } - } load_controller->active_mode = temp_controller->active_mode; + load_controller->UpdateMode(); } - /*---------------------------------------------------------*\ - | Update all colors | - \*---------------------------------------------------------*/ + /*-----------------------------------------*\ + | If color list matches, load all colors | + \*-----------------------------------------*/ if(temp_controller->colors.size() == load_controller->colors.size()) { for(std::size_t color_index = 0; color_index < temp_controller->colors.size(); color_index++) { load_controller->colors[color_index] = temp_controller->colors[color_index]; } + + load_controller->UpdateLEDs(); + } + + /*-----------------------------------------*\ + | If zone mode list matches, load all zone | + | modes | + \*-----------------------------------------*/ + if(temp_controller->GetZoneCount() == load_controller->GetZoneCount()) + { + for(std::size_t zone_idx = 0; zone_idx < temp_controller->GetZoneCount(); zone_idx++) + { + if((temp_controller->GetZoneName(zone_idx) == load_controller->GetZoneName(zone_idx) ) + &&(temp_controller->GetZoneType(zone_idx) == load_controller->GetZoneType(zone_idx) ) + &&(temp_controller->GetZoneLEDsMin(zone_idx) == load_controller->GetZoneLEDsMin(zone_idx) ) + &&(temp_controller->GetZoneLEDsMax(zone_idx) == load_controller->GetZoneLEDsMax(zone_idx) ) + &&(temp_controller->GetZoneModeCount(zone_idx) == load_controller->GetZoneModeCount(zone_idx))) + { + for(std::size_t mode_index = 0; mode_index < temp_controller->GetZoneModeCount(zone_idx); mode_index++) + { + if((temp_controller->GetZoneModeName(zone_idx, mode_index) == load_controller->GetZoneModeName(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeValue(zone_idx, mode_index) == load_controller->GetZoneModeValue(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeFlags(zone_idx, mode_index) == load_controller->GetZoneModeFlags(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeSpeedMin(zone_idx, mode_index) == load_controller->GetZoneModeSpeedMin(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeSpeedMax(zone_idx, mode_index) == load_controller->GetZoneModeSpeedMax(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeBrightnessMin(zone_idx, mode_index) == load_controller->GetZoneModeBrightnessMin(zone_idx, mode_index)) + &&(temp_controller->GetZoneModeBrightnessMax(zone_idx, mode_index) == load_controller->GetZoneModeBrightnessMax(zone_idx, mode_index)) + &&(temp_controller->GetZoneModeColorsMin(zone_idx, mode_index) == load_controller->GetZoneModeColorsMin(zone_idx, mode_index) ) + &&(temp_controller->GetZoneModeColorsMax(zone_idx, mode_index) == load_controller->GetZoneModeColorsMax(zone_idx, mode_index) )) + { + load_controller->zones[zone_idx].modes[mode_index].speed = temp_controller->zones[zone_idx].modes[mode_index].speed; + load_controller->zones[zone_idx].modes[mode_index].brightness = temp_controller->zones[zone_idx].modes[mode_index].brightness; + load_controller->zones[zone_idx].modes[mode_index].direction = temp_controller->zones[zone_idx].modes[mode_index].direction; + load_controller->zones[zone_idx].modes[mode_index].color_mode = temp_controller->zones[zone_idx].modes[mode_index].color_mode; + + load_controller->zones[zone_idx].modes[mode_index].colors.resize(temp_controller->zones[zone_idx].modes[mode_index].colors.size()); + + for(std::size_t mode_color_index = 0; mode_color_index < temp_controller->GetZoneModeColorsCount(zone_idx, mode_index); mode_color_index++) + { + load_controller->zones[zone_idx].modes[mode_index].colors[mode_color_index] = temp_controller->zones[zone_idx].modes[mode_index].colors[mode_color_index]; + } + } + } + + load_controller->SetZoneActiveMode(zone_idx, temp_controller->GetZoneActiveMode(zone_idx)); + load_controller->UpdateZoneMode(zone_idx); + } + } } } @@ -390,19 +720,32 @@ bool ProfileManager::LoadProfileWithOptions std::vector temp_controller_used; bool ret_val = false; - /*---------------------------------------------------------*\ - | Get the list of controllers from the resource manager | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Get the list of controllers from the resource | + | manager | + \*-------------------------------------------------*/ std::vector controllers = ResourceManager::get()->GetRGBControllers(); - /*---------------------------------------------------------*\ - | Open input file in binary mode | - \*---------------------------------------------------------*/ - temp_controllers = LoadProfileToList(profile_name); + nlohmann::json profile_json = ReadProfileJSON(profile_name); - /*---------------------------------------------------------*\ - | Set up used flag vector | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Open input file in binary mode | + \*-------------------------------------------------*/ + temp_controllers = GetControllerListFromProfile(profile_json); + + /*-------------------------------------------------*\ + | Signal to plugins that a profile is about to load | + \*-------------------------------------------------*/ + PluginManagerInterface* plugin_manager = ResourceManager::get()->GetPluginManager(); + + if(plugin_manager != NULL) + { + plugin_manager->OnProfileAboutToLoad(); + } + + /*-------------------------------------------------*\ + | Set up used flag vector | + \*-------------------------------------------------*/ temp_controller_used.resize(temp_controllers.size()); for(unsigned int controller_idx = 0; controller_idx < temp_controller_used.size(); controller_idx++) @@ -410,148 +753,68 @@ bool ProfileManager::LoadProfileWithOptions temp_controller_used[controller_idx] = false; } - /*---------------------------------------------------------*\ - | Loop through all controllers. For each controller, search| - | all saved controllers until a match is found | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Loop through all controllers. For each | + | controller, search all saved controllers until a | + | match is found | + \*-------------------------------------------------*/ for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++) { - bool temp_ret_val = LoadDeviceFromListWithOptions(temp_controllers, temp_controller_used, controllers[controller_index], load_size, load_settings); + bool temp_ret_val = LoadControllerFromListWithOptions(temp_controllers, temp_controller_used, controllers[controller_index], load_size, load_settings); std::string current_name = controllers[controller_index]->GetName() + " @ " + controllers[controller_index]->GetLocation(); LOG_INFO("[ProfileManager] Profile loading: %s for %s", ( temp_ret_val ? "Succeeded" : "FAILED!" ), current_name.c_str()); ret_val |= temp_ret_val; } - /*---------------------------------------------------------*\ - | Delete all temporary controllers | - \*---------------------------------------------------------*/ + /*-------------------------------------------------*\ + | Delete all temporary controllers | + \*-------------------------------------------------*/ for(unsigned int controller_idx = 0; controller_idx < temp_controllers.size(); controller_idx++) { delete temp_controllers[controller_idx]; } + /*-------------------------------------------------*\ + | Get plugin profile data | + \*-------------------------------------------------*/ + if(plugin_manager != NULL && profile_json.contains("plugins")) + { + plugin_manager->OnProfileLoad(profile_json["plugins"]); + } + return(ret_val); } -void ProfileManager::DeleteProfile(std::string profile_name) +nlohmann::json ProfileManager::ReadProfileFileJSON(filesystem::path profile_filepath) { - profile_name = StringUtils::remove_null_terminating_chars(profile_name); + std::ifstream profile_file(profile_filepath, std::ios::in); + nlohmann::json profile_json; - filesystem::path filename = configuration_directory / profile_name; - filename.concat(".orp"); - - filesystem::remove(filename); - - UpdateProfileList(); -} - -void ProfileManager::UpdateProfileList() -{ - profile_list.clear(); - - /*---------------------------------------------------------*\ - | Load profiles by looking for .orp files in current dir | - \*---------------------------------------------------------*/ - for(const auto & entry : filesystem::directory_iterator(configuration_directory)) + /*-------------------------------------------------*\ + | Read settings into JSON store | + \*-------------------------------------------------*/ + if(profile_file) { - std::string filename = entry.path().filename().string(); - - if(filename.find(".orp") != std::string::npos) + try { - LOG_INFO("[ProfileManager] Found file: %s attempting to validate header", filename.c_str()); + profile_file >> profile_json; + } + catch(const std::exception& e) + { + /*-----------------------------------------*\ + | If an exception was caught, that means | + | the JSON parsing failed. Clear out any | + | data in the store as it is corrupt. We | + | could attempt a reload for backup | + | location | + \*-----------------------------------------*/ + LOG_ERROR("[ProfileManager] JSON parsing failed: %s", e.what()); - /*---------------------------------------------------------*\ - | Open input file in binary mode | - \*---------------------------------------------------------*/ - filesystem::path file_path = configuration_directory; - file_path.append(filename); - std::ifstream profile_file(file_path, std::ios::in | std::ios::binary); - - /*---------------------------------------------------------*\ - | Read and verify file header | - \*---------------------------------------------------------*/ - char profile_string[16]; - unsigned int profile_version; - - profile_file.read(profile_string, 16); - profile_file.read((char *)&profile_version, sizeof(unsigned int)); - - if(strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0) - { - if(profile_version <= OPENRGB_PROFILE_VERSION) - { - /*---------------------------------------------------------*\ - | Add this profile to the list | - \*---------------------------------------------------------*/ - filename.erase(filename.length() - 4); - profile_list.push_back(filename); - - LOG_INFO("[ProfileManager] Valid v%i profile found for %s", profile_version, filename.c_str()); - } - else - { - LOG_WARNING("[ProfileManager] Profile %s isn't valid for current version (v%i, expected v%i at most)", filename.c_str(), profile_version, OPENRGB_PROFILE_VERSION); - } - } - else - { - LOG_WARNING("[ProfileManager] Profile %s isn't valid: header is missing", filename.c_str()); - } - - profile_file.close(); + profile_json.clear(); } } -} - -unsigned char * ProfileManager::GetProfileListDescription() -{ - unsigned int data_ptr = 0; - unsigned int data_size = 0; - - /*---------------------------------------------------------*\ - | Calculate data size | - \*---------------------------------------------------------*/ - unsigned short num_profiles = (unsigned short)profile_list.size(); - - data_size += sizeof(data_size); - data_size += sizeof(num_profiles); - - for(unsigned int i = 0; i < num_profiles; i++) - { - data_size += sizeof (unsigned short); - data_size += (unsigned int)strlen(profile_list[i].c_str()) + 1; - } - - /*---------------------------------------------------------*\ - | Create data buffer | - \*---------------------------------------------------------*/ - unsigned char *data_buf = new unsigned char[data_size]; - - /*---------------------------------------------------------*\ - | Copy in data size | - \*---------------------------------------------------------*/ - memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size)); - data_ptr += sizeof(data_size); - - /*---------------------------------------------------------*\ - | Copy in num_profiles | - \*---------------------------------------------------------*/ - memcpy(&data_buf[data_ptr], &num_profiles, sizeof(num_profiles)); - data_ptr += sizeof(num_profiles); - - /*---------------------------------------------------------*\ - | Copy in profile names (size+data) | - \*---------------------------------------------------------*/ - for(unsigned int i = 0; i < num_profiles; i++) - { - unsigned short name_len = (unsigned short)strlen(profile_list[i].c_str()) + 1; - - memcpy(&data_buf[data_ptr], &name_len, sizeof(name_len)); - data_ptr += sizeof(name_len); - - strcpy((char *)&data_buf[data_ptr], profile_list[i].c_str()); - data_ptr += name_len; - } - - return(data_buf); + + profile_file.close(); + + return(profile_json); } diff --git a/ProfileManager.h b/ProfileManager.h index 06b219b29..4c68a6570 100644 --- a/ProfileManager.h +++ b/ProfileManager.h @@ -3,6 +3,8 @@ | | | OpenRGB profile manager | | | +| Adam Honse 09 Nov 2025 | +| | | This file is part of the OpenRGB project | | SPDX-License-Identifier: GPL-2.0-or-later | \*---------------------------------------------------------*/ @@ -15,34 +17,37 @@ class ProfileManagerInterface { public: - virtual bool SaveProfile - ( - std::string profile_name, - bool sizes = false - ) = 0; - virtual bool LoadProfile(std::string profile_name) = 0; - virtual bool LoadSizeFromProfile(std::string profile_name) = 0; - virtual void DeleteProfile(std::string profile_name) = 0; - virtual unsigned char * GetProfileListDescription() = 0; + virtual void DeleteProfile(std::string profile_name) = 0; - std::vector profile_list; + virtual std::string GetActiveProfile() = 0; + virtual std::vector GetControllerListFromProfile(nlohmann::json profile_json) = 0; + virtual std::vector GetControllerListFromSizes() = 0; + virtual std::vector GetProfileList() = 0; + virtual unsigned char * GetProfileListDescription() = 0; - virtual bool LoadDeviceFromListWithOptions - ( - std::vector& temp_controllers, - std::vector& temp_controller_used, - RGBController* load_controller, - bool load_size, - bool load_settings - ) = 0; + virtual bool LoadControllerFromListWithOptions + ( + std::vector& temp_controllers, + std::vector& temp_controller_used, + RGBController* load_controller, + bool load_size, + bool load_settings + ) = 0; - virtual std::vector LoadProfileToList - ( - std::string profile_name, - bool sizes = false - ) = 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 SaveSizes() = 0; + + virtual void SetConfigurationDirectory(const filesystem::path& directory) = 0; + + virtual void SetProfileListFromDescription(char * data_buf) = 0; + + virtual void UpdateProfileList() = 0; - virtual void SetConfigurationDirectory(const filesystem::path& directory) = 0; protected: virtual ~ProfileManagerInterface() {}; }; @@ -53,43 +58,70 @@ public: ProfileManager(const filesystem::path& config_dir); ~ProfileManager(); - bool SaveProfile - ( - std::string profile_name, - bool sizes = false - ); - bool LoadProfile(std::string profile_name); - bool LoadSizeFromProfile(std::string profile_name); - void DeleteProfile(std::string profile_name); - unsigned char * GetProfileListDescription(); + void DeleteProfile(std::string profile_name); - std::vector profile_list; + std::string GetActiveProfile(); + std::vector GetControllerListFromProfile(nlohmann::json profile_json); + std::vector GetControllerListFromSizes(); + std::vector GetProfileList(); + unsigned char * GetProfileListDescription(); - bool LoadDeviceFromListWithOptions - ( - std::vector& temp_controllers, - std::vector& temp_controller_used, - RGBController* load_controller, - bool load_size, - bool load_settings - ); + bool LoadAutoProfileExit(); + bool LoadAutoProfileOpen(); + bool LoadAutoProfileResume(); + bool LoadAutoProfileSuspend(); - std::vector LoadProfileToList - ( - std::string profile_name, - bool sizes = false - ); + bool LoadControllerFromListWithOptions + ( + std::vector& temp_controllers, + std::vector& temp_controller_used, + RGBController* load_controller, + bool load_size, + bool load_settings + ); - void SetConfigurationDirectory(const filesystem::path& directory); + bool LoadProfile(std::string profile_name); + + nlohmann::json ReadProfileJSON(std::string profile_name); + + bool SaveProfile(std::string profile_name); + bool SaveProfileFromJSON(nlohmann::json profile_json); + bool SaveSizes(); + + void SetConfigurationDirectory(const filesystem::path& directory); + + void SetProfileListFromDescription(char * data_buf); + + void UpdateProfileList(); private: - filesystem::path configuration_directory; + /*-----------------------------------------------------*\ + | List of available profiles | + \*-----------------------------------------------------*/ + std::vector profile_list; - void UpdateProfileList(); - bool LoadProfileWithOptions - ( - std::string profile_name, - bool load_size, - bool load_settings - ); + /*-----------------------------------------------------*\ + | Active profile string | + \*-----------------------------------------------------*/ + std::string active_profile; + + /*-----------------------------------------------------*\ + | Profile paths | + \*-----------------------------------------------------*/ + filesystem::path configuration_directory; + filesystem::path profile_directory; + + /*-----------------------------------------------------*\ + | Private functions | + \*-----------------------------------------------------*/ + bool LoadAutoProfile(std::string setting_name); + + bool LoadProfileWithOptions + ( + std::string profile_name, + bool load_size, + bool load_settings + ); + + nlohmann::json ReadProfileFileJSON(filesystem::path profile_filepath); }; diff --git a/ResourceManager.cpp b/ResourceManager.cpp index d354569e8..f2b09e3ed 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -103,6 +103,9 @@ using namespace std::chrono_literals; ResourceManager *ResourceManager::get() { + /*-----------------------------------------------------*\ + | If ResourceManager does not exist yet, create it | + \*-----------------------------------------------------*/ if(!instance) { instance = new ResourceManager(); @@ -113,6 +116,25 @@ ResourceManager *ResourceManager::get() ResourceManager::ResourceManager() { + /*-----------------------------------------------------*\ + | Initialize global instance pointer the when created | + | There should only ever be one instance of | + | ResourceManager | + \*-----------------------------------------------------*/ + if(!instance) + { + instance = this; + } + /*-----------------------------------------------------*\ + | If, for whatever reason, ResourceManager already | + | exists, delete this instance as only one should exist | + \*-----------------------------------------------------*/ + else + { + delete this; + return; + } + /*-----------------------------------------------------*\ | Initialize Detection Variables | \*-----------------------------------------------------*/ @@ -126,6 +148,7 @@ ResourceManager::ResourceManager() init_finished = false; initial_detection = true; background_thread_running = true; + plugin_manager = NULL; /*-----------------------------------------------------*\ | Start the background detection thread in advance; it | @@ -189,7 +212,7 @@ ResourceManager::ResourceManager() \*-----------------------------------------------------*/ profile_manager = new ProfileManager(GetConfigurationDirectory()); server->SetProfileManager(profile_manager); - rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true); + rgb_controllers_sizes = profile_manager->GetControllerListFromSizes(); } ResourceManager::~ResourceManager() @@ -252,7 +275,7 @@ void ResourceManager::RegisterRGBController(RGBController *rgb_controller) \*-------------------------------------------------*/ for(unsigned int controller_size_idx = detection_prev_size; controller_size_idx < rgb_controllers_hw.size(); controller_size_idx++) { - profile_manager->LoadDeviceFromListWithOptions(rgb_controllers_sizes, detection_size_entry_used, rgb_controllers_hw[controller_size_idx], true, false); + profile_manager->LoadControllerFromListWithOptions(rgb_controllers_sizes, detection_size_entry_used, rgb_controllers_hw[controller_size_idx], true, false); } UpdateDeviceList(); @@ -691,7 +714,7 @@ void ResourceManager::SetConfigurationDirectory(const filesystem::path &director profile_manager->SetConfigurationDirectory(directory); rgb_controllers_sizes.clear(); - rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes", true); + rgb_controllers_sizes = profile_manager->GetControllerListFromSizes(); } NetworkServer* ResourceManager::GetServer() diff --git a/cli.cpp b/cli.cpp index d3d8682db..514ba1f01 100644 --- a/cli.cpp +++ b/cli.cpp @@ -865,7 +865,7 @@ bool OptionSize(std::vector* current_devices, std::string argumen /*---------------------------------------------------------*\ | Save the profile | \*---------------------------------------------------------*/ - ResourceManager::get()->GetProfileManager()->SaveProfile("sizes", true); + ResourceManager::get()->GetProfileManager()->SaveSizes(); } return true; @@ -880,23 +880,6 @@ bool OptionProfile(std::string argument, std::vector& rgb_contr \*---------------------------------------------------------*/ if(ResourceManager::get()->GetProfileManager()->LoadProfile(argument)) { - /*-----------------------------------------------------*\ - | Change device mode if profile loading was successful | - \*-----------------------------------------------------*/ - for(std::size_t controller_idx = 0; controller_idx < rgb_controllers.size(); controller_idx++) - { - RGBController* device = rgb_controllers[controller_idx]; - - device->DeviceUpdateMode(); - LOG_DEBUG("[CLI] Updating mode for %s to %i", device->GetName().c_str(), device->GetActiveMode()); - - if(device->GetModeColorMode(device->GetActiveMode()) == MODE_COLORS_PER_LED) - { - device->DeviceUpdateLEDs(); - LOG_DEBUG("[CLI] Mode uses per-LED color, also updating LEDs"); - } - } - std::cout << "Profile loaded successfully" << std::endl; return true; } diff --git a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp index f4a1e6d7f..f2e27cfca 100644 --- a/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage/OpenRGBDevicePage.cpp @@ -2493,36 +2493,32 @@ void OpenRGBDevicePage::on_SpinBoxModeColors_valueChanged(int count) \*-----------------------------------------*/ unsigned int mode_colors_min; unsigned int mode_colors_max; - unsigned int mode_colors; if(selected_zone_mode && (selected_mode >= 0)) { mode_colors_min = device->GetZoneModeColorsMin(selected_zone, selected_mode); mode_colors_max = device->GetZoneModeColorsMax(selected_zone, selected_mode); - mode_colors = device->GetZoneModeColorsCount(selected_zone, selected_mode); } else if(selected_zone_mode) { mode_colors_min = device->GetModeColorsMin(device->GetActiveMode()); mode_colors_max = device->GetModeColorsMax(device->GetActiveMode()); - mode_colors = device->GetModeColorsCount(device->GetActiveMode()); } else { mode_colors_min = device->GetModeColorsMin(selected_mode); mode_colors_max = device->GetModeColorsMax(selected_mode); - mode_colors = device->GetModeColorsCount(selected_mode); } - if((count >= mode_colors_min) && (count <= mode_colors_max)) + if(((unsigned int)count >= mode_colors_min) && ((unsigned int)count <= mode_colors_max)) { if(selected_zone_mode && (selected_mode >= 0)) { - device->SetZoneModeColorsCount(selected_zone, device->GetZoneActiveMode(selected_zone), count); + device->SetZoneModeColorsCount(selected_zone, device->GetZoneActiveMode(selected_zone), (std::size_t)count); } else { - device->SetModeColorsCount(device->GetActiveMode(), count); + device->SetModeColorsCount(device->GetActiveMode(), (std::size_t)count); } } diff --git a/qt/OpenRGBDevicePage/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage/OpenRGBDevicePage.h index 6f7b230cc..770d1937a 100644 --- a/qt/OpenRGBDevicePage/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage/OpenRGBDevicePage.h @@ -37,8 +37,6 @@ public: void HideDeviceView(); void ShowDeviceView(); - void UpdateDevice(); - private: /*-----------------------------------------------------*\ | UI Pointer | @@ -70,6 +68,7 @@ private: \*-----------------------------------------------------*/ void UpdateColor(); void UpdateColorUi(); + void UpdateDevice(); void UpdateLEDList(); void UpdateLEDUi(); void UpdateMode(); diff --git a/qt/OpenRGBDialog/OpenRGBDialog.cpp b/qt/OpenRGBDialog/OpenRGBDialog.cpp index 0e01ced9f..e431b9788 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.cpp +++ b/qt/OpenRGBDialog/OpenRGBDialog.cpp @@ -263,49 +263,6 @@ OpenRGBDialog::OpenRGBDialog(QWidget *parent) : QMainWindow(parent), ui(new Ui:: setGeometry(set_window); } - /*-----------------------------------------------------*\ - | If autoload_profiles doesn't exist or has missing | - | profiles, write it to config | - \*-----------------------------------------------------*/ - json autoload_profiles; - if(ui_settings.contains("autoload_profiles")) - { - autoload_profiles = ui_settings["autoload_profiles"]; - } - else - { - new_settings_keys = true; - } - - if(!autoload_profiles.contains("exit_profile")) - { - json profile; - profile["enabled"] = false; - profile["name"] = ""; - autoload_profiles["exit_profile"] = profile; - new_settings_keys = true; - } - - if(!autoload_profiles.contains("resume_profile")) - { - json profile; - profile["enabled"] = false; - profile["name"] = ""; - autoload_profiles["resume_profile"] = profile; - new_settings_keys = true; - } - - if(!autoload_profiles.contains("suspend_profile")) - { - json profile; - profile["enabled"] = false; - profile["name"] = ""; - autoload_profiles["suspend_profile"] = profile; - new_settings_keys = true; - } - - ui_settings["autoload_profiles"] = autoload_profiles; - /*-----------------------------------------------------*\ | Register detection progress callback with resource | | manager | @@ -592,7 +549,6 @@ void OpenRGBDialog::handleAboutToQuit() delete closeEvent; } - void OpenRGBDialog::changeEvent(QEvent *event) { if(event->type() == QEvent::LanguageChange) @@ -631,10 +587,8 @@ void OpenRGBDialog::closeEvent(QCloseEvent *event) { plugin_manager->UnloadPlugins(); - if(SelectConfigProfile("exit_profile")) + if(ResourceManager::get()->GetProfileManager()->LoadAutoProfileExit()) { - on_ButtonLoadProfile_clicked(); - /*---------------------------------------------*\ | Pause briefly to ensure that all profiles are | | loaded. | @@ -667,39 +621,6 @@ void OpenRGBDialog::keyPressEvent(QKeyEvent *event) } } -bool OpenRGBDialog::SelectConfigProfile(const std::string name) -{ - /*-----------------------------------------------------*\ - | Set automatic profile (if enabled and valid) | - \*-----------------------------------------------------*/ - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - - if(ui_settings.contains("autoload_profiles")) - { - json autoload_profiles = ui_settings["autoload_profiles"]; - if(autoload_profiles.contains(name)) - { - json profile = autoload_profiles[name]; - if (profile.contains("enabled") && profile["enabled"].get() && profile.contains("name")) - { - /*-----------------------------------------*\ - | Set the profile name from settings and | - | check the profile combobox for a match | - \*-----------------------------------------*/ - std::string profile_name = profile["name"].get(); - int profile_index = ui->ProfileBox->findText(QString::fromStdString(profile_name)); - - if(profile_index > -1) - { - ui->ProfileBox->setCurrentIndex(profile_index); - return true; - } - } - } - } - return false; -} - void OpenRGBDialog::AddPluginsPage() { /*-----------------------------------------------------*\ @@ -1335,18 +1256,18 @@ void OpenRGBDialog::UpdateProfileList() ui->ProfileBox->clear(); profileMenu->clear(); - for(std::size_t profile_index = 0; profile_index < profile_manager->profile_list.size(); profile_index++) + for(std::size_t profile_index = 0; profile_index < profile_manager->GetProfileList().size(); profile_index++) { /*---------------------------------------------*\ | Fill in profile combo box | \*---------------------------------------------*/ - ui->ProfileBox->addItem(profile_manager->profile_list[profile_index].c_str()); + ui->ProfileBox->addItem(profile_manager->GetProfileList()[profile_index].c_str()); /*---------------------------------------------*\ | Fill in profile tray icon menu | \*---------------------------------------------*/ - QAction* actionProfileSelected = new QAction(profile_manager->profile_list[profile_index].c_str(), this); - actionProfileSelected->setObjectName(profile_manager->profile_list[profile_index].c_str()); + QAction* actionProfileSelected = new QAction(profile_manager->GetProfileList()[profile_index].c_str(), this); + actionProfileSelected->setObjectName(profile_manager->GetProfileList()[profile_index].c_str()); connect(actionProfileSelected, SIGNAL(triggered()), this, SLOT(on_ProfileSelected())); profileMenu->addAction(actionProfileSelected); } @@ -1357,20 +1278,16 @@ void OpenRGBDialog::UpdateProfileList() void OpenRGBDialog::OnSuspend() { - if(SelectConfigProfile("suspend_profile")) + if(ResourceManager::get()->GetProfileManager()->LoadAutoProfileSuspend()) { plugin_manager->UnloadPlugins(); - on_ButtonLoadProfile_clicked(); } } void OpenRGBDialog::OnResume() { - if(SelectConfigProfile("resume_profile")) - { - on_ButtonLoadProfile_clicked(); - } plugin_manager->LoadPlugins(); + ResourceManager::get()->GetProfileManager()->LoadAutoProfileResume(); } void OpenRGBDialog::on_Exit() @@ -1489,10 +1406,23 @@ void OpenRGBDialog::onDetectionEnded() { ShowLEDView(); } + + /*-----------------------------------------------------*\ + | Load the on open automatic profile | + \*-----------------------------------------------------*/ + ResourceManager::get()->GetProfileManager()->LoadAutoProfileOpen(); } void OpenRGBDialog::on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue) { + /*-----------------------------------------------------*\ + | Send the about to load profile signal to plugins | + \*-----------------------------------------------------*/ + plugin_manager->OnProfileAboutToLoad(); + + /*-----------------------------------------------------*\ + | Apply the color to all device pages | + \*-----------------------------------------------------*/ for(int device = 0; device < ui->DevicesTabBar->count(); device++) { qobject_cast(ui->DevicesTabBar->widget(device))->SetCustomMode(red, green, blue); @@ -1508,7 +1438,7 @@ void OpenRGBDialog::on_SaveSizeProfile() /*-------------------------------------------------*\ | Save the profile | \*-------------------------------------------------*/ - profile_manager->SaveProfile("sizes", true); + profile_manager->SaveSizes(); } } @@ -1646,13 +1576,7 @@ void OpenRGBDialog::on_ProfileSelected() /*-------------------------------------------------*\ | Load the profile | \*-------------------------------------------------*/ - if(profile_manager->LoadProfile(profile_name)) - { - for(int device = 0; device < ui->DevicesTabBar->count(); device++) - { - qobject_cast(ui->DevicesTabBar->widget(device))->UpdateDevice(); - } - } + profile_manager->LoadProfile(profile_name); ui->ProfileBox->setCurrentIndex(ui->ProfileBox->findText(QString::fromStdString(profile_name))); } @@ -1672,13 +1596,7 @@ void OpenRGBDialog::on_ButtonLoadProfile_clicked() /*-------------------------------------------------*\ | Load the profile | \*-------------------------------------------------*/ - if(profile_manager->LoadProfile(profile_name)) - { - for(int device = 0; device < ui->DevicesTabBar->count(); device++) - { - qobject_cast(ui->DevicesTabBar->widget(device))->UpdateDevice(); - } - } + profile_manager->LoadProfile(profile_name); } } diff --git a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp b/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp index 43658fece..ec11b0b9b 100644 --- a/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp +++ b/qt/OpenRGBProfileSaveDialog/OpenRGBProfileSaveDialog.cpp @@ -24,7 +24,7 @@ OpenRGBProfileSaveDialog::OpenRGBProfileSaveDialog(QWidget *parent) : ui->setupUi(this); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - std::vector filenames = ResourceManager::get()->GetProfileManager()->profile_list; + std::vector filenames = ResourceManager::get()->GetProfileManager()->GetProfileList(); if(filenames.empty()) { diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp index 48b730615..58561ab3a 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.cpp @@ -254,6 +254,23 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : ui->CheckboxSharedSMBusAccess->hide(); #endif + /*-----------------------------------------------------*\ + | Load server settings | + \*-----------------------------------------------------*/ + json server_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Server"); + + if(server_settings.contains("all_devices")) + { + bool all_devices = server_settings["all_devices"]; + ui->CheckboxAllDevices->setChecked(all_devices); + } + + if(server_settings.contains("legacy_workaround")) + { + bool legacy_workaround = server_settings["legacy_workaround"]; + ui->CheckboxLegacyWorkaround->setChecked(legacy_workaround); + } + UpdateProfiles(); /*---------------------------------------------------------*\ @@ -315,53 +332,57 @@ void OpenRGBSettingsPage::changeEvent(QEvent *event) void OpenRGBSettingsPage::UpdateProfiles() { - /*---------------------------------------------------------*\ - | Load AutoStart settings | - \*---------------------------------------------------------*/ + /*-----------------------------------------------------*\ + | Load AutoStart settings | + \*-----------------------------------------------------*/ ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager(); - /*---------------------------------------------------------*\ - | Load profiles into combo box | - \*---------------------------------------------------------*/ + /*-----------------------------------------------------*\ + | Load profiles into combo box | + \*-----------------------------------------------------*/ if(profile_manager != NULL) { ui->ComboBoxAutoStartProfile->blockSignals(true); - ui->ComboBoxSuspendProfile->blockSignals(true); - ui->ComboBoxResumeProfile->blockSignals(true); ui->ComboBoxExitProfile->blockSignals(true); + ui->ComboBoxOpenProfile->blockSignals(true); + ui->ComboBoxResumeProfile->blockSignals(true); + ui->ComboBoxSuspendProfile->blockSignals(true); ui->ComboBoxAutoStartProfile->clear(); - ui->ComboBoxSuspendProfile->clear(); - ui->ComboBoxResumeProfile->clear(); ui->ComboBoxExitProfile->clear(); + ui->ComboBoxOpenProfile->clear(); + ui->ComboBoxResumeProfile->clear(); + ui->ComboBoxSuspendProfile->clear(); - for(std::size_t profile_index = 0; profile_index < profile_manager->profile_list.size(); profile_index++) + for(std::size_t profile_index = 0; profile_index < profile_manager->GetProfileList().size(); profile_index++) { - QString new_profile = QString(profile_manager->profile_list[profile_index].c_str()); + QString new_profile = QString(profile_manager->GetProfileList()[profile_index].c_str()); ui->ComboBoxAutoStartProfile->addItem(new_profile); - ui->ComboBoxSuspendProfile->addItem(new_profile); - ui->ComboBoxResumeProfile->addItem(new_profile); ui->ComboBoxExitProfile->addItem(new_profile); + ui->ComboBoxOpenProfile->addItem(new_profile); + ui->ComboBoxResumeProfile->addItem(new_profile); + ui->ComboBoxSuspendProfile->addItem(new_profile); } ui->ComboBoxAutoStartProfile->blockSignals(false); - ui->ComboBoxSuspendProfile->blockSignals(false); - ui->ComboBoxResumeProfile->blockSignals(false); ui->ComboBoxExitProfile->blockSignals(false); + ui->ComboBoxOpenProfile->blockSignals(false); + ui->ComboBoxResumeProfile->blockSignals(false); + ui->ComboBoxSuspendProfile->blockSignals(false); } - /*---------------------------------------------------------*\ - | Load user interface settings | - \*---------------------------------------------------------*/ + /*-----------------------------------------------------*\ + | Load user interface settings | + \*-----------------------------------------------------*/ json autostart_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("AutoStart"); if(autostart_settings.contains("profile")) { - /*-----------------------------------------------------*\ - | Set the profile name from settings and check the | - | profile combobox for a match | - \*-----------------------------------------------------*/ + /*-------------------------------------------------*\ + | Set the profile name from settings and check the | + | profile combobox for a match | + \*-------------------------------------------------*/ std::string profile_name = autostart_settings["profile"].get(); int profile_index = ui->ComboBoxAutoStartProfile->findText(QString::fromStdString(profile_name)); @@ -371,112 +392,117 @@ void OpenRGBSettingsPage::UpdateProfiles() } } - /*---------------------------------------------------------*\ - | Load user interface settings | - \*---------------------------------------------------------*/ - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); + /*-----------------------------------------------------*\ + | Load profile manager settings | + \*-----------------------------------------------------*/ + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); - if(ui_settings.contains("autoload_profiles")) + if(profilemanager_settings.contains("exit_profile")) { - json autoload_profiles = ui_settings["autoload_profiles"]; + json profile = profilemanager_settings["exit_profile"]; - if(autoload_profiles.contains("exit_profile")) + if(profile.contains("enabled")) { - json profile = autoload_profiles["exit_profile"]; - - if(profile.contains("enabled")) - { - bool is_enabled = profile["enabled"].get(); - ui->CheckboxSetOnExit->setChecked(is_enabled); - ui->ComboBoxExitProfile->setEnabled(is_enabled); - } - - if(profile.contains("name")) - { - /*-----------------------------------------------------*\ - | Set the profile name from settings and check the | - | profile combobox for a match | - \*-----------------------------------------------------*/ - std::string profile_name = profile["name"].get(); - int profile_index = ui->ComboBoxExitProfile->findText(QString::fromStdString(profile_name)); - - if(profile_index > -1) - { - ui->ComboBoxExitProfile->setCurrentIndex(profile_index); - } - } + bool is_enabled = profile["enabled"].get(); + ui->CheckboxSetOnExit->setChecked(is_enabled); + ui->ComboBoxExitProfile->setEnabled(is_enabled); } - if(autoload_profiles.contains("resume_profile")) + if(profile.contains("name")) { - json profile = autoload_profiles["resume_profile"]; + /*---------------------------------------------*\ + | Set the profile name from settings and check | + | the profile combobox for a match | + \*---------------------------------------------*/ + std::string profile_name = profile["name"].get(); + int profile_index = ui->ComboBoxExitProfile->findText(QString::fromStdString(profile_name)); - if(profile.contains("enabled")) + if(profile_index > -1) { - bool is_enabled = profile["enabled"].get(); - ui->CheckboxSetOnResume->setChecked(is_enabled); - ui->ComboBoxResumeProfile->setEnabled(is_enabled); - } - - if(profile.contains("name")) - { - /*-----------------------------------------------------*\ - | Set the profile name from settings and check the | - | profile combobox for a match | - \*-----------------------------------------------------*/ - std::string profile_name = profile["name"].get(); - int profile_index = ui->ComboBoxResumeProfile->findText(QString::fromStdString(profile_name)); - - if(profile_index > -1) - { - ui->ComboBoxResumeProfile->setCurrentIndex(profile_index); - } - } - } - - if(autoload_profiles.contains("suspend_profile")) - { - json profile = autoload_profiles["suspend_profile"]; - - if(profile.contains("enabled")) - { - bool is_enabled = profile["enabled"].get(); - ui->CheckboxSetOnSuspend->setChecked(is_enabled); - ui->ComboBoxSuspendProfile->setEnabled(is_enabled); - } - - if(profile.contains("name")) - { - /*-----------------------------------------------------*\ - | Set the profile name from settings and check the | - | profile combobox for a match | - \*-----------------------------------------------------*/ - std::string profile_name = profile["name"].get(); - int profile_index = ui->ComboBoxSuspendProfile->findText(QString::fromStdString(profile_name)); - - if(profile_index > -1) - { - ui->ComboBoxSuspendProfile->setCurrentIndex(profile_index); - } + ui->ComboBoxExitProfile->setCurrentIndex(profile_index); } } } - /*---------------------------------------------------------*\ - | Load server settings | - \*---------------------------------------------------------*/ - json server_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Server"); - - if(server_settings.contains("all_devices")) + if(profilemanager_settings.contains("open_profile")) { - bool all_devices = server_settings["all_devices"]; - ui->CheckboxAllDevices->setChecked(all_devices); + json profile = profilemanager_settings["open_profile"]; + + if(profile.contains("enabled")) + { + bool is_enabled = profile["enabled"].get(); + ui->CheckboxSetOnOpen->setChecked(is_enabled); + ui->ComboBoxOpenProfile->setEnabled(is_enabled); + } + + if(profile.contains("name")) + { + /*---------------------------------------------*\ + | Set the profile name from settings and check | + | the profile combobox for a match | + \*---------------------------------------------*/ + std::string profile_name = profile["name"].get(); + int profile_index = ui->ComboBoxOpenProfile->findText(QString::fromStdString(profile_name)); + + if(profile_index > -1) + { + ui->ComboBoxOpenProfile->setCurrentIndex(profile_index); + } + } } - if(server_settings.contains("legacy_workaround")) + if(profilemanager_settings.contains("resume_profile")) { - bool legacy_workaround = server_settings["legacy_workaround"]; - ui->CheckboxLegacyWorkaround->setChecked(legacy_workaround); + json profile = profilemanager_settings["resume_profile"]; + + if(profile.contains("enabled")) + { + bool is_enabled = profile["enabled"].get(); + ui->CheckboxSetOnResume->setChecked(is_enabled); + ui->ComboBoxResumeProfile->setEnabled(is_enabled); + } + + if(profile.contains("name")) + { + /*---------------------------------------------*\ + | Set the profile name from settings and check | + | the profile combobox for a match | + \*---------------------------------------------*/ + std::string profile_name = profile["name"].get(); + int profile_index = ui->ComboBoxResumeProfile->findText(QString::fromStdString(profile_name)); + + if(profile_index > -1) + { + ui->ComboBoxResumeProfile->setCurrentIndex(profile_index); + } + } + } + + if(profilemanager_settings.contains("suspend_profile")) + { + json profile = profilemanager_settings["suspend_profile"]; + + if(profile.contains("enabled")) + { + bool is_enabled = profile["enabled"].get(); + ui->CheckboxSetOnSuspend->setChecked(is_enabled); + ui->ComboBoxSuspendProfile->setEnabled(is_enabled); + } + + if(profile.contains("name")) + { + /*---------------------------------------------*\ + | Set the profile name from settings and check | + | the profile combobox for a match | + \*---------------------------------------------*/ + std::string profile_name = profile["name"].get(); + int profile_index = ui->ComboBoxSuspendProfile->findText(QString::fromStdString(profile_name)); + + if(profile_index > -1) + { + ui->ComboBoxSuspendProfile->setCurrentIndex(profile_index); + } + } } } @@ -586,10 +612,10 @@ void OpenRGBSettingsPage::on_CheckboxRunZoneChecks_clicked() void OpenRGBSettingsPage::on_CheckboxSetOnExit_clicked(bool checked) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["exit_profile"]["enabled"] = checked; - ui_settings["autoload_profiles"]["exit_profile"]["name"] = ui->ComboBoxExitProfile->currentText().toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["exit_profile"]["enabled"] = checked; + profilemanager_settings["exit_profile"]["name"] = ui->ComboBoxExitProfile->currentText().toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); ui->ComboBoxExitProfile->setEnabled(checked); @@ -597,18 +623,37 @@ void OpenRGBSettingsPage::on_CheckboxSetOnExit_clicked(bool checked) void OpenRGBSettingsPage::on_ComboBoxExitProfile_currentTextChanged(const QString exit_profile_name) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["exit_profile"]["name"] = exit_profile_name.toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["exit_profile"]["name"] = exit_profile_name.toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); + SaveSettings(); +} + +void OpenRGBSettingsPage::on_CheckboxSetOnOpen_clicked(bool checked) +{ + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["open_profile"]["enabled"] = checked; + profilemanager_settings["open_profile"]["name"] = ui->ComboBoxOpenProfile->currentText().toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); + SaveSettings(); + + ui->ComboBoxOpenProfile->setEnabled(checked); +} + +void OpenRGBSettingsPage::on_ComboBoxOpenProfile_currentTextChanged(const QString open_profile_name) +{ + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["open_profile"]["name"] = open_profile_name.toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); } void OpenRGBSettingsPage::on_CheckboxSetOnResume_clicked(bool checked) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["resume_profile"]["enabled"] = checked; - ui_settings["autoload_profiles"]["resume_profile"]["name"] = ui->ComboBoxResumeProfile->currentText().toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["resume_profile"]["enabled"] = checked; + profilemanager_settings["resume_profile"]["name"] = ui->ComboBoxResumeProfile->currentText().toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); ui->ComboBoxResumeProfile->setEnabled(checked); @@ -616,18 +661,18 @@ void OpenRGBSettingsPage::on_CheckboxSetOnResume_clicked(bool checked) void OpenRGBSettingsPage::on_ComboBoxResumeProfile_currentTextChanged(const QString resume_profile_name) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["resume_profile"]["name"] = resume_profile_name.toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["resume_profile"]["name"] = resume_profile_name.toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); } void OpenRGBSettingsPage::on_CheckboxSetOnSuspend_clicked(bool checked) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["suspend_profile"]["enabled"] = checked; - ui_settings["autoload_profiles"]["suspend_profile"]["name"] = ui->ComboBoxSuspendProfile->currentText().toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["suspend_profile"]["enabled"] = checked; + profilemanager_settings["suspend_profile"]["name"] = ui->ComboBoxSuspendProfile->currentText().toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); ui->ComboBoxSuspendProfile->setEnabled(checked); @@ -635,9 +680,9 @@ void OpenRGBSettingsPage::on_CheckboxSetOnSuspend_clicked(bool checked) void OpenRGBSettingsPage::on_ComboBoxSuspendProfile_currentTextChanged(const QString suspend_profile_name) { - json ui_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("UserInterface"); - ui_settings["autoload_profiles"]["suspend_profile"]["name"] = suspend_profile_name.toStdString(); - ResourceManager::get()->GetSettingsManager()->SetSettings("UserInterface", ui_settings); + json profilemanager_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ProfileManager"); + profilemanager_settings["suspend_profile"]["name"] = suspend_profile_name.toStdString(); + ResourceManager::get()->GetSettingsManager()->SetSettings("ProfileManager", profilemanager_settings); SaveSettings(); } diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h index 1e6fe400d..a9d7ea7ba 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.h @@ -85,6 +85,8 @@ private slots: void on_CheckboxSetOnExit_clicked(bool checked); void on_ComboBoxExitProfile_currentTextChanged(const QString exit_profile_name); + void on_CheckboxSetOnOpen_clicked(bool checked); + void on_ComboBoxOpenProfile_currentTextChanged(const QString open_profile_name); void on_CheckboxSetOnResume_clicked(bool checked); void on_ComboBoxResumeProfile_currentTextChanged(const QString resume_profile_name); void on_CheckboxSetOnSuspend_clicked(bool checked); diff --git a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui index 8acfe8590..785217fee 100644 --- a/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui +++ b/qt/OpenRGBSettingsPage/OpenRGBSettingsPage.ui @@ -6,8 +6,8 @@ 0 0 - 475 - 500 + 500 + 475 @@ -30,129 +30,29 @@ 0 - -328 + -211 508 - 1105 + 1161 - - + + - Enable Log Console (restart required) + Set Profile on Resume - - - - Load Profile + + + + 1 - - - - - - Disable Key Expansion in Device View + + 65535 - - - - - - Shared SMBus Access (restart required) - - - - - - - - - - Start at Login Status - - - - - - - Load Window Geometry - - - - - - - Hex Format - - - - - - - Show LED View by Default - - - - - - - Legacy Workaround - - - - - - - - - - Theme (restart required) - - - - - - - - - - Detection Settings: - - - - - - - Serve All Devices (Including those from client connections) - - - - - - - - - - AMD SMBus: Reduce CPU Usage (restart required) - - - - - - - - - - Start at Login Settings: - - - - - - - Set Server Host + + 6742 @@ -163,29 +63,13 @@ - - - - - + + - Start Minimized + Set Server Port - - - - - - - Start at Login - - - - - - @@ -193,10 +77,116 @@ - - + + + + + - Start Client + Set Server Host + + + + + + + Detection Settings: + + + + + + + Profile Settings: + + + + + + + Start at Login Status + + + + + + + Run Zone Checks on Rescan + + + + + + + Serve All Devices (Including those from client connections) + + + + + + + Set Profile on Exit + + + + + + + + + + Save Geometry on Close + + + + + + + + + + Shared SMBus Access (restart required) + + + + + + + Drivers Settings: + + + + + + + + + + AMD SMBus: Reduce CPU Usage (restart required) + + + + + + + Show LED View by Default + + + + + + + + + + Legacy Workaround + + + + + + + Start at Login Settings: @@ -207,7 +197,103 @@ - + + + + Server Settings: + + + + + + + + + + Start Server + + + + + + + Set Profile on Suspend + + + + + + + + + + Enable Log File (restart required) + + + + + + + Hex Format + + + + + + + Language + + + + + + + + + + Custom Arguments + + + + + + + Load Window Geometry + + + + + + + Start Minimized + + + + + + + Disable Key Expansion in Device View + + + + + + + Start at Login + + + + + + + + + + Load Profile + + + + Qt::Orientation::Vertical @@ -223,9 +309,6 @@ - - - @@ -233,48 +316,6 @@ - - - - Server Settings: - - - - - - - Save Geometry on Close - - - - - - - Start Server - - - - - - - Set Server Port - - - - - - - Set Profile on Suspend - - - - - - - Run Zone Checks on Rescan - - - @@ -282,61 +323,37 @@ - - + + + + + - Enable Log File (restart required) + Enable Log Console (restart required) - - - - 1 - - - 65535 - - - 6742 + + + + Theme (restart required) - - + + + + + - Set Profile on Resume + Set Profile on Open - - + + - Language - - - - - - - Drivers Settings: - - - - - - - Custom Arguments - - - - - - - - - - Set Profile on Exit + Start Client diff --git a/qt/OpenRGBZonesBulkResizer/OpenRGBZonesBulkResizer.cpp b/qt/OpenRGBZonesBulkResizer/OpenRGBZonesBulkResizer.cpp index 2433ebe8c..f6df9d12e 100644 --- a/qt/OpenRGBZonesBulkResizer/OpenRGBZonesBulkResizer.cpp +++ b/qt/OpenRGBZonesBulkResizer/OpenRGBZonesBulkResizer.cpp @@ -196,7 +196,7 @@ void OpenRGBZonesBulkResizer::on_save_button_clicked() /*-----------------------------------------------------*\ | Save the profile | \*-----------------------------------------------------*/ - profile_manager->SaveProfile("sizes", true); + profile_manager->SaveSizes(); } /*---------------------------------------------------------*\