frontend, libobs, plugins: Natural sorting for files, profile and scene names - #12577
frontend, libobs, plugins: Natural sorting for files, profile and scene names#12577Dankirk wants to merge 6 commits into
Conversation
|
Updated the list of filenames I tested the sorting with and I'm happy with the results. One issue remains: There is also a question if the default locale set with |
b12ac87 to
35c77a8
Compare
Warchamp7
left a comment
There was a problem hiding this comment.
Approving on a conceptual/UX level, but others will need to speak to the technical implications
28140c8 to
1c78f24
Compare
751c514 to
59ca15a
Compare
|
I addressed the lack of locale-awareness on Windows by adding some new apis to libsobs/util/platform. They provide the generic locale aware comparison and sorting, but also a convenience function for sorted directory file listing with the existing dir apis. The apis like Updated the pr description and documentation updates are included. |
Sort drag&dropped sources using locale-aware natural sorting with QCollator and system locale.
Change locale-aware sorting of profiles and scene collections in menus to locale-aware natural sorting, so number sequences in names are treated by value rather than their alphabetical order.
New comparison methods astrnatcmpi() and wstrnatcmpi() for sorting strings and documentation for them. Uses locale aware strcol() / wcscoll() and a custom implementation of natural comparison for number sequences. Supports multibyte and whcar surrogate characters. This is intended to be used for parts that do not have direct access to higher level methods like Qt QCollator.
Applies locale-aware natural sorting to the cycled files when adding directory to image slideshow. Previously files in directories were cycled in arbitrary order by os_readdir(). Locale-awareness is limited on Windows currently, because we are using minimal 'C' locale for it. This is to be addressed separately.
Applies the same natural, alphabetical sort to vlc playlist directories that was added for slideshow.
Adds locale aware functions for libobs and makes slideshow and vlc plugins use them for natural, locale aware file sorting. Adds documentation for the new locale apis.
Description
Applies natural, locale aware sorting when drag&dropping many sources at once and to profile and scene names in menus. For slideshow (mk2) and VLC the files in added directories are cycled using this sorting method instead of an arbitrary order. The order of items in the slideshow listbox is otherwise preserved.
For background: Natural sort means sorting by numerical value. Alphabetical sort arranges numbers like this: 1 < 10 < 11 < 2 < 3.
Natural sort does it this way: 1 < 2 < 3 < 10 < 11.
The natural sort is what Windows explorer uses under the hood when you sort by name or use
ls -von unix.For general use,
qt-wrappershas couple new methods for natural sorting:The list parameter is sorted using locale and number value aware algorithm with
QCollator. It works withQStringandQStringView. System locale is used to achieve the locale-aware sorting.For lower level stuff in C, like slideshow plugin, there's new comparison functions for
char*andwchar_t*indstrlibrary.The return value is <0, 0 or >0 as expected for return value of
qsort()'s callback function. This sorting usesstrcoll()andwcscoll()respectively for locale aware sorting, but does natural number sorting using a custom implementation.OBS doesn't currently use process wide system locale for C/C++ on Windows (issue disussed here #12624), so new locale apis are added to libobs platform library and documentation added. These can be used to do locale aware comparison / sorting in C directly and are used as basis for the main things
astrnatcmpandwstrnatcmp.OBSBasic_Dropfiles.cpp has somewhat sizable changes, due to how late the names for listed sources were acquired. This changes it so names are gathered first for sorting and only later added to the UI.
Motivation and Context
Fixes #10382
Couple requests on forums here and here. Most recently I saw a Youtuber mention this during a live stream.
The issue is with filenames and other listings that contain incremental numbers which are not sorted intuitively when sorted alphabetically. In fact the alphabetical sorting is also coincidental, since the methods for iterating over files give no guarantee about the order.
How Has This Been Tested?
I tested the features with files in directories with the following file names to see if they are sorted correctly:
testnames.txt
The files should appear in the order listed for en_FI locale. The files with 'ä' or 'ö' could be in another place for different locales. The important part is the numerical comparison works, so 5.jpg is before 10.jpg while the opposite is true for basic alphabetical sorting.
I'm on Windows 11 English US version, but with Finnish region/locale settings.
Types of changes
Checklist: