Reformat Session

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

@ -24,53 +24,54 @@
#include <memory> #include <memory>
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr<lc::Settings> settings;
lc::Session::Session( QVector< Client * > &&argAssocClients, lc::Session::Session(QVector<Client *> &&argAssocClients,
const QString &argZTreeDataTargetPath, const quint16 argZTreePort, const QString &argZTreeDataTargetPath, const quint16 argZTreePort,
const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients, const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent ): const QString &argLatexHeaderName, QObject *argParent):
QObject{ argParent }, QObject{argParent},
zTreePort{ argZTreePort }, zTreePort{argZTreePort},
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder }, anonymousReceiptsPlaceholder{argAnonymousReceiptsPlaceholder},
assocClients{ std::move( argAssocClients ) }, assocClients{std::move(argAssocClients)},
latexHeaderName{ argLatexHeaderName }, latexHeaderName{argLatexHeaderName},
printReceiptsForLocalClients{ argPrintReceiptsForLocalClients }, printReceiptsForLocalClients{argPrintReceiptsForLocalClients},
zTreeDataTargetPath{ argZTreeDataTargetPath }, zTreeDataTargetPath{argZTreeDataTargetPath},
zTreeVersionPath{ argZTreeVersionPath } 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 // 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; QDateTime current_time;
current_time = QDateTime::currentDateTime(); current_time = QDateTime::currentDateTime();
// If in the last three seconds of a minute, wait for the next one to start // If in the last three seconds of a minute, wait for the next one to start
if ( QTime::currentTime().second() > 56 ) { if (QTime::currentTime().second() > 56) {
QTimer::singleShot( 5000, this, SLOT( InitializeClasses() ) ); QTimer::singleShot(5000, this, SLOT(InitializeClasses()));
} else { } else {
InitializeClasses(); InitializeClasses();
} }
if ( !settings->wmctrlCmd.isEmpty() ) { if (!settings->wmctrlCmd.isEmpty()) {
QTimer::singleShot( 5000, this, SLOT( RenameWindow() ) ); QTimer::singleShot(5000, this, SLOT(RenameWindow()));
} }
} }
lc::Session::~Session() lc::Session::~Session()
{ {
for ( auto &client : assocClients ) { for (auto &client : assocClients) {
client->SetSessionPort( 0 ); client->SetSessionPort(0);
client->SetzLeafVersion( "" ); client->SetzLeafVersion("");
} }
} }
QVariant lc::Session::GetDataItem( int argIndex ) QVariant lc::Session::GetDataItem(int argIndex)
{ {
switch ( argIndex ) { switch (argIndex) {
case 0: case 0:
return QVariant{ zTreeVersionPath.split( '_', QString::KeepEmptyParts, Qt::CaseInsensitive )[ 1 ] }; return QVariant{zTreeVersionPath.split('_', QString::KeepEmptyParts,
Qt::CaseInsensitive)[1]};
case 1: case 1:
return QVariant{ zTreePort }; return QVariant{zTreePort};
default: default:
return QVariant{}; return QVariant{};
} }
@ -79,31 +80,32 @@ QVariant lc::Session::GetDataItem( int argIndex )
void lc::Session::InitializeClasses() void lc::Session::InitializeClasses()
{ {
// Create the new data directory // Create the new data directory
QDir dir{ zTreeDataTargetPath }; QDir dir{zTreeDataTargetPath};
QString date_string( QDateTime::currentDateTime().toString( "yyMMdd_hhmm" ) ); QString date_string(QDateTime::currentDateTime().toString("yyMMdd_hhmm"));
if ( !dir.mkdir( zTreeDataTargetPath + "/" + date_string + "-" + QString::number( zTreePort ) ) ) { if (!dir.mkdir(zTreeDataTargetPath + "/" + date_string + "-" + QString::number(zTreePort))) {
throw lcDataTargetPathCreationFailed{}; 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; qDebug() << "New session's chosen_zTree_data_target_path:" << zTreeDataTargetPath;
zTreeInstance = new ZTree{ zTreeDataTargetPath, zTreePort, zTreeVersionPath, this }; zTreeInstance = new ZTree{zTreeDataTargetPath, zTreePort,
connect( zTreeInstance, &ZTree::ZTreeClosed, zTreeVersionPath, this};
this, &Session::OnzTreeClosed ); connect(zTreeInstance, &ZTree::ZTreeClosed,
this, &Session::OnzTreeClosed);
// Only create a 'Receipts_Handler' instance, if all neccessary variables were set // Only create a 'Receipts_Handler' instance, if all neccessary variables were set
if ( latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty() if (latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty()
&& !settings->latexCmd.isEmpty() ) { && !settings->latexCmd.isEmpty()) {
new ReceiptsHandler{ zTreeDataTargetPath, printReceiptsForLocalClients, new ReceiptsHandler{zTreeDataTargetPath, printReceiptsForLocalClients,
anonymousReceiptsPlaceholder, latexHeaderName, this }; anonymousReceiptsPlaceholder, latexHeaderName, this};
} else { } else {
qDebug() << "No 'ReceiptsHandler' instance was created."; 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; qDebug() << "z-Tree running on port" << zTreePort << "closed with exit code" << argExitCode;
emit SessionFinished( this ); emit SessionFinished(this);
} }
void lc::Session::RenameWindow() void lc::Session::RenameWindow()
@ -111,13 +113,13 @@ void lc::Session::RenameWindow()
// Example: wmctrl -r <window name> -T <new name> // Example: wmctrl -r <window name> -T <new name>
QStringList arguments; 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 // Start the process
QProcess renameZTreeWindowProcess; QProcess renameZTreeWindowProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); renameZTreeWindowProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
renameZTreeWindowProcess.setProcessEnvironment( env ); renameZTreeWindowProcess.startDetached(settings->wmctrlCmd, arguments);
renameZTreeWindowProcess.startDetached( settings->wmctrlCmd, arguments );
qDebug() << "Renamed window"; 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. * 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. 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 Q_OBJECT
public: 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, Session(QVector<Client *> &&argAssocClients, const QString &argZTreeDataTargetPath,
const quint16 argZTreePort, const QString &argZTreeVersionPath, const quint16 argZTreePort, const QString &argZTreeVersionPath,
bool argPrintReceiptsForLocalClients, bool argPrintReceiptsForLocalClients,
const QString &argAnonymousReceiptsPlaceholder, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, QObject *argParent = nullptr ); const QString &argLatexHeaderName, QObject *argParent = nullptr);
~Session(); ~Session() override;
/*! Returns the data item with the given index /*! Returns the data item with the given index
* *
* @param argIndex The index of the desired item * @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. //! This gets thrown as an exception if the chosen data target path could not be created.
class lcDataTargetPathCreationFailed {}; class lcDataTargetPathCreationFailed {};
signals: signals:
void SessionFinished( Session *argSession ); void SessionFinished(Session *argSession);
private slots: private slots:
/*! Starts the session by creating instances of the relevant classes /*! Starts the session by creating instances of the relevant classes
*/ */
void InitializeClasses(); 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 /*! Changes zTree's window title to contain its port number to make zTree windows distinguishable
*/ */
void RenameWindow(); void RenameWindow();
private: private:
const QString anonymousReceiptsPlaceholder; //! Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "") //! Placeholder which shall be inserted for participant names if anonymous printing is desired (QString != "")
const QVector< Client* > assocClients; const QString anonymousReceiptsPlaceholder;
const QString latexHeaderName; //! The name of the chosen LaTeX header const QVector<Client *> assocClients;
const bool printReceiptsForLocalClients = true; //! True if receipts shall be printed for local clients //! The name of the chosen LaTeX header
QString zTreeDataTargetPath; //! The path were the data of this zTree instance's session will be saved const QString latexHeaderName;
ZTree *zTreeInstance= nullptr; //! The session's zTree instance //! True if receipts shall be printed for local clients
const QString zTreeVersionPath; //! The path to the version of zTree used by this session's instance 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