vorta icon indicating copy to clipboard operation
vorta copied to clipboard

Keep the profile list sorted when creating/renaming profiles

Open Parnassius opened this issue 1 year ago • 4 comments

Description

Creating a new profile adds the new profile at the bottom of the list in the main window. Similarly, editing an existing profile doesn't change its position in the list. This change keeps the list sorted alphabetically in both cases.

Related Issue

Fixes #1983

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] I have read the CONTRIBUTING guide.
  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.

Parnassius avatar Apr 07 '24 08:04 Parnassius

Screenshot from 2024-04-12 12-28-37 Works fine for me, assuming we want to keep the sorting case sensitive.

shivansh02 avatar Apr 12 '24 07:04 shivansh02

Thanks for testing, @shivansh02! I don't have a strong preference for the case-sensitivity, but would lean towards case-insensitive sorting.

m3nu avatar Apr 12 '24 11:04 m3nu

The latest commit adds case-insensitive sorting to the list in the main window, as well as the list in the Backup Now tray menu.

The solution I used was to ignore the ORDER BY sql directive and simply sort the profiles with python, using both the casefolded and the normal name as the sorting key. Adding the normal name as well is required to keep the sorting stable, otherwise two profiles called test and TEST would have no fixed ordering.

In my comment on #1983 I talked about the sortItems method of QListWidget, which would be perfect for the list in the main window. However the tray menu doesn't support anything similar, so I decided against it to keep the logic the same in both places.

One final option I thought about was the COLLATE NOCASE sqlite function, but that only converts the 26 ascii uppercase letters to the lowercase equivalents, so the sorting would have remained case-sensitive for non-ascii characters.

Parnassius avatar Apr 16 '24 20:04 Parnassius

The profile list is now sorted case-insensitively, couldn't test the Backup Now list because my distro doesn't have a tray menu.

shivansh02 avatar May 19 '24 15:05 shivansh02

Thanks for the contribution, @Parnassius and thanks to @shivansh02 for reviewing.

m3nu avatar May 25 '24 13:05 m3nu