From 09efef0a97159a492974bd64228cda79b7192064 Mon Sep 17 00:00:00 2001 From: Agoston Szepessy Date: Mon, 22 Dec 2025 23:31:24 -0800 Subject: [PATCH] Add exclusion support for HIBP report --- src/gui/reports/ReportsWidgetHibp.cpp | 82 ++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/src/gui/reports/ReportsWidgetHibp.cpp b/src/gui/reports/ReportsWidgetHibp.cpp index 04ac4dab3..807fc8529 100644 --- a/src/gui/reports/ReportsWidgetHibp.cpp +++ b/src/gui/reports/ReportsWidgetHibp.cpp @@ -23,6 +23,7 @@ #include "core/Metadata.h" #include "gui/GuiTools.h" #include "gui/Icons.h" +#include "gui/MessageBox.h" #include #include @@ -387,28 +388,93 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos) connect(delEntry, &QAction::triggered, this, &ReportsWidgetHibp::deleteSelectedEntries); // Create the "exclude from reports" menu item - const auto exclude = new QAction(icons()->icon("reports-exclude"), tr("Exclude from reports"), this); + const auto excludeAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Entry(s) from reports"), this); + const auto excludeGroupsAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); bool isExcluded = false; + bool isGroupExcluded = false; + for (auto index : selected) { auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row]; - if (entry && entry->excludeFromReports()) { + if (entry) { // If at least one entry is excluded switch to inclusion - isExcluded = true; + if (entry->excludeFromReports() || entry->group()->excludeFromReports()) { + isExcluded = true; + } + if (entry->group()->excludeFromReports()) { + isGroupExcluded = true; + } + break; } } - exclude->setCheckable(true); - exclude->setChecked(isExcluded); - menu->addAction(exclude); - connect(exclude, &QAction::toggled, exclude, [this, selected](bool state) { + excludeAction->setCheckable(true); + excludeAction->setChecked(isExcluded); + + excludeGroupsAction->setCheckable(true); + excludeGroupsAction->setChecked(isGroupExcluded); + + menu->addAction(excludeAction); + connect(excludeAction, &QAction::toggled, excludeAction, [this, selected](bool checked) { + QSet groups; + + // If we are including entries (checked is false) but a group is excluded, ask the user if they + // would like to include the rest of the group as well (or keep it excluded). + // If they exclude it, we need to include the whole group, and then exclude + // the entries that aren't selected here. + if (!checked) { + for(const auto index : selected) { + auto row = m_modelProxy->mapToSource(index).row(); + auto entry = m_rowToEntry[row]; + + if (entry) { + auto *group = entry->group(); + if (group->excludeFromReports() && !groups.contains(group)) { + QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from there as well?").arg(entry->title()); + auto response = MessageBox::question(this, tr("Include Group?"), msg, MessageBox::Yes | MessageBox::No | MessageBox::Cancel, MessageBox::No); + + if (response == MessageBox::Cancel) { + return; + } + else if (response == MessageBox::Yes) { + group->setExcludeFromReports(false); + } + else if (response == MessageBox::No) { + // We'll exclude all entries from the group here and then + // include the selected ones below + group->setExcludeFromReports(false); + group->markAllEntriesExcludedFromReports(); + } + + groups.insert(group); + } + } + } + } + for (auto index : selected) { auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row]; + + // If the containing group is excluded but the user wants to include + // this entry, ask if they want to keep the remaining items in the group + // excluded or included if (entry) { - entry->setExcludeFromReports(state); + entry->setExcludeFromReports(checked); + } + } + makeHibpTable(); + }); + + menu->addAction(excludeGroupsAction); + connect(excludeGroupsAction, &QAction::toggled, excludeGroupsAction, [this, selected](bool checked) { + for (const auto index : selected) { + auto row = m_modelProxy->mapToSource(index).row(); + auto entry = m_rowToEntry[row]; + if (entry) { + entry->group()->setExcludeFromReports(checked); } } makeHibpTable();