diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fa5f8b3..77e9b7b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,10 +64,14 @@ configure_file( # Inlude sources set(obs-websocket_SOURCES - src/obs-websocket.cpp) + src/obs-websocket.cpp + src/Config.cpp + src/forms/SettingsDialog.cpp) set(obs-websocket_HEADERS - src/obs-websocket.h) + src/obs-websocket.h + src/Config.h + src/forms/SettingsDialog.h) # Platform-independent build settings diff --git a/README.md b/README.md index f0211d51..9f12e6a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## YOU HAVE STUMBLED UPON THE DEV BRANCH FOR V5.0.0 -- You can find the main API sheet [here](https://gist.github.com/tt2468/59390b99e7841b28f56dffb3dd622ec9) +- You can find the main protocol spec here: [PROTOCOL.md](docs/generated/protocol.md). - You can find the planned requests sheet [here](https://docs.google.com/spreadsheets/d/1LfCZrbT8e7cSaKo_TuPDd-CJiptL7RSuo8iE63vMmMs/edit?usp=sharing) diff --git a/src/Config.cpp b/src/Config.cpp new file mode 100644 index 00000000..9810a48e --- /dev/null +++ b/src/Config.cpp @@ -0,0 +1,81 @@ +#include +#include + +#include "Config.h" + +#define CONFIG_SECTION_NAME "obs-websocket" + +#define PARAM_ENABLED "ServerEnabled" +#define PARAM_PORT "ServerPort" +#define PARAM_DEBUG "DebugEnabled" +#define PARAM_ALERTS "AlertsEnabled" +#define PARAM_AUTHREQUIRED "AuthRequred" +#define PARAM_PASSWORD "ServerPassword" + +Config::Config() : + ServerEnabled(true), + ServerPort(4444), + DebugEnabled(false), + AlertsEnabled(false), + AuthRequired(true), + ServerPassword("") +{ + qsrand(QTime::currentTime().msec()); + + SetDefaultsToGlobalStore(); +} + +void Config::Load() +{ + config_t* obsConfig = GetConfigStore(); + if (!obsConfig) { + blog(LOG_ERROR, "Unable to fetch OBS config!"); + return; + } + + ServerEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED); + ServerPort = config_get_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT); + DebugEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG); + AlertsEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS); + AuthRequired = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED); + ServerPassword = config_get_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD); +} + +void Config::Save() +{ + config_t* obsConfig = GetConfigStore(); + if (!obsConfig) { + blog(LOG_ERROR, "Unable to fetch OBS config!"); + return; + } + + config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED, ServerEnabled); + config_set_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); + config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG, DebugEnabled); + config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); + config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); + config_set_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD, QT_TO_UTF8(ServerPassword)); + + config_save(obsConfig); +} + +void Config::SetDefaultsToGlobalStore() +{ + config_t* obsConfig = GetConfigStore(); + if (!obsConfig) { + blog(LOG_ERROR, "Unable to fetch OBS config!"); + return; + } + + config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED, ServerEnabled); + config_set_default_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); + config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_DEBUG, DebugEnabled); + config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); + config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); + config_set_default_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD, QT_TO_UTF8(ServerPassword)); +} + +config_t* Config::GetConfigStore() +{ + return obs_frontend_get_global_config(); +} \ No newline at end of file diff --git a/src/Config.h b/src/Config.h new file mode 100644 index 00000000..1a8e43bd --- /dev/null +++ b/src/Config.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +#include "plugin-macros.generated.h" + +class Config { + public: + Config(); + void Load(); + void Save(); + void SetDefaultsToGlobalStore(); + config_t* GetConfigStore(); + + bool ServerEnabled; + uint16_t ServerPort; + bool DebugEnabled; + bool AlertsEnabled; + bool AuthRequired; + QString ServerPassword; + + private: + ; +}; \ No newline at end of file diff --git a/src/forms/SettingsDialog.cpp b/src/forms/SettingsDialog.cpp new file mode 100644 index 00000000..7a6498c3 --- /dev/null +++ b/src/forms/SettingsDialog.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "SettingsDialog.h" +#include "../obs-websocket.h" + +SettingsDialog::SettingsDialog(QWidget* parent) : + QDialog(parent, Qt::Dialog), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, + this, &SettingsDialog::FormAccepted); +} + +void SettingsDialog::showEvent(QShowEvent* event) { + ; +} + +void SettingsDialog::ToggleShowHide() { + if (!isVisible()) + setVisible(true); + else + setVisible(false); +} + +void SettingsDialog::FormAccepted() { + ; +} + +SettingsDialog::~SettingsDialog() { + delete ui; +} \ No newline at end of file diff --git a/src/forms/SettingsDialog.h b/src/forms/SettingsDialog.h new file mode 100644 index 00000000..5a580ed2 --- /dev/null +++ b/src/forms/SettingsDialog.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#include "ui_SettingsDialog.h" + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsDialog(QWidget* parent = 0); + ~SettingsDialog(); + void showEvent(QShowEvent* event); + void ToggleShowHide(); + +private Q_SLOTS: + void FormAccepted(); + +private: + Ui::SettingsDialog* ui; +}; \ No newline at end of file diff --git a/src/forms/SettingsDialog.ui b/src/forms/SettingsDialog.ui new file mode 100644 index 00000000..8d9a5be2 --- /dev/null +++ b/src/forms/SettingsDialog.ui @@ -0,0 +1,68 @@ + + + SettingsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/obs-websocket.cpp b/src/obs-websocket.cpp index cbb268de..283eec26 100644 --- a/src/obs-websocket.cpp +++ b/src/obs-websocket.cpp @@ -6,8 +6,9 @@ #include #include -#include "plugin-macros.generated.h" #include "obs-websocket.h" +#include "Config.h" +#include "forms/SettingsDialog.h" // Auto release definitions void ___source_dummy_addref(obs_source_t*) {} @@ -25,6 +26,8 @@ void ___data_item_release(obs_data_item_t* dataItem) { OBS_DECLARE_MODULE() OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US") +ConfigPtr _config; + bool obs_module_load(void) { blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION); blog(LOG_INFO, "Qt version (compile-time): %s | Qt version (run-time): %s", @@ -38,4 +41,8 @@ bool obs_module_load(void) { void obs_module_unload() { blog(LOG_INFO, "Finished shutting down."); +} + +ConfigPtr GetConfig() { + return _config; } \ No newline at end of file diff --git a/src/obs-websocket.h b/src/obs-websocket.h index 9191c743..bbb9ef8a 100644 --- a/src/obs-websocket.h +++ b/src/obs-websocket.h @@ -3,6 +3,8 @@ #include #include +#include "plugin-macros.generated.h" + // Autorelease object declarations void ___source_dummy_addref(obs_source_t*); void ___sceneitem_dummy_addref(obs_sceneitem_t*); @@ -24,4 +26,9 @@ using OBSOutputAutoRelease = void ___data_item_dummy_addref(obs_data_item_t*); void ___data_item_release(obs_data_item_t*); using OBSDataItemAutoRelease = - OBSRef; \ No newline at end of file + OBSRef; + +class Config; +typedef std::shared_ptr ConfigPtr; + +ConfigPtr GetConfig(); \ No newline at end of file diff --git a/src/plugin-macros.generated.h b/src/plugin-macros.generated.h index bce83b2c..dc3a53b5 100644 --- a/src/plugin-macros.generated.h +++ b/src/plugin-macros.generated.h @@ -21,6 +21,8 @@ with this program. If not, see #define OBS_WEBSOCKET_VERSION "5.0.0" +#define QT_TO_UTF8(str) str.toUtf8().constData() + #define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__) #endif // PLUGINNAME_H diff --git a/src/plugin-macros.h.in b/src/plugin-macros.h.in index f50e3036..3a8e93f6 100644 --- a/src/plugin-macros.h.in +++ b/src/plugin-macros.h.in @@ -1,26 +1,28 @@ -/* -obs-websocket -Copyright (C) 2021 Kyle Manning - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see -*/ - -#ifndef PLUGINNAME_H -#define PLUGINNAME_H - -#define OBS_WEBSOCKET_VERSION "@CMAKE_PROJECT_VERSION@" - -#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__) - +/* +obs-websocket +Copyright (C) 2021 Kyle Manning + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see +*/ + +#ifndef PLUGINNAME_H +#define PLUGINNAME_H + +#define OBS_WEBSOCKET_VERSION "@CMAKE_PROJECT_VERSION@" + +#define QT_TO_UTF8(str) str.toUtf8().constData() + +#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__) + #endif // PLUGINNAME_H \ No newline at end of file