Skip to content

Commit a901f59

Browse files
committed
Add option to interact with source settings buttons
1 parent ea826f1 commit a901f59

File tree

6 files changed

+130
-7
lines changed

6 files changed

+130
-7
lines changed

data/locale/en-US.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ AdvSceneSwitcher.action.source.type.enable="Enable"
442442
AdvSceneSwitcher.action.source.type.disable="Disable"
443443
AdvSceneSwitcher.action.source.type.settings="Set settings"
444444
AdvSceneSwitcher.action.source.type.refreshSettings="Refresh source settings"
445+
AdvSceneSwitcher.action.source.type.pressSettingsButton="Press settings button"
445446
AdvSceneSwitcher.action.source.type.refreshSettings.tooltip="Can be used to refresh browser, media, etc. sources"
446-
AdvSceneSwitcher.action.source.entry="{{actions}} {{sources}}"
447+
AdvSceneSwitcher.action.source.noSettingsButtons="No buttons found!"
448+
AdvSceneSwitcher.action.source.entry="{{actions}}{{sources}}{{settingsButtons}}"
447449
AdvSceneSwitcher.action.source.warning="Warning: Enabling and disabling sources globally cannot be controlled by the OBS UI"
448450
AdvSceneSwitcher.action.source.getSettings="Get current settings"
449451
AdvSceneSwitcher.action.media="Media"

data/locale/es-ES.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ AdvSceneSwitcher.action.source="Fuente"
382382
AdvSceneSwitcher.action.source.type.enable="Habilitar"
383383
AdvSceneSwitcher.action.source.type.disable="Deshabilitar"
384384
AdvSceneSwitcher.action.source.type.settings="Establecer configuración"
385-
AdvSceneSwitcher.action.source.entry="{{actions}} {{sources}}"
385+
AdvSceneSwitcher.action.source.entry="{{actions}}{{sources}}{{settingsButtons}}"
386386
AdvSceneSwitcher.action.source.warning="Advertencia: la IU de OBS no puede controlar la habilitación y deshabilitación global de fuentes"
387387
AdvSceneSwitcher.action.source.getSettings="Obtener la configuración actual"
388388
AdvSceneSwitcher.action.media="Medios"

data/locale/tr-TR.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ AdvSceneSwitcher.action.source="Kaynak"
312312
AdvSceneSwitcher.action.source.type.enable="Etkin"
313313
AdvSceneSwitcher.action.source.type.disable="Etkisiz"
314314
AdvSceneSwitcher.action.source.type.settings="Ayarları yap"
315-
AdvSceneSwitcher.action.source.entry="{{actions}} {{sources}}"
315+
AdvSceneSwitcher.action.source.entry="{{actions}}{{sources}}{{settingsButtons}}"
316316
AdvSceneSwitcher.action.source.warning="Uyarı: Kaynakların global olarak etkinleştirilmesi ve devre dışı bırakılması, OBS UI tarafından kontrol edilemez"
317317
AdvSceneSwitcher.action.source.getSettings="Mevcut Ayarları yap"
318318
AdvSceneSwitcher.action.media="Medya"

data/locale/zh-CN.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ AdvSceneSwitcher.action.source.type.disable="停用"
428428
AdvSceneSwitcher.action.source.type.settings="配置设置"
429429
AdvSceneSwitcher.action.source.type.refreshSettings="刷新源设置"
430430
AdvSceneSwitcher.action.source.type.refreshSettings.tooltip="可用于刷新浏览器、媒体等源"
431-
AdvSceneSwitcher.action.source.entry="{{actions}} {{sources}}"
431+
AdvSceneSwitcher.action.source.entry="{{actions}}{{sources}}{{settingsButtons}}"
432432
AdvSceneSwitcher.action.source.warning="警告:OBS UI无法控制全局启用和禁用源,注意,通过这个设置禁用,我测试,你必须通过这个在启用才行,不然点击小眼睛你无法显示!"
433433
AdvSceneSwitcher.action.source.getSettings="获取当前设置"
434434
AdvSceneSwitcher.action.media="媒体"

src/macro-core/macro-action-source.cpp

+111-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "advanced-scene-switcher.hpp"
33
#include "utility.hpp"
44

5+
Q_DECLARE_METATYPE(SourceSettingButton);
6+
57
const std::string MacroActionSource::id = "source";
68

79
bool MacroActionSource::_registered = MacroActionFactory::Register(
@@ -16,9 +18,42 @@ const static std::map<SourceAction, std::string> actionTypes = {
1618
"AdvSceneSwitcher.action.source.type.settings"},
1719
{SourceAction::REFRESH_SETTINGS,
1820
"AdvSceneSwitcher.action.source.type.refreshSettings"},
21+
{SourceAction::SETTINGS_BUTTON,
22+
"AdvSceneSwitcher.action.source.type.pressSettingsButton"},
1923
};
2024

21-
void refreshSourceSettings(obs_source_t *s)
25+
static std::vector<SourceSettingButton> getSourceButtons(OBSWeakSource source)
26+
{
27+
auto s = obs_weak_source_get_source(source);
28+
std::vector<SourceSettingButton> buttons;
29+
obs_properties_t *sourceProperties = obs_source_properties(s);
30+
auto it = obs_properties_first(sourceProperties);
31+
do {
32+
if (!it || obs_property_get_type(it) != OBS_PROPERTY_BUTTON) {
33+
continue;
34+
}
35+
SourceSettingButton button = {obs_property_name(it),
36+
obs_property_description(it)};
37+
buttons.emplace_back(button);
38+
} while (obs_property_next(&it));
39+
obs_source_release(s);
40+
return buttons;
41+
}
42+
43+
static void pressSourceButton(const SourceSettingButton &button,
44+
obs_source_t *source)
45+
{
46+
obs_properties_t *sourceProperties = obs_source_properties(source);
47+
obs_property_t *property =
48+
obs_properties_get(sourceProperties, button.id.c_str());
49+
if (!obs_property_button_clicked(property, source)) {
50+
blog(LOG_WARNING, "Failed to press settings button '%s' for %s",
51+
button.id.c_str(), obs_source_get_name(source));
52+
}
53+
obs_properties_destroy(sourceProperties);
54+
}
55+
56+
static void refreshSourceSettings(obs_source_t *s)
2257
{
2358
if (!s) {
2459
return;
@@ -55,6 +90,9 @@ bool MacroActionSource::PerformAction()
5590
case SourceAction::REFRESH_SETTINGS:
5691
refreshSourceSettings(s);
5792
break;
93+
case SourceAction::SETTINGS_BUTTON:
94+
pressSourceButton(_button, s);
95+
break;
5896
default:
5997
break;
6098
}
@@ -80,6 +118,7 @@ bool MacroActionSource::Save(obs_data_t *obj)
80118
obs_data_set_string(obj, "source", GetWeakSourceName(_source).c_str());
81119
obs_data_set_int(obj, "action", static_cast<int>(_action));
82120
obs_data_set_string(obj, "settings", _settings.c_str());
121+
_button.Save(obj);
83122
return true;
84123
}
85124

@@ -90,6 +129,7 @@ bool MacroActionSource::Load(obs_data_t *obj)
90129
_source = GetWeakSourceByName(sourceName);
91130
_action = static_cast<SourceAction>(obs_data_get_int(obj, "action"));
92131
_settings = obs_data_get_string(obj, "settings");
132+
_button.Load(obj);
93133
return true;
94134
}
95135

@@ -115,12 +155,30 @@ static inline void populateActionSelection(QComboBox *list)
115155
}
116156
}
117157

158+
static inline void populateSourceButtonSelection(QComboBox *list,
159+
OBSWeakSource source)
160+
{
161+
list->clear();
162+
auto buttons = getSourceButtons(source);
163+
if (buttons.empty()) {
164+
list->addItem(obs_module_text(
165+
"AdvSceneSwitcher.action.source.noSettingsButtons"));
166+
}
167+
168+
for (const auto &button : buttons) {
169+
QVariant value;
170+
value.setValue(button);
171+
list->addItem(QString::fromStdString(button.ToString()), value);
172+
}
173+
}
174+
118175
MacroActionSourceEdit::MacroActionSourceEdit(
119176
QWidget *parent, std::shared_ptr<MacroActionSource> entryData)
120177
: QWidget(parent)
121178
{
122179
_sources = new QComboBox();
123180
_actions = new QComboBox();
181+
_settingsButtons = new QComboBox();
124182
_getSettings = new QPushButton(
125183
obs_module_text("AdvSceneSwitcher.action.source.getSettings"));
126184
_settings = new ResizingPlainTextEdit(this);
@@ -132,6 +190,8 @@ MacroActionSourceEdit::MacroActionSourceEdit(
132190

133191
QWidget::connect(_actions, SIGNAL(currentIndexChanged(int)), this,
134192
SLOT(ActionChanged(int)));
193+
QWidget::connect(_settingsButtons, SIGNAL(currentIndexChanged(int)),
194+
this, SLOT(ButtonChanged(int)));
135195
QWidget::connect(_sources, SIGNAL(currentTextChanged(const QString &)),
136196
this, SLOT(SourceChanged(const QString &)));
137197
QWidget::connect(_getSettings, SIGNAL(clicked()), this,
@@ -147,6 +207,7 @@ MacroActionSourceEdit::MacroActionSourceEdit(
147207
{"{{actions}}", _actions},
148208
{"{{settings}}", _settings},
149209
{"{{getSettings}}", _getSettings},
210+
{"{{settingsButtons}}", _settingsButtons},
150211
};
151212
placeWidgets(obs_module_text("AdvSceneSwitcher.action.source.entry"),
152213
entryLayout, widgetPlaceholders);
@@ -169,10 +230,14 @@ void MacroActionSourceEdit::UpdateEntryData()
169230
return;
170231
}
171232

233+
populateSourceButtonSelection(_settingsButtons, _entryData->_source);
234+
172235
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
173236
_sources->setCurrentText(
174237
GetWeakSourceName(_entryData->_source).c_str());
175238
_settings->setPlainText(QString::fromStdString(_entryData->_settings));
239+
_settingsButtons->setCurrentText(
240+
QString::fromStdString(_entryData->_button.ToString()));
176241
SetWidgetVisibility();
177242

178243
adjustSize();
@@ -185,8 +250,11 @@ void MacroActionSourceEdit::SourceChanged(const QString &text)
185250
return;
186251
}
187252

188-
std::lock_guard<std::mutex> lock(switcher->m);
189-
_entryData->_source = GetWeakSourceByQString(text);
253+
{
254+
std::lock_guard<std::mutex> lock(switcher->m);
255+
_entryData->_source = GetWeakSourceByQString(text);
256+
}
257+
populateSourceButtonSelection(_settingsButtons, _entryData->_source);
190258
emit HeaderInfoChanged(
191259
QString::fromStdString(_entryData->GetShortDesc()));
192260
}
@@ -202,6 +270,17 @@ void MacroActionSourceEdit::ActionChanged(int value)
202270
SetWidgetVisibility();
203271
}
204272

273+
void MacroActionSourceEdit::ButtonChanged(int idx)
274+
{
275+
if (_loading || !_entryData) {
276+
return;
277+
}
278+
279+
std::lock_guard<std::mutex> lock(switcher->m);
280+
_entryData->_button = qvariant_cast<SourceSettingButton>(
281+
_settingsButtons->itemData(idx));
282+
}
283+
205284
void MacroActionSourceEdit::GetSettingsClicked()
206285
{
207286
if (_loading || !_entryData || !_entryData->_source) {
@@ -233,5 +312,34 @@ void MacroActionSourceEdit::SetWidgetVisibility()
233312
_settings->setVisible(showSettings);
234313
_getSettings->setVisible(showSettings);
235314
_warning->setVisible(showWarning);
315+
_settingsButtons->setVisible(_entryData->_action ==
316+
SourceAction::SETTINGS_BUTTON);
236317
adjustSize();
237318
}
319+
320+
bool SourceSettingButton::Save(obs_data_t *obj) const
321+
{
322+
auto data = obs_data_create();
323+
obs_data_set_string(data, "id", id.c_str());
324+
obs_data_set_string(data, "description", description.c_str());
325+
obs_data_set_obj(obj, "sourceSettingButton", data);
326+
obs_data_release(data);
327+
return true;
328+
}
329+
330+
bool SourceSettingButton::Load(obs_data_t *obj)
331+
{
332+
auto data = obs_data_get_obj(obj, "sourceSettingButton");
333+
id = obs_data_get_string(data, "id");
334+
description = obs_data_get_string(data, "description");
335+
obs_data_release(data);
336+
return true;
337+
}
338+
339+
std::string SourceSettingButton::ToString() const
340+
{
341+
if (id.empty()) {
342+
return "";
343+
}
344+
return "[" + id + "] " + description;
345+
}

src/macro-core/macro-action-source.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ enum class SourceAction {
1212
DISABLE,
1313
SETTINGS,
1414
REFRESH_SETTINGS,
15+
SETTINGS_BUTTON,
16+
};
17+
18+
struct SourceSettingButton {
19+
bool Save(obs_data_t *obj) const;
20+
bool Load(obs_data_t *obj);
21+
std::string ToString() const;
22+
23+
std::string id = "";
24+
std::string description = "";
1525
};
1626

1727
class MacroActionSource : public MacroAction {
@@ -30,6 +40,7 @@ class MacroActionSource : public MacroAction {
3040

3141
OBSWeakSource _source;
3242
std::string _settings = "";
43+
SourceSettingButton _button;
3344
SourceAction _action = SourceAction::ENABLE;
3445

3546
private:
@@ -56,6 +67,7 @@ class MacroActionSourceEdit : public QWidget {
5667
private slots:
5768
void SourceChanged(const QString &text);
5869
void ActionChanged(int value);
70+
void ButtonChanged(int idx);
5971
void GetSettingsClicked();
6072
void SettingsChanged();
6173
signals:
@@ -64,6 +76,7 @@ private slots:
6476
protected:
6577
QComboBox *_sources;
6678
QComboBox *_actions;
79+
QComboBox *_settingsButtons;
6780
QPushButton *_getSettings;
6881
ResizingPlainTextEdit *_settings;
6982
QLabel *_warning;

0 commit comments

Comments
 (0)