mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:57:57 +00:00
UI: Minor refactorings.
This commit is contained in:
parent
ac6d1ff403
commit
dc40085b53
@ -1,8 +1,8 @@
|
||||
#ifndef DATABASEMANAGER_H
|
||||
#define DATABASEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
@ -52,7 +52,7 @@ public slots:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
typedef QList<SqliteStmt *> QStmtList;
|
||||
using QStmtList = QList<SqliteStmt *>;
|
||||
|
||||
void initializeQuota();
|
||||
|
||||
|
@ -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<QObject *> rootObjects = m_engine->rootObjects();
|
||||
|
||||
if (rootObjects.isEmpty()) {
|
||||
showErrorBox("Cannot setup QML Engine");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_appWindow = qobject_cast<QWindow *>(
|
||||
m_engine->rootObjects().first());
|
||||
m_appWindow = qobject_cast<QWindow *>(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);
|
||||
}
|
||||
|
@ -92,7 +92,9 @@ private:
|
||||
void setupLogManager();
|
||||
|
||||
void setupTrayIcon();
|
||||
|
||||
bool setupEngine();
|
||||
void closeEngine();
|
||||
|
||||
bool loadSettings(FirewallConf *conf);
|
||||
bool saveSettings(FirewallConf *newConf, bool onlyFlags = false,
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FORTSETTINGS_H
|
||||
#define FORTSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QRect>
|
||||
#include <QSettings>
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(FirewallConf)
|
||||
|
||||
typedef QHash<QString, QByteArray> TasksMap;
|
||||
using TasksMap = QHash<QString, QByteArray>;
|
||||
|
||||
class FortSettings : public QObject
|
||||
{
|
||||
|
@ -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()
|
||||
|
@ -14,8 +14,8 @@ public:
|
||||
StatTraf = 0x04000000
|
||||
};
|
||||
|
||||
explicit LogEntry();
|
||||
virtual ~LogEntry();
|
||||
explicit LogEntry() = default;
|
||||
virtual ~LogEntry() = default;
|
||||
|
||||
virtual LogEntry::LogType type() const = 0;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -189,7 +189,7 @@ bool ConfUtil::parseAppGroups(const QList<AppGroup *> &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);
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ QT_FORWARD_DECLARE_CLASS(FirewallConf)
|
||||
|
||||
QT_FORWARD_DECLARE_STRUCT(fort_conf_limit)
|
||||
|
||||
typedef QVector<quint32> numbers_arr_t;
|
||||
using numbers_arr_t = QVector<quint32>;
|
||||
|
||||
typedef QVarLengthArray<AddressRange, 2> addrranges_arr_t;
|
||||
using addrranges_arr_t = QVarLengthArray<AddressRange, 2>;
|
||||
|
||||
typedef QMap<QString, quint32> appperms_map_t;
|
||||
typedef QMap<QString, qint8> appgroups_map_t;
|
||||
using appperms_map_t = QMap<QString, quint32>;
|
||||
using appgroups_map_t = QMap<QString, qint8>;
|
||||
|
||||
class ConfUtil : public QObject
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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()) {
|
||||
|
@ -1,16 +1,16 @@
|
||||
#ifndef IP4RANGE_H
|
||||
#define IP4RANGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
typedef struct {
|
||||
using Ip4Pair = struct {
|
||||
quint32 from, to;
|
||||
} Ip4Pair;
|
||||
};
|
||||
|
||||
typedef QMap<quint32, quint32> ip4range_map_t;
|
||||
typedef QVector<quint32> ip4range_arr_t;
|
||||
using ip4range_map_t = QMap<quint32, quint32>;
|
||||
using ip4range_arr_t = QVector<quint32>;
|
||||
|
||||
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)};
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user