Little rework of variables concerned with receipts creation and printing

remotes/origin/HEAD
markuspg 8 years ago
parent ce18a6129e
commit b45254aa3b

@ -32,18 +32,18 @@ lc::ReceiptsHandler::ReceiptsHandler( const QString &argZTreeDataTargetPath,
const QString &argLatexHeaderName,
QObject *argParent ) :
QObject{ argParent },
anonymousReceiptsPlaceholder{ new QString{ argAnonymousReceiptsPlaceholder } },
latexHeaderName{ new QString{ argLatexHeaderName } },
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder },
latexHeaderName{ argLatexHeaderName },
printReceiptsForLocalClients{ new bool { argPrintReceiptsForLocalClients } },
timer{ new QTimer{ this } },
zTreeDataTargetPath{ new QString{ argZTreeDataTargetPath } }
zTreeDataTargetPath{ argZTreeDataTargetPath }
{
// Guess the name of the payment file
QDateTime currentDate;
currentDate = QDateTime::currentDateTime();
dateString = new QString{ currentDate.toString( "yyMMdd_hhmm" ) };
expectedPaymentFileName = QString{ *dateString + ".pay" };
expectedPaymentFilePath = QString{ *zTreeDataTargetPath + "/" + *dateString + ".pay" };
dateString = currentDate.toString( "yyMMdd_hhmm" );
expectedPaymentFileName = QString{ dateString + ".pay" };
expectedPaymentFilePath = QString{ zTreeDataTargetPath + "/" + dateString + ".pay" };
qDebug() << "Expected payment file name is:" << expectedPaymentFilePath;
// Create a new file object representing the payment file
@ -61,14 +61,14 @@ lc::ReceiptsHandler::ReceiptsHandler( const QString &argZTreeDataTargetPath,
const QString &argLatexHeaderName,
const QString * const argDateString, QObject *argParent ) :
QObject{ argParent },
anonymousReceiptsPlaceholder{ new QString{ argAnonymousReceiptsPlaceholder } },
dateString{ new QString{ *argDateString } },
latexHeaderName{ new QString{ argLatexHeaderName } },
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder },
dateString{ *argDateString },
latexHeaderName{ argLatexHeaderName },
printReceiptsForLocalClients{ new bool { argPrintReceiptsForLocalClients } },
zTreeDataTargetPath{ new QString{ argZTreeDataTargetPath } }
zTreeDataTargetPath{ argZTreeDataTargetPath }
{
expectedPaymentFileName = QString{ *dateString + ".pay" };
expectedPaymentFilePath = QString{ *zTreeDataTargetPath + "/" + *argDateString + ".pay" };
expectedPaymentFileName = QString{ dateString + ".pay" };
expectedPaymentFilePath = QString{ zTreeDataTargetPath + "/" + *argDateString + ".pay" };
qDebug() << "Expected payment file name is:" << expectedPaymentFilePath;
// Create a new file object representing the payment file
@ -78,13 +78,9 @@ lc::ReceiptsHandler::ReceiptsHandler( const QString &argZTreeDataTargetPath,
}
lc::ReceiptsHandler::~ReceiptsHandler() {
delete anonymousReceiptsPlaceholder;
delete dateString;
delete latexHeaderName;
delete paymentFile;
delete printReceiptsForLocalClients;
delete receiptsPrinter;
delete zTreeDataTargetPath;
}
void lc::ReceiptsHandler::PrintReceipts() {
@ -134,7 +130,7 @@ void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() {
rawParticipantsData = nullptr;
// Make receipts overview anonymous if requested (at this stage just names are removed, so that the overview still containts the client names
if ( !anonymousReceiptsPlaceholder->isEmpty() ) {
if ( !anonymousReceiptsPlaceholder.isEmpty() ) {
MakeReceiptsAnonymous( participants, false );
}
@ -163,7 +159,7 @@ void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() {
// MISSING: Appending show up entries to the overview
// Make also the clients on the receipts anonymous. This is done as second step, so that the beforehand created overview still contains the clients
if ( !anonymousReceiptsPlaceholder->isEmpty() ) {
if ( !anonymousReceiptsPlaceholder.isEmpty() ) {
MakeReceiptsAnonymous( participants, true );
}
@ -189,7 +185,7 @@ void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() {
qDebug() << *latexText;
// Create the tex file
QFile *texFile = new QFile( *zTreeDataTargetPath + "/" + *dateString + ".tex" );
QFile *texFile = new QFile{ zTreeDataTargetPath + "/" + dateString + ".tex" };
qDebug() << "Tex file" << texFile->fileName() << "will be created for receipts printing.";
// Clean up any already existing files
if ( texFile->exists() ) {
@ -272,11 +268,11 @@ QVector<QString> *lc::ReceiptsHandler::GetParticipantsDataFromPaymentFile() {
QString *lc::ReceiptsHandler::LoadLatexHeader() {
// Prepare all facilities to read the latex header file
QFile latexHeaderFile( settings->lcInstDir + "/" + *latexHeaderName + "_header.tex" );
QFile latexHeaderFile( settings->lcInstDir + "/" + latexHeaderName + "_header.tex" );
if ( !latexHeaderFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "LaTeX header could not be loaded" ),
tr( "The LaTeX header at '%1/%2_header.tex' could not be loaded. Receipts printing will not work." )
.arg( settings->lcInstDir ).arg( *latexHeaderName ), QMessageBox::Ok };
.arg( settings->lcInstDir ).arg( latexHeaderName ), QMessageBox::Ok };
messageBox.exec();
return nullptr;
}
@ -294,14 +290,14 @@ void lc::ReceiptsHandler::MakeReceiptsAnonymous( QVector<paymentEntry_t*> *argDa
if ( !argAlsoAnonymizeClients ) {
qDebug() << "Names are made anonymous";
for ( QVector< paymentEntry_t* >::iterator it = argDataVector->begin(); it != argDataVector->end(); ++it ) {
( *it )->name = QString{ *anonymousReceiptsPlaceholder };
( *it )->name = anonymousReceiptsPlaceholder;
}
}
else {
qDebug() << "Clients and names are made anonymous";
for ( QVector< paymentEntry_t* >::iterator it = argDataVector->begin(); it != argDataVector->end(); ++it ) {
( *it )->name = QString{ *anonymousReceiptsPlaceholder };
( *it )->computer = QString{ "\\hspace{1cm}" };
( *it )->name = anonymousReceiptsPlaceholder;
( *it )->computer = "\\hspace{1cm}";
}
}
}

@ -77,16 +77,16 @@ private:
QString *LoadLatexHeader();
void MakeReceiptsAnonymous( QVector<paymentEntry_t*> *argDataVector, bool argAlsoAnonymizeClients );
const QString * const anonymousReceiptsPlaceholder; //! Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
QString *dateString = nullptr;
QString expectedPaymentFileName; //! The name of the expected payment file
QString expectedPaymentFilePath; //! The path of the expected payment file
const QString * const latexHeaderName; //! The name of the chosen LaTeX header template
QFile *paymentFile = nullptr; //! A pointer to the '*.pay' file being watched for existance and starting the printing process
const bool * const printReceiptsForLocalClients; //! Stores if receipts shall be printed for local clients
ReceiptsPrinter *receiptsPrinter = nullptr; //! Creates new thread for receipts printing
QTimer *timer = nullptr; //! Used for regular checking if the payment file was created
const QString * const zTreeDataTargetPath; //! A reference to the data target path stored in the session class instance
const QString anonymousReceiptsPlaceholder; //!< Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
QString dateString; //!< The expected date string of the payment file in form 'yyMMdd_hhmm'
QString expectedPaymentFileName; //!< The name of the expected payment file
QString expectedPaymentFilePath; //!< The path of the expected payment file
const QString latexHeaderName; //!< The name of the chosen LaTeX header template
QFile *paymentFile = nullptr; //!< A pointer to the '*.pay' file being watched for existance and starting the printing process
const bool * const printReceiptsForLocalClients; //!< Stores if receipts shall be printed for local clients
ReceiptsPrinter *receiptsPrinter = nullptr; //!< Creates new thread for receipts printing
QTimer *timer = nullptr; //!< Used for regular checking if the payment file was created
const QString zTreeDataTargetPath; //!< A reference to the data target path stored in the session class instance
};
}

@ -24,8 +24,8 @@
extern std::unique_ptr< lc::Settings > settings;
lc::ReceiptsPrinter::ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
lc::ReceiptsPrinter::ReceiptsPrinter( const QString &argDateString,
const QString &argWorkpath,
QObject *argParent ) :
QThread{ argParent },
dateString{ argDateString },

@ -38,13 +38,13 @@ class ReceiptsPrinter : public QThread {
void run() Q_DECL_OVERRIDE {
// Compile the TeX file to dvi
QStringList arguments;
arguments << "-interaction" << "batchmode" << QString{ *dateString + ".tex" };
arguments << "-interaction" << "batchmode" << QString{ dateString + ".tex" };
QProcess *process = nullptr;
process = new QProcess{};
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
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 };
@ -58,11 +58,11 @@ class ReceiptsPrinter : public QThread {
// Convert the dvi file to postscript
arguments = QStringList{};
arguments << "-q*" << "-o" << QString{ *dateString + ".ps" } << QString{ *dateString + ".dvi" };
arguments << "-q*" << "-o" << QString{ dateString + ".ps" } << QString{ dateString + ".dvi" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
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" } );
@ -76,11 +76,11 @@ class ReceiptsPrinter : public QThread {
// Print the postscript file
if ( !lprCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" };
arguments << QString{ workpath + "/" + dateString + ".ps" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
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" } );
@ -92,11 +92,11 @@ class ReceiptsPrinter : public QThread {
// Convert the postscript file to pdf
if ( !ps2pdfCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" } << QString{ *workpath + "/" + *dateString + ".pdf" };
arguments << QString{ workpath + "/" + dateString + ".ps" } << QString{ workpath + "/" + dateString + ".pdf" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
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" } );
@ -107,11 +107,11 @@ class ReceiptsPrinter : public QThread {
// Show the postscript file if the conversion succeeded
if ( !postscriptViewer.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" };
arguments << QString{ workpath + "/" + dateString + ".ps" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->setWorkingDirectory( workpath );
process->startDetached( postscriptViewer, arguments );
delete process;
process = nullptr;
@ -121,14 +121,14 @@ class ReceiptsPrinter : public QThread {
// Clean up the zTree working path
if ( !rmCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".aux" }
<< QString{ *workpath + "/" + *dateString + ".dvi" }
<< QString{ *workpath + "/" + *dateString + ".log" }
<< QString{ *workpath + "/" + *dateString + ".tex" };
arguments << QString{ workpath + "/" + dateString + ".aux" }
<< QString{ workpath + "/" + dateString + ".dvi" }
<< QString{ workpath + "/" + dateString + ".log" }
<< QString{ workpath + "/" + dateString + ".tex" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
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"));
@ -140,8 +140,8 @@ class ReceiptsPrinter : public QThread {
emit PrintingFinished();
}
public:
explicit ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
explicit ReceiptsPrinter( const QString &argDateString,
const QString &argWorkpath,
QObject *argParent = nullptr );
signals:
@ -149,7 +149,7 @@ signals:
void PrintingFinished();
private:
const QString * const dateString; //! The date string contained in the file paths
const QString dateString; //! The date string contained in the file paths
const QString dvipsCmd;
const QString latexCmd;
const QString lprCmd;
@ -158,7 +158,7 @@ private:
const QString ps2pdfCmd;
const QString rmCmd;
const QString vncViewer;
const QString * const workpath; //! The path were zTree was ordered to store all its data
const QString workpath; //!< The path were zTree was ordered to store all its data
};
}

Loading…
Cancel
Save