From a23fad0ba8e16cf0adc8d6d8107b6777956fb71e Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 15 Jun 2020 12:12:19 +0100 Subject: [PATCH] Tidy up some code to keep SonarQube happy. --- runtime/ConfigWindow.cpp | 8 ++------ runtime/ConfigWindow.h | 1 - runtime/FloatingWindow.cpp | 21 +++++++++---------- runtime/FloatingWindow.h | 1 - runtime/LogWindow.cpp | 21 +++++++------------ runtime/LogWindow.h | 2 -- runtime/Logger.h | 1 - runtime/MenuActions.cpp | 18 ++++++----------- runtime/MenuActions.h | 4 ++-- runtime/Server.cpp | 41 +++++++++++++++++++------------------- runtime/TrayIcon.cpp | 22 ++++++++------------ runtime/TrayIcon.h | 1 - 12 files changed, 55 insertions(+), 86 deletions(-) diff --git a/runtime/ConfigWindow.cpp b/runtime/ConfigWindow.cpp index c8c06e59e..c5722e660 100644 --- a/runtime/ConfigWindow.cpp +++ b/runtime/ConfigWindow.cpp @@ -13,16 +13,12 @@ #include "ui_ConfigWindow.h" ConfigWindow::ConfigWindow(QWidget *parent) : - QDialog(parent), - ui(new Ui::ConfigWindow) + QDialog(parent) { + ui = new Ui::ConfigWindow; ui->setupUi(this); } -ConfigWindow::~ConfigWindow() -{ - delete ui; -} void ConfigWindow::on_buttonBox_accepted() { diff --git a/runtime/ConfigWindow.h b/runtime/ConfigWindow.h index cafb9a14f..c7bbcbdcb 100644 --- a/runtime/ConfigWindow.h +++ b/runtime/ConfigWindow.h @@ -24,7 +24,6 @@ class ConfigWindow : public QDialog public: explicit ConfigWindow(QWidget *parent = Q_NULLPTR); - ~ConfigWindow(); QString getBrowserCommand(); bool getFixedPort(); diff --git a/runtime/FloatingWindow.cpp b/runtime/FloatingWindow.cpp index 6e2f2348a..70f3212f3 100644 --- a/runtime/FloatingWindow.cpp +++ b/runtime/FloatingWindow.cpp @@ -9,27 +9,24 @@ // //////////////////////////////////////////////////////////////////////////// + #include "FloatingWindow.h" #include "ui_FloatingWindow.h" + FloatingWindow::FloatingWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::FloatingWindow) + m_newAction(Q_NULLPTR), + m_configAction(Q_NULLPTR), + m_logAction(Q_NULLPTR), + m_quitAction(Q_NULLPTR), + m_floatingWindowMenu(Q_NULLPTR), + m_menuActions(Q_NULLPTR) { - m_newAction = Q_NULLPTR; - m_configAction = Q_NULLPTR; - m_logAction = Q_NULLPTR; - m_quitAction = Q_NULLPTR; - m_menuActions = Q_NULLPTR; - m_floatingWindowMenu = Q_NULLPTR; - + ui = new Ui::FloatingWindow; ui->setupUi(this); } -FloatingWindow::~FloatingWindow() -{ - delete ui; -} bool FloatingWindow::Init() { diff --git a/runtime/FloatingWindow.h b/runtime/FloatingWindow.h index 8b91bf5ce..868d1a0dc 100644 --- a/runtime/FloatingWindow.h +++ b/runtime/FloatingWindow.h @@ -28,7 +28,6 @@ class FloatingWindow : public QMainWindow public: explicit FloatingWindow(QWidget *parent = Q_NULLPTR); - ~FloatingWindow(); bool Init(); void enableShutdownMenu(); diff --git a/runtime/LogWindow.cpp b/runtime/LogWindow.cpp index 748468004..85d576f91 100644 --- a/runtime/LogWindow.cpp +++ b/runtime/LogWindow.cpp @@ -19,22 +19,17 @@ LogWindow::LogWindow(QWidget *parent, QString serverLogFile) : QDialog(parent), - ui(new Ui::LogWindow), m_serverLogFile(serverLogFile) { + ui = new Ui::LogWindow; ui->setupUi(this); } -LogWindow::~LogWindow() -{ - delete ui; -} - - void LogWindow::LoadLog() { - int startupLines, serverLines; + int startupLines; + int serverLines; ui->lblStatus->setText(tr("Loading logfiles...")); @@ -57,7 +52,8 @@ int LogWindow::readLog(QString logFile, QPlainTextEdit *logWidget) FILE *log; char *buffer; long len = 0; - int i, lines = 0; + int i; + int lines = 0; // Look busy! QApplication::setOverrideCursor(Qt::WaitCursor); @@ -83,11 +79,8 @@ int LogWindow::readLog(QString logFile, QPlainTextEdit *logWidget) buffer = static_cast(malloc((len + 1) * sizeof(char))); for (i = 0; i < len; i++) { - if (fread(buffer + i, 1, 1, log) > 0) - { - if (buffer[i] == '\n') - lines++; - } + if (fread(buffer + i, 1, 1, log) > 0 && buffer[i] == '\n') + lines++; } buffer[i] = 0; diff --git a/runtime/LogWindow.h b/runtime/LogWindow.h index 2ff1c2ebf..50bba3bfd 100644 --- a/runtime/LogWindow.h +++ b/runtime/LogWindow.h @@ -25,8 +25,6 @@ class LogWindow : public QDialog public: explicit LogWindow(QWidget *parent = Q_NULLPTR, QString serverLogFile = ""); - ~LogWindow(); - void LoadLog(); private slots: diff --git a/runtime/Logger.h b/runtime/Logger.h index c97aa8832..5ff25a269 100644 --- a/runtime/Logger.h +++ b/runtime/Logger.h @@ -26,7 +26,6 @@ private: Logger(); virtual ~Logger(); -private: static Logger* m_pThis; static QString m_sFileName; static QFile *m_Logfile; diff --git a/runtime/MenuActions.cpp b/runtime/MenuActions.cpp index e4013855e..79d5497d8 100644 --- a/runtime/MenuActions.cpp +++ b/runtime/MenuActions.cpp @@ -15,16 +15,13 @@ #include #include -MenuActions::MenuActions() +MenuActions::MenuActions(): + m_appServerUrl(""), + m_logFile(""), + m_logWindow(Q_NULLPTR) { - m_logWindow = Q_NULLPTR; - m_logFile = ""; - m_appServerUrl = ""; } -MenuActions::~MenuActions() -{ -} void MenuActions::setAppServerUrl(QString appServerUrl) { @@ -106,12 +103,9 @@ void MenuActions::onConfig() settings.setValue("PythonPath", pythonpath); settings.setValue("ApplicationPath", applicationpath); - if (needRestart) + if (needRestart && QMessageBox::Yes == QMessageBox::question(Q_NULLPTR, tr("Shut down server?"), QString(tr("The %1 server must be restarted for changes to take effect. Do you want to shut down the server now?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) { - if (QMessageBox::Yes == QMessageBox::question(Q_NULLPTR, tr("Shut down server?"), QString(tr("The %1 server must be restarted for changes to take effect. Do you want to shut down the server now?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) - { - exit(0); - } + exit(0); } } } diff --git a/runtime/MenuActions.h b/runtime/MenuActions.h index 2d9403712..a1728cedf 100644 --- a/runtime/MenuActions.h +++ b/runtime/MenuActions.h @@ -23,14 +23,14 @@ class MenuActions: public QObject Q_OBJECT public: MenuActions(); - ~MenuActions(); void setAppServerUrl(QString appServerUrl); void setLogFile(QString logFile); QString getAppServerUrl() { return m_appServerUrl; } private: - QString m_appServerUrl, m_logFile; + QString m_appServerUrl; + QString m_logFile; LogWindow *m_logWindow; protected slots: diff --git a/runtime/Server.cpp b/runtime/Server.cpp index f053cbb00..76bf45ada 100644 --- a/runtime/Server.cpp +++ b/runtime/Server.cpp @@ -55,15 +55,13 @@ static void add_to_path(QString &python_path, QString path, bool prepend=false) } } -Server::Server(quint16 port, QString key, QString logFileName) +Server::Server(quint16 port, QString key, QString logFileName): + m_port(port), + m_key(key), + m_logFileName(logFileName), + m_wcAppName(Q_NULLPTR), + m_wcPythonHome(Q_NULLPTR) { - // Appserver port etc - m_port = port; - m_key = key; - m_logFileName = logFileName; - m_wcAppName = Q_NULLPTR; - m_wcPythonHome = Q_NULLPTR; - // Initialise Python Py_NoSiteFlag=1; Py_NoUserSiteDirectory=1; @@ -72,7 +70,7 @@ Server::Server(quint16 port, QString key, QString logFileName) PGA_APP_NAME_UTF8 = PGA_APP_NAME.toUtf8(); // Python3 requires conversion of char * to wchar_t *, so... - char *appName = PGA_APP_NAME_UTF8.data(); + const char *appName = PGA_APP_NAME_UTF8.data(); const size_t cSize = strlen(appName)+1; m_wcAppName = new wchar_t[cSize]; mbstowcs (m_wcAppName, appName, cSize); @@ -83,9 +81,9 @@ Server::Server(quint16 port, QString key, QString logFileName) QString python_path = settings.value("PythonPath").toString(); // Get the application directory - QString app_dir = qApp->applicationDirPath(), - path_env = qgetenv("PATH"), - pythonHome; + QString app_dir = qApp->applicationDirPath(); + QString path_env = qgetenv("PATH"); + QString pythonHome; QStringList path_list; int i; @@ -179,10 +177,10 @@ Server::Server(quint16 port, QString key, QString logFileName) if (!pythonHome.isEmpty()) { pythonHome_utf8 = pythonHome.toUtf8(); - char *python_home = pythonHome_utf8.data(); - const size_t cSize = strlen(python_home) + 1; - m_wcPythonHome = new wchar_t[cSize]; - mbstowcs (m_wcPythonHome, python_home, cSize); + const char *python_home = pythonHome_utf8.data(); + const size_t home_size = strlen(python_home) + 1; + m_wcPythonHome = new wchar_t[home_size]; + mbstowcs (m_wcPythonHome, python_home, home_size); Py_SetPythonHome(m_wcPythonHome); } @@ -334,7 +332,7 @@ void Server::run() * which might allow local users to execute arbitrary code via a Trojan horse Python file in the current working directory. * Here we have to set arguments explicitly to python interpreter. Check more details in 'PySys_SetArgv' documentation. */ - char *appName = m_appfile_utf8.data(); + const char *appName = m_appfile_utf8.data(); const size_t cSize = strlen(appName)+1; wchar_t* wcAppName = new wchar_t[cSize]; mbstowcs (wcAppName, appName, cSize); @@ -353,12 +351,15 @@ void Server::run() void Server::shutdown(QUrl url) { - bool shotdown = shutdownServer(url); - if (!shotdown) + if (!shutdownServer(url)) setError(tr("Failed to shut down application server thread.")); QThread::quit(); QThread::wait(); - while(!this->isFinished()){} + while(!this->isFinished()) + { + Logger::GetLogger()->Log("Waiting for server to shut down."); + delay(250); + } } diff --git a/runtime/TrayIcon.cpp b/runtime/TrayIcon.cpp index 9e583eac0..075e6df23 100644 --- a/runtime/TrayIcon.cpp +++ b/runtime/TrayIcon.cpp @@ -12,21 +12,15 @@ // App headers #include "TrayIcon.h" -TrayIcon::TrayIcon() +TrayIcon::TrayIcon(): + m_newAction(Q_NULLPTR), + m_configAction(Q_NULLPTR), + m_logAction(Q_NULLPTR), + m_quitAction(Q_NULLPTR), + m_trayIcon(Q_NULLPTR), + m_trayIconMenu(Q_NULLPTR), + m_menuActions(Q_NULLPTR) { - m_trayIcon = Q_NULLPTR; - m_trayIconMenu = Q_NULLPTR; - - m_newAction = Q_NULLPTR; - m_configAction = Q_NULLPTR; - m_logAction = Q_NULLPTR; - m_quitAction = Q_NULLPTR; - m_menuActions = Q_NULLPTR; -} - -TrayIcon::~TrayIcon() -{ - } void TrayIcon::Init() diff --git a/runtime/TrayIcon.h b/runtime/TrayIcon.h index 5c84e414b..a9709cae8 100644 --- a/runtime/TrayIcon.h +++ b/runtime/TrayIcon.h @@ -24,7 +24,6 @@ class TrayIcon : public QWidget public: TrayIcon(); - ~TrayIcon(); void Init(); void enableShutdownMenu();