From 8d5717df7cb577adee7bc00a4859634a56d53e89 Mon Sep 17 00:00:00 2001 From: zneix Date: Sat, 14 Aug 2021 17:34:06 +0200 Subject: [PATCH] xd --- src/util/StreamLink.cpp | 65 +++++++++++++++++++++++++++++++++++++++-- src/util/StreamLink.hpp | 3 ++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index 2ac42cfa6..3f8c03a6a 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -2,8 +2,11 @@ #include "Application.hpp" #include "singletons/Settings.hpp" +#include "singletons/WindowManager.hpp" +#include "util/CombinePath.hpp" #include "util/Helpers.hpp" #include "util/SplitCommand.hpp" +#include "widgets/Window.hpp" #include "widgets/dialogs/QualityPopup.hpp" #include @@ -39,7 +42,7 @@ namespace { { if (getSettings()->streamlinkUseCustomPath) { - return getSettings()->streamlinkPath + "/" + getBinaryName(); + return combinePath(getSettings()->streamlinkPath, getBinaryName()); } else { @@ -200,7 +203,7 @@ void openStreamlinkForChannel(const QString &channel) if (preferredQuality == "choose") { getStreamQualities(channelURL, [=](QStringList qualityOptions) { - QualityPopup::showDialog(channel, qualityOptions); + showStreamlinkQualityDialog(channelURL, qualityOptions); }); return; @@ -244,4 +247,62 @@ void openStreamlinkForChannel(const QString &channel) openStreamlink(channelURL, quality, args); } +void showStreamlinkQualityDialog(const QString &channelURL, + QStringList &options) +{ + auto dialog = new QDialog( + static_cast(&(getApp()->windows->getMainWindow()))); + + auto vbox = new QVBoxLayout; + + // dropdown with options + auto dropdown = QComboBox(dialog); + dropdown.addItems(options); + + // buttons + auto buttonBox = + new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QObject::connect(buttonBox, &QDialogButtonBox::accepted, [dialog] { + dialog->accept(); + dialog->close(); + }); + + QObject::connect(buttonBox, &QDialogButtonBox::rejected, [dialog] { + dialog->reject(); + dialog->close(); + }); + + // Assign layout + vbox->addWidget(&dropdown); + vbox->addWidget(buttonBox); + + dialog->setLayout(vbox); + dialog->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + dialog->setWindowFlags( + (dialog->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) | + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + + // Adjust dialog's width to fit the title + QString title = "Chatterino - select stream quality"; + QFontMetrics titleMetrics(dialog->font()); + dialog->setWindowTitle(title); + dialog->setMinimumSize(titleMetrics.horizontalAdvance(title) + 50, + dialog->minimumSizeHint().height() + 10); + + if (dialog->exec() == QDialog::Accepted) + { + try + { + openStreamlink(channelURL, dropdown.currentText()); + } + catch (const Exception &ex) + { + qCWarning(chatterinoWidget) + << "Exception caught trying to open streamlink:" << ex.what(); + } + } +} + } // namespace chatterino diff --git a/src/util/StreamLink.hpp b/src/util/StreamLink.hpp index 99dbb95b9..38f02dadf 100644 --- a/src/util/StreamLink.hpp +++ b/src/util/StreamLink.hpp @@ -24,4 +24,7 @@ void openStreamlink(const QString &channelURL, const QString &quality, // from settings and opening a quality dialog if the quality is "Choose" void openStreamlinkForChannel(const QString &channel); +void showStreamlinkQualityDialog(const QString &channelName, + QStringList &options); + } // namespace chatterino