diff --git a/src/Lib/settings.cpp b/src/Lib/settings.cpp index b56d04c..11e6d14 100755 --- a/src/Lib/settings.cpp +++ b/src/Lib/settings.cpp @@ -383,3 +383,7 @@ void lc::Settings::SetLocalzLeafSize( QString arg) { localzLeafSize = arg; } +void lc::Settings::SetChosenZTreePort( const int argPort ){ + chosenzTreePort = argPort; +} + diff --git a/src/Lib/settings.h b/src/Lib/settings.h index 1489a69..42398b4 100755 --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -32,8 +32,6 @@ class Settings : public QObject { Q_OBJECT public: - void SetLocalzLeafSize( QString arg); - Settings() = delete; explicit Settings( const QSettings &argSettings, QObject *argParent = nullptr ); Settings( const Settings &argSettings ) = delete; @@ -58,6 +56,8 @@ public: const QString lcDataDir; const QString localUserName; QString localzLeafSize; + void SetLocalzLeafSize( QString arg); + QString GetLocalzLeafSize() const { return localzLeafSize; } const QString lprCmd; const QString netstatCmd; const QString netwBrdAddr; @@ -120,11 +120,6 @@ inline QString lc::Settings::GetLocalzLeafName() const { return localzLeafName; } -inline void lc::Settings::SetChosenZTreePort( const int argPort ) { - chosenzTreePort = argPort; - qDebug() << "'chosenZTreePort' set to:" << chosenzTreePort; -} - inline void lc::Settings::SetLocalzLeafName( const QString &argLocalzLeafName ) { localzLeafName = argLocalzLeafName; } diff --git a/src/localzleafstarter.cpp b/src/localzleafstarter.cpp index 244caa7..2c25413 100755 --- a/src/localzleafstarter.cpp +++ b/src/localzleafstarter.cpp @@ -33,10 +33,15 @@ lc::LocalzLeafStarter::LocalzLeafStarter( QWidget *argParent ) : { ui->setupUi( this ); + //Choose initial port from settings if ( settings->GetChosenZTreePort() ) { ui->SBzLeafPort->setValue( settings->GetChosenZTreePort() ); } + //Choose initial z-Leave size from settings + ui->LELocalzLeafSize->setText( settings->GetLocalzLeafSize() ); + + ui->CBzLeafVersion->addItem( tr( "Please choose a version" ) ); if ( !settings->installedZTreeVersions.isEmpty() ) { ui->CBzLeafVersion->addItems( settings->installedZTreeVersions ); @@ -55,6 +60,10 @@ void lc::LocalzLeafStarter::on_PBStartLocalzLeaf_clicked() { return; } + //Set chosen z-Leaf size + settings->SetLocalzLeafSize( ui->LELocalzLeafSize->text() ); + + //Emit start local z-Leaf request to main window emit LocalzLeafRequested( ui->LEzLeafName->text(), ui->CBzLeafVersion->currentText(), ui->SBzLeafPort->value() ); } diff --git a/src/localzleafstarter.ui b/src/localzleafstarter.ui index ecc4410..b92dea5 100755 --- a/src/localzleafstarter.ui +++ b/src/localzleafstarter.ui @@ -6,7 +6,7 @@ 0 0 - 352 + 371 352 @@ -20,7 +20,7 @@ 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: + Set the name of the to be started z-Leaf @@ -43,7 +43,7 @@ Choose of which version the started z-Leaf shall be. - Choose the version of the to be started z-Leaf: + Choose the version of the to be started z-Leaf @@ -66,12 +66,15 @@ 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: + Choose the port the to be started z-Leaf shall listen on + + ArrowCursor + Set the port on which the z-Tree which shall be connected to listens. @@ -89,6 +92,23 @@ + + + + Choose the size the local z-Leaf shall have + + + + + + + + + + Qt::Horizontal + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cd049a1..e720c69 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -280,105 +280,6 @@ void lc::MainWindow::LoadIconPixmaps() { } } -void lc::MainWindow::on_PBBoot_clicked() { - QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - 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->Boot(); - } - } -} - -void lc::MainWindow::on_PBChooseFile_clicked() { - QFileDialog *file_dialog = new QFileDialog{ this, tr( "Choose a file to beam" ), QDir::homePath() }; - file_dialog->setFileMode( QFileDialog::Directory ); - file_dialog->setOption( QFileDialog::DontUseNativeDialog, true ); - file_dialog->setOption( QFileDialog::ReadOnly, true ); - file_dialog->setOption( QFileDialog::ShowDirsOnly, true ); - - if(file_dialog->exec()) { - ui->LEFilePath->setText(file_dialog->selectedFiles().at(0)); - qDebug() << "Chose file" << ui->LEFilePath->text() << "for beaming."; - } - else { - ui->LEFilePath->setText( tr( "File choosing cancelled" ) ); - qDebug() << "File choosing cancelled"; - } - delete file_dialog; -} - -void lc::MainWindow::on_PBBeamFile_clicked() { - QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - const QString fileToBeam{ ui->LEFilePath->text() }; - if(fileToBeam == ""){ - QMessageBox::information(this, "Upload failed", "You didn't choose any folder to upload."); - } else { - //Iterate over the selected clients to upload the file - 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->BeamFile( fileToBeam, &settings->pkeyPathUser, &settings->userNameOnClients ); - } - } - // Inform the user about the path - QMessageBox::information(this, "Upload completed", "The folder was copied to all selected clients.\nThe path on every client is /home/ewfuser" + fileToBeam.mid(fileToBeam.lastIndexOf('/')) +".\nDon't forget to adjust the media path within zTree!"); - } -} - -void lc::MainWindow::on_PBExecute_clicked() { - // This will be set to false, if the command shall be executed only on the chosen clients (that's if not all clients are up) - bool executeOnEveryClient = true; - - // Cancel, if not all clients are up and running - for ( auto s: settings->GetClients() ) { - if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { - if ( s->GetClientState() < state_t::RESPONDING ) { - QMessageBox messageBox{ QMessageBox::Warning, tr( "Not all clients are running" ), - tr( "Not all clients are running. The command could not be executed on every client and should therefore be canceled to keep the clients consistent.\n\nAre you sure you want to continue only with the currently chosen clients?" ), QMessageBox::No | QMessageBox::Yes, this }; - messageBox.setDefaultButton( QMessageBox::No ); - messageBox.exec(); - executeOnEveryClient = false; - if ( messageBox.clickedButton() == messageBox.button( QMessageBox::No ) ) { - return; - } else { - break; - } - } - } - } - - // Get the command to be executed ... - QString command = ui->CBCommandToExecute->currentText(); - - // Set the correct public key - QString pkeyPathUser; - if ( ui->RBUseUserRoot->isChecked() ) { - pkeyPathUser = settings->pkeyPathRoot; - } else { - pkeyPathUser = settings->pkeyPathUser; - } - - // and execute it - if ( executeOnEveryClient ) { - qDebug() << "Executing command" << command << "on every client."; - for ( auto s: settings->GetClients() ) { - if ( !( s->name.contains( "backup", Qt::CaseInsensitive ) ) ) { - s->OpenTerminal( command, ui->RBUseUserRoot->isChecked() ); - } - } - } else { - qDebug() << "Executing command" << command << "only on chosen clients."; - QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - 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->OpenTerminal( command, ui->RBUseUserRoot->isChecked() ); - } - } - } -} - void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { QString program{ settings->killallCmd }; QStringList arguments; @@ -396,25 +297,6 @@ void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { qDebug() << program << arguments; } -void lc::MainWindow::on_PBOpenFilesystem_clicked() { - // Determine the correct user to be used - QString * userToBeUsed = nullptr; - if ( ui->RBUseUserRoot->isChecked() ) { - userToBeUsed = new QString{ "root" }; - } else { - userToBeUsed = new QString{ settings->userNameOnClients }; - } - - QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - 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->OpenFilesystem( userToBeUsed ); - } - } - delete userToBeUsed; -} - void lc::MainWindow::on_PBPrintPaymentFileManually_clicked() { ManualPrintingSetup *manPrint = new ManualPrintingSetup{ this }; manPrint->setWindowFlags( Qt::Window ); @@ -450,46 +332,6 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() { } } -void lc::MainWindow::on_PBShowORSEE_clicked() { - lablib->ShowOrsee(); -} - -void lc::MainWindow::on_PBShowPreprints_clicked() { - lablib->ShowPreprints(); -} - -void lc::MainWindow::on_PBShutdown_clicked() { - // Confirmation dialog - QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, "Confirm", "Really shutdown the selected clients?", QMessageBox::Yes|QMessageBox::No); - if (reply == QMessageBox::Yes) { - QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - 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 * >() ); - // Do not shut down the server itself - if ( client->name == "self"){ - QMessageBox::information(NULL, "Shutdown canceled", "It is not allowed to shutdown the server itself via labcontrol!"); - } else { - client->Shutdown(); - } - } - } - } else { - qDebug() << "Canceled shutting down the selected clients"; - } -} - -void lc::MainWindow::on_PBStartLocalzLeaf_clicked() { - 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_RBUseLocalUser_toggled(bool checked) { if ( checked ) { qDebug() << "'RBUseLocalUser' got toggled."; @@ -599,10 +441,6 @@ void lc::MainWindow::SetupWidgets() { "See the GNU General Public License for more details.\n\n" "You should have received a copy of the GNU General Public License\n" "along with Labcontrol. If not, see .\n\n\n" ); - - // Fill settings tab - ui->LESettingsServerLocalzLeafSize->setText ( settings->localzLeafSize ); - } void lc::MainWindow::StartReceiptsHandler( QString argzTreeDataTargetPath, @@ -651,6 +489,82 @@ void lc::MainWindow::UpdateClientsTableView() { /* Experiment tab functions */ +void lc::MainWindow::on_PBBoot_clicked() { + QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); + 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->Boot(); + } + } +} + +void lc::MainWindow::on_PBChooseFile_clicked() { + QFileDialog *file_dialog = new QFileDialog{ this, tr( "Choose a file to beam" ), QDir::homePath() }; + file_dialog->setFileMode( QFileDialog::Directory ); + file_dialog->setOption( QFileDialog::DontUseNativeDialog, true ); + file_dialog->setOption( QFileDialog::ReadOnly, true ); + file_dialog->setOption( QFileDialog::ShowDirsOnly, true ); + + if(file_dialog->exec()) { + ui->LEFilePath->setText(file_dialog->selectedFiles().at(0)); + qDebug() << "Chose file" << ui->LEFilePath->text() << "for beaming."; + } + else { + ui->LEFilePath->setText( tr( "File choosing cancelled" ) ); + qDebug() << "File choosing cancelled"; + } + delete file_dialog; +} + +void lc::MainWindow::on_PBBeamFile_clicked() { + QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); + const QString fileToBeam{ ui->LEFilePath->text() }; + if(fileToBeam == ""){ + QMessageBox::information(this, "Upload failed", "You didn't choose any folder to upload."); + } else { + //Iterate over the selected clients to upload the file + 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->BeamFile( fileToBeam, &settings->pkeyPathUser, &settings->userNameOnClients ); + } + } + // Inform the user about the path + QMessageBox::information(this, "Upload completed", "The folder was copied to all selected clients.\nThe path on every client is /home/ewfuser/media4ztree" + fileToBeam.mid(fileToBeam.lastIndexOf('/')) +".\nDon't forget to adjust the media path within zTree!"); + } +} + +void lc::MainWindow::on_PBShowORSEE_clicked() { + lablib->ShowOrsee(); +} + +void lc::MainWindow::on_PBShowPreprints_clicked() { + lablib->ShowPreprints(); +} + +void lc::MainWindow::on_PBShutdown_clicked() { + // Confirmation dialog + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "Confirm", "Really shutdown the selected clients?", QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); + 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 * >() ); + // Do not shut down the server itself + if ( client->name == "self"){ + QMessageBox::information(NULL, "Shutdown canceled", "It is not allowed to shutdown the server itself via labcontrol!"); + } else { + client->Shutdown(); + } + } + } + } else { + qDebug() << "Canceled shutting down the selected clients"; + } +} + void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) { if ( argIndex != 0 ) { QString program{ settings->webcamDisplayCmd }; @@ -732,6 +646,16 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() { } } +void lc::MainWindow::on_PBStartLocalzLeaf_clicked() { + 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::StartLocalzLeaf( QString argzLeafName, QString argzLeafVersion, int argzTreePort ) { if ( settings->tasksetCmd.isEmpty() || settings->wineCmd.isEmpty() @@ -877,6 +801,7 @@ void lc::MainWindow::on_PBStartSession_clicked() { //Set port to +1 int newPort = ui->SBPort->text().toInt() + 1; + settings->SetChosenZTreePort(newPort); ui->SBPort->setValue(newPort); } @@ -893,6 +818,49 @@ void lc::MainWindow::on_PBKillzLeaf_clicked() /* Admin tab functions */ +void lc::MainWindow::on_PBOpenFilesystem_clicked() { + // Determine the correct user to be used + QString * userToBeUsed = nullptr; + if ( ui->RBUseUserRoot->isChecked() ) { + userToBeUsed = new QString{ "root" }; + } else { + userToBeUsed = new QString{ settings->userNameOnClients }; + } + + QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); + 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->OpenFilesystem( userToBeUsed ); + } + } + delete userToBeUsed; +} + +void lc::MainWindow::on_PBExecute_clicked() { + + // Get the command to be executed ... + QString command = ui->CBCommandToExecute->currentText(); + + // Set the correct public key + QString pkeyPathUser; + if ( ui->RBUseUserRoot->isChecked() ) { + pkeyPathUser = settings->pkeyPathRoot; + } else { + pkeyPathUser = settings->pkeyPathUser; + } + + qDebug() << "Executing command" << command << " on chosen clients."; + QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); + 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->OpenTerminal( command, ui->RBUseUserRoot->isChecked() ); + } + } + +} + // Issue open terminal call void lc::MainWindow::on_PBOpenTerminal_clicked() { QString pkeyPathUser; @@ -909,11 +877,3 @@ void lc::MainWindow::on_PBOpenTerminal_clicked() { } } } - -/* Settings tab functions */ - -// Change settings temporarly call -void lc::MainWindow::on_PBChangeSettingsTemp_clicked() -{ - settings->SetLocalzLeafSize( ui->LESettingsServerLocalzLeafSize->text() ); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 3a8d6d6..154afef 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -129,9 +129,6 @@ private slots: void on_CBReceiptsHeader_activated(int argIndex); void on_ChBPrintanonymousreceipts_clicked(); void on_PBKillzLeaf_clicked(); - - /* Settings actions */ - void on_PBChangeSettingsTemp_clicked(); }; } diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 733e1af..51c126b 100755 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -64,7 +64,7 @@ - 1 + 0 true @@ -487,7 +487,7 @@ 10 88 691 - 461 + 468 @@ -707,6 +707,23 @@ + + + + command line to be executed + + + + + + + + 0 + 0 + + + + @@ -778,6 +795,13 @@ + + + + Local zLeaf + + + @@ -911,7 +935,7 @@ - Execute command on every client + Execute command on selected clients @@ -933,96 +957,6 @@ - - - Settings - - - - - 240 - 520 - 201 - 23 - - - - Change settings temporarly - - - - - - 10 - 10 - 691 - 501 - - - - Qt::ScrollBarAlwaysOn - - - true - - - - - 0 - 0 - 675 - 499 - - - - - - 0 - 0 - 671 - 481 - - - - - - - Server settings - - - - - - - Client settings - - - - - - - local_zleaf_size - - - - - - - - - - server_ip - - - - - - - - - - - Qt::RightToLeft