diff --git a/src/ui/FortFirewall.pro b/src/ui/FortFirewall.pro index 61f89238..228dc18a 100644 --- a/src/ui/FortFirewall.pro +++ b/src/ui/FortFirewall.pro @@ -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 diff --git a/src/ui/fort_images.qrc b/src/ui/fort_images.qrc new file mode 100644 index 00000000..9a43c405 --- /dev/null +++ b/src/ui/fort_images.qrc @@ -0,0 +1,5 @@ + + + images/cog.png + + diff --git a/src/ui/fort_qml.qrc b/src/ui/fort_qml.qrc new file mode 100644 index 00000000..921c423d --- /dev/null +++ b/src/ui/fort_qml.qrc @@ -0,0 +1,8 @@ + + + qml/main.qml + qml/pages/AddressesPage.qml + qml/pages/ApplicationsPage.qml + qml/pages/OptionsPage.qml + + diff --git a/src/ui/fortwindow.cpp b/src/ui/fortwindow.cpp new file mode 100644 index 00000000..504943e4 --- /dev/null +++ b/src/ui/fortwindow.cpp @@ -0,0 +1,49 @@ +#include "fortwindow.h" + +#include +#include + +#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("com.fortfirewall", 1, 0, "FortSettings", + "Singleton"); + + qmlRegisterType("com.fortfirewall", 1, 0, "AppGroup"); + qmlRegisterType("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); +} diff --git a/src/ui/fortwindow.h b/src/ui/fortwindow.h new file mode 100644 index 00000000..b9f296bc --- /dev/null +++ b/src/ui/fortwindow.h @@ -0,0 +1,39 @@ +#ifndef FORTWINDOW_H +#define FORTWINDOW_H + +#include + +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 diff --git a/src/ui/images/cog.png b/src/ui/images/cog.png new file mode 100644 index 00000000..67de2c6c Binary files /dev/null and b/src/ui/images/cog.png differ diff --git a/src/ui/main.cpp b/src/ui/main.cpp index 26ac37aa..96a5faf2 100644 --- a/src/ui/main.cpp +++ b/src/ui/main.cpp @@ -1,8 +1,21 @@ #include +#include + +#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(); } diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml new file mode 100644 index 00000000..a7115921 --- /dev/null +++ b/src/ui/qml/main.qml @@ -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() + } + } + } + } +} diff --git a/src/ui/qml/pages/AddressesPage.qml b/src/ui/qml/pages/AddressesPage.qml new file mode 100644 index 00000000..0b7ae9df --- /dev/null +++ b/src/ui/qml/pages/AddressesPage.qml @@ -0,0 +1,6 @@ +import QtQuick 2.9 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.2 + +Frame { +} diff --git a/src/ui/qml/pages/ApplicationsPage.qml b/src/ui/qml/pages/ApplicationsPage.qml new file mode 100644 index 00000000..0b7ae9df --- /dev/null +++ b/src/ui/qml/pages/ApplicationsPage.qml @@ -0,0 +1,6 @@ +import QtQuick 2.9 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.2 + +Frame { +} diff --git a/src/ui/qml/pages/OptionsPage.qml b/src/ui/qml/pages/OptionsPage.qml new file mode 100644 index 00000000..f3930499 --- /dev/null +++ b/src/ui/qml/pages/OptionsPage.qml @@ -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; + } + } + } +}