From c768f703ad7af9211ccc0f579ebdbaa7a53364a8 Mon Sep 17 00:00:00 2001 From: Ilya Melamed Date: Fri, 4 May 2018 15:36:01 -0700 Subject: [PATCH] UI: Add obs_frontend_add_scene_collection API call Allows the ability to add a new scene collection via the frontend API. Blocks until the scene collection has been successfully added to ensure synchronization between the calling thread and the UI thread. (Jim: Added detailed description to commit message) Closes obsproject/obs-studio#1232 --- UI/api-interface.cpp | 13 +++++++++++++ UI/obs-frontend-api/obs-frontend-api.cpp | 7 +++++++ UI/obs-frontend-api/obs-frontend-api.h | 1 + UI/obs-frontend-api/obs-frontend-internal.hpp | 1 + UI/window-basic-main-scene-collections.cpp | 14 +++++++++++--- UI/window-basic-main.hpp | 5 ++++- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index 636fd797d..b72f1cdab 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -167,6 +167,19 @@ struct OBSStudioAPI : obs_frontend_callbacks { } } + bool obs_frontend_add_scene_collection( + const char *name) override + { + bool success = false; + QMetaObject::invokeMethod(main, + "AddSceneCollection", + WaitConnection(), + Q_RETURN_ARG(bool, success), + Q_ARG(bool, true), + Q_ARG(QString, QT_UTF8(name))); + return success; + } + void obs_frontend_get_profiles( std::vector &strings) override { diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index 4a8e5389c..c3c933ab8 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -148,6 +148,13 @@ void obs_frontend_set_current_scene_collection(const char *collection) c->obs_frontend_set_current_scene_collection(collection); } +bool obs_frontend_add_scene_collection(const char *name) +{ + return callbacks_valid() + ? c->obs_frontend_add_scene_collection(name) + : false; +} + char **obs_frontend_get_profiles(void) { if (!callbacks_valid()) diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index 5706ed7d3..0a2a80e4b 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -95,6 +95,7 @@ EXPORT void obs_frontend_set_current_transition(obs_source_t *transition); EXPORT char **obs_frontend_get_scene_collections(void); EXPORT char *obs_frontend_get_current_scene_collection(void); EXPORT void obs_frontend_set_current_scene_collection(const char *collection); +EXPORT bool obs_frontend_add_scene_collection(const char *name); EXPORT char **obs_frontend_get_profiles(void); EXPORT char *obs_frontend_get_current_profile(void); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index a81a3031e..b1a906418 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -26,6 +26,7 @@ struct obs_frontend_callbacks { virtual char *obs_frontend_get_current_scene_collection(void)=0; virtual void obs_frontend_set_current_scene_collection( const char *collection)=0; + virtual bool obs_frontend_add_scene_collection(const char *name)=0; virtual void obs_frontend_get_profiles( std::vector &strings)=0; diff --git a/UI/window-basic-main-scene-collections.cpp b/UI/window-basic-main-scene-collections.cpp index 1bb7f2c23..9759a2707 100644 --- a/UI/window-basic-main-scene-collections.cpp +++ b/UI/window-basic-main-scene-collections.cpp @@ -154,13 +154,19 @@ static bool GetSceneCollectionName(QWidget *parent, std::string &name, return true; } -void OBSBasic::AddSceneCollection(bool create_new) +bool OBSBasic::AddSceneCollection(bool create_new, const QString &qname) { std::string name; std::string file; - if (!GetSceneCollectionName(this, name, file)) - return; + if (qname.isEmpty()) { + if (!GetSceneCollectionName(this, name, file)) + return false; + } else { + name = QT_TO_UTF8(qname); + if (SceneCollectionExists(name.c_str())) + return false; + } SaveProjectNow(); @@ -185,6 +191,8 @@ void OBSBasic::AddSceneCollection(bool create_new) api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED); api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED); } + + return true; } void OBSBasic::RefreshSceneCollections() diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 8f98e361e..2951438fa 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -259,7 +259,6 @@ private: void GetAudioSourceProperties(); void VolControlContextMenu(); - void AddSceneCollection(bool create_new); void RefreshSceneCollections(); void ChangeSceneCollection(); void LogScenes(); @@ -407,6 +406,10 @@ public slots: void SetCurrentScene(OBSSource scene, bool force = false, bool direct = false); + bool AddSceneCollection( + bool create_new, + const QString &name = QString()); + private slots: void AddSceneItem(OBSSceneItem item); void RemoveSceneItem(OBSSceneItem item);