From a054d60f66d553af86c2277cfe50b37451a79b8f Mon Sep 17 00:00:00 2001 From: David Marsh Date: Fri, 26 Jul 2024 14:18:09 +0100 Subject: [PATCH] Abstract platform icons into utils --- CMakeLists.txt | 2 ++ config-dialog.cpp | 27 ++------------------ config-dialog.hpp | 11 --------- config-utils.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++ config-utils.hpp | 20 +++++++++++++++ data/locale/en-US.ini | 2 +- multistream.cpp | 32 ++++-------------------- multistream.hpp | 11 --------- 8 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 config-utils.cpp create mode 100644 config-utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 43d0944..4515b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,11 +51,13 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_SOURCE_D target_sources(${PROJECT_NAME} PRIVATE config-dialog.cpp + config-utils.cpp output-dialog.cpp multistream.cpp file-updater.c resources.qrc config-dialog.hpp + config-utils.hpp output-dialog.hpp multistream.hpp file-updater.h) diff --git a/config-dialog.cpp b/config-dialog.cpp index 59836ed..67ef113 100644 --- a/config-dialog.cpp +++ b/config-dialog.cpp @@ -29,6 +29,7 @@ #include #include #include "output-dialog.hpp" +#include "config-utils.hpp" template std::string to_string_with_precision(const T a_value, const int n = 6) { @@ -41,30 +42,6 @@ template std::string to_string_with_precision(const T a_value, const void RemoveWidget(QWidget *widget); void RemoveLayoutItem(QLayoutItem *item); -// Platform icons deciphered from endpoints -QIcon OBSBasicSettings::getPlatformFromEndpoint(QString endpoint) -{ - - if (endpoint.contains(QString::fromUtf8(".contribute.live-video.net")) || - endpoint.contains(QString::fromUtf8(".twitch.tv"))) { // twitch - return platformIconTwitch; - } else if (endpoint.contains(QString::fromUtf8(".youtube.com"))) { // youtube - return platformIconYouTube; - } else if (endpoint.contains(QString::fromUtf8("fa723fc1b171.global-contribute.live-video.net"))) { // kick - return platformIconKick; - } else if (endpoint.contains(QString::fromUtf8(".tiktokcdn-"))) { // tiktok - return platformIconTikTok; - } else if (endpoint.contains(QString::fromUtf8(".pscp.tv"))) { // twitter - return platformIconTwitter; - } else if (endpoint.contains(QString::fromUtf8("livepush.trovo.live"))) { // trovo - return platformIconTrovo; - } else if (endpoint.contains(QString::fromUtf8(".facebook.com"))) { // facebook - return platformIconFacebook; - } else { // unknown - return platformIconUnknown; - } -} - OBSBasicSettings::OBSBasicSettings(QMainWindow *parent) : QDialog(parent) { setMinimumWidth(983); @@ -438,7 +415,7 @@ void OBSBasicSettings::AddServer(QFormLayout *outputsLayout, obs_data_t *setting auto server_title_layout = new QHBoxLayout; auto platformIconLabel = new QLabel; - auto platformIcon = getPlatformFromEndpoint(QString::fromUtf8(obs_data_get_string(settings, "stream_server"))); + auto platformIcon = ConfigUtils::getPlatformIconFromEndpoint(QString::fromUtf8(obs_data_get_string(settings, "stream_server"))); platformIconLabel->setPixmap(platformIcon.pixmap(30, 30)); server_title_layout->addWidget(platformIconLabel, 0); diff --git a/config-dialog.hpp b/config-dialog.hpp index 31dc882..58c8773 100644 --- a/config-dialog.hpp +++ b/config-dialog.hpp @@ -55,17 +55,6 @@ private: QPushButton *verticalAddButton; - // Platform icons - QIcon platformIconTwitch = QIcon(":/aitum/media/twitch.png"); - QIcon platformIconYouTube = QIcon(":/aitum/media/youtube.png"); - QIcon platformIconKick = QIcon(":/aitum/media/kick.png"); - QIcon platformIconTikTok = QIcon(":/aitum/media/tiktok.png"); - QIcon platformIconTwitter = QIcon(":/aitum/media/twitter.png"); - QIcon platformIconTrovo = QIcon(":/aitum/media/trovo.png"); - QIcon platformIconFacebook = QIcon(":/aitum/media/facebook.png"); - QIcon platformIconUnknown = QIcon(":/aitum/media/unknown.png"); - QIcon getPlatformFromEndpoint(QString endpoint); - private slots: void SetGeneralIcon(const QIcon &icon); void SetStreamIcon(const QIcon &icon); diff --git a/config-utils.cpp b/config-utils.cpp new file mode 100644 index 0000000..778edd3 --- /dev/null +++ b/config-utils.cpp @@ -0,0 +1,57 @@ +#include "config-utils.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "obs.h" +#include "obs-module.h" +#include "obs-frontend-api.h" +#include + + +// Generate buttons for default/custom stuff +QPushButton *ConfigUtils::generateButton(QString buttonText) { + auto styles = QString::fromUtf8("QPushButton[unselected=\"true\"] { background: pink; }"); + + auto button = new QPushButton(buttonText); + button->setStyleSheet(styles); + + return button; +} + +// For setting the active property stuff on buttons +void ConfigUtils::updateButtonStyles(QPushButton *defaultButton, QPushButton *customButton, int activeIndex) { + defaultButton->setProperty("unselected", activeIndex != 0 ? true : false); + customButton->setProperty("unselected", activeIndex != 1 ? true : false); +} + + +// Platform icons deciphered from endpoints +QIcon ConfigUtils::getPlatformIconFromEndpoint(QString endpoint) +{ + + if (endpoint.contains(QString::fromUtf8(".contribute.live-video.net")) || + endpoint.contains(QString::fromUtf8(".twitch.tv"))) { // twitch + return QIcon(":/aitum/media/twitch.png"); + } else if (endpoint.contains(QString::fromUtf8(".youtube.com"))) { // youtube + return QIcon(":/aitum/media/youtube.png"); + } else if (endpoint.contains(QString::fromUtf8("fa723fc1b171.global-contribute.live-video.net"))) { // kick + return QIcon(":/aitum/media/kick.png"); + } else if (endpoint.contains(QString::fromUtf8(".tiktokcdn-"))) { // tiktok + return QIcon(":/aitum/media/tiktok.png"); + } else if (endpoint.contains(QString::fromUtf8(".pscp.tv"))) { // twitter + return QIcon(":/aitum/media/twitter.png"); + } else if (endpoint.contains(QString::fromUtf8("livepush.trovo.live"))) { // trovo + return QIcon(":/aitum/media/trovo.png"); + } else if (endpoint.contains(QString::fromUtf8(".facebook.com"))) { // facebook + return QIcon(":/aitum/media/facebook.png"); + } else { // unknown + return QIcon(":/aitum/media/unknown.png"); + } +} diff --git a/config-utils.hpp b/config-utils.hpp new file mode 100644 index 0000000..90ffec0 --- /dev/null +++ b/config-utils.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include "obs.h" + +class ConfigUtils { +public: + static QPushButton *generateButton(QString buttonText); + static void updateButtonStyles(QPushButton *defaultButton, QPushButton *customButton, int activeIndex); + + + static QIcon getPlatformIconFromEndpoint(QString endpoint); +}; diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 560be51..5c5f612 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -24,7 +24,7 @@ Server="Server" Key="Key" Stream="Stream" EditServerSettings="Output Settings" -EditEncoderSettings="Encoder Settings" +EditEncoderSettings="Advanced Settings" BackButton="< Back" SaveOutput="Save Output" CreateOutput="Create Output" diff --git a/multistream.cpp b/multistream.cpp index 8aa1b1b..d3062a6 100644 --- a/multistream.cpp +++ b/multistream.cpp @@ -12,6 +12,8 @@ #include #include #include +#include "config-utils.hpp" + extern "C" { #include "file-updater.h" } @@ -106,30 +108,6 @@ void RemoveWidget(QWidget *widget) delete widget; } -// Platform icons deciphered from endpoints -QIcon MultistreamDock::getPlatformFromEndpoint(QString endpoint) -{ - - if (endpoint.contains(QString::fromUtf8(".contribute.live-video.net")) || - endpoint.contains(QString::fromUtf8(".twitch.tv"))) { // twitch - return platformIconTwitch; - } else if (endpoint.contains(QString::fromUtf8(".youtube.com"))) { // youtube - return platformIconYouTube; - } else if (endpoint.contains(QString::fromUtf8("fa723fc1b171.global-contribute.live-video.net"))) { // kick - return platformIconKick; - } else if (endpoint.contains(QString::fromUtf8(".tiktokcdn-"))) { // tiktok - return platformIconTikTok; - } else if (endpoint.contains(QString::fromUtf8(".pscp.tv"))) { // twitter - return platformIconTwitter; - } else if (endpoint.contains(QString::fromUtf8("livepush.trovo.live"))) { // trovo - return platformIconTrovo; - } else if (endpoint.contains(QString::fromUtf8(".facebook.com"))) { // facebook - return platformIconFacebook; - } else { // unknown - return platformIconUnknown; - } -} - // Output button styling void MultistreamDock::outputButtonStyle(QPushButton *button) { @@ -217,7 +195,7 @@ MultistreamDock::MultistreamDock(QWidget *parent) : QFrame(parent) // blank because we're not pulling settings through from bis, fix this mainPlatformIconLabel = new QLabel; - auto platformIcon = getPlatformFromEndpoint(QString::fromUtf8("")); + auto platformIcon = ConfigUtils::getPlatformIconFromEndpoint(QString::fromUtf8("")); mainPlatformIconLabel->setPixmap(platformIcon.pixmap(30, 30)); @@ -362,7 +340,7 @@ MultistreamDock::MultistreamDock(QWidget *parent) : QFrame(parent) auto url = QString::fromUtf8(obs_service_get_connect_info(service, OBS_SERVICE_CONNECT_INFO_SERVER_URL)); if (url != mainPlatformUrl) { mainPlatformUrl = url; - auto platformIcon = getPlatformFromEndpoint(url); + auto platformIcon = ConfigUtils::getPlatformIconFromEndpoint(url); mainPlatformIconLabel->setPixmap(platformIcon.pixmap(30, 30)); } @@ -572,7 +550,7 @@ void MultistreamDock::LoadOutput(obs_data_t *data, bool vertical) auto l2 = new QHBoxLayout; auto platformIconLabel = new QLabel; - auto platformIcon = getPlatformFromEndpoint(endpoint); + auto platformIcon = ConfigUtils::getPlatformIconFromEndpoint(endpoint); platformIconLabel->setPixmap(platformIcon.pixmap(30, 30)); diff --git a/multistream.hpp b/multistream.hpp index 09e32a0..a543d42 100644 --- a/multistream.hpp +++ b/multistream.hpp @@ -48,20 +48,9 @@ private: void storeMainStreamEncoders(); QStringList mainEncoderDescriptions = QStringList(MAX_OUTPUT_VIDEO_ENCODERS); - QIcon getPlatformFromEndpoint(QString endpoint); - QIcon streamActiveIcon = QIcon(":/aitum/media/streaming.svg"); QIcon streamInactiveIcon = QIcon(":/aitum/media/stream.svg"); - // Platform icons - QIcon platformIconTwitch = QIcon(":/aitum/media/twitch.png"); - QIcon platformIconYouTube = QIcon(":/aitum/media/youtube.png"); - QIcon platformIconKick = QIcon(":/aitum/media/kick.png"); - QIcon platformIconTikTok = QIcon(":/aitum/media/tiktok.png"); - QIcon platformIconTwitter = QIcon(":/aitum/media/twitter.png"); - QIcon platformIconTrovo = QIcon(":/aitum/media/trovo.png"); - QIcon platformIconFacebook = QIcon(":/aitum/media/facebook.png"); - QIcon platformIconUnknown = QIcon(":/aitum/media/unknown.png"); static void frontend_event(enum obs_frontend_event event, void *private_data);