mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-24 14:58:19 -05:00
Add action to switch profile
This commit is contained in:
parent
d69aba8ab7
commit
e0cca2a0d4
|
|
@ -197,6 +197,7 @@ set(advanced-scene-switcher_HEADERS
|
|||
src/headers/macro-action-media.hpp
|
||||
src/headers/macro-action-plugin-state.hpp
|
||||
src/headers/macro-action-preview-scene.hpp
|
||||
src/headers/macro-action-profile.hpp
|
||||
src/headers/macro-action-random.hpp
|
||||
src/headers/macro-action-recording.hpp
|
||||
src/headers/macro-action-replay-buffer.hpp
|
||||
|
|
@ -293,6 +294,7 @@ set(advanced-scene-switcher_SOURCES
|
|||
src/macro-action-media.cpp
|
||||
src/macro-action-plugin-state.cpp
|
||||
src/macro-action-preview-scene.cpp
|
||||
src/macro-action-profile.cpp
|
||||
src/macro-action-random.cpp
|
||||
src/macro-action-recording.cpp
|
||||
src/macro-action-replay-buffer.cpp
|
||||
|
|
|
|||
|
|
@ -380,6 +380,8 @@ AdvSceneSwitcher.action.systray.entry="Show notification: {{message}}"
|
|||
AdvSceneSwitcher.action.screenshot="Screenshot"
|
||||
AdvSceneSwitcher.action.screenshot.mainOutput="OBS's main output"
|
||||
AdvSceneSwitcher.action.screenshot.entry="Screenshot {{sources}}"
|
||||
AdvSceneSwitcher.action.profile="Profile"
|
||||
AdvSceneSwitcher.action.profile.entry="Switch active profile to {{profiles}}"
|
||||
|
||||
; Transition Tab
|
||||
AdvSceneSwitcher.transitionTab.title="Transition"
|
||||
|
|
@ -649,6 +651,7 @@ AdvSceneSwitcher.selectProcess="--select process--"
|
|||
AdvSceneSwitcher.selectFilter="--select filter--"
|
||||
AdvSceneSwitcher.selectMacro="--select macro--"
|
||||
AdvSceneSwitcher.selectItem="--select item--"
|
||||
AdvSceneSwitcher.selectProfile="--select profile--"
|
||||
AdvSceneSwitcher.enterPath="--enter path--"
|
||||
AdvSceneSwitcher.enterText="--enter text--"
|
||||
AdvSceneSwitcher.invaildEntriesWillNotBeSaved="invalid entries will not be saved"
|
||||
|
|
|
|||
51
src/headers/macro-action-profile.hpp
Normal file
51
src/headers/macro-action-profile.hpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
|
||||
class MacroActionProfile : public MacroAction {
|
||||
public:
|
||||
bool PerformAction();
|
||||
void LogAction();
|
||||
bool Save(obs_data_t *obj);
|
||||
bool Load(obs_data_t *obj);
|
||||
std::string GetShortDesc();
|
||||
std::string GetId() { return id; };
|
||||
static std::shared_ptr<MacroAction> Create()
|
||||
{
|
||||
return std::make_shared<MacroActionProfile>();
|
||||
}
|
||||
|
||||
std::string _profile;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroActionProfileEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroActionProfileEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroActionProfile> entryData = nullptr);
|
||||
void UpdateEntryData();
|
||||
static QWidget *Create(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
return new MacroActionProfileEdit(
|
||||
parent,
|
||||
std::dynamic_pointer_cast<MacroActionProfile>(action));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void ProfileChanged(const QString &text);
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
QComboBox *_profiles;
|
||||
std::shared_ptr<MacroActionProfile> _entryData;
|
||||
|
||||
private:
|
||||
bool _loading = true;
|
||||
};
|
||||
99
src/macro-action-profile.cpp
Normal file
99
src/macro-action-profile.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#include "headers/macro-action-profile.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
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()
|
||||
{
|
||||
vblog(LOG_INFO, "set profile type to \"%s\"", _profile.c_str());
|
||||
}
|
||||
|
||||
bool MacroActionProfile::Save(obs_data_t *obj)
|
||||
{
|
||||
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()
|
||||
{
|
||||
return _profile;
|
||||
}
|
||||
|
||||
void populateProfileSelection(QComboBox *box)
|
||||
{
|
||||
auto profiles = obs_frontend_get_profiles();
|
||||
char **temp = profiles;
|
||||
while (*temp) {
|
||||
const char *name = *temp;
|
||||
box->addItem(name);
|
||||
temp++;
|
||||
}
|
||||
bfree(profiles);
|
||||
box->model()->sort(0);
|
||||
addSelectionEntry(
|
||||
box, obs_module_text("AdvSceneSwitcher.selectProfile"), false);
|
||||
box->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
MacroActionProfileEdit::MacroActionProfileEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionProfile> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_profiles = new QComboBox();
|
||||
populateProfileSelection(_profiles);
|
||||
QWidget::connect(_profiles, SIGNAL(currentTextChanged(const QString &)),
|
||||
this, SLOT(ProfileChanged(const QString &)));
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{profiles}}", _profiles},
|
||||
};
|
||||
placeWidgets(obs_module_text("AdvSceneSwitcher.action.profile.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroActionProfileEdit::UpdateEntryData()
|
||||
{
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
_profiles->setCurrentText(QString::fromStdString(_entryData->_profile));
|
||||
}
|
||||
|
||||
void MacroActionProfileEdit::ProfileChanged(const QString &text)
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_profile = text.toStdString();
|
||||
emit HeaderInfoChanged(
|
||||
QString::fromStdString(_entryData->GetShortDesc()));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user