Skip to content

Commit

Permalink
Allow deleting extension plugin data from Browser Statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Sep 1, 2024
1 parent 48d0f2b commit f2d942a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 17 deletions.
18 changes: 18 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8902,6 +8902,17 @@ This option is deprecated, use --set-key-file instead.</source>
<source>Cannot generate valid passphrases because the wordlist is too short</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<source>Delete plugin data?</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message>
<source>Delete plugin data from Entry(s)?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QtIOCompressor</name>
Expand Down Expand Up @@ -9053,6 +9064,13 @@ This option is deprecated, use --set-key-file instead.</source>
<source> (Expired)</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<source>Delete plugin data from Entry(s)…</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>ReportsWidgetHealthcheck</name>
Expand Down
17 changes: 16 additions & 1 deletion src/gui/GuiTools.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -66,6 +66,21 @@ namespace GuiTools
}
}

bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries)
{
if (!parent || entries.isEmpty()) {
return false;
}

auto answer = MessageBox::question(parent,
QObject::tr("Delete plugin data?", "", entries.size()),
QObject::tr("Delete plugin data from Entry(s)?"),
MessageBox::Delete | MessageBox::Cancel,
MessageBox::Cancel);

return answer == MessageBox::Delete;
}

size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent)
{
if (!parent || entries.isEmpty()) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui/GuiTools.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,6 +26,7 @@ class Entry;
namespace GuiTools
{
bool confirmDeleteEntries(QWidget* parent, const QList<Entry*>& entries, bool permanent);
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries);
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent);
} // namespace GuiTools
#endif // KEEPASSXC_GUITOOLS_H
56 changes: 42 additions & 14 deletions src/gui/reports/ReportsWidgetBrowserStatistics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,7 +27,6 @@
#include "gui/styles/StateColorPalette.h"

#include <QJsonDocument>
#include <QJsonObject>
#include <QMenu>
#include <QShortcut>
#include <QSortFilterProxyModel>
Expand Down Expand Up @@ -277,9 +276,19 @@ void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos)
}

// Create the "delete entry" menu item
const auto delEntry = new QAction(icons()->icon("entry-delete"), tr("Delete Entry(s)…", "", selected.size()), this);
menu->addAction(delEntry);
connect(delEntry, &QAction::triggered, this, &ReportsWidgetBrowserStatistics::deleteSelectedEntries);
const auto deleteEntry =
new QAction(icons()->icon("entry-delete"), tr("Delete Entry(s)…", "", selected.size()), this);
menu->addAction(deleteEntry);
connect(deleteEntry, &QAction::triggered, this, &ReportsWidgetBrowserStatistics::deleteSelectedEntries);

// Create the "delete plugin data" menu item
const auto deletePluginData =
new QAction(icons()->icon("entry-delete"), tr("Delete plugin data from Entry(s)…", "", selected.size()), this);
menu->addAction(deletePluginData);
connect(deletePluginData,
&QAction::triggered,
this,
&ReportsWidgetBrowserStatistics::deletePluginDataFromSelectedEntries);

// Create the "exclude from reports" menu item
const auto exclude = new QAction(icons()->icon("reports-exclude"), tr("Exclude from reports"), this);
Expand Down Expand Up @@ -320,23 +329,28 @@ void ReportsWidgetBrowserStatistics::saveSettings()

void ReportsWidgetBrowserStatistics::deleteSelectedEntries()
{
QList<Entry*> selectedEntries;
for (auto index : m_ui->browserStatisticsTableView->selectionModel()->selectedRows()) {
auto row = m_modelProxy->mapToSource(index).row();
auto entry = m_rowToEntry[row].second;
if (entry) {
selectedEntries << entry;
}
}

const auto& selectedEntries = getSelectedEntries();
bool permanent = !m_db->metadata()->recycleBinEnabled();

if (GuiTools::confirmDeleteEntries(this, selectedEntries, permanent)) {
GuiTools::deleteEntriesResolveReferences(this, selectedEntries, permanent);
}

calculateBrowserStatistics();
}

void ReportsWidgetBrowserStatistics::deletePluginDataFromSelectedEntries()
{
const auto& selectedEntries = getSelectedEntries();
if (GuiTools::confirmDeletePluginData(this, selectedEntries)) {
for (auto& entry : selectedEntries) {
entry->customData()->remove(BrowserService::KEEPASSXCBROWSER_NAME);
}
}

calculateBrowserStatistics();
}

QMap<QString, QStringList> ReportsWidgetBrowserStatistics::getBrowserConfigFromEntry(Entry* entry) const
{
QMap<QString, QStringList> configList;
Expand Down Expand Up @@ -372,3 +386,17 @@ QMap<QString, QStringList> ReportsWidgetBrowserStatistics::getBrowserConfigFromE

return configList;
}

QList<Entry*> ReportsWidgetBrowserStatistics::getSelectedEntries() const
{
QList<Entry*> selectedEntries;
for (auto index : m_ui->browserStatisticsTableView->selectionModel()->selectedRows()) {
auto row = m_modelProxy->mapToSource(index).row();
auto entry = m_rowToEntry[row].second;
if (entry) {
selectedEntries << entry;
}
}

return selectedEntries;
}
4 changes: 3 additions & 1 deletion src/gui/reports/ReportsWidgetBrowserStatistics.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -54,9 +54,11 @@ public slots:
void emitEntryActivated(const QModelIndex& index);
void customMenuRequested(QPoint);
void deleteSelectedEntries();
void deletePluginDataFromSelectedEntries();

private:
void addStatisticsRow(bool hasUrls, bool hasSettings, Group*, Entry*, bool);
QList<Entry*> getSelectedEntries() const;
QMap<QString, QStringList> getBrowserConfigFromEntry(Entry* entry) const;

QScopedPointer<Ui::ReportsWidgetBrowserStatistics> m_ui;
Expand Down

0 comments on commit f2d942a

Please sign in to comment.