UI: Add front-end API library

Allows manipulating and modifying the front-end via plugins.
This commit is contained in:
jp9000
2016-09-06 22:01:48 -07:00
parent bfc21317bf
commit 8836592d92
15 changed files with 1049 additions and 6 deletions
+59 -1
View File
@@ -373,6 +373,13 @@ void OBSBasic::Save(const char *file)
obs_data_set_bool(saveData, "preview_locked", ui->preview->Locked());
if (api) {
obs_data_t *moduleObj = obs_data_create();
api->on_save(moduleObj);
obs_data_set_obj(saveData, "modules", moduleObj);
obs_data_release(moduleObj);
}
if (!obs_data_save_json_safe(saveData, file, "tmp", "bak"))
blog(LOG_ERROR, "Could not save scene data to %s", file);
@@ -655,6 +662,12 @@ retryScene:
ui->preview->SetLocked(previewLocked);
ui->actionLockPreview->setChecked(previewLocked);
if (api) {
obs_data_t *modulesObj = obs_data_get_obj(data, "modules");
api->on_load(modulesObj);
obs_data_release(modulesObj);
}
obs_data_release(data);
if (!opt_starting_scene.empty())
@@ -1019,6 +1032,8 @@ void OBSBasic::ResetOutputs()
#define SHUTDOWN_SEPARATOR \
"==== Shutting down =================================================="
extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main);
void OBSBasic::OBSInit()
{
ProfileScope("OBSBasic::OBSInit");
@@ -1065,6 +1080,8 @@ void OBSBasic::OBSInit()
InitOBSCallbacks();
InitHotkeys();
api = InitializeAPIInterface(this);
AddExtraModulePaths();
blog(LOG_INFO, "---------------------------------");
obs_load_all_modules();
@@ -2067,6 +2084,9 @@ void OBSBasic::DuplicateSelectedScene()
AddScene(source);
SetCurrentScene(source, true);
obs_scene_release(scene);
if (api)
api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
break;
}
}
@@ -2076,8 +2096,12 @@ void OBSBasic::RemoveSelectedScene()
OBSScene scene = GetCurrentScene();
if (scene) {
obs_source_t *source = obs_scene_get_source(scene);
if (QueryRemoveSource(source))
if (QueryRemoveSource(source)) {
obs_source_remove(source);
if (api)
api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
}
}
}
@@ -2639,6 +2663,10 @@ void OBSBasic::closeEvent(QCloseEvent *event)
signalHandlers.clear();
SaveProjectNow();
if (api)
api->on_event(OBS_FRONTEND_EVENT_EXIT);
disableSaving++;
/* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
@@ -3487,6 +3515,9 @@ void OBSBasic::SceneNameEdited(QWidget *editor,
obs_source_t *source = obs_scene_get_source(scene);
RenameListItem(this, ui->scenes, source, text);
if (api)
api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
UNUSED_PARAMETER(endHint);
}
@@ -3537,6 +3568,12 @@ void OBSBasic::OpenSceneFilters()
void OBSBasic::StartStreaming()
{
if (outputHandler->StreamingActive())
return;
if (api)
api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
SaveProject();
ui->streamButton->setEnabled(false);
@@ -3684,6 +3721,9 @@ void OBSBasic::StreamingStart()
sysTrayStream->setText(ui->streamButton->text());
sysTrayStream->setEnabled(true);
if (api)
api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
OnActivate();
blog(LOG_INFO, STREAMING_START);
@@ -3693,6 +3733,9 @@ void OBSBasic::StreamStopping()
{
ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
sysTrayStream->setText(ui->streamButton->text());
if (api)
api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
}
void OBSBasic::StreamingStop(int code)
@@ -3730,6 +3773,9 @@ void OBSBasic::StreamingStop(int code)
sysTrayStream->setText(ui->streamButton->text());
sysTrayStream->setEnabled(true);
if (api)
api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
OnDeactivate();
blog(LOG_INFO, STREAMING_STOP);
@@ -3754,6 +3800,9 @@ void OBSBasic::StartRecording()
if (outputHandler->RecordingActive())
return;
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
SaveProject();
outputHandler->StartRecording();
}
@@ -3762,6 +3811,9 @@ void OBSBasic::RecordStopping()
{
ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
sysTrayRecord->setText(ui->recordButton->text());
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
}
void OBSBasic::StopRecording()
@@ -3780,6 +3832,9 @@ void OBSBasic::RecordingStart()
ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
sysTrayRecord->setText(ui->recordButton->text());
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
OnActivate();
blog(LOG_INFO, RECORDING_START);
@@ -3820,6 +3875,9 @@ void OBSBasic::RecordingStop(int code)
QSystemTrayIcon::Warning);
}
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
OnDeactivate();
}