Reformat Settings

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2016 Markus Prasser * Copyright 2014-2018 Markus Prasser, Tobias Weiss
* *
* This file is part of Labcontrol. * This file is part of Labcontrol.
* *
@ -25,127 +25,127 @@
#include "client.h" #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) :
QObject{ argParent }, QObject{argParent},
defaultReceiptIndex{ GetDefaultReceiptIndex( argSettings ) }, defaultReceiptIndex{GetDefaultReceiptIndex(argSettings)},
browserCmd{ ReadSettingsItem( "browser_command", browserCmd{ReadSettingsItem("browser_command",
"Opening ORSEE in a browser will not work.",
argSettings, true ) },
clientBrowserCmd{ ReadSettingsItem( "client_browser_command",
"Opening a browser window on clients will not work.",
argSettings, false ) },
dvipsCmd{ ReadSettingsItem( "dvips_command",
"Receipts creation will not work.",
argSettings, true ) },
fileMngr{ ReadSettingsItem( "file_manager",
"The display of preprints will not work.",
argSettings, true ) },
killallCmd{ ReadSettingsItem( "killall_command",
"Killing 'zleaf.exe' instances will not work.",
argSettings, true ) },
latexCmd{ ReadSettingsItem( "latex_command",
"Receipts creation will not work.",
argSettings, true ) },
lcDataDir{ ReadSettingsItem( "labcontrol_data_directory",
"Datapath not set. Labcontrol will missbehave with high propability.",
argSettings, true ) },
localUserName{ GetLocalUserName() },
localzLeafSize{ ReadSettingsItem( "local_zLeaf_size",
"Resolution of local zLeaf window",
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.", "Opening ORSEE in a browser will not work.",
argSettings, false ) }, argSettings, true)},
pingCmd{ ReadSettingsItem( "ping_command", clientBrowserCmd{ReadSettingsItem("client_browser_command",
"Status updates for the clients will not work.", "Opening a browser window on clients will not work.",
argSettings, true ) }, argSettings, false)},
postscriptViewer{ ReadSettingsItem( "postscript_viewer", dvipsCmd{ReadSettingsItem("dvips_command",
"Viewing the generated receipts postscript file will not work.", "Receipts creation will not work.",
argSettings, true ) }, argSettings, true)},
ps2pdfCmd{ ReadSettingsItem( "ps2pdf_command", fileMngr{ReadSettingsItem("file_manager",
"Converting and viewing the generated receipts file will not work.", "The display of preprints will not work.",
argSettings, true ) }, argSettings, true)},
pkeyPathRoot{ ReadSettingsItem( "pkey_path_root", killallCmd{ ReadSettingsItem("killall_command",
"Administration actions concerning the clients will not be available.", "Killing 'zleaf.exe' instances will not work.",
argSettings, true ) }, argSettings, true)},
pkeyPathUser{ ReadSettingsItem( "pkey_path_user", latexCmd{ReadSettingsItem("latex_command",
"Many actions concerning the clients will not be available.", "Receipts creation will not work.",
argSettings, true ) }, argSettings, true)},
rmCmd{ ReadSettingsItem( "rm_command", lcDataDir{ReadSettingsItem("labcontrol_data_directory",
"Cleanup of the zTree data target path will not work.", "Datapath not set. Labcontrol will missbehave with high propability.",
argSettings, true ) }, argSettings, true)},
scpCmd{ ReadSettingsItem( "scp_command", localUserName{GetLocalUserName()},
"Beaming files to the clients will not be possible.", localzLeafSize{ReadSettingsItem("local_zLeaf_size",
argSettings, true ) }, "Resolution of local zLeaf window",
serverIP{ ReadSettingsItem( "server_ip", argSettings, false)},
"Starting zLeaves and retrieving client help messages will not work.", lprCmd{ReadSettingsItem("lpr_command",
argSettings, false ) }, "Receipts printing will not work.",
sshCmd{ ReadSettingsItem( "ssh_command", argSettings, true)},
"All actions concerning the clients will not be possible.", netstatCmd{ReadSettingsItem("netstat_command",
argSettings, true ) }, "Detection of active zLeaf connections will not work.",
tasksetCmd{ ReadSettingsItem( "taskset_command", argSettings, true)},
"Running z-Leaves or z-Tree will be possible.", netwBrdAddr{ReadSettingsItem("network_broadcast_address",
argSettings, true ) }, "Booting the clients will not work.",
termEmulCmd{ ReadSettingsItem( "terminal_emulator_command", argSettings, false)},
"Conducting administrative tasks will not be possible.", orseeUrl{ReadSettingsItem("orsee_url",
argSettings, true ) }, "Opening ORSEE in a browser will not work.",
userNameOnClients{ ReadSettingsItem( "user_name_on_clients", argSettings, false)},
"All actions concerning the clients performed by the experiment user will not work.", pingCmd{ReadSettingsItem("ping_command",
argSettings, false ) }, "Status updates for the clients will not work.",
vncViewer{ ReadSettingsItem( "vnc_viewer", argSettings, true)},
"Viewing the clients' screens will not work.", postscriptViewer{ReadSettingsItem("postscript_viewer",
argSettings, true ) }, "Viewing the generated receipts postscript file will not work.",
wakeonlanCmd{ ReadSettingsItem( "wakeonlan_command", argSettings, true)},
"Booting the clients will not work.", ps2pdfCmd{ReadSettingsItem("ps2pdf_command",
argSettings, true ) }, "Converting and viewing the generated receipts file will not work.",
webcamDisplayCmd{ ReadSettingsItem( "webcam_command", argSettings, true)},
"Displaying the laboratory's webcams will not work.", pkeyPathRoot{ReadSettingsItem("pkey_path_root",
argSettings, true ) }, "Administration actions concerning the clients will not be available.",
webcams{ argSettings.value( "webcams", "" ).toString().split( '|', QString::SkipEmptyParts, argSettings, true)},
Qt::CaseInsensitive ) }, pkeyPathUser{ReadSettingsItem("pkey_path_user",
webcams_names{ argSettings.value( "webcams_names", "" ).toString().split( '|', QString::SkipEmptyParts, "Many actions concerning the clients will not be available.",
Qt::CaseInsensitive ) }, argSettings, true)},
wineCmd{ ReadSettingsItem( "wine_command", rmCmd{ReadSettingsItem("rm_command",
"Running z-Leaves or z-Tree will be possible.", "Cleanup of the zTree data target path will not work.",
argSettings, true ) }, argSettings, true)},
wmctrlCmd{ ReadSettingsItem( "wmctrl_command", scpCmd{ReadSettingsItem("scp_command",
"Setting zTree's window title to its port number will not work.", "Beaming files to the clients will not be possible.",
argSettings, true ) }, argSettings, true)},
xsetCmd{ ReadSettingsItem( "xset_command", serverIP{ReadSettingsItem("server_ip",
"Deactivating the screen saver on the clients will not be possible.", "Starting zLeaves and retrieving client help messages will not work.",
argSettings, true ) }, argSettings, false)},
zTreeInstDir{ ReadSettingsItem( "ztree_installation_directory", sshCmd{ReadSettingsItem("ssh_command",
"zTree will not be available.", "All actions concerning the clients will not be possible.",
argSettings, true ) }, argSettings, true)},
restartCrashedSessionScript{ ReadSettingsItem( "restart_crashed_session_script", tasksetCmd{ReadSettingsItem("taskset_command",
"Script to be called after session crash", "Running z-Leaves or z-Tree will be possible.",
argSettings, false ) }, argSettings, true)},
adminUsers{ GetAdminUsers( argSettings ) }, termEmulCmd{ReadSettingsItem("terminal_emulator_command",
installedLaTeXHeaders{ DetectInstalledLaTeXHeaders() }, "Conducting administrative tasks will not be possible.",
installedZTreeVersions{ DetectInstalledzTreeVersions() }, argSettings, true)},
clientHelpNotificationServerPort{ GetClientHelpNotificationServerPort( argSettings ) }, userNameOnClients{ReadSettingsItem("user_name_on_clients",
chosenzTreePort{ GetInitialPort( argSettings ) }, "All actions concerning the clients performed by the experiment user will not work.",
clients{ CreateClients( argSettings, pingCmd ) }, argSettings, false)},
localzLeafName{ ReadSettingsItem( "local_zLeaf_name", vncViewer{ReadSettingsItem("vnc_viewer",
"The local zLeaf default name will default to 'local'.", "Viewing the clients' screens will not work.",
argSettings, false ) }, argSettings, true)},
clIPsToClMap{ CreateClIPsToClMap( clients ) } wakeonlanCmd{ReadSettingsItem("wakeonlan_command",
"Booting the clients will not work.",
argSettings, true)},
webcamDisplayCmd{ReadSettingsItem("webcam_command",
"Displaying the laboratory's webcams will not work.",
argSettings, true)},
webcams{argSettings.value("webcams", "").toString().split('|', QString::SkipEmptyParts,
Qt::CaseInsensitive)},
webcams_names{argSettings.value("webcams_names", "").toString().split('|', QString::SkipEmptyParts,
Qt::CaseInsensitive)},
wineCmd{ReadSettingsItem("wine_command",
"Running z-Leaves or z-Tree will be possible.",
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)},
restartCrashedSessionScript{ReadSettingsItem("restart_crashed_session_script",
"Script to be called after session crash",
argSettings, false)},
adminUsers{GetAdminUsers(argSettings ) },
installedLaTeXHeaders{DetectInstalledLaTeXHeaders()},
installedZTreeVersions{DetectInstalledzTreeVersions()},
clientHelpNotificationServerPort{GetClientHelpNotificationServerPort(argSettings)},
chosenzTreePort{GetInitialPort(argSettings)},
clients{CreateClients(argSettings, pingCmd)},
localzLeafName{ReadSettingsItem("local_zLeaf_name",
"The local zLeaf default name will default to 'local'.",
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()) {
qDebug() << "'local_zLeaf_name' was not set, defaulting to 'local'"; qDebug() << "'local_zLeaf_name' was not set, defaulting to 'local'";
localzLeafName = "local"; localzLeafName = "local";
} }
if ( webcams.isEmpty() ) { if (webcams.isEmpty()) {
qDebug() << "'webcams' was not properly set. No stationary webcams will be available."; qDebug() << "'webcams' was not properly set. No stationary webcams will be available.";
} else { } else {
qDebug() << "The following webcams where loaded:" << webcams; qDebug() << "The following webcams where loaded:" << webcams;
@ -153,15 +153,17 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
qDebug() << "Detected z-Tree versions" << installedZTreeVersions; qDebug() << "Detected z-Tree versions" << installedZTreeVersions;
} }
lc::Settings::~Settings() { lc::Settings::~Settings()
for ( QVector< Client* >::iterator it = clients.begin(); it != clients.end(); ++it ) { {
for (QVector<Client *>::iterator it = clients.begin(); it != clients.end(); ++it) {
delete *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)) {
qDebug() << "The path" << argPath << "specified by" << argVariableName qDebug() << "The path" << argPath << "specified by" << argVariableName
<< "does not exist:" << argMessage; << "does not exist:" << argMessage;
return false; return false;
@ -170,89 +172,92 @@ bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &
return true; return true;
} }
QVector< lc::Client* > lc::Settings::CreateClients( const QSettings &argSettings, QVector<lc::Client *> lc::Settings::CreateClients(const QSettings &argSettings,
const QString &argPingCmd ) { const QString &argPingCmd)
QVector< Client* > tempClientVec; {
QVector<Client *> tempClientVec;
// Get the client quantity to check the value lists for clients creation for correct length // Get the client quantity to check the value lists for clients creation for correct length
int clientQuantity = 0; int clientQuantity = 0;
if ( !argSettings.contains("client_quantity" ) ) { if (!argSettings.contains("client_quantity")) {
qWarning() << "'client_quantity' was not set. The client quantity will be guessed" qWarning() << "'client_quantity' was not set. The client quantity will be guessed"
" by the amount of client IPs set in 'client_ips'."; " by the amount of client IPs set in 'client_ips'.";
clientQuantity = argSettings.value( "client_ips", "" ).toString() clientQuantity = argSettings.value("client_ips", "").toString()
.split( '/', QString::SkipEmptyParts, Qt::CaseSensitive ).length(); .split('/', QString::SkipEmptyParts, Qt::CaseSensitive).length();
qDebug() << "'clientQuantity':" << clientQuantity; qDebug() << "'clientQuantity':" << clientQuantity;
} else { } else {
bool ok = true; bool ok = true;
clientQuantity = argSettings.value( "client_quantity" ).toInt( &ok ); clientQuantity = argSettings.value("client_quantity").toInt(&ok);
if ( !ok ) { if (!ok) {
qWarning() << "The variable 'client_quantity' was not convertible to int"; qWarning() << "The variable 'client_quantity' was not convertible to int";
} }
qDebug() << "'clientQuantity':" << clientQuantity; qDebug() << "'clientQuantity':" << clientQuantity;
} }
// Create all the clients in the lab // Create all the clients in the lab
QStringList clientIPs = argSettings.value( "client_ips" ).toString() QStringList clientIPs = argSettings.value("client_ips").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive ); .split('|', QString::SkipEmptyParts, Qt::CaseSensitive);
if ( clientIPs.length() != clientQuantity ) { if ( clientIPs.length() != clientQuantity) {
qWarning() << "The quantity of client ips does not match the client quantity. Client" qWarning() << "The quantity of client ips does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction."; " creation will fail. No clients will be available for interaction.";
return tempClientVec; return tempClientVec;
} }
qDebug() << "Client IPs:" << clientIPs.join( " / " ); qDebug() << "Client IPs:" << clientIPs.join( " / " );
QStringList clientMACs = argSettings.value( "client_macs" ).toString() QStringList clientMACs = argSettings.value("client_macs").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive ); .split('|', QString::SkipEmptyParts, Qt::CaseSensitive);
if ( clientMACs.length() != clientQuantity ) { if (clientMACs.length() != clientQuantity) {
qWarning() << "The quantity of client macs does not match the client quantity. Client" qWarning() << "The quantity of client macs does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction."; " creation will fail. No clients will be available for interaction.";
return tempClientVec; return tempClientVec;
} }
qDebug() << "Client MACs:" << clientMACs.join( " / " ); qDebug() << "Client MACs:" << clientMACs.join( " / " );
QStringList clientNames = argSettings.value( "client_names" ).toString() QStringList clientNames = argSettings.value("client_names").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive ); .split('|', QString::SkipEmptyParts, Qt::CaseSensitive);
if ( clientNames.length() != clientQuantity ) { if (clientNames.length() != clientQuantity) {
qWarning() << "The quantity of client names does not match the client quantity. Client" qWarning() << "The quantity of client names does not match the client quantity. Client"
" creation will fail. No clients will be available for interaction."; " creation will fail. No clients will be available for interaction.";
return tempClientVec; return tempClientVec;
} }
qDebug() << "Client names:" << clientNames.join( " / " ); qDebug() << "Client names:" << clientNames.join( " / " );
QStringList clientXPositions = argSettings.value( "client_xpos" ).toString() QStringList clientXPositions = argSettings.value("client_xpos").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive ); .split('|', QString::SkipEmptyParts, Qt::CaseSensitive);
if ( clientXPositions.length() != clientQuantity ) { if (clientXPositions.length() != clientQuantity) {
qWarning() << "The quantity of client x positions does not match the client quantity." qWarning() << "The quantity of client x positions does not match the client quantity."
" Client creation will fail. No clients will be available for interaction."; " Client creation will fail. No clients will be available for interaction.";
return tempClientVec; return tempClientVec;
} }
qDebug() << "clientXPositions:" << clientXPositions.join( " / " ); qDebug() << "clientXPositions:" << clientXPositions.join( " / " );
QStringList clientYPositions = argSettings.value( "client_ypos" ).toString() QStringList clientYPositions = argSettings.value("client_ypos").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseSensitive ); .split('|', QString::SkipEmptyParts, Qt::CaseSensitive);
if ( clientYPositions.length() != clientQuantity ) { if (clientYPositions.length() != clientQuantity) {
qWarning() << "The quantity of client y positions does not match the client quantity." qWarning() << "The quantity of client y positions does not match the client quantity."
" Client creation will fail. No clients will be available for interaction."; " Client creation will fail. No clients will be available for interaction.";
return tempClientVec; return tempClientVec;
} }
qDebug() << "clientYPositions:" << clientYPositions.join( " / " ); qDebug() << "clientYPositions:" << clientYPositions.join(" / ");
for ( int i = 0; i < clientQuantity; i++ ) { for (int i = 0; i < clientQuantity; i++) {
tempClientVec.append( new Client{ clientIPs[ i ], clientMACs[ i ], clientNames[ i ], tempClientVec.append(new Client{clientIPs[i], clientMACs[i], clientNames[i],
clientXPositions[ i ].toUShort(), clientXPositions[i].toUShort(),
clientYPositions[ i ].toUShort(), argPingCmd } ); clientYPositions[i].toUShort(), argPingCmd});
} }
return tempClientVec; return tempClientVec;
} }
QMap< QString, lc::Client* > lc::Settings::CreateClIPsToClMap( const QVector< Client* > &argClients ) { QMap< QString, lc::Client * > lc::Settings::CreateClIPsToClMap(const QVector<Client *>
QMap< QString, Client* > tempMap; &argClients)
for ( const auto &s : argClients ) { {
tempMap.insert( s->ip, s ); 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 // Get the address of the Client instance in RAM for display
const void *clientPtrAddr = static_cast< const void* >( tempMap[ s->ip ] ); const void *clientPtrAddr = static_cast<const void *>(tempMap[s->ip]);
qDebug() << "Added" << s->name qDebug() << "Added" << s->name
<< "to 'clientIPsToClientsMap':" << clientPtrAddr; << "to 'clientIPsToClientsMap':" << clientPtrAddr;
@ -260,63 +265,67 @@ QMap< QString, lc::Client* > lc::Settings::CreateClIPsToClMap( const QVector< Cl
return tempMap; 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
if ( !lcDataDir.isEmpty() ) { if (!lcDataDir.isEmpty()) {
QDir laTeXDirectory{ lcDataDir, "*_header.tex", QDir::Name, QDir laTeXDirectory{lcDataDir, "*_header.tex", QDir::Name,
QDir::CaseSensitive | QDir::Files | QDir::Readable }; QDir::CaseSensitive | QDir::Files | QDir::Readable};
if ( !laTeXDirectory.exists() || laTeXDirectory.entryList().isEmpty() ) { if (!laTeXDirectory.exists() || laTeXDirectory.entryList().isEmpty()) {
qDebug() << "Receipts printing will not work. No LaTeX headers could be found in" qDebug() << "Receipts printing will not work. No LaTeX headers could be found in"
<< lcDataDir; << lcDataDir;
} else { } else {
tempLaTeXHeaders = laTeXDirectory.entryList(); tempLaTeXHeaders = laTeXDirectory.entryList();
tempLaTeXHeaders.replaceInStrings( "_header.tex", "" ); tempLaTeXHeaders.replaceInStrings("_header.tex", "");
qDebug() << "LaTeX headers:" << tempLaTeXHeaders.join( " / " ); qDebug() << "LaTeX headers:" << tempLaTeXHeaders.join(" / ");
} }
} }
return tempLaTeXHeaders; return tempLaTeXHeaders;
} }
QStringList lc::Settings::DetectInstalledzTreeVersions() const { QStringList lc::Settings::DetectInstalledzTreeVersions() const
{
QStringList tempInstzTreeVersions; QStringList tempInstzTreeVersions;
if ( !zTreeInstDir.isEmpty() ) { if (!zTreeInstDir.isEmpty()) {
QDir zTreeDirectory{ zTreeInstDir, "zTree_*", QDir::Name, QDir zTreeDirectory{zTreeInstDir, "zTree_*", QDir::Name,
QDir::NoDotAndDotDot | QDir::Dirs QDir::NoDotAndDotDot | QDir::Dirs
| QDir::Readable | QDir::CaseSensitive }; | QDir::Readable | QDir::CaseSensitive};
if ( zTreeDirectory.entryList().isEmpty() ) { if (zTreeDirectory.entryList().isEmpty()) {
qWarning() << "No zTree versions could be found in" << zTreeInstDir; qWarning() << "No zTree versions could be found in" << zTreeInstDir;
} else { } else {
tempInstzTreeVersions = zTreeDirectory.entryList(); tempInstzTreeVersions = zTreeDirectory.entryList();
tempInstzTreeVersions.replaceInStrings( "zTree_", "" ); tempInstzTreeVersions.replaceInStrings("zTree_", "");
} }
} }
return tempInstzTreeVersions; return tempInstzTreeVersions;
} }
QStringList lc::Settings::GetAdminUsers( const QSettings &argSettings ) { QStringList lc::Settings::GetAdminUsers(const QSettings &argSettings)
{
// Read the list of users with administrative rights // Read the list of users with administrative rights
if ( !argSettings.contains( "admin_users" ) ) { if (!argSettings.contains("admin_users")) {
qDebug() << "The 'admin_users' variable was not set." qDebug() << "The 'admin_users' variable was not set."
" No users will be able to conduct administrative tasks."; " No users will be able to conduct administrative tasks.";
return QStringList{}; return QStringList{};
} else { } else {
QStringList adminUsers{ argSettings.value( "admin_users", "" ).toString() QStringList adminUsers{argSettings.value("admin_users", "").toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseInsensitive ) }; .split('|', QString::SkipEmptyParts, Qt::CaseInsensitive)};
qDebug() << "'adminUsers':" << adminUsers.join( " / " ); qDebug() << "'adminUsers':" << adminUsers.join(" / ");
return adminUsers; return adminUsers;
} }
return QStringList{}; return QStringList{};
} }
quint16 lc::Settings::GetClientHelpNotificationServerPort( const QSettings &argSettings ) { quint16 lc::Settings::GetClientHelpNotificationServerPort(const QSettings &argSettings)
{
// Read the port the ClientHelpNotificationServer shall listen on // Read the port the ClientHelpNotificationServer shall listen on
quint16 clientHelpNotificationServerPort = argSettings.value( "client_help_server_port", quint16 clientHelpNotificationServerPort = argSettings.value("client_help_server_port",
0 ).toUInt(); 0).toUInt();
if ( !clientHelpNotificationServerPort ) { if (!clientHelpNotificationServerPort) {
qDebug() << "The 'client_help_server_port' variable was not set or set to zero." qDebug() << "The 'client_help_server_port' variable was not set or set to zero."
" The ClientHelpNotificationServer will be deactivated therefore." " The ClientHelpNotificationServer will be deactivated therefore."
" Clients' help requests will be ignored by the server."; " Clients' help requests will be ignored by the server.";
return 0; return 0;
} else { } else {
qDebug() << "'clientHelpNotificationServerPort':" << clientHelpNotificationServerPort; qDebug() << "'clientHelpNotificationServerPort':" << clientHelpNotificationServerPort;
@ -325,37 +334,40 @@ quint16 lc::Settings::GetClientHelpNotificationServerPort( const QSettings &argS
return 0; return 0;
} }
int lc::Settings::GetDefaultReceiptIndex( const QSettings &argSettings ) { int lc::Settings::GetDefaultReceiptIndex( const QSettings &argSettings )
{
// Read the default receipt index for the 'CBReceipts' combobox // Read the default receipt index for the 'CBReceipts' combobox
if ( !argSettings.contains( "default_receipt_index" ) ) { if (!argSettings.contains("default_receipt_index")) {
qDebug() << "'default_receipt_index' was not set. It will default to '0'."; qDebug() << "'default_receipt_index' was not set. It will default to '0'.";
return 0; return 0;
} }
int tempIndex = argSettings.value( "default_receipt_index", 0 ).toInt(); int tempIndex = argSettings.value("default_receipt_index", 0).toInt();
qDebug() << "'defaultReceiptIndex':" << tempIndex; qDebug() << "'defaultReceiptIndex':" << tempIndex;
return tempIndex; return tempIndex;
} }
int lc::Settings::GetInitialPort( const QSettings &argSettings ) { int lc::Settings::GetInitialPort( const QSettings &argSettings )
{
// Read the initial port number // Read the initial port number
if ( !argSettings.contains( "initial_port" ) ) { if (!argSettings.contains("initial_port")) {
qDebug() << "The 'initial_port' variable was not set." qDebug() << "The 'initial_port' variable was not set."
" Labcontrol will default to port 7000 for new zTree instances."; " Labcontrol will default to port 7000 for new zTree instances.";
} }
int initialPort = argSettings.value( "initial_port", 7000 ).toInt(); int initialPort = argSettings.value("initial_port", 7000).toInt();
qDebug() << "'initial_port':" << initialPort; qDebug() << "'initial_port':" << initialPort;
return initialPort; return initialPort;
} }
QString lc::Settings::GetLocalUserName() { QString lc::Settings::GetLocalUserName()
const QProcessEnvironment env{ QProcessEnvironment::systemEnvironment() }; {
const QProcessEnvironment env{QProcessEnvironment::systemEnvironment()};
QString userName; QString userName;
// For Linux // For Linux
if ( env.contains( "USER" ) ) { if ( env.contains("USER")) {
userName = env.value( "USER", "" ); userName = env.value("USER", "");
qDebug() << "The local user name is" << userName; qDebug() << "The local user name is" << userName;
} else if ( env.contains( "USERNAME" ) ) { // For Windows } else if (env.contains("USERNAME")) { // For Windows
userName = env.value( "USERNAME", "" ); userName = env.value("USERNAME", "");
qDebug() << "The local user name is" << userName; qDebug() << "The local user name is" << userName;
} else { } else {
qWarning() << "The local user name could not be queried"; qWarning() << "The local user name could not be queried";
@ -363,17 +375,18 @@ QString lc::Settings::GetLocalUserName() {
return userName; return userName;
} }
QString lc::Settings::ReadSettingsItem( const QString &argVariableName, QString lc::Settings::ReadSettingsItem(const QString &argVariableName,
const QString &argMessage, const QString &argMessage,
const QSettings &argSettings, const QSettings &argSettings,
bool argItemIsFile) { bool argItemIsFile)
if ( !argSettings.contains( argVariableName ) ) { {
if (!argSettings.contains(argVariableName)) {
qDebug() << argVariableName << "was not set." << argMessage; qDebug() << argVariableName << "was not set." << argMessage;
return QString{}; return QString{};
} else { } else {
QString tempString{ argSettings.value( argVariableName ).toString() }; QString tempString{argSettings.value(argVariableName).toString()};
if ( argItemIsFile if (argItemIsFile
&& !CheckPathAndComplain( tempString, argVariableName, argMessage ) ) { && !CheckPathAndComplain(tempString, argVariableName, argMessage)) {
tempString.clear(); tempString.clear();
} }
return tempString; return tempString;
@ -381,11 +394,12 @@ QString lc::Settings::ReadSettingsItem( const QString &argVariableName,
return QString{}; return QString{};
} }
void lc::Settings::SetLocalzLeafSize( QString arg) { void lc::Settings::SetLocalzLeafSize(QString arg)
{
localzLeafSize = arg; localzLeafSize = arg;
} }
void lc::Settings::SetChosenZTreePort( const int argPort ){ void lc::Settings::SetChosenZTreePort(const int argPort)
{
chosenzTreePort = argPort; chosenzTreePort = argPort;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2016 Markus Prasser * Copyright 2014-2018 Markus Prasser, Tobias Weiss
* *
* This file is part of Labcontrol. * This file is part of Labcontrol.
* *
@ -28,23 +28,30 @@
namespace lc { namespace lc {
class Settings : public QObject { class Settings : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
Settings() = delete; Settings() = delete;
explicit Settings( const QSettings &argSettings, QObject *argParent = nullptr ); explicit Settings(const QSettings &argSettings, QObject *argParent = nullptr);
Settings( const Settings &argSettings ) = delete; Settings(const Settings &argSettings) = delete;
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(); ~Settings();
int GetChosenZTreePort() const { return chosenzTreePort; } int GetChosenZTreePort() const
QVector< Client* > &GetClients() { return clients; } {
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);
const int defaultReceiptIndex = 0; const int defaultReceiptIndex = 0;
const QString browserCmd; const QString browserCmd;
@ -56,8 +63,11 @@ public:
const QString lcDataDir; const QString lcDataDir;
const QString localUserName; const QString localUserName;
QString localzLeafSize; QString localzLeafSize;
void SetLocalzLeafSize( QString arg); void SetLocalzLeafSize(QString arg);
QString GetLocalzLeafSize() const { return localzLeafSize; } QString GetLocalzLeafSize() const
{
return localzLeafSize;
}
const QString lprCmd; const QString lprCmd;
const QString netstatCmd; const QString netstatCmd;
const QString netwBrdAddr; const QString netwBrdAddr;
@ -90,38 +100,41 @@ public:
const quint16 clientHelpNotificationServerPort = 0; const quint16 clientHelpNotificationServerPort = 0;
private: private:
static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName, static bool CheckPathAndComplain(const QString &argPath,
const QString &argMessage ); const QString &argVariableName,
static QVector< Client* > CreateClients( const QSettings &argSettings, const QString &argMessage);
const QString &argPingCmd ); static QVector<Client *> CreateClients(const QSettings &argSettings,
static QMap< QString, Client* > CreateClIPsToClMap( const QVector< Client* > &argClients ); 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);
static quint16 GetClientHelpNotificationServerPort( const QSettings &argSettings ); static quint16 GetClientHelpNotificationServerPort(const QSettings &argSettings);
static int GetDefaultReceiptIndex( const QSettings &argSettings ); static int GetDefaultReceiptIndex(const QSettings &argSettings);
static int GetInitialPort( const QSettings &argSettings ); static int GetInitialPort(const QSettings &argSettings);
static QString GetLocalUserName(); static QString GetLocalUserName();
static QString ReadSettingsItem( const QString &argVariableName, static QString ReadSettingsItem(const QString &argVariableName,
const QString &argMessage, const QString &argMessage,
const QSettings &argSettings, const QSettings &argSettings,
bool argItemIsFile ); bool argItemIsFile);
int chosenzTreePort = 0; int chosenzTreePort = 0;
QVector< Client* > clients; QVector< Client * > clients;
QString localzLeafName; QString localzLeafName;
public: public:
const QMap< QString, Client* > clIPsToClMap; const QMap<QString, Client *> clIPsToClMap;
}; };
} } // namespace lc
inline QString lc::Settings::GetLocalzLeafName() const { inline QString lc::Settings::GetLocalzLeafName() const
{
return localzLeafName; return localzLeafName;
} }
inline void lc::Settings::SetLocalzLeafName( const QString &argLocalzLeafName ) { inline void lc::Settings::SetLocalzLeafName(const QString &argLocalzLeafName)
{
localzLeafName = argLocalzLeafName; localzLeafName = argLocalzLeafName;
} }

Loading…
Cancel
Save