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.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"

View File

@ -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() {

View File

@ -6,18 +6,18 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>453</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>OBSWebSocket.Settings.DialogTitle</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<x>100</x>
<y>200</y>
<width>341</width>
<height>32</height>
</rect>
@ -29,6 +29,103 @@
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</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>
<resources/>
<connections>

View File

@ -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.");
}