Pārlūkot izejas kodu

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
Ilya Melamed 7 gadi atpakaļ
vecāks
revīzija
c768f703ad

+ 13 - 0
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<std::string> &strings) override
 	{

+ 7 - 0
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())

+ 1 - 0
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);

+ 1 - 0
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<std::string> &strings)=0;

+ 11 - 3
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()

+ 4 - 1
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);