Debian Codegraph @

src/stream_widget.cpp

raw symbols SCIP
1 #include "stream_widget.h"
2
3 StreamWidget::StreamWidget(QProcess *rclone, QProcess *player,
4 const QString &remote, const QString &stream,
5 QWidget *parent)
6 : QWidget(parent), mRclone(rclone), mPlayer(player) {
7 ui.setupUi(this);
8
9 ui.remote->setText(remote);
10 ui.stream->setText(stream);
11 ui.info->setText(remote);
12
13 ui.details->setVisible(false);
14
15 ui.output->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
16 ui.output->setVisible(false);
17
18 QObject::connect(
19 ui.showDetails, &QToolButton::toggled, this, [=](bool checked) {
20 ui.details->setVisible(checked);
21 ui.showDetails->setArrowType(checked ? Qt::DownArrow : Qt::RightArrow);
22 });
23
24 QObject::connect(
25 ui.showOutput, &QToolButton::toggled, this, [=](bool checked) {
26 ui.output->setVisible(checked);
27 ui.showOutput->setArrowType(checked ? Qt::DownArrow : Qt::RightArrow);
28 });
29
30 ui.cancel->setIcon(
31 QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
32
33 QObject::connect(ui.cancel, &QToolButton::clicked, this, [=]() {
34 if (mRunning) {
35 int button = QMessageBox::question(
36 this, "Stop", QString("Do you want to stop %1 stream?").arg(remote),
37 QMessageBox::Yes | QMessageBox::No);
38 if (button == QMessageBox::Yes) {
39 cancel();
40 }
41 } else {
42 emit closed();
43 }
44 });
45
46 QObject::connect(mRclone, &QProcess::readyRead, this, [=]() {
47 while (mRclone->canReadLine()) {
48 ui.output->appendPlainText(mRclone->readLine().trimmed());
49 }
50 });
51
52 QObject::connect(mRclone,
53 static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
54 &QProcess::finished),
55 this, [=]() {
56 mRclone->deleteLater();
57 mRunning = false;
58 emit finished();
59 emit closed();
60 });
61
62 ui.showDetails->setStyleSheet("QToolButton { border: 0; color: green; }");
63 ui.showDetails->setText("Streaming");
64 }
65
66 StreamWidget::~StreamWidget() {}
67
68 void StreamWidget::cancel() {
69 if (!mRunning) {
70 return;
71 }
72
73 mPlayer->terminate();
74 mRclone->kill();
75 mRclone->waitForFinished();
76 }