From 439b9e4d15ad40f737205bc524513c576861af53 Mon Sep 17 00:00:00 2001 From: Ilya M Date: Sun, 4 Feb 2018 23:36:56 +0200 Subject: [PATCH] UI: Add frontend API to defer saving Allows the ability to perform multiple actions that would normally save, and defer the save until all of those actions are complete. Closes obsproject/obs-studio#1231 --- UI/api-interface.cpp | 10 ++++++++++ UI/obs-frontend-api/obs-frontend-api.cpp | 12 ++++++++++++ UI/obs-frontend-api/obs-frontend-api.h | 2 ++ UI/obs-frontend-api/obs-frontend-internal.hpp | 4 +++- UI/window-basic-main.cpp | 13 +++++++++++++ UI/window-basic-main.hpp | 3 +++ 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/UI/api-interface.cpp b/UI/api-interface.cpp index a580b721c..636fd797d 100644 --- a/UI/api-interface.cpp +++ b/UI/api-interface.cpp @@ -329,6 +329,16 @@ struct OBSStudioAPI : obs_frontend_callbacks { main->SaveProject(); } + void obs_frontend_defer_save_begin(void) override + { + QMetaObject::invokeMethod(main, "DeferSaveBegin"); + } + + void obs_frontend_defer_save_end(void) override + { + QMetaObject::invokeMethod(main, "DeferSaveEnd"); + } + void obs_frontend_add_save_callback(obs_frontend_save_cb callback, void *private_data) override { diff --git a/UI/obs-frontend-api/obs-frontend-api.cpp b/UI/obs-frontend-api/obs-frontend-api.cpp index ee47fff00..4a8e5389c 100644 --- a/UI/obs-frontend-api/obs-frontend-api.cpp +++ b/UI/obs-frontend-api/obs-frontend-api.cpp @@ -297,6 +297,18 @@ void obs_frontend_save(void) c->obs_frontend_save(); } +void obs_frontend_defer_save_begin(void) +{ + if (callbacks_valid()) + c->obs_frontend_defer_save_begin(); +} + +void obs_frontend_defer_save_end(void) +{ + if (callbacks_valid()) + c->obs_frontend_defer_save_end(); +} + void obs_frontend_add_save_callback(obs_frontend_save_cb callback, void *private_data) { diff --git a/UI/obs-frontend-api/obs-frontend-api.h b/UI/obs-frontend-api/obs-frontend-api.h index 05483ff53..5706ed7d3 100644 --- a/UI/obs-frontend-api/obs-frontend-api.h +++ b/UI/obs-frontend-api/obs-frontend-api.h @@ -150,6 +150,8 @@ EXPORT void obs_frontend_replay_buffer_stop(void); EXPORT bool obs_frontend_replay_buffer_active(void); EXPORT void obs_frontend_save(void); +EXPORT void obs_frontend_defer_save_begin(void); +EXPORT void obs_frontend_defer_save_end(void); EXPORT obs_output_t *obs_frontend_get_streaming_output(void); EXPORT obs_output_t *obs_frontend_get_recording_output(void); diff --git a/UI/obs-frontend-api/obs-frontend-internal.hpp b/UI/obs-frontend-api/obs-frontend-internal.hpp index 0749d2ed5..a81a3031e 100644 --- a/UI/obs-frontend-api/obs-frontend-internal.hpp +++ b/UI/obs-frontend-api/obs-frontend-internal.hpp @@ -61,7 +61,9 @@ struct obs_frontend_callbacks { virtual config_t *obs_frontend_get_profile_config(void)=0; virtual config_t *obs_frontend_get_global_config(void)=0; - virtual void obs_frontend_save(void)=0; + virtual void obs_frontend_save(void) = 0; + virtual void obs_frontend_defer_save_begin(void) = 0; + virtual void obs_frontend_defer_save_end(void) = 0; virtual void obs_frontend_add_save_callback( obs_frontend_save_cb callback, void *private_data)=0; virtual void obs_frontend_remove_save_callback( diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index f1e23a348..5c8f445a8 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -550,6 +550,19 @@ void OBSBasic::Save(const char *file) obs_data_array_release(savedMultiviewProjectorList); } +void OBSBasic::DeferSaveBegin() +{ + os_atomic_inc_long(&disableSaving); +} + +void OBSBasic::DeferSaveEnd() +{ + long result = os_atomic_dec_long(&disableSaving); + if (result == 0) { + SaveProject(); + } +} + static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent) { obs_data_t *data = obs_data_get_obj(parent, name); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 9b4302fa1..7f21d73e6 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -380,6 +380,9 @@ private: obs_data_array_t *savedMultiviewProjectors); public slots: + void DeferSaveBegin(); + void DeferSaveEnd(); + void StartStreaming(); void StopStreaming(); void ForceStopStreaming();