Files
OpenRGB/ProfileManager.h
Adam Honse 7971ab1f38 Rework Profiles to use JSON format
* Update OpenRGB Plugin Interface to include functions for loading/saving profile JSON data into OpenRGB profiles
    * Update ProfileManager to handle auto-load profiles (Exit, Open, Resume, Suspend) and move their settings to ProfileManager section
    * Update ProfileManager to store profiles in "profiles" folder in .json format
    * Update ProfileManager to store size profile in sizes.json
    * Update ProfileManager to perform device UpdateMode/UpdateColors when loading profile
    * Code cleanup of ProfileManager and profile-related code
2025-12-19 22:33:52 -06:00

128 lines
6.2 KiB
C++

/*---------------------------------------------------------*\
| ProfileManager.h |
| |
| OpenRGB profile manager |
| |
| Adam Honse <calcprogrammer1@gmail.com> 09 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "filesystem.h"
class ProfileManagerInterface
{
public:
virtual void DeleteProfile(std::string profile_name) = 0;
virtual std::string GetActiveProfile() = 0;
virtual std::vector<RGBController*> GetControllerListFromProfile(nlohmann::json profile_json) = 0;
virtual std::vector<RGBController*> GetControllerListFromSizes() = 0;
virtual std::vector<std::string> GetProfileList() = 0;
virtual unsigned char * GetProfileListDescription() = 0;
virtual bool LoadControllerFromListWithOptions
(
std::vector<RGBController*>& temp_controllers,
std::vector<bool>& temp_controller_used,
RGBController* load_controller,
bool load_size,
bool load_settings
) = 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;
protected:
virtual ~ProfileManagerInterface() {};
};
class ProfileManager: public ProfileManagerInterface
{
public:
ProfileManager(const filesystem::path& config_dir);
~ProfileManager();
void DeleteProfile(std::string profile_name);
std::string GetActiveProfile();
std::vector<RGBController*> GetControllerListFromProfile(nlohmann::json profile_json);
std::vector<RGBController*> GetControllerListFromSizes();
std::vector<std::string> GetProfileList();
unsigned char * GetProfileListDescription();
bool LoadAutoProfileExit();
bool LoadAutoProfileOpen();
bool LoadAutoProfileResume();
bool LoadAutoProfileSuspend();
bool LoadControllerFromListWithOptions
(
std::vector<RGBController*>& temp_controllers,
std::vector<bool>& temp_controller_used,
RGBController* load_controller,
bool load_size,
bool load_settings
);
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:
/*-----------------------------------------------------*\
| List of available profiles |
\*-----------------------------------------------------*/
std::vector<std::string> profile_list;
/*-----------------------------------------------------*\
| Active profile string |
\*-----------------------------------------------------*/
std::string active_profile;
/*-----------------------------------------------------*\
| Profile paths |
\*-----------------------------------------------------*/
filesystem::path configuration_directory;
filesystem::path profile_directory;
/*-----------------------------------------------------*\
| 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);
};