Further use of globally accessible 'settings' object

remotes/origin/HEAD
markuspg 10 years ago
parent 1b57fe9273
commit 2072dc8db2

@ -33,13 +33,13 @@ network_broadcast_address=192.168.1.255
# A combination of an installed browser and the address of your lab's ORSEE # A combination of an installed browser and the address of your lab's ORSEE
orsee_url=http://yourORSEEserver.tld orsee_url=http://yourORSEEserver.tld
ping_command=/bin/ping ping_command=/bin/ping
# The public keys to access the clients
pkey_path_root=/usr/share/labcontrol/id_labclient_root
pkey_path_user=/usr/share/labcontrol/id_labclient_dsa
postscript_viewer=/usr/bin/okular postscript_viewer=/usr/bin/okular
ps2pdf_command=/usr/bin/ps2pdf ps2pdf_command=/usr/bin/ps2pdf
# The public keys to access the clients
public_key_path_root=/usr/share/labcontrol/id_labclient_root
public_key_path_user=/usr/share/labcontrol/id_labclient_dsa
rcp_command=/usr/bin/rcp
rm_command=/bin/rm rm_command=/bin/rm
scp_command=/usr/bin/scp
# The IP of the server running zTree # The IP of the server running zTree
server_ip=192.168.1.200 server_ip=192.168.1.200
ssh_command=/usr/bin/ssh ssh_command=/usr/bin/ssh

@ -83,12 +83,12 @@ void lc::Client::BeamFile( const QString &argFileToBeam, const QString * const a
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::RCP_CMD ] + " " + arguments.join( " " ) ); debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::RCP_CMD ] + " " + arguments.join( " " ) );
} }
void lc::Client::Boot( const QString * const argNetworkBroadcastAddress ) { void lc::Client::Boot( const QString &argNetworkBroadcastAddress ) {
if ( state == state_t::SHUTTING_DOWN || state == state_t::RESPONDING ) { if ( state == state_t::SHUTTING_DOWN || state == state_t::RESPONDING ) {
return; return;
} }
QStringList arguments; QStringList arguments;
arguments << "-i" << *argNetworkBroadcastAddress << mac; arguments << "-i" << argNetworkBroadcastAddress << mac;
// Start the process // Start the process
QProcess wakeonlanProcess; QProcess wakeonlanProcess;
@ -106,9 +106,10 @@ void lc::Client::Boot( const QString * const argNetworkBroadcastAddress ) {
GotStatusChanged( state_t::BOOTING ); GotStatusChanged( state_t::BOOTING );
} }
void lc::Client::DeactiveScreensaver( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) { void lc::Client::DeactiveScreensaver( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients ) {
QStringList arguments; QStringList arguments;
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name }
<< *( *settingsItems )[ ( int )settItms_t::XSET_CMD ] << "-display" << ":0.0" << "dpms" << "force" << "on"; << *( *settingsItems )[ ( int )settItms_t::XSET_CMD ] << "-display" << ":0.0" << "dpms" << "force" << "on";
// Start the process // Start the process
@ -137,9 +138,10 @@ void lc::Client::GotStatusChanged( state_t argState ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + name + " status changed to: " + QString::number( ( int )argState ) ); debugMessagesTextEdit->appendPlainText( "[DEBUG] " + name + " status changed to: " + QString::number( ( int )argState ) );
} }
void lc::Client::KillZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) { void lc::Client::KillZLeaf( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients ) {
QStringList arguments; QStringList arguments;
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name }
<< QString{ *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] + "/scripts/kill_zLeaf_labcontrol2.sh" }; << QString{ *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] + "/scripts/kill_zLeaf_labcontrol2.sh" };
// Start the process // Start the process
@ -168,7 +170,9 @@ void lc::Client::OpenFilesystem( const QString * const argUserToBeUsed ) {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::FILE_MANAGER ] + " " + arguments.join( " " ) ); debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::FILE_MANAGER ] + " " + arguments.join( " " ) );
} }
void lc::Client::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 & argPublickeyPathUser,
const QString &argUserNameOnClients ) {
if ( ( *settingsItems )[ ( int )settItms_t::TERM_EMUL_CMD ] ) { if ( ( *settingsItems )[ ( int )settItms_t::TERM_EMUL_CMD ] ) {
if ( state < state_t::RESPONDING ) { if ( state < state_t::RESPONDING ) {
return; return;
@ -178,10 +182,10 @@ void lc::Client::OpenTerminal( const QString &argCommand, const bool &argOpenAsR
arguments = new QStringList; arguments = new QStringList;
if ( !argOpenAsRoot ) { if ( !argOpenAsRoot ) {
*arguments << "--title" << name << "-e" << *arguments << "--title" << name << "-e" <<
QString{ *( *settingsItems )[ ( int )settItms_t::SSH_CMD ] + " -i " + *argPublickeyPathUser + " " + *argUserNameOnClients + "@" + name }; QString{ *( *settingsItems )[ ( int )settItms_t::SSH_CMD ] + " -i " + argPublickeyPathUser + " " + argUserNameOnClients + "@" + name };
} else { } else {
*arguments << "--title" << name << "-e" << *arguments << "--title" << name << "-e" <<
QString{ *( *settingsItems )[ ( int )settItms_t::SSH_CMD ] + " -i " + *argPublickeyPathUser + " " + "root@" + name }; QString{ *( *settingsItems )[ ( int )settItms_t::SSH_CMD ] + " -i " + argPublickeyPathUser + " " + "root@" + name };
} }
if ( ( *settingsItems )[ ( int )settItms_t::TERM_EMUL_CMD ]->contains( "konsole" ) ) { if ( ( *settingsItems )[ ( int )settItms_t::TERM_EMUL_CMD ]->contains( "konsole" ) ) {
@ -240,12 +244,12 @@ void lc::Client::ShowDesktop() {
debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::VNC_VIEWER ] + " " + arguments.join( " " ) ); debugMessagesTextEdit->appendPlainText( "[DEBUG] " + *( *settingsItems )[ ( int )settItms_t::VNC_VIEWER ] + " " + arguments.join( " " ) );
} }
void lc::Client::Shutdown( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ) { void lc::Client::Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients ) {
if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING || state == state_t::SHUTTING_DOWN ) { if ( state == state_t::NOT_RESPONDING || state == state_t::BOOTING || state == state_t::SHUTTING_DOWN ) {
return; return;
} }
QStringList arguments; QStringList arguments;
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } << "sudo shutdown -P now"; arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name } << "sudo shutdown -P now";
// Start the process // Start the process
QProcess shutdownProcess; QProcess shutdownProcess;
@ -263,8 +267,11 @@ void lc::Client::Shutdown( const QString * const argPublickeyPathUser, const QSt
GotStatusChanged( state_t::SHUTTING_DOWN ); GotStatusChanged( state_t::SHUTTING_DOWN );
} }
void lc::Client::StartZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients, const QString * const argZTreeVersion, void lc::Client::StartZLeaf( const QString &argPublickeyPathUser,
const QString * const argServerIP, unsigned short int argPort, const QString * const argFakeName ) { const QString &argUserNameOnClients,
const QString * const argZTreeVersion,
const QString &argServerIP, unsigned short int argPort,
const QString * const argFakeName ) {
if ( state < state_t::RESPONDING ) { if ( state < state_t::RESPONDING ) {
return; return;
} }
@ -282,15 +289,18 @@ void lc::Client::StartZLeaf( const QString * const argPublickeyPathUser, const Q
if ( ( messageBoxRunningZLeafFound != nullptr && messageBoxRunningZLeafFound->clickedButton() == messageBoxRunningZLeafFound->button( QMessageBox::Yes ) ) || state != state_t::ZLEAF_RUNNING ) { if ( ( messageBoxRunningZLeafFound != nullptr && messageBoxRunningZLeafFound->clickedButton() == messageBoxRunningZLeafFound->button( QMessageBox::Yes ) ) || state != state_t::ZLEAF_RUNNING ) {
QStringList arguments; QStringList arguments;
if ( argFakeName == nullptr && argPort == 7000 ) { if ( argFakeName == nullptr && argPort == 7000 ) {
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name }
<< "DISPLAY=:0.0" << QString{ "/home/" + *argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } << *argZTreeVersion << *argServerIP; << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP;
} else { } else {
if ( argFakeName == nullptr ) { if ( argFakeName == nullptr ) {
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name }
<< "DISPLAY=:0.0" << QString{ "/home/" + *argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } << *argZTreeVersion << *argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ); << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 );
} else { } else {
arguments << "-i" << *argPublickeyPathUser << QString{ *argUserNameOnClients + "@" + name } arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + name }
<< "DISPLAY=:0.0" << QString{ "/home/" + *argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } << *argZTreeVersion << *argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ) << *argFakeName ; << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ) << *argFakeName ;
} }
} }

@ -75,13 +75,14 @@ public:
/*! /*!
@param argNetworkBroadcastAddress The network broadcast address of the lab @param argNetworkBroadcastAddress The network broadcast address of the lab
*/ */
void Boot( const QString * const argNetworkBroadcastAddress ); void Boot( const QString &argNetworkBroadcastAddress );
//! Runs the 'deactivate_screensaver.sh' script on the client to deactivate the screensaver //! Runs the 'deactivate_screensaver.sh' script on the client to deactivate the screensaver
/*! /*!
@param argPublickeyPathUser The path to the publickey for user login on the clients @param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients @param argUserNameOnClients The name of the user on the clients
*/ */
void DeactiveScreensaver( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ); void DeactiveScreensaver( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients );
//! Returns the current state of the client //! Returns the current state of the client
/*! /*!
@return The current state of the client @return The current state of the client
@ -92,7 +93,7 @@ public:
@param argPublickeyPathUser The path to the publickey for user login on the clients @param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients @param argUserNameOnClients The name of the user on the clients
*/ */
void KillZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ); void KillZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients );
//! Opens a file manager for the client's file system //! Opens a file manager for the client's file system
/*! /*!
@param argUserToBeUsed The name of the user on the clients @param argUserToBeUsed The name of the user on the clients
@ -105,7 +106,9 @@ public:
@param argPublickeyPathUser The path to the publickey for user login on the clients @param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients @param argUserNameOnClients The name of the user on the clients
*/ */
void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot, const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ); void OpenTerminal( const QString &argCommand, const bool &argOpenAsRoot,
const QString &argPublickeyPathUser,
const QString &argUserNameOnClients );
//! Shows the desktop of the given client //! Shows the desktop of the given client
void ShowDesktop(); void ShowDesktop();
//! Shuts down the client //! Shuts down the client
@ -113,7 +116,7 @@ public:
@param argPublickeyPathUser The path to the publickey for user login on the clients @param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients @param argUserNameOnClients The name of the user on the clients
*/ */
void Shutdown( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients ); void Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients );
//! Starts a zLeaf instance on the client //! Starts a zLeaf instance on the client
/*! /*!
@param argPublickeyPathUser The path to the publickey for user login on the clients @param argPublickeyPathUser The path to the publickey for user login on the clients
@ -123,8 +126,9 @@ public:
@param argPort The port zTree ist listening on on the server @param argPort The port zTree ist listening on on the server
@param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client) @param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client)
*/ */
void StartZLeaf( const QString * const argPublickeyPathUser, const QString * const argUserNameOnClients, const QString * const argZTreeVersion, void StartZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients,
const QString * const argServerIP, unsigned short int argPort, const QString * const argFakeName = nullptr ); const QString * const argZTreeVersion, const QString &argServerIP,
unsigned short int argPort, const QString * const argFakeName = nullptr );
private: private:
QPlainTextEdit * const debugMessagesTextEdit = nullptr; QPlainTextEdit * const debugMessagesTextEdit = nullptr;

@ -84,18 +84,6 @@ lc::Lablib::~Lablib () {
delete settingsItems; delete settingsItems;
} }
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 ) );
return false;
}
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] '%1': %2" ).arg( argVariableName ).arg( *argPath ) );
return true;
}
void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() { void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
// Detect the installed LaTeX headers // Detect the installed LaTeX headers
if ( ( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ) { if ( ( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ) {
@ -148,73 +136,6 @@ void lc::Lablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections )
} }
void lc::Lablib::ReadSettings() { void lc::Lablib::ReadSettings() {
QStringList simpleLoadableItems = { QStringList{}
<< "browser_command"
<< "dvips_command"
<< "file_manager"
<< "labcontrol_installation_directory"
<< "latex_command"
<< "local_zLeaf_name"
<< "lpr_command"
<< "netstat_command"
<< "network_broadcast_address"
<< "orsee_command"
<< "ping_command"
<< "postscript_viewer"
<< "ps2pdf_command"
<< "public_key_path_root"
<< "public_key_path_user"
<< "rcp_command"
<< "rm_command"
<< "server_ip"
<< "ssh_command"
<< "terminal_emulator_command"
<< "user_name_on_clients"
<< "vnc_viewer"
<< "wakeonlan_command"
<< "wmctrl_command"
<< "xset_command"
<< "ztree_installation_directory" };
QStringList theItemsErrorComplaints = { QStringList{}
<< "Opening ORSEE in a browser will not work."
<< "Receipts creation will not work."
<< "The display of preprints will not work."
<< "Labcontrol will missbehave with high propability."
<< "Receipts creation will not work."
<< "The local zLeaf default name will default to 'local'."
<< "Receipts printing will not work."
<< "Detection of active zLeaf connections will not work."
<< "Booting the clients will not work."
<< "Opening ORSEE in a browser will not work."
<< "Status updates for the clients will not work."
<< "Viewing the generated receipts postscript file will not work."
<< "Converting and viewing the generated receipts file will not work."
<< "Administration actions concerning the clients will not be available."
<< "Many actions concerning the clients will not be available."
<< "Beaming files to the clients will not be possible."
<< "Cleanup of the zTree data target path will not work."
<< "Starting zLeaves and retrieving client help messages will not work."
<< "All actions concerning the clients will not be possible."
<< "Conducting administrative tasks will not be possible."
<< "All actions concerning the clients performed by the experiment user will not work."
<< "Viewing the client's screens will not work."
<< "Booting the clients will not work."
<< "Setting zTree's window title to its port number will not work."
<< "Deactivating the screen saver on the clients will not be possible."
<< "zTree will not be available" };
bool is_file[] = { true, true, true, true, true, false, true, true, false, false,
true, true, true, true, true, true, true, false, true, true,
false, true, true, true, false, true };
QString *tempItemStorage = nullptr;
for ( int i = 0; i < ( int )settItms_t::SETT_ITMS_QUANT; i++ ) {
tempItemStorage = ReadSettingsItem( simpleLoadableItems[ i ], theItemsErrorComplaints[ i ], is_file[ i ] );
settingsItems->replace( i, tempItemStorage );
}
tempItemStorage = nullptr;
// 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 ( !( *settingsItems )[ ( int )settItms_t::LOCAL_ZLEAF_NAME ] ) { if ( !( *settingsItems )[ ( int )settItms_t::LOCAL_ZLEAF_NAME ] ) {
settingsItems->replace( ( int )settItms_t::LOCAL_ZLEAF_NAME, new QString{ tr( "local" ) } ); settingsItems->replace( ( int )settItms_t::LOCAL_ZLEAF_NAME, new QString{ tr( "local" ) } );
@ -350,29 +271,6 @@ void lc::Lablib::ReadSettings() {
} }
} }
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 ) );
return nullptr;
}
else {
QString *tempString = new QString{ labSettings.value( argVariableName ).toString() };
if ( argItemIsFile && !CheckPathAndComplain( tempString, argVariableName, argComplaint ) ) {
delete tempString;
tempString = nullptr;
}
// Empty strings count as not set, so delete them for correct error handling in the rest of Labcontrol
if ( tempString && tempString->isEmpty() ) {
delete tempString;
tempString = nullptr;
}
return tempString;
}
return nullptr;
}
void lc::Lablib::SetAnonymousReceiptsPlaceholder( const QString &argPlaceHolder ) { void lc::Lablib::SetAnonymousReceiptsPlaceholder( const QString &argPlaceHolder ) {
anonymousReceiptsPlaceholder = argPlaceHolder; anonymousReceiptsPlaceholder = argPlaceHolder;
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] anonymous_receipts_placeholder set to: '%1'" ).arg( anonymousReceiptsPlaceholder ) ); debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] anonymous_receipts_placeholder set to: '%1'" ).arg( anonymousReceiptsPlaceholder ) );
@ -413,7 +311,7 @@ void lc::Lablib::ShowOrsee() {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
showOrseeProcess.setProcessEnvironment( env ); showOrseeProcess.setProcessEnvironment( env );
QString program{ settings->browserCmd }; QString program{ settings->browserCmd };
QStringList arguments{ QStringList{} << *( *settingsItems )[ ( int )settItms_t::ORSEE_URL ] }; 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

@ -161,27 +161,11 @@ private slots:
void GotNetstatQueryResult( QStringList *argActiveZLeafConnections ); void GotNetstatQueryResult( QStringList *argActiveZLeafConnections );
private: private:
//! Checks if the specified path exists and complains if not so
/**
* @param argPath The path which shall be check for existance
* @param argVariableName The name of the QSettings variable referring the path
* @param argComplaint The complaint which shall be added to debugging output
* @return True, if path exists, false if not
*/
bool CheckPathAndComplain( const QString * const argPath, const QString &argVariableName, const QString &argComplaint );
//! Detects installed zTree version and LaTeX headers //! Detects installed zTree version and LaTeX headers
void DetectInstalledZTreeVersionsAndLaTeXHeaders(); void DetectInstalledZTreeVersionsAndLaTeXHeaders();
/** Reads all settings from the QSettings 'labSettings' object. /** Reads all settings from the QSettings 'labSettings' object.
*/ */
void ReadSettings(); void ReadSettings();
//! Loads a single settings item from the globally accessible QSettings instance
/**
* @param arg_variable_name The name of the variable to load
* @param arg_complaint The complaint to display if the variable could not be loaded
* @param arg_is_file If the existance of the file referenced by the setting's value shall be checked
* @return The settings data or a nullptr on failure
*/
QString *ReadSettingsItem( const QString &argVariableName, const QString &argComplaint, bool argItemIsFile = false );
QStringList *adminUsers = nullptr; //! Stores all users with administrative rights QStringList *adminUsers = nullptr; //! Stores all users with administrative rights
QString anonymousReceiptsPlaceholder; //! The placeholder which shall substitute the client names on anonymous receipts (if != "") QString anonymousReceiptsPlaceholder; //! The placeholder which shall substitute the client names on anonymous receipts (if != "")

@ -1,6 +1,116 @@
#include <QDebug>
#include <QFile>
#include "settings.h" #include "settings.h"
Settings::Settings( QObject *argParent ) : lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
QObject{ argParent } QObject{ argParent },
browserCmd{ ReadSettingsItem( "browser_command",
"Opening ORSEE in a browser will not work.",
argSettings, true ) },
dvipsCmd{ ReadSettingsItem( "dvips_command",
"Receipts creation will not work.",
argSettings, true ) },
fileMngr{ ReadSettingsItem( "file_manager",
"The display of preprints will not work.",
argSettings, true ) },
latexCmd{ ReadSettingsItem( "latex_command",
"Receipts creation will not work.",
argSettings, true ) },
lcInstDir{ ReadSettingsItem( "labcontrol_installation_directory",
"Labcontrol will missbehave with high propability.",
argSettings, true ) },
localzLeafName{ ReadSettingsItem( "local_zLeaf_name",
"The local zLeaf default name will default to 'local'.",
argSettings, false ) },
lprCmd{ ReadSettingsItem( "lpr_command",
"Receipts printing will not work.",
argSettings, true ) },
netstatCmd{ ReadSettingsItem( "netstat_command",
"Detection of active zLeaf connections will not work.",
argSettings, true ) },
netwBrdAddr{ ReadSettingsItem( "network_broadcast_address",
"Booting the clients will not work.",
argSettings, false ) },
orseeUrl{ ReadSettingsItem( "orsee_url",
"Opening ORSEE in a browser will not work.",
argSettings, false ) },
pingCmd{ ReadSettingsItem( "ping_command",
"Status updates for the clients will not work.",
argSettings, true ) },
postscriptViewer{ ReadSettingsItem( "postscript_viewer",
"Viewing the generated receipts postscript file will not work.",
argSettings, true ) },
ps2pdfCmd{ ReadSettingsItem( "ps2pdf_command",
"Converting and viewing the generated receipts file will not work.",
argSettings, true ) },
pkeyPathRoot{ ReadSettingsItem( "pkey_path_root",
"Administration actions concerning the clients will not be available.",
argSettings, true ) },
pkeyPathUser{ ReadSettingsItem( "pkey_path_user",
"Many actions concerning the clients will not be available.",
argSettings, true ) },
rmCmd{ ReadSettingsItem( "rm_command",
"Cleanup of the zTree data target path will not work.",
argSettings, true ) },
scpCmd{ ReadSettingsItem( "scp_command",
"Beaming files to the clients will not be possible.",
argSettings, true ) },
serverIP{ ReadSettingsItem( "server_ip",
"Starting zLeaves and retrieving client help messages will not work.",
argSettings, false ) },
sshCmd{ ReadSettingsItem( "ssh_command",
"All actions concerning the clients will not be possible.",
argSettings, true ) },
termEmulCmd{ ReadSettingsItem( "terminal_emulator_command",
"Conducting administrative tasks will not be possible.",
argSettings, true ) },
userNameOnClients{ ReadSettingsItem( "user_name_on_clients",
"All actions concerning the clients performed by the experiment user will not work.",
argSettings, false ) },
vncViewer{ ReadSettingsItem( "vnc_viewer",
"Viewing the clients' screens will not work.",
argSettings, true ) },
wakeonlanCmd{ ReadSettingsItem( "wakeonlan_command",
"Booting the clients will not work.",
argSettings, true ) },
wmctrlCmd{ ReadSettingsItem( "wmctrl_command",
"Setting zTree's window title to its port number will not work.",
argSettings, true ) },
xsetCmd{ ReadSettingsItem( "xset_command",
"Deactivating the screen saver on the clients will not be possible.",
argSettings, true ) },
zTreeInstDir{ ReadSettingsItem( "ztree_installation_directory",
"zTree will not be available.",
argSettings, true ) }
{ {
} }
bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &argVariableName,
const QString &argMessage ) {
if ( !QFile::exists( argPath ) ) {
qDebug() << "The path" << argPath << "specified by" << argVariableName
<< "does not exist:" << argMessage;
return false;
}
qDebug() << argVariableName << ":" << argPath;
return true;
}
QString lc::Settings::ReadSettingsItem( const QString &argVariableName,
const QString &argMessage,
const QSettings &argSettings,
bool argItemIsFile) {
if ( !argSettings.contains( argVariableName ) ) {
qDebug() << argVariableName << "was not set." << argMessage;
return QString{};
} else {
QString tempString{ argSettings.value( argVariableName ).toString() };
if ( argItemIsFile
&& !CheckPathAndComplain( tempString, argVariableName, argMessage ) ) {
tempString.clear();
}
return tempString;
}
return QString{};
}

@ -2,12 +2,52 @@
#define SETTINGS_H #define SETTINGS_H
#include <QObject> #include <QObject>
#include <QSettings>
namespace lc {
class Settings : public QObject { class Settings : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit Settings( QObject *argParent = nullptr ); explicit Settings( const QSettings &argSettings, QObject *argParent = nullptr );
const QString browserCmd;
const QString dvipsCmd;
const QString fileMngr;
const QString latexCmd;
const QString lcInstDir;
const QString localzLeafName;
const QString lprCmd;
const QString netstatCmd;
const QString netwBrdAddr;
const QString orseeUrl;
const QString pingCmd;
const QString postscriptViewer;
const QString ps2pdfCmd;
const QString pkeyPathRoot;
const QString pkeyPathUser;
const QString rmCmd;
const QString scpCmd;
const QString serverIP;
const QString sshCmd;
const QString termEmulCmd;
const QString userNameOnClients;
const QString vncViewer;
const QString wakeonlanCmd;
const QString wmctrlCmd;
const QString xsetCmd;
const QString zTreeInstDir;
private:
static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName,
const QString &argMessage );
static QString ReadSettingsItem( const QString &argVariableName,
const QString &argMessage,
const QSettings &argSettings,
bool argItemIsFile );
}; };
}
#endif // SETTINGS_H #endif // SETTINGS_H

@ -93,7 +93,7 @@ bool lc::MainWindow::CheckIfUserIsAdmin() {
void lc::MainWindow::DisableDisfunctionalWidgets() { void lc::MainWindow::DisableDisfunctionalWidgets() {
// Disable all functions relying on the labcontrol installation directory if it is not available // Disable all functions relying on the labcontrol installation directory if it is not available
if ( !lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) ) { if ( settings->lcInstDir.isEmpty() ) {
ui->CBClientNames->setEnabled( false ); ui->CBClientNames->setEnabled( false );
ui->CBWebcamChooser->setEnabled( false ); ui->CBWebcamChooser->setEnabled( false );
ui->GBClientActions->setEnabled( false ); ui->GBClientActions->setEnabled( false );
@ -110,24 +110,24 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
} }
// Disable 'PBShowPreprints', if 'file_manager' was not set // Disable 'PBShowPreprints', if 'file_manager' was not set
if ( !lablib->GetSettingsItem( settItms_t::FILE_MANAGER ) ) { if ( settings->fileMngr.isEmpty() ) {
ui->PBShowPreprints->setEnabled( false ); ui->PBShowPreprints->setEnabled( false );
} }
// Disable 'PBBoot', if 'network_broadcast_address' was not set // Disable 'PBBoot', if 'network_broadcast_address' was not set
if ( !lablib->GetSettingsItem( settItms_t::NETW_BRDCAST_ADDR ) ) { if ( settings->netwBrdAddr.isEmpty() ) {
ui->PBBoot->setEnabled( false ); ui->PBBoot->setEnabled( false );
} }
// Disable 'PBShowORSEE', if 'orsee_command' was not set // Disable 'PBShowORSEE', if 'orsee_command' was not set
if ( settings->browserCmd.isEmpty() if ( settings->browserCmd.isEmpty()
|| !lablib->GetSettingsItem( settItms_t::ORSEE_URL ) ) { || settings->orseeUrl.isEmpty() ) {
ui->PBShowORSEE->setEnabled( false ); ui->PBShowORSEE->setEnabled( false );
} }
// Disable all widgets needless if 'public_key_path_user' or 'user_name_on_clients' was not set // Disable all widgets needless if 'public_key_path_user' or 'user_name_on_clients' was not set
if ( !lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ) if ( settings->pkeyPathUser.isEmpty()
|| !lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ) { || settings->userNameOnClients.isEmpty() ) {
ui->CBClientNames->setEnabled( false ); ui->CBClientNames->setEnabled( false );
ui->LEFilePath->setEnabled( false ); ui->LEFilePath->setEnabled( false );
ui->LFakeName->setEnabled( false ); ui->LFakeName->setEnabled( false );
@ -143,33 +143,33 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
} }
// Disable widgets needless if 'public_key_path_root' was not set // Disable widgets needless if 'public_key_path_root' was not set
if ( !lablib->GetSettingsItem( settItms_t::SSH_KEY_ROOT ) ) { if ( settings->pkeyPathRoot.isEmpty() ) {
ui->RBUseUserRoot->setEnabled( false ); ui->RBUseUserRoot->setEnabled( false );
ui->RBUseLocalUser->click(); ui->RBUseLocalUser->click();
} }
if ( !lablib->GetSettingsItem( settItms_t::SSH_KEY_ROOT ) if ( settings->pkeyPathRoot.isEmpty()
&& !lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ) ) { && settings->pkeyPathUser.isEmpty() ) {
ui->GBExecuteOnEveryClient->setEnabled( false ); ui->GBExecuteOnEveryClient->setEnabled( false );
ui->GBOptionsForAdminActions->setEnabled( false ); ui->GBOptionsForAdminActions->setEnabled( false );
ui->PBOpenTerminal->setEnabled( false ); ui->PBOpenTerminal->setEnabled( false );
} }
// Disable beam functionality if 'rcp_command' was not set // Disable beam functionality if 'rcp_command' was not set
if ( !lablib->GetSettingsItem( settItms_t::RCP_CMD ) ) { if ( settings->scpCmd.isEmpty() ) {
ui->LEFilePath->setEnabled( false ); ui->LEFilePath->setEnabled( false );
ui->PBBeamFile->setEnabled( false ); ui->PBBeamFile->setEnabled( false );
ui->PBChooseFile->setEnabled( false ); ui->PBChooseFile->setEnabled( false );
} }
// Disable 'PBRunzLeaf' and 'PBStartzLeaf' if 'server_ip' was not set // Disable 'PBRunzLeaf' and 'PBStartzLeaf' if 'server_ip' was not set
if ( !lablib->GetSettingsItem( settItms_t::SERVER_IP ) ) { if ( settings->serverIP.isEmpty() ) {
ui->PBRunzLeaf->setEnabled( false ); ui->PBRunzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false ); ui->PBStartzLeaf->setEnabled( false );
} }
// Disable any actions concerning the clients if 'ssh_command' was not set // Disable any actions concerning the clients if 'ssh_command' was not set
if ( !lablib->GetSettingsItem( settItms_t::SSH_CMD ) ) { if ( settings->sshCmd.isEmpty() ) {
ui->CBClientNames->setEnabled( false ); ui->CBClientNames->setEnabled( false );
ui->GBClientActions->setEnabled( false ); ui->GBClientActions->setEnabled( false );
ui->LFakeName->setEnabled( false ); ui->LFakeName->setEnabled( false );
@ -184,29 +184,29 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
} }
// Disable 'PBOpenTerminal' if 'terminal_emulator_command' was not set // Disable 'PBOpenTerminal' if 'terminal_emulator_command' was not set
if ( !lablib->GetSettingsItem( settItms_t::TERM_EMUL_CMD ) ) { if ( settings->termEmulCmd.isEmpty() ) {
ui->GBExecuteOnEveryClient->setEnabled( false ); ui->GBExecuteOnEveryClient->setEnabled( false );
ui->PBOpenTerminal->setEnabled( false ); ui->PBOpenTerminal->setEnabled( false );
} }
// Disable 'PBViewDesktop' if 'vnc_viewer' was not set // Disable 'PBViewDesktop' if 'vnc_viewer' was not set
if ( !lablib->GetSettingsItem( settItms_t::VNC_VIEWER ) ) { if ( settings->vncViewer.isEmpty() ) {
ui->PBViewDesktop->setEnabled( false ); ui->PBViewDesktop->setEnabled( false );
} }
// Disable 'PBBoot' if 'wakeonlan_command' was not set // Disable 'PBBoot' if 'wakeonlan_command' was not set
if ( !lablib->GetSettingsItem( settItms_t::WAKEONLAN_CMD ) ) { if ( settings->wakeonlanCmd.isEmpty() ) {
ui->PBBoot->setEnabled( false ); ui->PBBoot->setEnabled( false );
} }
// Disable the disable screensaver function if the 'xset_command' was not set // Disable the disable screensaver function if the 'xset_command' was not set
if ( !lablib->GetSettingsItem( settItms_t::XSET_CMD ) ) { if ( settings->xsetCmd.isEmpty() ) {
ui->PBDeactivateScreensaver->setEnabled( false ); ui->PBDeactivateScreensaver->setEnabled( false );
} }
} }
void lc::MainWindow::LoadIconPixmaps() { void lc::MainWindow::LoadIconPixmaps() {
if ( !lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) ) { if ( settings->lcInstDir.isEmpty() ) {
return; return;
} }
@ -219,17 +219,17 @@ void lc::MainWindow::LoadIconPixmaps() {
<< "zLeaf.png" }; << "zLeaf.png" };
for ( int i = 0; i < ( int )icons_t::ICON_QUANTITY; i++ ) { for ( int i = 0; i < ( int )icons_t::ICON_QUANTITY; i++ ) {
if ( !icons[ i ].load( *lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) + "/icons/" + iconNames[ i ] ) ) { if ( !icons[ i ].load( settings->lcInstDir + "/icons/" + iconNames[ i ] ) ) {
QMessageBox::information( this, tr( "Could not load icon '%1'" ).arg( iconNames[ i ] ), QMessageBox::information( this, tr( "Could not load icon '%1'" ).arg( iconNames[ i ] ),
tr( "The icon in '%1/icons/%2' could not be loaded." ) tr( "The icon in '%1/icons/%2' could not be loaded." )
.arg( *lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) ).arg( iconNames[ i ] ), QMessageBox::Ok ); .arg( settings->lcInstDir ).arg( iconNames[ i ] ), QMessageBox::Ok );
} }
} }
} }
void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) { void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) {
if ( argIndex != 0 ) { if ( argIndex != 0 ) {
QString program{ *lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) + "/webcam_display" }; QString program{ settings->lcInstDir + "/webcam_display" };
QStringList arguments; QStringList arguments;
arguments << ui->CBWebcamChooser->currentText(); arguments << ui->CBWebcamChooser->currentText();
@ -242,13 +242,11 @@ void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) {
void lc::MainWindow::on_PBBeamFile_clicked() { void lc::MainWindow::on_PBBeamFile_clicked() {
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const publickeyPathUser{ lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ) };
const QString * const userNameOnClients{ lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) };
const QString fileToBeam{ ui->LEFilePath->text() }; const QString fileToBeam{ ui->LEFilePath->text() };
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->BeamFile( fileToBeam, publickeyPathUser, userNameOnClients ); client->BeamFile( fileToBeam, &settings->pkeyPathUser, &settings->userNameOnClients );
} }
} }
} }
@ -258,7 +256,7 @@ void lc::MainWindow::on_PBBoot_clicked() {
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Boot( lablib->GetSettingsItem( settItms_t::NETW_BRDCAST_ADDR ) ); client->Boot( settings->netwBrdAddr );
} }
} }
} }
@ -282,12 +280,10 @@ void lc::MainWindow::on_PBChooseFile_clicked() {
} }
void lc::MainWindow::on_PBDeactivateScreensaver_clicked() { void lc::MainWindow::on_PBDeactivateScreensaver_clicked() {
const QString * const publickey_path_user{ lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ) };
const QString * const user_name_on_clients{ lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) };
QVector< Client* > *clients = lablib->GetClients(); QVector< Client* > *clients = lablib->GetClients();
for ( auto s : *clients ) { for ( auto s : *clients ) {
if ( s->GetClientState() >= state_t::RESPONDING ) if ( s->GetClientState() >= state_t::RESPONDING )
s->DeactiveScreensaver( publickey_path_user, user_name_on_clients ); s->DeactiveScreensaver( settings->pkeyPathUser, settings->userNameOnClients );
} }
} }
@ -319,21 +315,20 @@ void lc::MainWindow::on_PBExecute_clicked() {
QString command = ui->CBCommandToExecute->currentText(); QString command = ui->CBCommandToExecute->currentText();
// Set the correct public key // Set the correct public key
QString *tempPublickeyPathUser = nullptr; QString pkeyPathUser;
if ( ui->RBUseUserRoot->isChecked() ) { if ( ui->RBUseUserRoot->isChecked() ) {
tempPublickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_ROOT ); pkeyPathUser = settings->pkeyPathRoot;
} else { } else {
tempPublickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ); pkeyPathUser = settings->pkeyPathUser;
} }
const QString * const publickeyPathUser = tempPublickeyPathUser;
// and execute it // and execute it
if ( executeOnEveryClient ) { if ( executeOnEveryClient ) {
ui->PTEDebugMessages->appendPlainText( tr( "[DEBUG] Executing command '%1' on every client." ).arg( command ) ); ui->PTEDebugMessages->appendPlainText( tr( "[DEBUG] Executing command '%1' on every client." ).arg( command ) );
for ( auto s: *clients ) { for ( auto s: *clients ) {
if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) {
s->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), publickeyPathUser, s->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), pkeyPathUser,
lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ); settings->userNameOnClients );
} }
} }
} else { } else {
@ -342,8 +337,8 @@ void lc::MainWindow::on_PBExecute_clicked() {
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), publickeyPathUser, client->OpenTerminal( command, ui->RBUseUserRoot->isChecked(), pkeyPathUser,
lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ); settings->userNameOnClients );
} }
} }
} }
@ -352,7 +347,7 @@ void lc::MainWindow::on_PBExecute_clicked() {
} }
void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { void lc::MainWindow::on_PBKillLocalzLeaf_clicked() {
QString program{ *lablib->GetSettingsItem( settItms_t::LC_INST_DIR ) + "/scripts/kill_zLeaf_labcontrol2.sh" }; QString program{ settings->lcInstDir + "/scripts/kill_zLeaf_labcontrol2.sh" };
// Start the process // Start the process
QProcess kill_zleaf_process; QProcess kill_zleaf_process;
@ -368,12 +363,10 @@ void lc::MainWindow::on_PBKillLocalzLeaf_clicked() {
void lc::MainWindow::on_PBKillzLeaf_clicked() { void lc::MainWindow::on_PBKillzLeaf_clicked() {
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const publickeyPathUser{ lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ) };
const QString * const userNameOnClients{ lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->KillZLeaf( publickeyPathUser, userNameOnClients ); client->KillZLeaf( settings->pkeyPathUser, settings->userNameOnClients );
} }
} }
} }
@ -384,7 +377,7 @@ void lc::MainWindow::on_PBOpenFilesystem_clicked() {
if ( ui->RBUseUserRoot->isChecked() ) { if ( ui->RBUseUserRoot->isChecked() ) {
userToBeUsed = new QString{ "root" }; userToBeUsed = new QString{ "root" };
} else { } else {
userToBeUsed = new QString{ *lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) }; userToBeUsed = new QString{ settings->userNameOnClients };
} }
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
@ -398,20 +391,18 @@ void lc::MainWindow::on_PBOpenFilesystem_clicked() {
} }
void lc::MainWindow::on_PBOpenTerminal_clicked() { void lc::MainWindow::on_PBOpenTerminal_clicked() {
QString *tempPublickeyPathUser = nullptr; QString pkeyPathUser;
if ( ui->RBUseUserRoot->isChecked() ) { if ( ui->RBUseUserRoot->isChecked() ) {
tempPublickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_ROOT ); pkeyPathUser = settings->pkeyPathRoot;
} else { } else {
tempPublickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ); pkeyPathUser = settings->pkeyPathUser;
} }
const QString * const publickeyPathUser{ tempPublickeyPathUser };
const QString * const userNameOnClients{ lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) };
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked(), client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked(),
publickeyPathUser, userNameOnClients ); pkeyPathUser, settings->userNameOnClients );
} }
} }
} }
@ -459,14 +450,14 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() {
QMessageBox messageBox{ QMessageBox::Information, tr( "Too many clients selected" ), tr( "There are too many clients selected in the table view on the left. Please select only one." ), QMessageBox::Ok, this }; QMessageBox messageBox{ QMessageBox::Information, tr( "Too many clients selected" ), tr( "There are too many clients selected in the table view on the left. Please select only one." ), QMessageBox::Ok, this };
messageBox.exec(); messageBox.exec();
} else { } else {
const QString * const fakeName = new QString{ ui->CBClientNames->currentText() }, * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() }, const QString * const fakeName = new QString{ ui->CBClientNames->currentText() };
* const publickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ), * const serverIP = lablib->GetSettingsItem( settItms_t::SERVER_IP ), const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
* const userNameOnClients = lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS );
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( publickeyPathUser, userNameOnClients, zLeafVersion, serverIP, client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients,
ui->SBzLeafPort->value(), fakeName ); zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(),
fakeName );
} }
} }
delete fakeName; delete fakeName;
@ -492,12 +483,10 @@ void lc::MainWindow::on_PBShowSessions_clicked() {
void lc::MainWindow::on_PBShutdown_clicked() { void lc::MainWindow::on_PBShutdown_clicked() {
QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const publickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ),
* const userNameOnClients = lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS );
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->Shutdown( publickeyPathUser, userNameOnClients ); client->Shutdown( settings->pkeyPathUser, settings->userNameOnClients );
} }
} }
} }
@ -551,14 +540,13 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() {
} }
QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes();
const QString * const publickeyPathUser = lablib->GetSettingsItem( settItms_t::SSH_KEY_USER ), const QString * const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
* const serverIP = lablib->GetSettingsItem( settItms_t::SERVER_IP ),
* const userNameOnClients = lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ),
* const zLeafVersion = new QString{ ui->CBzLeafVersion->currentText() };
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *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 ); client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients,
zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(),
nullptr );
} }
} }
delete zLeafVersion; delete zLeafVersion;
@ -717,8 +705,8 @@ void lc::MainWindow::SetupWidgets() {
ui->LAdministrativeRights->setText( tr( "You don't have administrative rights." ) ); ui->LAdministrativeRights->setText( tr( "You don't have administrative rights." ) );
} }
ui->LUserName->setText( tr( "You are user %1" ).arg( lablib->GetUserNameOnServer() ) ); ui->LUserName->setText( tr( "You are user %1" ).arg( lablib->GetUserNameOnServer() ) );
if ( lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ) { if ( !settings->userNameOnClients.isEmpty() ) {
ui->RBUseLocalUser->setText( *lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ); ui->RBUseLocalUser->setText( settings->userNameOnClients );
} else { } else {
ui->RBUseUserRoot->click(); ui->RBUseUserRoot->click();
} }
@ -731,23 +719,30 @@ void lc::MainWindow::SetupWidgets() {
ui->RBUseLocalUser->click(); ui->RBUseLocalUser->click();
// Fill the CBCommandToExecute QComboBox // Fill the CBCommandToExecute QComboBox
if ( lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) ) { if ( !settings->userNameOnClients.isEmpty() ) {
ui->CBCommandToExecute->addItems( QStringList{} << "" << "apt update" << "apt full-upgrade -y" << "reboot" << "rm -rfv /home/" + *lablib->GetSettingsItem( settItms_t::USER_NAME_ON_CLIENTS ) + "/.mozilla" << "uname -a" ); ui->CBCommandToExecute->addItems( QStringList{} << "" << "apt update"
<< "apt full-upgrade -y" << "reboot"
<< "rm -rfv /home/" + settings->userNameOnClients + "/.mozilla"
<< "uname -a" );
} else { } else {
ui->CBCommandToExecute->addItems( QStringList{} << "" << "apt update" << "apt full-upgrade -y" << "reboot" << "uname -a" ); ui->CBCommandToExecute->addItems( QStringList{} << "" << "apt update"
<< "apt full-upgrade -y" << "reboot" << "uname -a" );
} }
DisableDisfunctionalWidgets(); DisableDisfunctionalWidgets();
const QString date{ __DATE__ };
const QString time{ __TIME__ };
// Set the info text in LInfo on the TInfo tab // Set the info text in LInfo on the TInfo tab
ui->LInfo->setText( "This is Labcontrol.\n\nCopyright 2014-2015 Markus Prasser\n\n\n" ui->LInfo->setText( "This is Labcontrol.\n\nCopyright 2014-2016 Markus Prasser\n\n\n"
"Labcontrol is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation" "Labcontrol is free software: you can redistribute it and/or modify\n"
", either version 3 of the License, or\n(at your option) any later version.\n\n" "it under the terms of the GNU General Public License as published by\n"
"Labcontrol is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\n\n" "the Free Software Foundation, either version 3 of the License, or\n"
"You should have received a copy of the GNU General Public License\nalong with Labcontrol. If not, see <http://www.gnu.org/licenses/>.\n\n\n" "(at your option) any later version.\n\n"
"This version of Labcontrol was compiled on " + date + " at " + time + "." ); "Labcontrol is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
"See the GNU General Public License for more details.\n\n"
"You should have received a copy of the GNU General Public License\n"
"along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.\n\n\n" );
} }
void lc::MainWindow::UpdateClientsTableView() { void lc::MainWindow::UpdateClientsTableView() {

Loading…
Cancel
Save