Skip to content

Commit

Permalink
Twitch service in new output dialog working
Browse files Browse the repository at this point in the history
  • Loading branch information
Dussed committed Jul 18, 2024
1 parent 026636b commit 89b887d
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 53 deletions.
23 changes: 22 additions & 1 deletion config-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
TwitchStreamKeyInfo="Please enter your stream key, you can find this on your <a href='https://dashboard.twitch.tv/settings/stream'>Twitch Creator Dashboard</a>."
138 changes: 92 additions & 46 deletions output-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -199,21 +249,25 @@ 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")));
pageLayout->addWidget(title);

// 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;
Expand All @@ -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
Expand All @@ -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);

Expand All @@ -290,31 +341,26 @@ 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);
resetOutputs();
});

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);
Expand Down
12 changes: 7 additions & 5 deletions output-dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include <QStackedWidget>
#include <QToolButton>
#include <QPushButton>
#include <QString>
#include "obs-data.h"

Expand Down Expand Up @@ -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;
};

0 comments on commit 89b887d

Please sign in to comment.