2018-06-26 14:09:39 +02:00
|
|
|
#include "QualityPopup.hpp"
|
2020-10-31 16:42:48 +01:00
|
|
|
#include "Application.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2020-10-31 16:42:48 +01:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/StreamLink.hpp"
|
2020-10-31 16:42:48 +01:00
|
|
|
#include "widgets/Window.hpp"
|
2017-09-11 23:35:59 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-03-24 14:13:04 +01:00
|
|
|
QualityPopup::QualityPopup(const QString &_channelName, QStringList options)
|
2020-10-31 16:42:48 +01:00
|
|
|
: BasePopup({},
|
|
|
|
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
|
|
|
|
, channelName_(_channelName)
|
2017-09-11 23:35:59 +02:00
|
|
|
{
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.okButton.setText("OK");
|
|
|
|
this->ui_.cancelButton.setText("Cancel");
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
QObject::connect(&this->ui_.okButton, &QPushButton::clicked, this,
|
2017-12-17 16:45:15 +01:00
|
|
|
&QualityPopup::okButtonClicked);
|
2018-06-11 15:04:54 +02:00
|
|
|
QObject::connect(&this->ui_.cancelButton, &QPushButton::clicked, this,
|
2017-12-17 16:45:15 +01:00
|
|
|
&QualityPopup::cancelButtonClicked);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.buttonBox.addButton(&this->ui_.okButton,
|
|
|
|
QDialogButtonBox::ButtonRole::AcceptRole);
|
2018-06-26 17:20:03 +02:00
|
|
|
this->ui_.buttonBox.addButton(&this->ui_.cancelButton,
|
|
|
|
QDialogButtonBox::ButtonRole::RejectRole);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.selector.addItems(options);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->ui_.vbox.addWidget(&this->ui_.selector);
|
|
|
|
this->ui_.vbox.addWidget(&this->ui_.buttonBox);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
this->setLayout(&this->ui_.vbox);
|
2017-09-11 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
2018-03-24 14:13:04 +01:00
|
|
|
void QualityPopup::showDialog(const QString &channelName, QStringList options)
|
2017-12-17 16:45:15 +01:00
|
|
|
{
|
2018-03-24 14:13:04 +01:00
|
|
|
QualityPopup *instance = new QualityPopup(channelName, options);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2020-10-31 15:12:42 +01:00
|
|
|
instance->window()->setWindowTitle("Chatterino - select stream quality");
|
2018-01-28 18:05:01 +01:00
|
|
|
instance->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
2017-09-11 23:35:59 +02:00
|
|
|
instance->show();
|
|
|
|
instance->activateWindow();
|
|
|
|
instance->raise();
|
|
|
|
instance->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-12-17 16:45:15 +01:00
|
|
|
void QualityPopup::okButtonClicked()
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
QString channelURL = "twitch.tv/" + this->channelName_;
|
2018-03-24 14:13:04 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
try
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
openStreamlink(channelURL, this->ui_.selector.currentText());
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
catch (const Exception &ex)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCWarning(chatterinoWidget)
|
|
|
|
<< "Exception caught trying to open streamlink:" << ex.what();
|
2018-03-24 14:13:04 +01:00
|
|
|
}
|
|
|
|
|
2017-09-11 23:35:59 +02:00
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QualityPopup::cancelButtonClicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
2017-12-17 16:45:15 +01:00
|
|
|
} // namespace chatterino
|