Reformat Lablib

remotes/origin/HEAD
markuspg 6 years ago
parent bca1a0d423
commit 2ec99238fe

@ -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.
* *
@ -24,39 +24,41 @@
#include "lablib.h" #include "lablib.h"
lc::Lablib::Lablib( QObject *argParent ) : lc::Lablib::Lablib(QObject *argParent) :
QObject{ argParent }, QObject{argParent},
labSettings{ "Labcontrol", "Labcontrol", this }, labSettings{"Labcontrol", "Labcontrol", this},
sessionsModel{ new SessionsModel{ this } } sessionsModel{new SessionsModel{this}}
{ {
for ( const auto &s : settings->GetClients() ) { for (const auto &s : settings->GetClients()) {
connect( this, &Lablib::ZLEAF_RUNNING, connect(this, &Lablib::ZLEAF_RUNNING,
s, &Client::SetStateToZLEAF_RUNNING ); s, &Client::SetStateToZLEAF_RUNNING);
} }
DetectInstalledZTreeVersionsAndLaTeXHeaders(); DetectInstalledZTreeVersionsAndLaTeXHeaders();
// Initialize all 'netstat' query mechanisms // Initialize all 'netstat' query mechanisms
if ( !settings->netstatCmd.isEmpty() ) { if (!settings->netstatCmd.isEmpty()) {
netstatAgent = new NetstatAgent{ settings->netstatCmd }; netstatAgent = new NetstatAgent{settings->netstatCmd};
netstatAgent->moveToThread( &netstatThread ); netstatAgent->moveToThread(&netstatThread);
connect( &netstatThread, &QThread::finished, netstatAgent, &QObject::deleteLater ); connect(&netstatThread, &QThread::finished, netstatAgent, &QObject::deleteLater);
connect( netstatAgent, &NetstatAgent::QueryFinished, connect(netstatAgent, &NetstatAgent::QueryFinished,
this, &Lablib::GotNetstatQueryResult ); this, &Lablib::GotNetstatQueryResult);
netstatThread.start(); netstatThread.start();
netstatTimer = new QTimer{ this }; netstatTimer = new QTimer{this};
connect( netstatTimer, &QTimer::timeout, connect(netstatTimer, &QTimer::timeout,
netstatAgent, &NetstatAgent::QueryClientConnections ); netstatAgent, &NetstatAgent::QueryClientConnections);
netstatTimer->start( 500 ); netstatTimer->start(500);
} }
// Initialize the server for client help requests retrieval // Initialize the server for client help requests retrieval
if ( settings->clientHelpNotificationServerPort && !settings->serverIP.isEmpty() ) { if (settings->clientHelpNotificationServerPort
clientHelpNotificationServer = new ClientHelpNotificationServer{ this }; && !settings->serverIP.isEmpty()) {
clientHelpNotificationServer = new ClientHelpNotificationServer{this};
} }
} }
lc::Lablib::~Lablib () { lc::Lablib::~Lablib ()
if ( netstatTimer ) { {
if (netstatTimer) {
netstatTimer->stop(); netstatTimer->stop();
delete netstatTimer; delete netstatTimer;
} }
@ -64,122 +66,127 @@ lc::Lablib::~Lablib () {
netstatThread.wait(); netstatThread.wait();
} }
bool lc::Lablib::CheckIfUserIsAdmin() const { bool lc::Lablib::CheckIfUserIsAdmin() const
for ( const auto &s : settings->adminUsers ) { {
if ( s == settings->localUserName ) { for (const auto &s : settings->adminUsers) {
qDebug() << "User" << settings->localUserName << "has administrative rights."; if (s == settings->localUserName) {
qDebug() << "User" << settings->localUserName
<< "has administrative rights.";
return true; return true;
} }
} }
return false; return false;
} }
void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() { void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders()
{
} }
void lc::Lablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections ) { void lc::Lablib::GotNetstatQueryResult(QStringList *argActiveZLeafConnections)
if ( argActiveZLeafConnections != nullptr ) { {
for ( auto s: *argActiveZLeafConnections ) { if (argActiveZLeafConnections != nullptr) {
for (auto s : *argActiveZLeafConnections) {
// Set all given clients' statuses to 'ZLEAF_RUNNING' // Set all given clients' statuses to 'ZLEAF_RUNNING'
emit ZLEAF_RUNNING( s ); emit ZLEAF_RUNNING( s );
} }
} } else
else
qDebug() << "Netstat status query failed."; qDebug() << "Netstat status query failed.";
delete argActiveZLeafConnections; delete argActiveZLeafConnections;
} }
void lc::Lablib::ShowOrsee() { void lc::Lablib::ShowOrsee()
{
QProcess showOrseeProcess; QProcess showOrseeProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); showOrseeProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
showOrseeProcess.setProcessEnvironment( env ); QString program{settings->browserCmd};
QString program{ settings->browserCmd }; const QStringList arguments{settings->orseeUrl};
QStringList arguments{ QStringList{} << settings->orseeUrl }; showOrseeProcess.startDetached(program, arguments);
showOrseeProcess.startDetached( program, arguments );
// Output message via the debug messages tab // Output message via the debug messages tab
qDebug() << program << arguments.join( " " ); qDebug() << program << arguments.join(" ");
} }
void lc::Lablib::ShowPreprints() { void lc::Lablib::ShowPreprints()
{
// Start the process // Start the process
QProcess showPreprintsProcess; QProcess showPreprintsProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); showPreprintsProcess.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
showPreprintsProcess.setProcessEnvironment( env ); const QString program{settings->fileMngr};
QString program{ settings->fileMngr }; const QStringList arguments{settings->lcDataDir + "/preprints"};
QStringList arguments{ QStringList{} << settings->lcDataDir + "/preprints" }; showPreprintsProcess.startDetached(program, arguments);
showPreprintsProcess.startDetached( program, arguments );
// Output message via the debug messages tab // Output message via the debug messages tab
qDebug() << program << arguments.join( " " ); qDebug() << program << arguments.join(" ");
} }
void lc::Lablib::StartNewSession( QVector< Client* > argAssocCl, void lc::Lablib::StartNewSession(QVector<Client *> argAssocCl,
QString argParticipNameReplacement, QString argParticipNameReplacement,
bool argPrintLocalReceipts, QString argReceiptsHeader, bool argPrintLocalReceipts, QString argReceiptsHeader,
QString argzTreeDataTargetPath, quint16 argzTreePort, QString argzTreeDataTargetPath, quint16 argzTreePort,
QString argzTreeVersion ) { QString argzTreeVersion)
if ( !QDir( argzTreeDataTargetPath ).exists() ) { {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target path does not exist" ), if (!QDir(argzTreeDataTargetPath).exists()) {
tr( "Your chosen data target path does not exist." QMessageBox messageBox{QMessageBox::Critical, tr("Data target path does not exist"),
" Do you want it to be created automatically?" ), tr("Your chosen data target path does not exist."
QMessageBox::Yes | QMessageBox::No }; " Do you want it to be created automatically?"),
QMessageBox::Yes | QMessageBox::No};
messageBox.exec(); messageBox.exec();
if ( messageBox.clickedButton() == messageBox.button( QMessageBox::No ) ) { if (messageBox.clickedButton() == messageBox.button(QMessageBox::No)) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory will not" QMessageBox messageBox{QMessageBox::Critical,
" be created" ), tr("Data target directory will not be created"),
tr( "Your chosen data target directory does not exist and" tr("Your chosen data target directory does not exist and"
" will not be created. Please choose another one." ), " will not be created. Please choose another one."),
QMessageBox::Ok }; QMessageBox::Ok};
messageBox.exec(); messageBox.exec();
return; return;
} else { } else {
if ( !QDir().mkpath( argzTreeDataTargetPath ) ) { if (!QDir().mkpath(argzTreeDataTargetPath)) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory could" QMessageBox messageBox{QMessageBox::Critical,
" not be created" ), tr("Data target directory could not be created"),
tr( "Your chosen data target directory does not exist" tr("Your chosen data target directory does not exist"
" and could not be created. Please choose another" " and could not be created. Please choose another"
" one." ), QMessageBox::Ok }; " one."), QMessageBox::Ok};
messageBox.exec(); messageBox.exec();
return; return;
} }
} }
} }
try { try {
sessionsModel->push_back( new Session{ std::move( argAssocCl ), sessionsModel->push_back(new Session{std::move(argAssocCl),
argzTreeDataTargetPath, argzTreeDataTargetPath,
argzTreePort, argzTreeVersion, argzTreePort, argzTreeVersion,
argPrintLocalReceipts, argPrintLocalReceipts,
argParticipNameReplacement, argParticipNameReplacement,
argReceiptsHeader } ); argReceiptsHeader});
occupiedPorts.append( sessionsModel->back()->zTreePort ); occupiedPorts.append(sessionsModel->back()->zTreePort);
} } catch (Session::lcDataTargetPathCreationFailed) {
catch ( Session::lcDataTargetPathCreationFailed ) { QMessageBox::information(nullptr, tr("Chosen data target path could not be created"),
QMessageBox::information( nullptr, tr( "Chosen data target path could not be created" ), tr("The path specified by your chosen data target path '%1'"
tr( "The path specified by your chosen data target path '%1'" " could not be created. Please check if it is a valid"
" could not be created. Please check if it is a valid" " location and you have all needed permissions.")
" location and you have all needed permissions." ) .arg(argzTreeDataTargetPath));
.arg( argzTreeDataTargetPath ) );
} }
} }
void lc::Lablib::SetLocalZLeafDefaultName( const QString &argName ) { void lc::Lablib::SetLocalZLeafDefaultName(const QString &argName)
settings->SetLocalzLeafName( argName ); {
labSettings.setValue( "local_zLeaf_name", argName ); settings->SetLocalzLeafName(argName);
labSettings.setValue("local_zLeaf_name", argName);
} }
//Returns the commandline that is issued on the client when zleaf is started //Returns the commandline that is issued on the client when zleaf is started
QStringList lc::Lablib::getzLeafArgs( int sessionPort, QString zleafVersion ){ QStringList lc::Lablib::getzLeafArgs(int sessionPort, QString zleafVersion)
{
QStringList arguments; QStringList arguments;
if ( sessionPort == 7000 ) { if (sessionPort == 7000) {
arguments << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd arguments << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + zleafVersion + "/zleaf.exe" } << QString{settings->zTreeInstDir + "/zTree_" + zleafVersion + "/zleaf.exe"}
<< "/server" << settings->serverIP; << "/server" << settings->serverIP;
} else { } else {
arguments << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd arguments << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + zleafVersion + "/zleaf.exe" } << QString{settings->zTreeInstDir + "/zTree_" + zleafVersion + "/zleaf.exe"}
<< "/server" << settings->serverIP << "/channel" << "/server" << settings->serverIP << "/channel"
<< QString::number( sessionPort- 7000 ); << QString::number(sessionPort - 7000);
} }
//Return the crafted QStringList //Return the crafted QStringList

@ -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.
* *
@ -45,7 +45,7 @@
#include "sessionsmodel.h" #include "sessionsmodel.h"
#include "settings.h" #include "settings.h"
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr<lc::Settings> settings;
namespace lc { namespace lc {
@ -56,15 +56,16 @@ namespace lc {
class Lablib : public QObject class Lablib : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/*! /*!
* \brief Lablib's constructor * \brief Lablib's constructor
* \param[in] argParent This 'lcLablib' instance's parent QObject * \param[in] argParent This 'lcLablib' instance's parent QObject
*/ */
Lablib( QObject *argParent = nullptr ); Lablib(QObject *argParent = nullptr);
/** Lablib's destructor /** Lablib's destructor
*/ */
~Lablib(); ~Lablib() override;
/*! /*!
* \brief CheckIfUserIsAdmin checks if the account with the passed user name has administrative rights * \brief CheckIfUserIsAdmin checks if the account with the passed user name has administrative rights
* \param argUserName The account name which shall checked for administrative rights * \param argUserName The account name which shall checked for administrative rights
@ -75,40 +76,46 @@ public:
* *
* @return A pointer to a QVector<unsigned int> containing all occupied ports * @return A pointer to a QVector<unsigned int> containing all occupied ports
*/ */
const QVector< quint16 > &GetOccupiedPorts () const { return occupiedPorts; } const QVector<quint16> &GetOccupiedPorts () const
{
return occupiedPorts;
}
/** Returns a pointer to the QAbstractTableModel storing the Session instances /** Returns a pointer to the QAbstractTableModel storing the Session instances
* *
* @return A pointer to the QAbstractTableModel storing the Session instances * @return A pointer to the QAbstractTableModel storing the Session instances
*/ */
SessionsModel *GetSessionsModel () const { return sessionsModel; } SessionsModel *GetSessionsModel () const
{
return sessionsModel;
}
//! Sets the default name of local zLeaf instances //! Sets the default name of local zLeaf instances
/** /**
* @param argName The default name local zLeaf instances shall have * @param argName The default name local zLeaf instances shall have
*/ */
void SetLocalZLeafDefaultName( const QString &argName ); void SetLocalZLeafDefaultName(const QString &argName);
void ShowOrsee(); void ShowOrsee();
void ShowPreprints(); void ShowPreprints();
void StartNewSession( QVector< Client* > argAssocCl, QString argParticipNameReplacement, void StartNewSession(QVector<Client *> argAssocCl, QString argParticipNameReplacement,
bool argPrintLocalReceipts, QString argReceiptsHeader, bool argPrintLocalReceipts, QString argReceiptsHeader,
QString argzTreeDataTargetPath, quint16 argzTreePort, QString argzTreeDataTargetPath, quint16 argzTreePort,
QString argzTreeVersion ); QString argzTreeVersion);
/*! /*!
* \brief Returns the commandline to issue on the client(s) in order to start zLeaf * \brief Returns the commandline to issue on the client(s) in order to start zLeaf
* @param sessionPort The port zLeaf shall connect to * @param sessionPort The port zLeaf shall connect to
* @param zLeafVersion zLeaf Version to start * @param zLeafVersion zLeaf Version to start
*/ */
QStringList getzLeafArgs( int sessionPort, QString zleafVersion ); QStringList getzLeafArgs(int sessionPort, QString zleafVersion);
public slots: public slots:
signals: signals:
void ZLEAF_RUNNING( QString argClientIP ); void ZLEAF_RUNNING(QString argClientIP);
private slots: private slots:
//! Gets the output from NetstatAgent //! Gets the output from NetstatAgent
void GotNetstatQueryResult( QStringList *argActiveZLeafConnections ); void GotNetstatQueryResult(QStringList *argActiveZLeafConnections);
private: private:
//! Detects installed zTree version and LaTeX headers //! Detects installed zTree version and LaTeX headers
@ -117,15 +124,19 @@ private:
*/ */
void ReadSettings(); void ReadSettings();
ClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients //! A server to retrieve help requests from the clients
ClientHelpNotificationServer *clientHelpNotificationServer = nullptr;
QSettings labSettings; QSettings labSettings;
NetstatAgent *netstatAgent = nullptr; //! Tries to detect active zLeaf connections from the clients //! Tries to detect active zLeaf connections from the clients
NetstatAgent *netstatAgent = nullptr;
QThread netstatThread; QThread netstatThread;
QTimer *netstatTimer = nullptr; //! A timer for regular execution of the NetstatAgent instance's request mechanism //! A timer for regular execution of the NetstatAgent instance's request mechanism
QTimer *netstatTimer = nullptr;
QVector< quint16 > occupiedPorts; QVector< quint16 > occupiedPorts;
SessionsModel *sessionsModel = nullptr; //! A derivation from QAbstractTableModel used to store the single Session instances //! A derivation from QAbstractTableModel used to store the single Session instances
SessionsModel *sessionsModel = nullptr;
}; };
} } // namespace lc
#endif // LABLIB_H #endif // LABLIB_H

Loading…
Cancel
Save