mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-14 12:51:43 -05:00
Switch to RegexConfig
This commit is contained in:
parent
a243e026c8
commit
7ddfdcf5be
|
|
@ -227,7 +227,6 @@ AdvSceneSwitcher.condition.source="Source"
|
|||
AdvSceneSwitcher.condition.source.type.active="Is active"
|
||||
AdvSceneSwitcher.condition.source.type.showing="Is showing"
|
||||
AdvSceneSwitcher.condition.source.type.settings="Settings match"
|
||||
AdvSceneSwitcher.condition.source.regex="Use regular expressions"
|
||||
AdvSceneSwitcher.condition.source.getSettings="Get current settings"
|
||||
AdvSceneSwitcher.condition.source.entry.line1="{{sources}} {{conditions}}"
|
||||
AdvSceneSwitcher.condition.source.entry.line2="{{settings}}"
|
||||
|
|
@ -240,7 +239,6 @@ AdvSceneSwitcher.condition.filter="Filter"
|
|||
AdvSceneSwitcher.condition.filter.type.active="Is enabled"
|
||||
AdvSceneSwitcher.condition.filter.type.showing="Is disabled"
|
||||
AdvSceneSwitcher.condition.filter.type.settings="Settings match"
|
||||
AdvSceneSwitcher.condition.filter.regex="Use regular expressions"
|
||||
AdvSceneSwitcher.condition.filter.getSettings="Get current settings"
|
||||
AdvSceneSwitcher.condition.filter.entry.line1="On {{sources}} {{filters}} {{conditions}}"
|
||||
AdvSceneSwitcher.condition.filter.entry.line2="{{settings}}"
|
||||
|
|
@ -286,7 +284,6 @@ AdvSceneSwitcher.condition.date.entry.nextMatchDate="Next match at: %1"
|
|||
AdvSceneSwitcher.condition.date.entry.updateOnRepeat="{{updateOnRepeat}} On repeat update selected date to repeat date"
|
||||
AdvSceneSwitcher.condition.sceneTransform="Scene item transform"
|
||||
AdvSceneSwitcher.condition.sceneTransform.getTransform="Get transform"
|
||||
AdvSceneSwitcher.condition.sceneTransform.regex="Use regular expressions"
|
||||
AdvSceneSwitcher.condition.sceneTransform.entry.line1="On{{scenes}}{{sources}}matches transform"
|
||||
AdvSceneSwitcher.condition.sceneTransform.entry.line2="{{settings}}"
|
||||
AdvSceneSwitcher.condition.sceneTransform.entry.line3="{{regex}} {{getSettings}}"
|
||||
|
|
@ -335,7 +332,6 @@ AdvSceneSwitcher.condition.stats.entry="{{stats}} is {{condition}} {{value}}"
|
|||
AdvSceneSwitcher.condition.profile="Profile"
|
||||
AdvSceneSwitcher.condition.profile.entry="Current active profile is {{profiles}}"
|
||||
AdvSceneSwitcher.condition.websocket="Websocket"
|
||||
AdvSceneSwitcher.condition.websocket.useRegex="Use regular expressions"
|
||||
AdvSceneSwitcher.condition.websocket.entry="Message was received:"
|
||||
|
||||
; Macro Actions
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ bool MacroConditionFile::matchFileContent(QString &filedata)
|
|||
_lastHash = newHash;
|
||||
}
|
||||
|
||||
if (_useRegex) {
|
||||
QRegularExpression expr(QString::fromStdString(_text));
|
||||
if (_regex.Enabled()) {
|
||||
auto expr = _regex.GetRegularExpression(_text);
|
||||
if (!expr.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -105,10 +105,10 @@ bool MacroConditionFile::CheckCondition()
|
|||
bool MacroConditionFile::Save(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Save(obj);
|
||||
_regex.Save(obj);
|
||||
obs_data_set_string(obj, "file", _file.c_str());
|
||||
obs_data_set_string(obj, "text", _text.c_str());
|
||||
obs_data_set_int(obj, "fileType", static_cast<int>(_fileType));
|
||||
obs_data_set_bool(obj, "useRegex", _useRegex);
|
||||
obs_data_set_bool(obj, "useTime", _useTime);
|
||||
obs_data_set_bool(obj, "onlyMatchIfChanged", _onlyMatchIfChanged);
|
||||
return true;
|
||||
|
|
@ -117,10 +117,15 @@ bool MacroConditionFile::Save(obs_data_t *obj)
|
|||
bool MacroConditionFile::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_regex.Load(obj);
|
||||
// TODO: remove in future version
|
||||
if (obs_data_has_user_value(obj, "useRegex")) {
|
||||
_regex.CreateBackwardsCompatibleRegex(
|
||||
obs_data_get_bool(obj, "useRegex"));
|
||||
}
|
||||
_file = obs_data_get_string(obj, "file");
|
||||
_text = obs_data_get_string(obj, "text");
|
||||
_fileType = static_cast<FileType>(obs_data_get_int(obj, "fileType"));
|
||||
_useRegex = obs_data_get_bool(obj, "useRegex");
|
||||
_useTime = obs_data_get_bool(obj, "useTime");
|
||||
_onlyMatchIfChanged = obs_data_get_bool(obj, "onlyMatchIfChanged");
|
||||
return true;
|
||||
|
|
@ -138,8 +143,7 @@ MacroConditionFileEdit::MacroConditionFileEdit(
|
|||
_fileType = new QComboBox();
|
||||
_filePath = new FileSelection();
|
||||
_matchText = new ResizingPlainTextEdit(this);
|
||||
_useRegex = new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.fileTab.useRegExp"));
|
||||
_regex = new RegexConfigWidget(parent);
|
||||
_checkModificationDate = new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.fileTab.checkfileContentTime"));
|
||||
_checkFileContent = new QCheckBox(
|
||||
|
|
@ -151,8 +155,8 @@ MacroConditionFileEdit::MacroConditionFileEdit(
|
|||
SLOT(PathChanged(const QString &)));
|
||||
QWidget::connect(_matchText, SIGNAL(textChanged()), this,
|
||||
SLOT(MatchTextChanged()));
|
||||
QWidget::connect(_useRegex, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(UseRegexChanged(int)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
QWidget::connect(_checkModificationDate, SIGNAL(stateChanged(int)),
|
||||
this, SLOT(CheckModificationDateChanged(int)));
|
||||
QWidget::connect(_checkFileContent, SIGNAL(stateChanged(int)), this,
|
||||
|
|
@ -165,7 +169,7 @@ MacroConditionFileEdit::MacroConditionFileEdit(
|
|||
{"{{fileType}}", _fileType},
|
||||
{"{{filePath}}", _filePath},
|
||||
{"{{matchText}}", _matchText},
|
||||
{"{{useRegex}}", _useRegex},
|
||||
{"{{useRegex}}", _regex},
|
||||
{"{{checkModificationDate}}", _checkModificationDate},
|
||||
{"{{checkFileContent}}", _checkFileContent},
|
||||
};
|
||||
|
|
@ -204,7 +208,7 @@ void MacroConditionFileEdit::UpdateEntryData()
|
|||
|
||||
_filePath->SetPath(QString::fromStdString(_entryData->_file));
|
||||
_matchText->setPlainText(QString::fromStdString(_entryData->_text));
|
||||
_useRegex->setChecked(_entryData->_useRegex);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
_checkModificationDate->setChecked(_entryData->_useTime);
|
||||
_checkFileContent->setChecked(_entryData->_onlyMatchIfChanged);
|
||||
|
||||
|
|
@ -257,14 +261,16 @@ void MacroConditionFileEdit::MatchTextChanged()
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionFileEdit::UseRegexChanged(int state)
|
||||
void MacroConditionFileEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_useRegex = state;
|
||||
_entryData->_regex = conf;
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionFileEdit::CheckModificationDateChanged(int state)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "macro.hpp"
|
||||
#include "file-selection.hpp"
|
||||
#include "resizing-text-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
|
|
@ -31,7 +32,7 @@ public:
|
|||
std::string _file = obs_module_text("AdvSceneSwitcher.enterPath");
|
||||
std::string _text = obs_module_text("AdvSceneSwitcher.enterText");
|
||||
FileType _fileType = FileType::LOCAL;
|
||||
bool _useRegex = false;
|
||||
RegexConfig _regex;
|
||||
bool _useTime = false;
|
||||
bool _onlyMatchIfChanged = false;
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ private slots:
|
|||
void FileTypeChanged(int index);
|
||||
void PathChanged(const QString &text);
|
||||
void MatchTextChanged();
|
||||
void UseRegexChanged(int state);
|
||||
void RegexChanged(RegexConfig);
|
||||
void CheckModificationDateChanged(int state);
|
||||
void OnlyMatchIfChangedChanged(int state);
|
||||
signals:
|
||||
|
|
@ -76,7 +77,7 @@ protected:
|
|||
QComboBox *_fileType;
|
||||
FileSelection *_filePath;
|
||||
ResizingPlainTextEdit *_matchText;
|
||||
QCheckBox *_useRegex;
|
||||
RegexConfigWidget *_regex;
|
||||
QCheckBox *_checkModificationDate;
|
||||
QCheckBox *_checkFileContent;
|
||||
std::shared_ptr<MacroConditionFile> _entryData;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ bool MacroConditionFilter::Save(obs_data_t *obj)
|
|||
obs_data_set_string(obj, "filter", GetWeakSourceName(_filter).c_str());
|
||||
obs_data_set_int(obj, "condition", static_cast<int>(_condition));
|
||||
obs_data_set_string(obj, "settings", _settings.c_str());
|
||||
obs_data_set_bool(obj, "regex", _regex);
|
||||
_regex.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,12 @@ bool MacroConditionFilter::Load(obs_data_t *obj)
|
|||
_condition = static_cast<FilterCondition>(
|
||||
obs_data_get_int(obj, "condition"));
|
||||
_settings = obs_data_get_string(obj, "settings");
|
||||
_regex = obs_data_get_bool(obj, "regex");
|
||||
_regex.Load(obj);
|
||||
// TOOD: remove in future version
|
||||
if (obs_data_has_user_value(obj, "regex")) {
|
||||
_regex.CreateBackwardsCompatibleRegex(
|
||||
obs_data_get_bool(obj, "regex"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -92,18 +97,16 @@ static inline void populateConditionSelection(QComboBox *list)
|
|||
|
||||
MacroConditionFilterEdit::MacroConditionFilterEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionFilter> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
_sources(new QComboBox()),
|
||||
_filters(new QComboBox()),
|
||||
_conditions(new QComboBox()),
|
||||
_getSettings(new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.filter.getSettings"))),
|
||||
_settings(new ResizingPlainTextEdit(this)),
|
||||
_regex(new RegexConfigWidget(parent))
|
||||
{
|
||||
_sources = new QComboBox();
|
||||
_filters = new QComboBox();
|
||||
_filters->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
_conditions = new QComboBox();
|
||||
_getSettings = new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.filter.getSettings"));
|
||||
_settings = new ResizingPlainTextEdit(this);
|
||||
_regex = new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.condition.filter.regex"));
|
||||
|
||||
populateConditionSelection(_conditions);
|
||||
populateSourcesWithFilterSelection(_sources);
|
||||
|
||||
|
|
@ -117,8 +120,8 @@ MacroConditionFilterEdit::MacroConditionFilterEdit(
|
|||
SLOT(GetSettingsClicked()));
|
||||
QWidget::connect(_settings, SIGNAL(textChanged()), this,
|
||||
SLOT(SettingsChanged()));
|
||||
QWidget::connect(_regex, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(RegexChanged(int)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
|
||||
QHBoxLayout *line1Layout = new QHBoxLayout;
|
||||
QHBoxLayout *line2Layout = new QHBoxLayout;
|
||||
|
|
@ -194,7 +197,7 @@ void MacroConditionFilterEdit::GetSettingsClicked()
|
|||
}
|
||||
|
||||
QString json = formatJsonString(getSourceSettings(_entryData->_filter));
|
||||
if (_entryData->_regex) {
|
||||
if (_entryData->_regex.Enabled()) {
|
||||
json = escapeForRegex(json);
|
||||
}
|
||||
_settings->setPlainText(json);
|
||||
|
|
@ -213,14 +216,17 @@ void MacroConditionFilterEdit::SettingsChanged()
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionFilterEdit::RegexChanged(int state)
|
||||
void MacroConditionFilterEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_regex = state;
|
||||
_entryData->_regex = conf;
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionFilterEdit::SetSettingsSelectionVisible(bool visible)
|
||||
|
|
@ -244,7 +250,7 @@ void MacroConditionFilterEdit::UpdateEntryData()
|
|||
GetWeakSourceName(_entryData->_filter).c_str());
|
||||
_conditions->setCurrentIndex(static_cast<int>(_entryData->_condition));
|
||||
_settings->setPlainText(QString::fromStdString(_entryData->_settings));
|
||||
_regex->setChecked(_entryData->_regex);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
SetSettingsSelectionVisible(_entryData->_condition ==
|
||||
FilterCondition::SETTINGS);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "resizing-text-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
|
|
@ -29,7 +30,7 @@ public:
|
|||
OBSWeakSource _filter;
|
||||
FilterCondition _condition = FilterCondition::ENABLED;
|
||||
std::string _settings = "";
|
||||
bool _regex = false;
|
||||
RegexConfig _regex;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
|
|
@ -58,7 +59,7 @@ private slots:
|
|||
void ConditionChanged(int cond);
|
||||
void GetSettingsClicked();
|
||||
void SettingsChanged();
|
||||
void RegexChanged(int);
|
||||
void RegexChanged(RegexConfig);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ protected:
|
|||
QComboBox *_conditions;
|
||||
QPushButton *_getSettings;
|
||||
ResizingPlainTextEdit *_settings;
|
||||
QCheckBox *_regex;
|
||||
RegexConfigWidget *_regex;
|
||||
|
||||
std::shared_ptr<MacroConditionFilter> _entryData;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ bool MacroConditionSceneTransform::Save(obs_data_t *obj)
|
|||
_scene.Save(obj);
|
||||
_source.Save(obj);
|
||||
obs_data_set_string(obj, "settings", _settings.c_str());
|
||||
obs_data_set_bool(obj, "regex", _regex);
|
||||
_regex.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,12 @@ bool MacroConditionSceneTransform::Load(obs_data_t *obj)
|
|||
_scene.Load(obj);
|
||||
_source.Load(obj);
|
||||
_settings = obs_data_get_string(obj, "settings");
|
||||
_regex = obs_data_get_bool(obj, "regex");
|
||||
_regex.Load(obj);
|
||||
// TOOD: remove in future version
|
||||
if (obs_data_has_user_value(obj, "regex")) {
|
||||
_regex.CreateBackwardsCompatibleRegex(
|
||||
obs_data_get_bool(obj, "regex"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -66,17 +71,16 @@ std::string MacroConditionSceneTransform::GetShortDesc()
|
|||
MacroConditionSceneTransformEdit::MacroConditionSceneTransformEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroConditionSceneTransform> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
_scenes(new SceneSelectionWidget(window(), false, false, true)),
|
||||
_sources(new SceneItemSelectionWidget(
|
||||
parent, true,
|
||||
SceneItemSelectionWidget::AllSelectionType::ANY)),
|
||||
_getSettings(new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.sceneTransform.getTransform"))),
|
||||
_settings(new ResizingPlainTextEdit(this)),
|
||||
_regex(new RegexConfigWidget(parent))
|
||||
{
|
||||
_scenes = new SceneSelectionWidget(window(), false, false, true);
|
||||
_sources = new SceneItemSelectionWidget(
|
||||
parent, true, SceneItemSelectionWidget::AllSelectionType::ANY);
|
||||
_getSettings = new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.sceneTransform.getTransform"));
|
||||
_settings = new ResizingPlainTextEdit(this);
|
||||
_regex = new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.sceneTransform.regex"));
|
||||
|
||||
QWidget::connect(_scenes, SIGNAL(SceneChanged(const SceneSelection &)),
|
||||
this, SLOT(SceneChanged(const SceneSelection &)));
|
||||
QWidget::connect(_scenes, SIGNAL(SceneChanged(const SceneSelection &)),
|
||||
|
|
@ -88,8 +92,8 @@ MacroConditionSceneTransformEdit::MacroConditionSceneTransformEdit(
|
|||
SLOT(GetSettingsClicked()));
|
||||
QWidget::connect(_settings, SIGNAL(textChanged()), this,
|
||||
SLOT(SettingsChanged()));
|
||||
QWidget::connect(_regex, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(RegexChanged(int)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{scenes}}", _scenes}, {"{{sources}}", _sources},
|
||||
|
|
@ -132,7 +136,7 @@ void MacroConditionSceneTransformEdit::UpdateEntryData()
|
|||
|
||||
_scenes->SetScene(_entryData->_scene);
|
||||
_sources->SetSceneItem(_entryData->_source);
|
||||
_regex->setChecked(_entryData->_regex);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
_settings->setPlainText(QString::fromStdString(_entryData->_settings));
|
||||
|
||||
adjustSize();
|
||||
|
|
@ -175,7 +179,7 @@ void MacroConditionSceneTransformEdit::GetSettingsClicked()
|
|||
}
|
||||
|
||||
auto settings = formatJsonString(getSceneItemTransform(items[0]));
|
||||
if (_entryData->_regex) {
|
||||
if (_entryData->_regex.Enabled()) {
|
||||
settings = escapeForRegex(settings);
|
||||
}
|
||||
_settings->setPlainText(settings);
|
||||
|
|
@ -198,12 +202,15 @@ void MacroConditionSceneTransformEdit::SettingsChanged()
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionSceneTransformEdit::RegexChanged(int state)
|
||||
void MacroConditionSceneTransformEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_regex = state;
|
||||
_entryData->_regex = conf;
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "scene-selection.hpp"
|
||||
#include "scene-item-selection.hpp"
|
||||
#include "resizing-text-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
|
|
@ -22,7 +23,7 @@ public:
|
|||
|
||||
SceneSelection _scene;
|
||||
SceneItemSelection _source;
|
||||
bool _regex = false;
|
||||
RegexConfig _regex;
|
||||
std::string _settings = "";
|
||||
|
||||
private:
|
||||
|
|
@ -53,7 +54,7 @@ private slots:
|
|||
void SourceChanged(const SceneItemSelection &);
|
||||
void GetSettingsClicked();
|
||||
void SettingsChanged();
|
||||
void RegexChanged(int);
|
||||
void RegexChanged(RegexConfig);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ protected:
|
|||
SceneItemSelectionWidget *_sources;
|
||||
QPushButton *_getSettings;
|
||||
ResizingPlainTextEdit *_settings;
|
||||
QCheckBox *_regex;
|
||||
RegexConfigWidget *_regex;
|
||||
|
||||
std::shared_ptr<MacroConditionSceneTransform> _entryData;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#include "utility.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
|
||||
#include <regex>
|
||||
|
||||
const std::string MacroConditionSource::id = "source";
|
||||
|
||||
bool MacroConditionSource::_registered = MacroConditionFactory::Register(
|
||||
|
|
@ -55,7 +53,7 @@ bool MacroConditionSource::Save(obs_data_t *obj)
|
|||
obs_data_set_string(obj, "source", GetWeakSourceName(_source).c_str());
|
||||
obs_data_set_int(obj, "condition", static_cast<int>(_condition));
|
||||
obs_data_set_string(obj, "settings", _settings.c_str());
|
||||
obs_data_set_bool(obj, "regex", _regex);
|
||||
_regex.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +65,12 @@ bool MacroConditionSource::Load(obs_data_t *obj)
|
|||
_condition = static_cast<SourceCondition>(
|
||||
obs_data_get_int(obj, "condition"));
|
||||
_settings = obs_data_get_string(obj, "settings");
|
||||
_regex = obs_data_get_bool(obj, "regex");
|
||||
_regex.Load(obj);
|
||||
// TOOD: remove in future version
|
||||
if (obs_data_has_user_value(obj, "regex")) {
|
||||
_regex.CreateBackwardsCompatibleRegex(
|
||||
obs_data_get_bool(obj, "regex"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -88,16 +91,14 @@ static inline void populateConditionSelection(QComboBox *list)
|
|||
|
||||
MacroConditionSourceEdit::MacroConditionSourceEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionSource> entryData)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
_sources(new QComboBox()),
|
||||
_conditions(new QComboBox()),
|
||||
_getSettings(new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.filter.getSettings"))),
|
||||
_settings(new ResizingPlainTextEdit(this)),
|
||||
_regex(new RegexConfigWidget(parent))
|
||||
{
|
||||
_sources = new QComboBox();
|
||||
_conditions = new QComboBox();
|
||||
_getSettings = new QPushButton(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.source.getSettings"));
|
||||
_settings = new ResizingPlainTextEdit(this);
|
||||
_regex = new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.condition.source.regex"));
|
||||
|
||||
populateConditionSelection(_conditions);
|
||||
populateSourceSelection(_sources);
|
||||
|
||||
|
|
@ -109,8 +110,8 @@ MacroConditionSourceEdit::MacroConditionSourceEdit(
|
|||
SLOT(GetSettingsClicked()));
|
||||
QWidget::connect(_settings, SIGNAL(textChanged()), this,
|
||||
SLOT(SettingsChanged()));
|
||||
QWidget::connect(_regex, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(RegexChanged(int)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
QHBoxLayout *line1Layout = new QHBoxLayout;
|
||||
|
|
@ -171,7 +172,7 @@ void MacroConditionSourceEdit::GetSettingsClicked()
|
|||
}
|
||||
|
||||
QString json = formatJsonString(getSourceSettings(_entryData->_source));
|
||||
if (_entryData->_regex) {
|
||||
if (_entryData->_regex.Enabled()) {
|
||||
json = escapeForRegex(json);
|
||||
}
|
||||
_settings->setPlainText(json);
|
||||
|
|
@ -190,14 +191,17 @@ void MacroConditionSourceEdit::SettingsChanged()
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionSourceEdit::RegexChanged(int state)
|
||||
void MacroConditionSourceEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_regex = state;
|
||||
_entryData->_regex = conf;
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionSourceEdit::SetSettingsSelectionVisible(bool visible)
|
||||
|
|
@ -218,7 +222,7 @@ void MacroConditionSourceEdit::UpdateEntryData()
|
|||
GetWeakSourceName(_entryData->_source).c_str());
|
||||
_conditions->setCurrentIndex(static_cast<int>(_entryData->_condition));
|
||||
_settings->setPlainText(QString::fromStdString(_entryData->_settings));
|
||||
_regex->setChecked(_entryData->_regex);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
SetSettingsSelectionVisible(_entryData->_condition ==
|
||||
SourceCondition::SETTINGS);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "resizing-text-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
|
|
@ -28,7 +29,7 @@ public:
|
|||
OBSWeakSource _source = nullptr;
|
||||
SourceCondition _condition = SourceCondition::ACTIVE;
|
||||
std::string _settings = "";
|
||||
bool _regex = false;
|
||||
RegexConfig _regex;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
|
|
@ -56,7 +57,7 @@ private slots:
|
|||
void ConditionChanged(int cond);
|
||||
void GetSettingsClicked();
|
||||
void SettingsChanged();
|
||||
void RegexChanged(int);
|
||||
void RegexChanged(RegexConfig);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ protected:
|
|||
QComboBox *_conditions;
|
||||
QPushButton *_getSettings;
|
||||
ResizingPlainTextEdit *_settings;
|
||||
QCheckBox *_regex;
|
||||
RegexConfigWidget *_regex;
|
||||
|
||||
std::shared_ptr<MacroConditionSource> _entryData;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,21 +12,22 @@ bool MacroConditionWebsocket::_registered = MacroConditionFactory::Register(
|
|||
{MacroConditionWebsocket::Create, MacroConditionWebsocketEdit::Create,
|
||||
"AdvSceneSwitcher.condition.websocket"});
|
||||
|
||||
static bool matchRegex(const std::string &msg, const std::string &expr)
|
||||
static bool matchRegex(const RegexConfig &conf, const std::string &msg,
|
||||
const std::string &expr)
|
||||
{
|
||||
try {
|
||||
std::regex regExpr(expr);
|
||||
return std::regex_match(msg, regExpr);
|
||||
} catch (const std::regex_error &) {
|
||||
auto regex = conf.GetRegularExpression(expr);
|
||||
if (!regex.isValid()) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
auto match = regex.match(QString::fromStdString(msg));
|
||||
return match.hasMatch();
|
||||
}
|
||||
|
||||
bool MacroConditionWebsocket::CheckCondition()
|
||||
{
|
||||
for (const auto &msg : switcher->websocketMessages) {
|
||||
if (_useRegex) {
|
||||
if (matchRegex(msg, _message)) {
|
||||
if (_regex.Enabled()) {
|
||||
if (matchRegex(_regex, msg, _message)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -42,7 +43,7 @@ bool MacroConditionWebsocket::Save(obs_data_t *obj)
|
|||
{
|
||||
MacroCondition::Save(obj);
|
||||
obs_data_set_string(obj, "message", _message.c_str());
|
||||
obs_data_set_bool(obj, "useRegex", _useRegex);
|
||||
_regex.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +51,12 @@ bool MacroConditionWebsocket::Load(obs_data_t *obj)
|
|||
{
|
||||
MacroCondition::Load(obj);
|
||||
_message = obs_data_get_string(obj, "message");
|
||||
_useRegex = obs_data_get_bool(obj, "useRegex");
|
||||
_regex.Load(obj);
|
||||
// TOOD: remove in future version
|
||||
if (obs_data_has_user_value(obj, "useRegex")) {
|
||||
_regex.CreateBackwardsCompatibleRegex(
|
||||
obs_data_get_bool(obj, "useRegex"), false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -63,20 +69,19 @@ MacroConditionWebsocketEdit::MacroConditionWebsocketEdit(
|
|||
QWidget *parent, std::shared_ptr<MacroConditionWebsocket> entryData)
|
||||
: QWidget(parent),
|
||||
_message(new ResizingPlainTextEdit(this)),
|
||||
_useRegex(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.condition.websocket.useRegex")))
|
||||
_regex(new RegexConfigWidget(parent))
|
||||
{
|
||||
QWidget::connect(_message, SIGNAL(textChanged()), this,
|
||||
SLOT(MessageChanged()));
|
||||
QWidget::connect(_useRegex, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(UseRegexChanged(int)));
|
||||
QWidget::connect(_regex, SIGNAL(RegexConfigChanged(RegexConfig)), this,
|
||||
SLOT(RegexChanged(RegexConfig)));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
|
||||
mainLayout->addWidget(new QLabel(
|
||||
obs_module_text("AdvSceneSwitcher.condition.websocket.entry")));
|
||||
mainLayout->addWidget(_message);
|
||||
mainLayout->addWidget(_useRegex);
|
||||
mainLayout->addWidget(_regex);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
|
|
@ -91,7 +96,7 @@ void MacroConditionWebsocketEdit::UpdateEntryData()
|
|||
}
|
||||
|
||||
_message->setPlainText(QString::fromStdString(_entryData->_message));
|
||||
_useRegex->setChecked(_entryData->_useRegex);
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
|
|
@ -110,12 +115,15 @@ void MacroConditionWebsocketEdit::MessageChanged()
|
|||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroConditionWebsocketEdit::UseRegexChanged(int state)
|
||||
void MacroConditionWebsocketEdit::RegexChanged(RegexConfig conf)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_useRegex = state;
|
||||
_entryData->_regex = conf;
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "resizing-text-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ public:
|
|||
}
|
||||
|
||||
std::string _message = obs_module_text("AdvSceneSwitcher.enterText");
|
||||
bool _useRegex = false;
|
||||
RegexConfig _regex;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
|
|
@ -44,13 +45,13 @@ public:
|
|||
|
||||
private slots:
|
||||
void MessageChanged();
|
||||
void UseRegexChanged(int state);
|
||||
void RegexChanged(RegexConfig);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
ResizingPlainTextEdit *_message;
|
||||
QCheckBox *_useRegex;
|
||||
RegexConfigWidget *_regex;
|
||||
std::shared_ptr<MacroConditionWebsocket> _entryData;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "utility.hpp"
|
||||
#include "platform-funcs.hpp"
|
||||
#include "scene-selection.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QLabel>
|
||||
|
|
@ -333,9 +334,8 @@ std::vector<obs_scene_item *> getSceneItemsWithName(obs_scene_t *scene,
|
|||
|
||||
// Match json1 with pattern json2
|
||||
bool matchJson(const std::string &json1, const std::string &json2,
|
||||
bool useRegex)
|
||||
const RegexConfig ®ex)
|
||||
{
|
||||
bool ret = false;
|
||||
auto j1 = formatJsonString(json1).toStdString();
|
||||
auto j2 = formatJsonString(json2).toStdString();
|
||||
|
||||
|
|
@ -346,24 +346,23 @@ bool matchJson(const std::string &json1, const std::string &json2,
|
|||
j2 = json2;
|
||||
}
|
||||
|
||||
if (useRegex) {
|
||||
try {
|
||||
std::regex expr(j2);
|
||||
ret = std::regex_match(
|
||||
j1, expr, std::regex_constants::match_default);
|
||||
} catch (const std::regex_error &) {
|
||||
if (regex.Enabled()) {
|
||||
auto expr = regex.GetRegularExpression(j2);
|
||||
if (!expr.isValid()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ret = j1 == j2;
|
||||
auto match = expr.match(QString::fromStdString(j1));
|
||||
return match.hasMatch();
|
||||
}
|
||||
return ret;
|
||||
return j1 == j2;
|
||||
}
|
||||
|
||||
bool compareSourceSettings(const OBSWeakSource &source,
|
||||
const std::string &settings, bool useRegex)
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex)
|
||||
{
|
||||
std::string currentSettings = getSourceSettings(source);
|
||||
return matchJson(currentSettings, settings, useRegex);
|
||||
return matchJson(currentSettings, settings, regex);
|
||||
}
|
||||
|
||||
std::string getDataFilePath(const std::string &file)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "scene-group.hpp"
|
||||
|
||||
class SceneSelection;
|
||||
class RegexConfig;
|
||||
|
||||
bool WeakSourceValid(obs_weak_source_t *ws);
|
||||
std::string GetWeakSourceName(obs_weak_source_t *weak_source);
|
||||
|
|
@ -26,12 +27,13 @@ bool compareIgnoringLineEnding(QString &s1, QString &s2);
|
|||
std::string getSourceSettings(OBSWeakSource ws);
|
||||
void setSourceSettings(obs_source_t *s, const std::string &settings);
|
||||
bool compareSourceSettings(const OBSWeakSource &source,
|
||||
const std::string &settings, bool regex);
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex);
|
||||
std::vector<obs_scene_item *> getSceneItemsWithName(obs_scene_t *scene,
|
||||
std::string &name);
|
||||
std::string getDataFilePath(const std::string &file);
|
||||
bool matchJson(const std::string &json1, const std::string &json2,
|
||||
bool useRegex);
|
||||
const RegexConfig ®ex);
|
||||
QString formatJsonString(std::string);
|
||||
QString formatJsonString(QString);
|
||||
QString escapeForRegex(QString &s);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user