mirror-chatterino2/src/widgets/dialogs/QualityPopup.cpp

80 lines
2 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "QualityPopup.hpp"
#include "Application.hpp"
#include "common/QLogging.hpp"
#include "singletons/WindowManager.hpp"
2018-06-26 14:09:39 +02:00
#include "util/StreamLink.hpp"
#include "widgets/Window.hpp"
namespace chatterino {
QualityPopup::QualityPopup(const QString &channelURL, QStringList options)
: BasePopup({},
static_cast<QWidget *>(&(getApp()->windows->getMainWindow())))
, channelURL_(channelURL)
{
this->ui_.selector = new QComboBox(this);
this->ui_.vbox = new QVBoxLayout(this);
this->ui_.buttonBox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
QObject::connect(this->ui_.buttonBox, &QDialogButtonBox::accepted, this,
2017-12-17 16:45:15 +01:00
&QualityPopup::okButtonClicked);
QObject::connect(this->ui_.buttonBox, &QDialogButtonBox::rejected, this,
2017-12-17 16:45:15 +01:00
&QualityPopup::cancelButtonClicked);
this->ui_.selector->addItems(options);
this->ui_.vbox->addWidget(this->ui_.selector);
this->ui_.vbox->addWidget(this->ui_.buttonBox);
this->setLayout(this->ui_.vbox);
}
void QualityPopup::showDialog(const QString &channelURL, QStringList options)
2017-12-17 16:45:15 +01:00
{
QualityPopup *instance = new QualityPopup(channelURL, options);
instance->window()->setWindowTitle("Chatterino - select stream quality");
2018-01-28 18:05:01 +01:00
instance->setAttribute(Qt::WA_DeleteOnClose, true);
instance->show();
instance->activateWindow();
instance->raise();
}
void QualityPopup::keyPressEvent(QKeyEvent *e)
2017-12-17 16:45:15 +01:00
{
if (this->handleEscape(e, this->ui_.buttonBox))
{
return;
}
if (this->handleEnter(e, this->ui_.buttonBox))
{
return;
}
BasePopup::keyPressEvent(e);
}
void QualityPopup::okButtonClicked()
{
2018-10-21 13:43:02 +02:00
try
{
openStreamlink(this->channelURL_, this->ui_.selector->currentText());
2018-10-21 13:43:02 +02:00
}
catch (const Exception &ex)
{
qCWarning(chatterinoWidget)
<< "Exception caught trying to open streamlink:" << ex.what();
}
this->close();
}
void QualityPopup::cancelButtonClicked()
{
this->close();
}
2017-12-17 16:45:15 +01:00
} // namespace chatterino