Bug 458400

Summary: Folder View widget shows .desktop files' filenames instead of desktop entry's Name property when using user-specified path
Product: [Plasma] plasmashell Reporter: Alexander Wilms <f.alexander.wilms>
Component: Desktop icons & Folder View widgetAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: minor CC: hein, nate, olib141
Priority: NOR    
Version: 5.25.4   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.2.0
Sentry Crash Report:

Description Alexander Wilms 2022-08-27 19:17:53 UTC
SUMMARY
When using the Folder Widget to display the contents of a folder below ~/Desktop, the Folder View shows the .desktop file names instead of the specified Name properties. 

This can be worked around by using desktop:///Productivity as user-defined path instead of file:///home/alexander/Desktop/Productivity, which is used by default when using the file browser to select a path.


STEPS TO REPRODUCE
1. Right click on desktop > add widget
2. Add Folder View
3. Right click on widget > Folder View preferences
4. Set a user defined path

OBSERVED RESULT
Folder View shows the .desktop file names

EXPECTED RESULT
Folder View shows the Name properties specified in the .desktop files

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20220825
KDE Plasma Version: 5.25.4
KDE Frameworks Version: 5.97.0
Qt Version: 5.15.5


ADDITIONAL INFORMATION
https://forum.kde.org/viewtopic.php?f=67&t=87492
Comment 1 Alexander Wilms 2022-08-31 20:56:08 UTC
Found the line of code which would need to be changed: https://invent.kde.org/plasma/plasma-desktop/-/blob/master/containments/desktop/package/contents/ui/ConfigLocation.qml#L167
Comment 2 Nate Graham 2022-09-01 14:32:24 UTC
Nice, wanna fix it?
Comment 3 Alexander Wilms 2022-09-01 16:29:02 UTC
I'm trying, but I don't know how to get a relative path from two absolute paths:
Apparently, the QDir type is not available in QML and in Javascript it's usually done with a NodeJS module.

    function getDesktopURI(fileURI) {
        var absoluteDesktopURI = StandardPaths.writableLocation(StandardPaths.DesktopLocation)
//      var relativeURI = absoluteDesktopURI.relativeFilePath(fileURI) <- QDir method
//      var desktopURI = relativeURI.replace("file://","desktop://")
        console.log(fileURI)
        console.log(absoluteDesktopURI)
//      console.log(relativeURI)

//        var path = require('path') <- NodeJS module
//        console.log(path.relative('/foo/bar/baz', '/foo')) 
        return fileURI
    }
Comment 4 Alexander Wilms 2022-09-08 10:54:50 UTC
I submitted a merge request: https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1125

I didn't test it in a Plasma session, but the unit test passes.
Comment 5 Nate Graham 2022-09-14 17:26:57 UTC
*** Bug 459077 has been marked as a duplicate of this bug. ***
Comment 6 Nate Graham 2024-07-02 16:59:54 UTC
Git commit 6ba1f9197348db4aa2d6c465cba34699c48e19ba by Nate Graham, on behalf of Alexander Wilms.
Committed on 02/07/2024 at 16:59.
Pushed by ngraham into branch 'master'.

containments/desktop: Store Folder View configuration paths relative to desktop

The Folder View widget currently shows .desktop files' filenames instead of
desktop entries' Name properties when using a user-specified path.

This commit fixes that issue by converting all file:// paths below the desktop
to relative ones using the desktop:// scheme.
FIXED-IN: 6.2.0

M  +5    -5    containments/desktop/package/contents/ui/ConfigLocation.qml
M  +3    -1    containments/desktop/package/contents/ui/FolderItemDelegate.qml
M  +1    -0    containments/desktop/plugins/folder/CMakeLists.txt
M  +1    -0    containments/desktop/plugins/folder/autotests/CMakeLists.txt
A  +61   -0    containments/desktop/plugins/folder/autotests/desktopschemehelpertest.cpp     [License: GPL(v2.0+)]
A  +20   -0    containments/desktop/plugins/folder/autotests/desktopschemehelpertest.h     [License: GPL(v2.0+)]
A  +73   -0    containments/desktop/plugins/folder/desktopschemehelper.cpp     [License: GPL(v2.0+)]
A  +27   -0    containments/desktop/plugins/folder/desktopschemehelper.h     [License: GPL(v2.0+)]
M  +37   -0    containments/desktop/plugins/folder/foldermodel.cpp
M  +3    -0    containments/desktop/plugins/folder/foldermodel.h
M  +9    -0    containments/desktop/plugins/folder/folderplugin.cpp
M  +2    -1    containments/desktop/plugins/folder/labelgenerator.cpp

https://invent.kde.org/plasma/plasma-desktop/-/commit/6ba1f9197348db4aa2d6c465cba34699c48e19ba