Bug 393015 - KIO Thumb::URI not following freedesktop thumbnail specifications, leading to incompatibilities with other DEs
Summary: KIO Thumb::URI not following freedesktop thumbnail specifications, leading to...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.44.0
Platform: Kubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords: junior-jobs
: 105332 111801 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-04-11 17:33 UTC by Glut
Modified: 2018-06-29 21:14 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Glut 2018-04-11 17:33:00 UTC
## Short Description

KIO::Previewjob does not follow the URI RFC2396 convention, as stated in the Thumbnail Managing Standard, leading to incompatibilities with thumbnails generated by other desktop environments like GNOME. This issue usually manifests itself when the path to the corresponding files contains spaces.


## Long Description

While trying out various thumbnail caching scripts (https://askubuntu.com/questions/199110) I noticed that the generated thumbnails would not be recognized by Dolphin if the corresponding file paths contained spaces. 

Investigating this further I discovered two main differences between the thumbnails generated by the aforementioned script (based on GNOME's ThumbnailFactory) and the ones generated in Dolphin (based on KIO::Previewjob):

- different MD5 hashes in their file names
- different Thumb::URI PNG metadata values

Here is an example. The path to the file in question is "/tmp/sample with spaces.pdf":

--- GNOME thumbnail ---

$ exiftool 7ad414e904540f83e5bf3bc39cbd1537.png 
ExifTool Version Number         : 10.80                                                      
File Name                       : 7ad414e904540f83e5bf3bc39cbd1537.png                       
Directory                       : .                                                          
File Size                       : 18 kB                                                      
File Modification Date/Time     : 2018:04:11 18:49:22+02:00                                  
File Access Date/Time           : 2018:04:11 18:49:22+02:00                                  
File Inode Change Date/Time     : 2018:04:11 18:49:22+02:00                                  
File Permissions                : rw-------                                                  
File Type                       : PNG                                                        
File Type Extension             : png                                                        
MIME Type                       : image/png                                                  
Image Width                     : 91                                                         
Image Height                    : 128
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Significant Bits                : 8 8 8 8
Thumb URI                       : file:///tmp/sample%20with%20spaces.pdf
Thumb M Time                    : 1438775293
Software                        : GNOME::ThumbnailFactory
Image Size                      : 91x128
Megapixels                      : 0.012


--- KDE thumbnail ---

$ exiftool 838263a8aae8a22b253be54cfd852a2f.png 
ExifTool Version Number         : 10.80
File Name                       : 838263a8aae8a22b253be54cfd852a2f.png
Directory                       : .
File Size                       : 18 kB
File Modification Date/Time     : 2018:04:11 18:54:21+02:00
File Access Date/Time           : 2018:04:11 18:54:22+02:00
File Inode Change Date/Time     : 2018:04:11 18:54:21+02:00
File Permissions                : rw-------
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 91
Image Height                    : 128
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Pixels Per Unit X               : 3780
Pixels Per Unit Y               : 3780
Pixel Units                     : meters
Software                        : KDE Thumbnail Generator PostScript-, PDF- und DVI-Dateien
Thumb M Time                    : 1438775293
Thumb Mimetype                  : application/pdf
Thumb Size                      : 50523375
Thumb URI                       : file:///tmp/sample with spaces.pdf
Image Size                      : 91x128
Megapixels                      : 0.012

Notice the different MD5 hashes and Thumb::URI metadata values.


The thumbnails generated by GNOME'S ThumbnailFactory seem to follow the URI RFC2396 convention which requires spaces to be escaped in URIs. This is the convention supplied in the Thumbnail Management Standard (https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html).


Looking through the code for KIO::Previewjob (https://api.kde.org/frameworks/kio/html/previewjob_8cpp_source.html) it seems like the URI is generated by KFileitem::mostLocalUrl (https://api.kde.org/frameworks/kio/html/classKFileItem.html#a8f9e259b8a63b8f2306dd0be6304a7a1). Not sure if changes to this part of the code are what at cause here, but I thought it could be a good starting point for someone to investigate who's more familiar with KDE and Qt.

----

This might seem like a minor issue, but it's really hampering using non-KDE apps on my desktop, as the thumbnails I can see in Dolphin either don't work in these apps (e.g. Synapse), or need to be generated again as duplicates with different hashes.

Thanks a lot for giving this a read.


## Additional information

Platform: Kubuntu 18.04 development branch, updates as of 2017-04-11

(please let me know if there is any additional information I can provide)
Comment 1 Glut 2018-04-11 17:36:22 UTC
Sorry, the Platform information meant to read: Kubuntu 18.04 development branch, updated as of 2018-04-11
Comment 2 Nate Graham 2018-04-11 21:38:39 UTC
Looks like we just need to not percent-encode the paths?
Comment 3 David Edmundson 2018-04-11 23:28:28 UTC
I wish all bug reports were that detailed. 

If you can  test that would be great.
https://phabricator.kde.org/D12133
Comment 4 Glut 2018-04-12 21:42:01 UTC
@Nate, David:

Thank you for the lightning-fast response, guys! Glad I could do my part in reporting this :). 

I don't have the required dev environment set up to compile and test this from source, but I'm looking forward to giving the fix a try once it lands in a package.
Comment 5 David Edmundson 2018-04-13 00:25:01 UTC
Git commit 371e523f5d7ee0e37934135db6499eff3b976162 by David Edmundson.
Committed on 12/04/2018 at 20:35.
Pushed by davidedmundson into branch 'master'.

Correctly encode URL of thumbnails

Summary:
As per the amazingly detailed bug report, the spec says URLs should be
percent encoded. The main knock-on effect is we get a different hash
value for our preview file and we duplicate thumbnails if a user uses a
GNOME app.

Test Plan:
Logged out and back in
Copied jpeg to a file with spaces
opened dolphin
Found relevant cache file in ~/.cache/thumbnails/normal based on timestamp
exiftool showed the correct URI.

Thumb URI                       : file:///tmp/with%20spaces.jpg

I assume the hash is now "correct" but I don't have a way to check

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: ngraham, #frameworks

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D12133

M  +4    -4    src/widgets/previewjob.cpp

https://commits.kde.org/kio/371e523f5d7ee0e37934135db6499eff3b976162
Comment 6 Nate Graham 2018-04-13 21:29:38 UTC
*** Bug 105332 has been marked as a duplicate of this bug. ***
Comment 7 Nate Graham 2018-06-29 21:14:57 UTC
*** Bug 111801 has been marked as a duplicate of this bug. ***