made start session working

remotes/origin/HEAD
Tobias Weiss 7 years ago
parent 7bea07b7ac
commit 6bd69f1f7e

@ -1,207 +0,0 @@
/*
* Copyright 2014-2016 Markus Prasser
*
* This file is part of Labcontrol.
*
* Labcontrol is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Labcontrol is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include <QDir>
#include <QFileDialog>
#include <QStandardItemModel>
#include "sessionstarter.h"
#include "ui_sessionstarter.h"
#include "Lib/settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::SessionStarter::SessionStarter( const QVector< quint16 > &argOccupiedPorts,
QWidget *argParent ) :
QWidget{ argParent },
clientsViewModel{ new QStandardItemModel{ this } },
occupiedPorts{ argOccupiedPorts },
ui{ new Ui::SessionStarter }
{
ui->setupUi( this );
CheckIfPortIsOccupied( settings->GetChosenZTreePort() );
if ( settings->dvipsCmd.isEmpty() || settings->latexCmd.isEmpty()
|| settings->lcInstDir.isEmpty() || settings->lprCmd.isEmpty()
|| settings->postscriptViewer.isEmpty() || settings->ps2pdfCmd.isEmpty()
|| settings->rmCmd.isEmpty() || settings->vncViewer.isEmpty() ) {
ui->GBReceipts->setEnabled( false );
QMessageBox::information( this, tr( "Receipts printing will not work" ),
tr( "Some component essential for receipts creation and"
" printing is missing. No receipts will be created or"
" printed." ), QMessageBox::Ok );
} else {
ui->CBReceiptsHeader->addItems( settings->installedLaTeXHeaders );
if ( settings->defaultReceiptIndex
&& settings->defaultReceiptIndex < ui->CBReceiptsHeader->count() ) {
ui->CBReceiptsHeader->setCurrentIndex( settings->defaultReceiptIndex );
}
}
ui->CBzTreeVersion->addItem( tr( "Please choose a version:" ) );
ui->CBzTreeVersion->addItems( settings->installedZTreeVersions );
ui->CBDataTargetPath->addItem( tr( "Set a new path HERE" ) );
ui->CBDataTargetPath->addItem( QDir::homePath() );
ui->CBDataTargetPath->addItem( QDir::homePath() + "/zTreeData" );
ui->CBDataTargetPath->setCurrentIndex( 2 );
connect( this, &SessionStarter::RequestNewDataTargetPath,
this, &SessionStarter::GetNewDataTargetPath );
for ( auto *s : settings->GetClients() ) {
int tempXPos = s->xPosition - 1, tempYPos = s->yPosition;
if ( clientsViewModel->item( tempYPos, tempXPos ) ) {
QMessageBox::information( this, tr( "Double assignment to one position" ),
tr( "Two client where set for the same position. Client"
" '%1' will be dropped." ).arg( s->name ) );
continue;
}
QStandardItem *item = new QStandardItem( s->name );
item->setEditable( false );
const QString sessionPort{ QString::number( s->GetSessionPort() ) };
if ( sessionPort == "0" ) {
item->setText( s->name );
} else {
item->setBackground( QBrush{ QColor{ 196, 196, 255 } } );
item->setSelectable( false );
item->setText( QString{ "(" + sessionPort + ") " + s->name } );
}
QVariant v = qVariantFromValue( static_cast< void* >( s ) );
item->setData( v, Qt::UserRole );
clientsViewModel->setItem( tempYPos, tempXPos, item );
}
ui->TVClients->setModel( clientsViewModel );
}
lc::SessionStarter::~SessionStarter() {
delete ui;
}
void lc::SessionStarter::CheckIfPortIsOccupied( quint16 argPort ) {
if ( occupiedPorts.contains( argPort ) ) {
CheckIfPortIsOccupied( argPort + 1 );
} else {
ui->SBPort->setValue( argPort );
}
}
void lc::SessionStarter::GetNewDataTargetPath() {
QFileDialog fileDialog{ this };
fileDialog.setFileMode( QFileDialog::Directory );
fileDialog.setDirectory( QDir::homePath() );
fileDialog.setOption( QFileDialog::ShowDirsOnly, true );
fileDialog.setOption( QFileDialog::DontUseNativeDialog, true );
if ( fileDialog.exec() ) {
const QString fileName = fileDialog.selectedFiles().at( 0 );
ui->CBDataTargetPath->addItem( fileName );
ui->CBDataTargetPath->setCurrentText( fileName );
}
}
void lc::SessionStarter::on_CBDataTargetPath_activated( int argIndex ) {
if ( !argIndex ) {
emit RequestNewDataTargetPath();
}
ui->CBDataTargetPath->setStyleSheet( "" );
}
void lc::SessionStarter::on_CBReceiptsHeader_activated( int argIndex ) {
Q_UNUSED( argIndex );
ui->CBReceiptsHeader->setStyleSheet( "" );
}
void lc::SessionStarter::on_CBzTreeVersion_activated( int argIndex ) {
Q_UNUSED( argIndex );
ui->CBzTreeVersion->setStyleSheet( "" );
}
void lc::SessionStarter::on_ChBPrintAnonymousReceipts_clicked( bool argChecked ) {
ui->ChBPrintAnonymousReceipts->setStyleSheet( "" );
ui->LReplaceParticipantNames->setEnabled( argChecked );
ui->CBReplaceParticipantNames->setEnabled( argChecked );
}
void lc::SessionStarter::on_PBStartSession_clicked() {
if ( ui->CBzTreeVersion->currentIndex() == 0 ) {
QMessageBox::information( this, tr( "No z-Tree version chosen" ),
tr( "A z-Tree version was not chosen, yet. This setting is"
" mandatory." ), QMessageBox::Ok );
return;
}
const QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes();
if( !ui->ChBSessionWithoutClients->isChecked() ) {
if ( !activatedItems.length() ) {
QMessageBox::information( this, tr( "Canceled, no clients were chosen" ),
tr( "The start of a new session was canceled."
" Some clients have to be selected first or the"
" creation of sessions without clients must be"
" allowed with the checkbox close to the bottom" ) );
return;
}
}
QString anonymousReceiptsPlaceholder;
if ( ui->ChBPrintAnonymousReceipts->isChecked() ) {
anonymousReceiptsPlaceholder = ui->CBReplaceParticipantNames->currentText();
}
QVector< Client* > associatedClients;
for ( auto cit = activatedItems.cbegin(); cit != activatedItems.cend(); ++cit ) {
if ( ( *cit ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *cit ).data( Qt::UserRole ).value< void* >() );
client->SetSessionPort( ui->SBPort->value() );
client->SetzLeafVersion( ui->CBzTreeVersion->currentText() );
associatedClients.append( client );
}
}
emit RequestNewSession( associatedClients, anonymousReceiptsPlaceholder,
ui->ChBReceiptsForLocalClients->isChecked(),
ui->CBReceiptsHeader->currentText(),
ui->CBDataTargetPath->currentText(),
static_cast< quint16 >( ui->SBPort->value() ),
ui->CBzTreeVersion->currentText() );
//Start z-Leaf on selected clients if checkbox is activated
if( ui->ChBautoStartClientZleaf->isChecked() ) {
for ( auto cit = activatedItems.cbegin(); cit != activatedItems.cend(); ++cit ) {
if ( ( *cit ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *cit ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( nullptr );
}
}
}
this->deleteLater();
}
void lc::SessionStarter::on_SBPort_editingFinished() {
ui->SBPort->setStyleSheet( "" );
CheckIfPortIsOccupied( ui->SBPort->value() );
}

@ -1,69 +0,0 @@
/*
* Copyright 2014-2016 Markus Prasser
*
* This file is part of Labcontrol.
*
* Labcontrol is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Labcontrol is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SESSIONSTARTER_H
#define SESSIONSTARTER_H
#include <QWidget>
class QStandardItemModel;
namespace lc {
class Client;
namespace Ui {
class SessionStarter;
}
class SessionStarter : public QWidget {
Q_OBJECT
public:
explicit SessionStarter( const QVector< quint16 > &argOccupiedPorts,
QWidget *argParent = nullptr );
~SessionStarter();
signals:
void RequestNewDataTargetPath();
void RequestNewSession( QVector< Client* > argAssocCl, QString argParticipNameReplacement,
bool argPrintLocalReceipts, QString argReceiptsHeader,
QString argzTreeDataTargetPath, quint16 argzTreePort,
QString argzTreeVersion );
private:
void CheckIfPortIsOccupied( quint16 argPort );
QStandardItemModel *clientsViewModel = nullptr;
const QVector< quint16 > &occupiedPorts;
Ui::SessionStarter *ui = nullptr;
private slots:
void GetNewDataTargetPath();
void on_CBDataTargetPath_activated( int argIndex );
void on_CBReceiptsHeader_activated( int argIndex );
void on_CBzTreeVersion_activated( int argIndex );
void on_ChBPrintAnonymousReceipts_clicked( bool argChecked );
void on_PBStartSession_clicked();
void on_SBPort_editingFinished();
};
}
#endif // SESSIONSTARTER_H

@ -1,319 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>lc::SessionStarter</class>
<widget class="QWidget" name="lc::SessionStarter">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="VLSessionStarter">
<item>
<layout class="QHBoxLayout" name="HLGroupBoxes">
<item>
<widget class="QGroupBox" name="GBzTree">
<property name="title">
<string>z-Tree</string>
</property>
<layout class="QVBoxLayout" name="VLzTree">
<item>
<widget class="QLabel" name="label">
<property name="toolTip">
<string>The z-Tree version which shall be used for the experiment.</string>
</property>
<property name="text">
<string>z-Tree version:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBzTreeVersion">
<property name="toolTip">
<string>The z-Tree version which shall be used for the experiment.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
<property name="maxVisibleItems">
<number>32</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LDataTargetPath">
<property name="toolTip">
<string>The path where z-Tree shall store its data.
Please take care that it does not contain any spaces or other special characters.</string>
</property>
<property name="text">
<string>Data target path:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBDataTargetPath">
<property name="toolTip">
<string>The path where z-Tree shall store its data.
Please take care that it does not contain any spaces or other special characters.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="HLPort">
<item>
<widget class="QLabel" name="LPort">
<property name="toolTip">
<string>The port which will be used by started z-Tree and z-Leaf instances. This only matters if multiple experiments shall be run in parallel.</string>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="SBPort">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>The port which will be used by started z-Tree and z-Leaf instances. This only matters if multiple experiments shall be run in parallel.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
<property name="minimum">
<number>7000</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="ChBRamdiskForGamesafeFile">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>This function is not implemented, yet.</string>
</property>
<property name="text">
<string>Use ramdisk for gamesafe file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="GBReceipts">
<property name="title">
<string>Receipts</string>
</property>
<layout class="QVBoxLayout" name="VLReceipts">
<item>
<widget class="QLabel" name="LReceiptsHeader">
<property name="toolTip">
<string>Choose the LaTeX template which shall be used for receipts creation.</string>
</property>
<property name="text">
<string>Template for receipts:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBReceiptsHeader">
<property name="toolTip">
<string>Choose the LaTeX template which shall be used for receipts creation.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBPrintAnonymousReceipts">
<property name="toolTip">
<string>Check this if you want the created receipts to be anonymous.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
<property name="text">
<string>Print anonymous receipts</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LReplaceParticipantNames">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Choose a string which shall replace the participant name on the anonymous receipts.</string>
</property>
<property name="text">
<string>Substitute participants' names with:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBReplaceParticipantNames">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Choose a string which shall replace the participant name on the anonymous receipts.</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string>\hspace{5cm}</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>\hspace{5cm}</string>
</property>
</item>
<item>
<property name="text">
<string>anonym</string>
</property>
</item>
<item>
<property name="text">
<string>anonymous</string>
</property>
</item>
<item>
<property name="text">
<string>nicht ausfüllen</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBReceiptsForLocalClients">
<property name="toolTip">
<string>This decides if receipts shall be printed for any z-Leaf instance running locally on the server.
Warning: If this is disabled no receipts will be printed for ANY participant whose name contains the character string &quot;local&quot;!</string>
</property>
<property name="text">
<string>Print receipts for local clients</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="LClientSelection">
<property name="toolTip">
<string>Select the clients which shall be attached to this session:</string>
</property>
<property name="text">
<string>Select the clients which shall be attached to this session:</string>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="TVClients">
<property name="toolTip">
<string>Select the clients which shall be attached to this session.</string>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBSessionWithoutClients">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>This allows an experimenter to override the normally hard requirement of choosing clients to be attached to the started session and start a session without attached clients.</string>
</property>
<property name="text">
<string>Allow session without attached clients</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ChBautoStartClientZleaf">
<property name="text">
<string>Start z-Leaf on clients with the session</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PBStartSession">
<property name="toolTip">
<string>Start a new session according to the above made settings.</string>
</property>
<property name="text">
<string>Start session</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PBCancel">
<property name="toolTip">
<string>Cancel the creation of a new session.</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>PBCancel</sender>
<signal>clicked()</signal>
<receiver>lc::SessionStarter</receiver>
<slot>deleteLater()</slot>
<hints>
<hint type="sourcelabel">
<x>319</x>
<y>552</y>
</hint>
<hint type="destinationlabel">
<x>319</x>
<y>287</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading…
Cancel
Save