After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 684026 - Improve gnome-desktop thumbnailing interface and code
Improve gnome-desktop thumbnailing interface and code
Status: RESOLVED OBSOLETE
Product: gnome-desktop
Classification: Core
Component: Thumbnail
unspecified
Other All
: Normal normal
: ---
Assigned To: Desktop Maintainers
Desktop Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-09-14 14:19 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2018-09-21 16:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
thumbnail: Clean up path generation code (7.07 KB, patch)
2012-09-14 14:19 UTC, Jasper St. Pierre (not reading bugmail)
needs-work Details | Review
thumbnail: Move thumbnail generation/saving to a few helper functions (10.55 KB, patch)
2012-09-14 14:19 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail (3.83 KB, patch)
2012-09-14 14:19 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
thumbnail: Clean up path generation code (7.10 KB, patch)
2012-09-14 22:33 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
thumbnail: Move thumbnail generation/saving to a few helper functions (10.59 KB, patch)
2012-09-14 22:33 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail (3.92 KB, patch)
2012-09-14 22:33 UTC, Jasper St. Pierre (not reading bugmail)
needs-work Details | Review
thumbnail: Clean up path generation code (7.23 KB, patch)
2014-10-21 12:17 UTC, Bastien Nocera
none Details | Review
thumbnail: Move thumbnail generation/saving to a few helper functions (11.12 KB, patch)
2014-10-21 13:07 UTC, Bastien Nocera
none Details | Review
thumbnail: Clean up path generation code (7.12 KB, patch)
2014-11-05 15:20 UTC, Bastien Nocera
committed Details | Review
thumbnail: Move thumbnail generation/saving to a few helper functions (10.91 KB, patch)
2014-11-05 15:20 UTC, Bastien Nocera
committed Details | Review
thumbnail: Fix thumbnail generation (1.16 KB, patch)
2014-11-29 03:55 UTC, Sebastian Keller
needs-work Details | Review
thumbnail: Don't fail after successfully creating the cache directory (1.00 KB, patch)
2014-12-04 23:34 UTC, Sebastian Keller
committed Details | Review
thumbnail: Include the filename in the thumbnail path (1.08 KB, patch)
2014-12-04 23:35 UTC, Sebastian Keller
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-09-14 14:19:28 UTC
This (eventually) adds a super simple method to return a thumbnail given a URI
and mtime, which is really what most people care about.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-09-14 14:19:30 UTC
Created attachment 224321 [details] [review]
thumbnail: Clean up path generation code

Put the path calculation code in one spot.
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-09-14 14:19:33 UTC
Created attachment 224322 [details] [review]
thumbnail: Move thumbnail generation/saving to a few helper functions

Another cleanup in preparation for a new "simple" thumbnail API.
Comment 3 Jasper St. Pierre (not reading bugmail) 2012-09-14 14:19:35 UTC
Created attachment 224323 [details] [review]
thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail

This is a simple method on the factory that gives you a thumbnail,
maybe from the cache, maybe not, you don't care. You just want a
thumbnail.
Comment 4 Cosimo Cecchi 2012-09-14 21:45:51 UTC
Review of attachment 224321 [details] [review]:

Looks like a great cleanup...I have a couple of minor comments below.
Also, why is there a "libgsystem" it submodule change in this patch?

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +883,3 @@
+    }
+
+

Looks like you're leaking the GChecksum

@@ -1388,3 @@
-  guint8 digest[16];
-  gsize digest_len = sizeof (digest);
-  GError *error;

Don't we still need this GError later in the function?
Comment 5 Jasper St. Pierre (not reading bugmail) 2012-09-14 22:08:02 UTC
(In reply to comment #4)
> Review of attachment 224321 [details] [review]:
> 
> Looks like a great cleanup...I have a couple of minor comments below.
> Also, why is there a "libgsystem" it submodule change in this patch?

I think I updated to the latest libgsystem by accident.

> @@ -1388,3 @@
> -  guint8 digest[16];
> -  gsize digest_len = sizeof (digest);
> -  GError *error;
> 
> Don't we still need this GError later in the function?

Nope. It was unused before.
Comment 6 Jasper St. Pierre (not reading bugmail) 2012-09-14 22:33:42 UTC
Created attachment 224368 [details] [review]
thumbnail: Clean up path generation code

Put the path calculation code in one spot.
Comment 7 Jasper St. Pierre (not reading bugmail) 2012-09-14 22:33:45 UTC
Created attachment 224369 [details] [review]
thumbnail: Move thumbnail generation/saving to a few helper functions

Another cleanup in preparation for a new "simple" thumbnail API.
Comment 8 Jasper St. Pierre (not reading bugmail) 2012-09-14 22:33:48 UTC
Created attachment 224370 [details] [review]
thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail

This is a simple method on the factory that gives you a thumbnail,
maybe from the cache, maybe not, you don't care. You just want a
thumbnail.
Comment 9 Bastien Nocera 2012-10-08 18:00:27 UTC
Review of attachment 224368 [details] [review]:

There's still libgsystem bits in this patch.

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +850,3 @@
+thumbnail_path (const char                *uri,
+                GnomeDesktopThumbnailSize  size,
+                gboolean                   is_fail)

Don't like the "is_fail" argument, could do with being 2 separate functions (even if they share the checksum generation).

@@ +865,3 @@
+  file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
+
+  /* XXX: appname is only used for failed thumbnails. Is this a mistake? */

That obviously needs investigating and fixing.
Comment 10 Bastien Nocera 2012-10-08 18:03:55 UTC
Review of attachment 224369 [details] [review]:

This patch would do with being split up.

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +1302,1 @@
+  dirname = g_path_get_dirname (path);

Leaking dirname.
Comment 11 Bastien Nocera 2012-10-08 18:06:42 UTC
Review of attachment 224370 [details] [review]:

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +1587,3 @@
+
+  /* FIXME: we cannot write anything to the thumbnal dir, apparently.
+   * What should we do here? */

Add error handling?

::: libgnome-desktop/gnome-desktop-thumbnail.h
@@ +106,3 @@
 						      int                 dest_height);
 
+char * gnome_desktop_thumbnail_factory_give_me_a_thumbnail (GnomeDesktopThumbnailFactory *factory,

Apart from being childish, that's not what the function does. It gives you a path to the thumbnail, not the thumbnail itself.
Comment 12 Jasper St. Pierre (not reading bugmail) 2012-10-08 19:12:16 UTC
(In reply to comment #9)
> Review of attachment 224368 [details] [review]:
> 
> There's still libgsystem bits in this patch.

I tried to fix this and apparently failed. Do you have any suggestions?

> ::: libgnome-desktop/gnome-desktop-thumbnail.c
> @@ +865,3 @@
> +  file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
> +
> +  /* XXX: appname is only used for failed thumbnails. Is this a mistake? */
> 
> That obviously needs investigating and fixing.

Sure, but that's orthagonal. We have to keep compatibility.
Comment 13 Jasper St. Pierre (not reading bugmail) 2012-10-08 19:13:40 UTC
(In reply to comment #11)
> Review of attachment 224370 [details] [review]:
> 
> ::: libgnome-desktop/gnome-desktop-thumbnail.c
> @@ +1587,3 @@
> +
> +  /* FIXME: we cannot write anything to the thumbnal dir, apparently.
> +   * What should we do here? */
> 
> Add error handling?

No. If we get here, this is a broken system where we can't write to XDG_CONFIG_DIR. Do we want all applications to handle broken systems by returning a GError*? I guess I can g_warning and return "".

> ::: libgnome-desktop/gnome-desktop-thumbnail.h
> @@ +106,3 @@
>                                int                 dest_height);
> 
> +char * gnome_desktop_thumbnail_factory_give_me_a_thumbnail
> (GnomeDesktopThumbnailFactory *factory,
> 
> Apart from being childish, that's not what the function does. It gives you a
> path to the thumbnail, not the thumbnail itself.

What would you like instead? The function name clearly isn't the best. Suggestions?
Comment 14 Bastien Nocera 2012-10-31 16:49:06 UTC
(In reply to comment #13)
> (In reply to comment #11)
> > Review of attachment 224370 [details] [review] [details]:
> > 
> > ::: libgnome-desktop/gnome-desktop-thumbnail.c
> > @@ +1587,3 @@
> > +
> > +  /* FIXME: we cannot write anything to the thumbnal dir, apparently.
> > +   * What should we do here? */
> > 
> > Add error handling?
> 
> No. If we get here, this is a broken system where we can't write to
> XDG_CONFIG_DIR. Do we want all applications to handle broken systems by
> returning a GError*? I guess I can g_warning and return "".

g_warning() and further error messages should be generated when the thumbnails fail to save. I doubt that an empty directory will have the desired effect.

> > ::: libgnome-desktop/gnome-desktop-thumbnail.h
> > @@ +106,3 @@
> >                                int                 dest_height);
> > 
> > +char * gnome_desktop_thumbnail_factory_give_me_a_thumbnail
> > (GnomeDesktopThumbnailFactory *factory,
> > 
> > Apart from being childish, that's not what the function does. It gives you a
> > path to the thumbnail, not the thumbnail itself.
> 
> What would you like instead? The function name clearly isn't the best.
> Suggestions?

Don't have any, but feel free to ask around, pretty much anything would be better than that in a public API.
Comment 15 Jasper St. Pierre (not reading bugmail) 2012-10-31 17:12:20 UTC
(In reply to comment #14)
> g_warning() and further error messages should be generated when the thumbnails
> fail to save. I doubt that an empty directory will have the desired effect.

I don't understand. The only possible case we'll get here is if we can't write anything to the thumbnail directory, in which case we can't give applications a path to anything. g_warning and returning "" is our best option, as far as I'm concerned.
Comment 16 Philip Withnall 2014-04-08 15:42:09 UTC
I think it would be pretty useful if gnome_desktop_thumbnail_factory_give_me_a_thumbnail() (or whatever it ends up being called) also took width and height parameters, and did the appropriate scaling internally, since most callers will probably want their thumbnails at a specific size.

Might also want to add some convenience wrappers to, e.g., take in a GFile and return a GIcon or something. Depends on your use case, I guess.

Other than that (and bearing in mind the comments from the other reviews) this looks like a nice simplification to me.
Comment 17 Bastien Nocera 2014-10-21 12:17:48 UTC
Created attachment 289025 [details] [review]
thumbnail: Clean up path generation code

Put the path calculation code in one spot.
Comment 18 Bastien Nocera 2014-10-21 13:07:54 UTC
Created attachment 289034 [details] [review]
thumbnail: Move thumbnail generation/saving to a few helper functions

Another cleanup in preparation for a new "simple" thumbnail API.
Comment 19 Bastien Nocera 2014-10-21 13:55:29 UTC
Looking at both nautilus and totem, heavy users of the thumbnailers, we usually have:
- thumbnail being provided by GIO or grilo, if available
- the usual _generate_thumbnail(), _save_thumbnail()/_create_failed_thumbnail() sequence

The current problems with the API are that there's no cancellables (bug 572961), and no builtin thread pool to queue up thumbnailing operations.

Jasper, what was the use case for gnome_desktop_thumbnail_factory_give_me_a_thumbnail()?
Was it for something not coming from GIO?
Comment 20 Debarshi Ray 2014-10-21 14:22:43 UTC
For the gnome-documents & gnome-photos use case:

Often there is no GVfs backend for the remote content that we handle. In those cases we plugin our own thumbnailer that calls out to a library (eg., grilo, libgdata, etc.) to get the thumbnail URI, that we fetch and save.

> The current problems with the API are that there's no cancellables (bug
> 572961), and no builtin thread pool to queue up thumbnailing operations.

If we are going to have an inbuilt thread pool, then I would like to have the ability to set my own sort function so that I can have local items thumbnailed before remote ones because they are likely to be faster. I can also think of fancier criteria like thumbnailing items which are currently in the view, etc..
Comment 21 Bastien Nocera 2014-10-21 14:54:21 UTC
(In reply to comment #20)
> For the gnome-documents & gnome-photos use case:
> 
> Often there is no GVfs backend for the remote content that we handle. In those
> cases we plugin our own thumbnailer that calls out to a library (eg., grilo,
> libgdata, etc.) to get the thumbnail URI, that we fetch and save.

What do you do here? Do you use the thumbnailer factory to save it, or do you save it locally for your app?

> > The current problems with the API are that there's no cancellables (bug
> > 572961), and no builtin thread pool to queue up thumbnailing operations.
> 
> If we are going to have an inbuilt thread pool, then I would like to have the
> ability to set my own sort function so that I can have local items thumbnailed
> before remote ones because they are likely to be faster. I can also think of
> fancier criteria like thumbnailing items which are currently in the view, etc..

Or you could create 2 thread pools, one for local, one for remote.
Comment 22 Debarshi Ray 2014-10-21 16:02:09 UTC
(In reply to comment #21)
> (In reply to comment #20)
> > For the gnome-documents & gnome-photos use case:
> > 
> > Often there is no GVfs backend for the remote content that we handle. In those
> > cases we plugin our own thumbnailer that calls out to a library (eg., grilo,
> > libgdata, etc.) to get the thumbnail URI, that we fetch and save.
> 
> What do you do here? Do you use the thumbnailer factory to save it, or do you
> save it locally for your app?

We "save" it to gnome_desktop_thumbnail_path_for_uri. Where is saving is done either by g_file_copy or g_output_stream_splice depending on whether there is a GVfs backend to grab the URI or the library offers an input stream for grabbing stuff (like libgdata does).

In case we failed to get a thumbnail (either the service doesn't offer them or we simply failed to get one), we can attempt to create it from the actual file when the user opens it for viewing. However, this is not implemented at the moment.

> > If we are going to have an inbuilt thread pool, then I would like to have the
> > ability to set my own sort function so that I can have local items thumbnailed
> > before remote ones because they are likely to be faster. I can also think of
> > fancier criteria like thumbnailing items which are currently in the view, etc..
> 
> Or you could create 2 thread pools, one for local, one for remote.

True.
Comment 23 Cosimo Cecchi 2014-10-21 16:36:03 UTC
Review of attachment 289025 [details] [review]:

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +1057,3 @@
+static char *
+thumbnail_failed_path (const char                *uri,
+  return file;

This parameter seems to be unused
Comment 24 Cosimo Cecchi 2014-10-21 16:56:35 UTC
Review of attachment 289034 [details] [review]:

::: libgnome-desktop/gnome-desktop-thumbnail.c
@@ +1520,3 @@
+  error = NULL;
+  if (width != NULL && height != NULL)
+    saved_ok  = gdk_pixbuf_save (pixbuf,

Any reason not to use the same "ret" variable instead of a separate "saved_ok"?
Comment 25 Jasper St. Pierre (not reading bugmail) 2014-10-21 18:44:47 UTC
(In reply to comment #19)
> Jasper, what was the use case for
> gnome_desktop_thumbnail_factory_give_me_a_thumbnail()?
> Was it for something not coming from GIO?

I honestly can't remember. It was something Cosimo and I worked on together. It might have been part of the old files search in gnome-shell.
Comment 26 Bastien Nocera 2014-11-05 15:20:27 UTC
Created attachment 290030 [details] [review]
thumbnail: Clean up path generation code

Put the path calculation code in one spot.
Comment 27 Bastien Nocera 2014-11-05 15:20:34 UTC
Created attachment 290031 [details] [review]
thumbnail: Move thumbnail generation/saving to a few helper functions

Another cleanup in preparation for a new "simple" thumbnail API.
Comment 28 Bastien Nocera 2014-11-18 18:38:26 UTC
Attachment 290030 [details] pushed as 57c18b8 - thumbnail: Clean up path generation code
Attachment 290031 [details] pushed as 97f6f77 - thumbnail: Move thumbnail generation/saving to a few helper functions
Comment 29 Sebastian Keller 2014-11-29 03:55:47 UTC
Created attachment 291762 [details] [review]
thumbnail: Fix thumbnail generation

With these patches in 3.15.2 thumbnail generation is broken and it causes thumbnailers to be spawned constantly. I've added a patch that gets it working again here.
Comment 30 Bastien Nocera 2014-12-04 23:31:09 UTC
Review of attachment 291762 [details] [review]:

As mentioned on IRC, could you please split the patch in two fixes, and explain them in the commit message.
Comment 31 Sebastian Keller 2014-12-04 23:34:42 UTC
Created attachment 292157 [details] [review]
thumbnail: Don't fail after successfully creating the  cache directory
Comment 32 Sebastian Keller 2014-12-04 23:35:14 UTC
Created attachment 292158 [details] [review]
thumbnail: Include the filename in the thumbnail path
Comment 33 Bastien Nocera 2014-12-05 09:52:03 UTC
Review of attachment 292157 [details] [review]:

Yes!
Comment 34 Bastien Nocera 2014-12-05 09:55:05 UTC
Review of attachment 292158 [details] [review]:

Looks good, but can you add a link to the pre-cleanup code in the commit log?
https://git.gnome.org/browse/gnome-desktop/tree/libgnome-desktop/gnome-desktop-thumbnail.c?id=f2d25fa7d6cdaba03679f0fc0921fc5f81bd3944#n1060
Comment 35 Bastien Nocera 2014-12-05 13:43:43 UTC
Attachment 292158 [details] pushed as ef0f02e - thumbnail: Include the filename in the thumbnail path
Comment 36 Bastien Nocera 2018-01-17 17:18:49 UTC
I've posted about a replacement API to be included lower down the stack on gtk-devel:
https://mail.gnome.org/archives/gtk-devel-list/2018-January/msg00018.html

Does this look sufficient for your uses? It's pretty much gnome_desktop_factory_give_me_a_thumbnail() but hopefully extensible.
If it's good enough, I'll likely start writing the code, and see what applications I can port.
Comment 37 GNOME Infrastructure Team 2018-09-21 16:34:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-desktop/issues/43.