mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
generic: Add SettingsDialog and Config
This commit is contained in:
parent
17f3137b40
commit
a8ca912044
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
81
src/Config.cpp
Normal file
81
src/Config.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <QTime>
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#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();
|
||||
}
|
25
src/Config.h
Normal file
25
src/Config.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <util/config-file.h>
|
||||
|
||||
#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:
|
||||
;
|
||||
};
|
34
src/forms/SettingsDialog.cpp
Normal file
34
src/forms/SettingsDialog.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <obs-frontend-api.h>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
||||
#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;
|
||||
}
|
22
src/forms/SettingsDialog.h
Normal file
22
src/forms/SettingsDialog.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
|
||||
#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;
|
||||
};
|
68
src/forms/SettingsDialog.ui
Normal file
68
src/forms/SettingsDialog.ui
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsDialog</class>
|
||||
<widget class="QDialog" name="SettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -6,8 +6,9 @@
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
|
||||
#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;
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
#include <obs.hpp>
|
||||
#include <memory>
|
||||
|
||||
#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<obs_data_item_t*, ___data_item_dummy_addref, ___data_item_release>;
|
||||
OBSRef<obs_data_item_t*, ___data_item_dummy_addref, ___data_item_release>;
|
||||
|
||||
class Config;
|
||||
typedef std::shared_ptr<Config> ConfigPtr;
|
||||
|
||||
ConfigPtr GetConfig();
|
@ -21,6 +21,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
|
||||
#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
|
||||
|
@ -1,26 +1,28 @@
|
||||
/*
|
||||
obs-websocket
|
||||
Copyright (C) 2021 Kyle Manning <tt2468@irltoolkit.com>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#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 <tt2468@irltoolkit.com>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user