Implemented advanced way of starting local z-Leaves

remotes/origin/HEAD
markuspg 10 years ago
parent b45254aa3b
commit 97a4ea3472

@ -4,7 +4,8 @@ TARGET = labcontrol
TEMPLATE = app
SOURCES += src/main.cpp \
SOURCES += src/localzleafstarter.cpp \
src/main.cpp \
src/mainwindow.cpp \
src/sessiondisplay.cpp \
src/sessionstarter.cpp \
@ -20,7 +21,8 @@ SOURCES += src/main.cpp \
src/Lib/settings.cpp \
src/Lib/ztree.cpp
HEADERS += src/mainwindow.h \
HEADERS += src/localzleafstarter.h \
src/mainwindow.h \
src/sessiondisplay.h \
src/sessionstarter.h \
src/Lib/client.h \
@ -36,7 +38,8 @@ HEADERS += src/mainwindow.h \
src/Lib/settings.h \
src/Lib/ztree.h
FORMS += src/mainwindow.ui \
FORMS += src/localzleafstarter.ui \
src/mainwindow.ui \
src/sessiondisplay.ui \
src/sessionstarter.ui

@ -0,0 +1,60 @@
/*
* 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 <QMessageBox>
#include "localzleafstarter.h"
#include "ui_localzleafstarter.h"
#include "Lib/settings.h"
extern std::unique_ptr< lc::Settings > settings;
lc::LocalzLeafStarter::LocalzLeafStarter( QWidget *argParent ) :
QWidget{ argParent },
ui{ new Ui::LocalzLeafStarter }
{
ui->setupUi( this );
if ( settings->GetChosenZTreePort() ) {
ui->SBzLeafPort->setValue( settings->GetChosenZTreePort() );
}
ui->CBzLeafVersion->addItem( tr( "Please choose a version" ) );
if ( !settings->installedZTreeVersions.isEmpty() ) {
ui->CBzLeafVersion->addItems( settings->installedZTreeVersions );
}
}
lc::LocalzLeafStarter::~LocalzLeafStarter() {
delete ui;
}
void lc::LocalzLeafStarter::on_PBStartLocalzLeaf_clicked() {
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox::information( this, tr( "No z-Tree version chosen" ),
tr( "The was not chosen a z-Tree version, yet. This is"
" mandatory, so please set one" ) , QMessageBox::Ok );
return;
}
emit LocalzLeafRequested( ui->LEzLeafName->text(), ui->CBzLeafVersion->currentText(),
ui->SBzLeafPort->value() );
}

@ -0,0 +1,50 @@
/*
* 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 LOCALZLEAFSTARTER_H
#define LOCALZLEAFSTARTER_H
#include <QWidget>
namespace lc {
namespace Ui {
class LocalzLeafStarter;
}
class LocalzLeafStarter : public QWidget {
Q_OBJECT
public:
explicit LocalzLeafStarter( QWidget *argParent = nullptr );
~LocalzLeafStarter();
signals:
void LocalzLeafRequested( QString argzLeafName, QString argzLeafVersion, int argzTreePort );
private:
Ui::LocalzLeafStarter *ui = nullptr;
private slots:
void on_PBStartLocalzLeaf_clicked();
};
}
#endif // LOCALZLEAFSTARTER_H

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>lc::LocalzLeafStarter</class>
<widget class="QWidget" name="lc::LocalzLeafStarter">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>352</height>
</rect>
</property>
<property name="windowTitle">
<string>Local z-Leaf Starter</string>
</property>
<layout class="QVBoxLayout" name="VLLocalzLeafStarter">
<item>
<widget class="QLabel" name="LzLeafName">
<property name="toolTip">
<string>This sets the name with which this local z-Leaf will connect to z-Tree.</string>
</property>
<property name="text">
<string>Set the name of the to be started z-Leaf:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="LEzLeafName">
<property name="toolTip">
<string>This sets the name with which this local z-Leaf will connect to z-Tree.</string>
</property>
<property name="styleSheet">
<string notr="true">background: cyan;</string>
</property>
<property name="text">
<string>local</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="LzLeafVersion">
<property name="toolTip">
<string>Choose of which version the started z-Leaf shall be.</string>
</property>
<property name="text">
<string>Choose the version of the to be started z-Leaf:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CBzLeafVersion">
<property name="toolTip">
<string>Choose of which version the started z-Leaf shall be.</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="LzLeafPort">
<property name="toolTip">
<string>Set the port on which the z-Tree which shall be connected to listens.</string>
</property>
<property name="text">
<string>Choose the port the to be started z-Leaf shall listen on:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="SBzLeafPort">
<property name="toolTip">
<string>Set the port on which the z-Tree which shall be connected to listens.</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>
<property name="value">
<number>7000</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PBStartLocalzLeaf">
<property name="toolTip">
<string>Start a local z-Leaf with the set parameters.</string>
</property>
<property name="text">
<string>Start local z-Leaf</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="PBCancel">
<property name="toolTip">
<string>Cancel the start of a new local z-Leaf.</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>PBCancel</sender>
<signal>clicked()</signal>
<receiver>lc::LocalzLeafStarter</receiver>
<slot>deleteLater()</slot>
<hints>
<hint type="sourcelabel">
<x>175</x>
<y>328</y>
</hint>
<hint type="destinationlabel">
<x>175</x>
<y>175</y>
</hint>
</hints>
</connection>
</connections>
</ui>

@ -23,6 +23,7 @@
#include <QDebug>
#include <QInputDialog>
#include "localzleafstarter.h"
#include "mainwindow.h"
#include "Lib/settings.h"
@ -165,6 +166,15 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
ui->TAdminActions->setEnabled( false );
}
if ( settings->tasksetCmd.isEmpty() ) {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
// Disable 'PBOpenTerminal' if 'terminal_emulator_command' was not set
if ( settings->termEmulCmd.isEmpty() ) {
ui->GBExecuteOnEveryClient->setEnabled( false );
@ -188,10 +198,28 @@ void lc::MainWindow::DisableDisfunctionalWidgets() {
ui->LWebcamChooser->setEnabled( false );
}
if ( settings->wineCmd.isEmpty() ) {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
// Disable the disable screensaver function if the 'xset_command' was not set
if ( settings->xsetCmd.isEmpty() ) {
ui->PBDeactivateScreensaver->setEnabled( false );
}
if ( settings->zTreeInstDir.isEmpty() ) {
ui->CBClientNames->setEnabled( false );
ui->LFakeName->setEnabled( false );
ui->PBRunzLeaf->setEnabled( false );
ui->PBStartLocalzLeaf->setEnabled( false );
ui->PBStartzLeaf->setEnabled( false );
ui->PBStartzTree->setEnabled( false );
}
}
void lc::MainWindow::LoadIconPixmaps() {
@ -344,7 +372,7 @@ void lc::MainWindow::on_PBKillLocalzLeaf_clicked() {
killLocalzLeafProc.setProcessEnvironment( env );
killLocalzLeafProc.startDetached( program, arguments );
local_zLeaves_are_running = false;
localzLeavesAreRunning = false;
// Output message via the debug messages tab
qDebug() << program << arguments;
@ -479,44 +507,13 @@ void lc::MainWindow::on_PBShutdown_clicked() {
}
void lc::MainWindow::on_PBStartLocalzLeaf_clicked() {
// Show an error message, if no z-Leaf version was chosen yet
if ( ui->CBzLeafVersion->currentIndex() == 0 ) {
QMessageBox::information( this, tr( "Unset z-Leaf version" ), tr( "There is no z-Leaf version chosen yet. Please choose one." ), QMessageBox::Ok );
return;
}
// Create a QMessageBox for user interaction if there is already a z-Leaf running
QMessageBox *messageBox = nullptr;
if ( local_zLeaves_are_running ) {
messageBox = new QMessageBox{ QMessageBox::Warning, tr( "Running local zLeaf found" ), tr( "There already seems to exist a local zLeaf instance" ), QMessageBox::No | QMessageBox::Yes, this };
messageBox->setInformativeText( "Do you want to start a local zLeaf nonetheless?" );
messageBox->setDefaultButton( QMessageBox::No );
messageBox->exec();
}
if ( ( messageBox != nullptr && messageBox->clickedButton() == messageBox->button( QMessageBox::Yes ) ) || !local_zLeaves_are_running ) {
// Ask for the name the local zLeaf shall have
QString name = QInputDialog::getText( this, tr( "The local zLeaf's name" ),
tr( "Please enter the name the local zLeaf shall have." ),
QLineEdit::Normal, lablib->GetLocalZLeafDefaultName() );
lablib->SetLocalZLeafDefaultName( name );
QString program = QString{ settings->lcInstDir + "/scripts/start_zLeaf_labcontrol2.sh" };
QStringList arguments;
arguments << ui->CBzLeafVersion->currentText() << "127.0.0.1" << QString::number( ui->SBzLeafPort->value() - 7000 ) << name;
// Start the process
QProcess start_zLeaf_process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
start_zLeaf_process.setProcessEnvironment( env );
start_zLeaf_process.startDetached( program, arguments );
local_zLeaves_are_running = true;
// Output message via the debug messages tab
qDebug() << program << arguments.join( " " );
}
delete messageBox;
LocalzLeafStarter *localzLeafStarter = new LocalzLeafStarter{ this };
localzLeafStarter->setWindowFlags( Qt::Window );
localzLeafStarter->show();
connect( localzLeafStarter, &LocalzLeafStarter::LocalzLeafRequested,
this, &MainWindow::StartLocalzLeaf );
connect( localzLeafStarter, SIGNAL( LocalzLeafRequested( QString, QString, int ) ),
localzLeafStarter, SLOT( deleteLater() ) );
}
void lc::MainWindow::on_PBStartzLeaf_clicked() {
@ -724,6 +721,23 @@ void lc::MainWindow::SetupWidgets() {
"along with Labcontrol. If not, see <http://www.gnu.org/licenses/>.\n\n\n" );
}
void lc::MainWindow::StartLocalzLeaf( QString argzLeafName, QString argzLeafVersion,
int argzTreePort ) {
if ( settings->tasksetCmd.isEmpty() || settings->wineCmd.isEmpty()
|| settings->zTreeInstDir.isEmpty() ) {
return;
}
QProcess startProc;
startProc.setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
QStringList arguments;
arguments << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + argzLeafVersion + "/zleaf.exe" }
<< "/server" << "127.0.0.1" << "/channel"
<< QString::number( argzTreePort - 7000 ) << "/name" << argzLeafName;
startProc.startDetached( settings->tasksetCmd, arguments );
}
void lc::MainWindow::UpdateClientsTableView() {
for ( auto s : *valid_items ) {
state_t state = static_cast< Client* >( s->data( Qt::UserRole ).value<void *>() )->GetClientState();

@ -78,6 +78,7 @@ private slots:
void on_PBStartzTree_clicked();
void on_PBViewDesktop_clicked();
void on_RBUseLocalUser_toggled(bool checked);
void StartLocalzLeaf( QString argzLeafName, QString argzLeafVersion, int argzTreePort );
//! Updates the icons of the QTableView displaying the clients' states
/*!
* This function iterates over all valid items of the 'TVClients' and sets their states
@ -104,7 +105,7 @@ private:
QTimer *gui_update_timer = nullptr; //! A QTimer triggering updates of the graphical user interface
QVector< QPixmap > icons; //! Vector of pixmaps storing the icons indicating the clients' statuses
Lablib *lablib = nullptr; //! Accumulator of all program logic being accessed by the GUI
bool local_zLeaves_are_running = false; //! Stores if a local zLeaf instance is running on the server ('true' if local zLeaf exists)
bool localzLeavesAreRunning = false; //! Stores if a local z-Leaf instance is running on the server ('true' if local z-Leaf exists)
QButtonGroup *userChooseButtonGroup = nullptr; //! Used to group the radio buttons choosing which user shall be used for administrative client actions
Ui::MainWindow *ui = nullptr; //! Pointer storing all GUI items
QVector<QStandardItem *> *valid_items = nullptr; //! Stores all valid Client instances displayed by the table view, its main use is as iterable object for 'update_clients_table_view()'

Loading…
Cancel
Save