Skip to content

Commit

Permalink
Prompt to delete recycle bin when disabling it
Browse files Browse the repository at this point in the history
Fixes keepassxreboot#3365

Add prompt to delete the recycle bin when disabling it. If the user chooses not to delete it, the recycle bin will be suffixed with "(old)" and the icon changed to the default group icon.

Also moved recycle bin creation within the database class where it belongs.
  • Loading branch information
markhakansson authored and droidmonkey committed Oct 20, 2019
1 parent a1e12c1 commit a876b3b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
9 changes: 8 additions & 1 deletion src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,15 @@ void Database::setPublicCustomData(const QVariantMap& customData)
void Database::createRecycleBin()
{
Q_ASSERT(!m_data.isReadOnly);
Group* recycleBin = Group::createRecycleBin();

auto recycleBin = new Group();
recycleBin->setUuid(QUuid::createUuid());
recycleBin->setParent(rootGroup());
recycleBin->setName(tr("Recycle Bin"));
recycleBin->setIcon(Group::RecycleBinIconNumber);
recycleBin->setSearchingEnabled(Group::Disable);
recycleBin->setAutoTypeEnabled(Group::Disable);

m_metadata->setRecycleBin(recycleBin);
}

Expand Down
16 changes: 5 additions & 11 deletions src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@ Group::~Group()
cleanupParent();
}

Group* Group::createRecycleBin()
{
Group* recycleBin = new Group();
recycleBin->setUuid(QUuid::createUuid());
recycleBin->setName(tr("Recycle Bin"));
recycleBin->setIcon(RecycleBinIconNumber);
recycleBin->setSearchingEnabled(Group::Disable);
recycleBin->setAutoTypeEnabled(Group::Disable);
return recycleBin;
}

template <class P, class V> inline bool Group::set(P& property, const V& value)
{
if (property != value) {
Expand Down Expand Up @@ -281,6 +270,11 @@ bool Group::isExpired() const
return m_data.timeInfo.expires() && m_data.timeInfo.expiryTime() < Clock::currentDateTimeUtc();
}

bool Group::isEmpty() const
{
return !hasChildren() && m_entries.isEmpty();
}

CustomData* Group::customData()
{
return m_customData;
Expand Down
3 changes: 1 addition & 2 deletions src/core/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class Group : public QObject
Group();
~Group();

static Group* createRecycleBin();

const QUuid& uuid() const;
const QString uuidToHex() const;
QString name() const;
Expand All @@ -103,6 +101,7 @@ class Group : public QObject
Entry* lastTopVisibleEntry() const;
bool isExpired() const;
bool isRecycled() const;
bool isEmpty() const;
CustomData* customData();
const CustomData* customData() const;

Expand Down
25 changes: 24 additions & 1 deletion src/gui/dbsettings/DatabaseSettingsWidgetGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "core/Entry.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "gui/MessageBox.h"

DatabaseSettingsWidgetGeneral::DatabaseSettingsWidgetGeneral(QWidget* parent)
: DatabaseSettingsWidget(parent)
Expand Down Expand Up @@ -77,9 +78,31 @@ void DatabaseSettingsWidgetGeneral::showEvent(QShowEvent* event)

bool DatabaseSettingsWidgetGeneral::save()
{
auto* meta = m_db->metadata();

if (!m_ui->recycleBinEnabledCheckBox->isChecked() && meta->recycleBinEnabled()) {
auto recycleBin = meta->recycleBin();
if (recycleBin && !recycleBin->isEmpty()) {
auto result = MessageBox::question(this,
tr("Delete Recycle Bin"),
tr("Do you want to delete the current recycle bin and all its "
"contents?\nThis action is not reversible."),
MessageBox::Delete | MessageBox::No,
MessageBox::No);

if (result == MessageBox::Delete) {
recycleBin->deleteLater();
} else {
recycleBin->setName(recycleBin->name().append(tr(" (old)")));
recycleBin->setIcon(Group::DefaultIconNumber);
}
}

meta->setRecycleBin(nullptr);
}

m_db->setCompressionAlgorithm(m_ui->compressionCheckbox->isChecked() ? Database::CompressionGZip
: Database::CompressionNone);
Metadata* meta = m_db->metadata();

meta->setName(m_ui->dbNameEdit->text());
meta->setDescription(m_ui->dbDescriptionEdit->text());
Expand Down
2 changes: 1 addition & 1 deletion tests/TestGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ void TestGroup::testAddEntryWithPath()
void TestGroup::testIsRecycled()
{
Database* db = new Database();
db->rootGroup()->createRecycleBin();
db->metadata()->setRecycleBinEnabled(true);

Group* group1 = new Group();
group1->setName("group1");
Expand Down

0 comments on commit a876b3b

Please sign in to comment.