Bug 477607

Summary: Folder tree view breaks if multiple nested subfolders are closed and opened
Product: [Applications] dolphin Reporter: Akseli Lahtinen <akselmo>
Component: view-engine: details modeAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kfm-devel, mothlight, nate
Priority: NOR Keywords: qt6
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Nested subfolders showing wrong
After rebuild

Description Akseli Lahtinen 2023-11-27 11:31:20 UTC
Created attachment 163537 [details]
Nested subfolders showing wrong

SUMMARY

See image. Every folder would have folders from 2 to 10 in them. If all are opened, then base folder is closed and opened, the last two folders dont expand properly.


STEPS TO REPRODUCE
1. Create a folder called test
2. Create folder inside test called base
3. In base folder, run following commands: mkdir -p 1/2/3/4/5/6/7/8/9/10, mkdir -p 2/2/3/4/5/6/7/8/9/10, mkdir -p 3/2/3/4/5/6/7/8/9/10
4. Open detail view in dolphin so that you're inside test folder and see only base folder.
5. Expand *all* folders
6. Toggle the arrow on base folder off and on

OBSERVED RESULT
See attachment

EXPECTED RESULT
The treeview would build correctly

SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 39
KDE Plasma Version: 5.81.80
KDE Frameworks Version: 5.245.0
Qt Version: 6.6.0
Kernel Version: 6.5.12-300.fc39.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 3600 6-Core Processor
Memory: 15.5 GiB of RAM
Graphics Processor: AMD Radeon RX 6600
Qt Version: 

ADDITIONAL INFORMATION

Admittedly this is quite niche issue, but it may cause other issues, especially since sometimes the nested arrow can appear next to a file instead of a folder.
Comment 1 Akseli Lahtinen 2023-11-27 11:33:07 UTC
If one toggles base folder again, it shrinks even more.
Comment 2 Akseli Lahtinen 2023-11-27 11:36:22 UTC
Dolphin version: dolphin 24.01.80
Comment 3 Akseli Lahtinen 2023-11-27 13:42:25 UTC
Seems the index for the folders gets reset and they get opened in wrong order.
Comment 4 Akseli Lahtinen 2023-11-28 09:06:08 UTC
Created attachment 163560 [details]
After rebuild

After rebuilding it now closes the 1 and 2 folders when base folder is toggled, but keeps 3 expanded. Only thing that changed was translation files.

This is better behavior, at least. Optimally all folders would expand like previously.
Comment 5 Nate Graham 2023-11-28 21:33:27 UTC
Hmm, I'm not able to see as issue with those steps.
Comment 6 Akseli Lahtinen 2023-12-04 12:25:43 UTC
I can still reproduce the issue, but it happens very randomly. Same steps as above should work though.
Comment 7 Akseli Lahtinen 2023-12-07 11:08:14 UTC
This bug happens only if your dolphinrc has anything in [PreviewSettings]

For example:

[PreviewSettings]
Plugins=audiothumbnail
Comment 8 Bug Janitor Service 2023-12-07 11:13:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/672
Comment 9 Akseli Lahtinen 2023-12-08 10:59:22 UTC
Git commit b1f9c2e5c90548f391477fa17889ff8d1abf8f53 by Akseli Lahtinen.
Committed on 08/12/2023 at 11:59.
Pushed by akselmo into branch 'master'.

Do not reset expandability when loading previews

Fixes a weird bug with the treeview if one has
```
[PreviewSettings]
Plugins=audiothumbnail
```
in their `dolphinrc`. It can be any PreviewSettings plugin, as long as there it at least one.

Check the bug report for more, but in short, the bug is reproducible like this:

```
create folder tree inside a test folder with 

mkdir -p 1/A/B/C/D/E/F/G/H/I
mkdir -p 2/A/B/C/D/E/F/G/H/I
mkdir -p 3/A/B/C/D/E/F/G/H/I

make sure you see the test folder, and expand it

expand folder 1, no need to expand all sub folders
expand folder 2
collapse and expand test folder
3 loses its expansion arrow

if all folders are expanded, only 3 keeps its order

if 1 and all its subfolders are expanded, then test is toggled,
folder 2 also loses its expansion arrow
```

Video of the bug:

![Screencast_20231207_112700](/uploads/4fad2a62a5a9a67760fa7faa8e3bec40/Screencast_20231207_112700.webm)

The path to the bug is: `KFileItemModelRolesUpdater::slotPreviewFailed` -> `KFileItemModelRolesUpdater::applyResolvedRoles` -> `KFileItemModelRolesUpdater::rolesData` -> `KFileItemModelRolesUpdater::startDirectorySizeCounting`. 

This causes Dolphin with preview plugins enabled trying to count the directories again, and the data gets reset even if there is something there. This then resets the `isExpandable` flag and that breaks the treeview, causing all kinds of issues, like being able to expand non-directories and makes things out of sync.

M  +0    -2    src/kitemviews/kfileitemmodelrolesupdater.cpp

https://invent.kde.org/system/dolphin/-/commit/b1f9c2e5c90548f391477fa17889ff8d1abf8f53
Comment 10 Akseli Lahtinen 2024-01-18 15:45:32 UTC
*** Bug 479240 has been marked as a duplicate of this bug. ***