UI: Prepare "-c prog export/import [path-to-json]" command line argument

This commit is contained in:
Nodir Temirkhodjaev 2024-09-20 15:11:40 +05:00
parent f98765a18a
commit baccf99761
3 changed files with 32 additions and 7 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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<WindowManager>()->showProgramEditForm(appPath);
return IoC<WindowManager>()->showProgramEditForm(path);
}
case ProgActionDel: {
return IoC<ConfAppManager>()->deleteAppPath(appPath);
return IoC<ConfAppManager>()->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<ConfAppManager>()->addOrUpdateAppPath(appPath, blocked, killProcess);
return IoC<ConfAppManager>()->addOrUpdateAppPath(path, blocked, killProcess);
}
case ProgActionExport: {
return IoC<ConfAppManager>()->exportJson(path);
}
case ProgActionImport: {
return IoC<ConfAppManager>()->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 <app-path>";
p.errorMessage = "Usage: prog add|del|allow|block|kill|show <path>";
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 {