-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deleting extension plugin data from Browser Statistics
- Loading branch information
1 parent
3c05dd2
commit 2f01604
Showing
8 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -27,7 +27,6 @@ | |
#include "gui/styles/StateColorPalette.h" | ||
|
||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QMenu> | ||
#include <QShortcut> | ||
#include <QSortFilterProxyModel> | ||
|
@@ -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); | ||
|
@@ -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; | ||
|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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; | ||
|