From 6c0c5d012b0a05d756cd1879d43dea7cc67b9ac2 Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 23 Sep 2016 23:16:23 +0200 Subject: [PATCH] Enabled starting z-Tree instances again --- Labcontrol.pro | 1 - data/Labcontrol.conf | 4 ++- data/scripts/start_zTree_labcontrol2.sh | 3 -- src/Lib/lablib.cpp | 46 ++++++++++++++++--------- src/Lib/lablib.h | 6 +++- src/Lib/settings.cpp | 6 ++++ src/Lib/settings.h | 2 ++ src/Lib/ztree.cpp | 17 ++++++--- src/mainwindow.cpp | 2 ++ src/sessionstarter.cpp | 9 +++++ src/sessionstarter.h | 6 ++++ 11 files changed, 75 insertions(+), 27 deletions(-) delete mode 100644 data/scripts/start_zTree_labcontrol2.sh diff --git a/Labcontrol.pro b/Labcontrol.pro index 851c472..ae4841b 100644 --- a/Labcontrol.pro +++ b/Labcontrol.pro @@ -51,5 +51,4 @@ OTHER_FILES += \ data/Labcontrol.conf \ data/scripts/kill_zLeaf_labcontrol2.sh \ data/scripts/start_zLeaf_labcontrol2.sh \ - data/scripts/start_zTree_labcontrol2.sh \ doc/manual.tex diff --git a/data/Labcontrol.conf b/data/Labcontrol.conf index 2ae0103..1bfa549 100644 --- a/data/Labcontrol.conf +++ b/data/Labcontrol.conf @@ -17,7 +17,7 @@ client_quantity=24 client_xpos=1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24 client_ypos=1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1 # If multiple receipts are availabe, this indicates, which one will be shown by default (the index counting from 0 following an alphabetical ordering) -default_receipt_index=1 +default_receipt_index=0 dvips_command=/usr/bin/dvips file_manager=/usr/bin/nautilus # The port which shall be used by zTree by default @@ -43,6 +43,7 @@ scp_command=/usr/bin/scp # The IP of the server running zTree server_ip=192.168.1.200 ssh_command=/usr/bin/ssh +taskset_command=/usr/bin/taskset terminal_emulator_command=/usr/bin/gnome-terminal # The name of the user of the clients which is used to conduct experiments user_name_on_clients=user @@ -50,6 +51,7 @@ vnc_viewer=/usr/bin/vinagre wakeonlan_command=/usr/bin/wakeonlan # URLs to available webcams webcams="webcam_left|webcam_right" +wine_command=/usr/bin/wine wmctrl_command=/usr/bin/wmctrl xset_command=/usr/bin/xset # The folder were all zTree versions are installed (in subfolders matching the scheme zTree_X.Y.Z) diff --git a/data/scripts/start_zTree_labcontrol2.sh b/data/scripts/start_zTree_labcontrol2.sh deleted file mode 100644 index 502a6e4..0000000 --- a/data/scripts/start_zTree_labcontrol2.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -/usr/bin/wine32 $1/$2/ztree.exe /datadir Z:/$3 /privdir Z:/$3 /gsfdir Z:/$3 /tempdir Z:/$3 /leafdir Z:/$3 /channel $4 & diff --git a/src/Lib/lablib.cpp b/src/Lib/lablib.cpp index 8f62d1e..668a4cf 100644 --- a/src/Lib/lablib.cpp +++ b/src/Lib/lablib.cpp @@ -329,37 +329,51 @@ void lc::Lablib::ShowPreprints() { debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] %1 %2" ).arg( program ).arg( arguments.join( " " ) ) ); } -void lc::Lablib::StartNewZTreeInstance() { - if ( !QDir( chosenZTreeDataTargetPath ).exists() ) { +void lc::Lablib::StartNewZTreeInstance( QString argDataTargetPath, int argPort, + QString argzTreeVersion, + bool argReceiptsForLocalClients, + QString argAnonReceiptPlaceholder, + QString argChosenLatexHeader ) { + if ( !QDir( argDataTargetPath ).exists() ) { QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target path does not exist" ), - tr( "Your chosen data target path does not exist. Do you want it to be created automatically?" ), QMessageBox::Yes | QMessageBox::No }; + tr( "Your chosen data target path does not exist." + " Do you want it to be created automatically?" ), + QMessageBox::Yes | QMessageBox::No }; messageBox.exec(); if ( messageBox.clickedButton() == messageBox.button( QMessageBox::No ) ) { - QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory will not be created" ), - tr( "Your chosen data target directory does not exist and will not be created. Please chose another one." ), QMessageBox::Ok }; + QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory will not" + " be created" ), + tr( "Your chosen data target directory does not exist and" + " will not be created. Please choose another one." ), + QMessageBox::Ok }; messageBox.exec(); return; - } - else { - if ( !QDir().mkpath( chosenZTreeDataTargetPath ) ) { - QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory could not be created" ), - tr( "Your chosen data target directory does not exist and could not be created. Please chose another one." ), QMessageBox::Ok }; + } else { + if ( !QDir().mkpath( argDataTargetPath ) ) { + QMessageBox messageBox{ QMessageBox::Critical, tr( "Data target directory could" + " not be created" ), + tr( "Your chosen data target directory does not exist" + " and could not be created. Please choose another" + " one." ), QMessageBox::Ok }; messageBox.exec(); return; } } } try { - sessionsModel->push_back( new Session{ debugMessagesTextEdit, chosenZTreeDataTargetPath, - chosenZTreePort, chosenZTreeVersion, - PrintReceiptsForLocalClients, - anonymousReceiptsPlaceholder, chosenLaTeXHeader } ); + sessionsModel->push_back( new Session{ debugMessagesTextEdit, argDataTargetPath, + argPort, argzTreeVersion, + argReceiptsForLocalClients, + argAnonReceiptPlaceholder, + argChosenLatexHeader } ); occupiedPorts->append( sessionsModel->back()->zTreePort ); } catch ( Session::lcDataTargetPathCreationFailed ) { QMessageBox::information( nullptr, tr( "Chosen data target path could not be created" ), - tr( "The path specified by your chosen data target path '%1' could not be created. Please check if it is a valid location and you have all needed permissions." ) - .arg( chosenZTreeDataTargetPath ) ); + tr( "The path specified by your chosen data target path '%1'" + " could not be created. Please check if it is a valid" + " location and you have all needed permissions." ) + .arg( argDataTargetPath ) ); } } diff --git a/src/Lib/lablib.h b/src/Lib/lablib.h index 03b862e..5d515d4 100644 --- a/src/Lib/lablib.h +++ b/src/Lib/lablib.h @@ -145,7 +145,11 @@ public: void SetUserNameOnServer( const QString &argUserName ); void ShowOrsee(); void ShowPreprints(); - void StartNewZTreeInstance(); + +public slots: + void StartNewZTreeInstance( QString argDataTargetPath, int argPort, QString argzTreeVersion, + bool argReceiptsForLocalClients, QString argAnonReceiptPlaceholder, + QString argChosenLatexHeader ); signals: void ZLEAF_RUNNING( QString argClientIP ); diff --git a/src/Lib/settings.cpp b/src/Lib/settings.cpp index 5a264a7..bc9dc0f 100644 --- a/src/Lib/settings.cpp +++ b/src/Lib/settings.cpp @@ -59,6 +59,9 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : 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 ) }, @@ -71,6 +74,9 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : wakeonlanCmd{ ReadSettingsItem( "wakeonlan_command", "Booting the clients will not work.", argSettings, true ) }, + 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 ) }, diff --git a/src/Lib/settings.h b/src/Lib/settings.h index ec08b3d..8be1b2c 100644 --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -38,10 +38,12 @@ public: const QString scpCmd; const QString serverIP; const QString sshCmd; + const QString tasksetCmd; const QString termEmulCmd; const QString userNameOnClients; const QString vncViewer; const QString wakeonlanCmd; + const QString wineCmd; const QString wmctrlCmd; const QString xsetCmd; const QString zTreeInstDir; diff --git a/src/Lib/ztree.cpp b/src/Lib/ztree.cpp index b552f7d..5bd3a12 100644 --- a/src/Lib/ztree.cpp +++ b/src/Lib/ztree.cpp @@ -27,15 +27,22 @@ extern std::unique_ptr< lc::Settings > settings; lc::ZTree::ZTree( QPlainTextEdit *argDebugMessagesTextEdit, const QString &argZTreeDataTargetPath, const int &argZTreePort, const QString &argZTreeVersionPath ) { - QString program{ settings->lcInstDir + "/scripts/start_zTree_labcontrol2.sh" }; - QStringList arguments; - arguments << settings->zTreeInstDir << argZTreeVersionPath << argZTreeDataTargetPath - << QString::number( static_cast< int >( argZTreePort ) - 7000 ); + QString program{ settings->tasksetCmd }; + QStringList arguments{ QStringList{} << "0x00000001" << settings->wineCmd + << QString{ settings->zTreeInstDir + "/zTree_" + + argZTreeVersionPath + "/ztree.exe" } + << "/datadir" << QString{ "Z:/" + argZTreeDataTargetPath } + << "/privdir" << QString{ "Z:/" + argZTreeDataTargetPath } + << "/gsfdir" << QString{ "Z:/" + argZTreeDataTargetPath } + << "/tempdir" << QString{ "Z:/" + argZTreeDataTargetPath } + << "/leafdir" << QString{ "Z:/" + argZTreeDataTargetPath } + << "/channel" << QString::number( argZTreePort - 7000 ) }; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); zTreeInstance.setProcessEnvironment( env ); zTreeInstance.startDetached( program, arguments, QDir::currentPath(), &pid ); - connect( &zTreeInstance, SIGNAL( finished( int ) ), SLOT( ZTreeInstanceClosed() ) ); + connect( &zTreeInstance, SIGNAL( finished( int ) ), + this, SLOT( ZTreeInstanceClosed() ) ); // Output message via the debug messages tab argDebugMessagesTextEdit->appendPlainText( "[DEBUG] " + program + " " + arguments.join( " " ) ); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2a2ab38..3924ea9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -557,6 +557,8 @@ void lc::MainWindow::on_PBStartzTree_clicked() { SessionStarter *sessionStarter = new SessionStarter{ lablib, ui->PTEDebugMessages, this }; sessionStarter->setWindowFlags( Qt::Window ); sessionStarter->show(); + connect( sessionStarter, &SessionStarter::SessionRequested, + lablib, &Lablib::StartNewZTreeInstance ); connect( sessionStarter, &SessionStarter::destroyed, sessionStarter, &SessionStarter::deleteLater ); // // Show an error message, if no zTree version was chosen yet diff --git a/src/sessionstarter.cpp b/src/sessionstarter.cpp index 57506e9..40dc0cc 100644 --- a/src/sessionstarter.cpp +++ b/src/sessionstarter.cpp @@ -95,6 +95,15 @@ void lc::SessionStarter::on_ChBReceiptsforLocalClients_clicked( bool checked ) { lablib->SetPrintReceiptsForLocalClients( checked ); } +void lc::SessionStarter::on_PBStartzTree_clicked() { + emit SessionRequested( ui->CBDataTargetPath->currentText(), ui->SBPort->value(), + ui->CBzTreeVersion->currentText(), + ui->ChBReceiptsforLocalClients->isChecked(), + ui->CBReplaceParticipantName->currentText(), + ui->CBReceiptsHeader->currentText() ); + close(); +} + void lc::SessionStarter::on_SBPort_editingFinished() { ui->SBPort->setStyleSheet( "" ); lablib->SetChosenZTreePort( ui->SBPort->value() ); diff --git a/src/sessionstarter.h b/src/sessionstarter.h index 6c4722e..28c631a 100644 --- a/src/sessionstarter.h +++ b/src/sessionstarter.h @@ -43,6 +43,11 @@ public: //! (because no installed z-Tree instances could be detected). class lcForbiddenCall {}; +signals: + void SessionRequested( QString argDataTargetPath, int argPort, QString argzTreeVersion, + bool argReceiptsForLocalClients, QString argAnonReceiptPlaceholder, + QString argChosenLatexHeader ); + private: QPlainTextEdit * const debugMessagesTextEdit = nullptr; Lablib * const lablib = nullptr; @@ -59,6 +64,7 @@ private slots: void on_CBzTreeVersion_activated(const QString &arg1); void on_ChBPrintanonymousreceipts_clicked( bool checked ); void on_ChBReceiptsforLocalClients_clicked(bool checked); + void on_PBStartzTree_clicked(); void on_SBPort_editingFinished(); signals: