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
public:
explicit ConfigWindow(QWidget *parent = 0);
explicit ConfigWindow(QWidget *parent = nullptr);
~ConfigWindow();
QString getBrowserCommand();

View File

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

View File

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

View File

@ -55,7 +55,7 @@ void LogWindow::ReadLog()
// Attempt to open the file
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));
this->setDisabled(false);

View File

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

View File

@ -24,7 +24,7 @@ Logger::~Logger()
Logger* Logger::GetLogger()
{
if (m_pThis == NULL)
if (m_pThis == nullptr)
{
m_pThis = new Logger();
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)
{
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);
out << text;
@ -49,11 +49,11 @@ void Logger::Log(const QString& sMessage)
void Logger::ReleaseLogger()
{
if (m_pThis != NULL)
if (m_pThis != nullptr)
{
if(m_Logfile != NULL)
if(m_Logfile != nullptr)
m_Logfile->close();
delete m_pThis;
m_pThis = NULL;
m_pThis = nullptr;
}
}

View File

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

View File

@ -17,7 +17,7 @@
MenuActions::MenuActions()
{
m_logWindow = NULL;
m_logWindow = nullptr;
m_logFile = "";
m_appServerUrl = "";
}
@ -52,7 +52,7 @@ void MenuActions::onNew()
if (!QDesktopServices::openUrl(m_appServerUrl))
{
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);
}
@ -105,7 +105,7 @@ void MenuActions::onConfig()
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);
}
@ -121,7 +121,7 @@ void MenuActions::onLog()
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));
}
@ -138,7 +138,7 @@ void MenuActions::onLog()
// Exit
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 shutdownSignal(m_appServerUrl);

View File

@ -61,8 +61,8 @@ Server::Server(quint16 port, QString key, QString logFileName)
m_port = port;
m_key = key;
m_logFileName = logFileName;
m_wcAppName = NULL;
m_wcPythonHome = NULL;
m_wcAppName = nullptr;
m_wcPythonHome = nullptr;
// Initialise Python
Py_NoSiteFlag=1;
@ -201,7 +201,7 @@ Server::Server(quint16 port, QString key, QString logFileName)
// Get the current path
PyObject* sysPath = PySys_GetObject((char*)"path");
if (sysPath != NULL)
if (sysPath != nullptr)
{
// Add 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
Logger::GetLogger()->Log("Redirecting stderr...");
PyObject *sys = PyImport_ImportModule("sys");
if (sys != NULL)
if (sys != nullptr)
{
PyObject *err = NULL;
PyObject *err = nullptr;
#ifdef PYTHON2
err = PyFile_FromString(m_logFileName.toUtf8().data(), (char *)"w");
#else
FILE *log = NULL;
FILE *log = nullptr;
#if defined(Q_OS_WIN)
char *logFile = m_logFileName.toUtf8().data();
@ -242,10 +242,10 @@ Server::Server(quint16 port, QString key, QString logFileName)
#else
log = fopen(m_logFileName.toUtf8().data(), (char *)"w");
#endif
if (log != NULL)
if (log != nullptr)
{
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
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
QFile(m_logFileName).setPermissions(QFile::ReadOwner|QFile::WriteOwner);
if (err != NULL)
if (err != nullptr)
{
PyObject_SetAttrString(sys, "stderr", err);
Logger::GetLogger()->Log("stderr redirected successfully.");

View File

@ -214,22 +214,22 @@ int main(int argc, char * argv[])
// Create Menu Actions
MenuActions *menuActions = new MenuActions();
if(menuActions != NULL)
if(menuActions != nullptr)
menuActions->setLogFile(logFileName);
splash->showMessage(QString(QWidget::tr("Checking for system tray...")), Qt::AlignBottom | Qt::AlignCenter);
Logger::GetLogger()->Log("Checking for system tray...");
// Check system tray is available or not. If not then create one floating window.
FloatingWindow *floatingWindow = NULL;
TrayIcon *trayicon = NULL;
FloatingWindow *floatingWindow = nullptr;
TrayIcon *trayicon = nullptr;
if (QSystemTrayIcon::isSystemTrayAvailable())
{
// Start the tray service
trayicon = new TrayIcon();
// Set the MenuActions object to connect to slot
if (trayicon != NULL)
if (trayicon != nullptr)
trayicon->setMenuActions(menuActions);
trayicon->Init();
@ -240,10 +240,10 @@ int main(int argc, char * argv[])
Logger::GetLogger()->Log("System tray not found, creating floating window...");
// Unable to find tray icon, so creating floting window
floatingWindow = new FloatingWindow();
if (floatingWindow == NULL)
if (floatingWindow == nullptr)
{
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::ReleaseLogger();
exit(1);
@ -270,12 +270,12 @@ int main(int argc, char * argv[])
Logger::GetLogger()->Log("Initializing server...");
if (!server->Init())
{
splash->finish(NULL);
splash->finish(nullptr);
qDebug() << 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::ReleaseLogger();
@ -297,12 +297,12 @@ int main(int argc, char * argv[])
// Any errors?
if (server->isFinished() || server->getError().length() > 0)
{
splash->finish(NULL);
splash->finish(nullptr);
qDebug() << 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);
// 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");
if (!alive && !PingServer(QUrl(appServerUrl)))
{
splash->finish(NULL);
splash->finish(nullptr);
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();
exit(1);
@ -392,9 +392,9 @@ int main(int argc, char * argv[])
menuActions->setAppServerUrl(appServerUrl);
// Enable the shutdown server menu as server started successfully.
if (trayicon != NULL)
if (trayicon != nullptr)
trayicon->enableShutdownMenu();
if (floatingWindow != NULL)
if (floatingWindow != nullptr)
floatingWindow->enableShutdownMenu();
QString cmd = settings.value("BrowserCommand").toString();
@ -409,7 +409,7 @@ int main(int argc, char * argv[])
if (!QDesktopServices::openUrl(appServerUrl))
{
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::ReleaseLogger();
@ -418,9 +418,9 @@ int main(int argc, char * argv[])
}
QObject::connect(menuActions, SIGNAL(shutdownSignal(QUrl)), server, SLOT(shutdown(QUrl)));
splash->finish(NULL);
splash->finish(nullptr);
if (floatingWindow != NULL)
if (floatingWindow != nullptr)
floatingWindow->show();
Logger::GetLogger()->Log("Everything works fine, successfully started pgAdmin4.");