diff --git a/src/Lib/settings.cpp b/src/Lib/settings.cpp old mode 100755 new mode 100644 index 7214061..12fdd64 --- a/src/Lib/settings.cpp +++ b/src/Lib/settings.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 Markus Prasser + * Copyright 2014-2018 Markus Prasser, Tobias Weiss * * This file is part of Labcontrol. * @@ -25,127 +25,127 @@ #include "client.h" #include "settings.h" -lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : - QObject{ argParent }, - defaultReceiptIndex{ GetDefaultReceiptIndex( argSettings ) }, - 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", +lc::Settings::Settings(const QSettings &argSettings, QObject *argParent) : + QObject{argParent}, + defaultReceiptIndex{GetDefaultReceiptIndex(argSettings)}, + browserCmd{ReadSettingsItem("browser_command", "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 ) }, - tasksetCmd{ ReadSettingsItem( "taskset_command", - "Running z-Leaves or z-Tree will 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 ) }, - 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 ) } + 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.", + 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)}, + tasksetCmd{ReadSettingsItem("taskset_command", + "Running z-Leaves or z-Tree will 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)}, + 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 - if ( localzLeafName.isEmpty() ) { + if (localzLeafName.isEmpty()) { qDebug() << "'local_zLeaf_name' was not set, defaulting to 'local'"; localzLeafName = "local"; } - if ( webcams.isEmpty() ) { + if (webcams.isEmpty()) { qDebug() << "'webcams' was not properly set. No stationary webcams will be available."; } else { 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; } -lc::Settings::~Settings() { - for ( QVector< Client* >::iterator it = clients.begin(); it != clients.end(); ++it ) { +lc::Settings::~Settings() +{ + for (QVector::iterator it = clients.begin(); it != clients.end(); ++it) { delete *it; } } -bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &argVariableName, - const QString &argMessage ) { - if ( !QFile::exists( argPath ) ) { +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; @@ -170,89 +172,92 @@ bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString & return true; } -QVector< lc::Client* > lc::Settings::CreateClients( const QSettings &argSettings, - const QString &argPingCmd ) { - QVector< Client* > tempClientVec; +QVector lc::Settings::CreateClients(const QSettings &argSettings, + const QString &argPingCmd) +{ + QVector tempClientVec; // Get the client quantity to check the value lists for clients creation for correct length 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" - " by the amount of client IPs set in 'client_ips'."; - clientQuantity = argSettings.value( "client_ips", "" ).toString() - .split( '/', QString::SkipEmptyParts, Qt::CaseSensitive ).length(); + " 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 ) { + 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 ) { + 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."; + " 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 ) { + 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."; + " 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 ) { + 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."; + " 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 ) { + 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."; + " 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 ) { + 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."; + " Client creation will fail. No clients will be available for interaction."; return tempClientVec; } - qDebug() << "clientYPositions:" << clientYPositions.join( " / " ); + 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 } ); + 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 ); +QMap< QString, lc::Client * > lc::Settings::CreateClIPsToClMap(const QVector + &argClients) +{ + QMap 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 ] ); + const void *clientPtrAddr = static_cast(tempMap[s->ip]); qDebug() << "Added" << s->name << "to 'clientIPsToClientsMap':" << clientPtrAddr; @@ -260,63 +265,67 @@ QMap< QString, lc::Client* > lc::Settings::CreateClIPsToClMap( const QVector< Cl return tempMap; } -QStringList lc::Settings::DetectInstalledLaTeXHeaders() const { - QStringList tempLaTeXHeaders{ "None found" }; +QStringList lc::Settings::DetectInstalledLaTeXHeaders() const +{ + QStringList tempLaTeXHeaders{"None found"}; // Detect the installed LaTeX headers - if ( !lcDataDir.isEmpty() ) { - QDir laTeXDirectory{ lcDataDir, "*_header.tex", QDir::Name, - QDir::CaseSensitive | QDir::Files | QDir::Readable }; - if ( !laTeXDirectory.exists() || laTeXDirectory.entryList().isEmpty() ) { + if (!lcDataDir.isEmpty()) { + QDir laTeXDirectory{lcDataDir, "*_header.tex", QDir::Name, + QDir::CaseSensitive | QDir::Files | QDir::Readable}; + if (!laTeXDirectory.exists() || laTeXDirectory.entryList().isEmpty()) { qDebug() << "Receipts printing will not work. No LaTeX headers could be found in" << lcDataDir; } else { tempLaTeXHeaders = laTeXDirectory.entryList(); - tempLaTeXHeaders.replaceInStrings( "_header.tex", "" ); - qDebug() << "LaTeX headers:" << tempLaTeXHeaders.join( " / " ); + tempLaTeXHeaders.replaceInStrings("_header.tex", ""); + qDebug() << "LaTeX headers:" << tempLaTeXHeaders.join(" / "); } } return tempLaTeXHeaders; } -QStringList lc::Settings::DetectInstalledzTreeVersions() const { +QStringList lc::Settings::DetectInstalledzTreeVersions() const +{ QStringList tempInstzTreeVersions; - if ( !zTreeInstDir.isEmpty() ) { - QDir zTreeDirectory{ zTreeInstDir, "zTree_*", QDir::Name, - QDir::NoDotAndDotDot | QDir::Dirs - | QDir::Readable | QDir::CaseSensitive }; - if ( zTreeDirectory.entryList().isEmpty() ) { + if (!zTreeInstDir.isEmpty()) { + QDir zTreeDirectory{zTreeInstDir, "zTree_*", QDir::Name, + QDir::NoDotAndDotDot | QDir::Dirs + | QDir::Readable | QDir::CaseSensitive}; + if (zTreeDirectory.entryList().isEmpty()) { qWarning() << "No zTree versions could be found in" << zTreeInstDir; } else { tempInstzTreeVersions = zTreeDirectory.entryList(); - tempInstzTreeVersions.replaceInStrings( "zTree_", "" ); + tempInstzTreeVersions.replaceInStrings("zTree_", ""); } } return tempInstzTreeVersions; } -QStringList lc::Settings::GetAdminUsers( const QSettings &argSettings ) { +QStringList lc::Settings::GetAdminUsers(const QSettings &argSettings) +{ // 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." - " No users will be able to conduct administrative tasks."; + " No users will be able to conduct administrative tasks."; return QStringList{}; } else { - QStringList adminUsers{ argSettings.value( "admin_users", "" ).toString() - .split( '|', QString::SkipEmptyParts, Qt::CaseInsensitive ) }; - qDebug() << "'adminUsers':" << adminUsers.join( " / " ); + QStringList adminUsers{argSettings.value("admin_users", "").toString() + .split('|', QString::SkipEmptyParts, Qt::CaseInsensitive)}; + qDebug() << "'adminUsers':" << adminUsers.join(" / "); return adminUsers; } return QStringList{}; } -quint16 lc::Settings::GetClientHelpNotificationServerPort( const QSettings &argSettings ) { +quint16 lc::Settings::GetClientHelpNotificationServerPort(const QSettings &argSettings) +{ // Read the port the ClientHelpNotificationServer shall listen on - quint16 clientHelpNotificationServerPort = argSettings.value( "client_help_server_port", - 0 ).toUInt(); - if ( !clientHelpNotificationServerPort ) { + quint16 clientHelpNotificationServerPort = argSettings.value("client_help_server_port", + 0).toUInt(); + if (!clientHelpNotificationServerPort) { qDebug() << "The 'client_help_server_port' variable was not set or set to zero." - " The ClientHelpNotificationServer will be deactivated therefore." - " Clients' help requests will be ignored by the server."; + " The ClientHelpNotificationServer will be deactivated therefore." + " Clients' help requests will be ignored by the server."; return 0; } else { qDebug() << "'clientHelpNotificationServerPort':" << clientHelpNotificationServerPort; @@ -325,37 +334,40 @@ quint16 lc::Settings::GetClientHelpNotificationServerPort( const QSettings &argS 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 - if ( !argSettings.contains( "default_receipt_index" ) ) { + if (!argSettings.contains("default_receipt_index")) { qDebug() << "'default_receipt_index' was not set. It will default to '0'."; return 0; } - int tempIndex = argSettings.value( "default_receipt_index", 0 ).toInt(); + int tempIndex = argSettings.value("default_receipt_index", 0).toInt(); qDebug() << "'defaultReceiptIndex':" << tempIndex; return tempIndex; } -int lc::Settings::GetInitialPort( const QSettings &argSettings ) { +int lc::Settings::GetInitialPort( const QSettings &argSettings ) +{ // Read the initial port number - if ( !argSettings.contains( "initial_port" ) ) { + if (!argSettings.contains("initial_port")) { 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; return initialPort; } -QString lc::Settings::GetLocalUserName() { - const QProcessEnvironment env{ QProcessEnvironment::systemEnvironment() }; +QString lc::Settings::GetLocalUserName() +{ + const QProcessEnvironment env{QProcessEnvironment::systemEnvironment()}; QString userName; // For Linux - if ( env.contains( "USER" ) ) { - userName = env.value( "USER", "" ); + if ( env.contains("USER")) { + userName = env.value("USER", ""); qDebug() << "The local user name is" << userName; - } else if ( env.contains( "USERNAME" ) ) { // For Windows - userName = env.value( "USERNAME", "" ); + } else if (env.contains("USERNAME")) { // For Windows + userName = env.value("USERNAME", ""); qDebug() << "The local user name is" << userName; } else { qWarning() << "The local user name could not be queried"; @@ -363,17 +375,18 @@ QString lc::Settings::GetLocalUserName() { return userName; } -QString lc::Settings::ReadSettingsItem( const QString &argVariableName, - const QString &argMessage, - const QSettings &argSettings, - bool argItemIsFile) { - if ( !argSettings.contains( argVariableName ) ) { +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 ) ) { + QString tempString{argSettings.value(argVariableName).toString()}; + if (argItemIsFile + && !CheckPathAndComplain(tempString, argVariableName, argMessage)) { tempString.clear(); } return tempString; @@ -381,11 +394,12 @@ QString lc::Settings::ReadSettingsItem( const QString &argVariableName, return QString{}; } -void lc::Settings::SetLocalzLeafSize( QString arg) { +void lc::Settings::SetLocalzLeafSize(QString arg) +{ localzLeafSize = arg; } -void lc::Settings::SetChosenZTreePort( const int argPort ){ +void lc::Settings::SetChosenZTreePort(const int argPort) +{ chosenzTreePort = argPort; } - diff --git a/src/Lib/settings.h b/src/Lib/settings.h old mode 100755 new mode 100644 index 685f66b..838313a --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 Markus Prasser + * Copyright 2014-2018 Markus Prasser, Tobias Weiss * * This file is part of Labcontrol. * @@ -28,23 +28,30 @@ namespace lc { -class Settings : public QObject { +class Settings : public QObject +{ Q_OBJECT public: Settings() = delete; - explicit Settings( const QSettings &argSettings, QObject *argParent = nullptr ); - Settings( const Settings &argSettings ) = delete; - Settings& operator=( const Settings &argSettings ) = delete; - Settings( Settings &&argSettings ) = delete; - Settings& operator=( Settings &&argSettings ) = delete; + explicit Settings(const QSettings &argSettings, QObject *argParent = nullptr); + Settings(const Settings &argSettings) = delete; + Settings &operator=(const Settings &argSettings) = delete; + Settings(Settings &&argSettings ) = delete; + Settings &operator=(Settings &&argSettings) = delete; ~Settings(); - int GetChosenZTreePort() const { return chosenzTreePort; } - QVector< Client* > &GetClients() { return clients; } + int GetChosenZTreePort() const + { + return chosenzTreePort; + } + QVector< Client * > &GetClients() + { + return clients; + } QString GetLocalzLeafName() const; - void SetChosenZTreePort( const int argPort ); - void SetLocalzLeafName( const QString &argLocalzLeafName ); + void SetChosenZTreePort(const int argPort); + void SetLocalzLeafName(const QString &argLocalzLeafName); const int defaultReceiptIndex = 0; const QString browserCmd; @@ -56,8 +63,11 @@ public: const QString lcDataDir; const QString localUserName; QString localzLeafSize; - void SetLocalzLeafSize( QString arg); - QString GetLocalzLeafSize() const { return localzLeafSize; } + void SetLocalzLeafSize(QString arg); + QString GetLocalzLeafSize() const + { + return localzLeafSize; + } const QString lprCmd; const QString netstatCmd; const QString netwBrdAddr; @@ -90,38 +100,41 @@ public: const quint16 clientHelpNotificationServerPort = 0; private: - static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName, - const QString &argMessage ); - static QVector< Client* > CreateClients( const QSettings &argSettings, - const QString &argPingCmd ); - static QMap< QString, Client* > CreateClIPsToClMap( const QVector< Client* > &argClients ); + static bool CheckPathAndComplain(const QString &argPath, + const QString &argVariableName, + const QString &argMessage); + static QVector CreateClients(const QSettings &argSettings, + const QString &argPingCmd); + static QMap CreateClIPsToClMap(const QVector &argClients); QStringList DetectInstalledLaTeXHeaders() const; QStringList DetectInstalledzTreeVersions() const; - static QStringList GetAdminUsers( const QSettings &argSettings ); - static quint16 GetClientHelpNotificationServerPort( const QSettings &argSettings ); - static int GetDefaultReceiptIndex( const QSettings &argSettings ); - static int GetInitialPort( const QSettings &argSettings ); + static QStringList GetAdminUsers(const QSettings &argSettings); + static quint16 GetClientHelpNotificationServerPort(const QSettings &argSettings); + static int GetDefaultReceiptIndex(const QSettings &argSettings); + static int GetInitialPort(const QSettings &argSettings); static QString GetLocalUserName(); - static QString ReadSettingsItem( const QString &argVariableName, - const QString &argMessage, - const QSettings &argSettings, - bool argItemIsFile ); + static QString ReadSettingsItem(const QString &argVariableName, + const QString &argMessage, + const QSettings &argSettings, + bool argItemIsFile); int chosenzTreePort = 0; - QVector< Client* > clients; + QVector< Client * > clients; QString localzLeafName; public: - const QMap< QString, Client* > clIPsToClMap; + const QMap clIPsToClMap; }; -} +} // namespace lc -inline QString lc::Settings::GetLocalzLeafName() const { +inline QString lc::Settings::GetLocalzLeafName() const +{ return localzLeafName; } -inline void lc::Settings::SetLocalzLeafName( const QString &argLocalzLeafName ) { +inline void lc::Settings::SetLocalzLeafName(const QString &argLocalzLeafName) +{ localzLeafName = argLocalzLeafName; }