From 677e393f479f79949087f53176cf742576d6b3e8 Mon Sep 17 00:00:00 2001 From: Freddie Meyer Date: Fri, 12 Jan 2018 00:18:58 -0800 Subject: [PATCH] Add support for filename formatting get/set (#162) --- src/Utils.cpp | 12 ++++++++ src/Utils.h | 2 ++ src/WSRequestHandler.cpp | 3 ++ src/WSRequestHandler.h | 3 ++ src/WSRequestHandler_General.cpp | 49 +++++++++++++++++++++++++++++--- 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index d6cd9ce6..b4cd387b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -502,3 +502,15 @@ bool Utils::IsRPHotkeySet() { size_t count = obs_data_array_count(bindings); return (count > 0); } + +const char* Utils::GetFilenameFormatting() { + config_t* profile = obs_frontend_get_profile_config(); + return config_get_string(profile, "Output", "FilenameFormatting"); +} + +bool Utils::SetFilenameFormatting(const char* filenameFormatting) { + config_t* profile = obs_frontend_get_profile_config(); + config_set_string(profile, "Output", "FilenameFormatting", filenameFormatting); + config_save(profile); + return true; +} diff --git a/src/Utils.h b/src/Utils.h index aac52246..e69aa806 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -82,6 +82,8 @@ class Utils { static bool ReplayBufferEnabled(); static void StartReplayBuffer(); static bool IsRPHotkeySet(); + static const char* GetFilenameFormatting(); + static bool SetFilenameFormatting(const char* filenameFormatting); }; #endif // UTILS_H diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 40e820fd..7294bfbb 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -31,6 +31,9 @@ QHash WSRequestHandler::messageMap { { "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat }, + { "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting }, + { "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting }, + { "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene }, { "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene }, { "GetSceneList", WSRequestHandler::HandleGetSceneList }, diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index a012f22f..34cf5c85 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -59,6 +59,9 @@ class WSRequestHandler : public QObject { static void HandleSetHeartbeat(WSRequestHandler* req); + static void HandleSetFilenameFormatting(WSRequestHandler* req); + static void HandleGetFilenameFormatting(WSRequestHandler* req); + static void HandleSetCurrentScene(WSRequestHandler* req); static void HandleGetCurrentScene(WSRequestHandler* req); static void HandleGetSceneList(WSRequestHandler* req); diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index afcb9053..0b87c4e6 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -8,7 +8,7 @@ /** * Returns the latest version of the plugin and the API. - * + * * @return {double} `version` OBSRemote compatible API version. Fixed to 1.1 for retrocompatibility. * @return {String} `obs-websocket-version` obs-websocket plugin version. * @return {String} `obs-studio-version` OBS Studio program version. @@ -43,11 +43,11 @@ /** * Tells the client if authentication is required. If so, returns authentication parameters `challenge` * and `salt` (see "Authentication" for more information). - * + * * @return {boolean} `authRequired` Indicates whether authentication is required. * @return {String (optional)} `challenge` * @return {String (optional)} `salt` - * + * * @api requests * @name GetAuthRequired * @category general @@ -71,7 +71,7 @@ void WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) { /** * Attempt to authenticate the client to the server. - * + * * @param {String} `auth` Response to the auth challenge (see "Authentication" for more information). * * @api requests @@ -125,3 +125,44 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { WSEvents::Instance->HeartbeatIsActive); req->SendOKResponse(response); } + +/** + * Set the filename formatting string + * + * @param {String} `filename-formatting` Filename formatting string to set. + * + * @api requests + * @name SetFilenameFormatting + * @category general + * @since unreleased + */ +void WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) { + if (!req->hasField("filename-formatting")) { + req->SendErrorResponse(" parameter missing"); + return; + } + + QString filenameFormatting = obs_data_get_string(req->data, "filename-formatting"); + if (!filenameFormatting.isEmpty()) { + Utils::SetFilenameFormatting(filenameFormatting.toUtf8()); + req->SendOKResponse(); + } else { + req->SendErrorResponse("invalid request parameters"); + } +} + +/** + * Get the filename formatting string + * + * @return {String} `filename-formatting` Current filename formatting string. + * + * @api requests + * @name GetFilenameFormatting + * @category general + * @since unreleased + */ +void WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) { + OBSDataAutoRelease response = obs_data_create(); + obs_data_set_string(response, "filename-formatting", Utils::GetFilenameFormatting()); + req->SendOKResponse(response); +}