Reformat Session

remotes/origin/HEAD
markuspg 6 years ago
parent f345d88315
commit 847c83d2d4

@ -24,53 +24,54 @@
#include <memory>
extern std::unique_ptr< lc::Settings > settings;
lc::Session::Session( QVector< Client * > &&argAssocClients,
const QString &argZTreeDataTargetPath, const quint16 argZTreePort,
const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent ):
QObject{ argParent },
zTreePort{ argZTreePort },
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder },
assocClients{ std::move( argAssocClients ) },
latexHeaderName{ argLatexHeaderName },
printReceiptsForLocalClients{ argPrintReceiptsForLocalClients },
zTreeDataTargetPath{ argZTreeDataTargetPath },
zTreeVersionPath{ argZTreeVersionPath }
extern std::unique_ptr<lc::Settings> settings;
lc::Session::Session(QVector<Client *> &&argAssocClients,
const QString &argZTreeDataTargetPath, const quint16 argZTreePort,
const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent):
QObject{argParent},
zTreePort{argZTreePort},
anonymousReceiptsPlaceholder{argAnonymousReceiptsPlaceholder},
assocClients{std::move(argAssocClients)},
latexHeaderName{argLatexHeaderName},
printReceiptsForLocalClients{argPrintReceiptsForLocalClients},
zTreeDataTargetPath{argZTreeDataTargetPath},
zTreeVersionPath{argZTreeVersionPath}
{
// This part ensures, that both class instances are created in the same minute, so that the payment file name can be guessed correctly
QDateTime current_time;
current_time = QDateTime::currentDateTime();
// If in the last three seconds of a minute, wait for the next one to start
if ( QTime::currentTime().second() > 56 ) {
QTimer::singleShot( 5000, this, SLOT( InitializeClasses() ) );
if (QTime::currentTime().second() > 56) {
QTimer::singleShot(5000, this, SLOT(InitializeClasses()));
} else {
InitializeClasses();
}
if ( !settings->wmctrlCmd.isEmpty() ) {
QTimer::singleShot( 5000, this, SLOT( RenameWindow() ) );
if (!settings->wmctrlCmd.isEmpty()) {
QTimer::singleShot(5000, this, SLOT(RenameWindow()));
}
}
lc::Session::~Session()
{
for ( auto &client : assocClients ) {
client->SetSessionPort( 0 );
client->SetzLeafVersion( "" );
for (auto &client : assocClients) {
client->SetSessionPort(0);
client->SetzLeafVersion("");
}
}
QVariant lc::Session::GetDataItem( int argIndex )
QVariant lc::Session::GetDataItem(int argIndex)
{
switch ( argIndex ) {
switch (argIndex) {
case 0:
return QVariant{ zTreeVersionPath.split( '_', QString::KeepEmptyParts, Qt::CaseInsensitive )[ 1 ] };
return QVariant{zTreeVersionPath.split('_', QString::KeepEmptyParts,
Qt::CaseInsensitive)[1]};
case 1:
return QVariant{ zTreePort };
return QVariant{zTreePort};
default:
return QVariant{};
}
@ -79,31 +80,32 @@ QVariant lc::Session::GetDataItem( int argIndex )
void lc::Session::InitializeClasses()
{
// Create the new data directory
QDir dir{ zTreeDataTargetPath };
QString date_string( QDateTime::currentDateTime().toString( "yyMMdd_hhmm" ) );
if ( !dir.mkdir( zTreeDataTargetPath + "/" + date_string + "-" + QString::number( zTreePort ) ) ) {
QDir dir{zTreeDataTargetPath};
QString date_string(QDateTime::currentDateTime().toString("yyMMdd_hhmm"));
if (!dir.mkdir(zTreeDataTargetPath + "/" + date_string + "-" + QString::number(zTreePort))) {
throw lcDataTargetPathCreationFailed{};
}
zTreeDataTargetPath.append( "/" + date_string + "-" + QString::number( zTreePort ) );
zTreeDataTargetPath.append("/" + date_string + "-" + QString::number(zTreePort));
qDebug() << "New session's chosen_zTree_data_target_path:" << zTreeDataTargetPath;
zTreeInstance = new ZTree{ zTreeDataTargetPath, zTreePort, zTreeVersionPath, this };
connect( zTreeInstance, &ZTree::ZTreeClosed,
this, &Session::OnzTreeClosed );
zTreeInstance = new ZTree{zTreeDataTargetPath, zTreePort,
zTreeVersionPath, this};
connect(zTreeInstance, &ZTree::ZTreeClosed,
this, &Session::OnzTreeClosed);
// Only create a 'Receipts_Handler' instance, if all neccessary variables were set
if ( latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty()
&& !settings->latexCmd.isEmpty() ) {
new ReceiptsHandler{ zTreeDataTargetPath, printReceiptsForLocalClients,
anonymousReceiptsPlaceholder, latexHeaderName, this };
if (latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty()
&& !settings->latexCmd.isEmpty()) {
new ReceiptsHandler{zTreeDataTargetPath, printReceiptsForLocalClients,
anonymousReceiptsPlaceholder, latexHeaderName, this};
} else {
qDebug() << "No 'ReceiptsHandler' instance was created.";
}
}
void lc::Session::OnzTreeClosed( int argExitCode )
void lc::Session::OnzTreeClosed(int argExitCode)
{
qDebug() << "z-Tree running on port" << zTreePort << "closed with exit code" << argExitCode;
emit SessionFinished( this );
emit SessionFinished(this);
}
void lc::Session::RenameWindow()
@ -111,13 +113,13 @@ void lc::Session::RenameWindow()
// Example: wmctrl -r <window name> -T <new name>
QStringList arguments;
arguments << "-r" << "zTree - Untitled Treatment 1" << "-T" << QString{ "zTree on port " + QString::number( zTreePort ) };
arguments << "-r" << "zTree - Untitled Treatment 1" << "-T"
<< QString{"zTree on port " + QString::number(zTreePort)};
// Start the process
QProcess renameZTreeWindowProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
renameZTreeWindowProcess.setProcessEnvironment( env );
renameZTreeWindowProcess.startDetached( settings->wmctrlCmd, arguments );
renameZTreeWindowProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
renameZTreeWindowProcess.startDetached(settings->wmctrlCmd, arguments);
qDebug() << "Renamed window";

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -34,48 +34,56 @@ class Client;
/*!
This class represents an entire session with its zTree instance and the corresponding lcReceiptsHandler instance.
*/
class Session : public QObject {
class Session : public QObject
{
Q_OBJECT
public:
const int zTreePort = 7000; //! The port this session's zTree instance is running on
//! The port this session's zTree instance is running on
const int zTreePort = 7000;
Session( QVector< Client* > &&argAssocClients, const QString &argZTreeDataTargetPath,
const quint16 argZTreePort, const QString &argZTreeVersionPath,
bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent = nullptr );
~Session();
Session(QVector<Client *> &&argAssocClients, const QString &argZTreeDataTargetPath,
const quint16 argZTreePort, const QString &argZTreeVersionPath,
bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent = nullptr);
~Session() override;
/*! Returns the data item with the given index
*
* @param argIndex The index of the desired item
*/
QVariant GetDataItem( int argIndex );
QVariant GetDataItem(int argIndex);
//! This gets thrown as an exception if the chosen data target path could not be created.
class lcDataTargetPathCreationFailed {};
signals:
void SessionFinished( Session *argSession );
void SessionFinished(Session *argSession);
private slots:
/*! Starts the session by creating instances of the relevant classes
*/
void InitializeClasses();
void OnzTreeClosed( int argExitCode );
void OnzTreeClosed(int argExitCode);
/*! Changes zTree's window title to contain its port number to make zTree windows distinguishable
*/
void RenameWindow();
private:
const QString anonymousReceiptsPlaceholder; //! Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
const QVector< Client* > assocClients;
const QString latexHeaderName; //! The name of the chosen LaTeX header
const bool printReceiptsForLocalClients = true; //! True if receipts shall be printed for local clients
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
//! Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
const QString anonymousReceiptsPlaceholder;
const QVector<Client *> assocClients;
//! The name of the chosen LaTeX header
const QString latexHeaderName;
//! True if receipts shall be printed for local clients
const bool printReceiptsForLocalClients = true;
//! The path were the data of this zTree instance's session will be saved
QString zTreeDataTargetPath;
//! The session's zTree instance
ZTree *zTreeInstance = nullptr;
//! The path to the version of zTree used by this session's instance
const QString zTreeVersionPath;
};
}

Loading…
Cancel
Save