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

@ -77,16 +77,16 @@ private:
QString *LoadLatexHeader(); QString *LoadLatexHeader();
void MakeReceiptsAnonymous( QVector<paymentEntry_t*> *argDataVector, bool argAlsoAnonymizeClients ); 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 != "") const QString anonymousReceiptsPlaceholder; //!< Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
QString *dateString = nullptr; QString dateString; //!< The expected date string of the payment file in form 'yyMMdd_hhmm'
QString expectedPaymentFileName; //! The name of the expected payment file QString expectedPaymentFileName; //!< The name of the expected payment file
QString expectedPaymentFilePath; //! The path 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 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 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 const bool * const printReceiptsForLocalClients; //!< Stores if receipts shall be printed for local clients
ReceiptsPrinter *receiptsPrinter = nullptr; //! Creates new thread for receipts printing ReceiptsPrinter *receiptsPrinter = nullptr; //!< Creates new thread for receipts printing
QTimer *timer = nullptr; //! Used for regular checking if the payment file was created 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 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; extern std::unique_ptr< lc::Settings > settings;
lc::ReceiptsPrinter::ReceiptsPrinter( const QString * const argDateString, lc::ReceiptsPrinter::ReceiptsPrinter( const QString &argDateString,
const QString * const argWorkpath, const QString &argWorkpath,
QObject *argParent ) : QObject *argParent ) :
QThread{ argParent }, QThread{ argParent },
dateString{ argDateString }, dateString{ argDateString },

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