Use nullptr instead of NULL or 0.

This commit is contained in:
Dave Page
2018-12-06 10:17:47 +00:00
parent 12ef55334b
commit 45cd17af84
10 changed files with 48 additions and 47 deletions

View File

@@ -23,7 +23,7 @@ class ConfigWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigWindow(QWidget *parent = 0); explicit ConfigWindow(QWidget *parent = nullptr);
~ConfigWindow(); ~ConfigWindow();
QString getBrowserCommand(); QString getBrowserCommand();

View File

@@ -16,12 +16,12 @@ FloatingWindow::FloatingWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::FloatingWindow) ui(new Ui::FloatingWindow)
{ {
m_newAction = NULL; m_newAction = nullptr;
m_configAction = NULL; m_configAction = nullptr;
m_logAction = NULL; m_logAction = nullptr;
m_quitAction = NULL; m_quitAction = nullptr;
m_menuActions = NULL; m_menuActions = nullptr;
m_floatingWindowMenu = NULL; m_floatingWindowMenu = nullptr;
ui->setupUi(this); ui->setupUi(this);
} }
@@ -87,7 +87,7 @@ void FloatingWindow::createActions()
void FloatingWindow::enableShutdownMenu() void FloatingWindow::enableShutdownMenu()
{ {
if (m_quitAction != NULL) if (m_quitAction != nullptr)
{ {
m_quitAction->setEnabled(true); m_quitAction->setEnabled(true);
} }

View File

@@ -27,7 +27,7 @@ class FloatingWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit FloatingWindow(QWidget *parent = 0); explicit FloatingWindow(QWidget *parent = nullptr);
~FloatingWindow(); ~FloatingWindow();
bool Init(); bool Init();

View File

@@ -55,7 +55,7 @@ void LogWindow::ReadLog()
// Attempt to open the file // Attempt to open the file
log = fopen(m_logFile.toUtf8().data(), "r"); log = fopen(m_logFile.toUtf8().data(), "r");
if (log == NULL) if (log == nullptr)
{ {
ui->textLog->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_logFile)); ui->textLog->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_logFile));
this->setDisabled(false); this->setDisabled(false);

View File

@@ -23,7 +23,7 @@ class LogWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit LogWindow(QWidget *parent = 0, QString logFile = ""); explicit LogWindow(QWidget *parent = nullptr, QString logFile = "");
~LogWindow(); ~LogWindow();
void ReadLog(); void ReadLog();

View File

@@ -24,7 +24,7 @@ Logger::~Logger()
Logger* Logger::GetLogger() Logger* Logger::GetLogger()
{ {
if (m_pThis == NULL) if (m_pThis == nullptr)
{ {
m_pThis = new Logger(); m_pThis = new Logger();
m_sFileName = QDir::homePath() + (QString("/.%1.startup.log").arg(PGA_APP_NAME)).remove(" "); m_sFileName = QDir::homePath() + (QString("/.%1.startup.log").arg(PGA_APP_NAME)).remove(" ");
@@ -40,7 +40,7 @@ Logger* Logger::GetLogger()
void Logger::Log(const QString& sMessage) void Logger::Log(const QString& sMessage)
{ {
QString text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + sMessage + "\n"; QString text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + sMessage + "\n";
if (m_Logfile != NULL) if (m_Logfile != nullptr)
{ {
QTextStream out(m_Logfile); QTextStream out(m_Logfile);
out << text; out << text;
@@ -49,11 +49,11 @@ void Logger::Log(const QString& sMessage)
void Logger::ReleaseLogger() void Logger::ReleaseLogger()
{ {
if (m_pThis != NULL) if (m_pThis != nullptr)
{ {
if(m_Logfile != NULL) if(m_Logfile != nullptr)
m_Logfile->close(); m_Logfile->close();
delete m_pThis; delete m_pThis;
m_pThis = NULL; m_pThis = nullptr;
} }
} }

View File

@@ -13,6 +13,7 @@
#define LOGGER_H #define LOGGER_H
#include <QObject> #include <QObject>
#include <QFile>
class Logger : public QObject class Logger : public QObject
{ {

View File

@@ -17,7 +17,7 @@
MenuActions::MenuActions() MenuActions::MenuActions()
{ {
m_logWindow = NULL; m_logWindow = nullptr;
m_logFile = ""; m_logFile = "";
m_appServerUrl = ""; m_appServerUrl = "";
} }
@@ -52,7 +52,7 @@ void MenuActions::onNew()
if (!QDesktopServices::openUrl(m_appServerUrl)) if (!QDesktopServices::openUrl(m_appServerUrl))
{ {
QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?."));
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
exit(1); exit(1);
} }
@@ -105,7 +105,7 @@ void MenuActions::onConfig()
if (needRestart) if (needRestart)
{ {
if (QMessageBox::Yes == QMessageBox::question(NULL, 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(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);
} }
@@ -121,7 +121,7 @@ void MenuActions::onLog()
if (!m_logWindow) if (!m_logWindow)
{ {
m_logWindow = new LogWindow(NULL, m_logFile); m_logWindow = new LogWindow(nullptr, m_logFile);
m_logWindow->setWindowTitle(QString(tr("%1 Log")).arg(PGA_APP_NAME)); m_logWindow->setWindowTitle(QString(tr("%1 Log")).arg(PGA_APP_NAME));
} }
@@ -138,7 +138,7 @@ void MenuActions::onLog()
// Exit // Exit
void MenuActions::onQuit() void MenuActions::onQuit()
{ {
if (QMessageBox::Yes == QMessageBox::question(NULL, tr("Shut down server?"), QString(tr("Are you sure you want to shut down the %1 server?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No)) if (QMessageBox::Yes == QMessageBox::question(nullptr, tr("Shut down server?"), QString(tr("Are you sure you want to shut down the %1 server?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No))
{ {
// Emit the signal to shut down the python server. // Emit the signal to shut down the python server.
emit shutdownSignal(m_appServerUrl); emit shutdownSignal(m_appServerUrl);

View File

@@ -61,8 +61,8 @@ Server::Server(quint16 port, QString key, QString logFileName)
m_port = port; m_port = port;
m_key = key; m_key = key;
m_logFileName = logFileName; m_logFileName = logFileName;
m_wcAppName = NULL; m_wcAppName = nullptr;
m_wcPythonHome = NULL; m_wcPythonHome = nullptr;
// Initialise Python // Initialise Python
Py_NoSiteFlag=1; Py_NoSiteFlag=1;
@@ -201,7 +201,7 @@ Server::Server(quint16 port, QString key, QString logFileName)
// Get the current path // Get the current path
PyObject* sysPath = PySys_GetObject((char*)"path"); PyObject* sysPath = PySys_GetObject((char*)"path");
if (sysPath != NULL) if (sysPath != nullptr)
{ {
// Add new additional path elements // Add new additional path elements
Logger::GetLogger()->Log("Adding new additional path elements"); Logger::GetLogger()->Log("Adding new additional path elements");
@@ -224,13 +224,13 @@ Server::Server(quint16 port, QString key, QString logFileName)
// Redirect stderr // Redirect stderr
Logger::GetLogger()->Log("Redirecting stderr..."); Logger::GetLogger()->Log("Redirecting stderr...");
PyObject *sys = PyImport_ImportModule("sys"); PyObject *sys = PyImport_ImportModule("sys");
if (sys != NULL) if (sys != nullptr)
{ {
PyObject *err = NULL; PyObject *err = nullptr;
#ifdef PYTHON2 #ifdef PYTHON2
err = PyFile_FromString(m_logFileName.toUtf8().data(), (char *)"w"); err = PyFile_FromString(m_logFileName.toUtf8().data(), (char *)"w");
#else #else
FILE *log = NULL; FILE *log = nullptr;
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
char *logFile = m_logFileName.toUtf8().data(); char *logFile = m_logFileName.toUtf8().data();
@@ -242,10 +242,10 @@ Server::Server(quint16 port, QString key, QString logFileName)
#else #else
log = fopen(m_logFileName.toUtf8().data(), (char *)"w"); log = fopen(m_logFileName.toUtf8().data(), (char *)"w");
#endif #endif
if (log != NULL) if (log != nullptr)
{ {
int fd = fileno(log); int fd = fileno(log);
err = PyFile_FromFd(fd, NULL, (char *)"w", -1, NULL, NULL, NULL, 0); err = PyFile_FromFd(fd, nullptr, (char *)"w", -1, nullptr, nullptr, nullptr, 0);
} }
else else
Logger::GetLogger()->Log(QString("Failed to open log file: %1").arg(m_logFileName)); Logger::GetLogger()->Log(QString("Failed to open log file: %1").arg(m_logFileName));
@@ -259,7 +259,7 @@ Server::Server(quint16 port, QString key, QString logFileName)
#endif #endif
#endif #endif
QFile(m_logFileName).setPermissions(QFile::ReadOwner|QFile::WriteOwner); QFile(m_logFileName).setPermissions(QFile::ReadOwner|QFile::WriteOwner);
if (err != NULL) if (err != nullptr)
{ {
PyObject_SetAttrString(sys, "stderr", err); PyObject_SetAttrString(sys, "stderr", err);
Logger::GetLogger()->Log("stderr redirected successfully."); Logger::GetLogger()->Log("stderr redirected successfully.");

View File

@@ -214,22 +214,22 @@ int main(int argc, char * argv[])
// Create Menu Actions // Create Menu Actions
MenuActions *menuActions = new MenuActions(); MenuActions *menuActions = new MenuActions();
if(menuActions != NULL) if(menuActions != nullptr)
menuActions->setLogFile(logFileName); menuActions->setLogFile(logFileName);
splash->showMessage(QString(QWidget::tr("Checking for system tray...")), Qt::AlignBottom | Qt::AlignCenter); splash->showMessage(QString(QWidget::tr("Checking for system tray...")), Qt::AlignBottom | Qt::AlignCenter);
Logger::GetLogger()->Log("Checking for system tray..."); Logger::GetLogger()->Log("Checking for system tray...");
// Check system tray is available or not. If not then create one floating window. // Check system tray is available or not. If not then create one floating window.
FloatingWindow *floatingWindow = NULL; FloatingWindow *floatingWindow = nullptr;
TrayIcon *trayicon = NULL; TrayIcon *trayicon = nullptr;
if (QSystemTrayIcon::isSystemTrayAvailable()) if (QSystemTrayIcon::isSystemTrayAvailable())
{ {
// Start the tray service // Start the tray service
trayicon = new TrayIcon(); trayicon = new TrayIcon();
// Set the MenuActions object to connect to slot // Set the MenuActions object to connect to slot
if (trayicon != NULL) if (trayicon != nullptr)
trayicon->setMenuActions(menuActions); trayicon->setMenuActions(menuActions);
trayicon->Init(); trayicon->Init();
@@ -240,10 +240,10 @@ int main(int argc, char * argv[])
Logger::GetLogger()->Log("System tray not found, creating floating window..."); Logger::GetLogger()->Log("System tray not found, creating floating window...");
// Unable to find tray icon, so creating floting window // Unable to find tray icon, so creating floting window
floatingWindow = new FloatingWindow(); floatingWindow = new FloatingWindow();
if (floatingWindow == NULL) if (floatingWindow == nullptr)
{ {
QString error = QString(QWidget::tr("Unable to initialize either a tray icon or control window.")); QString error = QString(QWidget::tr("Unable to initialize either a tray icon or control window."));
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
Logger::GetLogger()->Log(error); Logger::GetLogger()->Log(error);
Logger::ReleaseLogger(); Logger::ReleaseLogger();
exit(1); exit(1);
@@ -270,12 +270,12 @@ int main(int argc, char * argv[])
Logger::GetLogger()->Log("Initializing server..."); Logger::GetLogger()->Log("Initializing server...");
if (!server->Init()) if (!server->Init())
{ {
splash->finish(NULL); splash->finish(nullptr);
qDebug() << server->getError(); qDebug() << server->getError();
QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError());
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
Logger::GetLogger()->Log(error); Logger::GetLogger()->Log(error);
Logger::ReleaseLogger(); Logger::ReleaseLogger();
@@ -297,12 +297,12 @@ int main(int argc, char * argv[])
// Any errors? // Any errors?
if (server->isFinished() || server->getError().length() > 0) if (server->isFinished() || server->getError().length() > 0)
{ {
splash->finish(NULL); splash->finish(nullptr);
qDebug() << server->getError(); qDebug() << server->getError();
QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError());
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
Logger::GetLogger()->Log(error); Logger::GetLogger()->Log(error);
// Allow the user to tweak the Python Path if needed // Allow the user to tweak the Python Path if needed
@@ -372,9 +372,9 @@ int main(int argc, char * argv[])
Logger::GetLogger()->Log("Attempt to connect one more time in case of a long network timeout while looping"); Logger::GetLogger()->Log("Attempt to connect one more time in case of a long network timeout while looping");
if (!alive && !PingServer(QUrl(appServerUrl))) if (!alive && !PingServer(QUrl(appServerUrl)))
{ {
splash->finish(NULL); splash->finish(nullptr);
QString error(QWidget::tr("The application server could not be contacted.")); QString error(QWidget::tr("The application server could not be contacted."));
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
Logger::ReleaseLogger(); Logger::ReleaseLogger();
exit(1); exit(1);
@@ -392,9 +392,9 @@ int main(int argc, char * argv[])
menuActions->setAppServerUrl(appServerUrl); menuActions->setAppServerUrl(appServerUrl);
// Enable the shutdown server menu as server started successfully. // Enable the shutdown server menu as server started successfully.
if (trayicon != NULL) if (trayicon != nullptr)
trayicon->enableShutdownMenu(); trayicon->enableShutdownMenu();
if (floatingWindow != NULL) if (floatingWindow != nullptr)
floatingWindow->enableShutdownMenu(); floatingWindow->enableShutdownMenu();
QString cmd = settings.value("BrowserCommand").toString(); QString cmd = settings.value("BrowserCommand").toString();
@@ -409,7 +409,7 @@ int main(int argc, char * argv[])
if (!QDesktopServices::openUrl(appServerUrl)) if (!QDesktopServices::openUrl(appServerUrl))
{ {
QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?.")); QString error(QWidget::tr("Failed to open the system default web browser. Is one installed?."));
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); QMessageBox::critical(nullptr, QString(QWidget::tr("Fatal Error")), error);
Logger::GetLogger()->Log(error); Logger::GetLogger()->Log(error);
Logger::ReleaseLogger(); Logger::ReleaseLogger();
@@ -418,9 +418,9 @@ int main(int argc, char * argv[])
} }
QObject::connect(menuActions, SIGNAL(shutdownSignal(QUrl)), server, SLOT(shutdown(QUrl))); QObject::connect(menuActions, SIGNAL(shutdownSignal(QUrl)), server, SLOT(shutdown(QUrl)));
splash->finish(NULL); splash->finish(nullptr);
if (floatingWindow != NULL) if (floatingWindow != nullptr)
floatingWindow->show(); floatingWindow->show();
Logger::GetLogger()->Log("Everything works fine, successfully started pgAdmin4."); Logger::GetLogger()->Log("Everything works fine, successfully started pgAdmin4.");