From bedaf917c984f5e418ff0c1840600539e0fd37da Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Sat, 29 Jul 2023 15:16:23 +0300 Subject: [PATCH] lint --- .clang-format | 4 +- src/plugin-main.c | 3 +- src/request-data.cpp | 50 ++++------ src/request-data.h | 6 +- src/ui/RequestBuilder.cpp | 179 ++++++++++++---------------------- src/ui/RequestBuilder.h | 3 +- src/ui/text-render-helper.cpp | 7 +- src/ui/text-render-helper.h | 4 +- src/url-source.cpp | 85 ++++++---------- 9 files changed, 121 insertions(+), 220 deletions(-) diff --git a/.clang-format b/.clang-format index 89cbc19..33a3b3a 100644 --- a/.clang-format +++ b/.clang-format @@ -44,7 +44,7 @@ BreakBeforeBraces: Custom BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon BreakStringLiterals: false # apparently unpredictable -ColumnLimit: 80 +ColumnLimit: 100 CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 8 @@ -53,7 +53,7 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false FixNamespaceComments: false -ForEachMacros: +ForEachMacros: - 'json_object_foreach' - 'json_object_foreach_safe' - 'json_array_foreach' diff --git a/src/plugin-main.c b/src/plugin-main.c index 4533a18..c41bc64 100644 --- a/src/plugin-main.c +++ b/src/plugin-main.c @@ -26,8 +26,7 @@ extern struct obs_source_info url_source; bool obs_module_load(void) { - obs_log(LOG_INFO, "plugin loaded successfully (version %s)", - PLUGIN_VERSION); + obs_log(LOG_INFO, "plugin loaded successfully (version %s)", PLUGIN_VERSION); obs_register_source(&url_source); return true; } diff --git a/src/request-data.cpp b/src/request-data.cpp index 92df404..63a2a98 100644 --- a/src/request-data.cpp +++ b/src/request-data.cpp @@ -7,18 +7,15 @@ #include #include -static const std::string USER_AGENT = - std::string(PLUGIN_NAME) + "/" + std::string(PLUGIN_VERSION); +static const std::string USER_AGENT = std::string(PLUGIN_NAME) + "/" + std::string(PLUGIN_VERSION); -std::size_t writeFunctionStdString(void *ptr, std::size_t size, size_t nmemb, - std::string *data) +std::size_t writeFunctionStdString(void *ptr, std::size_t size, size_t nmemb, std::string *data) { data->append(static_cast(ptr), size * nmemb); return size * nmemb; } -struct request_data_handler_response -request_data_handler(url_source_request_data *request_data) +struct request_data_handler_response request_data_handler(url_source_request_data *request_data) { // Build the request with libcurl CURL *curl = curl_easy_init(); @@ -39,10 +36,8 @@ request_data_handler(url_source_request_data *request_data) // Add request headers struct curl_slist *headers = NULL; for (auto header : request_data->headers) { - std::string header_string = - header.first + ": " + header.second; - headers = curl_slist_append(headers, - header_string.c_str()); + std::string header_string = header.first + ": " + header.second; + headers = curl_slist_append(headers, header_string.c_str()); } curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); } @@ -54,8 +49,7 @@ request_data_handler(url_source_request_data *request_data) code = curl_easy_perform(curl); curl_easy_cleanup(curl); if (code != CURLE_OK) { - obs_log(LOG_INFO, "Failed to send request: %s", - curl_easy_strerror(code)); + obs_log(LOG_INFO, "Failed to send request: %s", curl_easy_strerror(code)); // Return an error response struct request_data_handler_response responseFail; responseFail.error_message = curl_easy_strerror(code); @@ -74,8 +68,7 @@ request_data_handler(url_source_request_data *request_data) try { json = nlohmann::json::parse(responseBody); } catch (nlohmann::json::parse_error &e) { - obs_log(LOG_INFO, "Failed to parse JSON response: %s", - e.what()); + obs_log(LOG_INFO, "Failed to parse JSON response: %s", e.what()); // Return an error response struct request_data_handler_response responseFail; responseFail.error_message = e.what(); @@ -87,16 +80,12 @@ request_data_handler(url_source_request_data *request_data) try { response.body_parsed = json.at(nlohmann::json::json_pointer( - request_data - ->output_json_path)) + request_data->output_json_path)) .get(); } catch (nlohmann::json::exception &e) { - obs_log(LOG_INFO, - "Failed to get JSON value: %s", - e.what()); + obs_log(LOG_INFO, "Failed to get JSON value: %s", e.what()); // Return an error response - struct request_data_handler_response - responseFail; + struct request_data_handler_response responseFail; responseFail.error_message = e.what(); responseFail.status_code = -1; return responseFail; @@ -135,8 +124,7 @@ std::string serialize_request_data(url_source_request_data *request_data) return json.dump(); } -url_source_request_data -unserialize_request_data(std::string serialized_request_data) +url_source_request_data unserialize_request_data(std::string serialized_request_data) { obs_log(LOG_INFO, "Unserializing request data"); // Unserialize the request data from a string using JSON @@ -144,8 +132,7 @@ unserialize_request_data(std::string serialized_request_data) try { json = nlohmann::json::parse(serialized_request_data); } catch (nlohmann::json::parse_error &e) { - obs_log(LOG_INFO, "Failed to parse JSON request data: %s", - e.what()); + obs_log(LOG_INFO, "Failed to parse JSON request data: %s", e.what()); // Return an empty request data object url_source_request_data request_data; return request_data; @@ -156,19 +143,16 @@ unserialize_request_data(std::string serialized_request_data) request_data.method = json["method"].get(); request_data.body = json["body"].get(); request_data.output_type = json["output_type"].get(); - request_data.output_json_path = - json["output_json_path"].get(); + request_data.output_json_path = json["output_json_path"].get(); request_data.output_xpath = json["output_xpath"].get(); request_data.output_regex = json["output_regex"].get(); - request_data.output_regex_flags = - json["output_regex_flags"].get(); - request_data.output_regex_group = - json["output_regex_group"].get(); + request_data.output_regex_flags = json["output_regex_flags"].get(); + request_data.output_regex_group = json["output_regex_group"].get(); nlohmann::json headers_json = json["headers"]; for (auto header : headers_json.items()) { - request_data.headers.push_back(std::make_pair( - header.key(), header.value().get())); + request_data.headers.push_back( + std::make_pair(header.key(), header.value().get())); } return request_data; diff --git a/src/request-data.h b/src/request-data.h index d50d36a..7e9aa21 100644 --- a/src/request-data.h +++ b/src/request-data.h @@ -29,12 +29,10 @@ struct request_data_handler_response { std::string error_message; }; -struct request_data_handler_response -request_data_handler(url_source_request_data *request_data); +struct request_data_handler_response request_data_handler(url_source_request_data *request_data); std::string serialize_request_data(url_source_request_data *request_data); -url_source_request_data -unserialize_request_data(std::string serialized_request_data); +url_source_request_data unserialize_request_data(std::string serialized_request_data); #endif // REQUEST_DATA_H diff --git a/src/ui/RequestBuilder.cpp b/src/ui/RequestBuilder.cpp index 215b90e..7fb1ef0 100644 --- a/src/ui/RequestBuilder.cpp +++ b/src/ui/RequestBuilder.cpp @@ -32,8 +32,7 @@ class KeyValueListWidget : public QWidget { QVBoxLayout *listLayout; public: - KeyValueListWidget(QWidget *parent = nullptr) - : QWidget(parent), listLayout(new QVBoxLayout) + KeyValueListWidget(QWidget *parent = nullptr) : QWidget(parent), listLayout(new QVBoxLayout) { setLayout(listLayout); @@ -42,59 +41,43 @@ class KeyValueListWidget : public QWidget { listLayout->addWidget(addButton); connect(addButton, &QPushButton::clicked, this, [=]() { // Add a new key-value widget - KeyValueWidget *keyValueWidget = - new KeyValueWidget(this); - listLayout->insertWidget(listLayout->count() - 1, - keyValueWidget); + KeyValueWidget *keyValueWidget = new KeyValueWidget(this); + listLayout->insertWidget(listLayout->count() - 1, keyValueWidget); }); } - void populateFromPairs( - std::vector> &pairs) + void populateFromPairs(std::vector> &pairs) { for (auto &pair : pairs) { KeyValueWidget *keyValueWidget = new KeyValueWidget; QLineEdit *keyLineEdit = - (QLineEdit *)keyValueWidget->layout() - ->itemAt(0) - ->widget(); + (QLineEdit *)keyValueWidget->layout()->itemAt(0)->widget(); QLineEdit *valueLineEdit = - (QLineEdit *)keyValueWidget->layout() - ->itemAt(1) - ->widget(); - keyLineEdit->setText( - QString::fromStdString(pair.first)); - valueLineEdit->setText( - QString::fromStdString(pair.second)); - listLayout->insertWidget(listLayout->count() - 1, - keyValueWidget); + (QLineEdit *)keyValueWidget->layout()->itemAt(1)->widget(); + keyLineEdit->setText(QString::fromStdString(pair.first)); + valueLineEdit->setText(QString::fromStdString(pair.second)); + listLayout->insertWidget(listLayout->count() - 1, keyValueWidget); } } }; void get_key_value_as_pairs_from_key_value_list_widget( - KeyValueListWidget *widget, - std::vector> &pairs) + KeyValueListWidget *widget, std::vector> &pairs) { pairs.clear(); for (int i = 0; i < widget->layout()->count() - 1; i++) { KeyValueWidget *keyValueWidget = (KeyValueWidget *)widget->layout()->itemAt(i)->widget(); - QLineEdit *keyLineEdit = (QLineEdit *)keyValueWidget->layout() - ->itemAt(0) - ->widget(); - QLineEdit *valueLineEdit = (QLineEdit *)keyValueWidget->layout() - ->itemAt(1) - ->widget(); - pairs.push_back( - std::make_pair(keyLineEdit->text().toStdString(), - valueLineEdit->text().toStdString())); + QLineEdit *keyLineEdit = (QLineEdit *)keyValueWidget->layout()->itemAt(0)->widget(); + QLineEdit *valueLineEdit = + (QLineEdit *)keyValueWidget->layout()->itemAt(1)->widget(); + pairs.push_back(std::make_pair(keyLineEdit->text().toStdString(), + valueLineEdit->text().toStdString())); } } RequestBuilder::RequestBuilder(url_source_request_data *request_data, - std::function update_handler, - QWidget *parent) + std::function update_handler, QWidget *parent) : QDialog(parent), layout(new QVBoxLayout) { setWindowTitle("HTTP Request Builder"); @@ -124,8 +107,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, methodComboBox->addItem("POST"); formLayout->addRow("Method:", methodComboBox); // set value from request_data - methodComboBox->setCurrentText( - QString::fromStdString(request_data->method)); + methodComboBox->setCurrentText(QString::fromStdString(request_data->method)); connect(methodComboBox, &QComboBox::currentTextChanged, this, [=]() { // If method is not GET, show the body input if (methodComboBox->currentText() != "GET") { @@ -163,74 +145,54 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, formOutputParsing->addRow("Content-Type", outputTypeComboBox); QLineEdit *outputJSONPathLineEdit = new QLineEdit; - outputJSONPathLineEdit->setText( - QString::fromStdString(request_data->output_json_path)); + outputJSONPathLineEdit->setText(QString::fromStdString(request_data->output_json_path)); formOutputParsing->addRow("JSON Pointer", outputJSONPathLineEdit); QLineEdit *outputXPathLineEdit = new QLineEdit; - outputXPathLineEdit->setText( - QString::fromStdString(request_data->output_xpath)); + outputXPathLineEdit->setText(QString::fromStdString(request_data->output_xpath)); formOutputParsing->addRow("XPath", outputXPathLineEdit); formOutputParsing->setRowVisible(outputXPathLineEdit, false); QLineEdit *outputRegexLineEdit = new QLineEdit; - outputRegexLineEdit->setText( - QString::fromStdString(request_data->output_regex)); + outputRegexLineEdit->setText(QString::fromStdString(request_data->output_regex)); formOutputParsing->addRow("Regex", outputRegexLineEdit); formOutputParsing->setRowVisible(outputRegexLineEdit, false); QLineEdit *outputRegexFlagsLineEdit = new QLineEdit; - outputRegexFlagsLineEdit->setText( - QString::fromStdString(request_data->output_regex_flags)); + outputRegexFlagsLineEdit->setText(QString::fromStdString(request_data->output_regex_flags)); formOutputParsing->addRow("Regex flags", outputRegexFlagsLineEdit); formOutputParsing->setRowVisible(outputRegexFlagsLineEdit, false); QLineEdit *outputRegexGroupLineEdit = new QLineEdit; - outputRegexGroupLineEdit->setText( - QString::fromStdString(request_data->output_regex_group)); + outputRegexGroupLineEdit->setText(QString::fromStdString(request_data->output_regex_group)); formOutputParsing->addRow("Regex group", outputRegexGroupLineEdit); formOutputParsing->setRowVisible(outputRegexGroupLineEdit, false); connect(outputTypeComboBox, &QComboBox::currentTextChanged, this, [=]() { if (outputTypeComboBox->currentText() == "JSON") { // Show the JSONPath input, hide others - formOutputParsing->setRowVisible(outputJSONPathLineEdit, - true); - formOutputParsing->setRowVisible(outputXPathLineEdit, - false); - formOutputParsing->setRowVisible(outputRegexLineEdit, - false); - formOutputParsing->setRowVisible( - outputRegexFlagsLineEdit, false); - formOutputParsing->setRowVisible( - outputRegexGroupLineEdit, false); + formOutputParsing->setRowVisible(outputJSONPathLineEdit, true); + formOutputParsing->setRowVisible(outputXPathLineEdit, false); + formOutputParsing->setRowVisible(outputRegexLineEdit, false); + formOutputParsing->setRowVisible(outputRegexFlagsLineEdit, false); + formOutputParsing->setRowVisible(outputRegexGroupLineEdit, false); } // If XML or HTML is selected as the output type, show the XPath input if (outputTypeComboBox->currentText() == "XML" || outputTypeComboBox->currentText() == "HTML") { // Show the XPath input, hide others - formOutputParsing->setRowVisible(outputJSONPathLineEdit, - false); - formOutputParsing->setRowVisible(outputXPathLineEdit, - true); - formOutputParsing->setRowVisible(outputRegexLineEdit, - false); - formOutputParsing->setRowVisible( - outputRegexFlagsLineEdit, false); - formOutputParsing->setRowVisible( - outputRegexGroupLineEdit, false); + formOutputParsing->setRowVisible(outputJSONPathLineEdit, false); + formOutputParsing->setRowVisible(outputXPathLineEdit, true); + formOutputParsing->setRowVisible(outputRegexLineEdit, false); + formOutputParsing->setRowVisible(outputRegexFlagsLineEdit, false); + formOutputParsing->setRowVisible(outputRegexGroupLineEdit, false); } // If text is selected as the output type, show the regex input if (outputTypeComboBox->currentText() == "Text") { // Show the regex input, hide others - formOutputParsing->setRowVisible(outputJSONPathLineEdit, - false); - formOutputParsing->setRowVisible(outputXPathLineEdit, - false); - formOutputParsing->setRowVisible(outputRegexLineEdit, - true); - formOutputParsing->setRowVisible( - outputRegexFlagsLineEdit, true); - formOutputParsing->setRowVisible( - outputRegexGroupLineEdit, true); + formOutputParsing->setRowVisible(outputJSONPathLineEdit, false); + formOutputParsing->setRowVisible(outputXPathLineEdit, false); + formOutputParsing->setRowVisible(outputRegexLineEdit, true); + formOutputParsing->setRowVisible(outputRegexFlagsLineEdit, true); + formOutputParsing->setRowVisible(outputRegexGroupLineEdit, true); } }); @@ -244,43 +206,35 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, layout->addWidget(errorMessageLabel); // Lambda to save the request settings to a request_data struct - auto saveSettingsToRequestData = - [=](url_source_request_data *request_data_for_saving) { - // Save the request settings to the request_data struct - request_data_for_saving->url = - urlLineEdit->text().toStdString(); - request_data_for_saving->method = - methodComboBox->currentText().toStdString(); - request_data_for_saving->body = - bodyLineEdit->text().toStdString(); - - // Save the headers - get_key_value_as_pairs_from_key_value_list_widget( - headersWidget, - request_data_for_saving->headers); - - // Save the output parsing options - request_data_for_saving->output_type = - outputTypeComboBox->currentText().toStdString(); - request_data_for_saving->output_json_path = - outputJSONPathLineEdit->text().toStdString(); - request_data_for_saving->output_xpath = - outputXPathLineEdit->text().toStdString(); - request_data_for_saving->output_regex = - outputRegexLineEdit->text().toStdString(); - request_data_for_saving->output_regex_flags = - outputRegexFlagsLineEdit->text().toStdString(); - request_data_for_saving->output_regex_group = - outputRegexGroupLineEdit->text().toStdString(); - }; + auto saveSettingsToRequestData = [=](url_source_request_data *request_data_for_saving) { + // Save the request settings to the request_data struct + request_data_for_saving->url = urlLineEdit->text().toStdString(); + request_data_for_saving->method = methodComboBox->currentText().toStdString(); + request_data_for_saving->body = bodyLineEdit->text().toStdString(); + + // Save the headers + get_key_value_as_pairs_from_key_value_list_widget(headersWidget, + request_data_for_saving->headers); + + // Save the output parsing options + request_data_for_saving->output_type = + outputTypeComboBox->currentText().toStdString(); + request_data_for_saving->output_json_path = + outputJSONPathLineEdit->text().toStdString(); + request_data_for_saving->output_xpath = outputXPathLineEdit->text().toStdString(); + request_data_for_saving->output_regex = outputRegexLineEdit->text().toStdString(); + request_data_for_saving->output_regex_flags = + outputRegexFlagsLineEdit->text().toStdString(); + request_data_for_saving->output_regex_group = + outputRegexGroupLineEdit->text().toStdString(); + }; connect(sendButton, &QPushButton::clicked, this, [=]() { // Hide the error message label errorMessageLabel->setVisible(false); // Get an interim request_data struct with the current settings - url_source_request_data *request_data_test = - new url_source_request_data; + url_source_request_data *request_data_test = new url_source_request_data; saveSettingsToRequestData(request_data_test); // Send the request @@ -289,8 +243,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, if (response.status_code == -1) { // Show the error message label - errorMessageLabel->setText( - QString::fromStdString(response.error_message)); + errorMessageLabel->setText(QString::fromStdString(response.error_message)); errorMessageLabel->setVisible(true); return; } @@ -303,8 +256,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, responseDialog->show(); // Add scroll area for the response body QScrollArea *responseBodyScrollArea = new QScrollArea; - QLabel *responseLabel = - new QLabel(QString::fromStdString(response.body)); + QLabel *responseLabel = new QLabel(QString::fromStdString(response.body)); // Wrap the text responseLabel->setWordWrap(true); // Set the label as the scroll area's widget @@ -313,13 +265,12 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data, // If there's a parsed output, add it to the dialog in a QGroupBox if (response.body_parsed != "") { - QGroupBox *parsedOutputGroupBox = - new QGroupBox("Parsed Output"); + QGroupBox *parsedOutputGroupBox = new QGroupBox("Parsed Output"); responseLayout->addWidget(parsedOutputGroupBox); QVBoxLayout *parsedOutputLayout = new QVBoxLayout; parsedOutputGroupBox->setLayout(parsedOutputLayout); - parsedOutputLayout->addWidget(new QLabel( - QString::fromStdString(response.body_parsed))); + parsedOutputLayout->addWidget( + new QLabel(QString::fromStdString(response.body_parsed))); } // Resize the dialog to fit the text diff --git a/src/ui/RequestBuilder.h b/src/ui/RequestBuilder.h index 7813df4..1dfeb7f 100644 --- a/src/ui/RequestBuilder.h +++ b/src/ui/RequestBuilder.h @@ -7,8 +7,7 @@ class RequestBuilder : public QDialog { public: RequestBuilder(url_source_request_data *request_data, // update handler lambda function - std::function update_handler, - QWidget *parent = nullptr); + std::function update_handler, QWidget *parent = nullptr); private: QVBoxLayout *layout; diff --git a/src/ui/text-render-helper.cpp b/src/ui/text-render-helper.cpp index 0d4160a..9467998 100644 --- a/src/ui/text-render-helper.cpp +++ b/src/ui/text-render-helper.cpp @@ -24,12 +24,11 @@ const QString template_text = R"( * @param height Output height * @param data Output buffer, user must free */ -void render_text_with_qtextdocument(std::string &text, uint32_t &width, - uint32_t &height, uint8_t **data) +void render_text_with_qtextdocument(std::string &text, uint32_t &width, uint32_t &height, + uint8_t **data) { // apply response in template - QString html = QString(template_text) - .replace("{text}", QString::fromStdString(text)); + QString html = QString(template_text).replace("{text}", QString::fromStdString(text)); QTextDocument textDocument; textDocument.setHtml(html); diff --git a/src/ui/text-render-helper.h b/src/ui/text-render-helper.h index cffd745..5e3f9f0 100644 --- a/src/ui/text-render-helper.h +++ b/src/ui/text-render-helper.h @@ -1,7 +1,7 @@ #ifndef TEXT_RENDER_HELPER_H #define TEXT_RENDER_HELPER_H -void render_text_with_qtextdocument(std::string &text, uint32_t &width, - uint32_t &height, uint8_t **data); +void render_text_with_qtextdocument(std::string &text, uint32_t &width, uint32_t &height, + uint8_t **data); #endif // TEXT_RENDER_HELPER_H diff --git a/src/url-source.cpp b/src/url-source.cpp index f84b117..e3c8a1a 100644 --- a/src/url-source.cpp +++ b/src/url-source.cpp @@ -20,7 +20,7 @@ with this program. If not, see #include #include #include -#include +#include #include #include "ui/RequestBuilder.h" @@ -49,8 +49,7 @@ static const char *url_source_name(void *unused) static void url_source_destroy(void *data) { - struct url_source_data *usd = - reinterpret_cast(data); + struct url_source_data *usd = reinterpret_cast(data); { std::lock_guard lock(curl_mutex); @@ -69,13 +68,7 @@ void curl_loop(struct url_source_data *usd) uint64_t cur_time = os_gettime_ns(); uint64_t start_time = cur_time; - struct obs_source_frame frame = { - .data = {[0] = (uint8_t *)nullptr}, - .linesize = {[0] = 20 * 4}, - .width = 20, - .height = 20, - .format = VIDEO_FORMAT_BGRX, - }; + struct obs_source_frame frame = {}; while (true) { { @@ -96,8 +89,7 @@ void curl_loop(struct url_source_data *usd) uint32_t width = 0; uint32_t height = 0; uint8_t *renderBuffer = nullptr; - render_text_with_qtextdocument(response.body_parsed, - width, height, + render_text_with_qtextdocument(response.body_parsed, width, height, &renderBuffer); // Update the frame frame.data[0] = renderBuffer; @@ -115,8 +107,7 @@ void curl_loop(struct url_source_data *usd) } // Sleep for n ms as per the update timer - std::this_thread::sleep_for( - std::chrono::milliseconds(usd->update_timer_ms)); + std::this_thread::sleep_for(std::chrono::milliseconds(usd->update_timer_ms)); } obs_log(LOG_INFO, "Stopping URL Source thread"); } @@ -124,13 +115,11 @@ void curl_loop(struct url_source_data *usd) static void *url_source_create(obs_data_t *settings, obs_source_t *source) { struct url_source_data *usd = - reinterpret_cast( - bzalloc(sizeof(struct url_source_data))); + reinterpret_cast(bzalloc(sizeof(struct url_source_data))); usd->source = source; // get request data from settings - std::string serialized_request_data = - obs_data_get_string(settings, "request_data"); + std::string serialized_request_data = obs_data_get_string(settings, "request_data"); if (serialized_request_data.empty()) { // Default request data usd->request_data.url = "https://catfact.ninja/fact"; @@ -138,15 +127,12 @@ static void *url_source_create(obs_data_t *settings, obs_source_t *source) usd->request_data.output_type = "json"; usd->request_data.output_json_path = "fact"; // serialize request data - std::string serialized_request_data = - serialize_request_data(&(usd->request_data)); + std::string serialized_request_data = serialize_request_data(&(usd->request_data)); // Save on settings - obs_data_set_string(settings, "request_data", - serialized_request_data.c_str()); + obs_data_set_string(settings, "request_data", serialized_request_data.c_str()); } else { // Unserialize request data - usd->request_data = - unserialize_request_data(serialized_request_data); + usd->request_data = unserialize_request_data(serialized_request_data); } // start the thread @@ -159,18 +145,14 @@ static void *url_source_create(obs_data_t *settings, obs_source_t *source) static void url_source_update(void *data, obs_data_t *settings) { obs_log(LOG_INFO, "Updating URL Source"); - struct url_source_data *usd = - reinterpret_cast(data); + struct url_source_data *usd = reinterpret_cast(data); // Update the request data from the settings - usd->update_timer_ms = - (uint32_t)obs_data_get_int(settings, "update_timer"); + usd->update_timer_ms = (uint32_t)obs_data_get_int(settings, "update_timer"); // serialize request data - std::string serialized_request_data = - serialize_request_data(&(usd->request_data)); + std::string serialized_request_data = serialize_request_data(&(usd->request_data)); // Save on settings - obs_data_set_string(settings, "request_data", - serialized_request_data.c_str()); + obs_data_set_string(settings, "request_data", serialized_request_data.c_str()); } static void url_source_defaults(obs_data_t *s) @@ -183,13 +165,11 @@ static void url_source_defaults(obs_data_t *s) static obs_properties_t *url_source_properties(void *data) { - struct url_source_data *usd = - reinterpret_cast(data); + struct url_source_data *usd = reinterpret_cast(data); obs_properties_t *ppts = obs_properties_create(); // URL input string - obs_property_t *urlprop = - obs_properties_add_text(ppts, "url", "URL", OBS_TEXT_DEFAULT); + obs_property_t *urlprop = obs_properties_add_text(ppts, "url", "URL", OBS_TEXT_DEFAULT); // Disable the URL input since it's setup via the Request Builder dialog obs_property_set_enabled(urlprop, false); @@ -197,30 +177,23 @@ static obs_properties_t *url_source_properties(void *data) ppts, "button", "Setup Request", [](obs_properties_t *, obs_property_t *, void *button_data) { struct url_source_data *button_usd = - reinterpret_cast( - button_data); + reinterpret_cast(button_data); // Open the Request Builder dialog RequestBuilder *builder = new RequestBuilder( &(button_usd->request_data), [=]() { // Update the request data from the settings obs_data_t *settings = - obs_source_get_settings( - button_usd->source); + obs_source_get_settings(button_usd->source); // serialize request data std::string serialized_request_data = - serialize_request_data(&( - button_usd - ->request_data)); + serialize_request_data(&(button_usd->request_data)); // Save on settings - obs_data_set_string( - settings, "request_data", - serialized_request_data.c_str()); + obs_data_set_string(settings, "request_data", + serialized_request_data.c_str()); // Update the URL input string - obs_data_set_string( - settings, "url", - button_usd->request_data.url - .c_str()); + obs_data_set_string(settings, "url", + button_usd->request_data.url.c_str()); }, (QWidget *)obs_frontend_get_main_window()); builder->show(); @@ -229,8 +202,7 @@ static obs_properties_t *url_source_properties(void *data) usd); // Update timer setting in milliseconds - obs_properties_add_int(ppts, "update_timer", "Update Timer (ms)", 100, - 10000, 100); + obs_properties_add_int(ppts, "update_timer", "Update Timer (ms)", 100, 10000, 100); return ppts; } @@ -242,9 +214,8 @@ static uint32_t url_source_size(void *data) } struct obs_source_info url_source { - .id = "url_source", .type = OBS_SOURCE_TYPE_INPUT, - .output_flags = OBS_SOURCE_ASYNC_VIDEO, .get_name = url_source_name, - .create = url_source_create, .destroy = url_source_destroy, - .get_defaults = url_source_defaults, - .get_properties = url_source_properties, .update = url_source_update + .id = "url_source", .type = OBS_SOURCE_TYPE_INPUT, .output_flags = OBS_SOURCE_ASYNC_VIDEO, + .get_name = url_source_name, .create = url_source_create, .destroy = url_source_destroy, + .get_defaults = url_source_defaults, .get_properties = url_source_properties, + .update = url_source_update };