diff --git a/src/ui/db/databasemanager.h b/src/ui/db/databasemanager.h index aa3cbe91..39ce44d5 100644 --- a/src/ui/db/databasemanager.h +++ b/src/ui/db/databasemanager.h @@ -1,8 +1,8 @@ #ifndef DATABASEMANAGER_H #define DATABASEMANAGER_H -#include #include +#include #include #include @@ -52,7 +52,7 @@ public slots: void clear(); private: - typedef QList QStmtList; + using QStmtList = QList; void initializeQuota(); diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 23ed5976..974836ab 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -166,7 +166,7 @@ void FortManager::setupTrayIcon() m_trayIcon->setToolTip(qApp->applicationDisplayName()); m_trayIcon->setIcon(QIcon(":/images/shield.png")); - connect(m_trayIcon, &QSystemTrayIcon::activated, + connect(m_trayIcon, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) { showWindow(); @@ -186,13 +186,14 @@ bool FortManager::setupEngine() m_engine->load(QUrl("qrc:/qml/main.qml")); - if (m_engine->rootObjects().isEmpty()) { + const QList rootObjects = m_engine->rootObjects(); + + if (rootObjects.isEmpty()) { showErrorBox("Cannot setup QML Engine"); return false; } - m_appWindow = qobject_cast( - m_engine->rootObjects().first()); + m_appWindow = qobject_cast(rootObjects.first()); Q_ASSERT(m_appWindow); m_appWindowState->install(m_appWindow); @@ -200,6 +201,16 @@ bool FortManager::setupEngine() return true; } +void FortManager::closeEngine() +{ + m_appWindow = nullptr; + + if (m_engine) { + m_engine->deleteLater(); + m_engine = nullptr; + } +} + void FortManager::showTrayIcon() { m_trayIcon->show(); @@ -291,12 +302,7 @@ void FortManager::exit(int retcode) closeGraphWindow(); closeWindow(); - m_appWindow = nullptr; - - if (m_engine) { - m_engine->deleteLater(); - m_engine = nullptr; - } + closeEngine(); qApp->exit(retcode); } diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 0d3b2f05..bd64a70f 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -92,7 +92,9 @@ private: void setupLogManager(); void setupTrayIcon(); + bool setupEngine(); + void closeEngine(); bool loadSettings(FirewallConf *conf); bool saveSettings(FirewallConf *newConf, bool onlyFlags = false, diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index 4f947e8d..444988e4 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -1,8 +1,8 @@ #ifndef FORTSETTINGS_H #define FORTSETTINGS_H -#include #include +#include #include #include @@ -10,7 +10,7 @@ QT_FORWARD_DECLARE_CLASS(FirewallConf) -typedef QHash TasksMap; +using TasksMap = QHash; class FortSettings : public QObject { diff --git a/src/ui/log/logentry.cpp b/src/ui/log/logentry.cpp index 294943ff..76088050 100644 --- a/src/ui/log/logentry.cpp +++ b/src/ui/log/logentry.cpp @@ -3,14 +3,6 @@ #include "../util/fileutil.h" #include "../util/osutil.h" -LogEntry::LogEntry() -{ -} - -LogEntry::~LogEntry() -{ -} - QString LogEntry::getAppPath(const QString &kernelPath, quint32 pid) { return kernelPath.isEmpty() diff --git a/src/ui/log/logentry.h b/src/ui/log/logentry.h index b8e42d52..a43f0405 100644 --- a/src/ui/log/logentry.h +++ b/src/ui/log/logentry.h @@ -14,8 +14,8 @@ public: StatTraf = 0x04000000 }; - explicit LogEntry(); - virtual ~LogEntry(); + explicit LogEntry() = default; + virtual ~LogEntry() = default; virtual LogEntry::LogType type() const = 0; diff --git a/src/ui/task/taskuzonline.cpp b/src/ui/task/taskuzonline.cpp index 916940a4..95d5e1cd 100644 --- a/src/ui/task/taskuzonline.cpp +++ b/src/ui/task/taskuzonline.cpp @@ -22,7 +22,7 @@ QStringList TaskUzonline::parseUzonlineBuffer(const QByteArray &buffer) if (startPos < 0 || endPos < 0) return QStringList(); - const QRegularExpression re("([\\d.]+)[^\\d.]*-[^\\d.]*([\\d.]+)"); + const QRegularExpression re(R"(([\d.]+)[^\d.]*-[^\d.]*([\d.]+))"); QStringList list; diff --git a/src/ui/util/conf/confutil.cpp b/src/ui/util/conf/confutil.cpp index 22617464..cd0812b9 100644 --- a/src/ui/util/conf/confutil.cpp +++ b/src/ui/util/conf/confutil.cpp @@ -189,7 +189,7 @@ bool ConfUtil::parseAppGroups(const QList &appGroups, appPerms.reserve(appPermsMap.size()); for (; it != end; ++it) { - const QString appPath = it.key(); + const QString &appPath = it.key(); appPathsLen += appPath.size() * sizeof(wchar_t); appPaths.append(appPath); @@ -240,7 +240,7 @@ bool ConfUtil::parseApps(const QString &text, bool blocked, QString ConfUtil::parseAppPath(const QStringRef &line) { - const QRegularExpression re("\\s*\"?\\s*([^\"]+)\\s*\"?\\s*"); + const QRegularExpression re(R"(\s*"?\s*([^"]+)\s*"?\s*)"); const QRegularExpressionMatch match = re.match(line); if (!match.hasMatch()) @@ -330,7 +330,6 @@ quint16 ConfUtil::writeLimits(struct fort_conf_limit *limits, limit->out_bytes = appGroup->enabled() && appGroup->limitOutEnabled() ? appGroup->speedLimitOut() * 1024 / 2 : 0; - const quint16 bit = quint16(1 << i); if (limit->in_bytes || limit->out_bytes) { limitBits |= (1 << i); } diff --git a/src/ui/util/conf/confutil.h b/src/ui/util/conf/confutil.h index 5592090b..d889d471 100644 --- a/src/ui/util/conf/confutil.h +++ b/src/ui/util/conf/confutil.h @@ -15,12 +15,12 @@ QT_FORWARD_DECLARE_CLASS(FirewallConf) QT_FORWARD_DECLARE_STRUCT(fort_conf_limit) -typedef QVector numbers_arr_t; +using numbers_arr_t = QVector; -typedef QVarLengthArray addrranges_arr_t; +using addrranges_arr_t = QVarLengthArray; -typedef QMap appperms_map_t; -typedef QMap appgroups_map_t; +using appperms_map_t = QMap; +using appgroups_map_t = QMap; class ConfUtil : public QObject { diff --git a/src/ui/util/device.cpp b/src/ui/util/device.cpp index a47c8b47..07e42626 100644 --- a/src/ui/util/device.cpp +++ b/src/ui/util/device.cpp @@ -30,7 +30,8 @@ bool Device::open(const QString &filePath) | SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION; m_handle = CreateFileW((LPCWSTR) filePath.utf16(), - access, share, NULL, creation, attr, NULL); + access, share, nullptr, + creation, attr, nullptr); return m_handle != INVALID_HANDLE_VALUE; } @@ -47,7 +48,7 @@ bool Device::close() bool Device::cancelIo() { - return CancelIoEx(m_handle, NULL); + return CancelIoEx(m_handle, nullptr); } bool Device::ioctl(quint32 code, char *in, int inSize, @@ -58,7 +59,7 @@ bool Device::ioctl(quint32 code, char *in, int inSize, const bool res = DeviceIoControl( m_handle, code, in, inSize, out, outSize, - &size, NULL); + &size, nullptr); if (retSize) { *retSize = size; diff --git a/src/ui/util/net/ip4range.cpp b/src/ui/util/net/ip4range.cpp index 04054c3a..f9a455a1 100644 --- a/src/ui/util/net/ip4range.cpp +++ b/src/ui/util/net/ip4range.cpp @@ -95,7 +95,7 @@ bool Ip4Range::fromText(const QString &text) bool Ip4Range::parseAddressMask(const QStringRef &line, quint32 &from, quint32 &to) { - const QRegularExpression re("([\\d.]+)\\s*([/-]?)\\s*(\\S*)"); + const QRegularExpression re(R"(([\d.]+)\s*([/-]?)\s*(\S*))"); const QRegularExpressionMatch match = re.match(line); if (!match.hasMatch()) { diff --git a/src/ui/util/net/ip4range.h b/src/ui/util/net/ip4range.h index 211283ff..2c6f6e00 100644 --- a/src/ui/util/net/ip4range.h +++ b/src/ui/util/net/ip4range.h @@ -1,16 +1,16 @@ #ifndef IP4RANGE_H #define IP4RANGE_H -#include #include +#include #include -typedef struct { +using Ip4Pair = struct { quint32 from, to; -} Ip4Pair; +}; -typedef QMap ip4range_map_t; -typedef QVector ip4range_arr_t; +using ip4range_map_t = QMap; +using ip4range_arr_t = QVector; class Ip4Range : public QObject { @@ -30,7 +30,7 @@ public: const ip4range_arr_t &fromArray() const { return m_fromArray; } const ip4range_arr_t &toArray() const { return m_toArray; } - const int size() const { return m_toArray.size(); } + int size() const { return m_toArray.size(); } const Ip4Pair at(int i) const { return Ip4Pair{m_fromArray.at(i), m_toArray.at(i)}; } diff --git a/src/ui/util/osutil.cpp b/src/ui/util/osutil.cpp index 81ea53b3..32e88e73 100644 --- a/src/ui/util/osutil.cpp +++ b/src/ui/util/osutil.cpp @@ -18,7 +18,7 @@ QString OsUtil::pidToPath(quint32 pid, bool isKernelPath) bool OsUtil::createGlobalMutex(const char *name) { - return !CreateMutexA(NULL, FALSE, name); + return !CreateMutexA(nullptr, FALSE, name); } quint32 OsUtil::lastErrorCode() @@ -28,12 +28,13 @@ quint32 OsUtil::lastErrorCode() QString OsUtil::lastErrorMessage(quint32 errorCode) { - LPWSTR buf = NULL; + LPWSTR buf = nullptr; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, errorCode, 0, (LPWSTR) &buf, 0, NULL); + nullptr, errorCode, 0, + (LPWSTR) &buf, 0, nullptr); if (!buf) { return QString("System Error %1").arg(errorCode);