2024-07-16 15:16:40 +02:00
|
|
|
#include "output-dialog.hpp"
|
|
|
|
|
|
|
|
#include <QDialog>
|
2024-07-16 18:41:19 +02:00
|
|
|
#include <QVBoxLayout>
|
2024-07-18 01:32:30 +02:00
|
|
|
#include <QHBoxLayout>
|
2024-07-16 18:41:19 +02:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QStackedWidget>
|
2024-07-16 23:00:33 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QToolButton>
|
2024-07-18 01:32:30 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QSizePolicy>
|
2024-07-16 20:52:59 +02:00
|
|
|
#include "obs-module.h"
|
2024-07-18 01:32:30 +02:00
|
|
|
#include "util/platform.h"
|
2024-07-16 20:52:59 +02:00
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
// Reset output values, e.g. when user hits the back button
|
|
|
|
void OutputDialog::resetOutputs() {
|
|
|
|
outputName = QString("");
|
|
|
|
outputServer = QString("");
|
|
|
|
outputKey = QString("");
|
|
|
|
}
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
QToolButton *OutputDialog::selectionButton(std::string title, QIcon icon, int selectionStep) {
|
2024-07-16 23:00:33 +02:00
|
|
|
auto button = new QToolButton;
|
|
|
|
|
|
|
|
button->setText(QString::fromUtf8(title));
|
|
|
|
button->setIcon(icon);
|
|
|
|
button->setIconSize(QSize(32, 32));
|
|
|
|
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
button->setStyleSheet("min-width: 110px; max-width: 110px; min-height: 90px; max-height: 90px; padding-top: 16px; font-weight: bold;");
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
connect(button, &QPushButton::clicked, [this, selectionStep] {
|
|
|
|
stackedWidget->setCurrentIndex(selectionStep);
|
|
|
|
});
|
|
|
|
|
2024-07-16 23:00:33 +02:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
// Gets a service from the service array matched by name
|
|
|
|
obs_data_t *OutputDialog::getService(std::string serviceName) {
|
|
|
|
auto total = obs_data_array_count(servicesData);
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < total; idx++) {
|
|
|
|
auto item = obs_data_array_item(servicesData, idx);
|
|
|
|
// blog(LOG_WARNING, "[Aitum Multistream] %s", obs_data_get_string(item, "name"));
|
|
|
|
|
|
|
|
if (serviceName == obs_data_get_string(item, "name")) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
OutputDialog::OutputDialog(QDialog *parent) : QDialog(parent) {
|
2024-07-18 01:32:30 +02:00
|
|
|
// Load the services from rtmp-services plugin
|
|
|
|
auto servicesPath = obs_module_get_config_path(obs_get_module("rtmp-services"), "services.json");
|
|
|
|
auto absolutePath = os_get_abs_path_ptr(servicesPath);
|
|
|
|
auto allData = obs_data_create_from_json_file(absolutePath);
|
|
|
|
|
|
|
|
servicesData = obs_data_get_array(allData, "services");
|
|
|
|
|
|
|
|
bfree(allData);
|
|
|
|
bfree(servicesPath);
|
|
|
|
bfree(absolutePath);
|
|
|
|
|
|
|
|
//
|
2024-07-16 20:52:59 +02:00
|
|
|
setModal(true);
|
2024-07-18 01:32:30 +02:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
setFixedSize(650, 400);
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
stackedWidget = new QStackedWidget;
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
stackedWidget->setStyleSheet("padding: 0px; margin: 0px;");
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
// Service selection page
|
|
|
|
stackedWidget->addWidget(WizardServicePage());
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
// Pages for each service
|
|
|
|
stackedWidget->addWidget(WizardInfoKick());
|
|
|
|
stackedWidget->addWidget(WizardInfoYouTube());
|
|
|
|
stackedWidget->addWidget(WizardInfoTwitter());
|
|
|
|
stackedWidget->addWidget(WizardInfoUnknown());
|
|
|
|
stackedWidget->addWidget(WizardInfoTwitch());
|
|
|
|
stackedWidget->addWidget(WizardInfoTrovo());
|
|
|
|
stackedWidget->addWidget(WizardInfoTikTok());
|
|
|
|
stackedWidget->addWidget(WizardInfoFacebook());
|
|
|
|
|
|
|
|
stackedWidget->setCurrentIndex(0);
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
stackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2024-07-16 20:52:59 +02:00
|
|
|
setWindowTitle(obs_module_text("NewOutputWindowTitle"));
|
2024-07-16 18:41:19 +02:00
|
|
|
|
|
|
|
auto stackedLayout = new QVBoxLayout;
|
2024-07-18 01:32:30 +02:00
|
|
|
stackedLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
stackedLayout->addWidget(stackedWidget, 1);
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
setLayout(stackedLayout);
|
2024-07-16 15:16:40 +02:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
QWidget *OutputDialog::WizardServicePage() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
2024-07-18 01:32:30 +02:00
|
|
|
pageLayout->setAlignment(Qt::AlignTop);
|
2024-07-16 18:41:19 +02:00
|
|
|
|
2024-07-16 20:52:59 +02:00
|
|
|
auto description = new QLabel(QString::fromUtf8(obs_module_text("NewOutputSelectService")));
|
2024-07-16 23:00:33 +02:00
|
|
|
description->setStyleSheet("margin-bottom: 20px;");
|
2024-07-16 20:52:59 +02:00
|
|
|
pageLayout->addWidget(description);
|
|
|
|
|
|
|
|
// layout for service selection
|
|
|
|
auto selectionLayout = new QVBoxLayout;
|
2024-07-18 01:32:30 +02:00
|
|
|
selectionLayout->setAlignment(Qt::AlignCenter);
|
2024-07-16 23:00:33 +02:00
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
auto spacerTest = new QSpacerItem(20, 45, QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2024-07-16 23:00:33 +02:00
|
|
|
|
|
|
|
pageLayout->addSpacerItem(spacerTest);
|
2024-07-16 20:52:59 +02:00
|
|
|
|
|
|
|
// row 1
|
|
|
|
auto rowOne = new QHBoxLayout;
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
rowOne->addWidget(selectionButton("Twitch", platformIconTwitch, 5));
|
|
|
|
rowOne->addWidget(selectionButton("YouTube", platformIconYouTube, 2));
|
|
|
|
rowOne->addWidget(selectionButton("TikTok", platformIconTikTok, 7));
|
|
|
|
rowOne->addWidget(selectionButton("Facebook", platformIconFacebook, 8));
|
2024-07-16 23:00:33 +02:00
|
|
|
|
|
|
|
selectionLayout->addLayout(rowOne);
|
2024-07-16 20:52:59 +02:00
|
|
|
|
|
|
|
// row 2
|
2024-07-16 23:00:33 +02:00
|
|
|
auto rowTwo = new QHBoxLayout;
|
2024-07-16 20:52:59 +02:00
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
rowTwo->addWidget(selectionButton("Trovo", platformIconTrovo, 6));
|
|
|
|
rowTwo->addWidget(selectionButton("X (Twitter)", platformIconTwitter, 3));
|
|
|
|
rowTwo->addWidget(selectionButton("Kick", platformIconKick, 1));
|
|
|
|
rowTwo->addWidget(selectionButton(obs_module_text("OtherService"), platformIconUnknown, 4));
|
2024-07-16 20:52:59 +02:00
|
|
|
|
2024-07-16 23:00:33 +02:00
|
|
|
selectionLayout->addLayout(rowTwo);
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-16 23:00:33 +02:00
|
|
|
//
|
|
|
|
pageLayout->addLayout(selectionLayout);
|
2024-07-16 18:41:19 +02:00
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OutputDialog::WizardInfoKick() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Kick Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OutputDialog::WizardInfoYouTube() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("YouTube Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OutputDialog::WizardInfoTwitter() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Twitter Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
page->setLayout(pageLayout);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
QWidget *OutputDialog::WizardInfoUnknown() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Unknown Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
page->setLayout(pageLayout);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
QWidget *OutputDialog::WizardInfoTwitch() {
|
|
|
|
auto page = new QWidget(this);
|
2024-07-18 01:32:30 +02:00
|
|
|
page->setStyleSheet("padding: 0px; margin: 0px;");
|
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
// Set defaults for this service
|
|
|
|
outputName = QString("Twitch Output");
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
|
|
|
|
// Layout
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
pageLayout->setSpacing(12);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
// Heading
|
|
|
|
auto title = new QLabel(QString::fromUtf8(obs_module_text("TwitchServiceInfo")));
|
2024-07-16 18:41:19 +02:00
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
// Content
|
|
|
|
auto contentLayout = new QVBoxLayout;
|
2024-07-18 16:18:56 +02:00
|
|
|
|
|
|
|
// Confirm button - initialised here so we can set state in form input connects
|
|
|
|
auto confirmButton = generateButton(QString("Create Output"));
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
// Form
|
|
|
|
auto formLayout = new QFormLayout;
|
|
|
|
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
|
|
|
formLayout->setLabelAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
|
|
|
|
formLayout->setSpacing(12);
|
|
|
|
|
|
|
|
// Output name
|
2024-07-18 16:18:56 +02:00
|
|
|
auto outputNameField = new QLineEdit;
|
|
|
|
outputNameField->setText(outputName);
|
|
|
|
outputNameField->setStyleSheet("padding: 4px 8px;");
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
connect(outputNameField, &QLineEdit::textEdited, [this, outputNameField, confirmButton] {
|
|
|
|
outputName = outputNameField->text();
|
|
|
|
validateOutputs(confirmButton);
|
|
|
|
});
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
formLayout->addRow(generateFormLabel("OutputName"), outputNameField);
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
// Server selection
|
2024-07-18 01:32:30 +02:00
|
|
|
auto serverSelection = new QComboBox;
|
|
|
|
serverSelection->setMinimumHeight(30);
|
|
|
|
serverSelection->setStyleSheet("padding: 4px 8px;");
|
2024-07-18 16:18:56 +02:00
|
|
|
|
|
|
|
connect(serverSelection, &QComboBox::currentIndexChanged, [this, serverSelection, confirmButton] {
|
|
|
|
outputServer = serverSelection->currentData().toString();
|
|
|
|
validateOutputs(confirmButton);
|
|
|
|
});
|
|
|
|
|
2024-07-18 01:32:30 +02:00
|
|
|
auto rawOptions = getService("Twitch");
|
|
|
|
|
|
|
|
// turn raw options into actual selectable options
|
|
|
|
if (rawOptions != nullptr) {
|
|
|
|
auto servers = obs_data_get_array(rawOptions, "servers");
|
|
|
|
auto totalServers = obs_data_array_count(servers);
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < totalServers; idx++) {
|
|
|
|
auto item = obs_data_array_item(servers, idx);
|
|
|
|
serverSelection->addItem(obs_data_get_string(item, "name"), obs_data_get_string(item, "url"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
formLayout->addRow(generateFormLabel("TwitchServer"), serverSelection);
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
// Server info
|
2024-07-18 16:18:56 +02:00
|
|
|
formLayout->addWidget(generateInfoLabel("TwitchServerInfo"));
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
// Server key
|
2024-07-18 16:18:56 +02:00
|
|
|
auto outputKeyField = new QLineEdit;
|
|
|
|
outputKeyField->setStyleSheet("padding: 4px 8px;");
|
|
|
|
connect(outputKeyField, &QLineEdit::textEdited, [this, outputKeyField, confirmButton] {
|
|
|
|
outputKey = outputKeyField->text();
|
|
|
|
validateOutputs(confirmButton);
|
|
|
|
});
|
2024-07-18 01:32:30 +02:00
|
|
|
|
2024-07-18 16:18:56 +02:00
|
|
|
formLayout->addRow(generateFormLabel("TwitchStreamKey"), outputKeyField);
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
// Server key info
|
2024-07-18 16:18:56 +02:00
|
|
|
formLayout->addWidget(generateInfoLabel("TwitchStreamKeyInfo"));
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
contentLayout->addLayout(formLayout);
|
|
|
|
|
|
|
|
// spacing
|
|
|
|
auto spacer = new QSpacerItem(1, 20, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
|
|
|
contentLayout->addSpacerItem(spacer);
|
|
|
|
|
|
|
|
pageLayout->addLayout(contentLayout);
|
|
|
|
|
|
|
|
// Controls
|
|
|
|
auto controlsLayout = new QHBoxLayout;
|
|
|
|
controlsLayout->setSpacing(12);
|
|
|
|
|
|
|
|
// back button
|
2024-07-18 16:18:56 +02:00
|
|
|
auto serviceButton = generateButton(QString("< Back"));
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
connect(serviceButton, &QPushButton::clicked, [this] {
|
|
|
|
stackedWidget->setCurrentIndex(0);
|
|
|
|
resetOutputs();
|
|
|
|
});
|
|
|
|
|
|
|
|
controlsLayout->addWidget(serviceButton, 0);
|
|
|
|
controlsLayout->addStretch(1);
|
2024-07-18 16:18:56 +02:00
|
|
|
|
|
|
|
// confirm button (initialised above so we can set state)
|
|
|
|
validateOutputs(confirmButton);
|
|
|
|
|
|
|
|
connect(confirmButton, &QPushButton::clicked, [this] {
|
|
|
|
acceptOutputs();
|
|
|
|
});
|
2024-07-18 01:32:30 +02:00
|
|
|
|
|
|
|
controlsLayout->addWidget(confirmButton, 0);
|
|
|
|
|
|
|
|
// Hook it all together
|
|
|
|
pageLayout->addLayout(controlsLayout);
|
2024-07-16 18:41:19 +02:00
|
|
|
page->setLayout(pageLayout);
|
2024-07-16 15:16:40 +02:00
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:41:19 +02:00
|
|
|
QWidget *OutputDialog::WizardInfoTrovo() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Trovo Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OutputDialog::WizardInfoTikTok() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Tiktok Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OutputDialog::WizardInfoFacebook() {
|
|
|
|
auto page = new QWidget(this);
|
|
|
|
|
|
|
|
auto pageLayout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto title = new QLabel(QString("Facebook Service page"));
|
|
|
|
pageLayout->addWidget(title);
|
|
|
|
|
|
|
|
page->setLayout(pageLayout);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|