From baccf9976111ab8eabc9a72f52f966657b3008f6 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 20 Sep 2024 15:11:40 +0500 Subject: [PATCH] UI: Prepare "-c prog export/import [path-to-json]" command line argument --- src/ui/conf/confappmanager.cpp | 14 ++++++++++++++ src/ui/conf/confappmanager.h | 3 +++ src/ui/control/controlmanager.cpp | 22 +++++++++++++++------- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/ui/conf/confappmanager.cpp b/src/ui/conf/confappmanager.cpp index df05ca3b..e0ae5d64 100644 --- a/src/ui/conf/confappmanager.cpp +++ b/src/ui/conf/confappmanager.cpp @@ -646,6 +646,20 @@ bool ConfAppManager::updateDriverConf(bool onlyFlags) return true; } +bool ConfAppManager::exportJson(const QString &path) const +{ + qCDebug(LC) << "Export apps as JSON:" << path; + + return false; +} + +bool ConfAppManager::importJson(const QString &path) +{ + qCDebug(LC) << "Import apps as JSON:" << path; + + return false; +} + bool ConfAppManager::loadAppById(App &app) { SqliteStmt stmt; diff --git a/src/ui/conf/confappmanager.h b/src/ui/conf/confappmanager.h index 08fe337e..464651af 100644 --- a/src/ui/conf/confappmanager.h +++ b/src/ui/conf/confappmanager.h @@ -56,6 +56,9 @@ public: virtual bool updateDriverConf(bool onlyFlags = false); + bool exportJson(const QString &path) const; + bool importJson(const QString &path); + signals: void appAlerted(); void appsChanged(); diff --git a/src/ui/control/controlmanager.cpp b/src/ui/control/controlmanager.cpp index a757df61..f0bbac01 100644 --- a/src/ui/control/controlmanager.cpp +++ b/src/ui/control/controlmanager.cpp @@ -51,16 +51,18 @@ enum ProgAction : quint32 { ProgActionAllow = (1 << 2), ProgActionBlock = (1 << 3), ProgActionKill = (1 << 4), + ProgActionExport = (1 << 5), + ProgActionImport = (1 << 6), }; -bool processCommandProgAction(ProgAction progAction, const QString &appPath) +bool processCommandProgAction(ProgAction progAction, const QString &path) { switch (progAction) { case ProgActionAdd: { - return IoC()->showProgramEditForm(appPath); + return IoC()->showProgramEditForm(path); } case ProgActionDel: { - return IoC()->deleteAppPath(appPath); + return IoC()->deleteAppPath(path); } case ProgActionAllow: case ProgActionBlock: @@ -68,7 +70,13 @@ bool processCommandProgAction(ProgAction progAction, const QString &appPath) const bool blocked = (progAction != ProgActionAllow); const bool killProcess = (progAction == ProgActionKill); - return IoC()->addOrUpdateAppPath(appPath, blocked, killProcess); + return IoC()->addOrUpdateAppPath(path, blocked, killProcess); + } + case ProgActionExport: { + return IoC()->exportJson(path); + } + case ProgActionImport: { + return IoC()->importJson(path); } default: return false; @@ -107,7 +115,7 @@ bool processCommandProg(const ProcessCommandArgs &p) { const ProgAction progAction = progActionByText(p.args.value(0).toString()); if (progAction == ProgActionNone) { - p.errorMessage = "Usage: prog add|del|allow|block|kill|show "; + p.errorMessage = "Usage: prog add|del|allow|block|kill|show "; return false; } @@ -116,9 +124,9 @@ bool processCommandProg(const ProcessCommandArgs &p) return false; } - const QString appPath = p.args.value(1).toString(); + const QString path = p.args.value(1).toString(); - return processCommandProgAction(progAction, appPath); + return processCommandProgAction(progAction, path); } enum ZoneAction : quint32 {