From 176a870ae3d6effd6f7a2a089b4feab59cf665c5 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 16 Dec 2019 15:41:44 +0500 Subject: [PATCH] UI: Remove QML; Prepare OptionsWindow. --- deploy/deployment.json | 25 ----- deploy/setup-deployment.bat | 2 +- src/scripts/Readme.txt | 5 - src/scripts/torrent.qs | 2 - src/ui/FortFirewall.pro | 9 +- src/ui/conf/firewallconf.cpp | 10 -- src/ui/conf/firewallconf.h | 5 - src/ui/control/controlmanager.cpp | 90 +++++++++--------- src/ui/control/controlmanager.h | 10 +- src/ui/control/controlworker.cpp | 4 +- src/ui/control/controlworker.h | 8 +- src/ui/form/optionswindow.cpp | 15 +++ src/ui/form/optionswindow.h | 23 +++++ src/ui/fortmanager.cpp | 141 ++++++---------------------- src/ui/fortmanager.h | 20 ++-- src/ui/fortsettings.cpp | 6 +- src/ui/fortsettings.h | 4 +- src/ui/main.cpp | 2 +- src/ui/task/taskmanager.cpp | 5 - src/ui/task/taskmanager.h | 3 - src/ui/translationmanager.cpp | 2 +- src/ui/translationmanager.h | 2 +- src/ui/util/app/appiconprovider.cpp | 38 -------- src/ui/util/app/appiconprovider.h | 23 ----- src/ui/util/app/appinfo.cpp | 6 -- src/ui/util/app/appinfo.h | 3 - 26 files changed, 149 insertions(+), 314 deletions(-) delete mode 100644 src/scripts/Readme.txt delete mode 100644 src/scripts/torrent.qs create mode 100644 src/ui/form/optionswindow.cpp create mode 100644 src/ui/form/optionswindow.h delete mode 100644 src/ui/util/app/appiconprovider.cpp delete mode 100644 src/ui/util/app/appiconprovider.h diff --git a/deploy/deployment.json b/deploy/deployment.json index 1a5bcd00..79713f8c 100644 --- a/deploy/deployment.json +++ b/deploy/deployment.json @@ -4,17 +4,11 @@ "common": [ "${QTPATH}/bin/Qt6Core.dll", "${QTPATH}/bin/Qt6Gui.dll", - "${QTPATH}/bin/Qt6Qml.dll", - "${QTPATH}/bin/Qt6QmlModels.dll", - "${QTPATH}/bin/Qt6Quick.dll", - "${QTPATH}/bin/Qt6QuickControls2.dll", - "${QTPATH}/bin/Qt6QuickTemplates2.dll", "${QTPATH}/bin/Qt6Widgets.dll" ], "fort": [ "${BUILD}/FortFirewall.exe", "${ROOT}/ChangeLog", - "${ROOT}/src/scripts | *.qs Readme.txt |", "${ROOT}/src/ui/i18n | *.qm |" ] }, @@ -23,25 +17,6 @@ "${ROOT}/src/driver/scripts | *.bat *.lnk |" ] }, - "${TARGET}/imports": { - "common": [ - "${QTPATH}/qml/QtQuick.2 | *.dll qmldir | *d.dll", - "${QTPATH}/qml/QtQml | *.dll qmldir | *d.dll" - ] - }, - "${TARGET}/imports/QtQml": { - "common": [ - "${QTPATH}/qml/QtQml/Models.2 | *.dll qmldir | *d.dll" - ] - }, - "${TARGET}/imports/QtQuick": { - "common": [ - "${QTPATH}/qml/QtQuick/Controls.2 | *.dll qmldir *.qml | *d.dll", - "${QTPATH}/qml/QtQuick/Layouts | *.dll qmldir | *d.dll", - "${QTPATH}/qml/QtQuick/Templates.2 | *.dll qmldir | *d.dll", - "${QTPATH}/qml/QtQuick/Window.2 | *.dll qmldir | *d.dll" - ] - }, "${TARGET}/plugins": { "common": [ "${QTPATH}/plugins/platforms | qwindows.dll | *d.dll" diff --git a/deploy/setup-deployment.bat b/deploy/setup-deployment.bat index c2444e1e..c9898ac5 100644 --- a/deploy/setup-deployment.bat +++ b/deploy/setup-deployment.bat @@ -6,7 +6,7 @@ md %TARGET_PATH% cd %TARGET_PATH% del /Q /F qt*.* FortFirewall.exe -rd /Q /S driver\scripts i18n imports plugins scripts +rd /Q /S driver\scripts i18n imports plugins cd .. powershell.exe -executionpolicy remotesigned -file setup-deployment.ps1 %TARGET_PATH% %* diff --git a/src/scripts/Readme.txt b/src/scripts/Readme.txt deleted file mode 100644 index 3e9d4442..00000000 --- a/src/scripts/Readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -This folder contains control scripts. - -Run as: FortFirewall.exe --control "arg1" "arg2" ... - -Example: FortFirewall.exe --control scripts/torrent.qs "torrentEnabled=0" diff --git a/src/scripts/torrent.qs b/src/scripts/torrent.qs deleted file mode 100644 index de692ac4..00000000 --- a/src/scripts/torrent.qs +++ /dev/null @@ -1,2 +0,0 @@ -const torrentGroup = conf.appGroupByName("Torrent"); -torrentGroup.enabled = !!parseInt(arg["torrentEnabled"]); diff --git a/src/ui/FortFirewall.pro b/src/ui/FortFirewall.pro index b9a1805e..e0009acb 100644 --- a/src/ui/FortFirewall.pro +++ b/src/ui/FortFirewall.pro @@ -1,4 +1,4 @@ -QT += core gui qml quick widgets +QT += core gui widgets CONFIG += c++11 @@ -18,6 +18,7 @@ SOURCES += \ control/controlworker.cpp \ driver/drivermanager.cpp \ driver/driverworker.cpp \ + form/optionswindow.cpp \ fortcommon.cpp \ fortmanager.cpp \ fortsettings.cpp \ @@ -50,7 +51,6 @@ SOURCES += \ task/taskupdatechecker.cpp \ task/taskworker.cpp \ translationmanager.cpp \ - util/app/appiconprovider.cpp \ util/app/appinfo.cpp \ util/app/appinfocache.cpp \ util/app/appinfojob.cpp \ @@ -94,6 +94,7 @@ HEADERS += \ control/controlworker.h \ driver/drivermanager.h \ driver/driverworker.h \ + form/optionswindow.h \ fortcommon.h \ fortmanager.h \ fortsettings.h \ @@ -125,7 +126,6 @@ HEADERS += \ task/taskupdatechecker.h \ task/taskworker.h \ translationmanager.h \ - util/app/appiconprovider.h \ util/app/appinfo.h \ util/app/appinfocache.h \ util/app/appinfojob.h \ @@ -175,9 +175,6 @@ QML_FILES += \ OTHER_FILES += \ $${QML_FILES} -# QML files -RESOURCES += fort_qml.qrc - # Images RESOURCES += fort_images.qrc diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index fd6be91e..f35ce970 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -211,11 +211,6 @@ void FirewallConf::setAppGroupBits(quint32 groupBits) } } -QQmlListProperty FirewallConf::addressGroups() -{ - return {this, m_addressGroups}; -} - AppGroup *FirewallConf::appGroupByName(const QString &name) const { for (AppGroup *appGroup : appGroupsList()) { @@ -225,11 +220,6 @@ AppGroup *FirewallConf::appGroupByName(const QString &name) const return nullptr; } -QQmlListProperty FirewallConf::appGroups() -{ - return {this, m_appGroups}; -} - void FirewallConf::addAppGroup(AppGroup *appGroup, int to) { appGroup->setParent(this); diff --git a/src/ui/conf/firewallconf.h b/src/ui/conf/firewallconf.h index 4743e375..c4534e40 100644 --- a/src/ui/conf/firewallconf.h +++ b/src/ui/conf/firewallconf.h @@ -2,7 +2,6 @@ #define FIREWALLCONF_H #include -#include #include QT_FORWARD_DECLARE_CLASS(AddressGroup) @@ -38,8 +37,6 @@ class FirewallConf : public QObject Q_PROPERTY(quint32 quotaDayMb READ quotaDayMb WRITE setQuotaDayMb NOTIFY quotaDayMbChanged) Q_PROPERTY(quint32 quotaMonthMb READ quotaMonthMb WRITE setQuotaMonthMb NOTIFY quotaMonthMbChanged) Q_PROPERTY(AddressGroup *inetAddressGroup READ inetAddressGroup NOTIFY addressGroupsChanged) - Q_PROPERTY(QQmlListProperty addressGroups READ addressGroups NOTIFY addressGroupsChanged) - Q_PROPERTY(QQmlListProperty appGroups READ appGroups NOTIFY appGroupsChanged) Q_CLASSINFO("DefaultProperty", "appGroups") public: @@ -121,12 +118,10 @@ public: AddressGroup *inetAddressGroup() const { return m_addressGroups.at(0); } const QList &addressGroupsList() const { return m_addressGroups; } - QQmlListProperty addressGroups(); Q_INVOKABLE AppGroup *appGroupByName(const QString &name) const; const QList &appGroupsList() const { return m_appGroups; } - QQmlListProperty appGroups(); const QList &removedAppGroupsList() const { return m_removedAppGroups; } void clearRemovedAppGroups() const; diff --git a/src/ui/control/controlmanager.cpp b/src/ui/control/controlmanager.cpp index 347ea624..3ed5b083 100644 --- a/src/ui/control/controlmanager.cpp +++ b/src/ui/control/controlmanager.cpp @@ -1,13 +1,14 @@ #include "controlmanager.h" -#include #include #include +#include "../conf/appgroup.h" #include "../conf/firewallconf.h" #include "../util/fileutil.h" #include "controlworker.h" #include "fortmanager.h" +#include "fortsettings.h" Q_DECLARE_LOGGING_CATEGORY(CLOG_CONTROL_MANAGER) Q_LOGGING_CATEGORY(CLOG_CONTROL_MANAGER, "fort.controlManager") @@ -16,11 +17,11 @@ Q_LOGGING_CATEGORY(CLOG_CONTROL_MANAGER, "fort.controlManager") #define logCritical() qCCritical(CLOG_CONTROL_MANAGER,) ControlManager::ControlManager(const QString &globalName, - const QString &scriptPath, + const QString &command, QObject *parent) : QObject(parent), - m_isClient(!scriptPath.isEmpty()), - m_scriptPath(scriptPath), + m_isClient(!command.isEmpty()), + m_command(command), m_fortManager(nullptr), m_worker(nullptr), m_semaphore(globalName + QLatin1String("_ControlSemaphore"), 0, @@ -64,57 +65,60 @@ bool ControlManager::post(const QStringList &args) ControlWorker worker(&m_semaphore, &m_sharedMemory); - return worker.post(m_scriptPath, args); + return worker.post(m_command, args); } -void ControlManager::processRequest(const QString &scriptPath, +void ControlManager::processRequest(const QString &command, const QStringList &args) { - const QString script = FileUtil::readFile(scriptPath); - if (script.isEmpty()) { - logWarning() << "Script is empty:" - << scriptPath; - return; + QString errorMessage; + if (!processCommand(command, args, errorMessage)) { + logWarning() << "Bad control command" << errorMessage + << ':' << command << args; } +} - QJSEngine engine; - engine.installExtensions(QJSEngine::ConsoleExtension); +bool ControlManager::processCommand(const QString &command, + const QStringList &args, + QString &errorMessage) +{ + const int argsSize = args.size(); - QJSValue globalObject = engine.globalObject(); - - // Arguments - QJSValue argsJs = engine.newArray(args.size()); - QJSValue argsMapJs = engine.newObject(); - for (int i = 0, n = args.size(); i < n; ++i) { - const QString &arg = args.at(i); - argsJs.setProperty(i, arg); - - const int sepPos = arg.indexOf('='); - if (sepPos > 0) { - const QString k = arg.left(sepPos); - const QString v = arg.mid(sepPos + 1); - argsMapJs.setProperty(k, v); + if (command == QLatin1String("ini")) { + if (argsSize < 3) { + errorMessage = "ini "; + return false; } - } - globalObject.setProperty("args", argsJs); - globalObject.setProperty("arg", argsMapJs); - // FirewallConf - QJSValue firewallConfJs = engine.newQObject( - m_fortManager->firewallConf()); - globalObject.setProperty("conf", firewallConfJs); + auto settings = m_fortManager->fortSettings(); - // Run the script - const QJSValue res = engine.evaluate(script, scriptPath); - if (res.isError()) { - logWarning() << "Script error:" - << scriptPath << "line" - << res.property("lineNumber").toInt() - << ":" << res.toString(); - return; + settings->setProperty(args.at(0).toLatin1(), QVariant(args.at(1))); + } else if (command == QLatin1String("conf")) { + if (argsSize < 3) { + errorMessage = "conf "; + return false; + } + + auto conf = m_fortManager->firewallConf(); + + const auto confPropName = args.at(0); + + if (confPropName == QLatin1String("appGroup")) { + if (argsSize < 4) { + errorMessage = "conf appGroup "; + return false; + } + + auto appGroup = conf->appGroupByName(args.at(1)); + appGroup->setProperty(args.at(2).toLatin1(), QVariant(args.at(3))); + } else { + conf->setProperty(confPropName.toLatin1(), QVariant(args.at(1))); + } + + m_fortManager->saveOriginConf(tr("Control command executed")); } - m_fortManager->saveOriginConf(tr("Control script executed")); + return true; } void ControlManager::setupWorker() diff --git a/src/ui/control/controlmanager.h b/src/ui/control/controlmanager.h index 5918d92a..ba9ce944 100644 --- a/src/ui/control/controlmanager.h +++ b/src/ui/control/controlmanager.h @@ -16,7 +16,7 @@ class ControlManager : public QObject public: explicit ControlManager(const QString &globalName, - const QString &scriptPath, + const QString &command, QObject *parent = nullptr); ~ControlManager() override; CLASS_DELETE_COPY_MOVE(ControlManager) @@ -31,10 +31,14 @@ signals: public slots: private slots: - void processRequest(const QString &scriptPath, + void processRequest(const QString &command, const QStringList &args); private: + bool processCommand(const QString &command, + const QStringList &args, + QString &errorMessage); + void setupWorker(); void abort(); @@ -42,7 +46,7 @@ private: private: bool m_isClient; - QString m_scriptPath; + QString m_command; FortManager *m_fortManager; ControlWorker *m_worker; diff --git a/src/ui/control/controlworker.cpp b/src/ui/control/controlworker.cpp index b8b1d951..f0ae50e0 100644 --- a/src/ui/control/controlworker.cpp +++ b/src/ui/control/controlworker.cpp @@ -38,12 +38,12 @@ void ControlWorker::abort() } } -bool ControlWorker::post(const QString &scriptPath, +bool ControlWorker::post(const QString &command, const QStringList &args) { m_sharedMemory->lock(); - const bool res = writeDataStream(scriptPath, args); + const bool res = writeDataStream(command, args); m_sharedMemory->unlock(); diff --git a/src/ui/control/controlworker.h b/src/ui/control/controlworker.h index 06206ea7..ca14a655 100644 --- a/src/ui/control/controlworker.h +++ b/src/ui/control/controlworker.h @@ -19,11 +19,11 @@ public: void run() override; - bool post(const QString &scriptPath, + bool post(const QString &command, const QStringList &args); signals: - void requestReady(const QString &scriptPath, + void requestReady(const QString &command, const QStringList &args); public slots: @@ -35,9 +35,9 @@ private: bool writeData(const QByteArray &data); QByteArray readData() const; - bool writeDataStream(const QString &scriptPath, + bool writeDataStream(const QString &command, const QStringList &args); - bool readDataStream(QString &scriptPath, + bool readDataStream(QString &command, QStringList &args) const; private: diff --git a/src/ui/form/optionswindow.cpp b/src/ui/form/optionswindow.cpp new file mode 100644 index 00000000..1a130040 --- /dev/null +++ b/src/ui/form/optionswindow.cpp @@ -0,0 +1,15 @@ +#include "optionswindow.h" + +OptionsWindow::OptionsWindow(QWindow *parent) : + QWindow(parent) +{ + setupUi(); +} + +void OptionsWindow::setupUi() +{ +} + +void OptionsWindow::retranslateUi() +{ +} diff --git a/src/ui/form/optionswindow.h b/src/ui/form/optionswindow.h new file mode 100644 index 00000000..0e959aaf --- /dev/null +++ b/src/ui/form/optionswindow.h @@ -0,0 +1,23 @@ +#ifndef OPTIONSWINDOW_H +#define OPTIONSWINDOW_H + +#include +#include + +class OptionsWindow : public QWindow +{ + Q_OBJECT + +public: + explicit OptionsWindow(QWindow *parent = nullptr); + +signals: + +public slots: + void retranslateUi(); + +private: + void setupUi(); +}; + +#endif // OPTIONSWINDOW_H diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index acea1e6d..d06d3d1b 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -6,8 +6,6 @@ #include #include #include -#include -#include #include #include #include @@ -18,6 +16,7 @@ #include "conf/confmanager.h" #include "conf/firewallconf.h" #include "driver/drivermanager.h" +#include "form/optionswindow.h" #include "fortsettings.h" #include "graph/graphwindow.h" #include "log/logmanager.h" @@ -31,7 +30,6 @@ #include "task/taskinfoupdatechecker.h" #include "task/taskmanager.h" #include "translationmanager.h" -#include "util/app/appiconprovider.h" #include "util/app/appinfocache.h" #include "util/app/appinfomanager.h" #include "util/dateutil.h" @@ -52,9 +50,8 @@ FortManager::FortManager(FortSettings *fortSettings, QObject *parent) : QObject(parent), m_trayIcon(new QSystemTrayIcon(this)), - m_engine(nullptr), - m_appWindow(nullptr), - m_appWindowState(new WindowStateWatcher(this)), + m_optWindow(nullptr), + m_optWindowState(new WindowStateWatcher(this)), m_graphWindow(nullptr), m_graphWindowState(new WidgetWindowStateWatcher(this)), m_fortSettings(fortSettings), @@ -91,8 +88,6 @@ FortManager::FortManager(FortSettings *fortSettings, loadSettings(); - registerQmlTypes(); - setupTaskManager(); setupTranslationManager(); setupTrayIcon(); @@ -108,48 +103,6 @@ FortManager::~FortManager() closeLogManager(); } -void FortManager::registerQmlTypes() -{ - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "DriverManager", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "FortSettings", - "Singleton"); - - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "LogManager", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "AppBlockedModel", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "AppStatModel", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "IpListModel", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "TrafListModel", - "Singleton"); - - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "TranslationManager", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "TaskManager", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "TaskInfo", - "Singleton"); - qmlRegisterUncreatableType("com.fortfirewall", 1, 0, "TaskInfoUpdateChecker", - "Singleton"); - - qmlRegisterType("com.fortfirewall", 1, 0, "AddressGroup"); - qmlRegisterType("com.fortfirewall", 1, 0, "AppGroup"); - qmlRegisterType("com.fortfirewall", 1, 0, "FirewallConf"); - - qRegisterMetaType(); - qmlRegisterType("com.fortfirewall", 1, 0, "AppInfoCache"); - qmlRegisterType("com.fortfirewall", 1, 0, "DateUtil"); - qmlRegisterType("com.fortfirewall", 1, 0, "FileUtil"); - qmlRegisterType("com.fortfirewall", 1, 0, "GuiUtil"); - qmlRegisterType("com.fortfirewall", 1, 0, "HostInfoCache"); - qmlRegisterType("com.fortfirewall", 1, 0, "NetUtil"); - qmlRegisterType("com.fortfirewall", 1, 0, "OsUtil"); - qmlRegisterType("com.fortfirewall", 1, 0, "StringUtil"); -} - void FortManager::setupThreadPool() { QThreadPool::globalInstance()->setMaxThreadCount( @@ -257,7 +210,7 @@ void FortManager::setupTrayIcon() connect(m_trayIcon, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) { - showWindow(); + showOptionsWindow(); } }); @@ -281,61 +234,26 @@ void FortManager::setupAppInfoCache() m_appInfoCache->setManager(manager); } -bool FortManager::setupEngine() +bool FortManager::setupOptionsWindow() { if (m_fortSettings->isPortable()) { - qputenv("QML_DISABLE_DISK_CACHE", "1"); qputenv("QT_DISABLE_SHADER_DISK_CACHE", "1"); } - m_engine = new QQmlApplicationEngine(this); - - QQmlContext *context = m_engine->rootContext(); - context->setContextProperty("fortManager", this); - context->setContextProperty("driverManager", m_driverManager); - context->setContextProperty("translationManager", TranslationManager::instance()); - context->setContextProperty("taskManager", m_taskManager); - context->setContextProperty("appInfoCache", m_appInfoCache); - - m_engine->addImageProvider(AppIconProvider::id(), - new AppIconProvider(m_appInfoCache->manager())); - - m_engine->load(QUrl("qrc:/qml/main.qml")); - - const QList rootObjects = m_engine->rootObjects(); - - if (rootObjects.isEmpty()) { - showErrorBox("Cannot setup QML Engine"); - return false; - } + m_optWindow = new OptionsWindow(); connect(TranslationManager::instance(), &TranslationManager::languageChanged, - m_engine, &QQmlEngine::retranslate); + m_optWindow, &OptionsWindow::retranslateUi); - m_appWindow = qobject_cast(rootObjects.first()); - Q_ASSERT(m_appWindow); - - m_appWindowState->install(m_appWindow); + m_optWindowState->install(m_optWindow); return true; } -void FortManager::closeEngine() -{ - m_appWindow = nullptr; - - if (m_engine) { - m_engine->deleteLater(); - m_engine = nullptr; - } -} - void FortManager::closeUi() { closeGraphWindow(true); - closeWindow(); - - closeEngine(); + closeOptionsWindow(); } void FortManager::launch() @@ -365,13 +283,13 @@ void FortManager::showTrayMenu(QMouseEvent *event) menu->popup(event->globalPos()); } -void FortManager::showWindow() +void FortManager::showOptionsWindow() { - if (!m_engine) { - setupEngine(); + if (!m_optWindow) { + setupOptionsWindow(); } - if (!m_appWindow || !(m_appWindow->isVisible() + if (!m_optWindow || !(m_optWindow->isVisible() || checkPassword())) return; @@ -380,21 +298,24 @@ void FortManager::showWindow() setFirewallConfToEdit(newConf); } - m_appWindow->show(); - m_appWindow->raise(); - m_appWindow->requestActivate(); + m_optWindow->show(); + m_optWindow->raise(); + m_optWindow->requestActivate(); - restoreWindowState(); + restoreOptWindowState(); } -void FortManager::closeWindow() +void FortManager::closeOptionsWindow() { - if (!m_appWindow) + if (!m_optWindow) return; - saveWindowState(); + saveOptWindowState(); - m_appWindow->hide(); + m_optWindow->hide(); + + m_optWindow->deleteLater(); + m_optWindow = nullptr; setFirewallConfToEdit(nullptr); } @@ -504,7 +425,7 @@ bool FortManager::saveOriginConf(const QString &message) if (!saveSettings(m_firewallConf)) return false; - closeWindow(); + closeOptionsWindow(); showTrayMessage(message); return true; } @@ -646,17 +567,17 @@ void FortManager::saveTrayFlags() updateDriverConf(true); } -void FortManager::saveWindowState() +void FortManager::saveOptWindowState() { - m_fortSettings->setOptWindowGeometry(m_appWindowState->geometry()); - m_fortSettings->setOptWindowMaximized(m_appWindowState->maximized()); + m_fortSettings->setOptWindowGeometry(m_optWindowState->geometry()); + m_fortSettings->setOptWindowMaximized(m_optWindowState->maximized()); emit afterSaveWindowState(); } -void FortManager::restoreWindowState() +void FortManager::restoreOptWindowState() { - m_appWindowState->restore(m_appWindow, QSize(1024, 768), + m_optWindowState->restore(m_optWindow, QSize(1024, 768), m_fortSettings->optWindowGeometry(), m_fortSettings->optWindowMaximized()); @@ -699,7 +620,7 @@ void FortManager::updateTrayMenu() QAction *optionsAction = addAction( menu, QIcon(":/images/cog.png"), tr("Options"), - this, SLOT(showWindow())); + this, SLOT(showOptionsWindow())); addHotKey(optionsAction, fortSettings()->hotKeyOptions(), hotKeyEnabled); m_graphWindowAction = addAction( diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 20c22ed9..e6d428ea 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -6,7 +6,6 @@ #include "mainwindow.h" #include "util/classhelpers.h" -QT_FORWARD_DECLARE_CLASS(QQmlApplicationEngine) QT_FORWARD_DECLARE_CLASS(QSystemTrayIcon) QT_FORWARD_DECLARE_CLASS(AppInfoCache) @@ -19,6 +18,7 @@ QT_FORWARD_DECLARE_CLASS(GraphWindow) QT_FORWARD_DECLARE_CLASS(HotKeyManager) QT_FORWARD_DECLARE_CLASS(LogManager) QT_FORWARD_DECLARE_CLASS(NativeEventFilter) +QT_FORWARD_DECLARE_CLASS(OptionsWindow) QT_FORWARD_DECLARE_CLASS(QuotaManager) QT_FORWARD_DECLARE_CLASS(StatManager) QT_FORWARD_DECLARE_CLASS(TaskManager) @@ -65,8 +65,8 @@ public slots: void showTrayMessage(const QString &message); void showTrayMenu(QMouseEvent *event); - void showWindow(); - void closeWindow(); + void showOptionsWindow(); + void closeOptionsWindow(); void showGraphWindow(); void closeGraphWindow(bool storeVisibility = false); @@ -98,8 +98,6 @@ private slots: private: void setFirewallConfToEdit(FirewallConf *conf); - static void registerQmlTypes(); - void setupThreadPool(); bool setupDriver(); @@ -121,8 +119,7 @@ private: void setupAppInfoCache(); - bool setupEngine(); - void closeEngine(); + bool setupOptionsWindow(); void closeUi(); @@ -135,8 +132,8 @@ private: void updateLogManager(bool active); void updateStatManager(FirewallConf *conf); - void saveWindowState(); - void restoreWindowState(); + void saveOptWindowState(); + void restoreOptWindowState(); void saveGraphWindowState(bool visible); void restoreGraphWindowState(); @@ -159,10 +156,9 @@ private: MainWindow m_window; // dummy window for tray icon QSystemTrayIcon *m_trayIcon; - QQmlApplicationEngine *m_engine; - QWindow *m_appWindow; - WindowStateWatcher *m_appWindowState; + OptionsWindow *m_optWindow; + WindowStateWatcher *m_optWindowState; GraphWindow *m_graphWindow; WidgetWindowStateWatcher *m_graphWindowState; diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index 36fb66fe..9fd4e73e 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -64,7 +64,7 @@ void FortSettings::processArguments(const QStringList &args) const QCommandLineOption controlOption( QStringList() << "c" << "control", - "Control running instance by executing the JS file.", "control"); + "Control running instance by executing the command.", "control"); parser.addOption(controlOption); parser.addVersionOption(); @@ -98,8 +98,8 @@ void FortSettings::processArguments(const QStringList &args) FileUtil::absolutePath(m_statPath)); } - // Control JS file path - m_controlPath = parser.value(controlOption); + // Control command + m_controlCommand = parser.value(controlOption); // Other Arguments m_args = parser.positionalArguments(); diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index 36799e84..6dcfd01a 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -173,7 +173,7 @@ public: QString confOldFilePath() const; QString confBackupFilePath() const; - QString controlPath() const { return m_controlPath; } + QString controlCommand() const { return m_controlCommand; } QStringList args() const { return m_args; } @@ -250,7 +250,7 @@ private: QString m_profilePath; QString m_statPath; - QString m_controlPath; + QString m_controlCommand; QStringList m_args; QString m_errorMessage; diff --git a/src/ui/main.cpp b/src/ui/main.cpp index b169def9..e2cce51d 100644 --- a/src/ui/main.cpp +++ b/src/ui/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) } ControlManager controlManager(QApplication::applicationName(), - fortSettings.controlPath()); + fortSettings.controlCommand()); // Send control request to running instance if (controlManager.isClient()) { diff --git a/src/ui/task/taskmanager.cpp b/src/ui/task/taskmanager.cpp index bf36de53..244f66dc 100644 --- a/src/ui/task/taskmanager.cpp +++ b/src/ui/task/taskmanager.cpp @@ -22,11 +22,6 @@ TaskManager::TaskManager(FortManager *fortManager, this, &TaskManager::runExpiredTasks); } -QQmlListProperty TaskManager::taskInfos() -{ - return {this, m_taskInfos}; -} - void TaskManager::setupTasks() { m_taskInfoUpdateChecker = new TaskInfoUpdateChecker(this); diff --git a/src/ui/task/taskmanager.h b/src/ui/task/taskmanager.h index 48a44b3a..c15ea91e 100644 --- a/src/ui/task/taskmanager.h +++ b/src/ui/task/taskmanager.h @@ -2,7 +2,6 @@ #define TASKMANAGER_H #include -#include #include QT_FORWARD_DECLARE_CLASS(ConfManager) @@ -15,7 +14,6 @@ class TaskManager : public QObject { Q_OBJECT Q_PROPERTY(TaskInfoUpdateChecker *taskInfoUpdateChecker READ taskInfoUpdateChecker CONSTANT) - Q_PROPERTY(QQmlListProperty taskInfos READ taskInfos NOTIFY taskInfosChanged) Q_CLASSINFO("DefaultProperty", "taskInfos") public: @@ -27,7 +25,6 @@ public: TaskInfoUpdateChecker *taskInfoUpdateChecker() const { return m_taskInfoUpdateChecker; } const QList &taskInfosList() const { return m_taskInfos; } - QQmlListProperty taskInfos(); signals: void taskInfosChanged(); diff --git a/src/ui/translationmanager.cpp b/src/ui/translationmanager.cpp index 11b437e4..68143268 100644 --- a/src/ui/translationmanager.cpp +++ b/src/ui/translationmanager.cpp @@ -89,7 +89,7 @@ bool TranslationManager::switchLanguage(int language) installTranslator(language, m_locale); m_language = language; - emit languageChanged(m_language); + emit languageChanged(); return true; } diff --git a/src/ui/translationmanager.h b/src/ui/translationmanager.h index 2d0aa2a9..a4f63811 100644 --- a/src/ui/translationmanager.h +++ b/src/ui/translationmanager.h @@ -32,7 +32,7 @@ public: int getLanguageByName(const QString &localeName) const; signals: - void languageChanged(int language); + void languageChanged(); public slots: bool switchLanguage(int language = 0); diff --git a/src/ui/util/app/appiconprovider.cpp b/src/ui/util/app/appiconprovider.cpp deleted file mode 100644 index e4c2dc34..00000000 --- a/src/ui/util/app/appiconprovider.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "appiconprovider.h" - -#include "appinfomanager.h" - -AppIconProvider::AppIconProvider(AppInfoManager *manager) : - QQuickImageProvider(QQuickImageProvider::Image), - m_manager(manager) -{ -} - -QImage AppIconProvider::requestImage(const QString &id, QSize *size, - const QSize &requestedSize) -{ - Q_UNUSED(size) - Q_UNUSED(requestedSize) - - QImage icon; - - bool ok; - const qint64 iconId = id.toLongLong(&ok, 16); - if (ok && iconId != 0) { - icon = m_manager->loadIconFromDb(iconId); - } - - return icon.isNull() ? QImage(":/images/application.png") - : icon; -} - -QString AppIconProvider::id() -{ - return QLatin1String("app-icon"); -} - -QString AppIconProvider::iconPath(qint64 iconId) -{ - return QLatin1String("image://") + id() - + QString("/%1").arg(iconId, 0, 16); -} diff --git a/src/ui/util/app/appiconprovider.h b/src/ui/util/app/appiconprovider.h deleted file mode 100644 index d9cd32e1..00000000 --- a/src/ui/util/app/appiconprovider.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef APPICONPROVIDER_H -#define APPICONPROVIDER_H - -#include - -QT_FORWARD_DECLARE_CLASS(AppInfoManager) - -class AppIconProvider: public QQuickImageProvider -{ -public: - explicit AppIconProvider(AppInfoManager *manager); - - QImage requestImage(const QString &id, QSize *size, - const QSize &requestedSize) override; - - static QString id(); - static QString iconPath(qint64 iconId); - -private: - AppInfoManager *m_manager; -}; - -#endif // APPICONPROVIDER_H diff --git a/src/ui/util/app/appinfo.cpp b/src/ui/util/app/appinfo.cpp index 1588e678..f237d9a3 100644 --- a/src/ui/util/app/appinfo.cpp +++ b/src/ui/util/app/appinfo.cpp @@ -1,13 +1,7 @@ #include "appinfo.h" -#include "appiconprovider.h" #include "apputil.h" -QString AppInfo::iconPath() const -{ - return AppIconProvider::iconPath(iconId); -} - bool AppInfo::isFileModified(const QString &appPath) const { return fileModTime != AppUtil::getModTime(appPath); diff --git a/src/ui/util/app/appinfo.h b/src/ui/util/app/appinfo.h index c3d6ba0f..5c374577 100644 --- a/src/ui/util/app/appinfo.h +++ b/src/ui/util/app/appinfo.h @@ -7,15 +7,12 @@ class AppInfo { Q_GADGET - Q_PROPERTY(QString iconPath READ iconPath CONSTANT) Q_PROPERTY(QString fileDescription MEMBER fileDescription CONSTANT) Q_PROPERTY(QString companyName MEMBER companyName CONSTANT) Q_PROPERTY(QString productName MEMBER productName CONSTANT) Q_PROPERTY(QString productVersion MEMBER productVersion CONSTANT) public: - QString iconPath() const; - bool isFileModified(const QString &appPath) const; public: