Merged client creation and more settings in 'lc::Settings'

remotes/origin/HEAD
markuspg 10 years ago
parent 97a4ea3472
commit e1561ece2c

@ -27,7 +27,8 @@
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr< lc::Settings > settings;
lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &argName, lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition ): unsigned short int argXPosition, unsigned short int argYPosition,
const QString &argPingCmd ):
ip{ argIP }, ip{ argIP },
mac{ argMAC }, mac{ argMAC },
name{ argName }, name{ argName },
@ -37,8 +38,8 @@ lc::Client::Client( const QString &argIP, const QString &argMAC, const QString &
{ {
qRegisterMetaType< state_t >( "STATE" ); qRegisterMetaType< state_t >( "STATE" );
if ( !settings->pingCmd.isEmpty() ) { if ( !argPingCmd.isEmpty() ) {
pinger = new ClientPinger{ ip, settings->pingCmd }; pinger = new ClientPinger{ ip, argPingCmd };
pinger->moveToThread( &pingerThread ); pinger->moveToThread( &pingerThread );
connect( &pingerThread, &QThread::finished, connect( &pingerThread, &QThread::finished,
pinger, &QObject::deleteLater ); pinger, &QObject::deleteLater );

@ -60,7 +60,8 @@ public:
* \param argYPosition The client's y coordinate in the lab's grid * \param argYPosition The client's y coordinate in the lab's grid
*/ */
Client( const QString &argIP, const QString &argMAC, const QString &argName, Client( const QString &argIP, const QString &argMAC, const QString &argName,
unsigned short int argXPosition, unsigned short int argYPosition ); unsigned short int argXPosition, unsigned short int argYPosition,
const QString &argPingCmd );
//! Client's destructor //! Client's destructor
~Client(); ~Client();
//! Beams the chosen file to the client's 'media4ztree' directory //! Beams the chosen file to the client's 'media4ztree' directory

@ -24,10 +24,8 @@
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr< lc::Settings > settings;
lc::ClientHelpNotificationServer::ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap, lc::ClientHelpNotificationServer::ClientHelpNotificationServer( QObject *argParent ) :
QObject *argParent ) :
QObject{ argParent }, QObject{ argParent },
clientIPsToClientsMap{ argClientIPsToClientsMap },
hostAddress{ settings->serverIP } hostAddress{ settings->serverIP }
{ {
QNetworkConfigurationManager manager; QNetworkConfigurationManager manager;
@ -94,8 +92,8 @@ void lc::ClientHelpNotificationServer::SendReply() {
QString peerAddress = clientConnection->peerAddress().toString(); QString peerAddress = clientConnection->peerAddress().toString();
QString peerName; QString peerName;
bool unknownClient = false; bool unknownClient = false;
if ( clientIPsToClientsMap->contains( peerAddress ) ) { if ( settings->clIPsToClMap.contains( peerAddress ) ) {
peerName = ( *clientIPsToClientsMap )[ peerAddress ]->name; peerName = settings->clIPsToClMap[ peerAddress ]->name;
} else { } else {
unknownClient = true; unknownClient = true;
} }

@ -32,15 +32,13 @@ namespace lc {
class ClientHelpNotificationServer : public QObject { class ClientHelpNotificationServer : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap, explicit ClientHelpNotificationServer( QObject *argParent = nullptr );
QObject *argParent = nullptr );
signals: signals:
public slots: public slots:
private: private:
const QMap< QString, Client* > * const clientIPsToClientsMap = nullptr;
QTcpServer *helpMessageServer = nullptr; QTcpServer *helpMessageServer = nullptr;
const QHostAddress hostAddress; const QHostAddress hostAddress;
QNetworkSession *networkSession = nullptr; QNetworkSession *networkSession = nullptr;

@ -26,13 +26,14 @@
lc::Lablib::Lablib( QObject *argParent ) : lc::Lablib::Lablib( QObject *argParent ) :
QObject{ argParent }, QObject{ argParent },
clientIPsToClientsMap{ new QMap< QString, Client* > },
labSettings{ "Economic Laboratory", "Labcontrol", this }, labSettings{ "Economic Laboratory", "Labcontrol", this },
occupiedPorts{ new QVector< int > }, occupiedPorts{ new QVector< int > },
sessionsModel{ new SessionsModel{ this } } sessionsModel{ new SessionsModel{ this } }
{ {
ReadSettings(); for ( const auto &s : settings->GetClients() ) {
connect( this, &Lablib::ZLEAF_RUNNING,
s, &Client::SetStateToZLEAF_RUNNING );
}
DetectInstalledZTreeVersionsAndLaTeXHeaders(); DetectInstalledZTreeVersionsAndLaTeXHeaders();
// Initialize all 'netstat' query mechanisms // Initialize all 'netstat' query mechanisms
@ -51,8 +52,7 @@ lc::Lablib::Lablib( QObject *argParent ) :
// 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 && !settings->serverIP.isEmpty() ) {
clientHelpNotificationServer = new ClientHelpNotificationServer{ clientIPsToClientsMap, clientHelpNotificationServer = new ClientHelpNotificationServer{ this };
this };
} }
} }
@ -63,12 +63,6 @@ lc::Lablib::~Lablib () {
} }
netstatThread.quit(); netstatThread.quit();
netstatThread.wait(); netstatThread.wait();
if ( clients ) {
for ( QVector< Client* >::iterator it = clients->begin(); it != clients->end(); ++it ) {
delete *it;
}
}
delete clients;
delete occupiedPorts; delete occupiedPorts;
} }
@ -97,90 +91,6 @@ void lc::Lablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections )
delete argActiveZLeafConnections; delete argActiveZLeafConnections;
} }
void lc::Lablib::ReadSettings() {
// Get the client quantity to check the value lists for clients creation for correct length
int clientQuantity = 0;
if ( !labSettings.contains("client_quantity" ) ) {
QMessageBox messageBox{ QMessageBox::Information, tr( "'client_quantity' not set" ),
tr( "The 'client_quantity' variable was not set. The client quantity will be guessed by the amount of client ips set in 'client_ips'." ) };
messageBox.exec();
qDebug() << "'client_quantity' was not set. The client quantity will be guessed"
" by the amount of client IPs set in 'client_ips'.";
clientQuantity = labSettings.value( "client_ips", "" ).toString().split( '/', QString::SkipEmptyParts, Qt::CaseSensitive ).length();
qDebug() << "'clientQuantity':" << clientQuantity;
} else {
clientQuantity = labSettings.value( "client_quantity" ).toInt();
qDebug() << "'clientQuantity':" << clientQuantity;
}
// Create all the clients in the lab
QStringList clientIPs = labSettings.value( "client_ips" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientIPs.length() != clientQuantity ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Wrong client ip quantity" ),
tr( "The quantity of client ips does not match the client quantity. Client creation will fail. No clients will be available for interaction." ), QMessageBox::Ok };
messageBox.exec();
return;
}
qDebug() << "Client IPs:" << clientIPs.join( " / " );
QStringList clientMACs = labSettings.value( "client_macs" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientMACs.length() != clientQuantity ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Wrong client mac quantity" ),
tr( "The quantity of client macs does not match the client quantity. Client creation will fail. No clients will be available for interaction." ), QMessageBox::Ok };
messageBox.exec();
return;
}
qDebug() << "Client MACs:" << clientMACs.join( " / " );
QStringList clientNames = labSettings.value( "client_names" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientNames.length() != clientQuantity ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Wrong client name quantity" ),
tr( "The quantity of client names does not match the client quantity. Client creation will fail. No clients will be available for interaction." ), QMessageBox::Ok };
messageBox.exec();
return;
}
qDebug() << "Client names:" << clientNames.join( " / " );
QStringList clientXPositions = labSettings.value( "client_xpos" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientXPositions.length() != clientQuantity ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Wrong client x positions quantity" ),
tr( "The quantity of client x positions does not match the client quantity. Client creation will fail. No clients will be available for interaction." ), QMessageBox::Ok };
messageBox.exec();
return;
}
qDebug() << "clientXPositions:" << clientXPositions.join( " / " );
QStringList clientYPositions = labSettings.value( "client_ypos" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientYPositions.length() != clientQuantity ) {
QMessageBox messageBox{ QMessageBox::Critical, tr( "Wrong client y positions quantity" ),
tr( "The quantity of client y positions does not match the client quantity. Client creation will fail. No clients will be available for interaction." ), QMessageBox::Ok };
messageBox.exec();
return;
}
qDebug() << "clientYPositions:" << clientYPositions.join( " / " );
clients = new QVector< Client* >;
for ( int i = 0; i < clientQuantity; i++ ) {
clients->append( new Client{ clientIPs[ i ], clientMACs[ i ], clientNames[ i ],
clientXPositions[ i ].toUShort(),
clientYPositions[ i ].toUShort() } );
// Add an corresponding entry to the 'client_ips_to_clients_map' std::map<QString, Client*>
( *clientIPsToClientsMap )[ clients->last()->ip ] = clients->last();
// Get the address of the Client instance in RAM for display
const void *clientPointerAddress = static_cast< const void* >( ( *clientIPsToClientsMap )[ clients->last()->ip ] );
// Connect the 'Client' instance to the 'ZLEAF_RUNNING(QString client_ip)' signal
connect( this, &Lablib::ZLEAF_RUNNING,
clients->last(), &Client::SetStateToZLEAF_RUNNING );
qDebug() << "Added" << clients->last()->name
<< "to 'clientIPsToClientsMap':" << clientPointerAddress;
}
}
void lc::Lablib::SetPrintReceiptsForLocalClients( const bool &argPrintReceiptsForLocalClients ) {
PrintReceiptsForLocalClients = argPrintReceiptsForLocalClients;
qDebug() << "Set 'PrintReceiptsForLocalClients' to:" << PrintReceiptsForLocalClients;
}
void lc::Lablib::ShowOrsee() { void lc::Lablib::ShowOrsee() {
QProcess showOrseeProcess; QProcess showOrseeProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();

@ -71,16 +71,6 @@ public:
* \return True, if the account has administrative rights; false, otherwise * \return True, if the account has administrative rights; false, otherwise
*/ */
bool CheckIfUserIsAdmin() const; bool CheckIfUserIsAdmin() const;
/** Returns a pointer to the clients known to Lablib
*
* @return A QVector of pointers to the Client class instances
*/
QVector< Client* > *GetClients () const { return clients; }
/** Returns a pointer to the QString storing the default name for local zLeafs
*
* @return A pointer to the QString storing the default name for local zLeafs
*/
QString GetLocalZLeafDefaultName() const { return settings->GetLocalzLeafName(); }
/** Returns a pointer to a QVector<unsigned int> containing all by sessions occupied ports /** Returns a pointer to a QVector<unsigned int> containing all by sessions occupied ports
* *
* @return A pointer to a QVector<unsigned int> containing all occupied ports * @return A pointer to a QVector<unsigned int> containing all occupied ports
@ -91,17 +81,11 @@ public:
* @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; }
/** Returns true if receipts for local clients shall be printed
*
* @return True if receipts for local clients shall be printed
*/
bool GetPrintReceiptsForLocalClients() const { return PrintReceiptsForLocalClients; }
//! 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 SetPrintReceiptsForLocalClients( const bool &argPrintReceiptsForLocalClients );
void ShowOrsee(); void ShowOrsee();
void ShowPreprints(); void ShowPreprints();
@ -125,14 +109,11 @@ private:
void ReadSettings(); void ReadSettings();
ClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients ClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients
QMap< QString, Client* > * clientIPsToClientsMap = nullptr; //! A map container storing ip-client pairs
QVector<Client*> *clients = nullptr; //! A QVector storing pointers to all Client instances
QSettings labSettings; QSettings labSettings;
NetstatAgent *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; QThread netstatThread;
QTimer *netstatTimer = nullptr; //! A timer for regular execution of the NetstatAgent instance's request mechanism QTimer *netstatTimer = nullptr; //! A timer for regular execution of the NetstatAgent instance's request mechanism
QVector< int > *occupiedPorts = nullptr; QVector< int > *occupiedPorts = nullptr;
bool PrintReceiptsForLocalClients = true;
SessionsModel *sessionsModel = nullptr; //! A derivation from QAbstractTableModel used to store the single Session instances SessionsModel *sessionsModel = nullptr; //! A derivation from QAbstractTableModel used to store the single Session instances
}; };

@ -22,6 +22,7 @@
#include <QFile> #include <QFile>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include "client.h"
#include "settings.h" #include "settings.h"
lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
@ -122,9 +123,11 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
installedZTreeVersions{ DetectInstalledzTreeVersions() }, installedZTreeVersions{ DetectInstalledzTreeVersions() },
clientHelpNotificationServerPort{ GetClientHelpNotificationServerPort( argSettings ) }, clientHelpNotificationServerPort{ GetClientHelpNotificationServerPort( argSettings ) },
chosenzTreePort{ GetInitialPort( argSettings ) }, chosenzTreePort{ GetInitialPort( argSettings ) },
clients{ CreateClients( argSettings, pingCmd ) },
localzLeafName{ ReadSettingsItem( "local_zLeaf_name", localzLeafName{ ReadSettingsItem( "local_zLeaf_name",
"The local zLeaf default name will default to 'local'.", "The local zLeaf default name will default to 'local'.",
argSettings, false ) } argSettings, false ) },
clIPsToClMap{ CreateClIPsToClMap( clients ) }
{ {
// Let the local zLeaf name default to 'local' if none was given in the settings // Let the local zLeaf name default to 'local' if none was given in the settings
if ( localzLeafName.isEmpty() ) { if ( localzLeafName.isEmpty() ) {
@ -139,6 +142,12 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
qDebug() << "Detected z-Tree versions" << installedZTreeVersions; qDebug() << "Detected z-Tree versions" << installedZTreeVersions;
} }
lc::Settings::~Settings() {
for ( QVector< Client* >::iterator it = clients.begin(); it != clients.end(); ++it ) {
delete *it;
}
}
bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &argVariableName, bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &argVariableName,
const QString &argMessage ) { const QString &argMessage ) {
if ( !QFile::exists( argPath ) ) { if ( !QFile::exists( argPath ) ) {
@ -150,6 +159,96 @@ bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &
return true; return true;
} }
QVector< lc::Client* > lc::Settings::CreateClients( const QSettings &argSettings,
const QString &argPingCmd ) {
QVector< Client* > tempClientVec;
// Get the client quantity to check the value lists for clients creation for correct length
int clientQuantity = 0;
if ( !argSettings.contains("client_quantity" ) ) {
qWarning() << "'client_quantity' was not set. The client quantity will be guessed"
" by the amount of client IPs set in 'client_ips'.";
clientQuantity = argSettings.value( "client_ips", "" ).toString()
.split( '/', QString::SkipEmptyParts, Qt::CaseSensitive ).length();
qDebug() << "'clientQuantity':" << clientQuantity;
} else {
bool ok = true;
clientQuantity = argSettings.value( "client_quantity" ).toInt( &ok );
if ( !ok ) {
qWarning() << "The variable 'client_quantity' was not convertible to int";
}
qDebug() << "'clientQuantity':" << clientQuantity;
}
// Create all the clients in the lab
QStringList clientIPs = argSettings.value( "client_ips" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientIPs.length() != clientQuantity ) {
qWarning() << "The quantity of client ips does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction.";
return tempClientVec;
}
qDebug() << "Client IPs:" << clientIPs.join( " / " );
QStringList clientMACs = argSettings.value( "client_macs" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientMACs.length() != clientQuantity ) {
qWarning() << "The quantity of client macs does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction.";
return tempClientVec;
}
qDebug() << "Client MACs:" << clientMACs.join( " / " );
QStringList clientNames = argSettings.value( "client_names" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientNames.length() != clientQuantity ) {
qWarning() << "The quantity of client names does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction.";
return tempClientVec;
}
qDebug() << "Client names:" << clientNames.join( " / " );
QStringList clientXPositions = argSettings.value( "client_xpos" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientXPositions.length() != clientQuantity ) {
qWarning() << "The quantity of client x positions does not match the client quantity."
" Client creation will fail. No clients will be available for interaction.";
return tempClientVec;
}
qDebug() << "clientXPositions:" << clientXPositions.join( " / " );
QStringList clientYPositions = argSettings.value( "client_ypos" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive );
if ( clientYPositions.length() != clientQuantity ) {
qWarning() << "The quantity of client y positions does not match the client quantity."
" Client creation will fail. No clients will be available for interaction.";
return tempClientVec;
}
qDebug() << "clientYPositions:" << clientYPositions.join( " / " );
for ( int i = 0; i < clientQuantity; i++ ) {
tempClientVec.append( new Client{ clientIPs[ i ], clientMACs[ i ], clientNames[ i ],
clientXPositions[ i ].toUShort(),
clientYPositions[ i ].toUShort(), argPingCmd } );
}
return tempClientVec;
}
QMap< QString, lc::Client* > lc::Settings::CreateClIPsToClMap( const QVector< Client* > &argClients ) {
QMap< QString, Client* > tempMap;
for ( const auto &s : argClients ) {
tempMap.insert( s->ip, s );
// Get the address of the Client instance in RAM for display
const void *clientPtrAddr = static_cast< const void* >( tempMap[ s->ip ] );
qDebug() << "Added" << s->name
<< "to 'clientIPsToClientsMap':" << clientPtrAddr;
}
return tempMap;
}
QStringList lc::Settings::DetectInstalledLaTeXHeaders() const { QStringList lc::Settings::DetectInstalledLaTeXHeaders() const {
QStringList tempLaTeXHeaders{ "None found" }; QStringList tempLaTeXHeaders{ "None found" };
// Detect the installed LaTeX headers // Detect the installed LaTeX headers

@ -24,6 +24,8 @@
#include <QObject> #include <QObject>
#include <QSettings> #include <QSettings>
#include "client.h"
namespace lc { namespace lc {
class Settings : public QObject { class Settings : public QObject {
@ -36,8 +38,10 @@ public:
Settings& operator=( const Settings &argSettings ) = delete; Settings& operator=( const Settings &argSettings ) = delete;
Settings( Settings &&argSettings ) = delete; Settings( Settings &&argSettings ) = delete;
Settings& operator=( Settings &&argSettings ) = delete; Settings& operator=( Settings &&argSettings ) = delete;
~Settings();
int GetChosenZTreePort() const { return chosenzTreePort; } int GetChosenZTreePort() const { return chosenzTreePort; }
QVector< Client* > &GetClients() { return clients; }
QString GetLocalzLeafName() const; QString GetLocalzLeafName() const;
void SetChosenZTreePort( const int argPort ); void SetChosenZTreePort( const int argPort );
void SetLocalzLeafName( const QString &argLocalzLeafName ); void SetLocalzLeafName( const QString &argLocalzLeafName );
@ -82,6 +86,9 @@ public:
private: private:
static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName, static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName,
const QString &argMessage ); const QString &argMessage );
static QVector< Client* > CreateClients( const QSettings &argSettings,
const QString &argPingCmd );
static QMap< QString, Client* > CreateClIPsToClMap( const QVector< Client* > &argClients );
QStringList DetectInstalledLaTeXHeaders() const; QStringList DetectInstalledLaTeXHeaders() const;
QStringList DetectInstalledzTreeVersions() const; QStringList DetectInstalledzTreeVersions() const;
static QStringList GetAdminUsers( const QSettings &argSettings ); static QStringList GetAdminUsers( const QSettings &argSettings );
@ -95,7 +102,11 @@ private:
bool argItemIsFile ); bool argItemIsFile );
int chosenzTreePort = 0; int chosenzTreePort = 0;
QVector< Client* > clients;
QString localzLeafName; QString localzLeafName;
public:
const QMap< QString, Client* > clIPsToClMap;
}; };
} }

@ -297,8 +297,7 @@ void lc::MainWindow::on_PBChooseFile_clicked() {
} }
void lc::MainWindow::on_PBDeactivateScreensaver_clicked() { void lc::MainWindow::on_PBDeactivateScreensaver_clicked() {
QVector< Client* > *clients = lablib->GetClients(); for ( auto s : settings->GetClients() ) {
for ( auto s : *clients ) {
if ( s->GetClientState() >= state_t::RESPONDING ) if ( s->GetClientState() >= state_t::RESPONDING )
s->DeactiveScreensaver(); s->DeactiveScreensaver();
} }
@ -309,15 +308,13 @@ void lc::MainWindow::on_PBExecute_clicked() {
bool executeOnEveryClient = true; bool executeOnEveryClient = true;
// Cancel, if not all clients are up and running // Cancel, if not all clients are up and running
QVector< Client* > *clients = lablib->GetClients(); for ( auto s: settings->GetClients() ) {
for ( auto s: *clients ) {
if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) {
if ( s->GetClientState() < state_t::RESPONDING ) { if ( s->GetClientState() < state_t::RESPONDING ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "Not all clients are running" ), QMessageBox messageBox{ QMessageBox::Warning, tr( "Not all clients are running" ),
tr( "Not all clients are running. The command could not be executed on every client and should therefore be canceled to keep the clients consistent.\n\nAre you sure you want to continue only with the currently chosen clients?" ), QMessageBox::No | QMessageBox::Yes, this }; tr( "Not all clients are running. The command could not be executed on every client and should therefore be canceled to keep the clients consistent.\n\nAre you sure you want to continue only with the currently chosen clients?" ), QMessageBox::No | QMessageBox::Yes, this };
messageBox.setDefaultButton( QMessageBox::No ); messageBox.setDefaultButton( QMessageBox::No );
messageBox.exec(); messageBox.exec();
clients = nullptr;
executeOnEveryClient = false; executeOnEveryClient = false;
if ( messageBox.clickedButton() == messageBox.button( QMessageBox::No ) ) { if ( messageBox.clickedButton() == messageBox.button( QMessageBox::No ) ) {
return; return;
@ -342,7 +339,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
// and execute it // and execute it
if ( executeOnEveryClient ) { if ( executeOnEveryClient ) {
qDebug() << "Executing command" << command << "on every client."; qDebug() << "Executing command" << command << "on every client.";
for ( auto s: *clients ) { for ( auto s: settings->GetClients() ) {
if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) {
s->OpenTerminal( command, ui->RBUseUserRoot->isChecked() ); s->OpenTerminal( command, ui->RBUseUserRoot->isChecked() );
} }
@ -357,8 +354,6 @@ void lc::MainWindow::on_PBExecute_clicked() {
} }
} }
} }
clients = nullptr;
} }
void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { void lc::MainWindow::on_PBKillLocalzLeaf_clicked() {
@ -537,7 +532,7 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() {
} }
void lc::MainWindow::on_PBStartzTree_clicked() { void lc::MainWindow::on_PBStartzTree_clicked() {
SessionStarter *sessionStarter = new SessionStarter{ lablib, this }; SessionStarter *sessionStarter = new SessionStarter{ this };
sessionStarter->setWindowFlags( Qt::Window ); sessionStarter->setWindowFlags( Qt::Window );
sessionStarter->show(); sessionStarter->show();
connect( sessionStarter, &SessionStarter::SessionRequested, connect( sessionStarter, &SessionStarter::SessionRequested,
@ -605,12 +600,11 @@ void lc::MainWindow::SetupWidgets() {
// Set the correct initial port for the // Set the correct initial port for the
ui->SBzLeafPort->setValue( settings->GetChosenZTreePort() ); ui->SBzLeafPort->setValue( settings->GetChosenZTreePort() );
// Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients // Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients
const QVector< Client* > *clients = lablib->GetClients(); if ( !settings->GetClients().isEmpty() ) {
if ( !( clients == nullptr ) ) {
valid_items = new QVector< QStandardItem * >; valid_items = new QVector< QStandardItem * >;
valid_items->reserve( clients->size() ); valid_items->reserve( settings->GetClients().size() );
clients_view_model = new QStandardItemModel{ this }; clients_view_model = new QStandardItemModel{ this };
for ( auto *s : *clients ) { for ( auto *s : settings->GetClients() ) {
int temp_xpos = s->xPosition - 1, temp_ypos = s->yPosition - 1; int temp_xpos = s->xPosition - 1, temp_ypos = s->yPosition - 1;
// Check if a client already exists at the given position and skip, if so // Check if a client already exists at the given position and skip, if so
@ -654,7 +648,6 @@ void lc::MainWindow::SetupWidgets() {
for ( const auto &s : settings->webcams ) for ( const auto &s : settings->webcams )
ui->CBWebcamChooser->addItem( s ); ui->CBWebcamChooser->addItem( s );
} }
clients = nullptr;
const QStringList &zTreeEntries = settings->installedZTreeVersions; const QStringList &zTreeEntries = settings->installedZTreeVersions;
if ( zTreeEntries.isEmpty() ) { if ( zTreeEntries.isEmpty() ) {

@ -27,9 +27,8 @@
extern std::unique_ptr< lc::Settings > settings; extern std::unique_ptr< lc::Settings > settings;
lc::SessionStarter::SessionStarter( Lablib *argLablib, QWidget *parent ) : lc::SessionStarter::SessionStarter( QWidget *parent ) :
QWidget{ parent }, QWidget{ parent },
lablib{ argLablib },
ui{ new Ui::SessionStarter } ui{ new Ui::SessionStarter }
{ {
ui->setupUi( this ); ui->setupUi( this );
@ -89,9 +88,9 @@ void lc::SessionStarter::on_ChBPrintanonymousreceipts_clicked( bool checked ) {
ui->ChBPrintanonymousreceipts->setStyleSheet( "" ); ui->ChBPrintanonymousreceipts->setStyleSheet( "" );
} }
void lc::SessionStarter::on_ChBReceiptsforLocalClients_clicked( bool checked ) { void lc::SessionStarter::on_ChBReceiptsforLocalClients_clicked( bool argChecked ) {
Q_UNUSED( argChecked );
ui->ChBReceiptsforLocalClients->setStyleSheet( "" ); ui->ChBReceiptsforLocalClients->setStyleSheet( "" );
lablib->SetPrintReceiptsForLocalClients( checked );
} }
void lc::SessionStarter::on_PBStartzTree_clicked() { void lc::SessionStarter::on_PBStartzTree_clicked() {
@ -148,7 +147,4 @@ void lc::SessionStarter::SetupWidgets() {
ui->CBDataTargetPath->setCurrentIndex( 2 ); ui->CBDataTargetPath->setCurrentIndex( 2 );
connect( this, &SessionStarter::NewDataTargetPathRequested, connect( this, &SessionStarter::NewDataTargetPathRequested,
this, &SessionStarter::GetNewDataTargetPath ); this, &SessionStarter::GetNewDataTargetPath );
// Set the initial status of CBReceiptsforLocalClients according to the settings in lcLablib
ui->ChBReceiptsforLocalClients->setChecked( lablib->GetPrintReceiptsForLocalClients() );
} }

@ -35,7 +35,7 @@ class SessionStarter : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit SessionStarter( Lablib *argLablib, QWidget *parent = nullptr ); explicit SessionStarter( QWidget *parent = nullptr );
~SessionStarter(); ~SessionStarter();
//! This gets thrown as an exception if this class is created even if it shouldn't //! This gets thrown as an exception if this class is created even if it shouldn't
@ -48,7 +48,6 @@ signals:
QString argChosenLatexHeader ); QString argChosenLatexHeader );
private: private:
Lablib * const lablib = nullptr;
Ui::SessionStarter *ui = nullptr; Ui::SessionStarter *ui = nullptr;
void SetupWidgets(); void SetupWidgets();
@ -60,7 +59,7 @@ private slots:
void on_CBReceiptsHeader_activated( const QString &argHeader ); void on_CBReceiptsHeader_activated( const QString &argHeader );
void on_CBzTreeVersion_activated( const QString &argVersion ); void on_CBzTreeVersion_activated( const QString &argVersion );
void on_ChBPrintanonymousreceipts_clicked( bool checked ); void on_ChBPrintanonymousreceipts_clicked( bool checked );
void on_ChBReceiptsforLocalClients_clicked(bool checked); void on_ChBReceiptsforLocalClients_clicked( bool argChecked );
void on_PBStartzTree_clicked(); void on_PBStartzTree_clicked();
void on_SBPort_editingFinished(); void on_SBPort_editingFinished();

@ -196,6 +196,9 @@ Please take care that it does not contain any spaces or other special characters
<property name="text"> <property name="text">
<string>Print receipts for local clients</string> <string>Print receipts for local clients</string>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

Loading…
Cancel
Save