tsMuxer/tsMuxerGUI/muxForm.cpp
Daniel Kamil Kozar b2ac11b0b5
Replace the old QObject::connect syntax with the new one supported since Qt5
The old syntax is essentially based on the "normalised representation" created
by the SIGNAL and SLOT macros, with potential mismatched only being caught at
runtime. The new syntax causes these errors to appear in compile time.
2019-12-07 19:17:19 +01:00

88 lines
2.5 KiB
C++

#include "muxForm.h"
const static int MAX_ERRORS_CNT = 10000;
MuxForm::MuxForm(QWidget *parent)
: QDialog(parent, Qt::WindowMaximizeButtonHint), muxProcess(0) {
ui.setupUi(this);
connect(ui.progressBar, &QProgressBar::valueChanged, this,
&MuxForm::onProgressChanged);
connect(ui.abortBtn, &QPushButton::clicked, this, &MuxForm::onAbort);
connect(ui.okBtn, &QPushButton::clicked, this, &MuxForm::close);
}
void MuxForm::closeEvent(QCloseEvent *event) {
onAbort();
event->accept();
}
void MuxForm::prepare(const QString &label) {
muxProcess = 0;
errCnt = 0;
setWindowTitle(label);
ui.muxLabel->setText(label + '.');
ui.progressBar->setValue(0);
ui.stdoutText->clear();
ui.stderrText->clear();
ui.abortBtn->setEnabled(true);
ui.okBtn->setEnabled(false);
}
void MuxForm::onProgressChanged() {
ui.progressLabel->setText(
QString("Progress: ") +
QString::number(ui.progressBar->value() / 10.0, 'f', 1) + '%');
}
void MuxForm::setProgress(int value) { ui.progressBar->setValue(value); }
void MuxForm::addStdOutLine(const QString &line) {
ui.stdoutText->append(line);
QTextCursor c = ui.stdoutText->textCursor();
c.movePosition(QTextCursor::End);
ui.stdoutText->setTextCursor(c);
}
void MuxForm::addStdErrLine(const QString &line) {
if (errCnt >= MAX_ERRORS_CNT)
return;
ui.stderrText->append(line);
errCnt = ui.stderrText->document()->blockCount();
if (errCnt >= MAX_ERRORS_CNT) {
ui.stderrText->append("---------------------------------------");
ui.stderrText->append("Too many errors! tsMuxeR is terminated.");
onAbort();
}
QTextCursor c = ui.stderrText->textCursor();
c.movePosition(QTextCursor::End);
ui.stderrText->setTextCursor(c);
}
void MuxForm::muxFinished(int exitCode, const QString &prefix) {
Q_UNUSED(prefix);
if (muxProcess && ui.abortBtn->isEnabled()) {
if (exitCode == 0)
setWindowTitle("tsMuxeR successfully finished");
else
setWindowTitle("tsMuxeR finished with error code " +
QString::number(exitCode));
ui.muxLabel->setText(windowTitle() + '.');
ui.abortBtn->setEnabled(false);
ui.okBtn->setEnabled(true);
}
}
void MuxForm::onAbort() {
if (muxProcess == nullptr)
return;
ui.abortBtn->setEnabled(false);
ui.okBtn->setEnabled(true);
setWindowTitle("terminating tsMuxeR...");
muxProcess->kill();
muxProcess->waitForFinished();
setWindowTitle("tsMuxeR is terminated");
muxProcess = nullptr;
}
void MuxForm::setProcess(QProcess *proc) { muxProcess = proc; }