From 6c4620803352498f4fff1c4e28e0a0d2443a61f8 Mon Sep 17 00:00:00 2001 From: markuspg Date: Mon, 26 Sep 2016 23:42:17 +0200 Subject: [PATCH] Moved 'installedZTreeVersions' into 'lc::Settings' --- src/Lib/lablib.cpp | 23 ----------------------- src/Lib/lablib.h | 6 ------ src/Lib/settings.cpp | 19 +++++++++++++++++++ src/Lib/settings.h | 2 ++ src/mainwindow.cpp | 6 +++--- src/sessionstarter.cpp | 11 ++++++++--- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/Lib/lablib.cpp b/src/Lib/lablib.cpp index 44c815d..ed7e8a7 100644 --- a/src/Lib/lablib.cpp +++ b/src/Lib/lablib.cpp @@ -71,7 +71,6 @@ lc::Lablib::~Lablib () { } } delete clients; - delete InstalledZTreeVersions; delete occupiedPorts; } @@ -106,28 +105,6 @@ void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() { debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] LaTeX headers: %1" ).arg( installedLaTeXHeaders->join( " / " ) ) ); } } - - // Detect the installed zTree versions - if ( !settings->zTreeInstDir.isEmpty() ) { - QDir zTreeDirectory{ settings->zTreeInstDir, "zTree*", QDir::Name, - QDir::NoDotAndDotDot | QDir::Dirs - | QDir::Readable | QDir::CaseSensitive }; - if ( zTreeDirectory.entryList().isEmpty() ) { - QMessageBox messageBox{ QMessageBox::Critical, tr( "zTree not found" ), - tr( "No zTree installation found in '%1'. Running zTree will not be possible." ) - .arg( settings->zTreeInstDir ), QMessageBox::Ok }; - messageBox.exec(); - - debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No zTree versions could be found in '%1'." ) - .arg( settings->zTreeInstDir ) ); - } - else { - InstalledZTreeVersions = new QStringList{ zTreeDirectory.entryList() }; - InstalledZTreeVersions->replaceInStrings( "zTree_", "" ); - - debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] zTree versions: %1" ).arg( InstalledZTreeVersions->join( " / " ) ) ) ; - } - } } void lc::Lablib::GotNetstatQueryResult( QStringList *argActiveZLeafConnections ) { diff --git a/src/Lib/lablib.h b/src/Lib/lablib.h index b74f8f7..7fbd416 100644 --- a/src/Lib/lablib.h +++ b/src/Lib/lablib.h @@ -112,11 +112,6 @@ public: * @return A pointer to a QStringList containing all available LaTeX headers */ QStringList *GetInstalledLaTeXHeaders () const {return installedLaTeXHeaders; } - /** Returns a QStringList containing all available zTree versions of this system - * - * @return A pointer to a QStringList containing all available zTree versions - */ - QStringList *GetInstalledZTreeVersions () const { return InstalledZTreeVersions; } void SetChosenZTreeDataTargetPath( const QString &argZTreeDataTargetPath ); void SetChosenZTreePort( const int &argPort ); //! Sets the default name of local zLeaf instances @@ -157,7 +152,6 @@ private: QPlainTextEdit *debugMessagesTextEdit = nullptr; //! This stores a pointer to the text edit in the debug tab to be able to write to it int defaultReceiptIndex = 0; //! Stores the index of the LaTeX header to be displayed by default QStringList *installedLaTeXHeaders = nullptr; - QStringList *InstalledZTreeVersions = nullptr; QSettings labSettings; NetstatAgent *netstatAgent = nullptr; //! Tries to detect active zLeaf connections from the clients QThread netstatThread; diff --git a/src/Lib/settings.cpp b/src/Lib/settings.cpp index 86fbde5..7aba065 100644 --- a/src/Lib/settings.cpp +++ b/src/Lib/settings.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -90,11 +91,13 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) : zTreeInstDir{ ReadSettingsItem( "ztree_installation_directory", "zTree will not be available.", argSettings, true ) }, + installedZTreeVersions{ DetectInstalledzTreeVersions() }, localzLeafName{ ReadSettingsItem( "local_zLeaf_name", "The local zLeaf default name will default to 'local'.", argSettings, false ) } { qDebug() << "The following webcams where loaded:" << webcams; + qDebug() << "Detected z-Tree versions" << installedZTreeVersions; } bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString &argVariableName, @@ -108,6 +111,22 @@ bool lc::Settings::CheckPathAndComplain( const QString &argPath, const QString & return true; } +QStringList lc::Settings::DetectInstalledzTreeVersions() const { + QStringList tempInstzTreeVersions; + if ( !zTreeInstDir.isEmpty() ) { + QDir zTreeDirectory{ zTreeInstDir, "zTree_*", QDir::Name, + QDir::NoDotAndDotDot | QDir::Dirs + | QDir::Readable | QDir::CaseSensitive }; + if ( zTreeDirectory.entryList().isEmpty() ) { + qWarning() << "No zTree versions could be found in" << zTreeInstDir; + } else { + tempInstzTreeVersions = zTreeDirectory.entryList(); + tempInstzTreeVersions.replaceInStrings( "zTree_", "" ); + } + } + return tempInstzTreeVersions; +} + QString lc::Settings::GetLocalUserName() { const QProcessEnvironment env{ QProcessEnvironment::systemEnvironment() }; QString userName; diff --git a/src/Lib/settings.h b/src/Lib/settings.h index 446ad61..7170e5d 100644 --- a/src/Lib/settings.h +++ b/src/Lib/settings.h @@ -49,10 +49,12 @@ public: const QString wmctrlCmd; const QString xsetCmd; const QString zTreeInstDir; + const QStringList installedZTreeVersions; private: static bool CheckPathAndComplain( const QString &argPath, const QString &argVariableName, const QString &argMessage ); + QStringList DetectInstalledzTreeVersions() const; static QString GetLocalUserName(); static QString ReadSettingsItem( const QString &argVariableName, const QString &argMessage, diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 84203dc..8602adc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -654,8 +654,8 @@ void lc::MainWindow::SetupWidgets() { } clients = nullptr; - const QStringList *zTreeEntries = lablib->GetInstalledZTreeVersions(); - if ( zTreeEntries == nullptr ) { + const QStringList &zTreeEntries = settings->installedZTreeVersions; + if ( zTreeEntries.isEmpty() ) { ui->CBClientNames->setEnabled( false ); ui->GBzTree->setEnabled( false ); ui->GLzLeafSettings->setEnabled( false ); @@ -665,7 +665,7 @@ void lc::MainWindow::SetupWidgets() { ui->PBStartzLeaf->setEnabled( false ); } else { ui->CBzLeafVersion->addItem( "NONE" ); - for ( auto zTreeVersionString : *zTreeEntries ) { + for ( const auto &zTreeVersionString : zTreeEntries ) { ui->CBzLeafVersion->addItem( zTreeVersionString ); } ui->CBzLeafVersion->setCurrentIndex( 0 ); diff --git a/src/sessionstarter.cpp b/src/sessionstarter.cpp index 08afdc1..51436ab 100644 --- a/src/sessionstarter.cpp +++ b/src/sessionstarter.cpp @@ -17,8 +17,13 @@ * along with Labcontrol. If not, see . */ +#include + #include "sessionstarter.h" #include "ui_sessionstarter.h" +#include "Lib/settings.h" + +extern std::unique_ptr< lc::Settings > settings; lc::SessionStarter::SessionStarter( Lablib *argLablib, QPlainTextEdit *argDebugMessagesTextEdit, QWidget *parent ) : QWidget{ parent }, @@ -106,9 +111,9 @@ void lc::SessionStarter::SetupWidgets() { // Fill the 'CBzTreeVersion' combobox with known entries from the lablib class ui->CBzTreeVersion->addItem( "NONE" ); - const QStringList * const zTreeEntries = lablib->GetInstalledZTreeVersions(); - if ( !( zTreeEntries == nullptr ) ) { - for ( auto zTreeVersionString : *zTreeEntries ) { + const QStringList &zTreeEntries = settings->installedZTreeVersions; + if ( !zTreeEntries.isEmpty() ) { + for ( const auto &zTreeVersionString : zTreeEntries ) { ui->CBzTreeVersion->addItem( zTreeVersionString ); } ui->CBzTreeVersion->setCurrentIndex( 0 );