Skip to content

Add context menu entry to clean the Recycle Bin in databases#520

Merged
louib merged 5 commits intokeepassxreboot:developfrom
vsvyatski:develop
Apr 22, 2017
Merged

Add context menu entry to clean the Recycle Bin in databases#520
louib merged 5 commits intokeepassxreboot:developfrom
vsvyatski:develop

Conversation

@vsvyatski
Copy link
Copy Markdown
Contributor

Description

This implements the feature request (issue) #503, created by myself. If it's possible, could you include this functionality into the incoming version 2.2.0?

Motivation and context

In some way I missed the "Empty recycle bin" menu item from the original KeePass, so I felt up to implementing this functionality for KeePassXC. This pull request basically gets the job done for #503.

How has this been tested?

It was tested by running your unit tests (testcsvimport failed again) and manually by playing with the UI I had introduced. The stuff seems to be functioning properly. My testing environment is Windows 10 Creators Update.

Screenshots (if appropriate):

I have slightly modified the "Groups" so that it's more similar to the original KeePass. Below is the screenshot of KeePass 2.35
original KeePass

Here is the context menu of KeePassXC in my implementation (don't judge me too hard if it looks inappropriate to you)
context menu of KeePassXC

The same stuff in the main menu
main menu of KeePassXC

If the recycle bin is not selected, the "Empty recycle bin" is not shown, see below
context menu of KeePassXC on non-trash group

Types of changes

  • ✅ New feature (non-breaking change which adds functionality)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ Almost all new and existing tests passed (except for # 18). [REQUIRED]
  • ✅ No -DWITH_ASAN=ON, because I'm on Windows. [REQUIRED]
  • ✅ User manual on this program should be updated (if it exists, of course) to describe this new feature.

This implements the feature request (issue) #503.
return m_groupView->currentGroup() && m_groupView->currentGroup() == m_db->metadata()->recycleBin();
}

void DatabaseWidget::emptyTrash()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsvyatski for consistency we might want to name that emptyRecycleBin

return;
}

if (currentGroup == m_db->metadata()->recycleBin()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsvyatski why not use isRecycleBinSelected?

if (currentGroup == m_db->metadata()->recycleBin()) {
QMessageBox::StandardButton result = MessageBox::question(
this, tr("Empty recycle bin?"),
tr("Are you sure you want to permanently delete everytning from your recycle bin?"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsvyatski everything**


if (result == QMessageBox::Yes) {
// destroying direct entries of the recycle bin
QList<Entry*> subEntries = currentGroup->entries();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsvyatski I'd argue this could go in one of the core classes. In Database, there is already createRecycleBin, recycleEntry and recycleGroup. Maybe we could add emptyRecycleBin there. It would also be easier to unit test!

Copy link
Copy Markdown
Member

@louib louib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsvyatski thanks for the PR! I added some comments on the changes.

// destroying direct entries of the recycle bin
QList<Entry*> subEntries = m_metadata->recycleBin()->entries();
for (Entry* entry : subEntries) {
delete entry;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the appropriate way to get rid of an entry? I would imagine you would have to go through the db object to remove entries and groups officially.

Copy link
Copy Markdown
Contributor Author

@vsvyatski vsvyatski Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@droidmonkey Well, it seems it is, or almost it is. Here is the code from Group destructor (src link):

Group::~Group()
{
    // Destroy entries and children manually so DeletedObjects can be added
    // to database.
    const QList<Entry*> entries = m_entries;
    for (Entry* entry : entries) {
        delete entry;
    }

    const QList<Group*> children = m_children;
    for (Group* group : children) {
        delete group;
    }

    if (m_db && m_parent) {
        DeletedObject delGroup;
        delGroup.deletionTime = QDateTime::currentDateTimeUtc();
        delGroup.uuid = m_uuid;
        m_db->addDeletedObject(delGroup);
    }

    cleanupParent();
}

As you can see, it does things similar to what I've done.

Here is the source of Entry destructor(src link)

Entry::~Entry()
{
    if (m_group) {
        m_group->removeEntry(this);

        if (m_group->database()) {
            m_group->database()->addDeletedObject(m_uuid);
        }
    }

    qDeleteAll(m_history);
}

It updates the DB and all that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional information. After cleaning the recycle bin and saving, a KDBX file is reduced in size and can be opened in KeePass 2.35 (the original .NET program). The latter doesn't report any errors and the recycle bin looks clean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, just making sure.

@louib
Copy link
Copy Markdown
Member

louib commented Apr 21, 2017

@vsvyatski Do you think you could add a unit test for the new function in Database, now that it's well encapsulated?

As a side note, I could be nice at some point to have an empty recycle bin icon for when the recycle bin is empty!

@vsvyatski
Copy link
Copy Markdown
Contributor Author

@louib I could try. I don't see any class TestDatabase in the tests folder though. What is the proper place to put that test? Should I create a new class?

Regarding your side note: perhaps later, I believe the original KeePass doesn't have that empty recycle bin icon either.

@louib
Copy link
Copy Markdown
Member

louib commented Apr 21, 2017

@vsvyatski you could create a TestDatabase class in the tests directory (look at TestEntry.cpp for example).

I'll add an issue for the empty recycle bin.

@vsvyatski
Copy link
Copy Markdown
Contributor Author

@louib I've added 3 out of 4 test cases. I'm going to need to continue on another machine therefore I'm pushing the code. I will additionally notify you once I consider the tests implemented.

@vsvyatski
Copy link
Copy Markdown
Contributor Author

@louib As promised, I'm done with the tests. You can now review.

@louib
Copy link
Copy Markdown
Member

louib commented Apr 22, 2017

@vsvyatski awesome work, thanks for the contribution!

@louib louib merged commit ad79162 into keepassxreboot:develop Apr 22, 2017
@phoerious phoerious added this to the v2.2.0 milestone May 7, 2017
droidmonkey added a commit that referenced this pull request Jun 25, 2017
- Added YubiKey 2FA integration for unlocking databases [#127]
- Added TOTP support [#519]
- Added CSV import tool [#146, #490]
- Added KeePassXC CLI tool [#254]
- Added diceware password generator [#373]
- Added support for entry references [#370, #378]
- Added support for Twofish encryption [#167]
- Enabled DEP and ASLR for in-memory protection [#371]
- Enabled single instance mode [#510]
- Enabled portable mode [#645]
- Enabled database lock on screensaver and session lock [#545]
- Redesigned welcome screen with common features and recent databases [#292]
- Multiple updates to search behavior [#168, #213, #374, #471, #603, #654]
- Added auto-type fields {CLEARFIELD}, {SPACE}, {{}, {}} [#267, #427, #480]
- Fixed auto-type errors on Linux [#550]
- Prompt user prior to executing a cmd:// URL [#235]
- Entry attributes can be protected (hidden) [#220]
- Added extended ascii to password generator [#538]
- Added new database icon to toolbar [#289]
- Added context menu entry to empty recycle bin in databases [#520]
- Added "apply" button to entry and group edit windows [#624]
- Added macOS tray icon and enabled minimize on close [#583]
- Fixed issues with unclean shutdowns [#170, #580]
- Changed keyboard shortcut to create new database to CTRL+SHIFT+N [#515]
- Compare window title to entry URLs [#556]
- Implemented inline error messages [#162]
- Ignore group expansion and other minor changes when making database "dirty" [#464]
- Updated license and copyright information on souce files [#632]
- Added contributors list to about dialog [#629]
supershoop pushed a commit to supershoop/keepassxc that referenced this pull request Oct 5, 2022
In these cases delete the group instead of trying to move it to the recycle bin.

Closes keepassxreboot#520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants