diff --git a/src/ui/conf/confappmanager.cpp b/src/ui/conf/confappmanager.cpp index 4b0bf3ef..333ee328 100644 --- a/src/ui/conf/confappmanager.cpp +++ b/src/ui/conf/confappmanager.cpp @@ -116,6 +116,8 @@ const char *const sqlInsertAppAlert = "INSERT INTO app_alert(app_id) VALUES(?1); const char *const sqlDeleteAppAlert = "DELETE FROM app_alert WHERE app_id = ?1;"; +const char *const sqlDeleteAppAlerts = "DELETE FROM app_alert;"; + const char *const sqlUpdateAppBlocked = "UPDATE app SET blocked = ?2, kill_process = ?3" " WHERE app_id = ?1;"; @@ -395,6 +397,17 @@ bool ConfAppManager::deleteApps(const QVector &appIdList) return ok; } +bool ConfAppManager::clearAlerts() +{ + const bool ok = DbQuery(sqliteDb()).sql(sqlDeleteAppAlerts).executeOk(); + + if (ok) { + emitAppsChanged(); + } + + return ok; +} + bool ConfAppManager::deleteApp(qint64 appId, bool &isWildcard) { bool ok = false; diff --git a/src/ui/conf/confappmanager.h b/src/ui/conf/confappmanager.h index 83969727..08fe337e 100644 --- a/src/ui/conf/confappmanager.h +++ b/src/ui/conf/confappmanager.h @@ -42,6 +42,7 @@ public: virtual bool updateApp(App &app); virtual bool updateAppName(qint64 appId, const QString &appName); virtual bool deleteApps(const QVector &appIdList); + virtual bool clearAlerts(); virtual bool purgeApps(); virtual bool updateAppsBlocked( const QVector &appIdList, bool blocked, bool killProcess); diff --git a/src/ui/control/control.cpp b/src/ui/control/control.cpp index c8888cc3..cd2c19b8 100644 --- a/src/ui/control/control.cpp +++ b/src/ui/control/control.cpp @@ -38,6 +38,7 @@ static const QHash g_commandNames = { CASE_STRING(Rpc_ConfAppManager_updateApp), CASE_STRING(Rpc_ConfAppManager_updateAppName), CASE_STRING(Rpc_ConfAppManager_deleteApps), + CASE_STRING(Rpc_ConfAppManager_clearAlerts), CASE_STRING(Rpc_ConfAppManager_purgeApps), CASE_STRING(Rpc_ConfAppManager_updateAppsBlocked), CASE_STRING(Rpc_ConfAppManager_appAlerted), @@ -145,6 +146,7 @@ static const RpcManager g_commandManagers[] = { Rpc_ConfAppManager, // Rpc_ConfAppManager_updateApp, Rpc_ConfAppManager, // Rpc_ConfAppManager_updateAppName, Rpc_ConfAppManager, // Rpc_ConfAppManager_deleteApps, + Rpc_ConfAppManager, // Rpc_ConfAppManager_clearAlerts, Rpc_ConfAppManager, // Rpc_ConfAppManager_purgeApps, Rpc_ConfAppManager, // Rpc_ConfAppManager_updateAppsBlocked, Rpc_ConfAppManager, // Rpc_ConfAppManager_appEndTimesUpdated, @@ -232,6 +234,7 @@ static const qint8 g_commandValidations[] = { true, // Rpc_ConfAppManager_updateApp, true, // Rpc_ConfAppManager_updateAppName, true, // Rpc_ConfAppManager_deleteApps, + true, // Rpc_ConfAppManager_clearAlerts, true, // Rpc_ConfAppManager_purgeApps, true, // Rpc_ConfAppManager_updateAppsBlocked, 0, // Rpc_ConfAppManager_appEndTimesUpdated, diff --git a/src/ui/control/control_types.h b/src/ui/control/control_types.h index d12447d3..9deda741 100644 --- a/src/ui/control/control_types.h +++ b/src/ui/control/control_types.h @@ -40,6 +40,7 @@ enum Command : qint8 { Rpc_ConfAppManager_updateApp, Rpc_ConfAppManager_updateAppName, Rpc_ConfAppManager_deleteApps, + Rpc_ConfAppManager_clearAlerts, Rpc_ConfAppManager_purgeApps, Rpc_ConfAppManager_updateAppsBlocked, Rpc_ConfAppManager_appEndTimesUpdated, diff --git a/src/ui/form/prog/programscontroller.cpp b/src/ui/form/prog/programscontroller.cpp index 9357b579..2deb88bd 100644 --- a/src/ui/form/prog/programscontroller.cpp +++ b/src/ui/form/prog/programscontroller.cpp @@ -63,6 +63,11 @@ void ProgramsController::deleteApps(const QVector &appIdList) } } +void ProgramsController::clearAlerts() +{ + confAppManager()->clearAlerts(); +} + void ProgramsController::purgeApps() { taskManager()->runTask(TaskInfo::AppPurger); diff --git a/src/ui/form/prog/programscontroller.h b/src/ui/form/prog/programscontroller.h index 0d7a5471..c04c8c1d 100644 --- a/src/ui/form/prog/programscontroller.h +++ b/src/ui/form/prog/programscontroller.h @@ -25,6 +25,7 @@ public slots: bool updateAppName(qint64 appId, const QString &appName); void updateAppsBlocked(const QVector &appIdList, bool blocked, bool killProcess); void deleteApps(const QVector &appIdList); + void clearAlerts(); void purgeApps(); private: diff --git a/src/ui/form/prog/programswindow.cpp b/src/ui/form/prog/programswindow.cpp index e1c99dbd..6b7d2960 100644 --- a/src/ui/form/prog/programswindow.cpp +++ b/src/ui/form/prog/programswindow.cpp @@ -130,6 +130,7 @@ void ProgramsWindow::retranslateUi() m_actEditApp->setText(tr("Edit")); m_actRemoveApp->setText(tr("Remove")); m_actReviewAlerts->setText(tr("Review Alerts")); + m_actClearAlerts->setText(tr("Clear Alerts")); m_actPurgeApps->setText(tr("Purge Obsolete")); m_actFindApps->setText(tr("Find")); @@ -276,6 +277,10 @@ void ProgramsWindow::setupEditMenu() editMenu->addSeparator(); m_actReviewAlerts = editMenu->addAction(IconCache::icon(":/icons/error.png"), QString()); + m_actClearAlerts = editMenu->addAction(QString()); + + editMenu->addSeparator(); + m_actPurgeApps = editMenu->addAction(IconCache::icon(":/icons/recycle.png"), QString()); m_actFindApps = editMenu->addAction(IconCache::icon(":/icons/magnifier.png"), QString()); @@ -294,6 +299,7 @@ void ProgramsWindow::setupEditMenu() connect(m_actRemoveApp, &QAction::triggered, this, &ProgramsWindow::deleteSelectedApps); connect(m_actReviewAlerts, &QAction::triggered, this, [&] { windowManager()->showProgramAlertWindow(); }); + connect(m_actClearAlerts, &QAction::triggered, this, &ProgramsWindow::clearAlerts); connect(m_actPurgeApps, &QAction::triggered, this, [&] { windowManager()->showConfirmBox([&] { ctrl()->purgeApps(); }, tr("Are you sure to remove all non-existent programs?")); @@ -578,6 +584,12 @@ void ProgramsWindow::deleteSelectedApps() + "\n\n" + appNames.join('\n')); } +void ProgramsWindow::clearAlerts() +{ + windowManager()->showConfirmBox( + [=, this] { ctrl()->clearAlerts(); }, tr("Are you sure to clear alerts?")); +} + int ProgramsWindow::appListCurrentIndex() const { return m_appListView->currentRow(); diff --git a/src/ui/form/prog/programswindow.h b/src/ui/form/prog/programswindow.h index f4a8e10f..e7b8cc8a 100644 --- a/src/ui/form/prog/programswindow.h +++ b/src/ui/form/prog/programswindow.h @@ -76,6 +76,8 @@ private: void updateSelectedApps(bool blocked, bool killProcess = false); void deleteSelectedApps(); + void clearAlerts(); + int appListCurrentIndex() const; AppRow appListCurrentRow() const; QString appListCurrentPath() const; @@ -96,6 +98,7 @@ private: QAction *m_actEditApp = nullptr; QAction *m_actRemoveApp = nullptr; QAction *m_actReviewAlerts = nullptr; + QAction *m_actClearAlerts = nullptr; QAction *m_actPurgeApps = nullptr; QAction *m_actFindApps = nullptr; QPushButton *m_btEdit = nullptr; diff --git a/src/ui/rpc/confappmanagerrpc.cpp b/src/ui/rpc/confappmanagerrpc.cpp index 1ddcf047..73f7e04a 100644 --- a/src/ui/rpc/confappmanagerrpc.cpp +++ b/src/ui/rpc/confappmanagerrpc.cpp @@ -55,6 +55,12 @@ bool processConfAppManager_deleteApps( return confAppManager->deleteApps(appIdList); } +bool processConfAppManager_clearAlerts(ConfAppManager *confAppManager, + const ProcessCommandArgs & /*p*/, QVariantList & /*resArgs*/) +{ + return confAppManager->clearAlerts(); +} + bool processConfAppManager_purgeApps(ConfAppManager *confAppManager, const ProcessCommandArgs & /*p*/, QVariantList & /*resArgs*/) { @@ -81,6 +87,7 @@ static const processConfAppManager_func processConfAppManager_funcList[] = { &processConfAppManager_updateApp, // Rpc_ConfAppManager_updateApp, &processConfAppManager_updateAppName, // Rpc_ConfAppManager_updateAppName, &processConfAppManager_deleteApps, // Rpc_ConfAppManager_deleteApps, + &processConfAppManager_clearAlerts, // Rpc_ConfAppManager_clearAlerts, &processConfAppManager_purgeApps, // Rpc_ConfAppManager_purgeApps, &processConfAppManager_updateAppsBlocked, // Rpc_ConfAppManager_updateAppsBlocked, }; @@ -140,6 +147,11 @@ bool ConfAppManagerRpc::deleteApps(const QVector &appIdList) return IoC()->doOnServer(Control::Rpc_ConfAppManager_deleteApps, args); } +bool ConfAppManagerRpc::clearAlerts() +{ + return IoC()->doOnServer(Control::Rpc_ConfAppManager_clearAlerts); +} + bool ConfAppManagerRpc::purgeApps() { return IoC()->doOnServer(Control::Rpc_ConfAppManager_purgeApps); diff --git a/src/ui/rpc/confappmanagerrpc.h b/src/ui/rpc/confappmanagerrpc.h index fa437cc7..36a01dc2 100644 --- a/src/ui/rpc/confappmanagerrpc.h +++ b/src/ui/rpc/confappmanagerrpc.h @@ -21,6 +21,7 @@ public: bool updateApp(App &app) override; bool updateAppName(qint64 appId, const QString &appName) override; bool deleteApps(const QVector &appIdList) override; + bool clearAlerts() override; bool purgeApps() override; bool updateAppsBlocked( const QVector &appIdList, bool blocked, bool killProcess) override;