Prompt to delete recycle bin when disabling it

Fixes #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.
This commit is contained in:
Mark Hakansson 2019-10-12 15:27:35 +02:00 committed by Jonathan White
parent a1e12c1b30
commit a876b3b72f
5 changed files with 39 additions and 16 deletions

View File

@ -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);
}

View File

@ -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) {
@ -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;

View File

@ -80,8 +80,6 @@ public:
Group();
~Group();
static Group* createRecycleBin();
const QUuid& uuid() const;
const QString uuidToHex() const;
QString name() const;
@ -103,6 +101,7 @@ public:
Entry* lastTopVisibleEntry() const;
bool isExpired() const;
bool isRecycled() const;
bool isEmpty() const;
CustomData* customData();
const CustomData* customData() const;

View File

@ -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)
@ -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());

View File

@ -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");