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 {
|
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
QualityPopup::QualityPopup(const QString &channelURL, QStringList options)
|
2020-10-31 16:42:48 +01:00
|
|
|
: BasePopup({},
|
|
|
|
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
|
2021-08-15 15:59:52 +02:00
|
|
|
, channelURL_(channelURL)
|
2017-09-11 23:35:59 +02:00
|
|
|
{
|
2021-08-15 15:59:52 +02:00
|
|
|
this->ui_.selector = new QComboBox(this);
|
|
|
|
this->ui_.vbox = new QVBoxLayout(this);
|
|
|
|
this->ui_.buttonBox = new QDialogButtonBox(
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
QObject::connect(this->ui_.buttonBox, &QDialogButtonBox::accepted, this,
|
2017-12-17 16:45:15 +01:00
|
|
|
&QualityPopup::okButtonClicked);
|
2021-08-15 15:59:52 +02:00
|
|
|
QObject::connect(this->ui_.buttonBox, &QDialogButtonBox::rejected, this,
|
2017-12-17 16:45:15 +01:00
|
|
|
&QualityPopup::cancelButtonClicked);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
this->ui_.selector->addItems(options);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
this->ui_.vbox->addWidget(this->ui_.selector);
|
|
|
|
this->ui_.vbox->addWidget(this->ui_.buttonBox);
|
2017-09-11 23:35:59 +02:00
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
this->setLayout(this->ui_.vbox);
|
2017-09-11 23:35:59 +02:00
|
|
|
}
|
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
void QualityPopup::showDialog(const QString &channelURL, QStringList options)
|
2017-12-17 16:45:15 +01:00
|
|
|
{
|
2021-08-15 15:59:52 +02:00
|
|
|
QualityPopup *instance = new QualityPopup(channelURL, 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();
|
|
|
|
}
|
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
void QualityPopup::keyPressEvent(QKeyEvent *e)
|
2017-12-17 16:45:15 +01:00
|
|
|
{
|
2021-08-15 15:59:52 +02:00
|
|
|
if (this->handleEscape(e, this->ui_.buttonBox))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this->handleEnter(e, this->ui_.buttonBox))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BasePopup::keyPressEvent(e);
|
|
|
|
}
|
2018-03-24 14:13:04 +01:00
|
|
|
|
2021-08-15 15:59:52 +02:00
|
|
|
void QualityPopup::okButtonClicked()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
try
|
|
|
|
{
|
2021-08-15 15:59:52 +02:00
|
|
|
openStreamlink(this->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
|