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

61 lines
1.7 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "QualityPopup.hpp"
#include "debug/Log.hpp"
#include "util/StreamLink.hpp"
namespace chatterino {
QualityPopup::QualityPopup(const QString &_channelName, QStringList options)
2018-07-06 19:23:47 +02:00
: channelName_(_channelName)
{
2018-06-11 15:04:54 +02:00
this->ui_.okButton.setText("OK");
this->ui_.cancelButton.setText("Cancel");
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);
2018-06-11 15:04:54 +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);
2018-06-11 15:04:54 +02:00
this->ui_.selector.addItems(options);
2018-06-11 15:04:54 +02:00
this->ui_.vbox.addWidget(&this->ui_.selector);
this->ui_.vbox.addWidget(&this->ui_.buttonBox);
2018-06-11 15:04:54 +02:00
this->setLayout(&this->ui_.vbox);
}
void QualityPopup::showDialog(const QString &channelName, QStringList options)
2017-12-17 16:45:15 +01:00
{
QualityPopup *instance = new QualityPopup(channelName, options);
2018-01-28 18:05:01 +01:00
instance->setAttribute(Qt::WA_DeleteOnClose, true);
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_;
try {
2018-07-06 19:23:47 +02:00
openStreamlink(channelURL, this->ui_.selector.currentText());
2018-06-26 17:06:17 +02:00
} catch (const Exception &ex) {
Log("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