Twitch service in new output dialog working

This commit is contained in:
David Marsh 2024-07-18 15:18:56 +01:00
parent 026636b03b
commit 89b887d8c9
4 changed files with 122 additions and 53 deletions

View File

@ -173,7 +173,28 @@ OBSBasicSettings::OBSBasicSettings(QMainWindow *parent) : QDialog(parent)
if (outputDialog->exec() == QDialog::Accepted) { if (outputDialog->exec() == QDialog::Accepted) {
// got a result // 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 { } else {
blog(LOG_WARNING, "[Aitum Multistream] output rejected"); blog(LOG_WARNING, "[Aitum Multistream] output rejected");
} }

View File

@ -35,6 +35,6 @@ OtherService="Other Service"
TwitchServiceInfo="Please complete the following fields to add a new Twitch output." TwitchServiceInfo="Please complete the following fields to add a new Twitch output."
TwitchServer="Twitch Server" TwitchServer="Twitch Server"
TwitchServerInfo="Pick your closest Twitch ingest server.\nYou can find your closest/recommended server by clicking <a href='https://help.twitch.tv/s/twitch-ingest/recommendation'>here</a>." TwitchServerInfo="Pick your closest Twitch ingest server.\nYou can find your closest/recommended server by clicking <a href='https://help.twitch.tv/s/twitch-ingest-recommendation'>here</a>."
TwitchStreamKey="Twitch Stream Key" TwitchStreamKey="Twitch Stream Key"
TwitchStreamKeyInfo="Please enter your stream key, you can find this on your <a href='https://dashboard.twitch.tv/settings/stream'>Twitch Creator Dashboard</a>." TwitchStreamKeyInfo="Please enter your stream key, you can find this on your <a href='https://dashboard.twitch.tv/settings/stream'>Twitch Creator Dashboard</a>."

View File

@ -22,6 +22,56 @@ void OutputDialog::resetOutputs() {
outputKey = QString(""); 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) { QToolButton *OutputDialog::selectionButton(std::string title, QIcon icon, int selectionStep) {
auto button = new QToolButton; auto button = new QToolButton;
@ -199,21 +249,25 @@ QWidget *OutputDialog::WizardInfoUnknown() {
QWidget *OutputDialog::WizardInfoTwitch() { QWidget *OutputDialog::WizardInfoTwitch() {
auto page = new QWidget(this); auto page = new QWidget(this);
page->setStyleSheet("padding: 0px; margin: 0px;"); page->setStyleSheet("padding: 0px; margin: 0px;");
auto pageLayout = new QVBoxLayout; // Set defaults for this service
pageLayout->setSpacing(16); outputName = QString("Twitch Output");
// Layout
auto pageLayout = new QVBoxLayout;
pageLayout->setSpacing(12);
// Heading // Heading
auto title = new QLabel(QString::fromUtf8(obs_module_text("TwitchServiceInfo"))); auto title = new QLabel(QString::fromUtf8(obs_module_text("TwitchServiceInfo")));
pageLayout->addWidget(title); pageLayout->addWidget(title);
// Content // Content
auto contentLayout = new QVBoxLayout; 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 // Form
auto formLayout = new QFormLayout; auto formLayout = new QFormLayout;
@ -222,20 +276,27 @@ QWidget *OutputDialog::WizardInfoTwitch() {
formLayout->setSpacing(12); formLayout->setSpacing(12);
// Output name // Output name
auto outputNameTitle = new QLabel(QString::fromUtf8(obs_module_text("OutputName"))); auto outputNameField = new QLineEdit;
outputNameTitle->setStyleSheet("font-weight: bold;"); outputNameField->setText(outputName);
outputNameField->setStyleSheet("padding: 4px 8px;");
auto outputName = new QLineEdit; connect(outputNameField, &QLineEdit::textEdited, [this, outputNameField, confirmButton] {
outputName->setStyleSheet("padding: 4px 8px;"); outputName = outputNameField->text();
formLayout->addRow(outputNameTitle, outputName); validateOutputs(confirmButton);
});
formLayout->addRow(generateFormLabel("OutputName"), outputNameField);
// Server selection // Server selection
auto serverSelectionTitle = new QLabel(QString::fromUtf8(obs_module_text("TwitchServer")));
serverSelectionTitle->setStyleSheet("font-weight: bold;");
auto serverSelection = new QComboBox; auto serverSelection = new QComboBox;
serverSelection->setMinimumHeight(30); serverSelection->setMinimumHeight(30);
serverSelection->setStyleSheet("padding: 4px 8px;"); serverSelection->setStyleSheet("padding: 4px 8px;");
connect(serverSelection, &QComboBox::currentIndexChanged, [this, serverSelection, confirmButton] {
outputServer = serverSelection->currentData().toString();
validateOutputs(confirmButton);
});
auto rawOptions = getService("Twitch"); auto rawOptions = getService("Twitch");
// turn raw options into actual selectable options // 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 // Server info
auto serverInfo = new QLabel; formLayout->addWidget(generateInfoLabel("TwitchServerInfo"));
serverInfo->setTextFormat(Qt::RichText);
serverInfo->setText(QString::fromUtf8(obs_module_text("TwitchServerInfo")));
serverInfo->setOpenExternalLinks(true);
serverInfo->setWordWrap(true);
formLayout->addWidget(serverInfo);
// Server key // Server key
auto outputKeyTitle = new QLabel(QString::fromUtf8(obs_module_text("TwitchStreamKey"))); auto outputKeyField = new QLineEdit;
outputNameTitle->setStyleSheet("font-weight: bold;"); outputKeyField->setStyleSheet("padding: 4px 8px;");
connect(outputKeyField, &QLineEdit::textEdited, [this, outputKeyField, confirmButton] {
outputKey = outputKeyField->text();
validateOutputs(confirmButton);
});
auto outputKey = new QLineEdit; formLayout->addRow(generateFormLabel("TwitchStreamKey"), outputKeyField);
outputName->setStyleSheet("padding: 4px 8px;");
formLayout->addRow(outputKeyTitle, outputKey);
// Server key info // Server key info
auto keyInfo = new QLabel; formLayout->addWidget(generateInfoLabel("TwitchStreamKeyInfo"));
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);
contentLayout->addLayout(formLayout); contentLayout->addLayout(formLayout);
@ -290,12 +341,8 @@ QWidget *OutputDialog::WizardInfoTwitch() {
auto controlsLayout = new QHBoxLayout; auto controlsLayout = new QHBoxLayout;
controlsLayout->setSpacing(12); controlsLayout->setSpacing(12);
// back button // back button
auto serviceButton = new QPushButton; auto serviceButton = generateButton(QString("< Back"));
serviceButton->setText(QString("< Back"));
serviceButton->setStyleSheet("padding: 4px 12px;");
serviceButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(serviceButton, &QPushButton::clicked, [this] { connect(serviceButton, &QPushButton::clicked, [this] {
stackedWidget->setCurrentIndex(0); stackedWidget->setCurrentIndex(0);
@ -303,18 +350,17 @@ QWidget *OutputDialog::WizardInfoTwitch() {
}); });
controlsLayout->addWidget(serviceButton, 0); controlsLayout->addWidget(serviceButton, 0);
controlsLayout->addStretch(1); controlsLayout->addStretch(1);
// confirm button
auto confirmButton = new QPushButton; // confirm button (initialised above so we can set state)
confirmButton->setEnabled(false); validateOutputs(confirmButton);
confirmButton->setText(QString("Create Output"));
confirmButton->setStyleSheet("padding: 4px 12px;"); connect(confirmButton, &QPushButton::clicked, [this] {
confirmButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); acceptOutputs();
});
controlsLayout->addWidget(confirmButton, 0); controlsLayout->addWidget(confirmButton, 0);
// Hook it all together // Hook it all together
pageLayout->addLayout(controlsLayout); pageLayout->addLayout(controlsLayout);
page->setLayout(pageLayout); page->setLayout(pageLayout);

View File

@ -4,6 +4,7 @@
#include <QWidget> #include <QWidget>
#include <QStackedWidget> #include <QStackedWidget>
#include <QToolButton> #include <QToolButton>
#include <QPushButton>
#include <QString> #include <QString>
#include "obs-data.h" #include "obs-data.h"
@ -36,14 +37,15 @@ private:
obs_data_array_t *servicesData; obs_data_array_t *servicesData;
QString outputName;
QString outputServer;
QString outputKey;
void resetOutputs(); void resetOutputs();
void acceptOutputs();
void validateOutputs(QPushButton *confirmButton);
obs_data_t *getService(std::string serviceName); obs_data_t *getService(std::string serviceName);
QStackedWidget *stackedWidget; QStackedWidget *stackedWidget;
public: public:
OutputDialog(QDialog *parent); OutputDialog(QDialog *parent);
QString outputName;
QString outputServer;
QString outputKey;
}; };