Bug 504997 - Wallpapers are sorted by filename, not title, putting Coast in the wrong spot
Summary: Wallpapers are sorted by filename, not title, putting Coast in the wrong spot
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Image & Slideshow wallpaper plugins (other bugs)
Version First Reported In: 6.4.80
Platform: Other Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-30 01:12 UTC by Justin Zobel
Modified: 2025-09-26 20:39 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.5.0
Sentry Crash Report:


Attachments
Screenshot (148.30 KB, image/png)
2025-05-30 01:12 UTC, Justin Zobel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Zobel 2025-05-30 01:12:08 UTC
Created attachment 181888 [details]
Screenshot

See screenshot.
Comment 1 TraceyC 2025-05-30 02:29:38 UTC
I can confirm this on git-master. For Wallpaper type: Image, the wallpapers are not listed alphabetically
I also see Mountain - Coast - Nexus
Also, Volna comes before Nuvole
Comment 2 cwo 2025-05-30 08:23:20 UTC
(In reply to TraceyC from comment #1)
> Also, Volna comes before Nuvole

I can't reproduce this, Nuvole is in the right place.

Volna is the alphabetically last one, is Nuvole maybe a different version? (e.g. ~/kde/usr/share/wallpapers vs /usr/share/wallpapers)
Comment 3 TraceyC 2025-05-30 16:10:59 UTC
Nuvole - /usr/share/wallpapers/Next/contents/images_dark - this one comes after Volna
Volna - /home/tracey/kde/usr/share/wallpapers/Volna/contents/images

There is a second instance of Nuvole in /home/tracey/kde/usr/share/wallpapers/Nuvole/contents/images_dark that's in the right place alphabetically
Comment 4 Nate Graham 2025-06-10 22:55:41 UTC
The solution is probably somewhere in https://invent.kde.org/plasma/plasma-workspace/-/tree/master/wallpapers/image/plugin/model; currently trying to figure it out.
Comment 5 Nate Graham 2025-06-10 23:43:15 UTC
This is a bit complicated.

There are two base wallpaper models: one for standalone images (ImageListModel), and one for packages (PackageListModel). On top of them is another model that combines them into one (ImageListProxyModel). Then when used for a slideshow, a proxy model (SlideFilterModel) introduces sorting, but sorts by filename rather than display name. There is no proxy model to introduce sorting for non-slideshow image wallpaper views; ImageProxyModel gets used directly.

So we need to:
1. Fix the slideshow sorting to sort by display name, not file path
2. Introduce sorting of the same kind for non-slideshow views, probably by creating a second proxy model for it

I'm going to try to do #1 first, and then try my luck at #2, but I may eventually need someone else to help or take over.
Comment 6 Nate Graham 2025-06-10 23:43:49 UTC
While investigating, I also found another bug with the display string being improper with some images, and proposed a fix with https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/5580.
Comment 7 Nate Graham 2025-06-11 00:31:52 UTC
Something like this should fix #1, but I haven't gotten it to fully work yet, and my Qt model-fu may not be sufficient to continue here. If anyone enterprising wants to pick up from here (or redo it from scratch to be better), feel free.


diff --git a/wallpapers/image/plugin/slidefiltermodel.cpp b/wallpapers/image/plugin/slidefiltermodel.cpp
index ed10a20b33..1f09771e03 100644
--- a/wallpapers/image/plugin/slidefiltermodel.cpp
+++ b/wallpapers/image/plugin/slidefiltermodel.cpp
@@ -19,6 +19,11 @@
 
 namespace
 {
+inline QString getDisplayName(const QModelIndex &modelIndex)
+{
+    return modelIndex.data(Qt::DisplayRole).toString();
+}
+
 inline QString getLocalFilePath(const QModelIndex &modelIndex)
 {
     return modelIndex.data(ImageRoles::PathRole).toUrl().toLocalFile();
@@ -145,20 +150,22 @@ bool SlideFilterModel::lessThan(const QModelIndex &source_left, const QModelInde
             QFileInfo rightFile(getLocalFilePath(source_right));
             QString leftFilePath = getFilePathWithDir(leftFile);
             QString rightFilePath = getFilePathWithDir(rightFile);
+            const QString leftImage(getDisplayName(source_left));
+            const QString rightImage(getDisplayName(source_right));
 
             if (leftFilePath == rightFilePath) {
-                return QString::compare(leftFile.fileName(), rightFile.fileName(), cs) < 0;
+                return QString::compare(leftImage, rightImage, cs) < 0;
             } else if (leftFilePath.startsWith(rightFilePath, cs)) {
                 return true;
             } else if (rightFilePath.startsWith(leftFilePath, cs)) {
                 return false;
             } else {
-                return QString::compare(leftFilePath, rightFilePath, cs) < 0;
+                return QString::compare(leftImage, rightImage, cs) < 0;
             }
         } else {
-            QFileInfo leftFile(getLocalFilePath(source_left));
-            QFileInfo rightFile(getLocalFilePath(source_right));
-            return QString::compare(leftFile.fileName(), rightFile.fileName(), cs) < 0;
+            const QString leftImage(getDisplayName(source_left));
+            const QString rightImage(getDisplayName(source_right));
+            return QString::compare(leftImage, rightImage, cs) < 0;
         }
     case SortingMode::AlphabeticalReversed:
         if (m_SortingFoldersFirst) {
@@ -166,20 +173,22 @@ bool SlideFilterModel::lessThan(const QModelIndex &source_left, const QModelInde
             QFileInfo rightFile(getLocalFilePath(source_right));
             QString leftFilePath = getFilePathWithDir(leftFile);
             QString rightFilePath = getFilePathWithDir(rightFile);
+            const QString leftImage(getDisplayName(source_left));
+            const QString rightImage(getDisplayName(source_right));
 
             if (leftFilePath == rightFilePath) {
-                return QString::compare(leftFile.fileName(), rightFile.fileName(), cs) > 0;
+                return QString::compare(leftImage, rightImage, cs) > 0;
             } else if (leftFilePath.startsWith(rightFilePath, cs)) {
                 return true;
             } else if (rightFilePath.startsWith(leftFilePath, cs)) {
                 return false;
             } else {
-                return QString::compare(leftFilePath, rightFilePath, cs) > 0;
+                return QString::compare(leftImage, rightImage, cs) > 0;
             }
         } else {
-            QFileInfo leftFile(getLocalFilePath(source_left));
-            QFileInfo rightFile(getLocalFilePath(source_right));
-            return QString::compare(leftFile.fileName(), rightFile.fileName(), cs) > 0;
+            const QString leftImage(getDisplayName(source_left));
+            const QString rightImage(getDisplayName(source_right));
+            return QString::compare(leftImage, rightImage, cs) > 0;
         }
     case SortingMode::Modified: // oldest first
     {
Comment 8 Bug Janitor Service 2025-09-24 10:01:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/5841
Comment 9 Bug Janitor Service 2025-09-24 10:01:16 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/5841
Comment 10 David Redondo 2025-09-26 10:32:21 UTC
Git commit ddb208848825473cd67a82e9243f3024e2288369 by David Redondo.
Committed on 26/09/2025 at 10:12.
Pushed by davidre into branch 'master'.

wallpapers/slideshow: Use user visible strings for sorting

Sorting the file names leads to puzzling results for the user.
Co-Authored-By: Nate Graham <nate@kde.org>

M  +19   -10   wallpapers/image/plugin/slidefiltermodel.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/ddb208848825473cd67a82e9243f3024e2288369
Comment 11 David Redondo 2025-09-26 10:32:29 UTC
Git commit 6b72204bb4ba3547450e368d70338d79decf8f70 by David Redondo.
Committed on 26/09/2025 at 10:12.
Pushed by davidre into branch 'master'.

wallpapers/image: Sort wallpapers alphabetically
FIXED-IN: 6.5

M  +24   -1    wallpapers/image/imagepackage/contents/ui/ThumbnailsComponent.qml

https://invent.kde.org/plasma/plasma-workspace/-/commit/6b72204bb4ba3547450e368d70338d79decf8f70
Comment 12 David Redondo 2025-09-26 12:17:17 UTC
Git commit 3b00327fd74d7297b94cdbb61fa8d22918d83863 by David Redondo.
Committed on 26/09/2025 at 11:56.
Pushed by davidre into branch 'Plasma/6.5'.

wallpapers/slideshow: Use user visible strings for sorting

Sorting the file names leads to puzzling results for the user.
Co-Authored-By: Nate Graham <nate@kde.org>

(cherry picked from commit ddb208848825473cd67a82e9243f3024e2288369)

M  +19   -10   wallpapers/image/plugin/slidefiltermodel.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/3b00327fd74d7297b94cdbb61fa8d22918d83863
Comment 13 David Redondo 2025-09-26 12:17:25 UTC
Git commit 3785a93f002eac41b90a0b3c74a995b1e286d0ec by David Redondo.
Committed on 26/09/2025 at 11:56.
Pushed by davidre into branch 'Plasma/6.5'.

wallpapers/image: Sort wallpapers alphabetically
FIXED-IN: 6.5
(cherry picked from commit 6b72204bb4ba3547450e368d70338d79decf8f70)

M  +24   -1    wallpapers/image/imagepackage/contents/ui/ThumbnailsComponent.qml

https://invent.kde.org/plasma/plasma-workspace/-/commit/3785a93f002eac41b90a0b3c74a995b1e286d0ec