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 authored and droidmonkey committed Sep 2, 2024
1 parent 3c05dd2 commit 2f01604
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 20 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>
<source>Delete plugin data?</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>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
9 changes: 9 additions & 0 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,15 @@ bool BrowserService::deleteEntry(const QString& uuid)
return true;
}

void BrowserService::removePluginData(Entry* entry) const
{
if (entry) {
entry->beginUpdate();
entry->customData()->remove(BrowserService::KEEPASSXCBROWSER_NAME);
entry->endUpdate();
}
}

QList<Entry*> BrowserService::searchEntries(const QSharedPointer<Database>& db,
const QString& siteUrl,
const QString& formUrl,
Expand Down
1 change: 1 addition & 0 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class BrowserService : public QObject
const QSharedPointer<Database>& selectedDb = {});
bool updateEntry(const EntryParameters& entryParameters, const QString& uuid);
bool deleteEntry(const QString& uuid);
void removePluginData(Entry* entry) const;
QJsonArray findEntries(const EntryParameters& entryParameters, const StringPairList& keyList, bool* entriesFound);
void requestGlobalAutoType(const QString& search);

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 <[email protected]>
* Copyright (C) 2024 KeePassXC Team <[email protected]>
*
* 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?"),
QObject::tr("Delete plugin data from Entry(s)?", "", entries.size()),
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 <[email protected]>
* Copyright (C) 2024 KeePassXC Team <[email protected]>
*
* 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
4 changes: 1 addition & 3 deletions src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ void DatabaseSettingsWidgetBrowser::removeStoredPermissions()
}

if (entry->customData()->contains(BrowserService::KEEPASSXCBROWSER_NAME)) {
entry->beginUpdate();
entry->customData()->remove(BrowserService::KEEPASSXCBROWSER_NAME);
entry->endUpdate();
browserService()->removePluginData(entry);
++counter;
}
progress.setValue(progress.value() + 1);
Expand Down
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 <[email protected]>
* Copyright (C) 2024 KeePassXC Team <[email protected]>
*
* 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) {
browserService()->removePluginData(entry);
}
}

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 <[email protected]>
* Copyright (C) 2024 KeePassXC Team <[email protected]>
*
* 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 2f01604

Please sign in to comment.