Пример #1
0
/**
 * shell_get_thumbnail:
 *
 * @uri: URI of the file to thumbnail
 *
 * @mime_type: Mime-Type of the file to thumbnail
 *
 * Return value: #GdkPixbuf containing a thumbnail for file @uri
 *               if the thumbnail exists or can be generated, %NULL otherwise
 */
GdkPixbuf *
shell_get_thumbnail(const gchar *uri,
                    const gchar *mime_type)
{
    char *existing_thumbnail;
    GdkPixbuf *pixbuf = NULL;
    GError *error = NULL;
    GFile *file = NULL;
    GFileInfo *file_info = NULL;
    GTimeVal mtime_g;
    time_t mtime = 0;

    file = g_file_new_for_uri (uri);
    file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL);
    g_object_unref (file);
    if (file_info) {
        g_file_info_get_modification_time (file_info, &mtime_g);
        g_object_unref (file_info);
        mtime = (time_t) mtime_g.tv_sec;
    }

    if (thumbnail_factory == NULL)
      thumbnail_factory = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL);

    existing_thumbnail = gnome_thumbnail_factory_lookup (thumbnail_factory, uri, mtime);

    if (existing_thumbnail != NULL)
      {
        pixbuf = gdk_pixbuf_new_from_file(existing_thumbnail, &error);
        if (error != NULL) 
          {
            g_warning("Could not generate a pixbuf from file %s: %s", existing_thumbnail, error->message);
            g_clear_error (&error);
          }
      }
    else if (gnome_thumbnail_factory_has_valid_failed_thumbnail (thumbnail_factory, uri, mtime))
      return NULL;
    else if (gnome_thumbnail_factory_can_thumbnail (thumbnail_factory, uri, mime_type, mtime)) 
      {
        pixbuf = gnome_thumbnail_factory_generate_thumbnail (thumbnail_factory, uri, mime_type);
        if (pixbuf)
          {
            // we need to save the thumbnail so that we don't need to generate it again in the future
            gnome_thumbnail_factory_save_thumbnail (thumbnail_factory, pixbuf, uri, mtime);
          }          
        else 
          {
            g_warning ("Could not generate thumbnail for %s", uri);
            gnome_thumbnail_factory_create_failed_thumbnail (thumbnail_factory, uri, mtime);
          }
      }

    return pixbuf;   
}
Пример #2
0
static GnomeThumbnailFactory *
get_thumbnail_factory (void)
{
	static GnomeThumbnailFactory *thumbnail_factory = NULL;

	if (thumbnail_factory == NULL) {
		thumbnail_factory = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL);
	}

	return thumbnail_factory;
}