From 89b887d8c9dabed38a41885f819c899bb76f4328 Mon Sep 17 00:00:00 2001 From: David Marsh Date: Thu, 18 Jul 2024 15:18:56 +0100 Subject: [PATCH] Twitch service in new output dialog working --- config-dialog.cpp | 23 ++++++- data/locale/en-US.ini | 2 +- output-dialog.cpp | 138 ++++++++++++++++++++++++++++-------------- output-dialog.hpp | 12 ++-- 4 files changed, 122 insertions(+), 53 deletions(-) diff --git a/config-dialog.cpp b/config-dialog.cpp index 9e73e4c..189b097 100644 --- a/config-dialog.cpp +++ b/config-dialog.cpp @@ -173,7 +173,28 @@ OBSBasicSettings::OBSBasicSettings(QMainWindow *parent) : QDialog(parent) if (outputDialog->exec() == QDialog::Accepted) { // got a result - blog(LOG_WARNING, "[Aitum Multistream] output accepted"); + blog(LOG_WARNING, "[Aitum Multistream] output accepted %s %s %s", outputDialog->outputName.toUtf8().constData(), outputDialog->outputServer.toUtf8().constData(), outputDialog->outputKey.toUtf8().constData()); + + // create a new output + if (!settings) + return; + auto outputs = obs_data_get_array(settings, "outputs"); + if (!outputs) { + outputs = obs_data_array_create(); + obs_data_set_array(settings, "outputs", outputs); + } + auto s = obs_data_create(); + + // Set the info from the output dialog + obs_data_set_string(s, "name", outputDialog->outputName.toUtf8().constData()); + obs_data_set_string(s, "stream_server", outputDialog->outputServer.toUtf8().constData()); + obs_data_set_string(s, "stream_key", outputDialog->outputKey.toUtf8().constData()); + + obs_data_array_push_back(outputs, s); + obs_data_array_release(outputs); + AddServer(mainOutputsLayout, s); + obs_data_release(s); + } else { blog(LOG_WARNING, "[Aitum Multistream] output rejected"); } diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index d26b959..4600be0 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -35,6 +35,6 @@ OtherService="Other Service" TwitchServiceInfo="Please complete the following fields to add a new Twitch output." TwitchServer="Twitch Server" -TwitchServerInfo="Pick your closest Twitch ingest server.\nYou can find your closest/recommended server by clicking here." +TwitchServerInfo="Pick your closest Twitch ingest server.\nYou can find your closest/recommended server by clicking here." TwitchStreamKey="Twitch Stream Key" TwitchStreamKeyInfo="Please enter your stream key, you can find this on your Twitch Creator Dashboard." diff --git a/output-dialog.cpp b/output-dialog.cpp index b7bd0b4..e154c1c 100644 --- a/output-dialog.cpp +++ b/output-dialog.cpp @@ -22,6 +22,56 @@ void OutputDialog::resetOutputs() { outputKey = QString(""); } +// For when we're done +void OutputDialog::acceptOutputs() { + accept(); +} + +// For validating the current values and then updating the confirm button state +void OutputDialog::validateOutputs(QPushButton *confirmButton) { + + if (outputName.isEmpty()) { + confirmButton->setEnabled(false); + } else if (outputServer.isEmpty()) { + confirmButton->setEnabled(false); + } else if (outputKey.isEmpty()) { + confirmButton->setEnabled(false); + } else { + confirmButton->setEnabled(true); + } + +} + +// Helper for generating info QLabels +QLabel *generateInfoLabel(std::string text) { + auto label = new QLabel; + label->setTextFormat(Qt::RichText); + label->setText(QString::fromUtf8(obs_module_text(text.c_str()))); + label->setOpenExternalLinks(true); + label->setWordWrap(true); + label->setAlignment(Qt::AlignTop); + + return label; +} + +// Helper for generating form QLabels +QLabel *generateFormLabel(std::string text) { + auto label = new QLabel(QString::fromUtf8(obs_module_text(text.c_str()))); + label->setStyleSheet("font-weight: bold;"); + + return label; +} + +// Helper for generating QPushButtons w/ style +QPushButton *generateButton(QString text) { + auto button = new QPushButton; + button->setText(text); + button->setStyleSheet("padding: 4px 12px;"); + button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + return button; +} + QToolButton *OutputDialog::selectionButton(std::string title, QIcon icon, int selectionStep) { auto button = new QToolButton; @@ -199,12 +249,15 @@ QWidget *OutputDialog::WizardInfoUnknown() { QWidget *OutputDialog::WizardInfoTwitch() { auto page = new QWidget(this); - page->setStyleSheet("padding: 0px; margin: 0px;"); - auto pageLayout = new QVBoxLayout; - pageLayout->setSpacing(16); + // Set defaults for this service + outputName = QString("Twitch Output"); + + // Layout + auto pageLayout = new QVBoxLayout; + pageLayout->setSpacing(12); // Heading auto title = new QLabel(QString::fromUtf8(obs_module_text("TwitchServiceInfo"))); @@ -212,8 +265,9 @@ QWidget *OutputDialog::WizardInfoTwitch() { // Content auto contentLayout = new QVBoxLayout; -// auto filler = new QLabel(QString("filler text")); -// contentLayout->addWidget(filler); + + // Confirm button - initialised here so we can set state in form input connects + auto confirmButton = generateButton(QString("Create Output")); // Form auto formLayout = new QFormLayout; @@ -222,20 +276,27 @@ QWidget *OutputDialog::WizardInfoTwitch() { formLayout->setSpacing(12); // Output name - auto outputNameTitle = new QLabel(QString::fromUtf8(obs_module_text("OutputName"))); - outputNameTitle->setStyleSheet("font-weight: bold;"); + auto outputNameField = new QLineEdit; + outputNameField->setText(outputName); + outputNameField->setStyleSheet("padding: 4px 8px;"); - auto outputName = new QLineEdit; - outputName->setStyleSheet("padding: 4px 8px;"); - formLayout->addRow(outputNameTitle, outputName); + connect(outputNameField, &QLineEdit::textEdited, [this, outputNameField, confirmButton] { + outputName = outputNameField->text(); + validateOutputs(confirmButton); + }); - // Server selection + formLayout->addRow(generateFormLabel("OutputName"), outputNameField); - auto serverSelectionTitle = new QLabel(QString::fromUtf8(obs_module_text("TwitchServer"))); - serverSelectionTitle->setStyleSheet("font-weight: bold;"); + // Server selection auto serverSelection = new QComboBox; serverSelection->setMinimumHeight(30); serverSelection->setStyleSheet("padding: 4px 8px;"); + + connect(serverSelection, &QComboBox::currentIndexChanged, [this, serverSelection, confirmButton] { + outputServer = serverSelection->currentData().toString(); + validateOutputs(confirmButton); + }); + auto rawOptions = getService("Twitch"); // turn raw options into actual selectable options @@ -250,33 +311,23 @@ QWidget *OutputDialog::WizardInfoTwitch() { } - formLayout->addRow(serverSelectionTitle, serverSelection); + formLayout->addRow(generateFormLabel("TwitchServer"), serverSelection); // Server info - auto serverInfo = new QLabel; - serverInfo->setTextFormat(Qt::RichText); - serverInfo->setText(QString::fromUtf8(obs_module_text("TwitchServerInfo"))); - serverInfo->setOpenExternalLinks(true); - serverInfo->setWordWrap(true); - formLayout->addWidget(serverInfo); + formLayout->addWidget(generateInfoLabel("TwitchServerInfo")); // Server key - auto outputKeyTitle = new QLabel(QString::fromUtf8(obs_module_text("TwitchStreamKey"))); - outputNameTitle->setStyleSheet("font-weight: bold;"); + auto outputKeyField = new QLineEdit; + outputKeyField->setStyleSheet("padding: 4px 8px;"); + connect(outputKeyField, &QLineEdit::textEdited, [this, outputKeyField, confirmButton] { + outputKey = outputKeyField->text(); + validateOutputs(confirmButton); + }); - auto outputKey = new QLineEdit; - outputName->setStyleSheet("padding: 4px 8px;"); - formLayout->addRow(outputKeyTitle, outputKey); + formLayout->addRow(generateFormLabel("TwitchStreamKey"), outputKeyField); // Server key info - auto keyInfo = new QLabel; - keyInfo->setTextFormat(Qt::RichText); - keyInfo->setText(QString::fromUtf8(obs_module_text("TwitchStreamKeyInfo"))); - keyInfo->setOpenExternalLinks(true); - keyInfo->setWordWrap(true); - keyInfo->setAlignment(Qt::AlignTop); - formLayout->addWidget(keyInfo); - + formLayout->addWidget(generateInfoLabel("TwitchStreamKeyInfo")); contentLayout->addLayout(formLayout); @@ -290,12 +341,8 @@ QWidget *OutputDialog::WizardInfoTwitch() { auto controlsLayout = new QHBoxLayout; controlsLayout->setSpacing(12); - // back button - auto serviceButton = new QPushButton; - serviceButton->setText(QString("< Back")); - serviceButton->setStyleSheet("padding: 4px 12px;"); - serviceButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + auto serviceButton = generateButton(QString("< Back")); connect(serviceButton, &QPushButton::clicked, [this] { stackedWidget->setCurrentIndex(0); @@ -303,18 +350,17 @@ QWidget *OutputDialog::WizardInfoTwitch() { }); controlsLayout->addWidget(serviceButton, 0); - controlsLayout->addStretch(1); - // confirm button - auto confirmButton = new QPushButton; - confirmButton->setEnabled(false); - confirmButton->setText(QString("Create Output")); - confirmButton->setStyleSheet("padding: 4px 12px;"); - confirmButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + // confirm button (initialised above so we can set state) + validateOutputs(confirmButton); + + connect(confirmButton, &QPushButton::clicked, [this] { + acceptOutputs(); + }); controlsLayout->addWidget(confirmButton, 0); - // Hook it all together pageLayout->addLayout(controlsLayout); page->setLayout(pageLayout); diff --git a/output-dialog.hpp b/output-dialog.hpp index 999ccae..3a0469b 100644 --- a/output-dialog.hpp +++ b/output-dialog.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "obs-data.h" @@ -35,15 +36,16 @@ class OutputDialog : public QDialog { QIcon platformIconUnknown = QIcon(":/aitum/media/unknown.png"); obs_data_array_t *servicesData; - - QString outputName; - QString outputServer; - QString outputKey; - + void resetOutputs(); + void acceptOutputs(); + void validateOutputs(QPushButton *confirmButton); obs_data_t *getService(std::string serviceName); QStackedWidget *stackedWidget; public: OutputDialog(QDialog *parent); + QString outputName; + QString outputServer; + QString outputKey; };