Skip to content

Commit

Permalink
Twitter Service
Browse files Browse the repository at this point in the history
  • Loading branch information
Dussed committed Jul 18, 2024
1 parent dcaafc4 commit 00b3bc5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 2 deletions.
8 changes: 8 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ TrovoServer="Trovo Server"
TrovoServerInfo="The stream server URL is preset for Trovo, you do not need to change it."
TrovoStreamKey="Trovo Stream Key"
TrovoStreamKeyInfo="Please enter your stream key, you can find this in your <a href='https://studio.trovo.live/mychannel/stream'>Trovo Studio page</a>."

# Twitter Output Dialog
TwitterOutput="X (Twitter) Output"
TwitterServiceInfo="Please complete the following fields to add a new X (Twitter) output."
TwitterServer="X (Twitter) Server"
TwitterServerInfo="Pick your closest X (Twitter) ingest server."
TwitterStreamKey="X (Twitter) Stream Key"
TwitterStreamKeyInfo="Please enter your stream key, you can find this in your <a href='https://studio.twitter.com/producer/sources'>X (Twitter) Producer page</a>."
119 changes: 117 additions & 2 deletions output-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,129 @@ QWidget *OutputDialog::WizardInfoYouTube() {

QWidget *OutputDialog::WizardInfoTwitter() {
auto page = new QWidget(this);

page->setStyleSheet("padding: 0px; margin: 0px;");

// Layout
auto pageLayout = new QVBoxLayout;
pageLayout->setSpacing(12);

auto title = new QLabel(QString("Twitter Service page"));
// Heading
auto title = new QLabel(QString::fromUtf8(obs_module_text("TwitterServiceInfo")));
pageLayout->addWidget(title);

// Content
auto contentLayout = new QVBoxLayout;

// Confirm button - initialised here so we can set state in form input connects
auto confirmButton = generateButton(QString("Create Output"));

// Form
auto formLayout = new QFormLayout;
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
formLayout->setLabelAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
formLayout->setSpacing(12);

// Output name
auto outputNameField = new QLineEdit;
outputNameField->setText(QString::fromUtf8(obs_module_text("TwitterOutput")));
outputNameField->setStyleSheet("padding: 4px 8px;");

connect(outputNameField, &QLineEdit::textEdited, [this, outputNameField, confirmButton] {
outputName = outputNameField->text();
validateOutputs(confirmButton);
});

formLayout->addRow(generateFormLabel("OutputName"), outputNameField);

// 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("Twitter");

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

// Set default value for server
outputServer = serverSelection->currentData().toString();

formLayout->addRow(generateFormLabel("TwitterServer"), serverSelection);

// Server info
formLayout->addWidget(generateInfoLabel("TwitterServerInfo"));

// Server key
auto outputKeyField = new QLineEdit;
outputKeyField->setStyleSheet("padding: 4px 8px;");
connect(outputKeyField, &QLineEdit::textEdited, [this, outputKeyField, confirmButton] {
outputKey = outputKeyField->text();
validateOutputs(confirmButton);
});

formLayout->addRow(generateFormLabel("TwitterStreamKey"), outputKeyField);

// Server key info
formLayout->addWidget(generateInfoLabel("TwitterStreamKeyInfo"));

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
auto serviceButton = generateButton(QString("< Back"));

connect(serviceButton, &QPushButton::clicked, [this] {
stackedWidget->setCurrentIndex(0);
resetOutputs();
});

controlsLayout->addWidget(serviceButton, 0);
controlsLayout->addStretch(1);

// confirm button (initialised above so we can set state)
connect(confirmButton, &QPushButton::clicked, [this] {
acceptOutputs();
});

controlsLayout->addWidget(confirmButton, 0);

// Hook it all together
pageLayout->addLayout(controlsLayout);
page->setLayout(pageLayout);

// Defaults for when we're changed to
connect(stackedWidget, &QStackedWidget::currentChanged, [this, outputNameField, serverSelection, outputKeyField, confirmButton] {
if (stackedWidget->currentIndex() == 3) {
outputName = outputNameField->text();
outputServer = serverSelection->currentData().toString();
outputKey = outputKeyField->text();
validateOutputs(confirmButton);
}
});

return page;
}

Expand Down

0 comments on commit 00b3bc5

Please sign in to comment.