From 598e68855a58a877dd0c27d23e3c0d63a563e5bf Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 7 Oct 2016 23:18:12 +0200 Subject: [PATCH] Made starting and killing of z-Leaves independent of installed scripts --- data/Labcontrol.conf | 2 + data/scripts/kill_zLeaf_labcontrol2.sh | 3 -- data/scripts/start_zLeaf_labcontrol2.sh | 15 ------- src/Lib/client.cpp | 56 +++++++++++++++---------- src/Lib/client.h | 16 +++---- src/Lib/settings.cpp | 3 ++ src/Lib/settings.h | 1 + src/mainwindow.cpp | 25 ++++++----- 8 files changed, 59 insertions(+), 62 deletions(-) delete mode 100644 data/scripts/kill_zLeaf_labcontrol2.sh delete mode 100644 data/scripts/start_zLeaf_labcontrol2.sh diff --git a/data/Labcontrol.conf b/data/Labcontrol.conf index 746fc0a..2fdcc83 100644 --- a/data/Labcontrol.conf +++ b/data/Labcontrol.conf @@ -22,6 +22,8 @@ dvips_command=/usr/bin/dvips file_manager=/usr/bin/dolphin # The port which shall be used by zTree by default initial_port=8000 +# The command used to kill 'zleaf.exe' instances (part of the 'psmisc' package) +killall_command=/usr/bin/killall # Where all Labcontrol data got installed labcontrol_installation_directory=/usr/local/share/labcontrol latex_command=/usr/bin/latex diff --git a/data/scripts/kill_zLeaf_labcontrol2.sh b/data/scripts/kill_zLeaf_labcontrol2.sh deleted file mode 100644 index 598407e..0000000 --- a/data/scripts/kill_zLeaf_labcontrol2.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -/usr/bin/killall -I -q zleaf.exe diff --git a/data/scripts/start_zLeaf_labcontrol2.sh b/data/scripts/start_zLeaf_labcontrol2.sh deleted file mode 100644 index e2ea4c2..0000000 --- a/data/scripts/start_zLeaf_labcontrol2.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# Start a zLeaf with the given arguments -if [ $# == 2 ]; then - DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 & - exit -fi -if [ $# == 3 ]; then - DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 /channel $3 & - exit -fi -if [ $# == 4 ]; then - DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 /channel $3 /name $4 & - exit -fi diff --git a/src/Lib/client.cpp b/src/Lib/client.cpp index 6fbce98..b4bef5b 100644 --- a/src/Lib/client.cpp +++ b/src/Lib/client.cpp @@ -138,11 +138,11 @@ void lc::Client::GotStatusChanged( state_t argState ) { qDebug() << name << "status changed to:" << static_cast< unsigned short int >( argState ); } -void lc::Client::KillZLeaf( const QString &argPublickeyPathUser, - const QString &argUserNameOnClients ) { +void lc::Client::KillZLeaf() { QStringList arguments; - arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } - << QString{ settings->lcInstDir + "/scripts/kill_zLeaf_labcontrol2.sh" }; + arguments << "-i" << settings->pkeyPathUser + << QString{ settings->userNameOnClients + "@" + ip } + << settings->killallCmd << "-I" << "-q" << "zleaf.exe"; // Start the process QProcess killZLeafProcess; @@ -267,40 +267,51 @@ void lc::Client::Shutdown( const QString &argPublickeyPathUser, const QString &a GotStatusChanged( state_t::SHUTTING_DOWN ); } -void lc::Client::StartZLeaf( const QString &argPublickeyPathUser, - const QString &argUserNameOnClients, - const QString * const argZTreeVersion, - const QString &argServerIP, unsigned short int argPort, +void lc::Client::StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort, const QString * const argFakeName ) { if ( state < state_t::RESPONDING ) { return; } // Create a QMessageBox for user interaction if there is already a zLeaf running - QMessageBox *messageBoxRunningZLeafFound = nullptr; + std::unique_ptr< QMessageBox > messageBoxRunningZLeafFound; if ( state == state_t::ZLEAF_RUNNING ) { - messageBoxRunningZLeafFound = new QMessageBox{ QMessageBox::Warning, "Running zLeaf found", - QString{ "There is already a zLeaf running on " + name + "." }, QMessageBox::No | QMessageBox::Yes }; - messageBoxRunningZLeafFound->setInformativeText( "Do you want to start a zLeaf on client " + name + " nonetheless?" ); + messageBoxRunningZLeafFound.reset( new QMessageBox{ QMessageBox::Warning, "Running zLeaf found", + QString{ "There is already a zLeaf running on " + name + "." }, + QMessageBox::No | QMessageBox::Yes } ); + messageBoxRunningZLeafFound->setInformativeText( "Do you want to start a zLeaf on client " + + name + " nonetheless?" ); messageBoxRunningZLeafFound->setDefaultButton( QMessageBox::No ); messageBoxRunningZLeafFound->exec(); } - if ( ( messageBoxRunningZLeafFound != nullptr && messageBoxRunningZLeafFound->clickedButton() == messageBoxRunningZLeafFound->button( QMessageBox::Yes ) ) || state != state_t::ZLEAF_RUNNING ) { + if ( ( messageBoxRunningZLeafFound.get() != nullptr + && messageBoxRunningZLeafFound->clickedButton() + == messageBoxRunningZLeafFound->button( QMessageBox::Yes ) ) + || state != state_t::ZLEAF_RUNNING ) { QStringList arguments; if ( argFakeName == nullptr && argPort == 7000 ) { - arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } - << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } - << *argZTreeVersion << argServerIP; + arguments << "-i" << settings->pkeyPathUser + << QString{ settings->userNameOnClients + "@" + ip } + << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd + << QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" } + << "/server" << settings->serverIP; } else { if ( argFakeName == nullptr ) { - arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } - << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } - << *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ); + arguments << "-i" << settings->pkeyPathUser + << QString{ settings->userNameOnClients + "@" + ip } + << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd + << QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" } + << "/server" << settings->serverIP << "/channel" + << QString::number( static_cast< int >( argPort ) - 7000 ); } else { - arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip } - << "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" } - << *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ) << *argFakeName ; + arguments << "-i" << settings->pkeyPathUser + << QString{ settings->userNameOnClients + "@" + ip } + << "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd + << QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" } + << "/server" << settings->serverIP << "/channel" + << QString::number( static_cast< int >( argPort ) - 7000 ) + << "/name" << *argFakeName; } } @@ -313,5 +324,4 @@ void lc::Client::StartZLeaf( const QString &argPublickeyPathUser, // Output message via the debug messages tab qDebug() << settings->sshCmd << arguments.join( " " ); } - delete messageBoxRunningZLeafFound; } diff --git a/src/Lib/client.h b/src/Lib/client.h index 7e3a03b..f376a1a 100644 --- a/src/Lib/client.h +++ b/src/Lib/client.h @@ -89,12 +89,10 @@ public: @return The current state of the client */ state_t GetClientState() const { return state; } - //! Kills all processes 'zleaf.exe' on the client /*! - @param argPublickeyPathUser The path to the publickey for user login on the clients - @param argUserNameOnClients The name of the user on the clients - */ - void KillZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients ); + * \brief Kills all processes 'zleaf.exe' on the client + */ + void KillZLeaf(); //! Opens a file manager for the client's file system /*! @param argUserToBeUsed The name of the user on the clients @@ -120,16 +118,12 @@ public: void Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients ); //! Starts a zLeaf instance on the client /*! - @param argPublickeyPathUser The path to the publickey for user login on the clients - @param argUserNameOnClients The name of the user on the clients @param argZTreeVersion The version of zLeaf which shall be started - @param argServerIP The ip of the server which is running zTree @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) */ - void StartZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients, - const QString * const argZTreeVersion, const QString &argServerIP, - unsigned short int argPort, const QString * const argFakeName = nullptr ); + void StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort, + const QString * const argFakeName = nullptr ); private: unsigned short int protectedCycles; diff --git a/src/Lib/settings.cpp b/src/Lib/settings.cpp index a411ad1..b9282f4 100644 --- a/src/Lib/settings.cpp +++ b/src/Lib/settings.cpp @@ -16,6 +16,9 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : 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 ) }, diff --git a/src/Lib/settings.h b/src/Lib/settings.h index a075f0c..62a2952 100644 --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -23,6 +23,7 @@ public: const QString browserCmd; const QString dvipsCmd; const QString fileMngr; + const QString killallCmd; const QString latexCmd; const QString lcInstDir; const QString localUserName; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2f9857c..b8f9670 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -69,6 +69,11 @@ bool lc::MainWindow::CheckIfUserIsAdmin() { } void lc::MainWindow::DisableDisfunctionalWidgets() { + // Disable all z-Leaf killing related buttons if the 'killall' command is not available + if ( settings->killallCmd.isEmpty() ) { + ui->PBKillLocalzLeaf->setEnabled( false ); + ui->PBKillzLeaf->setEnabled( false ); + } // Disable all functions relying on the labcontrol installation directory if it is not available if ( settings->lcInstDir.isEmpty() ) { ui->CBClientNames->setEnabled( false ); @@ -331,18 +336,20 @@ void lc::MainWindow::on_PBExecute_clicked() { } void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { - QString program{ settings->lcInstDir + "/scripts/kill_zLeaf_labcontrol2.sh" }; + QString program{ settings->killallCmd }; + QStringList arguments; + arguments << "-I" << "-q" << "zleaf.exe"; // Start the process - QProcess kill_zleaf_process; + QProcess killLocalzLeafProc; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - kill_zleaf_process.setProcessEnvironment( env ); - kill_zleaf_process.startDetached( program ); + killLocalzLeafProc.setProcessEnvironment( env ); + killLocalzLeafProc.startDetached( program, arguments ); local_zLeaves_are_running = false; // Output message via the debug messages tab - qDebug() << program; + qDebug() << program << arguments; } void lc::MainWindow::on_PBKillzLeaf_clicked() { @@ -350,7 +357,7 @@ void lc::MainWindow::on_PBKillzLeaf_clicked() { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); - client->KillZLeaf( settings->pkeyPathUser, settings->userNameOnClients ); + client->KillZLeaf(); } } } @@ -439,8 +446,7 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() { for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); - client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients, - zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(), + client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(), fakeName ); } } @@ -529,8 +535,7 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() { for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() ); - client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients, - zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(), + client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(), nullptr ); } }