File: macro-action-profile.cpp

package info (click to toggle)
obs-advanced-scene-switcher 1.32.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,492 kB
  • sloc: xml: 297,593; cpp: 147,875; python: 387; sh: 280; ansic: 170; makefile: 33
file content (90 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "macro-action-profile.hpp"
#include "layout-helpers.hpp"

#include <obs-frontend-api.h>

namespace advss {

const std::string MacroActionProfile::id = "profile";

bool MacroActionProfile::_registered = MacroActionFactory::Register(
	MacroActionProfile::id,
	{MacroActionProfile::Create, MacroActionProfileEdit::Create,
	 "AdvSceneSwitcher.action.profile"});

bool MacroActionProfile::PerformAction()
{
	obs_frontend_set_current_profile(_profile.c_str());
	return true;
}

void MacroActionProfile::LogAction() const
{
	ablog(LOG_INFO, "set profile type to \"%s\"", _profile.c_str());
}

bool MacroActionProfile::Save(obs_data_t *obj) const
{
	MacroAction::Save(obj);
	obs_data_set_string(obj, "profile", _profile.c_str());
	return true;
}

bool MacroActionProfile::Load(obs_data_t *obj)
{
	MacroAction::Load(obj);
	_profile = obs_data_get_string(obj, "profile");
	return true;
}

std::string MacroActionProfile::GetShortDesc() const
{
	return _profile;
}

std::shared_ptr<MacroAction> MacroActionProfile::Create(Macro *m)
{
	return std::make_shared<MacroActionProfile>(m);
}

std::shared_ptr<MacroAction> MacroActionProfile::Copy() const
{
	return std::make_shared<MacroActionProfile>(*this);
}

MacroActionProfileEdit::MacroActionProfileEdit(
	QWidget *parent, std::shared_ptr<MacroActionProfile> entryData)
	: QWidget(parent),
	  _profiles(new ProfileSelectionWidget(this))
{
	QWidget::connect(_profiles, SIGNAL(currentTextChanged(const QString &)),
			 this, SLOT(ProfileChanged(const QString &)));

	auto layout = new QHBoxLayout;
	PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.profile.entry"),
		     layout, {{"{{profiles}}", _profiles}});
	setLayout(layout);

	_entryData = entryData;
	UpdateEntryData();
	_loading = false;
}

void MacroActionProfileEdit::UpdateEntryData()
{
	if (!_entryData) {
		return;
	}

	_profiles->setCurrentText(QString::fromStdString(_entryData->_profile));
}

void MacroActionProfileEdit::ProfileChanged(const QString &text)
{
	GUARD_LOADING_AND_LOCK();
	_entryData->_profile = text.toStdString();
	emit HeaderInfoChanged(
		QString::fromStdString(_entryData->GetShortDesc()));
}

} // namespace advss