SettingsDialog: Add configs

This commit is contained in:
tt2468 2021-04-26 20:55:18 -07:00
parent 5fffca73fc
commit 6f2f207adc
4 changed files with 158 additions and 28 deletions

View File

@ -1,21 +1,16 @@
OBSWebsocket.Settings.DialogTitle="WebSockets Server Settings" OBSWebSocket.Settings.DialogTitle="WebSocket Server Settings"
OBSWebsocket.Settings.ServerEnable="Enable WebSockets server" OBSWebSocket.Settings.ServerEnable="Enable WebSocket server"
OBSWebsocket.Settings.ServerPort="Server Port" OBSWebSocket.Settings.AlertsEnable="Enable System Tray Alerts"
OBSWebsocket.Settings.AuthRequired="Enable authentication" OBSWebSocket.Settings.DebugEnable="Enable Debug Logging"
OBSWebsocket.Settings.Password="Password" OBSWebSocket.Settings.AuthRequired="Enable Authentication"
OBSWebsocket.Settings.LockToIPv4="Lock server to only using IPv4" OBSWebSocket.Settings.Password="Server Password"
OBSWebsocket.Settings.DebugEnable="Enable debug logging" OBSWebSocket.Settings.CopyPassword="Copy Password to Clipboard"
OBSWebsocket.Settings.AlertsEnable="Enable System Tray Alerts" OBSWebSocket.Settings.ServerPort="Server Port"
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.Title="New WebSocket connection."
OBSWebsocket.NotifyConnect.Message="Client %1 connected" OBSWebSocket.NotifyConnect.Message="Client %1 connected."
OBSWebsocket.NotifyDisconnect.Title="WebSocket client disconnected" OBSWebSocket.NotifyDisconnect.Title="WebSocket client disconnected."
OBSWebsocket.NotifyDisconnect.Message="Client %1 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.Server.StartFailed.Title="WebSocket Server Failure"
OBSWebsocket.ProfileChanged.Started="WebSockets server enabled in this profile. Server started." 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"
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)"

View File

@ -3,6 +3,7 @@
#include "SettingsDialog.h" #include "SettingsDialog.h"
#include "../obs-websocket.h" #include "../obs-websocket.h"
#include "../Config.h"
SettingsDialog::SettingsDialog(QWidget* parent) : SettingsDialog::SettingsDialog(QWidget* parent) :
QDialog(parent, Qt::Dialog), QDialog(parent, Qt::Dialog),
@ -15,7 +16,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
} }
void SettingsDialog::showEvent(QShowEvent* event) { 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() { void SettingsDialog::ToggleShowHide() {
@ -26,7 +38,19 @@ void SettingsDialog::ToggleShowHide() {
} }
void SettingsDialog::FormAccepted() { 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() { SettingsDialog::~SettingsDialog() {

View File

@ -6,18 +6,18 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>453</width>
<height>300</height> <height>235</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>OBSWebSocket.Settings.DialogTitle</string>
</property> </property>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>30</x> <x>100</x>
<y>240</y> <y>200</y>
<width>341</width> <width>341</width>
<height>32</height> <height>32</height>
</rect> </rect>
@ -29,6 +29,103 @@
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>431</width>
<height>191</height>
</rect>
</property>
<layout class="QFormLayout" name="mainForm">
<item row="0" column="0">
<widget class="QLabel" name="enableWebSocketServerLabel">
<property name="text">
<string>OBSWebSocket.Settings.ServerEnable</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="enableWebSocketServerCheckBox">
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="enableSystemTrayAlertsLabel">
<property name="text">
<string>OBSWebSocket.Settings.AlertsEnable</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="enableSystemTrayAlertsCheckBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="enableDebugLoggingLabel">
<property name="text">
<string>OBSWebSocket.Settings.DebugEnable</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="enableDebugLoggingCheckBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="enableAuthenticationLabel">
<property name="text">
<string>OBSWebSocket.Settings.AuthRequired</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="enableAuthenticationCheckBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="serverPasswordLabel">
<property name="text">
<string>OBSWebSocket.Settings.Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="serverPasswordLineEdit">
<property name="echoMode">
<enum>QLineEdit::PasswordEchoOnEdit</enum>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="copyPasswordButton">
<property name="text">
<string>OBSWebSocket.Settings.CopyPassword</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="serverPortLabel">
<property name="text">
<string>OBSWebSocket.Settings.ServerPort</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="serverPortSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65534</number>
</property>
<property name="value">
<number>4444</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>

View File

@ -27,12 +27,25 @@ OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US") OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
ConfigPtr _config; ConfigPtr _config;
SettingsDialog *_settingsDialog = nullptr;
bool obs_module_load(void) { bool obs_module_load(void) {
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION); 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", blog(LOG_INFO, "Qt version (compile-time): %s | Qt version (run-time): %s",
QT_VERSION_STR, qVersion()); 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 // Loading finished
blog(LOG_INFO, "Module loaded."); blog(LOG_INFO, "Module loaded.");
@ -40,6 +53,7 @@ bool obs_module_load(void) {
} }
void obs_module_unload() { void obs_module_unload() {
_config.reset();
blog(LOG_INFO, "Finished shutting down."); blog(LOG_INFO, "Finished shutting down.");
} }