From 868458ea427812ac965488a7f44a0a4032f6612d Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 23 Sep 2016 00:57:51 +0200 Subject: [PATCH] Utilized global accessible 'settings' object in 'Lablib' class --- src/Lib/clienthelpnotificationserver.cpp | 4 +-- src/Lib/clienthelpnotificationserver.h | 2 +- src/Lib/lablib.cpp | 35 ++++++++++++++---------- src/Lib/netstatagent.cpp | 4 +-- src/Lib/netstatagent.h | 4 +-- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Lib/clienthelpnotificationserver.cpp b/src/Lib/clienthelpnotificationserver.cpp index ec1132f..11a4b6b 100644 --- a/src/Lib/clienthelpnotificationserver.cpp +++ b/src/Lib/clienthelpnotificationserver.cpp @@ -20,10 +20,10 @@ #include "clienthelpnotificationserver.h" lc::ClientHelpNotificationServer::ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap, - const QString * const argServerIP, const unsigned short int &argServerPort, QObject *argParent ) : + const QString &argServerIP, const unsigned short int &argServerPort, QObject *argParent ) : QObject{ argParent }, clientIPsToClientsMap{ argClientIPsToClientsMap }, - hostAddress{ *argServerIP }, + hostAddress{ argServerIP }, serverPort{ argServerPort } { QNetworkConfigurationManager manager; diff --git a/src/Lib/clienthelpnotificationserver.h b/src/Lib/clienthelpnotificationserver.h index c6c4cef..e525ffe 100644 --- a/src/Lib/clienthelpnotificationserver.h +++ b/src/Lib/clienthelpnotificationserver.h @@ -33,7 +33,7 @@ class ClientHelpNotificationServer : public QObject { Q_OBJECT public: explicit ClientHelpNotificationServer( const QMap< QString, Client* > * const argClientIPsToClientsMap, - const QString * const argServerIP, const unsigned short int &argServerPort, QObject *argParent = nullptr ); + const QString &argServerIP, const unsigned short int &argServerPort, QObject *argParent = nullptr ); signals: diff --git a/src/Lib/lablib.cpp b/src/Lib/lablib.cpp index 92f8409..04c0e41 100644 --- a/src/Lib/lablib.cpp +++ b/src/Lib/lablib.cpp @@ -42,8 +42,8 @@ lc::Lablib::Lablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent DetectInstalledZTreeVersionsAndLaTeXHeaders(); // Initialize all 'netstat' query mechanisms - if ( ( *settingsItems )[ ( int )settItms_t::NETSTAT_CMD ] ) { - netstatAgent = new NetstatAgent{ ( *settingsItems )[ ( int )settItms_t::NETSTAT_CMD ] }; + if ( !settings->netstatCmd.isEmpty() ) { + netstatAgent = new NetstatAgent{ settings->netstatCmd }; netstatAgent->moveToThread( &netstatThread ); connect( &netstatThread, &QThread::finished, netstatAgent, &QObject::deleteLater ); connect( netstatAgent, &NetstatAgent::QueryFinished, @@ -56,8 +56,11 @@ lc::Lablib::Lablib( QPlainTextEdit *argDebugMessagesTextEdit, QObject *argParent } // Initialize the server for client help requests retrieval - if ( clientHelpNotificationServerPort && ( *settingsItems )[ ( int )settItms_t::SERVER_IP ] ) { - clientHelpNotificationServer = new ClientHelpNotificationServer{ clientIPsToClientsMap,( *settingsItems )[ ( int )settItms_t::SERVER_IP ], clientHelpNotificationServerPort, this }; + if ( clientHelpNotificationServerPort && !settings->serverIP.isEmpty() ) { + clientHelpNotificationServer = new ClientHelpNotificationServer{ clientIPsToClientsMap, + settings->serverIP, + clientHelpNotificationServerPort, + this }; } } @@ -86,16 +89,17 @@ lc::Lablib::~Lablib () { void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() { // Detect the installed LaTeX headers - if ( ( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ) { - QDir laTeXDirectory{ *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ], "*header.tex", QDir::Name, QDir::CaseSensitive | QDir::Files | QDir::Readable }; + if ( !settings->lcInstDir.isEmpty() ) { + QDir laTeXDirectory{ settings->lcInstDir, "*header.tex", QDir::Name, + QDir::CaseSensitive | QDir::Files | QDir::Readable }; if ( !laTeXDirectory.exists() || laTeXDirectory.entryList().isEmpty() ) { QMessageBox messageBox{ QMessageBox::Critical, tr( "No LaTeX headers found" ), tr( "No LaTeX headers could be found in '%1'. Receipts printing will not work" ) - .arg( *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ), QMessageBox::Ok }; + .arg( settings->lcInstDir ), QMessageBox::Ok }; messageBox.exec(); installedLaTeXHeaders = new QStringList{ "None found" }; debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No LaTeX headers could be found in '%1'." ) - .arg( *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] ) ); + .arg( settings->lcInstDir ) ); } else { installedLaTeXHeaders = new QStringList{ laTeXDirectory.entryList() }; installedLaTeXHeaders->replaceInStrings( "_header.tex", "" ); @@ -104,15 +108,18 @@ void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() { } // Detect the installed zTree versions - if ( ( *settingsItems )[ ( int )settItms_t::ZTREE_INST_DIR ] ) { - QDir zTreeDirectory{ *( *settingsItems )[ ( int )settItms_t::ZTREE_INST_DIR ], "zTree*", QDir::Name, QDir::NoDotAndDotDot | QDir::Dirs | QDir::Readable | QDir::CaseSensitive }; + 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( *( *settingsItems )[ ( int )settItms_t::ZTREE_INST_DIR ] ), QMessageBox::Ok }; + .arg( settings->zTreeInstDir ), QMessageBox::Ok }; messageBox.exec(); - debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No zTree versions could be found in '%1'." ).arg( *( *settingsItems )[ ( int )settItms_t::ZTREE_INST_DIR ] ) ); + debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] No zTree versions could be found in '%1'." ) + .arg( settings->zTreeInstDir ) ); } else { InstalledZTreeVersions = new QStringList{ zTreeDirectory.entryList() }; @@ -323,8 +330,8 @@ void lc::Lablib::ShowPreprints() { QProcess showPreprintsProcess; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); showPreprintsProcess.setProcessEnvironment( env ); - QString program{ *( *settingsItems )[ ( int )settItms_t::FILE_MANAGER ] }; - QStringList arguments{ QStringList{} << *( *settingsItems )[ ( int )settItms_t::LC_INST_DIR ] + "/preprints" }; + QString program{ settings->fileMngr }; + QStringList arguments{ QStringList{} << settings->lcInstDir + "/preprints" }; showPreprintsProcess.startDetached( program, arguments ); // Output message via the debug messages tab diff --git a/src/Lib/netstatagent.cpp b/src/Lib/netstatagent.cpp index 8c00eb8..44caed5 100644 --- a/src/Lib/netstatagent.cpp +++ b/src/Lib/netstatagent.cpp @@ -19,11 +19,11 @@ #include "netstatagent.h" -lc::NetstatAgent::NetstatAgent( QString *argNetstatCommand, QObject *argParent ) : +lc::NetstatAgent::NetstatAgent( const QString &argNetstatCommand, QObject *argParent ) : QObject{ argParent }, extractionRegexp{ "\\d+\\.\\d+\\.\\d+\\.\\d+" }, netstatArguments{ QStringList{} << "-anp" << "--tcp" }, - netstatCommand{ *argNetstatCommand }, + netstatCommand{ argNetstatCommand }, netstatQueryProcess{ this }, searchRegexp{ "\\W(ESTABLISHED|VERBUNDEN)( +)(\\d+)(/ztree.exe)\\W", QRegularExpression::CaseInsensitiveOption } { diff --git a/src/Lib/netstatagent.h b/src/Lib/netstatagent.h index 8d4ae41..f295c6b 100644 --- a/src/Lib/netstatagent.h +++ b/src/Lib/netstatagent.h @@ -35,7 +35,7 @@ class NetstatAgent : public QObject { Q_OBJECT public: - explicit NetstatAgent( QString *argNetstatCommand, QObject *argParent = nullptr ); + explicit NetstatAgent( const QString &argNetstatCommand, QObject *argParent = nullptr ); signals: //! This signal is emitted if the query of the currently active zLeaf connections finished @@ -47,7 +47,7 @@ public slots: private: const QRegularExpression extractionRegexp; const QStringList netstatArguments; - const QString netstatCommand; + const QString &netstatCommand; QProcess netstatQueryProcess; const QRegularExpression searchRegexp; };