UI: Programs: Add "Notes" field

This commit is contained in:
Nodir Temirkhodjaev 2024-01-17 13:23:41 +03:00
parent 695518083d
commit 118b431245
10 changed files with 86 additions and 53 deletions

View File

@ -26,7 +26,8 @@ bool App::isExtraFlagsEqual(const App &o) const
bool App::isOptionsEqual(const App &o) const bool App::isOptionsEqual(const App &o) const
{ {
return isFlagsEqual(o) && isZonesEqual(o) && groupIndex == o.groupIndex return isFlagsEqual(o) && isZonesEqual(o) && groupIndex == o.groupIndex
&& appOriginPath == o.appOriginPath && appPath == o.appPath && endTime == o.endTime; && appOriginPath == o.appOriginPath && appPath == o.appPath && notes == o.notes
&& endTime == o.endTime;
} }
bool App::isNameEqual(const App &o) const bool App::isNameEqual(const App &o) const

View File

@ -39,6 +39,7 @@ public:
QString appOriginPath; QString appOriginPath;
QString appPath; QString appPath;
QString appName; QString appName;
QString notes;
QDateTime endTime; QDateTime endTime;
QDateTime creatTime; QDateTime creatTime;

View File

@ -32,6 +32,8 @@ constexpr int APP_END_TIMER_INTERVAL_MAX = 24 * 60 * 60 * 1000; // 1 day
" t.app_id," \ " t.app_id," \
" t.origin_path," \ " t.origin_path," \
" t.path," \ " t.path," \
" t.name," \
" t.notes," \
" t.is_wildcard," \ " t.is_wildcard," \
" t.use_group_perm," \ " t.use_group_perm," \
" t.apply_child," \ " t.apply_child," \
@ -44,6 +46,7 @@ constexpr int APP_END_TIMER_INTERVAL_MAX = 24 * 60 * 60 * 1000; // 1 day
" t.kill_process," \ " t.kill_process," \
" t.accept_zones," \ " t.accept_zones," \
" t.reject_zones," \ " t.reject_zones," \
" t.end_time," \
" g.order_index as group_index," \ " g.order_index as group_index," \
" (alert.app_id IS NOT NULL) as alerted" " (alert.app_id IS NOT NULL) as alerted"
@ -69,29 +72,29 @@ const char *const sqlSelectEndedApps = "SELECT" SELECT_APP_FIELDS " FROM app t"
const char *const sqlSelectAppIdByPath = "SELECT app_id FROM app WHERE path = ?1;"; const char *const sqlSelectAppIdByPath = "SELECT app_id FROM app WHERE path = ?1;";
const char *const sqlUpsertApp = "INSERT INTO app(app_group_id, origin_path, path, name," const char *const sqlUpsertApp = "INSERT INTO app(app_group_id, origin_path, path, name, notes,"
" is_wildcard, use_group_perm, apply_child, kill_child," " is_wildcard, use_group_perm, apply_child, kill_child,"
" lan_only, parked, log_blocked, log_conn," " lan_only, parked, log_blocked, log_conn,"
" blocked, kill_process, accept_zones, reject_zones," " blocked, kill_process, accept_zones, reject_zones,"
" end_time, creat_time)" " end_time, creat_time)"
" VALUES(?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9," " VALUES(?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9,"
" ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)" " ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20)"
" ON CONFLICT(path) DO UPDATE" " ON CONFLICT(path) DO UPDATE"
" SET app_group_id = ?2, origin_path = ?3, name = ?5," " SET app_group_id = ?2, origin_path = ?3, name = ?5,"
" is_wildcard = ?6, use_group_perm = ?7," " notes = ?6, is_wildcard = ?7, use_group_perm = ?8,"
" apply_child = ?8, kill_child = ?9, lan_only = ?10," " apply_child = ?9, kill_child = ?10, lan_only = ?11,"
" parked = ?11, log_blocked = ?12, log_conn = ?13," " parked = ?12, log_blocked = ?13, log_conn = ?14,"
" blocked = ?14, kill_process = ?15," " blocked = ?15, kill_process = ?16,"
" accept_zones = ?16, reject_zones = ?17, end_time = ?18" " accept_zones = ?17, reject_zones = ?18, end_time = ?19"
" RETURNING app_id;"; " RETURNING app_id;";
const char *const sqlUpdateApp = "UPDATE app" const char *const sqlUpdateApp = "UPDATE app"
" SET app_group_id = ?2, origin_path = ?3, path = ?4," " SET app_group_id = ?2, origin_path = ?3, path = ?4, name = ?5,"
" name = ?5, is_wildcard = ?6, use_group_perm = ?7," " notes = ?6, is_wildcard = ?7, use_group_perm = ?8,"
" apply_child = ?8, kill_child = ?9, lan_only = ?10," " apply_child = ?9, kill_child = ?10, lan_only = ?11,"
" parked = ?11, log_blocked = ?12, log_conn = ?13," " parked = ?12, log_blocked = ?13, log_conn = ?14,"
" blocked = ?14, kill_process = ?15," " blocked = ?15, kill_process = ?16,"
" accept_zones = ?16, reject_zones = ?17, end_time = ?18" " accept_zones = ?17, reject_zones = ?18, end_time = ?19"
" WHERE app_id = ?1" " WHERE app_id = ?1"
" RETURNING app_id;"; " RETURNING app_id;";
@ -196,10 +199,11 @@ void ConfAppManager::beginAddOrUpdateApp(
{ {
const auto vars = QVariantList() const auto vars = QVariantList()
<< app.appId << appGroup.id() << app.appOriginPath << app.appId << appGroup.id() << app.appOriginPath
<< (!app.appPath.isEmpty() ? app.appPath : QVariant()) << app.appName << app.isWildcard << (!app.appPath.isEmpty() ? app.appPath : QVariant()) << app.appName << app.notes
<< app.useGroupPerm << app.applyChild << app.killChild << app.lanOnly << app.parked << app.isWildcard << app.useGroupPerm << app.applyChild << app.killChild << app.lanOnly
<< app.logBlocked << app.logConn << app.blocked << app.killProcess << app.acceptZones << app.parked << app.logBlocked << app.logConn << app.blocked << app.killProcess
<< app.rejectZones << (!app.endTime.isNull() ? app.endTime : QVariant()) << app.acceptZones << app.rejectZones
<< (!app.endTime.isNull() ? app.endTime : QVariant())
<< (onlyUpdate ? QVariant() : QDateTime::currentDateTime()); << (onlyUpdate ? QVariant() : QDateTime::currentDateTime());
const char *sql = onlyUpdate ? sqlUpdateApp : sqlUpsertApp; const char *sql = onlyUpdate ? sqlUpdateApp : sqlUpsertApp;
@ -575,20 +579,23 @@ void ConfAppManager::fillApp(App &app, const SqliteStmt &stmt)
app.appId = stmt.columnInt64(0); app.appId = stmt.columnInt64(0);
app.appOriginPath = stmt.columnText(1); app.appOriginPath = stmt.columnText(1);
app.appPath = stmt.columnText(2); app.appPath = stmt.columnText(2);
app.isWildcard = stmt.columnBool(3); app.appName = stmt.columnText(3);
app.useGroupPerm = stmt.columnBool(4); app.notes = stmt.columnText(4);
app.applyChild = stmt.columnBool(5); app.isWildcard = stmt.columnBool(5);
app.killChild = stmt.columnBool(6); app.useGroupPerm = stmt.columnBool(6);
app.lanOnly = stmt.columnBool(7); app.applyChild = stmt.columnBool(7);
app.parked = stmt.columnBool(8); app.killChild = stmt.columnBool(8);
app.logBlocked = stmt.columnBool(9); app.lanOnly = stmt.columnBool(9);
app.logConn = stmt.columnBool(10); app.parked = stmt.columnBool(10);
app.blocked = stmt.columnBool(11); app.logBlocked = stmt.columnBool(11);
app.killProcess = stmt.columnBool(12); app.logConn = stmt.columnBool(12);
app.acceptZones = stmt.columnUInt(13); app.blocked = stmt.columnBool(13);
app.rejectZones = stmt.columnUInt(14); app.killProcess = stmt.columnBool(14);
app.groupIndex = stmt.columnInt(15); app.acceptZones = stmt.columnUInt(15);
app.alerted = stmt.columnBool(16); app.rejectZones = stmt.columnUInt(16);
app.endTime = stmt.columnDateTime(17);
app.groupIndex = stmt.columnInt(18);
app.alerted = stmt.columnBool(19);
} }
bool ConfAppManager::updateDriverDeleteApp(const QString &appPath) bool ConfAppManager::updateDriverDeleteApp(const QString &appPath)

View File

@ -32,7 +32,7 @@ namespace {
const QLoggingCategory LC("conf"); const QLoggingCategory LC("conf");
constexpr int DATABASE_USER_VERSION = 29; constexpr int DATABASE_USER_VERSION = 30;
const char *const sqlSelectAddressGroups = "SELECT addr_group_id, include_all, exclude_all," const char *const sqlSelectAddressGroups = "SELECT addr_group_id, include_all, exclude_all,"
" include_zones, exclude_zones," " include_zones, exclude_zones,"

View File

@ -126,6 +126,7 @@ CREATE TABLE app(
origin_path TEXT, origin_path TEXT,
path TEXT, path TEXT,
name TEXT, name TEXT,
notes TEXT,
is_wildcard BOOLEAN NOT NULL DEFAULT 0, is_wildcard BOOLEAN NOT NULL DEFAULT 0,
use_group_perm BOOLEAN NOT NULL DEFAULT 1, use_group_perm BOOLEAN NOT NULL DEFAULT 1,
apply_child BOOLEAN NOT NULL DEFAULT 0, apply_child BOOLEAN NOT NULL DEFAULT 0,

View File

@ -131,6 +131,8 @@ void ProgramEditDialog::initializeNameField(bool isSingleSelection, bool isPathE
m_editName->setEnabled(isSingleSelection); m_editName->setEnabled(isSingleSelection);
m_editName->setClearButtonEnabled(isSingleSelection); m_editName->setClearButtonEnabled(isSingleSelection);
m_btGetName->setEnabled(isSingleSelection); m_btGetName->setEnabled(isSingleSelection);
m_editNotes->setText(m_appRow.notes);
m_editNotes->setEnabled(isSingleSelection);
} }
void ProgramEditDialog::activate() void ProgramEditDialog::activate()
@ -156,11 +158,13 @@ void ProgramEditDialog::retranslateUi()
m_labelEditPath->setText(isWildcard() ? tr("Wildcard Paths:") : tr("File Path:")); m_labelEditPath->setText(isWildcard() ? tr("Wildcard Paths:") : tr("File Path:"));
retranslatePathPlaceholderText(); retranslatePathPlaceholderText();
m_btSelectFile->setToolTip(tr("Select File")); m_btSelectFile->setToolTip(tr("Select File"));
m_labelEditName->setText(tr("Name:")); m_labelEditName->setText(tr("Name:"));
m_btGetName->setToolTip(tr("Get Program Name")); m_btGetName->setToolTip(tr("Get Program Name"));
m_labelEditNotes->setText(tr("Notes:"));
m_labelAppGroup->setText(tr("Application Group:")); m_labelAppGroup->setText(tr("Application Group:"));
m_cbUseGroupPerm->setText(tr("Use Application Group's Enabled State")); m_cbUseGroupPerm->setText(tr("Use Application Group's Enabled State"));
m_cbApplyChild->setText(tr("Apply same rules to child processes")); m_cbApplyChild->setText(tr("Apply same rules to child processes"));
@ -289,15 +293,21 @@ QLayout *ProgramEditDialog::setupAppLayout()
// App Path // App Path
auto pathLayout = setupAppPathLayout(); auto pathLayout = setupAppPathLayout();
layout->addRow("Program Path:", pathLayout); layout->addRow("File Path:", pathLayout);
m_labelEditPath = qobject_cast<QLabel *>(layout->labelForField(pathLayout)); m_labelEditPath = qobject_cast<QLabel *>(layout->labelForField(pathLayout));
// App Name // App Name
auto nameLayout = setupAppNameLayout(); auto nameLayout = setupAppNameLayout();
layout->addRow("Program Name:", nameLayout); layout->addRow("Name:", nameLayout);
m_labelEditName = qobject_cast<QLabel *>(layout->labelForField(nameLayout)); m_labelEditName = qobject_cast<QLabel *>(layout->labelForField(nameLayout));
// Notes
auto notesLayout = setupNotesLayout();
layout->addRow("Notes:", notesLayout);
m_labelEditNotes = qobject_cast<QLabel *>(layout->labelForField(notesLayout));
// App Group // App Group
setupComboAppGroups(); setupComboAppGroups();
@ -360,16 +370,23 @@ QLayout *ProgramEditDialog::setupAppPathLayout()
QLayout *ProgramEditDialog::setupAppNameLayout() QLayout *ProgramEditDialog::setupAppNameLayout()
{ {
auto layout = new QHBoxLayout();
m_editName = new QLineEdit(); m_editName = new QLineEdit();
m_editName->setMaxLength(1024); m_editName->setMaxLength(1024);
m_btGetName = ControlUtil::createIconToolButton( m_btGetName = ControlUtil::createIconToolButton(
":/icons/arrow_refresh_small.png", [&] { fillEditName(); }); ":/icons/arrow_refresh_small.png", [&] { fillEditName(); });
layout->addWidget(m_editName); auto layout = ControlUtil::createHLayoutByWidgets({ m_editName, m_btGetName });
layout->addWidget(m_btGetName);
return layout;
}
QLayout *ProgramEditDialog::setupNotesLayout()
{
m_editNotes = new PlainTextEdit();
m_editNotes->setFixedHeight(40);
auto layout = ControlUtil::createHLayoutByWidgets({ m_editNotes });
return layout; return layout;
} }
@ -610,6 +627,7 @@ void ProgramEditDialog::fillApp(App &app) const
app.killProcess = m_rbKillProcess->isChecked(); app.killProcess = m_rbKillProcess->isChecked();
app.groupIndex = m_comboAppGroup->currentIndex(); app.groupIndex = m_comboAppGroup->currentIndex();
app.appName = m_editName->text(); app.appName = m_editName->text();
app.notes = m_editNotes->toPlainText();
app.acceptZones = m_btZones->zones(); app.acceptZones = m_btZones->zones();
app.rejectZones = m_btZones->uncheckedZones(); app.rejectZones = m_btZones->uncheckedZones();

View File

@ -55,6 +55,7 @@ private:
QLayout *setupAppLayout(); QLayout *setupAppLayout();
QLayout *setupAppPathLayout(); QLayout *setupAppPathLayout();
QLayout *setupAppNameLayout(); QLayout *setupAppNameLayout();
QLayout *setupNotesLayout();
void setupComboAppGroups(); void setupComboAppGroups();
QLayout *setupLogLayout(); QLayout *setupLogLayout();
QLayout *setupAllowLayout(); QLayout *setupAllowLayout();
@ -87,6 +88,8 @@ private:
QLabel *m_labelEditName = nullptr; QLabel *m_labelEditName = nullptr;
QLineEdit *m_editName = nullptr; QLineEdit *m_editName = nullptr;
QToolButton *m_btGetName = nullptr; QToolButton *m_btGetName = nullptr;
QLabel *m_labelEditNotes = nullptr;
PlainTextEdit *m_editNotes = nullptr;
QLabel *m_labelAppGroup = nullptr; QLabel *m_labelAppGroup = nullptr;
QComboBox *m_comboAppGroup = nullptr; QComboBox *m_comboAppGroup = nullptr;
QCheckBox *m_cbUseGroupPerm = nullptr; QCheckBox *m_cbUseGroupPerm = nullptr;

View File

@ -451,7 +451,6 @@ void ProgramsWindow::openAppEditForm(const AppRow &appRow, const QVector<qint64>
{ {
m_formAppEdit->initialize(appRow, appIdList); m_formAppEdit->initialize(appRow, appIdList);
m_formAppEdit->show();
m_formAppEdit->activate(); m_formAppEdit->activate();
} }

View File

@ -322,10 +322,10 @@ bool AppListModel::updateAppRow(const QString &sql, const QVariantList &vars, Ap
} }
appRow.appId = stmt.columnInt64(0); appRow.appId = stmt.columnInt64(0);
appRow.groupIndex = stmt.columnInt(1); appRow.appOriginPath = stmt.columnText(1);
appRow.appOriginPath = stmt.columnText(2); appRow.appPath = stmt.columnText(2);
appRow.appPath = stmt.columnText(3); appRow.appName = stmt.columnText(3);
appRow.appName = stmt.columnText(4); appRow.notes = stmt.columnText(4);
appRow.isWildcard = stmt.columnBool(5); appRow.isWildcard = stmt.columnBool(5);
appRow.useGroupPerm = stmt.columnBool(6); appRow.useGroupPerm = stmt.columnBool(6);
appRow.applyChild = stmt.columnBool(7); appRow.applyChild = stmt.columnBool(7);
@ -338,9 +338,10 @@ bool AppListModel::updateAppRow(const QString &sql, const QVariantList &vars, Ap
appRow.killProcess = stmt.columnBool(14); appRow.killProcess = stmt.columnBool(14);
appRow.acceptZones = stmt.columnUInt(15); appRow.acceptZones = stmt.columnUInt(15);
appRow.rejectZones = stmt.columnUInt(16); appRow.rejectZones = stmt.columnUInt(16);
appRow.alerted = stmt.columnBool(17); appRow.endTime = stmt.columnDateTime(17);
appRow.endTime = stmt.columnDateTime(18); appRow.creatTime = stmt.columnDateTime(18);
appRow.creatTime = stmt.columnDateTime(19); appRow.groupIndex = stmt.columnInt(19);
appRow.alerted = stmt.columnBool(20);
return true; return true;
} }
@ -391,10 +392,10 @@ QString AppListModel::sqlBase() const
{ {
return "SELECT" return "SELECT"
" t.app_id," " t.app_id,"
" g.order_index as group_index,"
" t.origin_path," " t.origin_path,"
" t.path," " t.path,"
" t.name," " t.name,"
" t.notes,"
" t.is_wildcard," " t.is_wildcard,"
" t.use_group_perm," " t.use_group_perm,"
" t.apply_child," " t.apply_child,"
@ -407,9 +408,10 @@ QString AppListModel::sqlBase() const
" t.kill_process," " t.kill_process,"
" t.accept_zones," " t.accept_zones,"
" t.reject_zones," " t.reject_zones,"
" (alert.app_id IS NOT NULL) as alerted,"
" t.end_time," " t.end_time,"
" t.creat_time" " t.creat_time,"
" g.order_index as group_index,"
" (alert.app_id IS NOT NULL) as alerted"
" FROM app t" " FROM app t"
" JOIN app_group g ON g.app_group_id = t.app_group_id" " JOIN app_group g ON g.app_group_id = t.app_group_id"
" LEFT JOIN app_alert alert ON alert.app_id = t.app_id"; " LEFT JOIN app_alert alert ON alert.app_id = t.app_id";

View File

@ -59,7 +59,7 @@ QVariantList ConfAppManagerRpc::appToVarList(const App &app)
return { app.isWildcard, app.useGroupPerm, app.applyChild, app.killChild, app.lanOnly, return { app.isWildcard, app.useGroupPerm, app.applyChild, app.killChild, app.lanOnly,
app.parked, app.logBlocked, app.logConn, app.blocked, app.killProcess, app.groupIndex, app.parked, app.logBlocked, app.logConn, app.blocked, app.killProcess, app.groupIndex,
app.acceptZones, app.rejectZones, app.appId, app.appOriginPath, app.appPath, app.appName, app.acceptZones, app.rejectZones, app.appId, app.appOriginPath, app.appPath, app.appName,
app.endTime }; app.notes, app.endTime };
} }
App ConfAppManagerRpc::varListToApp(const QVariantList &v) App ConfAppManagerRpc::varListToApp(const QVariantList &v)
@ -82,6 +82,7 @@ App ConfAppManagerRpc::varListToApp(const QVariantList &v)
app.appOriginPath = v.value(14).toString(); app.appOriginPath = v.value(14).toString();
app.appPath = v.value(15).toString(); app.appPath = v.value(15).toString();
app.appName = v.value(16).toString(); app.appName = v.value(16).toString();
app.endTime = v.value(17).toDateTime(); app.notes = v.value(17).toString();
app.endTime = v.value(18).toDateTime();
return app; return app;
} }