Bug 494430 - With Folder View widget showing desktop:/, popup titles incorrectly show KDE Connect phones some of the time
Summary: With Folder View widget showing desktop:/, popup titles incorrectly show KDE ...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Desktop icons & Folder View widget (show other bugs)
Version: 6.2.3
Platform: Other Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2024-10-10 12:49 UTC by Filip
Modified: 2025-01-23 22:59 UTC (History)
8 users (show)

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


Attachments
Smartphone and PC connected (2.84 MB, image/png)
2024-10-10 12:49 UTC, Filip
Details
Smartphone and PC not connected (2.84 MB, image/png)
2024-10-10 12:50 UTC, Filip
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Filip 2024-10-10 12:49:40 UTC
Created attachment 174620 [details]
Smartphone and PC connected

SUMMARY
Desktop Settings window title displays my phone name (when it's connected through KDE Connect with PC) in the title

STEPS TO REPRODUCE
1. Connect your phone to PC through KDE Connect
2. Right click on desktop and open Desktop and Wallpaper
3. Look at the title

OBSERVED RESULT
Phone name > user_home_directory/Desktop Settings in the title

EXPECTED RESULT
Title says only Desktop Settings

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.2.0
KDE Frameworks Version: 6.6.0
Qt Version: 6.7.3
Kernel Version: 6.11.2-arch1-1 (64-bit)
Graphics Platform: Wayland
Comment 1 Filip 2024-10-10 12:50:04 UTC
Created attachment 174621 [details]
Smartphone and PC not connected
Comment 2 Nate Graham 2024-11-14 19:39:46 UTC
Can reproduce. How strange!
Comment 3 Nate Graham 2024-11-14 20:58:04 UTC
It's caused by this line in plasma-desktop:labelgenerator.cpp:

> const QModelIndex index = s_placesModel->closestItem(url);

At this point `url` points to the actual location to be shown. Then PlacesModel::closestItem() apparently thinks the entry that's closest to it is the KDE Connect one.
Comment 4 Nate Graham 2024-11-14 21:03:13 UTC
This is a bug in KFilePlacesModel::closestItem(). It does something super weird. Here's a debug log of it going through my places model to try to find the best match:

Looking at QUrl("file:///home/nate")
I think it matches QUrl("/home/nate/Desktop/")
It's the new best match
Looking at QUrl("file:///home/nate/Desktop")
I think it matches QUrl("/home/nate/Desktop/")
It's the new best match
Looking at QUrl("file:///home/nate/Documents")
Looking at QUrl("file:///home/nate/Documents/Tabletop games")
Looking at QUrl("file:///home/nate/Downloads")
Looking at QUrl("file:///home/nate/Music")
Looking at QUrl("file:///home/nate/Pictures")
Looking at QUrl("file:///home/nate/Videos")
Looking at QUrl("file:///home/nate/Documents/KDE")
Looking at QUrl("file:///home/nate/Documents/Work & Money/Blue Systems")
Looking at QUrl("trash:/")
I think it matches QUrl("/home/nate/Desktop/")
Looking at QUrl("remote:/")
I think it matches QUrl("/home/nate/Desktop/")
Looking at QUrl("smb://gaston@192.168.1.140/Users/gaston")
Looking at QUrl("recentlyused:/files")
Looking at QUrl("recentlyused:/locations")
Looking at QUrl("file:///home")
I think it matches QUrl("/home/nate/Desktop/")
Looking at QUrl("file:///")
I think it matches QUrl("/home/nate/Desktop/")
Looking at QUrl("kdeconnect://2af2212406d8fc90/")
I think it matches QUrl("/home/nate/Desktop/")
It's the new best match


Looks like every IOWorker that's not file:/ is being considered a match, so it thinks they're all great matches and returns the last one, which is typically KDE Connect.
Comment 5 Nate Graham 2024-11-14 21:13:42 UTC
It looks like QUrl::isParentOf changed behavior here. Now this line of code returns true:

> QUrl("kdeconnect://foobar).isParentOf(QUrl("file://my/favorite/place))

That doesn't seem to have been the case in the past. This is what's tripping it up.
Comment 6 Kai Uwe Broulik 2024-11-15 06:20:16 UTC
> QUrl("kdeconnect://foobar).isParentOf(QUrl("file://my/favorite/place))

Cannot reproduce with Qt 6.8.0 or Qt dev. There have been numerous changes to QUrl normalization and what not recently, though. Maybe it’s a Qt 6.7(.3) issue that’s since been fixed?

Either way, this would be a Qt bg, QUrl::isParentOf clearly states that the schemes of the two URLs must match for them to ever be considered related. The only change I can see to this particular function is from Sep 2022 when it was ported from count/length to size, so the issue must be elsewhere(?)
Comment 7 Nate Graham 2024-11-15 16:11:12 UTC
Kai looked into this and found that the QUrl behavior did not change, but what did change is that desktop:/ got changed into /home/$USER/Desktop by https://invent.kde.org/plasma/plasma-desktop/-/commit/6ba1f9197348db4aa2d6c465cba34699c48e19ba, which triggered this issue.

Alexander, could you look into that?
Comment 8 Alexander Wilms 2024-11-16 03:06:25 UTC
I can reproduce this as well.

So the bug needs to be fixed in KFilePlacesModel::closestItem(), not the code that was changed in https://invent.kde.org/plasma/plasma-desktop/-/commit/6ba1f9197348db4aa2d6c465cba34699c48e19ba, correct?
Comment 9 Nate Graham 2024-11-18 16:57:55 UTC
There may be multiple ways to fix it.

KFilePlacesModel::closestItem() does not seem to be doing the right thing in my estimation, due to the way QUrl::isParentOf() works), but it also wasn't a problem with the old code that passed it desktop:/. The issue only appears when it gets /home/$USER/Desktop instead.
Comment 10 Bug Janitor Service 2025-01-17 16:44:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/2729
Comment 11 Nate Graham 2025-01-23 20:51:11 UTC
Git commit 9a6336387a42af3639d85a26b65b3337dda3e360 by Nate Graham.
Committed on 23/01/2025 at 20:31.
Pushed by ngraham into branch 'master'.

applets/folder: Don't use DesktopSchemeHelper::getFileUrl to get title

It isn't needed since we don't directly display it to the user; instead
we poke and prod it in various ways and then return the processed
string. This means we need the original URL, not a modified version of
it, which makes KFilePlacesModel::closestItem() return the wrong thing.

KFilePlacesModel::closestItem() isn't doing anything technically
incorrect here; it's our problem for giving it malformed data.

This fixes the Folder View widget having the wrong title when showing
the contents of desktop:/, as it does by default.
FIXED-IN: 6.3.0

M  +1    -1    containments/desktop/plugins/folder/labelgenerator.cpp

https://invent.kde.org/plasma/plasma-desktop/-/commit/9a6336387a42af3639d85a26b65b3337dda3e360
Comment 12 Nate Graham 2025-01-23 22:59:42 UTC
Git commit 985180895292b612c2e96d8c17e7fcf54b698a84 by Nate Graham.
Committed on 23/01/2025 at 22:18.
Pushed by ngraham into branch 'Plasma/6.3'.

applets/folder: Don't use DesktopSchemeHelper::getFileUrl to get title

It isn't needed since we don't directly display it to the user; instead
we poke and prod it in various ways and then return the processed
string. This means we need the original URL, not a modified version of
it, which makes KFilePlacesModel::closestItem() return the wrong thing.

KFilePlacesModel::closestItem() isn't doing anything technically
incorrect here; it's our problem for giving it malformed data.

This fixes the Folder View widget having the wrong title when showing
the contents of desktop:/, as it does by default.
FIXED-IN: 6.3.0


(cherry picked from commit 9a6336387a42af3639d85a26b65b3337dda3e360)

Co-authored-by: Nate Graham <nate@kde.org>

M  +1    -1    containments/desktop/plugins/folder/labelgenerator.cpp

https://invent.kde.org/plasma/plasma-desktop/-/commit/985180895292b612c2e96d8c17e7fcf54b698a84