mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-28 12:17:04 -05:00
Add default settings support
This commit is contained in:
@@ -133,20 +133,6 @@ static void addSettingsHelper(obs_property_t *property,
|
||||
} while (obs_property_next(&property));
|
||||
}
|
||||
|
||||
std::vector<SourceSetting> GetSoruceSettings(obs_source_t *source)
|
||||
{
|
||||
properties_t properties(obs_source_properties(source),
|
||||
obs_properties_destroy);
|
||||
if (!properties) {
|
||||
return {};
|
||||
}
|
||||
std::vector<SourceSetting> settings;
|
||||
|
||||
auto it = obs_properties_first(properties.get());
|
||||
addSettingsHelper(it, settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
static std::optional<std::string>
|
||||
getDataJsonWithDefaults(const OBSWeakSource &ws)
|
||||
{
|
||||
@@ -495,11 +481,25 @@ void SourceSettingSelection::SelectionIdxChanged(int idx)
|
||||
emit SelectionChanged(setting);
|
||||
}
|
||||
|
||||
static std::vector<SourceSetting> getSourceSettings(obs_source_t *source)
|
||||
{
|
||||
properties_t properties(obs_source_properties(source),
|
||||
obs_properties_destroy);
|
||||
if (!properties) {
|
||||
return {};
|
||||
}
|
||||
std::vector<SourceSetting> settings;
|
||||
|
||||
auto it = obs_properties_first(properties.get());
|
||||
addSettingsHelper(it, settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
void SourceSettingSelection::Populate(const OBSWeakSource &source)
|
||||
{
|
||||
_settings->clear();
|
||||
OBSSourceAutoRelease s = obs_weak_source_get_source(source);
|
||||
auto settings = GetSoruceSettings(s);
|
||||
const auto settings = getSourceSettings(s);
|
||||
for (const auto &setting : settings) {
|
||||
QVariant variant;
|
||||
variant.setValue(setting);
|
||||
|
||||
@@ -32,7 +32,6 @@ private:
|
||||
friend class SourceSettingSelection;
|
||||
};
|
||||
|
||||
std::vector<SourceSetting> GetSoruceSettings(obs_source_t *source);
|
||||
std::optional<std::string> GetSourceSettingValue(const OBSWeakSource &source,
|
||||
const SourceSetting &setting);
|
||||
std::optional<std::string>
|
||||
|
||||
@@ -4,23 +4,30 @@
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::string GetSourceSettings(OBSWeakSource ws)
|
||||
std::optional<std::string> GetSourceSettings(OBSWeakSource ws,
|
||||
bool includeDefaults)
|
||||
{
|
||||
if (!ws) {
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string settings;
|
||||
auto s = obs_weak_source_get_source(ws);
|
||||
obs_data_t *data = obs_source_get_settings(s);
|
||||
OBSSourceAutoRelease source = obs_weak_source_get_source(ws);
|
||||
OBSDataAutoRelease dataWithoutDefaults =
|
||||
obs_source_get_settings(source);
|
||||
if (!dataWithoutDefaults) {
|
||||
return {};
|
||||
}
|
||||
|
||||
OBSDataAutoRelease dataWithDefaults =
|
||||
obs_data_get_defaults(dataWithoutDefaults);
|
||||
obs_data_apply(dataWithDefaults, dataWithoutDefaults);
|
||||
|
||||
auto &data = includeDefaults ? dataWithDefaults : dataWithoutDefaults;
|
||||
auto json = obs_data_get_json(data);
|
||||
if (json) {
|
||||
settings = json;
|
||||
if (!json) {
|
||||
return {};
|
||||
}
|
||||
obs_data_release(data);
|
||||
obs_source_release(s);
|
||||
|
||||
return settings;
|
||||
return json;
|
||||
}
|
||||
|
||||
void SetSourceSettings(obs_source_t *s, const std::string &settings)
|
||||
@@ -39,12 +46,11 @@ void SetSourceSettings(obs_source_t *s, const std::string &settings)
|
||||
obs_data_release(data);
|
||||
}
|
||||
|
||||
bool CompareSourceSettings(const OBSWeakSource &source,
|
||||
bool CompareSourceSettings(const std::string &sourceSettings,
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex)
|
||||
{
|
||||
std::string currentSettings = GetSourceSettings(source);
|
||||
return MatchJson(currentSettings, settings, regex);
|
||||
return MatchJson(sourceSettings, settings, regex);
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
#pragma once
|
||||
#include <obs.hpp>
|
||||
#include <string>
|
||||
#include <regex-config.hpp>
|
||||
|
||||
#include <obs.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::string GetSourceSettings(OBSWeakSource ws);
|
||||
std::optional<std::string> GetSourceSettings(OBSWeakSource ws,
|
||||
bool includeDefaults);
|
||||
void SetSourceSettings(obs_source_t *s, const std::string &settings);
|
||||
bool CompareSourceSettings(const OBSWeakSource &source,
|
||||
bool CompareSourceSettings(const std::string &sourceSettings,
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user