From 97a4ea3472a22fb2429a8862fcae7c748336cd44 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Oct 2016 11:42:44 +0200 Subject: [PATCH] Implemented advanced way of starting local z-Leaves --- Labcontrol.pro | 9 ++- src/localzleafstarter.cpp | 60 +++++++++++++++++ src/localzleafstarter.h | 50 ++++++++++++++ src/localzleafstarter.ui | 133 ++++++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 92 +++++++++++++++----------- src/mainwindow.h | 3 +- 6 files changed, 304 insertions(+), 43 deletions(-) create mode 100644 src/localzleafstarter.cpp create mode 100644 src/localzleafstarter.h create mode 100644 src/localzleafstarter.ui diff --git a/Labcontrol.pro b/Labcontrol.pro index ae4841b..6046e18 100644 --- a/Labcontrol.pro +++ b/Labcontrol.pro @@ -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 diff --git a/src/localzleafstarter.cpp b/src/localzleafstarter.cpp new file mode 100644 index 0000000..244caa7 --- /dev/null +++ b/src/localzleafstarter.cpp @@ -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 . + */ + +#include + +#include + +#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() ); +} diff --git a/src/localzleafstarter.h b/src/localzleafstarter.h new file mode 100644 index 0000000..ba4a951 --- /dev/null +++ b/src/localzleafstarter.h @@ -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 . + */ + +#ifndef LOCALZLEAFSTARTER_H +#define LOCALZLEAFSTARTER_H + +#include + +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 diff --git a/src/localzleafstarter.ui b/src/localzleafstarter.ui new file mode 100644 index 0000000..ecc4410 --- /dev/null +++ b/src/localzleafstarter.ui @@ -0,0 +1,133 @@ + + + lc::LocalzLeafStarter + + + + 0 + 0 + 352 + 352 + + + + Local z-Leaf Starter + + + + + + This sets the name with which this local z-Leaf will connect to z-Tree. + + + Set the name of the to be started z-Leaf: + + + + + + + This sets the name with which this local z-Leaf will connect to z-Tree. + + + background: cyan; + + + local + + + + + + + Choose of which version the started z-Leaf shall be. + + + Choose the version of the to be started z-Leaf: + + + + + + + Choose of which version the started z-Leaf shall be. + + + background: cyan; + + + 32 + + + + + + + Set the port on which the z-Tree which shall be connected to listens. + + + Choose the port the to be started z-Leaf shall listen on: + + + + + + + Set the port on which the z-Tree which shall be connected to listens. + + + background: cyan; + + + 7000 + + + 65535 + + + 7000 + + + + + + + Start a local z-Leaf with the set parameters. + + + Start local z-Leaf + + + + + + + Cancel the start of a new local z-Leaf. + + + Cancel + + + + + + + + + PBCancel + clicked() + lc::LocalzLeafStarter + deleteLater() + + + 175 + 328 + + + 175 + 175 + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5ab86e6..df97013 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,6 +23,7 @@ #include #include +#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 .\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() )->GetClientState(); diff --git a/src/mainwindow.h b/src/mainwindow.h index fbdaccf..956c769 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 *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()'