mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:46:03 +00:00
UI: Improve ActivityPage.
This commit is contained in:
parent
1983b0b7b9
commit
bd29dc6784
@ -22,7 +22,8 @@ SOURCES += \
|
||||
util/fileutil.cpp \
|
||||
util/ip4range.cpp \
|
||||
util/netutil.cpp \
|
||||
util/processinfo.cpp
|
||||
util/processinfo.cpp \
|
||||
util/osutil.cpp
|
||||
|
||||
HEADERS += \
|
||||
activityLog/logbuffer.h \
|
||||
@ -40,7 +41,8 @@ HEADERS += \
|
||||
util/fileutil.h \
|
||||
util/ip4range.h \
|
||||
util/netutil.h \
|
||||
util/processinfo.h
|
||||
util/processinfo.h \
|
||||
util/osutil.h
|
||||
|
||||
QML_FILES += \
|
||||
qml/*.qml \
|
||||
|
@ -1,9 +1,5 @@
|
||||
#include "logentry.h"
|
||||
|
||||
#include "../util/fileutil.h"
|
||||
#include "../util/netutil.h"
|
||||
#include "../util/processinfo.h"
|
||||
|
||||
LogEntry::LogEntry(quint32 ip, quint32 pid,
|
||||
const QString &dosPath,
|
||||
QObject *parent) :
|
||||
@ -37,19 +33,3 @@ void LogEntry::setDosPath(const QString &dosPath)
|
||||
emit dosPathChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString LogEntry::ipText() const
|
||||
{
|
||||
return NetUtil::ip4ToText(m_ip);
|
||||
}
|
||||
|
||||
QString LogEntry::path() const
|
||||
{
|
||||
QString dosPath = m_dosPath;
|
||||
if (dosPath.isEmpty()) {
|
||||
const ProcessInfo pi(m_pid);
|
||||
dosPath = pi.dosPath();
|
||||
}
|
||||
|
||||
return FileUtil::dosPathToPath(dosPath);
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ class LogEntry : public QObject
|
||||
Q_PROPERTY(quint32 ip READ ip WRITE setIp NOTIFY ipChanged)
|
||||
Q_PROPERTY(quint32 pid READ pid WRITE setPid NOTIFY pidChanged)
|
||||
Q_PROPERTY(QString dosPath READ dosPath WRITE setDosPath NOTIFY dosPathChanged)
|
||||
Q_PROPERTY(QString ipText READ ipText NOTIFY ipChanged)
|
||||
Q_PROPERTY(QString path READ path NOTIFY dosPathChanged)
|
||||
|
||||
public:
|
||||
explicit LogEntry(quint32 ip = 0, quint32 pid = 0,
|
||||
@ -26,9 +24,6 @@ public:
|
||||
QString dosPath() const { return m_dosPath; }
|
||||
void setDosPath(const QString &dosPath);
|
||||
|
||||
QString ipText() const;
|
||||
QString path() const;
|
||||
|
||||
signals:
|
||||
void ipChanged();
|
||||
void pidChanged();
|
||||
|
@ -15,6 +15,9 @@
|
||||
#include "conf/firewallconf.h"
|
||||
#include "driver/drivermanager.h"
|
||||
#include "fortsettings.h"
|
||||
#include "util/fileutil.h"
|
||||
#include "util/netutil.h"
|
||||
#include "util/osutil.h"
|
||||
|
||||
FortManager::FortManager(QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -50,6 +53,10 @@ void FortManager::registerQmlTypes()
|
||||
|
||||
qmlRegisterType<LogBuffer>("com.fortfirewall", 1, 0, "LogBuffer");
|
||||
qmlRegisterType<LogEntry>("com.fortfirewall", 1, 0, "LogEntry");
|
||||
|
||||
qmlRegisterType<FileUtil>("com.fortfirewall", 1, 0, "FileUtil");
|
||||
qmlRegisterType<NetUtil>("com.fortfirewall", 1, 0, "NetUtil");
|
||||
qmlRegisterType<OsUtil>("com.fortfirewall", 1, 0, "OsUtil");
|
||||
}
|
||||
|
||||
bool FortManager::setupDriver()
|
||||
|
@ -36,6 +36,18 @@ ApplicationWindow {
|
||||
fortManager.closeWindow();
|
||||
}
|
||||
|
||||
FileUtil {
|
||||
id: fileUtil
|
||||
}
|
||||
|
||||
NetUtil {
|
||||
id: netUtil
|
||||
}
|
||||
|
||||
OsUtil {
|
||||
id: osUtil
|
||||
}
|
||||
|
||||
MainPage {
|
||||
id: mainPage
|
||||
anchors.fill: parent
|
||||
|
@ -33,24 +33,43 @@ BasePage {
|
||||
}
|
||||
|
||||
function clearAppPaths() {
|
||||
listView.model = undefined;
|
||||
|
||||
appPaths = ([]);
|
||||
appPathsMap = ({});
|
||||
}
|
||||
|
||||
function processLogBuffer() {
|
||||
const curIndex = listView.currentIndex;
|
||||
listView.model = undefined;
|
||||
|
||||
while (logBuffer.read(logEntry)) {
|
||||
var path = logEntry.path;
|
||||
var ipText = logEntry.ipText;
|
||||
console.log(">", path, ipText);
|
||||
var path = getEntryPath(logEntry);
|
||||
var ipText = netUtil.ip4ToText(logEntry.ip);
|
||||
|
||||
var ipTextsMap = appPathsMap[path];
|
||||
if (!ipTextsMap) {
|
||||
ipTextsMap = ({});
|
||||
appPathsMap[path] = ipTextsMap;
|
||||
|
||||
curIndex = appPaths.length;
|
||||
appPaths.push(path);
|
||||
}
|
||||
|
||||
ipTextsMap[ipText] = (ipTextsMap[ipText] || 0) + 1;
|
||||
}
|
||||
|
||||
listView.model = appPaths;
|
||||
listView.currentIndex = curIndex;
|
||||
}
|
||||
|
||||
function getEntryPath(logEntry) {
|
||||
var dosPath = logEntry.dosPath;
|
||||
if (!dosPath) {
|
||||
dosPath = osUtil.pidToDosPath(logEntry.pid);
|
||||
}
|
||||
|
||||
return fileUtil.dosPathToPath(dosPath);
|
||||
}
|
||||
|
||||
Connections {
|
||||
@ -80,12 +99,23 @@ console.log(">", path, ipText);
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
|
||||
RowLayout {
|
||||
Button {
|
||||
enabled: btCopy.enabled
|
||||
text: QT_TRANSLATE_NOOP("qml", "Clear")
|
||||
onClicked: clearAppPaths()
|
||||
}
|
||||
Button {
|
||||
id: btCopy
|
||||
enabled: currentItem
|
||||
text: QT_TRANSLATE_NOOP("qml", "Copy")
|
||||
readonly property Item currentItem: listView.currentItem
|
||||
onClicked: {
|
||||
osUtil.setClipboardData(currentItem.text);
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
@ -98,9 +128,48 @@ console.log(">", path, ipText);
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
Frame {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
clip: true
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
|
||||
highlightRangeMode: ListView.ApplyRange
|
||||
highlightResizeDuration: 150
|
||||
highlightMoveDuration: 200
|
||||
|
||||
highlight: Item {
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: -7
|
||||
radius: 2
|
||||
border.width: 3
|
||||
border.color: "black"
|
||||
color: "transparent"
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Label {
|
||||
width: listView.width
|
||||
font.pixelSize: 20
|
||||
elide: Text.ElideRight
|
||||
text: modelData
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
const index = listView.indexAt(mouse.x, mouse.y);
|
||||
if (index >= 0) {
|
||||
listView.currentIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ public:
|
||||
static QString driveToDosName(const QString &drive);
|
||||
|
||||
// Convert Native path to Win32 path
|
||||
static QString dosPathToPath(const QString &dosPath);
|
||||
Q_INVOKABLE static QString dosPathToPath(const QString &dosPath);
|
||||
|
||||
// Convert Win32 path to Native path
|
||||
static QString pathToDosPath(const QString &path);
|
||||
Q_INVOKABLE static QString pathToDosPath(const QString &path);
|
||||
|
||||
static QString absolutePath(const QString &path);
|
||||
|
||||
|
@ -12,10 +12,10 @@ public:
|
||||
explicit NetUtil(QObject *parent = nullptr);
|
||||
|
||||
// Convert IPv4 address from text to number
|
||||
static quint32 textToIp4(const QString &text, bool *ok = 0);
|
||||
Q_INVOKABLE static quint32 textToIp4(const QString &text, bool *ok = 0);
|
||||
|
||||
// Convert IPv4 address from number to text
|
||||
static QString ip4ToText(quint32 ip);
|
||||
Q_INVOKABLE static QString ip4ToText(quint32 ip);
|
||||
};
|
||||
|
||||
#endif // NETUTIL_H
|
||||
|
35
src/ui/util/osutil.cpp
Normal file
35
src/ui/util/osutil.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "osutil.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QPixmap>
|
||||
#include <QImage>
|
||||
|
||||
#include "processinfo.h"
|
||||
|
||||
OsUtil::OsUtil(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OsUtil::setClipboardData(const QVariant &data)
|
||||
{
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
|
||||
switch (data.type()) {
|
||||
case QVariant::Pixmap:
|
||||
clipboard->setPixmap(data.value<QPixmap>());
|
||||
break;
|
||||
case QVariant::Image:
|
||||
clipboard->setImage(data.value<QImage>());
|
||||
break;
|
||||
default:
|
||||
clipboard->setText(data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
QString OsUtil::pidToDosPath(quint32 pid)
|
||||
{
|
||||
const ProcessInfo pi(pid);
|
||||
return pi.dosPath();
|
||||
}
|
19
src/ui/util/osutil.h
Normal file
19
src/ui/util/osutil.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef OSUTIL_H
|
||||
#define OSUTIL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
class OsUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OsUtil(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE static void setClipboardData(const QVariant &data);
|
||||
|
||||
Q_INVOKABLE static QString pidToDosPath(quint32 pid);
|
||||
};
|
||||
|
||||
#endif // OSUTIL_H
|
Loading…
Reference in New Issue
Block a user