Files
OpenRGB/JsonUtils.cpp
Adam Honse 072d27d9dd Settings Rework
* Add JSON string configuration field to RGBController to store device-specific configurations
    * This JSON string holds both configuration and schema
    * Add settings schema tracking to SettingsManager
    * Implement dynamic settings widget that generates a settings UI based on a JSON schema
    * Implement SettingsManager callback for notifying of settings changes and settings schema updates
    * Always enable Entire Device zone option and use it to enable Edit Device
    * Rename SaveSizes to SaveConfiguration in ProfileManager and Sizes.json to Configuration.json
    * Add zone flag for indicating that a zone's geometry may change, informing profile manager to ignore this check
    * Remove Theme setting and Theme Manager, as this didn't work on most setups anyways and Qt6 has proper Windows dark theming
2026-05-14 17:25:35 -05:00

72 lines
1.8 KiB
C++

/*---------------------------------------------------------*\
| JsonUtils.cpp |
| |
| JSON utility functions |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "JsonUtils.h"
bool JsonUtils::JsonGetBool(nlohmann::json& val, std::string key, bool dft)
{
if((val.contains(key)) && (val[key].type() == nlohmann::json::value_t::boolean))
{
return((bool)val[key]);
}
else
{
return(dft);
}
}
int JsonUtils::JsonGetInt(nlohmann::json& val, std::string key, int dft)
{
if((val.contains(key)) &&
((val[key].type() == nlohmann::json::value_t::number_integer) ||
(val[key].type() == nlohmann::json::value_t::number_unsigned) ||
(val[key].type() == nlohmann::json::value_t::number_float)))
{
return((int)val[key]);
}
else
{
return(dft);
}
}
std::string JsonUtils::JsonGetString(nlohmann::json& val, std::string key, std::string dft, bool allow_empty)
{
if((val.contains(key)) && (val[key].type() == nlohmann::json::value_t::string))
{
std::string ret_val = (std::string)val[key];
if((!allow_empty) && (ret_val == ""))
{
return(dft);
}
else
{
return(ret_val);
}
}
else
{
return(dft);
}
}
bool JsonUtils::JsonParse(std::string json_string, nlohmann::json& json_ref)
{
try
{
json_ref = nlohmann::json::parse(json_string);
return(true);
}
catch(...)
{
return(false);
}
}