Skip to content

Draft: [feature]: Implement grouping by common prefix

Overview

This is a feature-complete but not super well-tested version of the grouping model that I want to have in Dolphin.

Disclaimer

Unit tests are WIP.

Details

The main and key difference is that the new grouping behaviour is "intelligent" enough to recognise common numerical prefixes and boundaries.

  • The upshot is that if you have two files one with "common" and the other with "commonality" the word "common" is not extracted as a common prefix. But if the two variants are "common.string" and "common.bool" they are included as common prefixes.

  • Similarly numerical prefixes have to be reapeated, so things like cd1.track01, cd1.track02 ... cd1.track99 all end up in a group with cd1 as the prefix.

  • The boundary for choice is done in a neat way: it checks if the characters all belong to the same class, so things like non-latin languages will still benefit, provided their punctuation is classified as punctuation, and numbers as numbers.

  • The headers are also more intelligent. They take the first and last element of the group. So if you know what you're looking for it can lead to some very useful results. One in particular, is that the i18n status of the strings is irrelevant. Things can have mixed locales, as long as the common prefix is used, they'll end up in the same group.

  • I've taken the liberty of replacing the original grouping by-name behaviour with mine, because I think that it can still be implemented, but more in line with how Apple devices do so for sorted lists: a small scoll-bar-like element with tiny characters that can be used to teleport to different initial characters. Given that the new method will never group objects into an "other" category, this means that the two behaviours can be implemented simultaneously. Furthermore, that tiny scroll-bar element might be useful for scrolling through the history of objects with other grouping methods enabled.

Finally, I've tested that this doesn't cause a huge performance regression. The entire grouping pipeline seems to be doing a lot of work in the foreground thread, so I had to get rid of the parts of the grouping heuristic that would make it more than linear. It's not super slow, but it is more demanding than the old algorithm.

Further work

  1. I think that there ought to be a multimedia grouping heuristic that could be implemented either with help of Elisa (and calling that code from Dolphin, which might not be as far fetched as one would believe), or directly as its own dynamic library. More on that later in a discussion.

  2. I think the grouping modes in Dolphin should be made a bit more accessible. I plan to explain how to do that in my personal blog, but that's just not a good long-term solution. Maybe make it available in the menus, but not as deeply nested... maybe give it a presence on the default toolbar right next to the view buttons.

  3. I think the heuristic could be made smarter. I was conscious of the performance, but if I were allowed to make a bigger change to grouping methodology, by doing the grouping in a JIT fashion, doing some of it in parallel, and adding some more function to the headers (e.g. allow one to select all things in a sub-group by clicking on it, similarly to how we can select an entire folder with the plus icon or a single click (in plasma 6)).

  4. I really think that there ought to be some good tests for this that rely on some internationalised data. The previous implementation had a lot of comments that hint at the behaviour breaking on other locales. I tested my implementation on my local collections, and it usually produces well-structured groups, but I'm not sure how the testing is done in general.


As a word of caution I've not done a lot of C++ since Qt 4 days, and definitely not in the modern context. If the code is not idiomatically C++, please let me know, I know it might be faster for you to fix it, but this is far from the only contribution I'd like to make to a KDE progject, and definitely not the last time you'll hear from me at Dolphin.

Signed-off-by: Aleksandr Petrosyan ap886@cantab.ac.uk

Merge request reports