Tidy up some code to keep SonarQube happy.

This commit is contained in:
Akshay Joshi 2020-06-15 12:12:19 +01:00 committed by Dave Page
parent 18277543b6
commit a23fad0ba8
12 changed files with 55 additions and 86 deletions

View File

@ -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()
{

View File

@ -24,7 +24,6 @@ class ConfigWindow : public QDialog
public:
explicit ConfigWindow(QWidget *parent = Q_NULLPTR);
~ConfigWindow();
QString getBrowserCommand();
bool getFixedPort();

View File

@ -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()
{

View File

@ -28,7 +28,6 @@ class FloatingWindow : public QMainWindow
public:
explicit FloatingWindow(QWidget *parent = Q_NULLPTR);
~FloatingWindow();
bool Init();
void enableShutdownMenu();

View File

@ -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<char *>(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;

View File

@ -25,8 +25,6 @@ class LogWindow : public QDialog
public:
explicit LogWindow(QWidget *parent = Q_NULLPTR, QString serverLogFile = "");
~LogWindow();
void LoadLog();
private slots:

View File

@ -26,7 +26,6 @@ private:
Logger();
virtual ~Logger();
private:
static Logger* m_pThis;
static QString m_sFileName;
static QFile *m_Logfile;

View File

@ -15,16 +15,13 @@
#include <QClipboard>
#include <QMessageBox>
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);
}
}
}

View File

@ -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:

View File

@ -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);
}
}

View File

@ -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()

View File

@ -24,7 +24,6 @@ class TrayIcon : public QWidget
public:
TrayIcon();
~TrayIcon();
void Init();
void enableShutdownMenu();