Make proper use of namespaces in the entire backend classes

remotes/origin/HEAD
markuspg 8 years ago
parent b514858e96
commit 7a463a48a5

@ -19,7 +19,10 @@
#include "client.h"
lcClient::lcClient( QPlainTextEdit *argDebugMessagesTextEdit, QString *argIP, QString *argMAC, QString *argName, unsigned short int argXPosition, unsigned short int argYPosition, bool argHasWebcam, const QVector< QString* > * const argSettingsItems ):
lc::Client::Client( QPlainTextEdit *argDebugMessagesTextEdit, QString *argIP, QString *argMAC,
QString *argName, unsigned short int argXPosition,
unsigned short int argYPosition, bool argHasWebcam,
const QVector< QString* > * const argSettingsItems ):
hasWebcam{ argHasWebcam },
ip{ *argIP },
mac{ *argMAC },
@ -33,16 +36,20 @@ lcClient::lcClient( QPlainTextEdit *argDebugMessagesTextEdit, QString *argIP, QS
qRegisterMetaType< state_t >( "STATE" );
if ( ( *settingsItems )[ ( int )settingsItems_t::PING_COMMAND ] ) {
pinger = new lcClientPinger{ &ip, ( *settingsItems )[ ( int )settingsItems_t::PING_COMMAND ] };
pinger = new ClientPinger{ &ip, ( *settingsItems )[ ( int )settingsItems_t::PING_COMMAND ] };
pinger->moveToThread( &pingerThread );
connect( &pingerThread, &QThread::finished, pinger, &QObject::deleteLater );
connect( this, &lcClient::PingWanted, pinger, &lcClientPinger::doPing );
connect( pinger, &lcClientPinger::PingFinished, this, &lcClient::GotStatusChanged );
connect( &pingerThread, &QThread::finished,
pinger, &QObject::deleteLater );
connect( this, &Client::PingWanted,
pinger, &ClientPinger::doPing );
connect( pinger, &ClientPinger::PingFinished,
this, &Client::GotStatusChanged );
// connect(pinger, &ClientPinger::ping_string, this, &Client::display_ping_string);
pingerThread.start();
pingTimer = new QTimer{ this };
connect( pingTimer, &QTimer::timeout, this, &lcClient::RequestAPing ) ;
connect( pingTimer, &QTimer::timeout,
this, &Client::RequestAPing ) ;
pingTimer->start( 3000 );
}
@ -51,7 +58,7 @@ lcClient::lcClient( QPlainTextEdit *argDebugMessagesTextEdit, QString *argIP, QS
.arg( QString::number( yPosition ) ).arg( QString::number( hasWebcam ) ) );
}
lcClient::~lcClient() {
lc::Client::~Client() {
if ( pingTimer ) {
pingTimer->stop();
}
@ -60,7 +67,7 @@ lcClient::~lcClient() {
pingerThread.wait();
}
void lcClient::BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::BeamFile( const QString &argFileToBeam, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
if ( state < state_t::RESPONDING ) {
return;
}
@ -77,7 +84,7 @@ void lcClient::BeamFile( const QString &argFileToBeam, const QString * const arg
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settingsItems_t::RCP_COMMAND ] + " " + arguments.join( " " ) );
}
void lcClient::Boot( const QString * const argNetworkBroadcastAddress ) {
void lc::Client::Boot( const QString * const argNetworkBroadcastAddress ) {
if ( state == state_t::SHUTTING_DOWN || state == state_t::RESPONDING ) {
return;
}
@ -100,7 +107,7 @@ void lcClient::Boot( const QString * const argNetworkBroadcastAddress ) {
GotStatusChanged( state_t::BOOTING );
}
void lcClient::DeactiveScreensaver( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::DeactiveScreensaver( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
QStringList arguments;
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name }
<< *( *settingsItems )[ ( int )settingsItems_t::XSET_COMMAND ] << "-display" << ":0.0" << "dpms" << "force" << "on";
@ -120,7 +127,7 @@ void lcClient::DeactiveScreensaver( const QString * const argPublickeyPathUser,
// delete ping_string;
// }
void lcClient::GotStatusChanged( state_t argState ) {
void lc::Client::GotStatusChanged( state_t argState ) {
if ( ( protectedCycles > 0 ) && ( state == state_t::BOOTING ) && ( argState != state_t::RESPONDING ) ) {
return;
}
@ -131,7 +138,7 @@ void lcClient::GotStatusChanged( state_t argState ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + name + " status changed to: " + QString::number( ( int )argState ) );
}
void lcClient::KillZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::KillZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
QStringList arguments;
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name }
<< QString{ *( *settingsItems )[ ( int )settingsItems_t::LABCONTROL_INSTALLATION_DIRECTORY ] + "/scripts/kill_zLeaf_labcontrol2.sh" };
@ -149,7 +156,7 @@ void lcClient::KillZLeaf( const QString * const argPublickeyPathUser, const QStr
pingTimer->start( 3000 );
}
void lcClient::OpenFilesystem( const QString * const argUserToBeUsed ) {
void lc::Client::OpenFilesystem( const QString * const argUserToBeUsed ) {
if ( state < state_t::RESPONDING ) {
return;
}
@ -162,7 +169,7 @@ void lcClient::OpenFilesystem( const QString * const argUserToBeUsed ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settingsItems_t::FILE_MANAGER ] + " " + arguments.join( " " ) );
}
void lcClient::OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
if ( ( *settingsItems )[ ( int )settingsItems_t::TERMINAL_EMULATOR_COMMAND ] ) {
if ( state < state_t::RESPONDING ) {
return;
@ -201,14 +208,14 @@ void lcClient::OpenTerminal( const QString &argCommand, const bool &argOpenAsRoo
}
}
void lcClient::RequestAPing() {
void lc::Client::RequestAPing() {
if ( protectedCycles > 0 ) {
--protectedCycles;
}
emit PingWanted();
}
void lcClient::SetStateToZLEAF_RUNNING( QString argClientIP ) {
void lc::Client::SetStateToZLEAF_RUNNING( QString argClientIP ) {
if ( argClientIP != ip ) {
return;
}
@ -221,7 +228,7 @@ void lcClient::SetStateToZLEAF_RUNNING( QString argClientIP ) {
}
}
void lcClient::ShowDesktop() {
void lc::Client::ShowDesktop() {
QStringList arguments;
arguments << name;
@ -234,7 +241,7 @@ void lcClient::ShowDesktop() {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settingsItems_t::VNC_VIEWER ] + " " + arguments.join( " " ) );
}
void lcClient::Shutdown( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
void lc::Client::Shutdown( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) {
if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING || state == state_t::SHUTTING_DOWN ) {
return;
}
@ -257,7 +264,7 @@ void lcClient::Shutdown( const QString * const argPublickeyPathUser, const QStri
GotStatusChanged( state_t::SHUTTING_DOWN );
}
void lcClient::StartZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients, const QString * const argZTreeVersion,
void lc::Client::StartZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients, const QString * const argZTreeVersion,
const QString * const argServerIP, unsigned short int argPort, const QString * const argFakeName ) {
if ( state < state_t::RESPONDING ) {
return;

@ -31,12 +31,13 @@
#include "global.h"
#include "clientpinger.h"
namespace lc {
//! Class which represents the clients in the lab
/*!
This class contains elements and functions needed to represent all functions of a client.
*/
class lcClient : public QObject
{
class Client : public QObject {
Q_OBJECT
public slots:
@ -62,9 +63,9 @@ public:
@param argHasWebcam If the represented client has a webcam installed
@param argSettingsItems A QVector storing many needed data QStrings
*/
lcClient( QPlainTextEdit *argDebugMessagesTextEditPtr, QString *argIP, QString *argMAC, QString *argName, unsigned short int argXPosition, unsigned short int argYPosition, bool argHasWebcam, const QVector< QString* > * const argSettingsItems );
Client( QPlainTextEdit *argDebugMessagesTextEditPtr, QString *argIP, QString *argMAC, QString *argName, unsigned short int argXPosition, unsigned short int argYPosition, bool argHasWebcam, const QVector< QString* > * const argSettingsItems );
//! Client's destructor
~lcClient();
~Client();
//! Beams the chosen file to the client's 'media4ztree' directory
/*!
@param argFileToBeam The file which shall be beamed to the client's 'media4ztree' directory
@ -130,7 +131,7 @@ public:
private:
QPlainTextEdit * const debugMessagesTextEdit = nullptr;
unsigned short int protectedCycles;
lcClientPinger *pinger = nullptr;
ClientPinger *pinger = nullptr;
QThread pingerThread;
const QVector<QString*> * const settingsItems;
state_t state = state_t::UNINITIALIZED;
@ -145,4 +146,6 @@ signals:
void PingWanted();
};
}
#endif // CLIENT_H

@ -19,7 +19,7 @@
#include "clienthelpnotificationserver.h"
lcClientHelpNotificationServer::lcClientHelpNotificationServer( const QMap< QString, lcClient* > * const argClientIPsToClientsMap,
lc::ClientHelpNotificationServer::ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap,
const QString * const argServerIP, const unsigned short int &argServerPort, QObject *argParent ) :
QObject{ argParent },
clientIPsToClientsMap{ argClientIPsToClientsMap },
@ -40,16 +40,18 @@ lcClientHelpNotificationServer::lcClientHelpNotificationServer( const QMap< QStr
config = manager.defaultConfiguration();
}
networkSession = new QNetworkSession{ config, this };
connect( networkSession, &QNetworkSession::opened, this, &lcClientHelpNotificationServer::OpenSession );
connect( networkSession, &QNetworkSession::opened,
this, &ClientHelpNotificationServer::OpenSession );
networkSession->open();
} else {
OpenSession();
}
connect( helpMessageServer, &QTcpServer::newConnection, this, &lcClientHelpNotificationServer::SendReply );
connect( helpMessageServer, &QTcpServer::newConnection,
this, &ClientHelpNotificationServer::SendReply );
}
void lcClientHelpNotificationServer::OpenSession() {
void lc::ClientHelpNotificationServer::OpenSession() {
// Save the used configuration
if ( networkSession ) {
QNetworkConfiguration config = networkSession->configuration();
@ -75,7 +77,7 @@ void lcClientHelpNotificationServer::OpenSession() {
}
}
void lcClientHelpNotificationServer::SendReply() {
void lc::ClientHelpNotificationServer::SendReply() {
QByteArray block;
QDataStream out{ &block, QIODevice::WriteOnly };
out.setVersion( QDataStream::Qt_5_2 );

@ -27,11 +27,12 @@
#include <QMessageBox>
#include <QtNetwork>
class lcClientHelpNotificationServer : public QObject
{
namespace lc {
class ClientHelpNotificationServer : public QObject {
Q_OBJECT
public:
explicit lcClientHelpNotificationServer( const QMap< QString, lcClient* > * const argClientIPsToClientsMap,
explicit ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap,
const QString * const argServerIP, const unsigned short int &argServerPort, QObject *argParent = nullptr );
signals:
@ -39,7 +40,7 @@ signals:
public slots:
private:
const QMap< QString, lcClient* > * const clientIPsToClientsMap = nullptr;
const QMap< QString, Client* > * const clientIPsToClientsMap = nullptr;
QTcpServer *helpMessageServer = nullptr;
const QHostAddress hostAddress;
QNetworkSession *networkSession = nullptr;
@ -50,4 +51,6 @@ private slots:
void SendReply();
};
}
#endif // CLIENTHELPNOTIFICATIONSERVER_H

@ -19,7 +19,8 @@
#include "clientpinger.h"
lcClientPinger::lcClientPinger( const QString * const argIP, const QString * const argPingCommand, QObject *argParent ) :
lc::ClientPinger::ClientPinger( const QString * const argIP,
const QString * const argPingCommand, QObject *argParent ) :
QObject{ argParent },
ip{ argIP },
// Arguments: -c 1 (send 1 ECHO_REQUEST packet) -w 1 (timeout after 1 second) -q (quiet output)
@ -33,12 +34,12 @@ lcClientPinger::lcClientPinger( const QString * const argIP, const QString * con
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join(" ")));
}
lcClientPinger::~lcClientPinger() {
lc::ClientPinger::~ClientPinger() {
delete pingProcess;
delete pingArguments;
}
void lcClientPinger::doPing() {
void lc::ClientPinger::doPing() {
// Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED;
@ -60,6 +61,6 @@ void lcClientPinger::doPing() {
}
}
void lcClientPinger::setStateToZLEAF_RUNNING() {
void lc::ClientPinger::setStateToZLEAF_RUNNING() {
state = state_t::ZLEAF_RUNNING;
}

@ -26,13 +26,15 @@
#include "global.h"
namespace lc {
//! The ClientPinger class is used to do repetitive pings of the owning Client instance's client.
/*!
This class is just used for executing repetitive pings.
*/
class lcClientPinger : public QObject
{
class ClientPinger : public QObject {
Q_OBJECT
public:
//! ClientPinger's constructor
/*!
@ -40,9 +42,9 @@ public:
@param argPingCommand The path were the command to be executed for pings resides
@param argParent The ClientPinger's parent owning this instance of it
*/
explicit lcClientPinger( const QString * const argIP, const QString * const argPingCommand, QObject *argParent = nullptr );
explicit ClientPinger( const QString * const argIP, const QString * const argPingCommand, QObject *argParent = nullptr );
//! ClientPinger's destructor
~lcClientPinger();
~ClientPinger();
public slots:
//! This slot executes a ping when called.
@ -64,4 +66,6 @@ signals:
void PingFinished( state_t state );
};
}
#endif // CLIENTPINGER_H

@ -23,9 +23,9 @@
#include "lablib.h"
lcLablib::lcLablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent ) :
lc::Lablib::Lablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent ) :
QObject{ argParent },
clientIPsToClientsMap{ new QMap< QString, lcClient* > },
clientIPsToClientsMap{ new QMap< QString, Client* > },
debugMessagesTextEdit{ argDebugMessagesTextEdit },
labSettings{ "Economic Laboratory", "Labcontrol", this },
occupiedPorts{ new QVector< int > },
@ -39,23 +39,25 @@ lcLablib::lcLablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent
// Initialize all 'netstat' query mechanisms
if ( ( *settingsItems )[ ( int )settingsItems_t::NETSTAT_COMMAND ] ) {
netstatAgent = new lcNetstatAgent{ ( *settingsItems )[ ( int )settingsItems_t::NETSTAT_COMMAND ] };
netstatAgent = new NetstatAgent{ ( *settingsItems )[ ( int )settingsItems_t::NETSTAT_COMMAND ] };
netstatAgent->moveToThread( &netstatThread );
connect( &netstatThread, &QThread::finished, netstatAgent, &QObject::deleteLater );
connect( netstatAgent, &lcNetstatAgent::QueryFinished, this, &lcLablib::GotNetstatQueryResult );
connect( netstatAgent, &NetstatAgent::QueryFinished,
this, &Lablib::GotNetstatQueryResult );
netstatThread.start();
netstatTimer = new QTimer{ this };
connect( netstatTimer, &QTimer::timeout, netstatAgent, &lcNetstatAgent::QueryClientConnections );
connect( netstatTimer, &QTimer::timeout,
netstatAgent, &NetstatAgent::QueryClientConnections );
netstatTimer->start( 500 );
}
// Initialize the server for client help requests retrieval
if ( clientHelpNotificationServerPort && ( *settingsItems )[ ( int )settingsItems_t::SERVER_IP ] ) {
clientHelpNotificationServer = new lcClientHelpNotificationServer{ clientIPsToClientsMap, ( *settingsItems )[ ( int )settingsItems_t::SERVER_IP ], clientHelpNotificationServerPort, this };
clientHelpNotificationServer = new ClientHelpNotificationServer{ clientIPsToClientsMap,( *settingsItems )[ ( int )settingsItems_t::SERVER_IP ], clientHelpNotificationServerPort, this };
}
}
lcLablib::~lcLablib () {
lc::Lablib::~Lablib () {
if ( netstatTimer ) {
netstatTimer->stop();
delete netstatTimer;
@ -64,7 +66,7 @@ lcLablib::~lcLablib () {
netstatThread.wait();
delete adminUsers;
if ( clients ) {
for ( QVector< lcClient* >::iterator it = clients->begin(); it != clients->end(); ++it ) {
for ( QVector< Client* >::iterator it = clients->begin(); it != clients->end(); ++it ) {
delete *it;
}
}
@ -78,7 +80,9 @@ lcLablib::~lcLablib () {
delete settingsItems;
}
bool lcLablib::CheckPathAndComplain( const QString * const argPath, const QString &argVariableName, const QString &argComplaint ) {
bool lc::Lablib::CheckPathAndComplain( const QString * const argPath,
const QString &argVariableName,
const QString &argComplaint ) {
if ( !QFile::exists( *argPath ) ) {
QMessageBox::information( nullptr, tr( "Specified path '%1' does not exist" ).arg( argVariableName ), tr( "The path specified by '%1' does not exist. %2" ).arg( argVariableName ).arg( argComplaint ) );
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] The path specified by '%1' does not exist. %2" ).arg( argVariableName ).arg( argComplaint ) );
@ -88,7 +92,7 @@ bool lcLablib::CheckPathAndComplain( const QString * const argPath, const QStrin
return true;
}
void lcLablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
// Detect the installed LaTeX headers
if ( ( *settingsItems )[ ( int )settingsItems_t::LABCONTROL_INSTALLATION_DIRECTORY ] ) {
QDir laTeXDirectory{ *( *settingsItems )[ ( int )settingsItems_t::LABCONTROL_INSTALLATION_DIRECTORY ], "*header.tex", QDir::Name, QDir::CaseSensitive | QDir::Files | QDir::Readable };
@ -127,7 +131,7 @@ void lcLablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
}
}
void lcLablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections ) {
void lc::Lablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections ) {
if ( argActiveZLeafConnections != nullptr ) {
for ( auto s: *argActiveZLeafConnections ) {
// Set all given clients' statuses to 'ZLEAF_RUNNING'
@ -139,7 +143,7 @@ void lcLablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections ) {
delete argActiveZLeafConnections;
}
void lcLablib::ReadSettings() {
void lc::Lablib::ReadSettings() {
QStringList simpleLoadableItems = { QStringList{}
<< "dvips_command"
<< "file_manager"
@ -325,9 +329,9 @@ void lcLablib::ReadSettings() {
}
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] client_ypos: %1" ).arg( clientYPositions.join( " / " ) ) );
clients = new QVector< lcClient* >;
clients = new QVector< Client* >;
for ( int i = 0; i < clientQuantity; i++ ) {
clients->append( new lcClient{ debugMessagesTextEdit, &clientIPs[ i ], &clientMACs[ i ], &clientNames[ i ], clientXPositions[ i ].toUShort(),
clients->append( new Client{ debugMessagesTextEdit, &clientIPs[ i ], &clientMACs[ i ], &clientNames[ i ], clientXPositions[ i ].toUShort(),
clientYPositions[ i ].toUShort(), clientWebcams[ i ].toInt(), settingsItems } );
// Add an corresponding entry to the 'client_ips_to_clients_map' std::map<QString, Client*>
@ -340,13 +344,14 @@ void lcLablib::ReadSettings() {
clientPointerAddressStream << clientPointerAddress;
// Connect the 'Client' instance to the 'ZLEAF_RUNNING(QString client_ip)' signal
connect( this, &lcLablib::ZLEAF_RUNNING, clients->last(), &lcClient::SetStateToZLEAF_RUNNING );
connect( this, &Lablib::ZLEAF_RUNNING,
clients->last(), &Client::SetStateToZLEAF_RUNNING );
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] Added '%1' to 'client_ips_to_clients_map': '%2'" ).arg( clients->last()->name ).arg( clientPointerAddressString ) );
}
}
QString *lcLablib::ReadSettingsItem( const QString &argVariableName, const QString &argComplaint, bool argItemIsFile ) {
QString *lc::Lablib::ReadSettingsItem( const QString &argVariableName, const QString &argComplaint, bool argItemIsFile ) {
if ( !labSettings.contains( argVariableName ) ) {
QMessageBox::information( nullptr, tr( "'%1' not set" ).arg( argVariableName ), tr( "The '%1' variable was not set. %2" ).arg( argVariableName ).arg( argComplaint ) );
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] '%1' was not set. %2" ).arg( argVariableName ).arg( argComplaint ) );
@ -369,42 +374,42 @@ QString *lcLablib::ReadSettingsItem( const QString &argVariableName, const QStri
return nullptr;
}
void lcLablib::SetAnonymousReceiptsPlaceholder( const QString &argPlaceHolder ) {
void lc::Lablib::SetAnonymousReceiptsPlaceholder( const QString &argPlaceHolder ) {
anonymousReceiptsPlaceholder = argPlaceHolder;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] anonymous_receipts_placeholder set to: '%1'" ).arg( anonymousReceiptsPlaceholder ) );
}
void lcLablib::SetChosenLaTeXHeader( const QString &argLatexHeader ) {
void lc::Lablib::SetChosenLaTeXHeader( const QString &argLatexHeader ) {
chosenLaTeXHeader = argLatexHeader;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] chosen_latex_header set to: '%1'" ).arg( chosenLaTeXHeader ) );
}
void lcLablib::SetChosenZTreeDataTargetPath( const QString &argZTreeDataTargetPath ) {
void lc::Lablib::SetChosenZTreeDataTargetPath( const QString &argZTreeDataTargetPath ) {
chosenZTreeDataTargetPath = argZTreeDataTargetPath;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] chosen_zTree_data_target_path set to: '%1'" ).arg( chosenZTreeDataTargetPath ) );
}
void lcLablib::SetChosenZTreePort( const int &argPort ) {
void lc::Lablib::SetChosenZTreePort( const int &argPort ) {
chosenZTreePort = argPort;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] chosen_zTree_port set to: '%1'" ).arg( QString::number( chosenZTreePort ) ) );
}
void lcLablib::SetChosenZTreeVersion( const QString &argZTreeVersion ) {
void lc::Lablib::SetChosenZTreeVersion( const QString &argZTreeVersion ) {
chosenZTreeVersion = QString{ "zTree_" + argZTreeVersion };
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] chosen_zTree_version set to: '%1'" ).arg( chosenZTreeVersion ) );
}
void lcLablib::SetPrintReceiptsForLocalClients( const bool &argPrintReceiptsForLocalClients ) {
void lc::Lablib::SetPrintReceiptsForLocalClients( const bool &argPrintReceiptsForLocalClients ) {
PrintReceiptsForLocalClients = argPrintReceiptsForLocalClients;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] Set print_receipts_for_local_clients to : '%1'" ).arg( QString::number( PrintReceiptsForLocalClients ) ) );
}
void lcLablib::SetUserNameOnServer( const QString &argUserName ) {
void lc::Lablib::SetUserNameOnServer( const QString &argUserName ) {
userNameOnServer = argUserName;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] user_name_on_server set to: '%1'" ).arg( userNameOnServer ) );
}
void lcLablib::ShowOrsee() {
void lc::Lablib::ShowOrsee() {
// Start the process
QProcess showOrseeProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -415,7 +420,7 @@ void lcLablib::ShowOrsee() {
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] %1" ).arg( *( *settingsItems )[ ( int )settingsItems_t::ORSEE_COMMAND ] ) );
}
void lcLablib::ShowPreprints() {
void lc::Lablib::ShowPreprints() {
// Start the process
QProcess showPreprintsProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@ -428,7 +433,7 @@ void lcLablib::ShowPreprints() {
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] %1 %2" ).arg( program ).arg( arguments.join( " " ) ) );
}
void lcLablib::StartNewZTreeInstance() {
void lc::Lablib::StartNewZTreeInstance() {
if ( !QDir( chosenZTreeDataTargetPath ).exists() ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target path does not exist" ),
tr( "Your chosen data target path does not exist. Do you want it to be created automatically?" ), QMessageBox::Yes | QMessageBox::No };
@ -449,18 +454,21 @@ void lcLablib::StartNewZTreeInstance() {
}
}
try {
sessionsModel->push_back( new lcSession{ debugMessagesTextEdit, chosenZTreeDataTargetPath, chosenZTreePort, chosenZTreeVersion,
PrintReceiptsForLocalClients, anonymousReceiptsPlaceholder, chosenLaTeXHeader, settingsItems } );
sessionsModel->push_back( new Session{ debugMessagesTextEdit, chosenZTreeDataTargetPath,
chosenZTreePort, chosenZTreeVersion,
PrintReceiptsForLocalClients,
anonymousReceiptsPlaceholder, chosenLaTeXHeader,
settingsItems } );
occupiedPorts->append( sessionsModel->back()->zTreePort );
}
catch ( lcSession::lcDataTargetPathCreationFailed ) {
catch ( Session::lcDataTargetPathCreationFailed ) {
QMessageBox::information( nullptr, tr( "Chosen data target path could not be created" ),
tr( "The path specified by your chosen data target path '%1' could not be created. Please check if it is a valid location and you have all needed permissions." )
.arg( chosenZTreeDataTargetPath ) );
}
}
void lcLablib::SetLocalZLeafDefaultName( const QString &argName ) {
void lc::Lablib::SetLocalZLeafDefaultName( const QString &argName ) {
delete ( *settingsItems )[ ( int )settingsItems_t::LOCAL_ZLEAF_NAME ];
( *settingsItems )[ ( int )settingsItems_t::LOCAL_ZLEAF_NAME ] = new QString{ argName };
labSettings.setValue( "local_zLeaf_name", argName );

@ -43,11 +43,13 @@
#include "session.h"
#include "sessionsmodel.h"
namespace lc {
//! This class represents the entire lab and running sessions.
/*!
This class contains elements and functions needed to represent the lab and running sessions.
*/
class lcLablib : public QObject
class Lablib : public QObject
{
Q_OBJECT
public:
@ -56,10 +58,10 @@ public:
* @param argDebugMessagesTextEdit A pointer to the debug messages text edit for verbose output
* @param argParent This 'lcLablib' instance's parent QObject
*/
lcLablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent = nullptr );
Lablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent = nullptr );
/** Lablib's destructor
*/
~lcLablib();
~Lablib();
/*! Returns the users who have administrative rights
*
* @return The users with administrative rights
@ -79,7 +81,7 @@ public:
*
* @return A QVector of pointers to the Client class instances
*/
QVector<lcClient*> *GetClients () const { return clients; }
QVector< Client* > *GetClients () const { return clients; }
/** Returns the default receipt index for the 'CBReceipts' combobox
*
* @return The default receipt index for the 'CBReceipts' combobox
@ -187,16 +189,16 @@ private:
QString chosenZTreeDataTargetPath;
int chosenZTreePort = 7000; //! Stores the currently chosen port for new zTree instances
QString chosenZTreeVersion;
lcClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients
ClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients
unsigned short int clientHelpNotificationServerPort = 0; //! The port the help requests shall be received on
QMap< QString, lcClient* > * clientIPsToClientsMap = nullptr; //! A map container storing ip-client pairs
QVector<lcClient*> *clients = nullptr; //! A QVector storing pointers to all Client instances
QMap< QString, Client* > * clientIPsToClientsMap = nullptr; //! A map container storing ip-client pairs
QVector<Client*> *clients = nullptr; //! A QVector storing pointers to all Client instances
QPlainTextEdit *debugMessagesTextEdit = nullptr; //! This stores a pointer to the text edit in the debug tab to be able to write to it
int defaultReceiptIndex = 0; //! Stores the index of the LaTeX header to be displayed by default
QStringList *installedLaTeXHeaders = nullptr;
QStringList *InstalledZTreeVersions = nullptr;
QSettings labSettings;
lcNetstatAgent *netstatAgent = nullptr; //! Tries to detect active zLeaf connections from the clients
NetstatAgent *netstatAgent = nullptr; //! Tries to detect active zLeaf connections from the clients
QThread netstatThread;
QTimer *netstatTimer = nullptr; //! A timer for regular execution of the NetstatAgent instance's request mechanism
QVector< int > *occupiedPorts = nullptr;
@ -207,4 +209,6 @@ private:
QStringList *webcams = nullptr; //! A QStringList containing all available stationary webcams in the laboratory
};
}
#endif // LABLIB_H

@ -19,7 +19,7 @@
#include "netstatagent.h"
lcNetstatAgent::lcNetstatAgent( QString *argNetstatCommand, QObject *argParent ) :
lc::NetstatAgent::NetstatAgent( QString *argNetstatCommand, QObject *argParent ) :
QObject{ argParent },
extractionRegexp{ "\\d+\\.\\d+\\.\\d+\\.\\d+" },
netstatArguments{ QStringList{} << "-anp" << "--tcp" },
@ -31,7 +31,7 @@ lcNetstatAgent::lcNetstatAgent( QString *argNetstatCommand, QObject *argParent )
netstatQueryProcess.setProcessEnvironment( env );
}
void lcNetstatAgent::QueryClientConnections() {
void lc::NetstatAgent::QueryClientConnections() {
netstatQueryProcess.start( netstatCommand, netstatArguments );
if ( !netstatQueryProcess.waitForFinished( 400 ) ) {
emit QueryFinished( nullptr );

@ -25,15 +25,17 @@
#include <QRegularExpression>
#include <QStringList>
namespace lc {
//! The NetstatAgent class is used to do repetitive runs of the 'netstat' program to check for active zLeaf connections.
/*!
This class is just used for repetive executions of netstat.
*/
class lcNetstatAgent : public QObject
{
class NetstatAgent : public QObject {
Q_OBJECT
public:
explicit lcNetstatAgent( QString *argNetstatCommand, QObject *argParent = nullptr );
explicit NetstatAgent( QString *argNetstatCommand, QObject *argParent = nullptr );
signals:
//! This signal is emitted if the query of the currently active zLeaf connections finished
@ -50,4 +52,6 @@ private:
const QRegularExpression searchRegexp;
};
}
#endif // NETSTATAGENT_H

@ -19,9 +19,13 @@
#include "receipts_handler.h"
lcReceiptsHandler::lcReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
const bool &argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, const QVector< QString* > * const argSettingsItems, QObject *argParent ) :
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 },
@ -43,13 +47,18 @@ lcReceiptsHandler::lcReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit,
paymentFile = new QFile( expectedPaymentFilePath );
// Create a QTimer regularly checking if the payment file was created and print it if so
connect( timer, &QTimer::timeout, this, &lcReceiptsHandler::PrintReceipts );
connect( timer, &QTimer::timeout,
this, &ReceiptsHandler::PrintReceipts );
timer->start( 2000 );
}
lcReceiptsHandler::lcReceiptsHandler( 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 ) :
lc::ReceiptsHandler::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 ) :
QObject{ argParent },
anonymousReceiptsPlaceholder{ new QString{ argAnonymousReceiptsPlaceholder } },
settingsItems{ argSettingsItems },
@ -69,7 +78,7 @@ lcReceiptsHandler::lcReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit,
PrintReceipts();
}
lcReceiptsHandler::~lcReceiptsHandler() {
lc::ReceiptsHandler::~ReceiptsHandler() {
delete anonymousReceiptsPlaceholder;
delete dateString;
delete latexHeaderName;
@ -79,7 +88,7 @@ lcReceiptsHandler::~lcReceiptsHandler() {
delete zTreeDataTargetPath;
}
void lcReceiptsHandler::PrintReceipts() {
void lc::ReceiptsHandler::PrintReceipts() {
// If the payment file exists, print it
if ( paymentFile->exists() ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] The payment file has been created and will be printed" );
@ -91,7 +100,7 @@ void lcReceiptsHandler::PrintReceipts() {
}
}
void lcReceiptsHandler::CreateReceiptsFromPaymentFile() {
void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() {
// Get the data needed for receipts creation from the payment file
QVector<QString> *rawParticipantsData = nullptr;
rawParticipantsData = GetParticipantsDataFromPaymentFile();
@ -206,17 +215,19 @@ void lcReceiptsHandler::CreateReceiptsFromPaymentFile() {
delete latexText;
latexText = nullptr;
receiptsPrinter = new lcReceiptsPrinter{ dateString, zTreeDataTargetPath, settingsItems };
receiptsPrinter = new ReceiptsPrinter{ dateString, zTreeDataTargetPath, settingsItems };
receiptsPrinter->start();
connect( receiptsPrinter, &lcReceiptsPrinter::PrintingFinished, this, &lcReceiptsHandler::DeleteReceiptsPrinterInstance );
connect( receiptsPrinter, &lcReceiptsPrinter::ErrorOccurred, this, &lcReceiptsHandler::DisplayMessageBox );
connect( receiptsPrinter, &ReceiptsPrinter::PrintingFinished,
this, &ReceiptsHandler::DeleteReceiptsPrinterInstance );
connect( receiptsPrinter, &ReceiptsPrinter::ErrorOccurred,
this, &ReceiptsHandler::DisplayMessageBox );
// Clean up
texFile->close();
delete texFile;
}
void lcReceiptsHandler::DeleteReceiptsPrinterInstance() {
void lc::ReceiptsHandler::DeleteReceiptsPrinterInstance() {
receiptsPrinter->quit();
receiptsPrinter->wait();
delete receiptsPrinter;
@ -226,14 +237,14 @@ void lcReceiptsHandler::DeleteReceiptsPrinterInstance() {
emit PrintingFinished();
}
void lcReceiptsHandler::DisplayMessageBox( QString *argErrorMessage, QString *argHeading ) {
void lc::ReceiptsHandler::DisplayMessageBox( QString *argErrorMessage, QString *argHeading ) {
QMessageBox messageBox( QMessageBox::Warning, *argHeading, *argErrorMessage, QMessageBox::Ok );
delete argHeading;
delete argErrorMessage;
messageBox.exec();
}
QVector<QString> *lcReceiptsHandler::GetParticipantsDataFromPaymentFile() {
QVector<QString> *lc::ReceiptsHandler::GetParticipantsDataFromPaymentFile() {
// Create the vector to store the single lines of the file
QVector<QString> *participantsData = new QVector<QString>;
@ -260,7 +271,7 @@ QVector<QString> *lcReceiptsHandler::GetParticipantsDataFromPaymentFile() {
return participantsData;
}
QString *lcReceiptsHandler::LoadLatexHeader() {
QString *lc::ReceiptsHandler::LoadLatexHeader() {
// Prepare all facilities to read the latex header file
QFile latexHeaderFile( *( *settingsItems )[ ( int )settingsItems_t::LABCONTROL_INSTALLATION_DIRECTORY ] + "/" + *latexHeaderName + "_header.tex" );
if ( !latexHeaderFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
@ -279,7 +290,7 @@ QString *lcReceiptsHandler::LoadLatexHeader() {
return header;
}
void lcReceiptsHandler::MakeReceiptsAnonymous( QVector<paymentEntry_t*> *argDataVector, bool argAlsoAnonymizeClients ) {
void lc::ReceiptsHandler::MakeReceiptsAnonymous( QVector<paymentEntry_t*> *argDataVector, bool argAlsoAnonymizeClients ) {
if ( !argAlsoAnonymizeClients ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] Names are made anonymous" );
for ( QVector< paymentEntry_t* >::iterator it = argDataVector->begin(); it != argDataVector->end(); ++it ) {

@ -30,6 +30,8 @@
#include "receiptsprinter.h"
namespace lc {
//! A struct representing one payoff entry.
/*!
This class represents a single payoff entry which will be used in the receipts creation process. Multiple instances of this will be used to represent the individual participants' outcomes.
@ -40,18 +42,18 @@ struct paymentEntry_t {QString computer; QString name; double payoff;};
/*!
This class is element of every session and is used to handle the receipts printing.
*/
class lcReceiptsHandler : public QObject
{
class ReceiptsHandler : public QObject {
Q_OBJECT
public:
explicit lcReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
explicit ReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
const bool &argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder,
const QString &argLatexHeaderName, const QVector<QString*> * const argSettingsItems, QObject *argParent = nullptr );
explicit lcReceiptsHandler( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath,
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 );
~lcReceiptsHandler();
~ReceiptsHandler();
signals:
void PrintingFinished();
@ -82,9 +84,11 @@ private:
const QString * const 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
const bool * const printReceiptsForLocalClients; //! Stores if receipts shall be printed for local clients
lcReceiptsPrinter *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
const QString * const zTreeDataTargetPath; //! A reference to the data target path stored in the session class instance
};
}
#endif // RECEIPTS_HANDLER_H

@ -19,7 +19,10 @@
#include "receiptsprinter.h"
lcReceiptsPrinter::lcReceiptsPrinter( const QString * const argDateString, const QString * const argWorkpath, const QVector< QString* > * const argSettingsItems, QObject *argParent ) :
lc::ReceiptsPrinter::ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
const QVector< QString* > * const argSettingsItems,
QObject *argParent ) :
QThread{ argParent },
dateString{ argDateString },
settingsItems{ argSettingsItems },

@ -26,12 +26,15 @@
#include "global.h"
namespace lc {
//! A class for receipts creation.
/*!
This class is used to do the actual printing of the receipts in an own thread.
*/
class lcReceiptsPrinter : public QThread {
class ReceiptsPrinter : public QThread {
Q_OBJECT
void run() Q_DECL_OVERRIDE {
// Compile the TeX file to dvi
QStringList arguments;
@ -118,8 +121,10 @@ class lcReceiptsPrinter : public QThread {
// Clean up the zTree working path
if ( ( *settingsItems )[ ( int )settingsItems_t::RM_COMMAND ] ) {
arguments = QStringList{};
arguments << QString{ *workpath + "/" + *dateString + ".aux" } << QString{ *workpath + "/" + *dateString + ".dvi" }
<< QString{ *workpath + "/" + *dateString + ".log" } << QString{ *workpath + "/" + *dateString + ".tex" };
arguments << QString{ *workpath + "/" + *dateString + ".aux" }
<< QString{ *workpath + "/" + *dateString + ".dvi" }
<< QString{ *workpath + "/" + *dateString + ".log" }
<< QString{ *workpath + "/" + *dateString + ".tex" };
process = new QProcess{};
process->setProcessEnvironment( env );
@ -135,7 +140,10 @@ class lcReceiptsPrinter : public QThread {
emit PrintingFinished();
}
public:
explicit lcReceiptsPrinter( const QString * const argDateString, const QString * const argWorkpath, const QVector< QString* > * const argSettingsItems, QObject *argParent = nullptr );
explicit ReceiptsPrinter( const QString * const argDateString,
const QString * const argWorkpath,
const QVector< QString* > * const argSettingsItems,
QObject *argParent = nullptr );
signals:
void ErrorOccurred(QString *error_message, QString *heading);
@ -148,4 +156,6 @@ private:
const QString * const workpath; //! The path were zTree was ordered to store all its data
};
}
#endif // RECEIPTSPRINTER_H

@ -19,9 +19,12 @@
#include "session.h"
lcSession::lcSession( 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 ):
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 ):
zTreePort{ argZTreePort },
anonymousReceiptsPlaceholder{ argAnonymousReceiptsPlaceholder },
debugMessagesTextEdit{ argDebugMessagesTextEdit },
@ -47,12 +50,12 @@ lcSession::lcSession( QPlainTextEdit * const argDebugMessagesTextEdit, const QSt
}
}
lcSession::~lcSession() {
lc::Session::~Session() {
delete receiptsHandler;
delete zTreeInstance;
}
QVariant lcSession::GetDataItem( int argIndex ) {
QVariant lc::Session::GetDataItem( int argIndex ) {
switch ( argIndex ) {
case 0:
return QVariant{ zTreeVersionPath.split( '_', QString::KeepEmptyParts, Qt::CaseInsensitive )[ 1 ] };
@ -63,7 +66,7 @@ QVariant lcSession::GetDataItem( int argIndex ) {
}
}
void lcSession::InitializeClasses() {
void lc::Session::InitializeClasses() {
// Create the new data directory
QDir dir{ zTreeDataTargetPath };
QString date_string( QDateTime::currentDateTime().toString( "yyMMdd_hhmm" ) );
@ -73,16 +76,20 @@ void lcSession::InitializeClasses() {
zTreeDataTargetPath.append( "/" + date_string + "-" + QString::number( zTreePort ) );
debugMessagesTextEdit->appendPlainText( "[DEBUG] New session's chosen_zTree_data_target_path: " + zTreeDataTargetPath );
zTreeInstance = new lcZTree{ debugMessagesTextEdit, zTreeDataTargetPath, zTreePort, zTreeVersionPath, settingsItems };
zTreeInstance = new ZTree{ debugMessagesTextEdit, zTreeDataTargetPath,
zTreePort, zTreeVersionPath, settingsItems };
// Only create a 'Receipts_Handler' instance, if all neccessary variables were set
if ( latexHeaderName != "None found" && ( *settingsItems )[ ( int )settingsItems_t::DVIPS_COMMAND ] && ( *settingsItems )[ ( int )settingsItems_t::LATEX_COMMAND ] ) {
receiptsHandler = new lcReceiptsHandler{ debugMessagesTextEdit, zTreeDataTargetPath, printReceiptsForLocalClients, anonymousReceiptsPlaceholder, latexHeaderName, settingsItems };
receiptsHandler = new ReceiptsHandler{ debugMessagesTextEdit, zTreeDataTargetPath,
printReceiptsForLocalClients,
anonymousReceiptsPlaceholder,
latexHeaderName, settingsItems };
} else {
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No ReceiptsHandler instance was created." ) );
}
}
void lcSession::RenameWindow() {
void lc::Session::RenameWindow() {
// Example: wmctrl -r <window name> -T <new name>
QStringList arguments;

@ -26,20 +26,22 @@
#include "receipts_handler.h"
#include "ztree.h"
namespace lc {
//! A class containing an entire session.
/*!
This class represents an entire session with its zTree instance and the corresponding lcReceiptsHandler instance.
*/
class lcSession : public QObject
{
class Session : public QObject {
Q_OBJECT
public:
const int zTreePort = 7000; //! The port this session's zTree instance is running on
lcSession( QPlainTextEdit * const argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath, const int argZTreePort,
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 );
~lcSession();
~Session();
/*! Returns the data item with the given index
*
@ -66,11 +68,13 @@ private:
QPlainTextEdit * const debugMessagesTextEdit = nullptr; //! A pointer to the programs debugMessagesTextEdit to be able to emit debugging messages
const QString latexHeaderName; //! The name of the chosen LaTeX header
const bool printReceiptsForLocalClients = true; //! True if receipts shall be printed for local clients
lcReceiptsHandler *receiptsHandler = nullptr; //! For automatic creation and printing of the receipts
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
lcZTree *zTreeInstance= nullptr; //! The session's zTree instance
ZTree *zTreeInstance= nullptr; //! The session's zTree instance
const QString zTreeVersionPath; //! The path to the version of zTree used by this session's instance
};
}
#endif // SESSION_H

@ -19,28 +19,28 @@
#include "sessionsmodel.h"
SessionsModel::SessionsModel(QObject *parent) :
QAbstractTableModel{parent},
sessions_vector{ new QVector< lcSession* > }
lc::SessionsModel::SessionsModel( QObject *argParent ) :
QAbstractTableModel{ argParent },
sessions_vector{ new QVector< Session* > }
{
}
SessionsModel::~SessionsModel() {
lc::SessionsModel::~SessionsModel() {
for (auto s: *sessions_vector)
delete s;
delete sessions_vector;
}
lcSession *SessionsModel::back() const {
lc::Session *lc::SessionsModel::back() const {
return sessions_vector->back();
}
int SessionsModel::columnCount(const QModelIndex &parent) const {
int lc::SessionsModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return 2;
}
QVariant SessionsModel::data(const QModelIndex &index, int role) const {
QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant{};
@ -53,7 +53,7 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const {
return QVariant{};
}
QVariant SessionsModel::headerData(int section, Qt::Orientation orientation, int role) const {
QVariant lc::SessionsModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch(section) {
case 0:
@ -71,11 +71,11 @@ QVariant SessionsModel::headerData(int section, Qt::Orientation orientation, int
return QVariant{};
}
void SessionsModel::push_back( lcSession *argSession ) {
void lc::SessionsModel::push_back( Session *argSession ) {
sessions_vector->push_back( argSession );
}
int SessionsModel::rowCount(const QModelIndex &parent) const {
int lc::SessionsModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return sessions_vector->length();
}

@ -24,18 +24,19 @@
#include "session.h"
class SessionsModel : public QAbstractTableModel
{
namespace lc {
class SessionsModel : public QAbstractTableModel {
Q_OBJECT
public:
explicit SessionsModel(QObject *parent = 0);
~SessionsModel();
SessionsModel(const SessionsModel&) = delete;
lcSession *back() const;
Session *back() const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
void push_back( lcSession *argSession );
void push_back( Session *argSession );
int rowCount(const QModelIndex &parent) const;
@ -44,7 +45,9 @@ signals:
public slots:
private:
QVector<lcSession*> *sessions_vector;
QVector< Session* > *sessions_vector = nullptr;
};
}
#endif // SESSIONSMODEL_H

@ -19,7 +19,10 @@
#include "ztree.h"
lcZTree::lcZTree( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath, const int &argZTreePort, const QString &argZTreeVersionPath, const QVector<QString*> * const argSettingsItems ) {
lc::ZTree::ZTree( QPlainTextEdit *argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath, const int &argZTreePort,
const QString &argZTreeVersionPath,
const QVector<QString*> * const argSettingsItems ) {
QString program{ *( *argSettingsItems )[ ( int )settingsItems_t::LABCONTROL_INSTALLATION_DIRECTORY ] + "/scripts/start_zTree_labcontrol2.sh" };
QStringList arguments;
arguments << *( *argSettingsItems )[ ( int )settingsItems_t::ZTREE_INSTALLATION_DIRECTORY ] << argZTreeVersionPath << argZTreeDataTargetPath << QString::number( static_cast<int>( argZTreePort ) - 7000 );
@ -33,6 +36,6 @@ lcZTree::lcZTree( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZT
argDebugMessagesTextEdit->appendPlainText( "[DEBUG] " + program + " " + arguments.join( " " ) );
}
void lcZTree::ZTreeInstanceClosed() {
void lc::ZTree::ZTreeInstanceClosed() {
emit ZTreeClosed();
}

@ -26,14 +26,20 @@
#include "global.h"
namespace lc {
//! A class to contain running zTree instances.
/*!
This class is element of every session and is used to handle all zTree related data.
*/
class lcZTree: public QObject {
class ZTree: public QObject {
Q_OBJECT
public:
lcZTree( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath, const int &argZTreePort, const QString &argZTreeVersionPath, const QVector<QString*> * const argSettingsItems );
ZTree( QPlainTextEdit *argDebugMessagesTextEdit,
const QString &argZTreeDataTargetPath,
const int &argZTreePort, const QString &argZTreeVersionPath,
const QVector<QString*> * const argSettingsItems );
signals:
void ZTreeClosed();
@ -46,4 +52,6 @@ private:
QProcess zTreeInstance;
};
}
#endif // ZTREE_H

@ -28,7 +28,7 @@ lc::MainWindow::MainWindow( QWidget *argParent ) :
ui{ new Ui::MainWindow }
{
ui->setupUi( this );
lablib = new lcLablib{ ui->PTEDebugMessages, this };
lablib = new Lablib{ ui->PTEDebugMessages, this };
LoadIconPixmaps();
@ -234,7 +234,7 @@ void lc::MainWindow::on_PBBeamFile_clicked() {
const QString fileToBeam{ ui->LEFilePath->text() };
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->BeamFile( fileToBeam, publickeyPathUser, userNameOnClients );
}
}
@ -244,7 +244,7 @@ void lc::MainWindow::on_PBBoot_clicked() {
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Boot( lablib->GetSettingsItem( settingsItems_t::NETWORK_BROADCAST_ADDRESS ) );
}
}
@ -270,7 +270,7 @@ void lc::MainWindow::on_PBChooseFile_clicked() {
void lc::MainWindow::on_PBDeactivateScreensaver_clicked() {
const QString * const publickey_path_user = lablib->GetSettingsItem( settingsItems_t::PUBLICKEY_PATH_USER ), * const user_name_on_clients = lablib->GetSettingsItem( settingsItems_t::USER_NAME_ON_CLIENTS );
QVector< lcClient* > *clients = lablib->GetClients();
QVector< Client* > *clients = lablib->GetClients();
for ( auto s : *clients ) {
if ( s->GetClientState() >= state_t::RESPONDING )
s->DeactiveScreensaver( publickey_path_user, user_name_on_clients );
@ -282,7 +282,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
bool executeOnEveryClient = true;
// Cancel, if not all clients are up and running
QVector< lcClient* > *clients = lablib->GetClients();
QVector< Client* > *clients = lablib->GetClients();
for ( auto s: *clients ) {
if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) {
if ( s->GetClientState() < state_t::RESPONDING ) {
@ -326,7 +326,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), publickeyPathUser, lablib->GetSettingsItem( settingsItems_t::USER_NAME_ON_CLIENTS ) );
}
}
@ -355,7 +355,7 @@ void lc::MainWindow::on_PBKillzLeaf_clicked() {
const QString * const publickeyPathUser = lablib->GetSettingsItem( settingsItems_t::PUBLICKEY_PATH_USER ), * const userNameOnClients = lablib->GetSettingsItem( settingsItems_t::USER_NAME_ON_CLIENTS );
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->KillZLeaf( publickeyPathUser, userNameOnClients );
}
}
@ -373,7 +373,7 @@ void lc::MainWindow::on_PBOpenFilesystem_clicked() {
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenFilesystem( userToBeUsed );
}
}
@ -392,7 +392,7 @@ void lc::MainWindow::on_PBOpenTerminal_clicked() {
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked(), publickeyPathUser, userNameOnClients );
}
}
@ -443,7 +443,7 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() {
* const userNameOnClients = lablib->GetSettingsItem( settingsItems_t::USER_NAME_ON_CLIENTS );
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( publickeyPathUser, userNameOnClients, zLeafVersion, serverIP, ui->SBzLeafPort->value(), fakeName );
}
}
@ -474,7 +474,7 @@ void lc::MainWindow::on_PBShutdown_clicked() {
* const userNameOnClients = lablib->GetSettingsItem( settingsItems_t::USER_NAME_ON_CLIENTS );
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Shutdown( publickeyPathUser, userNameOnClients );
}
}
@ -535,7 +535,7 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() {
* const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( publickeyPathUser, userNameOnClients, zLeafVersion, serverIP, ui->SBzLeafPort->value(), nullptr );
}
}
@ -593,7 +593,7 @@ void lc::MainWindow::on_PBViewDesktop_clicked() {
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
lcClient *client = static_cast< lcClient * >( ( *it ).data( Qt::UserRole ).value< void * >() );
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->ShowDesktop();
}
}
@ -607,7 +607,7 @@ void lc::MainWindow::on_RBUseLocalUser_toggled(bool checked) {
void lc::MainWindow::SetupWidgets() {
// Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients
const QVector< lcClient* > *clients = lablib->GetClients();
const QVector< Client* > *clients = lablib->GetClients();
if ( !( clients == nullptr ) ) {
valid_items = new QVector< QStandardItem * >;
valid_items->reserve( clients->size() );
@ -737,7 +737,7 @@ void lc::MainWindow::SetupWidgets() {
void lc::MainWindow::UpdateClientsTableView() {
for ( auto s : *valid_items ) {
state_t state = static_cast< lcClient * >( s->data( Qt::UserRole ).value<void *>() )->GetClientState();
state_t state = static_cast< Client* >( s->data( Qt::UserRole ).value<void *>() )->GetClientState();
switch ( state ) {
case state_t::RESPONDING:
s->setBackground( QBrush( QColor( 128, 255, 128, 255 ) ) );

@ -53,7 +53,7 @@ class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow( QWidget *argParent = 0 );
explicit MainWindow( QWidget *argParent = nullptr );
~MainWindow();
private slots:
@ -103,7 +103,7 @@ private:
QStandardItemModel *clients_view_model = nullptr; //! The view storing all clients data
QTimer *gui_update_timer = nullptr; //! A QTimer triggering updates of the graphical user interface
QPixmap *icons = nullptr; //! Array of pixmaps storing the icons indicating the clients' statuses
lcLablib *lablib = nullptr; //! Accumulator of all program logic being accessed by the GUI
Lablib *lablib = nullptr; //! Accumulator of all program logic being accessed by the GUI
bool local_zLeaves_are_running = false; //! Stores if a local zLeaf instance is running on the server ('true' if local zLeaf exists)
QButtonGroup *userChooseButtonGroup = nullptr; //! Used to group the radio buttons choosing which user shall be used for administrative client actions
Ui::MainWindow *ui = nullptr; //! Pointer storing all GUI items

@ -20,7 +20,7 @@
#include "sessionstarter.h"
#include "ui_sessionstarter.h"
lc::SessionStarter::SessionStarter( lcLablib *argLablib, QPlainTextEdit *argDebugMessagesTextEdit, QWidget *parent ) :
lc::SessionStarter::SessionStarter( Lablib *argLablib, QPlainTextEdit *argDebugMessagesTextEdit, QWidget *parent ) :
QWidget{ parent },
debugMessagesTextEdit { argDebugMessagesTextEdit },
lablib{ argLablib },

@ -35,7 +35,8 @@ class SessionStarter : public QWidget {
Q_OBJECT
public:
explicit SessionStarter( lcLablib *argLablib, QPlainTextEdit *argDebugMessagesTextEdit, QWidget *parent = nullptr );
explicit SessionStarter( Lablib *argLablib, QPlainTextEdit *argDebugMessagesTextEdit,
QWidget *parent = nullptr );
~SessionStarter();
//! This gets thrown as an exception if this class is created even if it shouldn't
@ -44,7 +45,7 @@ public:
private:
QPlainTextEdit * const debugMessagesTextEdit = nullptr;
lcLablib * const lablib = nullptr;
Lablib * const lablib = nullptr;
Ui::SessionStarter *ui = nullptr;
void SetupWidgets();

Loading…
Cancel
Save