Skip to content

Commit 2f01604

Browse files
varjolintudroidmonkey
varjolintu
authored andcommitted
Allow deleting extension plugin data from Browser Statistics
1 parent 3c05dd2 commit 2f01604

8 files changed

+92
-20
lines changed

share/translations/keepassxc_en.ts

+18
Original file line numberDiff line numberDiff line change
@@ -8902,6 +8902,17 @@ This option is deprecated, use --set-key-file instead.</source>
89028902
<source>Cannot generate valid passphrases because the wordlist is too short</source>
89038903
<translation type="unfinished"></translation>
89048904
</message>
8905+
<message>
8906+
<source>Delete plugin data?</source>
8907+
<translation type="unfinished"></translation>
8908+
</message>
8909+
<message numerus="yes">
8910+
<source>Delete plugin data from Entry(s)?</source>
8911+
<translation type="unfinished">
8912+
<numerusform></numerusform>
8913+
<numerusform></numerusform>
8914+
</translation>
8915+
</message>
89058916
</context>
89068917
<context>
89078918
<name>QtIOCompressor</name>
@@ -9053,6 +9064,13 @@ This option is deprecated, use --set-key-file instead.</source>
90539064
<source> (Expired)</source>
90549065
<translation type="unfinished"></translation>
90559066
</message>
9067+
<message numerus="yes">
9068+
<source>Delete plugin data from Entry(s)…</source>
9069+
<translation type="unfinished">
9070+
<numerusform></numerusform>
9071+
<numerusform></numerusform>
9072+
</translation>
9073+
</message>
90569074
</context>
90579075
<context>
90589076
<name>ReportsWidgetHealthcheck</name>

src/browser/BrowserService.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,15 @@ bool BrowserService::deleteEntry(const QString& uuid)
977977
return true;
978978
}
979979

980+
void BrowserService::removePluginData(Entry* entry) const
981+
{
982+
if (entry) {
983+
entry->beginUpdate();
984+
entry->customData()->remove(BrowserService::KEEPASSXCBROWSER_NAME);
985+
entry->endUpdate();
986+
}
987+
}
988+
980989
QList<Entry*> BrowserService::searchEntries(const QSharedPointer<Database>& db,
981990
const QString& siteUrl,
982991
const QString& formUrl,

src/browser/BrowserService.h

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class BrowserService : public QObject
118118
const QSharedPointer<Database>& selectedDb = {});
119119
bool updateEntry(const EntryParameters& entryParameters, const QString& uuid);
120120
bool deleteEntry(const QString& uuid);
121+
void removePluginData(Entry* entry) const;
121122
QJsonArray findEntries(const EntryParameters& entryParameters, const StringPairList& keyList, bool* entriesFound);
122123
void requestGlobalAutoType(const QString& search);
123124

src/gui/GuiTools.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 KeePassXC Team <[email protected]>
2+
* Copyright (C) 2024 KeePassXC Team <[email protected]>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -66,6 +66,21 @@ namespace GuiTools
6666
}
6767
}
6868

69+
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries)
70+
{
71+
if (!parent || entries.isEmpty()) {
72+
return false;
73+
}
74+
75+
auto answer = MessageBox::question(parent,
76+
QObject::tr("Delete plugin data?"),
77+
QObject::tr("Delete plugin data from Entry(s)?", "", entries.size()),
78+
MessageBox::Delete | MessageBox::Cancel,
79+
MessageBox::Cancel);
80+
81+
return answer == MessageBox::Delete;
82+
}
83+
6984
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent)
7085
{
7186
if (!parent || entries.isEmpty()) {

src/gui/GuiTools.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 KeePassXC Team <[email protected]>
2+
* Copyright (C) 2024 KeePassXC Team <[email protected]>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ class Entry;
2626
namespace GuiTools
2727
{
2828
bool confirmDeleteEntries(QWidget* parent, const QList<Entry*>& entries, bool permanent);
29+
bool confirmDeletePluginData(QWidget* parent, const QList<Entry*>& entries);
2930
size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent);
3031
} // namespace GuiTools
3132
#endif // KEEPASSXC_GUITOOLS_H

src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ void DatabaseSettingsWidgetBrowser::removeStoredPermissions()
214214
}
215215

216216
if (entry->customData()->contains(BrowserService::KEEPASSXCBROWSER_NAME)) {
217-
entry->beginUpdate();
218-
entry->customData()->remove(BrowserService::KEEPASSXCBROWSER_NAME);
219-
entry->endUpdate();
217+
browserService()->removePluginData(entry);
220218
++counter;
221219
}
222220
progress.setValue(progress.value() + 1);

src/gui/reports/ReportsWidgetBrowserStatistics.cpp

+42-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 KeePassXC Team <[email protected]>
2+
* Copyright (C) 2024 KeePassXC Team <[email protected]>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@
2727
#include "gui/styles/StateColorPalette.h"
2828

2929
#include <QJsonDocument>
30-
#include <QJsonObject>
3130
#include <QMenu>
3231
#include <QShortcut>
3332
#include <QSortFilterProxyModel>
@@ -277,9 +276,19 @@ void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos)
277276
}
278277

279278
// Create the "delete entry" menu item
280-
const auto delEntry = new QAction(icons()->icon("entry-delete"), tr("Delete Entry(s)…", "", selected.size()), this);
281-
menu->addAction(delEntry);
282-
connect(delEntry, &QAction::triggered, this, &ReportsWidgetBrowserStatistics::deleteSelectedEntries);
279+
const auto deleteEntry =
280+
new QAction(icons()->icon("entry-delete"), tr("Delete Entry(s)…", "", selected.size()), this);
281+
menu->addAction(deleteEntry);
282+
connect(deleteEntry, &QAction::triggered, this, &ReportsWidgetBrowserStatistics::deleteSelectedEntries);
283+
284+
// Create the "delete plugin data" menu item
285+
const auto deletePluginData =
286+
new QAction(icons()->icon("entry-delete"), tr("Delete plugin data from Entry(s)…", "", selected.size()), this);
287+
menu->addAction(deletePluginData);
288+
connect(deletePluginData,
289+
&QAction::triggered,
290+
this,
291+
&ReportsWidgetBrowserStatistics::deletePluginDataFromSelectedEntries);
283292

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

321330
void ReportsWidgetBrowserStatistics::deleteSelectedEntries()
322331
{
323-
QList<Entry*> selectedEntries;
324-
for (auto index : m_ui->browserStatisticsTableView->selectionModel()->selectedRows()) {
325-
auto row = m_modelProxy->mapToSource(index).row();
326-
auto entry = m_rowToEntry[row].second;
327-
if (entry) {
328-
selectedEntries << entry;
329-
}
330-
}
331-
332+
const auto& selectedEntries = getSelectedEntries();
332333
bool permanent = !m_db->metadata()->recycleBinEnabled();
334+
333335
if (GuiTools::confirmDeleteEntries(this, selectedEntries, permanent)) {
334336
GuiTools::deleteEntriesResolveReferences(this, selectedEntries, permanent);
335337
}
336338

337339
calculateBrowserStatistics();
338340
}
339341

342+
void ReportsWidgetBrowserStatistics::deletePluginDataFromSelectedEntries()
343+
{
344+
const auto& selectedEntries = getSelectedEntries();
345+
if (GuiTools::confirmDeletePluginData(this, selectedEntries)) {
346+
for (auto& entry : selectedEntries) {
347+
browserService()->removePluginData(entry);
348+
}
349+
}
350+
351+
calculateBrowserStatistics();
352+
}
353+
340354
QMap<QString, QStringList> ReportsWidgetBrowserStatistics::getBrowserConfigFromEntry(Entry* entry) const
341355
{
342356
QMap<QString, QStringList> configList;
@@ -372,3 +386,17 @@ QMap<QString, QStringList> ReportsWidgetBrowserStatistics::getBrowserConfigFromE
372386

373387
return configList;
374388
}
389+
390+
QList<Entry*> ReportsWidgetBrowserStatistics::getSelectedEntries() const
391+
{
392+
QList<Entry*> selectedEntries;
393+
for (auto index : m_ui->browserStatisticsTableView->selectionModel()->selectedRows()) {
394+
auto row = m_modelProxy->mapToSource(index).row();
395+
auto entry = m_rowToEntry[row].second;
396+
if (entry) {
397+
selectedEntries << entry;
398+
}
399+
}
400+
401+
return selectedEntries;
402+
}

src/gui/reports/ReportsWidgetBrowserStatistics.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021 KeePassXC Team <[email protected]>
2+
* Copyright (C) 2024 KeePassXC Team <[email protected]>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -54,9 +54,11 @@ public slots:
5454
void emitEntryActivated(const QModelIndex& index);
5555
void customMenuRequested(QPoint);
5656
void deleteSelectedEntries();
57+
void deletePluginDataFromSelectedEntries();
5758

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

6264
QScopedPointer<Ui::ReportsWidgetBrowserStatistics> m_ui;

0 commit comments

Comments
 (0)