Sort icon and cursor themes case-insensitively
ClosedPublic

Authored by ngraham on Sep 19 2018, 4:25 AM.

Details

Summary

Stick a QSortFilterProxyModel between the model and the view, and tell it to sort case-insensitively. Thanks to https://stackoverflow.com/a/5732026/2934226 for providing the solution.

BUG: 368600
FIXED-IN: 5.14.0

Test Plan

Could not test as I was unable to locate a working GTK 2 or 3 theme that started with a lowercase letter. But theoretically this code should do the trick, and it does not appear to cause any regressions at least.

Diff Detail

Repository
R99 KDE Gtk Configuration Tool
Branch
sort-icon-and-cursor-themes-case-insensitively (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 3002
Build 3020: arc lint + arc unit
ngraham created this revision.Sep 19 2018, 4:25 AM
Restricted Application added a project: Plasma. · View Herald TranscriptSep 19 2018, 4:25 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
ngraham requested review of this revision.Sep 19 2018, 4:25 AM
ngraham edited the summary of this revision. (Show Details)Sep 19 2018, 4:26 AM
ngraham edited the summary of this revision. (Show Details)

Can't we fix the CursorThemesModel and IconThemesModel to already populate themselves correctly?

Data structures are not really my forte, but I had a look. It seems possible but rather complicated due to the way the models populate and update themselves and return data. I'd like to see what @apol has to say.

Is there some big disadvantage with this approach in this patch? Negative memory/performance implications?

cfeck added a subscriber: cfeck.Sep 19 2018, 9:26 PM

If you would need to process the data sorted, you would already sort the model. But here, it is only sorted for display, and that's exactly the use case for the proxy model.

ngraham updated this revision to Diff 41956.Sep 20 2018, 4:06 AM

Rebase on Plasma/5.14 branch

broulik resigned from this revision.Sep 20 2018, 8:41 AM
wbauer added a subscriber: wbauer.EditedSep 20 2018, 8:55 AM

Well, I tried this patch (applied upon 5.13.90a) and it doesn't seem to change anything.
I still get icon and cursor themes starting with a lower-case character sorted after all those with an upper-case character.

I suppose that's because, according to the QSortFilterProxyModel docs, At this point, neither sorting nor filtering is enabled; the original data is displayed in the view.
Apparently you need to explicitly call sort() on the proxy model...
See http://doc.qt.io/qt-5/qsortfilterproxymodel.html#details

Regardless of that, using a QSortFilterProxyModel would render the previous fix (https://phabricator.kde.org/R99:7b56c23870798adbeb3f110eacae7f1020dcad6f) useless (as I see it there's no need to sort the model if it goes through QSFPM anyway), so it should be reverted here IMHO.

Btw, the lower-case cursor themes I have installed ("handhelds", "redglass", "whiteglass") come from the (openSUSE) package xcursor-themes.
From the package's README:

This is a default set of cursor themes for use with libXcursor,
originally created for the XFree86 Project, and now shipped as part
of the X.Org software distribution.
...
The master development code repository can be found at:

git://anongit.freedesktop.org/git/xorg/data/cursors
 
http://cgit.freedesktop.org/xorg/data/cursors

Although, just renaming or copying an existing cursor theme folder (they are in /usr/share/icons/) accordingly should suffice for testing as well.

wbauer added a comment.EditedSep 20 2018, 9:46 AM

I suppose that's because, according to the QSortFilterProxyModel docs, At this point, neither sorting nor filtering is enabled; the original data is displayed in the view.
Apparently you need to explicitly call sort() on the proxy model...

Yes, adding cursorsProxyModel->sort(0); and iconsProxyModel->sort(0); here seems to "fix" the sorting.
Although, I think that would need to be done every time the data changes. (can that happen later on? I haven't looked at all the code...)

Maybe it would be better to derive CursorThemesModel and IconThemesModel from QSortFilterProxyModel instead of QStandardItemModel, and keep the previous fix?
Or maybe reimplement sort() in these classes, the base implementation of QStandardItemModel just does nothing if I read the docs correctly (that also means that the previous fix actually did nothing either).

Just some thoughts, though.

Although, I think that would need to be done every time the data changes.

QSortFilterProxyModel does that automatically

Although, I think that would need to be done every time the data changes.

QSortFilterProxyModel does that automatically

You mean it will keep the data sorted after changes if you call sort() once?
It obviously doesn't sort it automatically by default.

ngraham updated this revision to Diff 41983.Sep 20 2018, 1:11 PM

Address review comments

Maybe it would be better to derive CursorThemesModel and IconThemesModel from QSortFilterProxyModel instead of QStandardItemModel, and keep the previous fix?

I had that idea too and gave it a shot, but got into the weeds quickly and abandoned the effort because it seemed too challenging. If this seems like the correct approach, I can give it another go.

apol accepted this revision.Sep 20 2018, 3:16 PM

LGTM, not sure why sort() doesn't work though.

This revision is now accepted and ready to land.Sep 20 2018, 3:16 PM

Works (and looks) fine for me now.

Btw, it wouldn't really be necessary to call setSortRole(Qt::DisplayRole), as the default value is Qt::DisplayRole anyway. (but of course doing it is not wrong either...)

@wbauer, thanks for the hint. I've tested this with xcursor-themes and verified that it works for me too.

I'll keep setSortRole(Qt::DisplayRole) for explicitness if nobody objects.

This revision was automatically updated to reflect the committed changes.

Darn, looks like arc didn't notice my rebase on 5.14. Oh well, I guess this'll go into 5.15.

Darn, looks like arc didn't notice my rebase on 5.14. Oh well, I guess this'll go into 5.15.

Well, you could cherry-pick it into the 5.14 branch (using git cherry-pick xxx).
Not sure if it's worth it though...