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
This commit is contained in:
Ilya Melamed 2018-05-04 15:36:01 -07:00 committed by jp9000
parent 3eec139b2e
commit c768f703ad
6 changed files with 37 additions and 4 deletions

View file

@ -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
{

View file

@ -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())

View file

@ -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);

View file

@ -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;

View file

@ -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()

View file

@ -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);