Bug 337815

Summary: If preview is enabled and sorting is disabled new folders/files don't have correct icons
Product: [Plasma] plasmashell Reporter: Bhushan Shah <bhush94>
Component: FolderAssignee: Eike Hein <hein>
Status: RESOLVED FIXED    
Severity: normal CC: faure
Priority: NOR    
Version: master   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: problem
video of problem
video

Description Bhushan Shah 2014-07-26 14:30:28 UTC
Created attachment 87964 [details]
problem

This is regression after recent changes. see screenshot.. After selecting folder or making changes to folder corrects it
Comment 1 Eike Hein 2014-07-27 13:14:32 UTC
Can't reproduce, do you have any more clues?
Comment 2 Bhushan Shah 2014-07-27 13:17:07 UTC
Umm, I can reliably reproduce that.. folder is selected as /home/bshah and all other things are default.. when i login to session it don't have correct icons but corrects itself after I either select items or click on items..
Comment 3 Eike Hein 2014-07-27 13:18:52 UTC
Can you dump your Folder config here please?
Comment 4 Eike Hein 2014-07-27 13:21:15 UTC
Also, do you see a pattern in the wrong icons? Is it always the same icons (both in terms of "the same items have the wrong icons" and "the wrong icons are the same pictures")? Are the wrong icons icons that should be used by other items, i.e. are the icons swapped between items?

I can't really see why this would happen (there haven't really been any relevant changes), so every clue is needed.
Comment 5 Bhushan Shah 2014-07-27 13:23:27 UTC
[Containments][13]
activityId=12188ba2-bfd2-43d1-be08-7a6cf2d8e70c
formfactor=0
immutability=1
lastScreen=0
location=0
plugin=org.kde.plasma.folder
wallpaperplugin=org.kde.image

[Containments][13][Applets][16][Configuration][General]
showSecondHand=true

[Containments][13][ConfigDialog]
DialogHeight=648
DialogWidth=720

[Containments][13][General]
ToolBoxButtonState=topright
ToolBoxButtonX=1338
iconSize=3
positions=2,11,file:///home/bshah/plasma-workspace-git,1,4,file:///home/bshah/Breeze.colors,1,3,file:///home/bshah/2014-07-26-195749_381x140_scrot.png,1,2,file:///home/bshah/Music,1,1,file:///home/bshah/irclogs,0,3,file:///home/bshah/Downloads,0,2,file:///home/bshah/aur,0,1,file:///home/bshah/Desktop,0,0,file:///home/bshah/core.5281,0,6,file:///home/bshah/src,0,5,file:///home/bshah/plasma-desktop-git,0,4,file:///home/bshah/testu.qml,1,0
sortMode=0
url=file:///home/bshah

[Containments][13][Wallpaper][General]
height=768
width=1366

[Containments][7][Wallpaper][General]
SlidePaths=/usr/share/wallpapers/

This is config part, and pattern I see is wrong folder icons only.. files have correct icons.
Comment 6 Eike Hein 2014-07-27 13:31:52 UTC
> This is config part, and pattern I see is wrong folder icons only.. files have correct icons.

- Is it always the same folders?

- Is it always the same icons (pictures)?

- Are the icons related to other items? (I.e. are they using icons that are also used by files in the dir.)

- Can you take a video of it correcting itself when you interact with it? So I can see what might be called in KDirModel.

- Does it still happen when you disable previews?
Comment 7 Eike Hein 2014-07-27 13:36:32 UTC
One more:

- Does it still happen when you set the view to sorted again (e.g. sort by Name) and lose custom positions?

(Please test toggling previews first, before this, the sequence might be important for reproducing.)
Comment 8 Bhushan Shah 2014-07-27 13:38:07 UTC
(In reply to Eike Hein from comment #6)
> - Is it always the same folders?

no, this happens for the all folders that are in the home.. even this happens for newly created folders.

> - Is it always the same icons (pictures)?

?? you mean wrong icons..? If, yes.. they are always same..

> - Are the icons related to other items? (I.e. are they using icons that are
> also used by files in the dir.)

No

> - Can you take a video of it correcting itself when you interact with it? So
> I can see what might be called in KDirModel.

Sure

> - Does it still happen when you disable previews?

Have not tried it.. but can try.
Comment 9 Bhushan Shah 2014-07-27 13:39:36 UTC
Also this happens only when you login to session, restarting plasmashell is not enough..
Comment 10 Bhushan Shah 2014-07-27 13:41:53 UTC
(In reply to Eike Hein from comment #7)
> One more:
> 
> - Does it still happen when you set the view to sorted again (e.g. sort by
> Name) and lose custom positions?
> 
> (Please test toggling previews first, before this, the sequence might be
> important for reproducing.)

Alright, toggling preview not really helped but sorting view helped. if they are unsorted I can reproduce bug.
Comment 11 Eike Hein 2014-07-27 13:42:54 UTC
> no, this happens for the all folders that are in the home.. even this happens for newly created folders.

You mean when you create a new folder in a terminal with "mkdir foo" after login it comes up with the wrong icon?

If it happens for all folders, why does "aur" have a folder icon in your screenshot? Is that not the correct icon?


> ?? you mean wrong icons..? If, yes.. they are always same..

Yes, I wanted to know if it is always the same picture (the page with the four little tetris blocks) or if it varies.
Comment 12 Bhushan Shah 2014-07-27 13:45:07 UTC
(In reply to Eike Hein from comment #11)
> > no, this happens for the all folders that are in the home.. even this happens for newly created folders.
> 
> You mean when you create a new folder in a terminal with "mkdir foo" after
> login it comes up with the wrong icon?
> 
> If it happens for all folders, why does "aur" have a folder icon in your
> screenshot? Is that not the correct icon?

It is correct icon but I corrected it by selecting it.. (interacting with it)

a video will be really helpful here, wait a moment.

> 
> 
> > ?? you mean wrong icons..? If, yes.. they are always same..
> 
> Yes, I wanted to know if it is always the same picture (the page with the
> four little tetris blocks) or if it varies.
Comment 13 Eike Hein 2014-07-27 13:49:47 UTC
If you change folder/plugin/foldermodel.cpp from:

  dirLister->setDelayedMimeTypes(true);

to

  dirLister->setDelayedMimeTypes(false);

does it fix it?

This wouldn't be an acceptable solution, but it would confirm my current theory of there being a race condition causing Positioner to miss and relay a dataChanged() replacing the icon as MIME types are resolved.
Comment 14 Eike Hein 2014-07-27 13:50:16 UTC
*miss and not relay
Comment 15 Bhushan Shah 2014-07-27 13:55:12 UTC
Created attachment 87982 [details]
video of problem

look video, also this shows pixel art I am having.. :(
Comment 16 Bhushan Shah 2014-07-27 14:09:16 UTC
(In reply to Eike Hein from comment #13)
> does it fix it?
yup, seems to fix..
Comment 17 Eike Hein 2014-07-27 14:11:03 UTC
Alright, thanks ... this will be tricky to work on without being able to reproduce, but at least we now have an idea what happens; I'll give it a try next week.
Comment 18 Nicolás Alvarez 2014-07-27 14:11:15 UTC
The content of attachment 87982 [details] has been deleted for the following reason:

sound enabled
Comment 19 Bhushan Shah 2014-07-27 14:14:25 UTC
(In reply to Eike Hein from comment #17)
> Alright, thanks ... this will be tricky to work on without being able to
> reproduce, but at least we now have an idea what happens; I'll give it a try
> next week.

any idea of pixel art I am having? :(
Comment 20 Eike Hein 2014-07-27 14:16:14 UTC
Not really ... I'd blame the driver though since Folder doesn't really do anything special there (the only "special" part  with custom OpenGL code is the DND pixmap stuff).
Comment 21 Eike Hein 2014-07-30 01:13:36 UTC
Please re-test current master, there's a good chance it's fixed now.
Comment 22 Bhushan Shah 2014-07-30 05:25:35 UTC
Looks like fixed. Thank you!

I guess this commit fixed this, http://commits.kde.org/plasma-desktop/79ab391618c5393941afbcb8a5bc87952701fd28
Comment 23 Bhushan Shah 2014-07-30 05:37:52 UTC
Alright, sorry but let me reopen this, this issue is fixed to some level. If I create new directory or file I don
t get correct icon and get tetris icon instead.
Comment 24 Eike Hein 2014-07-30 17:12:48 UTC
Can you give me super-detailed steps?
Comment 25 Bhushan Shah 2014-07-30 17:15:11 UTC
Alright,

1) Switch to folder
2) Set url to home dir
3) Move some icons so that they are in unsorted mode
4) From command line create new folder
--> mkdir foo
5) newly created dir does not have correct folder icon but tetris icon
Comment 26 Bhushan Shah 2014-07-30 17:24:48 UTC
Created attachment 88037 [details]
video

 ofcourse not a major problem. I can live with this all day but here is video to explain things..
Comment 27 Eike Hein 2014-07-30 17:47:52 UTC
Sure it's a major problem :)

I'll be investigating this over night - I have some concern I might not be able to reproduce it because my SSD is too fast. Will you be online tomorrow morning (European time) like today? Then I can maybe give you a patch to produce debug output for me.
Comment 28 Bhushan Shah 2014-07-30 17:49:54 UTC
I'll be online in early morning tomorrow yes..
Comment 29 Eike Hein 2014-07-31 02:34:35 UTC
So from debugging with Bhushan, it looks like this remaining issue is caused by KDirModel not emitting dataChanged() when it updates the icon.

He's getting a rowsAboutToBeInserted+rowsInserted signal pair for the new folder, but it initially has the "tetris" icon, and when KDirModel figures out that it's a folder it doesn't emit dataChanged() for the icon change.

This might be down to the interaction between KDirModel and KFilePreviewGenerator, because Bhushan reports that the problem disappears when he disables preview thumbnails.

Meanwhile I still can't reproduce this locally -- I get the insert, too, but it already has the icon by that time. Most likely because my SSD is faster than Bhushan's laptop HDD.

I'm going to CC dfaure here in the hopes that he has an existing familiarity with the problem or so.
Comment 30 Eike Hein 2014-07-31 02:59:39 UTC
I've been able to reproduce it now - turns out it's possible here on file:// urls, but not on desktop:// - and am hunting the bug through KFilePreviewGenerator.

When previews are off it successfully runs the MIME type resolve machinery and ends up calling setData() on the dir model so we get a dataChanged(), but with previews on dispatchIconUpdateQueue() gets called before any previews are ready, and by the time the preview is ready no dispatch happens anymore.
Comment 31 Eike Hein 2014-07-31 06:03:05 UTC
Proposed fix at https://git.reviewboard.kde.org/r/119551/
Comment 32 Bhushan Shah 2014-07-31 06:37:53 UTC
So I just looked around review request, can not test at the moment but any reason why it works for desktop:// urls and not file:// urls? do desktop kioslave have something special then file kioslave? so it works in it?
Comment 33 Eike Hein 2014-07-31 06:45:20 UTC
I'm guessing the desktop:// kioslave somehow causes the MIME type to be already determined by the time KDirModel emits the rowsInserted(), haven't looked at its code though.
Comment 34 Bhushan Shah 2014-07-31 07:03:07 UTC
Doesn't it make sense to fix file kioslave (if possible)
Comment 35 Eike Hein 2014-07-31 07:16:47 UTC
No, there's nothing wrong with the file kioslave. It's a design bug in KFilePreviewGenerator. As the review request explains, KDirLister has a "don't determine MIME types unless asked" option, which Folder uses for speed reasons*. KFilePreviewGenerator is in charge of asking and doing model updates, but forgets doing the latter in a specific set of circumstances, which my patch corrects.

As a proof of the principle, you can do the following: In FolderModel::setViewAdapter, disable the construction of the new KFilePreviewGenerator instance. You'll notice then that folders will never get their correct icons, because their MIME type is never asked for. If OTOH you change the setDelayedMimeTypes(true) call to false, it will start working.

In the case of the desktop:// kioslave, for unknown reasons the MIME type is already known by the time the items are inserted into the model. Probably because the kioslave code calls something that causes it to be determined -- which technically defeats the purpose of setDelayedMimeTypes(true), though it doesn't really matter much in case of the desktop.

* = The reason it's a speed optimization is because KFilePreviewGenerator is capable of taking into account which parts of the view are currently scrolled into view and can prioritize preview generation / MIME type resolving based on that.
Comment 36 Eike Hein 2014-07-31 08:06:02 UTC
Git commit 561a812dad85d052ad1181129099ae22549f5603 by Eike Hein.
Committed on 31/07/2014 at 08:04.
Pushed by hein into branch 'master'.

Unsuccessful preview jobs still resolve the MIME type; make the model announce the DecorationRole change.

REVIEW:119551
Reviewed-by: David Faure

M  +16   -9    src/filewidgets/kfilepreviewgenerator.cpp

http://commits.kde.org/kio/561a812dad85d052ad1181129099ae22549f5603