Bug 476995

Summary: The Folders pane only show subdirs one level deep
Product: [Applications] gwenview Reporter: Eugene Shalygin <eugene.shalygin+bugzilla.kde>
Component: generalAssignee: Gwenview Bugs <gwenview-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: idontfeelcomfygivingyoumyemail, jprofesorek, karsten.elfenbein, kdudka, malcolm.white3
Priority: NOR    
Version First Reported In: 23.08.3   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Eugene Shalygin 2023-11-14 15:20:33 UTC
The folders pane only show the root ones and one level deep. 

STEPS TO REPRODUCE
1.  Open any image in a deep sub-directory.
2.  Open the "Folders" pane.

OBSERVED RESULT
There is no synchronization between the currently displayed image and the "Folders" pane. Expanding folders there does not work. 

SOFTWARE/OS VERSIONS
Operating System: Gentoo Linux 2.14
KDE Plasma Version: 5.27.9
KDE Frameworks Version: 5.112.0
Qt Version: 5.15.11
Kernel Version: 6.6.1-gentoo (64-bit)
Graphics Platform: Wayland
Comment 1 Karsten 2023-12-21 15:35:54 UTC
I also get this issue on Arch Linux with
Gwenview 23.08.4
KDE Framework 5.113.0
Qt 5.15.11
Window system xcb
Comment 2 Malcolm White 2023-12-27 12:38:44 UTC
This is also true for Gwenview 28.08.3 and has actually been the case for months.
Operating System: openSUSE Tumbleweed 20231225
KDE Plasma Version: 5.27.10
KDE Frameworks Version: 5.113.0
Qt Version: 5.15.11
Kernel Version: 6.6.6-1-default (64-bit)
Graphics Platform: X11
Processors: 2 × Intel® Celeron® CPU G540 @ 2.50GHz
Memory: 3.7 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 2000
Manufacturer: Gigabyte Technology Co., Ltd.
Comment 3 Blazius 2024-01-21 02:08:06 UTC
Also confirming that I have encountered this bug for months (since at least August 2023).

Gwenview Version: 23.08.4
The xcb windowing system

OS: Arch Linux 
KDE Plasma Version: 5.27.10
KDE Frameworks Version: 5.114.0
Qt Version: 5.15.12
Kernel Version: 6.7.0-arch3-1 (64-bit)
Graphics Platform: X11
Processors: 16 × AMD Ryzen 7 5800X 8-Core Processor
Memory: 31.2 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2
Manufacturer: Gigabyte Technology Co., Ltd.
Product Name: B550M DS3H

This might be relevant, it is printed on console when trying for the first time to expand a node in the Folders tree view:

org.kde.kdegraphics.gwenview.app: Found no root index for QUrl("file:///home/blazius")
Comment 4 Jan K 2024-01-22 19:24:09 UTC
I have the same problem, also on Gentoo with its current stable versions of qt5/plasma/kde frameworks etc.

It seems that the `Gwenview::PlaceTreeModel` from lib/placetreemodel.cpp malfunctions. The file has not been changed for two years, so my guess is that recent changes in KFilePlacesModel (KIO) broke gwenview.

As far as my debugger claims, `Gwenview::PlaceTreeModel::canFetchMore` always returns `false` when I try to expand a folder.
So far I flinched from further debugging once I saw I'd have to rebuild qt & KDE libs with debugging symbols. I might dig into it with some pointers…



Also, I can't tell if this is related or not, but it seems that in vicinity of the class responsible for the folders tab a test case fails.
When I try `make test` I get:
===========================================================
make test
Running tests...
Test project /tmp/gwenview/build
(…)
      Start  5: placetreemodeltest
 5/14 Test  #5: placetreemodeltest ...............***Failed    1.16 sec```
========================================================
********* Start testing of PlaceTreeModelTest *********
Config: Using QtTest library 5.15.11, Qt 5.15.11 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 13.2.1 20230826), gentoo 2.14
PASS   : PlaceTreeModelTest::initTestCase()
QWARN  : PlaceTreeModelTest::testListPlaces() kf.kio.core: Malformed JSON protocol file for protocol: "trash" , number of the ExtraNames fields should match the number of ExtraTypes fields
QWARN  : PlaceTreeModelTest::testListPlaces() kf.kio.core: Malformed JSON protocol file for protocol: "trash" , number of the ExtraNames fields should match the number of ExtraTypes fields
FAIL!  : PlaceTreeModelTest::testListPlaces() Compared values are not the same
   Actual   (model.rowCount()): 11
   Expected (8)               : 8
   Loc: [/tmp/gwenview/tests/auto/placetreemodeltest.cpp(127)]
QWARN  : PlaceTreeModelTest::testListUrl1() kf.jobwidgets: Cannot register a job with KUiServerV2JobTracker without QGuiApplication::desktopFileName
QWARN  : PlaceTreeModelTest::testListUrl1() kf.kio.core: Malformed JSON protocol file for protocol: "trash" , number of the ExtraNames fields should match the number of ExtraTypes fields
QWARN  : PlaceTreeModelTest::testListUrl1() org.kde.kdegraphics.gwenview.lib: Unresolved mime type  "image/qoi"
QWARN  : PlaceTreeModelTest::testListUrl1() org.kde.kdegraphics.gwenview.lib: Unresolved mime type  "image/x-mng"
QWARN  : PlaceTreeModelTest::testListUrl1() org.kde.kdegraphics.gwenview.lib: Unresolved raw mime type  "image/x-samsung-srw"
PASS   : PlaceTreeModelTest::testListUrl1()
PASS   : PlaceTreeModelTest::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted, 1066ms
********* Finished testing of PlaceTreeModelTest *********
========================================================

This might be a red herring,  but it still raises my eyebrows that '/' is being added twice, for once I added a loop to print the model, I got:
========================================================
    for(int i = 0 ; i < 11; ++i)
        qDebug("URL for index %d is: %s", i, model.urlForIndex(model.index(i, 0)).path().toLocal8Bit().data());
========================================================
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 0 is: /tmp/placetreemodeltest-vstthm/url1
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 1 is: /tmp/placetreemodeltest-vstthm/url2
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 2 is: /home/jasiu
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 3 is: /home/jasiu/Desktop
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 4 is: /home/jasiu/Documents
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 5 is: /home/jasiu/Downloads
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 6 is: /home/jasiu/Pictures
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 7 is: /
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 8 is: /
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 9 is: /files
QDEBUG : PlaceTreeModelTest::testListPlaces() URL for index 10 is: /locations
========================================================
Comment 5 Jan K 2024-02-04 15:02:50 UTC
So far I failed to comprehend the relations of PlaceTreeModel, SortedDirModel, KFilePlacesModel, etc., but it turns out that dumb hacking the 'canFetchMore' to always return true makes gwenview usable again - one can browse the directory tree, and it's again in sync with the main view.
By no means this solves the issue, for it renders all directories as having subdirectories. (Upon expanding an empty directory, nothing happens apart from displaying 'v' in place of '>' on to the left of the directory name.)
I regard this to be a **very** dirty workaround for time being.

===========================================================
--- a/lib/placetreemodel.cpp    2024-02-04 15:26:58.085270323 +0100
--- b/lib/placetreemodel.cpp    2024-02-04 15:26:58.085270323 +0100
@@ -273,8 +273,8 @@
         // Special case to avoid calling openUrl on all places at startup
         return true;
     }
-    const QModelIndex dirIndex = d->dirIndexForNode(node, parent);
-    return node.model->canFetchMore(dirIndex);
+    // const QModelIndex dirIndex = d->dirIndexForNode(node, parent);
+    return true; // node.model->canFetchMore(dirIndex);
 }
 
 void PlaceTreeModel::fetchMore(const QModelIndex &parent)
===========================================================
Comment 6 Kamil Dudka 2024-03-05 20:59:03 UTC
The last update of my Gentoo Linux system made the bug disappear.  Surprisingly, it was not an update of gwenview what fixed the bug.  It must have been the update of KDE Frameworks to 5.115.0.