Reformat ReceiptsPrinter

remotes/origin/HEAD
markuspg 7 years ago
parent f5f32c4bcf
commit f345d88315

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -32,22 +32,27 @@ namespace lc {
/*!
This class is used to do the actual printing of the receipts in an own thread.
*/
class ReceiptsPrinter : public QThread {
class ReceiptsPrinter : public QThread
{
Q_OBJECT
void run() Q_DECL_OVERRIDE {
void run() override
{
// Compile the TeX file to dvi
QStringList arguments;
arguments << "-interaction" << "batchmode" << QString{dateString + ".tex"};
QProcess *process = nullptr;
process = new QProcess{};
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QProcessEnvironment env{QProcessEnvironment::systemEnvironment()};
process->setProcessEnvironment(env);
process->setWorkingDirectory(workpath);
process->start(latexCmd, arguments);
if (!process->waitForFinished(processTimeOut)) {
QMessageBox message_box{ QMessageBox::Warning, "dvi creation failed", "The creation of the receipts dvi timed out after 30 seconds. Automatic receipts creation will not work.", QMessageBox::Ok };
QMessageBox message_box{QMessageBox::Warning, "dvi creation failed",
"The creation of the receipts dvi timed out"
" after 30 seconds. Automatic receipts creation will not work.",
QMessageBox::Ok};
message_box.exec();
delete process;
process = nullptr;
@ -65,7 +70,8 @@ class ReceiptsPrinter : public QThread {
process->setWorkingDirectory(workpath);
process->start(dvipsCmd, arguments);
if (!process->waitForFinished(processTimeOut)) {
emit ErrorOccurred(new QString{ "The conversion of the receipts dvi to postscript timed out after 30 seconds. Automatic receipts creation will not work." }, new QString{ "dvi to postscript conversion failed" } );
emit ErrorOccurred(new QString{"The conversion of the receipts dvi to postscript timed out after 30 seconds. Automatic receipts creation will not work."},
new QString{"dvi to postscript conversion failed"});
delete process;
process = nullptr;
return;
@ -83,7 +89,8 @@ class ReceiptsPrinter : public QThread {
process->setWorkingDirectory(workpath);
process->start(lprCmd, arguments);
if ( !process->waitForFinished( processTimeOut ) ) {
emit ErrorOccurred( new QString{ "The receipts postscript file was successfully created but could not be printed." }, new QString{ "Printing failed" } );
emit ErrorOccurred(new QString{"The receipts postscript file was successfully created but could not be printed."},
new QString{"Printing failed"});
}
delete process;
process = nullptr;
@ -99,7 +106,8 @@ class ReceiptsPrinter : public QThread {
process->setWorkingDirectory(workpath);
process->start(ps2pdfCmd, arguments);
if (!process->waitForFinished(processTimeOut)) {
emit ErrorOccurred( new QString{ "The receipts were successfully printed but the creation of the PDF file failed." }, new QString{ "PDF creation failed" } );
emit ErrorOccurred(new QString{"The receipts were successfully printed but the creation of the PDF file failed."},
new QString{"PDF creation failed"});
}
delete process;
process = nullptr;
@ -131,7 +139,9 @@ class ReceiptsPrinter : public QThread {
process->setWorkingDirectory(workpath);
process->start( rmCmd, arguments);
if (!process->waitForFinished(processTimeOut)) {
emit ErrorOccurred(new QString("The cleanup of the temporary files for receipts creation timed out. Some spare files may be left in your zTree working directory."), new QString("Cleanup failed"));
emit ErrorOccurred(new
QString("The cleanup of the temporary files for receipts creation timed out. Some spare files may be left in your zTree working directory."),
new QString("Cleanup failed"));
}
delete process;
process = nullptr;
@ -154,13 +164,14 @@ private:
const QString latexCmd;
const QString lprCmd;
const QString postscriptViewer;
const int processTimeOut = 15000; //! The maximum time which will be granted to a started process
const int processTimeOut =
15000; //! The maximum time which will be granted to a started process
const QString ps2pdfCmd;
const QString rmCmd;
const QString vncViewer;
const QString workpath; //!< The path were zTree was ordered to store all its data
};
}
} // namespace lc
#endif // RECEIPTSPRINTER_H

Loading…
Cancel
Save