borgbase / vorta

Desktop Backup Client for Borg Backup
https://vorta.borgbase.com
GNU General Public License v3.0
1.99k stars 132 forks source link

Keep the profile list sorted when creating/renaming profiles #1986

Closed Parnassius closed 4 months ago

Parnassius commented 5 months ago

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

Checklist:

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

shivansh02 commented 5 months ago

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

m3nu commented 5 months ago

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

Parnassius commented 5 months ago

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.

shivansh02 commented 4 months ago

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

m3nu commented 4 months ago

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