From 6f2f207adc5a8e6963060f5741d1af4698e39bd9 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Mon, 26 Apr 2021 20:55:18 -0700 Subject: [PATCH] SettingsDialog: Add configs --- data/locale/en-US.ini | 37 ++++++------ src/forms/SettingsDialog.cpp | 28 ++++++++- src/forms/SettingsDialog.ui | 107 +++++++++++++++++++++++++++++++++-- src/obs-websocket.cpp | 14 +++++ 4 files changed, 158 insertions(+), 28 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 0382082f..b42cb25e 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -1,21 +1,16 @@ -OBSWebsocket.Settings.DialogTitle="WebSockets Server Settings" -OBSWebsocket.Settings.ServerEnable="Enable WebSockets server" -OBSWebsocket.Settings.ServerPort="Server Port" -OBSWebsocket.Settings.AuthRequired="Enable authentication" -OBSWebsocket.Settings.Password="Password" -OBSWebsocket.Settings.LockToIPv4="Lock server to only using IPv4" -OBSWebsocket.Settings.DebugEnable="Enable debug logging" -OBSWebsocket.Settings.AlertsEnable="Enable System Tray Alerts" -OBSWebsocket.Settings.AuthDisabledWarning="Running obs-websocket with authentication disabled is not recommended, as it allows attackers to easily collect sensetive data. Are you sure you want to proceed?" -OBSWebsocket.NotifyConnect.Title="New WebSocket connection" -OBSWebsocket.NotifyConnect.Message="Client %1 connected" -OBSWebsocket.NotifyDisconnect.Title="WebSocket client disconnected" -OBSWebsocket.NotifyDisconnect.Message="Client %1 disconnected" -OBSWebsocket.Server.StartFailed.Title="WebSockets Server failure" -OBSWebsocket.Server.StartFailed.Message="The WebSockets server failed to start, maybe because:\n - TCP port %1 may currently be in use elsewhere on this system, possibly by another application. Try setting a different TCP port in the WebSocket server settings, or stop any application that could be using this port.\n - Error message: %2" -OBSWebsocket.ProfileChanged.Started="WebSockets server enabled in this profile. Server started." -OBSWebsocket.ProfileChanged.Stopped="WebSockets server disabled in this profile. Server stopped." -OBSWebsocket.ProfileChanged.Restarted="WebSockets server port changed in this profile. Server restarted." -OBSWebsocket.InitialPasswordSetup.Title="obs-websocket - Server Password Configuration" -OBSWebsocket.InitialPasswordSetup.Text="It looks like you are running obs-websocket for the first time. Do you want to configure a password now for the WebSockets server? Setting a password is highly recommended." -OBSWebsocket.InitialPasswordSetup.DismissedText="You can configure a server password later in the WebSockets Server Settings. (Under the Tools menu of OBS Studio)" +OBSWebSocket.Settings.DialogTitle="WebSocket Server Settings" +OBSWebSocket.Settings.ServerEnable="Enable WebSocket server" +OBSWebSocket.Settings.AlertsEnable="Enable System Tray Alerts" +OBSWebSocket.Settings.DebugEnable="Enable Debug Logging" +OBSWebSocket.Settings.AuthRequired="Enable Authentication" +OBSWebSocket.Settings.Password="Server Password" +OBSWebSocket.Settings.CopyPassword="Copy Password to Clipboard" +OBSWebSocket.Settings.ServerPort="Server Port" + +OBSWebSocket.NotifyConnect.Title="New WebSocket connection." +OBSWebSocket.NotifyConnect.Message="Client %1 connected." +OBSWebSocket.NotifyDisconnect.Title="WebSocket client disconnected." +OBSWebSocket.NotifyDisconnect.Message="Client %1 disconnected" + +OBSWebSocket.Server.StartFailed.Title="WebSocket Server Failure" +OBSWebSocket.Server.StartFailed.Message="The WebSocket server failed to start. TCP port %1 may already be in use elsewhere on this system by another application. Try setting a different TCP port in the WebSocket server settings, or stop any application that could be using this port.\n Error message: %2" \ No newline at end of file diff --git a/src/forms/SettingsDialog.cpp b/src/forms/SettingsDialog.cpp index 7a6498c3..516b2978 100644 --- a/src/forms/SettingsDialog.cpp +++ b/src/forms/SettingsDialog.cpp @@ -3,6 +3,7 @@ #include "SettingsDialog.h" #include "../obs-websocket.h" +#include "../Config.h" SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent, Qt::Dialog), @@ -15,7 +16,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) : } void SettingsDialog::showEvent(QShowEvent* event) { - ; + auto conf = GetConfig(); + if (!conf) { + blog(LOG_INFO, "Unable to retreive config!"); + return; + } + + ui->enableWebSocketServerCheckBox->setChecked(conf->ServerEnabled); + ui->enableSystemTrayAlertsCheckBox->setChecked(conf->AlertsEnabled); + ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled); + ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired); + ui->serverPasswordLineEdit->setText(conf->ServerPassword); + ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired); } void SettingsDialog::ToggleShowHide() { @@ -26,7 +38,19 @@ void SettingsDialog::ToggleShowHide() { } void SettingsDialog::FormAccepted() { - ; + auto conf = GetConfig(); + if (!conf) { + blog(LOG_INFO, "Unable to retreive config!"); + return; + } + + conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked(); + conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked(); + conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked(); + conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked(); + conf->ServerPassword = ui->serverPasswordLineEdit->text(); + + conf->Save(); } SettingsDialog::~SettingsDialog() { diff --git a/src/forms/SettingsDialog.ui b/src/forms/SettingsDialog.ui index 8d9a5be2..7146a07a 100644 --- a/src/forms/SettingsDialog.ui +++ b/src/forms/SettingsDialog.ui @@ -6,18 +6,18 @@ 0 0 - 400 - 300 + 453 + 235 - Dialog + OBSWebSocket.Settings.DialogTitle - 30 - 240 + 100 + 200 341 32 @@ -29,6 +29,103 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 9 + 9 + 431 + 191 + + + + + + + OBSWebSocket.Settings.ServerEnable + + + + + + + true + + + + + + + OBSWebSocket.Settings.AlertsEnable + + + + + + + + + + OBSWebSocket.Settings.DebugEnable + + + + + + + + + + OBSWebSocket.Settings.AuthRequired + + + + + + + + + + OBSWebSocket.Settings.Password + + + + + + + QLineEdit::PasswordEchoOnEdit + + + + + + + OBSWebSocket.Settings.CopyPassword + + + + + + + OBSWebSocket.Settings.ServerPort + + + + + + + 1 + + + 65534 + + + 4444 + + + + + diff --git a/src/obs-websocket.cpp b/src/obs-websocket.cpp index 283eec26..5cd933d0 100644 --- a/src/obs-websocket.cpp +++ b/src/obs-websocket.cpp @@ -27,12 +27,25 @@ OBS_DECLARE_MODULE() OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US") ConfigPtr _config; +SettingsDialog *_settingsDialog = nullptr; 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", QT_VERSION_STR, qVersion()); + _config = ConfigPtr(new Config()); + _config->Load(); + + obs_frontend_push_ui_translation(obs_module_get_string); + QMainWindow* mainWindow = (QMainWindow*)obs_frontend_get_main_window(); + _settingsDialog = new SettingsDialog(mainWindow); + obs_frontend_pop_ui_translation(); + + const char* menuActionText = obs_module_text("OBSWebSocket.Settings.DialogTitle"); + QAction* menuAction = (QAction*)obs_frontend_add_tools_menu_qaction(menuActionText); + QObject::connect(menuAction, &QAction::triggered, [] { _settingsDialog->ToggleShowHide(); }); + // Loading finished blog(LOG_INFO, "Module loaded."); @@ -40,6 +53,7 @@ bool obs_module_load(void) { } void obs_module_unload() { + _config.reset(); blog(LOG_INFO, "Finished shutting down."); }