Got entirely rid of any 'settingsItems' or alias usages

remotes/origin/HEAD
markuspg 8 years ago
parent c522b5168e
commit 18b42ef0af

@ -22,13 +22,6 @@
#include <QMetaType>
enum class settItms_t : unsigned short int { BROWSER_CMD, DVIPS_CMD, FILE_MANAGER, LC_INST_DIR,
LATEX_CMD, LOCAL_ZLEAF_NAME, LPR_CMD, NETSTAT_CMD, NETW_BRDCAST_ADDR,
ORSEE_URL, PING_COMMAND, POSTSCRIPT_VIEWER, PS2PDF_COMMAND,
SSH_KEY_ROOT, SSH_KEY_USER, RCP_CMD, RM_CMD, SERVER_IP, SSH_CMD,
TERM_EMUL_CMD, USER_NAME_ON_CLIENTS, VNC_VIEWER, WAKEONLAN_CMD,
WMCTRL_CMD, XSET_CMD, ZTREE_INST_DIR, SETT_ITMS_QUANT };
//! Opens a terminal for the client
enum class state_t : unsigned short int {
//! The client is booting but not yet responding

@ -29,8 +29,7 @@ lc::Lablib::Lablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent
debugMessagesTextEdit{ argDebugMessagesTextEdit },
labSettings{ "Economic Laboratory", "Labcontrol", this },
occupiedPorts{ new QVector< int > },
sessionsModel{ new SessionsModel{ this } },
settingsItems{ new QVector< QString* >{ ( int )settItms_t::SETT_ITMS_QUANT, nullptr } }
sessionsModel{ new SessionsModel{ this } }
{
ReadSettings();
@ -76,10 +75,6 @@ lc::Lablib::~Lablib () {
delete InstalledZTreeVersions;
delete occupiedPorts;
delete webcams;
for (auto s: *settingsItems) {
delete s;
}
delete settingsItems;
}
void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
@ -358,8 +353,7 @@ void lc::Lablib::StartNewZTreeInstance() {
sessionsModel->push_back( new Session{ debugMessagesTextEdit, chosenZTreeDataTargetPath,
chosenZTreePort, chosenZTreeVersion,
PrintReceiptsForLocalClients,
anonymousReceiptsPlaceholder, chosenLaTeXHeader,
settingsItems } );
anonymousReceiptsPlaceholder, chosenLaTeXHeader } );
occupiedPorts->append( sessionsModel->back()->zTreePort );
}
catch ( Session::lcDataTargetPathCreationFailed ) {

@ -182,7 +182,6 @@ private:
QVector< int > *occupiedPorts = nullptr;
bool PrintReceiptsForLocalClients = true;
SessionsModel *sessionsModel = nullptr; //! A derivation from QAbstractTableModel used to store the single Session instances
QVector<QString*> *settingsItems = nullptr; //! A QVector storing all simple settings
QString userNameOnServer; //! The user name on the server as extracted from the environment variables
QStringList *webcams = nullptr; //! A QStringList containing all available stationary webcams in the laboratory
};

@ -17,18 +17,21 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "receipts_handler.h"
#include "settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::ReceiptsHandler::ReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath,
const bool &argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName,
const QVector< QString* > * const argSettingsItems,
QObject *argParent ) :
QObject{ argParent },
anonymousReceiptsPlaceholder{ new QString{ argAnonymousReceiptsPlaceholder } },
settingsItems{ argSettingsItems },
debugMessagesTextEdit{ argDebugMessagesTextEdit },
latexHeaderName{ new QString{ argLatexHeaderName } },
printReceiptsForLocalClients{ new bool { argPrintReceiptsForLocalClients } },
@ -57,11 +60,9 @@ lc::ReceiptsHandler::ReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit,
const bool &argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName,
const QVector< QString* > * const argSettingsItems,
const QString * const argDateString, QObject *argParent ) :
QObject{ argParent },
anonymousReceiptsPlaceholder{ new QString{ argAnonymousReceiptsPlaceholder } },
settingsItems{ argSettingsItems },
dateString{ new QString{ *argDateString } },
debugMessagesTextEdit{ argDebugMessagesTextEdit },
latexHeaderName{ new QString{ argLatexHeaderName } },
@ -215,7 +216,7 @@ void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() {
delete latexText;
latexText = nullptr;
receiptsPrinter = new ReceiptsPrinter{ dateString, zTreeDataTargetPath, settingsItems };
receiptsPrinter = new ReceiptsPrinter{ dateString, zTreeDataTargetPath };
receiptsPrinter->start();
connect( receiptsPrinter, &ReceiptsPrinter::PrintingFinished,
this, &ReceiptsHandler::DeleteReceiptsPrinterInstance );
@ -273,10 +274,11 @@ QVector<QString> *lc::ReceiptsHandler::GetParticipantsDataFromPaymentFile() {
QString *lc::ReceiptsHandler::LoadLatexHeader() {
// Prepare all facilities to read the latex header file
QFile latexHeaderFile( *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] + "/" + *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( *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ).arg( *latexHeaderName ), QMessageBox::Ok };
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 };
messageBox.exec();
return nullptr;
}

@ -47,12 +47,14 @@ class ReceiptsHandler : public QObject {
public:
explicit ReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
const bool &argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, const QVector<QString*> * const argSettingsItems, QObject *argParent = nullptr );
const bool &argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent = nullptr );
explicit ReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
const bool &argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, const QVector<QString*> * const argSettingsItems,
const QString * const argDateString, QObject *argParent = nullptr );
const bool &argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName,
const QString * const argDateString, QObject *argParent = nullptr );
~ReceiptsHandler();
signals:
@ -76,7 +78,6 @@ private:
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 QVector<QString*> * const settingsItems; //! A QVector storing all needed command paths
QString *dateString = nullptr;
QPlainTextEdit * const debugMessagesTextEdit = nullptr; //! A pointer to the programs debug_messages_text_edit to be able to emit debugging messages
QString expectedPaymentFileName; //! The name of the expected payment file

@ -17,15 +17,25 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "receiptsprinter.h"
#include "settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::ReceiptsPrinter::ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
const QVector< QString* > * const argSettingsItems,
QObject *argParent ) :
QThread{ argParent },
dateString{ argDateString },
settingsItems{ argSettingsItems },
dvipsCmd{ settings->dvipsCmd },
latexCmd{ settings->latexCmd },
lprCmd{ settings->lprCmd },
postscriptViewer{ settings->postscriptViewer },
ps2pdfCmd{ settings->ps2pdfCmd },
rmCmd{ settings->rmCmd },
vncViewer{ settings->vncViewer },
workpath{ argWorkpath }
{
}

@ -45,7 +45,7 @@ class ReceiptsPrinter : public QThread {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->start( *( *settingsItems )[ ( int )settItms_t::LATEX_CMD ], arguments );
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 };
message_box.exec();
@ -63,7 +63,7 @@ class ReceiptsPrinter : public QThread {
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->start( *( *settingsItems )[ ( int )settItms_t::DVIPS_CMD ], arguments );
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" } );
delete process;
@ -74,14 +74,14 @@ class ReceiptsPrinter : public QThread {
process = nullptr;
// Print the postscript file
if ( ( *settingsItems )[ ( int )settItms_t::LPR_CMD ] ) {
if ( !lprCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->start( *( *settingsItems )[ ( int )settItms_t::LPR_CMD ], arguments );
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" } );
}
@ -90,14 +90,14 @@ class ReceiptsPrinter : public QThread {
}
// Convert the postscript file to pdf
if ( ( *settingsItems )[ ( int )settItms_t::PS2PDF_COMMAND ] ) {
if ( !ps2pdfCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" } << QString{ *workpath + "/" + *dateString + ".pdf" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->start( *( *settingsItems )[ ( int )settItms_t::PS2PDF_COMMAND ], arguments );
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" } );
}
@ -105,21 +105,21 @@ class ReceiptsPrinter : public QThread {
process = nullptr;
// Show the postscript file if the conversion succeeded
if ( ( *settingsItems )[ ( int )settItms_t::POSTSCRIPT_VIEWER ] ) {
if ( !postscriptViewer.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".ps" };
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->startDetached( *( *settingsItems )[ ( int )settItms_t::POSTSCRIPT_VIEWER ], arguments );
process->startDetached( postscriptViewer, arguments );
delete process;
process = nullptr;
}
}
// Clean up the zTree working path
if ( ( *settingsItems )[ ( int )settItms_t::RM_CMD ] ) {
if ( !rmCmd.isEmpty() ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".aux" }
<< QString{ *workpath + "/" + *dateString + ".dvi" }
@ -129,7 +129,7 @@ class ReceiptsPrinter : public QThread {
process = new QProcess{};
process->setProcessEnvironment( env );
process->setWorkingDirectory( *workpath );
process->start( *( *settingsItems )[ ( int )settItms_t::RM_CMD ], arguments);
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"));
}
@ -142,7 +142,6 @@ class ReceiptsPrinter : public QThread {
public:
explicit ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
const QVector< QString* > * const argSettingsItems,
QObject *argParent = nullptr );
signals:
@ -151,8 +150,14 @@ signals:
private:
const QString * const dateString; //! The date string contained in the file paths
const QString dvipsCmd;
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 QVector<QString*> * const settingsItems; //! A QVector storing all needed command paths
const QString ps2pdfCmd;
const QString rmCmd;
const QString vncViewer;
const QString * const workpath; //! The path were zTree was ordered to store all its data
};

@ -17,20 +17,23 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "session.h"
#include "settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::Session::Session( QPlainTextEdit * const argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath, const int argZTreePort,
const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName,
const QVector<QString*> * const argSettingsItems ):
const QString &argLatexHeaderName ):
zTreePort{ argZTreePort },
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder },
debugMessagesTextEdit{ argDebugMessagesTextEdit },
latexHeaderName{ argLatexHeaderName },
printReceiptsForLocalClients{ argPrintReceiptsForLocalClients },
settingsItems{ argSettingsItems },
zTreeDataTargetPath{ argZTreeDataTargetPath },
zTreeVersionPath{ argZTreeVersionPath }
{
@ -45,7 +48,7 @@ lc::Session::Session( QPlainTextEdit * const argDebugMessagesTextEdit,
InitializeClasses();
}
if ( ( *settingsItems )[ ( int )settItms_t::WMCTRL_CMD ] ) {
if ( !settings->wmctrlCmd.isEmpty() ) {
QTimer::singleShot( 5000, this, SLOT( RenameWindow() ) );
}
}
@ -77,13 +80,14 @@ void lc::Session::InitializeClasses() {
debugMessagesTextEdit->appendPlainText( "[DEBUG] New session's chosen_zTree_data_target_path: " + zTreeDataTargetPath );
zTreeInstance = new ZTree{ debugMessagesTextEdit, zTreeDataTargetPath,
zTreePort, zTreeVersionPath, settingsItems };
zTreePort, zTreeVersionPath };
// Only create a 'Receipts_Handler' instance, if all neccessary variables were set
if ( latexHeaderName != "None found" && ( *settingsItems )[ ( int )settItms_t::DVIPS_CMD ] && ( *settingsItems )[ ( int )settItms_t::LATEX_CMD ] ) {
if ( latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty()
&& !settings->latexCmd.isEmpty() ) {
receiptsHandler = new ReceiptsHandler{ debugMessagesTextEdit, zTreeDataTargetPath,
printReceiptsForLocalClients,
anonymousReceiptsPlaceholder,
latexHeaderName, settingsItems };
latexHeaderName };
} else {
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No ReceiptsHandler instance was created." ) );
}
@ -99,7 +103,7 @@ void lc::Session::RenameWindow() {
QProcess renameZTreeWindowProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
renameZTreeWindowProcess.setProcessEnvironment( env );
renameZTreeWindowProcess.startDetached( *( *settingsItems )[ ( int )settItms_t::WMCTRL_CMD ], arguments );
renameZTreeWindowProcess.startDetached( settings->wmctrlCmd, arguments );
debugMessagesTextEdit->appendPlainText( "[DEBUG] Renamed window" );

@ -40,7 +40,7 @@ public:
Session( QPlainTextEdit * const argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath, const int argZTreePort,
const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, const QVector<QString*> * const argSettingsItems );
const QString &argLatexHeaderName );
~Session();
/*! Returns the data item with the given index
@ -69,7 +69,6 @@ private:
const QString latexHeaderName; //! The name of the chosen LaTeX header
const bool printReceiptsForLocalClients = true; //! True if receipts shall be printed for local clients
ReceiptsHandler *receiptsHandler = nullptr; //! For automatic creation and printing of the receipts
const QVector<QString*> * const settingsItems; //! A QVector container storing all needed command paths
QString zTreeDataTargetPath; //! The path were the data of this zTree instance's session will be saved
ZTree *zTreeInstance= nullptr; //! The session's zTree instance
const QString zTreeVersionPath; //! The path to the version of zTree used by this session's instance

@ -20,9 +20,6 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
lcInstDir{ ReadSettingsItem( "labcontrol_installation_directory",
"Labcontrol will missbehave with high propability.",
argSettings, true ) },
localzLeafName{ ReadSettingsItem( "local_zLeaf_name",
"The local zLeaf default name will default to 'local'.",
argSettings, false ) },
lprCmd{ ReadSettingsItem( "lpr_command",
"Receipts printing will not work.",
argSettings, true ) },
@ -82,7 +79,10 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
argSettings, true ) },
zTreeInstDir{ ReadSettingsItem( "ztree_installation_directory",
"zTree will not be available.",
argSettings, true ) }
argSettings, true ) },
localzLeafName{ ReadSettingsItem( "local_zLeaf_name",
"The local zLeaf default name will default to 'local'.",
argSettings, false ) }
{
}

@ -17,15 +17,20 @@
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include "settings.h"
#include "ztree.h"
extern std::unique_ptr< lc::Settings > settings;
lc::ZTree::ZTree( QPlainTextEdit *argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath, const int &argZTreePort,
const QString &argZTreeVersionPath,
const QVector<QString*> * const argSettingsItems ) {
QString program{ *( *argSettingsItems )[ ( int )settItms_t::LC_INST_DIR ] + "/scripts/start_zTree_labcontrol2.sh" };
const QString &argZTreeVersionPath ) {
QString program{ settings->lcInstDir + "/scripts/start_zTree_labcontrol2.sh" };
QStringList arguments;
arguments << *( *argSettingsItems )[ ( int )settItms_t::ZTREE_INST_DIR ] << argZTreeVersionPath << argZTreeDataTargetPath << QString::number( static_cast<int>( argZTreePort ) - 7000 );
arguments << settings->zTreeInstDir << argZTreeVersionPath << argZTreeDataTargetPath
<< QString::number( static_cast< int >( argZTreePort ) - 7000 );
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
zTreeInstance.setProcessEnvironment( env );

@ -38,8 +38,7 @@ class ZTree: public QObject {
public:
ZTree( QPlainTextEdit *argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath,
const int &argZTreePort, const QString &argZTreeVersionPath,
const QVector<QString*> * const argSettingsItems );
const int &argZTreePort, const QString &argZTreeVersionPath );
signals:
void ZTreeClosed();

Loading…
Cancel
Save