Add support for filename formatting get/set (#162)

This commit is contained in:
Freddie Meyer
2018-01-12 00:18:58 -08:00
committed by Stéphane L
parent e5dae8f5a7
commit 677e393f47
5 changed files with 65 additions and 4 deletions

View File

@ -502,3 +502,15 @@ bool Utils::IsRPHotkeySet() {
size_t count = obs_data_array_count(bindings); size_t count = obs_data_array_count(bindings);
return (count > 0); 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;
}

View File

@ -82,6 +82,8 @@ class Utils {
static bool ReplayBufferEnabled(); static bool ReplayBufferEnabled();
static void StartReplayBuffer(); static void StartReplayBuffer();
static bool IsRPHotkeySet(); static bool IsRPHotkeySet();
static const char* GetFilenameFormatting();
static bool SetFilenameFormatting(const char* filenameFormatting);
}; };
#endif // UTILS_H #endif // UTILS_H

View File

@ -31,6 +31,9 @@ QHash<QString, void(*)(WSRequestHandler*)> WSRequestHandler::messageMap {
{ "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat }, { "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat },
{ "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting },
{ "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting },
{ "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene }, { "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene },
{ "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene }, { "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene },
{ "GetSceneList", WSRequestHandler::HandleGetSceneList }, { "GetSceneList", WSRequestHandler::HandleGetSceneList },

View File

@ -59,6 +59,9 @@ class WSRequestHandler : public QObject {
static void HandleSetHeartbeat(WSRequestHandler* req); static void HandleSetHeartbeat(WSRequestHandler* req);
static void HandleSetFilenameFormatting(WSRequestHandler* req);
static void HandleGetFilenameFormatting(WSRequestHandler* req);
static void HandleSetCurrentScene(WSRequestHandler* req); static void HandleSetCurrentScene(WSRequestHandler* req);
static void HandleGetCurrentScene(WSRequestHandler* req); static void HandleGetCurrentScene(WSRequestHandler* req);
static void HandleGetSceneList(WSRequestHandler* req); static void HandleGetSceneList(WSRequestHandler* req);

View File

@ -125,3 +125,44 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
WSEvents::Instance->HeartbeatIsActive); WSEvents::Instance->HeartbeatIsActive);
req->SendOKResponse(response); 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("<filename-formatting> 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);
}