diff --git a/src/Lib/clienthelpnotificationserver.cpp b/src/Lib/clienthelpnotificationserver.cpp index 4b4f8b3..d18b15e 100644 --- a/src/Lib/clienthelpnotificationserver.cpp +++ b/src/Lib/clienthelpnotificationserver.cpp @@ -28,11 +28,11 @@ #include -extern std::unique_ptr settings; - -lc::ClientHelpNotificationServer::ClientHelpNotificationServer(QObject *argParent) : +lc::ClientHelpNotificationServer::ClientHelpNotificationServer(const Settings *const argSettings, + QObject *argParent) : QObject{argParent}, - hostAddress{settings->serverIP} + hostAddress{settings->serverIP}, + settings{argSettings} { QNetworkConfigurationManager manager; if (manager.capabilities() diff --git a/src/Lib/clienthelpnotificationserver.h b/src/Lib/clienthelpnotificationserver.h index c1d704c..b4516dc 100644 --- a/src/Lib/clienthelpnotificationserver.h +++ b/src/Lib/clienthelpnotificationserver.h @@ -27,17 +27,21 @@ class QTcpServer; namespace lc { +class Settings; + class ClientHelpNotificationServer : public QObject { Q_OBJECT public: - explicit ClientHelpNotificationServer(QObject *argParent = nullptr); + explicit ClientHelpNotificationServer(const Settings *const argSettings, + QObject *argParent = nullptr); private: QTcpServer *helpMessageServer = nullptr; const QHostAddress hostAddress; QNetworkSession *networkSession = nullptr; + const Settings *const settings = nullptr; private slots: void OpenSession(); diff --git a/src/Lib/lablib.cpp b/src/Lib/lablib.cpp index c4a2d54..3c4a453 100644 --- a/src/Lib/lablib.cpp +++ b/src/Lib/lablib.cpp @@ -24,10 +24,11 @@ #include "lablib.h" -lc::Lablib::Lablib(QObject *argParent) : +lc::Lablib::Lablib(Settings *const argSettings, QObject *argParent) : QObject{argParent}, labSettings{"Labcontrol", "Labcontrol", this}, - sessionsModel{new SessionsModel{this}} + sessionsModel{new SessionsModel{this}}, +settings{argSettings} { for (const auto &s : settings->GetClients()) { connect(this, &Lablib::ZLEAF_RUNNING, @@ -52,7 +53,8 @@ lc::Lablib::Lablib(QObject *argParent) : // Initialize the server for client help requests retrieval if (settings->clientHelpNotificationServerPort && !settings->serverIP.isEmpty()) { - clientHelpNotificationServer = new ClientHelpNotificationServer{this}; + clientHelpNotificationServer + = new ClientHelpNotificationServer{settings, this}; } } @@ -157,7 +159,8 @@ void lc::Lablib::StartNewSession(QVector argAssocCl, argzTreePort, argzTreeVersion, argPrintLocalReceipts, argParticipNameReplacement, - argReceiptsHeader}); + argReceiptsHeader, + settings}); occupiedPorts.append(sessionsModel->back()->zTreePort); } catch (Session::lcDataTargetPathCreationFailed) { QMessageBox::information(nullptr, tr("Chosen data target path could not be created"), diff --git a/src/Lib/lablib.h b/src/Lib/lablib.h index d7530bf..fd0070f 100644 --- a/src/Lib/lablib.h +++ b/src/Lib/lablib.h @@ -45,8 +45,6 @@ #include "sessionsmodel.h" #include "settings.h" -extern std::unique_ptr settings; - namespace lc { //! This class represents the entire lab and running sessions. @@ -62,7 +60,7 @@ public: * \brief Lablib's constructor * \param[in] argParent This 'lcLablib' instance's parent QObject */ - Lablib(QObject *argParent = nullptr); + Lablib(Settings *const argSettings, QObject *argParent = nullptr); /** Lablib's destructor */ ~Lablib() override; @@ -135,6 +133,7 @@ private: QVector< quint16 > occupiedPorts; //! A derivation from QAbstractTableModel used to store the single Session instances SessionsModel *sessionsModel = nullptr; + Settings *const settings = nullptr; }; } // namespace lc diff --git a/src/Lib/receipts_handler.cpp b/src/Lib/receipts_handler.cpp index 69120fa..0a7daf2 100644 --- a/src/Lib/receipts_handler.cpp +++ b/src/Lib/receipts_handler.cpp @@ -24,9 +24,8 @@ #include "receipts_handler.h" #include "settings.h" -extern std::unique_ptr settings; - -lc::ReceiptsHandler::ReceiptsHandler(const QString &argZTreeDataTargetPath, +lc::ReceiptsHandler::ReceiptsHandler(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, const QString &argLatexHeaderName, @@ -39,6 +38,7 @@ lc::ReceiptsHandler::ReceiptsHandler(const QString &argZTreeDataTargetPath, latexHeaderName{argLatexHeaderName}, paymentFile{expectedPaymentFilePath}, printReceiptsForLocalClients{argPrintReceiptsForLocalClients}, + settings{argSettings}, timer{new QTimer{this}}, zTreeDataTargetPath{argZTreeDataTargetPath} { @@ -50,7 +50,8 @@ zTreeDataTargetPath{argZTreeDataTargetPath} timer->start(2000); } -lc::ReceiptsHandler::ReceiptsHandler(const QString &argZTreeDataTargetPath, +lc::ReceiptsHandler::ReceiptsHandler(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, const QString &argLatexHeaderName, @@ -63,6 +64,7 @@ lc::ReceiptsHandler::ReceiptsHandler(const QString &argZTreeDataTargetPath, latexHeaderName{argLatexHeaderName}, paymentFile{expectedPaymentFilePath}, printReceiptsForLocalClients{argPrintReceiptsForLocalClients}, + settings{argSettings}, zTreeDataTargetPath{argZTreeDataTargetPath} { qDebug() << "Expected payment file name is:" << expectedPaymentFilePath; @@ -198,13 +200,14 @@ void lc::ReceiptsHandler::CreateReceiptsFromPaymentFile() } // Open a QTextStream to write to the file - QTextStream out(texFile); + QTextStream out{texFile}; out << *latexText; delete latexText; latexText = nullptr; - receiptsPrinter = new ReceiptsPrinter{dateString, zTreeDataTargetPath, this}; + receiptsPrinter = new ReceiptsPrinter{dateString, settings, + zTreeDataTargetPath, this}; receiptsPrinter->start(); connect(receiptsPrinter, &ReceiptsPrinter::PrintingFinished, this, &ReceiptsHandler::DeleteReceiptsPrinterInstance); diff --git a/src/Lib/receipts_handler.h b/src/Lib/receipts_handler.h index 8260103..aff2daf 100644 --- a/src/Lib/receipts_handler.h +++ b/src/Lib/receipts_handler.h @@ -42,6 +42,8 @@ struct paymentEntry_t { double payoff; }; +class Settings; + //! A class to handle receipts printing. /*! This class is element of every session and is used to handle the receipts printing. @@ -51,11 +53,13 @@ class ReceiptsHandler : public QObject Q_OBJECT public: - explicit ReceiptsHandler(const QString &argZTreeDataTargetPath, + explicit ReceiptsHandler(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, const QString &argLatexHeaderName, QObject *argParent = nullptr); - explicit ReceiptsHandler(const QString &argZTreeDataTargetPath, + explicit ReceiptsHandler(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, const QString &argLatexHeaderName, @@ -98,6 +102,7 @@ private: const bool printReceiptsForLocalClients; //! Creates new thread for receipts printing ReceiptsPrinter *receiptsPrinter = nullptr; + const Settings *const settings = nullptr; //! Used for regular checking if the payment file was created QTimer *timer = nullptr; //! A reference to the data target path stored in the session class instance diff --git a/src/Lib/receiptsprinter.cpp b/src/Lib/receiptsprinter.cpp index 0a1f493..6804107 100644 --- a/src/Lib/receiptsprinter.cpp +++ b/src/Lib/receiptsprinter.cpp @@ -17,25 +17,22 @@ * along with Labcontrol. If not, see . */ -#include - #include "receiptsprinter.h" #include "settings.h" -extern std::unique_ptr settings; - lc::ReceiptsPrinter::ReceiptsPrinter(const QString &argDateString, + const Settings *const argSettings, const QString &argWorkpath, QObject *argParent) : QThread{argParent}, dateString{argDateString}, - dvipsCmd{settings->dvipsCmd}, - latexCmd{settings->latexCmd}, - lprCmd{settings->lprCmd}, - postscriptViewer{ settings->postscriptViewer}, - ps2pdfCmd{settings->ps2pdfCmd}, - rmCmd{settings->rmCmd}, - vncViewer{settings->vncViewer}, + dvipsCmd{argSettings->dvipsCmd}, + latexCmd{argSettings->latexCmd}, + lprCmd{argSettings->lprCmd}, + postscriptViewer{argSettings->postscriptViewer}, + ps2pdfCmd{argSettings->ps2pdfCmd}, + rmCmd{argSettings->rmCmd}, + vncViewer{argSettings->vncViewer}, workpath{argWorkpath} { } diff --git a/src/Lib/receiptsprinter.h b/src/Lib/receiptsprinter.h index 38c46d1..5433d08 100644 --- a/src/Lib/receiptsprinter.h +++ b/src/Lib/receiptsprinter.h @@ -28,6 +28,8 @@ namespace lc { +class Settings; + //! A class for receipts creation. /*! This class is used to do the actual printing of the receipts in an own thread. @@ -151,6 +153,7 @@ class ReceiptsPrinter : public QThread } public: explicit ReceiptsPrinter(const QString &argDateString, + const Settings *const argSettings, const QString &argWorkpath, QObject *argParent = nullptr); diff --git a/src/Lib/session.cpp b/src/Lib/session.cpp index 0e757b4..4006ccf 100644 --- a/src/Lib/session.cpp +++ b/src/Lib/session.cpp @@ -24,19 +24,19 @@ #include -extern std::unique_ptr settings; - lc::Session::Session(QVector &&argAssocClients, const QString &argZTreeDataTargetPath, const quint16 argZTreePort, const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, - const QString &argLatexHeaderName, QObject *argParent): + const QString &argLatexHeaderName, + const Settings *const argSettings, QObject *argParent): QObject{argParent}, zTreePort{argZTreePort}, anonymousReceiptsPlaceholder{argAnonymousReceiptsPlaceholder}, assocClients{std::move(argAssocClients)}, latexHeaderName{argLatexHeaderName}, printReceiptsForLocalClients{argPrintReceiptsForLocalClients}, + settings{argSettings}, zTreeDataTargetPath{argZTreeDataTargetPath}, zTreeVersionPath{argZTreeVersionPath} { @@ -88,14 +88,15 @@ void lc::Session::InitializeClasses() zTreeDataTargetPath.append("/" + date_string + "-" + QString::number(zTreePort)); qDebug() << "New session's chosen_zTree_data_target_path:" << zTreeDataTargetPath; - zTreeInstance = new ZTree{zTreeDataTargetPath, zTreePort, + zTreeInstance = new ZTree{settings, zTreeDataTargetPath, zTreePort, zTreeVersionPath, this}; connect(zTreeInstance, &ZTree::ZTreeClosed, this, &Session::OnzTreeClosed); // Only create a 'Receipts_Handler' instance, if all neccessary variables were set if (latexHeaderName != "None found" && !settings->dvipsCmd.isEmpty() && !settings->latexCmd.isEmpty()) { - new ReceiptsHandler{zTreeDataTargetPath, printReceiptsForLocalClients, + new ReceiptsHandler{settings, zTreeDataTargetPath, + printReceiptsForLocalClients, anonymousReceiptsPlaceholder, latexHeaderName, this}; } else { qDebug() << "No 'ReceiptsHandler' instance was created."; diff --git a/src/Lib/session.h b/src/Lib/session.h index ed732ae..8bd278f 100644 --- a/src/Lib/session.h +++ b/src/Lib/session.h @@ -29,6 +29,7 @@ namespace lc { class Client; +class Settings; //! A class containing an entire session. /*! @@ -46,7 +47,8 @@ public: const quint16 argZTreePort, const QString &argZTreeVersionPath, bool argPrintReceiptsForLocalClients, const QString &argAnonymousReceiptsPlaceholder, - const QString &argLatexHeaderName, QObject *argParent = nullptr); + const QString &argLatexHeaderName, + const Settings *const argSettings, QObject *argParent = nullptr); ~Session() override; /*! Returns the data item with the given index @@ -78,6 +80,7 @@ private: const QString latexHeaderName; //! True if receipts shall be printed for local clients const bool printReceiptsForLocalClients = true; + const Settings *const settings; //! The path were the data of this zTree instance's session will be saved QString zTreeDataTargetPath; //! The session's zTree instance diff --git a/src/Lib/settings.h b/src/Lib/settings.h index 838313a..f34f697 100644 --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -45,7 +45,7 @@ public: { return chosenzTreePort; } - QVector< Client * > &GetClients() + const QVector &GetClients() const { return clients; } diff --git a/src/Lib/ztree.cpp b/src/Lib/ztree.cpp index 4c1c3e5..9369e99 100644 --- a/src/Lib/ztree.cpp +++ b/src/Lib/ztree.cpp @@ -25,11 +25,11 @@ #include -extern std::unique_ptr settings; - -lc::ZTree::ZTree(const QString &argZTreeDataTargetPath, const int argZTreePort, +lc::ZTree::ZTree(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, const int argZTreePort, const QString &argZTreeVersionPath, QObject *argParent) : - QObject{argParent} + QObject{argParent}, + settings{argSettings} { QStringList arguments{QStringList{} << "-c" << "0" << settings->wineCmd << QString{settings->zTreeInstDir + "/zTree_" diff --git a/src/Lib/ztree.h b/src/Lib/ztree.h index 1684b07..9c00c56 100644 --- a/src/Lib/ztree.h +++ b/src/Lib/ztree.h @@ -26,6 +26,8 @@ namespace lc { +class Settings; + //! A class to contain running zTree instances. /*! This class is element of every session and is used to handle all zTree related data. @@ -35,7 +37,8 @@ class ZTree: public QObject Q_OBJECT public: - ZTree(const QString &argZTreeDataTargetPath, + ZTree(const Settings *const argSettings, + const QString &argZTreeDataTargetPath, const int argZTreePort, const QString &argZTreeVersionPath, QObject *argParent = nullptr); @@ -43,6 +46,7 @@ signals: void ZTreeClosed(int argExitCode); private: + const Settings *const settings = nullptr; QProcess zTreeInstance; }; diff --git a/src/localzleafstarter.cpp b/src/localzleafstarter.cpp index 9455524..bd8dc6c 100644 --- a/src/localzleafstarter.cpp +++ b/src/localzleafstarter.cpp @@ -25,10 +25,10 @@ #include -extern std::unique_ptr settings; - -lc::LocalzLeafStarter::LocalzLeafStarter(QWidget *argParent) : +lc::LocalzLeafStarter::LocalzLeafStarter(Settings *const argSettings, + QWidget *argParent) : QWidget{argParent}, + settings{argSettings}, ui{new Ui::LocalzLeafStarter} { ui->setupUi(this); diff --git a/src/localzleafstarter.h b/src/localzleafstarter.h index d8704ac..c13f7fd 100644 --- a/src/localzleafstarter.h +++ b/src/localzleafstarter.h @@ -28,12 +28,15 @@ namespace Ui { class LocalzLeafStarter; } // namespace Ui +class Settings; + class LocalzLeafStarter : public QWidget { Q_OBJECT public: - explicit LocalzLeafStarter(QWidget *argParent = nullptr); + explicit LocalzLeafStarter(Settings *const argSettings, + QWidget *argParent = nullptr); ~LocalzLeafStarter() override; signals: @@ -41,6 +44,7 @@ signals: int argzTreePort); private: + Settings *const settings = nullptr; Ui::LocalzLeafStarter *const ui = nullptr; private slots: diff --git a/src/main.cpp b/src/main.cpp index da2f43e..e00d6db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) QApplication a{argc, argv}; settings = std::make_unique(QSettings{"Labcontrol", "Labcontrol"}); - lc::MainWindow w; + lc::MainWindow w{settings.get()}; w.show(); return a.exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b0fb33d..c5db45f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 Markus Prasser + * Copyright 2014-2018 Markus Prasser, Tobias Weiss * * This file is part of Labcontrol. * @@ -17,8 +17,6 @@ * along with Labcontrol. If not, see . */ -#include - #include #include #include @@ -28,70 +26,73 @@ #include "manualprintingsetup.h" #include "Lib/settings.h" -extern std::unique_ptr< lc::Settings > settings; - -lc::MainWindow::MainWindow( QWidget *argParent ) : - QMainWindow{ argParent }, - icons( static_cast< int >( icons_t::ICON_QUANTITY ) ), - ui{ new Ui::MainWindow } +lc::MainWindow::MainWindow(Settings *const argSettings, + QWidget *argParent) : + QMainWindow{argParent}, + icons(static_cast(icons_t::ICON_QUANTITY)), + settings{argSettings}, + ui{new Ui::MainWindow} { - ui->setupUi( this ); - lablib = new Lablib{ this }; + ui->setupUi(this); + lablib = new Lablib{settings, this}; LoadIconPixmaps(); SetupWidgets(); - if ( valid_items ) { - gui_update_timer = new QTimer{ this }; + if (valid_items) { + gui_update_timer = new QTimer{this}; connect( gui_update_timer, &QTimer::timeout, this, &MainWindow::UpdateClientsTableView ); - gui_update_timer->start( 500 ); + gui_update_timer->start(500); } - /* session actions */ + /* session actions */ // Add z-Tree versions to the corresponding combo box - ui->CBzTreeVersion->addItem( tr( "Please choose a version:" ) ); - ui->CBzTreeVersion->addItems( settings->installedZTreeVersions ); + ui->CBzTreeVersion->addItem(tr("Please choose a version:")); + ui->CBzTreeVersion->addItems(settings->installedZTreeVersions); // Add default path to the corresponding combo box - 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, &MainWindow::RequestNewDataTargetPath, - this, &MainWindow::GetNewDataTargetPath ); - - if ( settings->dvipsCmd.isEmpty() || settings->latexCmd.isEmpty() - || settings->lcDataDir.isEmpty() || settings->lprCmd.isEmpty() - || settings->postscriptViewer.isEmpty() || settings->ps2pdfCmd.isEmpty() - || settings->rmCmd.isEmpty() || settings->vncViewer.isEmpty() ) { - 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 ); + 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, &MainWindow::RequestNewDataTargetPath, + this, &MainWindow::GetNewDataTargetPath); + + if (settings->dvipsCmd.isEmpty() || settings->latexCmd.isEmpty() + || settings->lcDataDir.isEmpty() || settings->lprCmd.isEmpty() + || settings->postscriptViewer.isEmpty() || settings->ps2pdfCmd.isEmpty() + || settings->rmCmd.isEmpty() || settings->vncViewer.isEmpty()) { + 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 ); + ui->CBReceiptsHeader->addItems(settings->installedLaTeXHeaders); - if ( settings->defaultReceiptIndex - && settings->defaultReceiptIndex < ui->CBReceiptsHeader->count() ) { - ui->CBReceiptsHeader->setCurrentIndex( settings->defaultReceiptIndex ); + if (settings->defaultReceiptIndex + && settings->defaultReceiptIndex < ui->CBReceiptsHeader->count()) { + ui->CBReceiptsHeader->setCurrentIndex(settings->defaultReceiptIndex); } } } -lc::MainWindow::~MainWindow() { +lc::MainWindow::~MainWindow() +{ delete ui; delete valid_items; } -bool lc::MainWindow::CheckIfUserIsAdmin() { - if ( settings->localUserName.isEmpty() ) { - QMessageBox messageBox{ QMessageBox::Warning, tr( "User not detectable" ), - tr( "Your user name could not be queryed. The admin tab will be" - " disabled. You won't be able to perform administrative" - " actions but can conduct experiments normally." ), - QMessageBox::Ok }; +bool lc::MainWindow::CheckIfUserIsAdmin() +{ + if (settings->localUserName.isEmpty()) { + QMessageBox messageBox{QMessageBox::Warning, tr("User not detectable"), + tr("Your user name could not be queryed. The" + " admin tab will be disabled. You won't be" + " able to perform administrative actions" + " but can conduct experiments normally."), + QMessageBox::Ok}; messageBox.exec(); return false; } @@ -101,7 +102,8 @@ bool lc::MainWindow::CheckIfUserIsAdmin() { return lablib->CheckIfUserIsAdmin(); } -void lc::MainWindow::DisableDisfunctionalWidgets() { +void lc::MainWindow::DisableDisfunctionalWidgets() +{ const QStringList &zTreeEntries = settings->installedZTreeVersions; if ( zTreeEntries.isEmpty() ) { ui->CBClientNames->setEnabled( false ); @@ -145,13 +147,13 @@ void lc::MainWindow::DisableDisfunctionalWidgets() { // Disable 'PBShowORSEE', if 'orsee_command' was not set if ( settings->browserCmd.isEmpty() - || settings->orseeUrl.isEmpty() ) { + || settings->orseeUrl.isEmpty() ) { ui->PBShowORSEE->setEnabled( false ); } // Disable all widgets needless if 'public_key_path_user' or 'user_name_on_clients' was not set if ( settings->pkeyPathUser.isEmpty() - || settings->userNameOnClients.isEmpty() ) { + || settings->userNameOnClients.isEmpty() ) { ui->CBClientNames->setEnabled( false ); ui->LEFilePath->setEnabled( false ); ui->L_FakeName->setEnabled( false ); @@ -172,7 +174,7 @@ void lc::MainWindow::DisableDisfunctionalWidgets() { } if ( settings->pkeyPathRoot.isEmpty() - && settings->pkeyPathUser.isEmpty() ) { + && settings->pkeyPathUser.isEmpty() ) { ui->GBExecuteOnEveryClient->setEnabled( false ); ui->GBOptionsForAdminActions->setEnabled( false ); ui->PBOpenTerminal->setEnabled( false ); @@ -234,7 +236,7 @@ void lc::MainWindow::DisableDisfunctionalWidgets() { // Deactivate the webcam choosing interface if no webcams are available or the viewer is missing if ( settings->webcamDisplayCmd.isEmpty() - || settings->webcams.isEmpty() ) { + || settings->webcams.isEmpty() ) { ui->CBWebcamChooser->setEnabled( false ); ui->L_WebcamChooser->setEnabled( false ); } @@ -258,18 +260,19 @@ void lc::MainWindow::DisableDisfunctionalWidgets() { } } -void lc::MainWindow::LoadIconPixmaps() { +void lc::MainWindow::LoadIconPixmaps() +{ if ( settings->lcDataDir.isEmpty() ) { return; } const QStringList iconNames{ QStringList{} - << "unknown.png" - << "off.png" - << "down.png" - << "boot.png" - << "on.png" - << "zLeaf.png" }; + << "unknown.png" + << "off.png" + << "down.png" + << "boot.png" + << "on.png" + << "zLeaf.png" }; for ( int i = 0; i < ( int )icons_t::ICON_QUANTITY; i++ ) { if ( !icons[ i ].load( settings->lcDataDir + "/icons/" + iconNames[ i ] ) ) { @@ -280,7 +283,8 @@ void lc::MainWindow::LoadIconPixmaps() { } } -void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { +void lc::MainWindow::on_PBKillLocalzLeaf_clicked() +{ QString program{ settings->killallCmd }; QStringList arguments; arguments << "-I" << "-q" << "zleaf.exe"; @@ -297,21 +301,24 @@ void lc::MainWindow::on_PBKillLocalzLeaf_clicked() { qDebug() << program << arguments; } -void lc::MainWindow::on_PBPrintPaymentFileManually_clicked() { - ManualPrintingSetup *manPrint = new ManualPrintingSetup{ this }; - manPrint->setWindowFlags( Qt::Window ); +void lc::MainWindow::on_PBPrintPaymentFileManually_clicked() +{ + ManualPrintingSetup *manPrint = new ManualPrintingSetup{settings, this}; + manPrint->setWindowFlags(Qt::Window); manPrint->show(); - connect( manPrint, SIGNAL( destroyed( QObject* ) ), - manPrint, SLOT( deleteLater() ) ); - connect( manPrint, &ManualPrintingSetup::RequestReceiptsHandler, - this, &MainWindow::StartReceiptsHandler ); + connect(manPrint, SIGNAL(destroyed(QObject *)), + manPrint, SLOT(deleteLater())); + connect(manPrint, &ManualPrintingSetup::RequestReceiptsHandler, + this, &MainWindow::StartReceiptsHandler); } -void lc::MainWindow::on_PBRunzLeaf_clicked() { +void lc::MainWindow::on_PBRunzLeaf_clicked() +{ // Check if more than one client is selected and issue a warning message if so unsigned short int numberOfSelectedClients = 0; QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { + for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); + ++it ) { if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) { ++numberOfSelectedClients; } @@ -321,10 +328,11 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() { QMessageBox messageBox{ QMessageBox::Information, tr( "Too many clients selected" ), tr( "There are too many clients selected in the table view on the left. Please select only one." ), QMessageBox::Ok, this }; messageBox.exec(); } else { - const QString * const fakeName = new QString{ ui->CBClientNames->currentText() }; - for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { + const QString *const fakeName = new QString{ ui->CBClientNames->currentText() }; + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->StartZLeaf( fakeName ); } } @@ -332,13 +340,15 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() { } } -void lc::MainWindow::on_RBUseLocalUser_toggled(bool checked) { +void lc::MainWindow::on_RBUseLocalUser_toggled(bool checked) +{ if ( checked ) { qDebug() << "'RBUseLocalUser' got toggled."; } } -void lc::MainWindow::SetupWidgets() { +void lc::MainWindow::SetupWidgets() +{ // Fill the 'CBClientNames' with possible client names and the 'TVClients' with the clients if ( !settings->GetClients().isEmpty() ) { valid_items = new QVector< QStandardItem * >; @@ -370,7 +380,7 @@ void lc::MainWindow::SetupWidgets() { valid_items->squeeze(); } else { QMessageBox messageBox{ QMessageBox::Warning, tr( "Could not construct clients view" ), - tr( "The creation of the clients view failed. Please check the file '/etc/xdg/Labcontrol/Labcontrol.conf'." ), QMessageBox::Ok, this }; + tr( "The creation of the clients view failed. Please check the file '/etc/xdg/Labcontrol/Labcontrol.conf'." ), QMessageBox::Ok, this }; messageBox.exec(); ui->CBClientNames->setEnabled( false ); ui->GBClientActions->setEnabled( false ); @@ -443,21 +453,26 @@ void lc::MainWindow::SetupWidgets() { "along with Labcontrol. If not, see .\n\n\n" ); } -void lc::MainWindow::StartReceiptsHandler( QString argzTreeDataTargetPath, - bool argReceiptsForLocalClients, - QString argAnonymousReceiptsPlaceholder, - QString argLatexHeaderName, QString argDateString) { - ReceiptsHandler *recHand = new ReceiptsHandler{ argzTreeDataTargetPath, - argReceiptsForLocalClients, - argAnonymousReceiptsPlaceholder, - argLatexHeaderName, argDateString, this }; - connect( recHand, &ReceiptsHandler::PrintingFinished, - recHand, &ReceiptsHandler::deleteLater ); +void lc::MainWindow::StartReceiptsHandler(QString argzTreeDataTargetPath, + bool argReceiptsForLocalClients, + QString argAnonymousReceiptsPlaceholder, + QString argLatexHeaderName, + QString argDateString) +{ + const auto recHand = new ReceiptsHandler{settings, argzTreeDataTargetPath, + argReceiptsForLocalClients, + argAnonymousReceiptsPlaceholder, + argLatexHeaderName, + argDateString, this}; + connect(recHand, &ReceiptsHandler::PrintingFinished, + recHand, &ReceiptsHandler::deleteLater); } -void lc::MainWindow::UpdateClientsTableView() { +void lc::MainWindow::UpdateClientsTableView() +{ for ( auto s : *valid_items ) { - state_t state = static_cast< Client* >( s->data( Qt::UserRole ).value() )->GetClientState(); + state_t state = static_cast< Client * >( s->data( + Qt::UserRole ).value() )->GetClientState(); switch ( state ) { case state_t::RESPONDING: s->setBackground( QBrush( QColor( 128, 255, 128, 255 ) ) ); @@ -489,89 +504,103 @@ void lc::MainWindow::UpdateClientsTableView() { /* Experiment tab functions */ -void lc::MainWindow::on_PBBoot_clicked() { +void lc::MainWindow::on_PBBoot_clicked() +{ QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->Boot(); } } } -void lc::MainWindow::on_PBChooseFile_clicked() { +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()) { + if (file_dialog->exec()) { ui->LEFilePath->setText(file_dialog->selectedFiles().at(0)); qDebug() << "Chose file" << ui->LEFilePath->text() << "for beaming."; - } - else { + } else { ui->LEFilePath->setText( tr( "File choosing cancelled" ) ); qDebug() << "File choosing cancelled"; } delete file_dialog; } -void lc::MainWindow::on_PBBeamFile_clicked() { +void lc::MainWindow::on_PBBeamFile_clicked() +{ QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); const QString fileToBeam{ ui->LEFilePath->text() }; - if(fileToBeam == ""){ + 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 ); + //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!"); + // 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() { +void lc::MainWindow::on_PBShowORSEE_clicked() +{ lablib->ShowOrsee(); } -void lc::MainWindow::on_PBShowPreprints_clicked() { +void lc::MainWindow::on_PBShowPreprints_clicked() +{ lablib->ShowPreprints(); } -void lc::MainWindow::on_PBShutdown_clicked() { +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); + 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 ) { + 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 *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!"); + 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"; + qDebug() << "Canceled shutting down the selected clients"; } } -void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) { +void lc::MainWindow::on_CBWebcamChooser_activated( int argIndex ) +{ if ( argIndex != 0 ) { QString program{ settings->webcamDisplayCmd }; QStringList arguments; // Attention argIndex is NOT 0-based - arguments << settings->webcams[argIndex-1]; + arguments << settings->webcams[argIndex - 1]; qDebug() << "Webcam" << arguments << "will be opened"; QProcess showWebcamProcess; @@ -586,9 +615,10 @@ void lc::MainWindow::on_PBstartBrowser_clicked() QString argURL = ui->LEURL->text(); bool argFullscreen = ui->CBFullscreen->checkState(); QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->StartClientBrowser( &argURL, &argFullscreen ); } } @@ -598,12 +628,14 @@ void lc::MainWindow::on_PBstopBrowser_clicked() { // Confirmation dialog QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, "Confirm", "Really kill all selected browser instances?", QMessageBox::Yes|QMessageBox::No); + reply = QMessageBox::question(this, "Confirm", "Really kill all selected browser instances?", + QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->StopClientBrowser( ); } } @@ -616,9 +648,10 @@ void lc::MainWindow::on_PBstopBrowser_clicked() void lc::MainWindow::on_PBViewDesktopViewOnly_clicked() { QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->ShowDesktopViewOnly(); } } @@ -628,9 +661,10 @@ void lc::MainWindow::on_PBViewDesktopViewOnly_clicked() void lc::MainWindow::on_PBViewDesktopFullControl_clicked() { QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->ShowDesktopFullControl(); } } @@ -638,18 +672,21 @@ void lc::MainWindow::on_PBViewDesktopFullControl_clicked() /* Session tab functions */ -void lc::MainWindow::on_PBStartzLeaf_clicked() { +void lc::MainWindow::on_PBStartzLeaf_clicked() +{ QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->StartZLeaf( nullptr, ui->LEzLeafCommandline->text() ); } } } -void lc::MainWindow::on_PBStartLocalzLeaf_clicked() { - LocalzLeafStarter *localzLeafStarter = new LocalzLeafStarter{ this }; +void lc::MainWindow::on_PBStartLocalzLeaf_clicked() +{ + LocalzLeafStarter *localzLeafStarter = new LocalzLeafStarter{settings, this}; localzLeafStarter->setWindowFlags( Qt::Window ); localzLeafStarter->show(); connect( localzLeafStarter, &LocalzLeafStarter::LocalzLeafRequested, @@ -659,9 +696,10 @@ void lc::MainWindow::on_PBStartLocalzLeaf_clicked() { } void lc::MainWindow::StartLocalzLeaf( QString argzLeafName, QString argzLeafVersion, - int argzTreePort ) { + int argzTreePort ) +{ if ( settings->tasksetCmd.isEmpty() || settings->wineCmd.isEmpty() - || settings->zTreeInstDir.isEmpty() ) { + || settings->zTreeInstDir.isEmpty() ) { return; } @@ -673,7 +711,7 @@ void lc::MainWindow::StartLocalzLeaf( QString argzLeafName, QString argzLeafVers << "/server" << "127.0.0.1" << "/channel" << QString::number( argzTreePort - 7000 ) << "/name" << argzLeafName; if ( !settings->localzLeafSize.isEmpty() ) { - arguments << "/size" << QString{ settings->localzLeafSize }; + arguments << "/size" << QString{ settings->localzLeafSize }; } qDebug() << "Start local zLeaf:" << arguments; @@ -687,7 +725,8 @@ void lc::MainWindow::on_PBStopZtree_clicked() arguments << "-I" << "-q" << "ztree.exe"; // Confirmation dialog QMessageBox::StandardButton reply; - reply = QMessageBox::question(this, "Confirm", "Really kill all z-Tree instances?", QMessageBox::Yes|QMessageBox::No); + reply = QMessageBox::question(this, "Confirm", "Really kill all z-Tree instances?", + QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { // Kill all z-Tree processes QProcess killLocalzLeafProc; @@ -704,11 +743,11 @@ void lc::MainWindow::on_PBStopZtree_clicked() void lc::MainWindow::on_PBRecoverCrashedSession_clicked() { // TODO: Implement the functionality of the restore session script in here (no zenity script) - QProcess startProc; - startProc.setProcessEnvironment( QProcessEnvironment::systemEnvironment() ); - if ( !settings->restartCrashedSessionScript.isEmpty() ) { - startProc.startDetached( settings->restartCrashedSessionScript); - } + QProcess startProc; + startProc.setProcessEnvironment( QProcessEnvironment::systemEnvironment() ); + if ( !settings->restartCrashedSessionScript.isEmpty() ) { + startProc.startDetached( settings->restartCrashedSessionScript); + } } void lc::MainWindow::on_CBDataTargetPath_activated( int argIndex ) @@ -721,7 +760,8 @@ void lc::MainWindow::on_CBDataTargetPath_activated( int argIndex ) } // Open a folder chooser dialog for zTree data path -void lc::MainWindow::GetNewDataTargetPath() { +void lc::MainWindow::GetNewDataTargetPath() +{ QFileDialog fileDialog{ this }; fileDialog.setFileMode( QFileDialog::Directory ); fileDialog.setDirectory( QDir::homePath() ); @@ -749,7 +789,8 @@ void lc::MainWindow::on_ChBPrintanonymousreceipts_clicked() } // Start session button actions -void lc::MainWindow::on_PBStartSession_clicked() { +void lc::MainWindow::on_PBStartSession_clicked() +{ if ( ui->CBzTreeVersion->currentIndex() == 0 ) { QMessageBox::information( this, tr( "No z-Tree version chosen" ), @@ -759,7 +800,7 @@ void lc::MainWindow::on_PBStartSession_clicked() { } const QModelIndexList activatedItems = ui->TVClients->selectionModel()->selectedIndexes(); - if( !ui->ChBSessionWithoutAttachedClients->isChecked() ) { + if ( !ui->ChBSessionWithoutAttachedClients->isChecked() ) { if ( !activatedItems.length() ) { QMessageBox::information( this, tr( "Canceled, no clients were chosen" ), tr( "The start of a new session was canceled.\n" @@ -775,10 +816,10 @@ void lc::MainWindow::on_PBStartSession_clicked() { anonymousReceiptsPlaceholder = ui->CBReplaceParticipantNames->currentText(); } - QVector< Client* > associatedClients; + 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 *client = static_cast< Client * >( ( *cit ).data( Qt::UserRole ).value< void * >() ); client->SetSessionPort( ui->SBPort->value() ); client->SetzLeafVersion( ui->CBzTreeVersion->currentText() ); associatedClients.append( client ); @@ -786,21 +827,22 @@ void lc::MainWindow::on_PBStartSession_clicked() { } this->lablib->StartNewSession ( associatedClients, anonymousReceiptsPlaceholder, - ui->ChBReceiptsForLocalClients->isChecked(), - ui->CBReceiptsHeader->currentText(), - ui->CBDataTargetPath->currentText(), - static_cast< quint16 >( ui->SBPort->value() ), - ui->CBzTreeVersion->currentText() ); + ui->ChBReceiptsForLocalClients->isChecked(), + ui->CBReceiptsHeader->currentText(), + ui->CBDataTargetPath->currentText(), + static_cast< quint16 >( ui->SBPort->value() ), + ui->CBzTreeVersion->currentText() ); //Display the command line - QString cmd = this->lablib->getzLeafArgs( ui->SBPort->value(), ui->CBzTreeVersion->currentText()).join(" "); + QString cmd = this->lablib->getzLeafArgs( ui->SBPort->value(), + ui->CBzTreeVersion->currentText()).join(" "); ui->LEzLeafCommandline->setText(cmd); //Start z-Leaf on selected clients if checkbox is activated - if( ui->ChBautoStartClientZleaf->isChecked() ) { + 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 *client = static_cast< Client * >( ( *cit ).data( Qt::UserRole ).value< void * >() ); client->StartZLeaf( nullptr, cmd ); } } @@ -816,9 +858,10 @@ void lc::MainWindow::on_PBStartSession_clicked() { void lc::MainWindow::on_PBKillzLeaf_clicked() { QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->KillZLeaf(); } } @@ -826,9 +869,10 @@ void lc::MainWindow::on_PBKillzLeaf_clicked() /* Admin tab functions */ -void lc::MainWindow::on_PBOpenFilesystem_clicked() { +void lc::MainWindow::on_PBOpenFilesystem_clicked() +{ // Determine the correct user to be used - QString * userToBeUsed = nullptr; + QString *userToBeUsed = nullptr; if ( ui->RBUseUserRoot->isChecked() ) { userToBeUsed = new QString{ "root" }; } else { @@ -836,16 +880,18 @@ void lc::MainWindow::on_PBOpenFilesystem_clicked() { } QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->OpenFilesystem( userToBeUsed ); } } delete userToBeUsed; } -void lc::MainWindow::on_PBExecute_clicked() { +void lc::MainWindow::on_PBExecute_clicked() +{ // Get the command to be executed ... QString command = ui->CBCommandToExecute->currentText(); @@ -860,9 +906,10 @@ void lc::MainWindow::on_PBExecute_clicked() { 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 ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->OpenTerminal( command, ui->RBUseUserRoot->isChecked() ); } } @@ -870,7 +917,8 @@ void lc::MainWindow::on_PBExecute_clicked() { } // Issue open terminal call -void lc::MainWindow::on_PBOpenTerminal_clicked() { +void lc::MainWindow::on_PBOpenTerminal_clicked() +{ QString pkeyPathUser; if ( ui->RBUseUserRoot->isChecked() ) { pkeyPathUser = settings->pkeyPathRoot; @@ -878,9 +926,10 @@ void lc::MainWindow::on_PBOpenTerminal_clicked() { pkeyPathUser = settings->pkeyPathUser; } QModelIndexList activated_items = ui->TVClients->selectionModel()->selectedIndexes(); - for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) { + 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 *client = static_cast< Client * >( ( *it ).data( Qt::UserRole ).value< void * >() ); client->OpenTerminal( QString{}, ui->RBUseUserRoot->isChecked() ); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 154afef..b0753a6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 Markus Prasser + * Copyright 2014-2018 Markus Prasser, Tobias Weiss * * This file is part of Labcontrol. * @@ -43,16 +43,20 @@ namespace Ui { class MainWindow; } +class Settings; + //! The class containing the graphical user interface. /*! This class represents the graphical user interface and all connected functionality. */ -class MainWindow : public QMainWindow { +class MainWindow : public QMainWindow +{ Q_OBJECT public: - explicit MainWindow( QWidget *argParent = nullptr ); - ~MainWindow(); + explicit MainWindow(Settings *const argSettings, + QWidget *argParent = nullptr); + ~MainWindow() override; private slots: void on_CBWebcamChooser_activated(int index); @@ -85,10 +89,10 @@ private slots: signals: /*Session actions*/ void RequestNewDataTargetPath(); - void RequestNewSession( QVector< Client* > argAssocCl, QString argParticipNameReplacement, - bool argPrintLocalReceipts, QString argReceiptsHeader, - QString argzTreeDataTargetPath, quint16 argzTreePort, - QString argzTreeVersion ); + void RequestNewSession(QVector argAssocCl, QString argParticipNameReplacement, + bool argPrintLocalReceipts, QString argReceiptsHeader, + QString argzTreeDataTargetPath, quint16 argzTreePort, + QString argzTreeVersion); private: //! Checks, if the user has administrative rights @@ -103,21 +107,31 @@ private: //! Sets up all used widgets void SetupWidgets(); - QStandardItemModel *clients_view_model = nullptr; //! The view storing all clients data - 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 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()' + //! The view storing all clients data + QStandardItemModel *clients_view_model = nullptr; + //! A QTimer triggering updates of the graphical user interface + QTimer *gui_update_timer = nullptr; + //! Vector of pixmaps storing the icons indicating the clients' statuses + QVector icons; + //! Accumulator of all program logic being accessed by the GUI + Lablib *lablib = nullptr; + //! Stores if a local z-Leaf instance is running on the server ('true' if local z-Leaf exists) + bool localzLeavesAreRunning = false; + Settings *const settings = nullptr; + //! Used to group the radio buttons choosing which user shall be used for administrative client actions + QButtonGroup *userChooseButtonGroup = nullptr; + //! Pointer storing all GUI items + Ui::MainWindow *const ui = nullptr; + //! Stores all valid Client instances displayed by the table view, its main use is as iterable object for 'update_clients_table_view()' + QVector *valid_items = nullptr; private slots: - void StartReceiptsHandler( QString argzTreeDataTargetPath, - bool argReceiptsForLocalClients, - QString argAnonymousReceiptsPlaceholder, - QString argLatexHeaderName, - QString argDateString ); + void StartReceiptsHandler(QString argzTreeDataTargetPath, + bool argReceiptsForLocalClients, + QString argAnonymousReceiptsPlaceholder, + QString argLatexHeaderName, + QString argDateString + ); void on_PBstartBrowser_clicked(); void on_PBstopBrowser_clicked(); @@ -125,12 +139,12 @@ private slots: void on_PBStopZtree_clicked(); void on_PBRecoverCrashedSession_clicked(); void GetNewDataTargetPath(); - void on_CBDataTargetPath_activated( int argIndex ); + void on_CBDataTargetPath_activated(int argIndex); void on_CBReceiptsHeader_activated(int argIndex); void on_ChBPrintanonymousreceipts_clicked(); void on_PBKillzLeaf_clicked(); }; -} +} // namespace lc #endif // MAINWINDOW_H diff --git a/src/manualprintingsetup.cpp b/src/manualprintingsetup.cpp index 30ed20c..f143199 100644 --- a/src/manualprintingsetup.cpp +++ b/src/manualprintingsetup.cpp @@ -17,13 +17,6 @@ * along with Labcontrol. If not, see . */ -/* #include "manualprintingsetup.h" -#include "ui_manualprintingsetup.h" -#include "Lib/settings.h" - -#include - */ - #include "manualprintingsetup.h" #include "ui_manualprintingsetup.h" #include "Lib/settings.h" @@ -33,10 +26,10 @@ #include -extern std::unique_ptr settings; - -lc::ManualPrintingSetup::ManualPrintingSetup(QWidget *argParent) : +lc::ManualPrintingSetup::ManualPrintingSetup(const Settings *const argSettings, + QWidget *argParent) : QWidget{argParent}, + settings{argSettings}, ui{new Ui::ManualPrintingSetup} { ui->setupUi(this); diff --git a/src/manualprintingsetup.h b/src/manualprintingsetup.h index 3561983..b4de0d5 100644 --- a/src/manualprintingsetup.h +++ b/src/manualprintingsetup.h @@ -28,12 +28,15 @@ namespace Ui { class ManualPrintingSetup; } // namespace Ui +class Settings; + class ManualPrintingSetup : public QWidget { Q_OBJECT public: - explicit ManualPrintingSetup(QWidget *argParent = nullptr); + explicit ManualPrintingSetup(const Settings *const argSettings, + QWidget *argParent = nullptr); ~ManualPrintingSetup() override; signals: @@ -45,6 +48,7 @@ signals: private: QString dateString; + const Settings *const settings = nullptr; Ui::ManualPrintingSetup *const ui = nullptr; QString workPath;