mirror of
https://github.com/tnodir/fort
synced 2024-11-15 03:36:07 +00:00
Add FortWindow class.
This commit is contained in:
parent
d5934407ef
commit
4af9947935
@ -1,5 +1,3 @@
|
||||
lessThan(QT_VERSION, 5.7.1): error(This project requires Qt 5.7.1 or later)
|
||||
|
||||
QT += core gui qml widgets
|
||||
|
||||
CONFIG += c++11
|
||||
@ -15,6 +13,7 @@ SOURCES += \
|
||||
firewallLog/logentry.cpp \
|
||||
fortcommon.cpp \
|
||||
fortsettings.cpp \
|
||||
fortwindow.cpp \
|
||||
util/confutil.cpp \
|
||||
util/device.cpp \
|
||||
util/fileutil.cpp \
|
||||
@ -29,6 +28,7 @@ HEADERS += \
|
||||
firewallLog/logentry.h \
|
||||
fortcommon.h \
|
||||
fortsettings.h \
|
||||
fortwindow.h \
|
||||
util/confutil.h \
|
||||
util/device.h \
|
||||
util/fileutil.h \
|
||||
@ -37,7 +37,8 @@ HEADERS += \
|
||||
util/processinfo.h
|
||||
|
||||
QML_FILES += \
|
||||
qml/*.qml
|
||||
qml/*.qml \
|
||||
qml/pages/*.qml
|
||||
|
||||
OTHER_FILES += \
|
||||
$${QML_FILES} \
|
||||
@ -46,12 +47,18 @@ OTHER_FILES += \
|
||||
TRANSLATIONS += \
|
||||
i18n/i18n_ru.ts
|
||||
|
||||
# QML files
|
||||
RESOURCES += fort_qml.qrc
|
||||
|
||||
# Compiled translation files
|
||||
RESOURCES += fort_i18n.qrc
|
||||
#RESOURCES += fort_i18n.qrc
|
||||
|
||||
# Default FortFirewall.ini
|
||||
RESOURCES += fort_ini.qrc
|
||||
|
||||
# Images
|
||||
RESOURCES += fort_images.qrc
|
||||
|
||||
# Windows
|
||||
LIBS += -lfwpuclnt -lkernel32 -lpsapi -luser32 -luuid -lws2_32
|
||||
RC_FILE = fort.rc
|
||||
|
5
src/ui/fort_images.qrc
Normal file
5
src/ui/fort_images.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/cog.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
8
src/ui/fort_qml.qrc
Normal file
8
src/ui/fort_qml.qrc
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>qml/main.qml</file>
|
||||
<file>qml/pages/AddressesPage.qml</file>
|
||||
<file>qml/pages/ApplicationsPage.qml</file>
|
||||
<file>qml/pages/OptionsPage.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
49
src/ui/fortwindow.cpp
Normal file
49
src/ui/fortwindow.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "fortwindow.h"
|
||||
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include "conf/appgroup.h"
|
||||
#include "conf/firewallconf.h"
|
||||
#include "fortsettings.h"
|
||||
|
||||
FortWindow::FortWindow(FirewallConf *firewallConf,
|
||||
FortSettings *fortSettings,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_firewallConf(firewallConf),
|
||||
m_fortSettings(fortSettings)
|
||||
{
|
||||
}
|
||||
|
||||
void FortWindow::registerQmlTypes()
|
||||
{
|
||||
qmlRegisterUncreatableType<FortSettings>("com.fortfirewall", 1, 0, "FortSettings",
|
||||
"Singleton");
|
||||
|
||||
qmlRegisterType<AppGroup>("com.fortfirewall", 1, 0, "AppGroup");
|
||||
qmlRegisterType<FirewallConf>("com.fortfirewall", 1, 0, "FirewallConf");
|
||||
}
|
||||
|
||||
void FortWindow::setupContext()
|
||||
{
|
||||
QQmlContext *context = m_engine->rootContext();
|
||||
|
||||
context->setContextProperty("firewallConf", m_firewallConf);
|
||||
context->setContextProperty("fortSettings", m_fortSettings);
|
||||
context->setContextProperty("fortWindow", this);
|
||||
}
|
||||
|
||||
void FortWindow::show()
|
||||
{
|
||||
m_engine = new QQmlApplicationEngine(this);
|
||||
|
||||
setupContext();
|
||||
|
||||
m_engine->load(QUrl("qrc:/qml/main.qml"));
|
||||
}
|
||||
|
||||
bool FortWindow::save()
|
||||
{
|
||||
return m_fortSettings->writeConf(*m_firewallConf);
|
||||
}
|
39
src/ui/fortwindow.h
Normal file
39
src/ui/fortwindow.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef FORTWINDOW_H
|
||||
#define FORTWINDOW_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QQmlApplicationEngine;
|
||||
|
||||
class FortSettings;
|
||||
class FirewallConf;
|
||||
|
||||
class FortWindow : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FortWindow(FirewallConf *firewallConf,
|
||||
FortSettings *fortSettings,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
static void registerQmlTypes();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void show();
|
||||
|
||||
bool save();
|
||||
|
||||
private:
|
||||
void setupContext();
|
||||
|
||||
private:
|
||||
QQmlApplicationEngine *m_engine;
|
||||
|
||||
FirewallConf *m_firewallConf;
|
||||
FortSettings *m_fortSettings;
|
||||
};
|
||||
|
||||
#endif // FORTWINDOW_H
|
BIN
src/ui/images/cog.png
Normal file
BIN
src/ui/images/cog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 512 B |
@ -1,8 +1,21 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "conf/firewallconf.h"
|
||||
#include "fortsettings.h"
|
||||
#include "fortwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
FirewallConf firewallConf;
|
||||
FortSettings fortSettings(qApp->arguments());
|
||||
fortSettings.readConf(firewallConf);
|
||||
|
||||
FortWindow fortWindow(&firewallConf, &fortSettings);
|
||||
fortWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
83
src/ui/qml/main.qml
Normal file
83
src/ui/qml/main.qml
Normal file
@ -0,0 +1,83 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Dialogs 1.2
|
||||
import QtQuick.Controls 2.2
|
||||
import "pages"
|
||||
|
||||
ApplicationWindow {
|
||||
id: mainWindow
|
||||
|
||||
visible: true
|
||||
title: QT_TRANSLATE_NOOP("qml", "Fort Firewall")
|
||||
|
||||
width: 640
|
||||
height: 480
|
||||
minimumWidth: 400
|
||||
minimumHeight: 300
|
||||
|
||||
font.pixelSize: 16
|
||||
|
||||
Component.onCompleted: {
|
||||
tabBar.currentItem.forceActiveFocus();
|
||||
}
|
||||
|
||||
function closeWindow() {
|
||||
mainWindow.close();
|
||||
}
|
||||
|
||||
Page {
|
||||
anchors.fill: parent
|
||||
|
||||
Keys.onEscapePressed: closeWindow()
|
||||
|
||||
header: TabBar {
|
||||
id: tabBar
|
||||
currentIndex: swipeView.currentIndex
|
||||
|
||||
TabButton {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Options")
|
||||
}
|
||||
TabButton {
|
||||
text: QT_TRANSLATE_NOOP("qml", "IPv4 Addresses")
|
||||
}
|
||||
TabButton {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Applications")
|
||||
}
|
||||
}
|
||||
|
||||
SwipeView {
|
||||
id: swipeView
|
||||
anchors.fill: parent
|
||||
currentIndex: tabBar.currentIndex
|
||||
|
||||
OptionsPage {
|
||||
}
|
||||
AddressesPage {
|
||||
}
|
||||
ApplicationsPage {
|
||||
}
|
||||
}
|
||||
|
||||
footer: Pane {
|
||||
RowLayout {
|
||||
anchors.right: parent.right
|
||||
|
||||
Button {
|
||||
text: QT_TRANSLATE_NOOP("qml", "OK")
|
||||
onClicked: {
|
||||
if (fortWindow.save())
|
||||
closeWindow();
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Cancel")
|
||||
onClicked: closeWindow()
|
||||
}
|
||||
Button {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Quit")
|
||||
onClicked: Qt.quit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
src/ui/qml/pages/AddressesPage.qml
Normal file
6
src/ui/qml/pages/AddressesPage.qml
Normal file
@ -0,0 +1,6 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Frame {
|
||||
}
|
6
src/ui/qml/pages/ApplicationsPage.qml
Normal file
6
src/ui/qml/pages/ApplicationsPage.qml
Normal file
@ -0,0 +1,6 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Frame {
|
||||
}
|
20
src/ui/qml/pages/OptionsPage.qml
Normal file
20
src/ui/qml/pages/OptionsPage.qml
Normal file
@ -0,0 +1,20 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Frame {
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
|
||||
CheckBox {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Start with Windows")
|
||||
}
|
||||
CheckBox {
|
||||
text: QT_TRANSLATE_NOOP("qml", "Filtering enabled")
|
||||
checked: firewallConf.filterEnabled
|
||||
onToggled: {
|
||||
firewallConf.filterEnabled = checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user