UI: Programs: Add "Clear Alerts" button

This commit is contained in:
Nodir Temirkhodjaev 2024-08-16 16:18:16 +05:00
parent 2644e4e4df
commit 8798e91d8b
10 changed files with 52 additions and 0 deletions

View File

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

View File

@ -42,6 +42,7 @@ public:
virtual bool updateApp(App &app);
virtual bool updateAppName(qint64 appId, const QString &appName);
virtual bool deleteApps(const QVector<qint64> &appIdList);
virtual bool clearAlerts();
virtual bool purgeApps();
virtual bool updateAppsBlocked(
const QVector<qint64> &appIdList, bool blocked, bool killProcess);

View File

@ -38,6 +38,7 @@ static const QHash<Command, const char *> 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,

View File

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

View File

@ -63,6 +63,11 @@ void ProgramsController::deleteApps(const QVector<qint64> &appIdList)
}
}
void ProgramsController::clearAlerts()
{
confAppManager()->clearAlerts();
}
void ProgramsController::purgeApps()
{
taskManager()->runTask(TaskInfo::AppPurger);

View File

@ -25,6 +25,7 @@ public slots:
bool updateAppName(qint64 appId, const QString &appName);
void updateAppsBlocked(const QVector<qint64> &appIdList, bool blocked, bool killProcess);
void deleteApps(const QVector<qint64> &appIdList);
void clearAlerts();
void purgeApps();
private:

View File

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

View File

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

View File

@ -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<qint64> &appIdList)
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfAppManager_deleteApps, args);
}
bool ConfAppManagerRpc::clearAlerts()
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfAppManager_clearAlerts);
}
bool ConfAppManagerRpc::purgeApps()
{
return IoC<RpcManager>()->doOnServer(Control::Rpc_ConfAppManager_purgeApps);

View File

@ -21,6 +21,7 @@ public:
bool updateApp(App &app) override;
bool updateAppName(qint64 appId, const QString &appName) override;
bool deleteApps(const QVector<qint64> &appIdList) override;
bool clearAlerts() override;
bool purgeApps() override;
bool updateAppsBlocked(
const QVector<qint64> &appIdList, bool blocked, bool killProcess) override;