Display thumbnails of recent files in the overlay mode by using GnomeThumbnailFactory to get them. Fall back to the system icon for the file type provided by GtkRecentInfo when a thumbnail is not available.
svn path=/trunk/; revision=143
This commit is contained in:
@ -10,6 +10,7 @@ include Makefile-tray.am
|
||||
|
||||
gnome_shell_cflags = \
|
||||
$(MUTTER_PLUGIN_CFLAGS) \
|
||||
$(LIBGNOMEUI_CFLAGS) \
|
||||
-Itray \
|
||||
-DGETTEXT_PACKAGE=gnome-shell \
|
||||
-DGNOME_SHELL_DATADIR=\"$(pkgdatadir)\" \
|
||||
@ -65,6 +66,7 @@ shell-marshal.c: Makefile shell-marshal.list
|
||||
libgnome_shell_la_LDFLAGS = -avoid-version -module
|
||||
libgnome_shell_la_LIBADD = \
|
||||
$(MUTTER_PLUGIN_LIBS) \
|
||||
$(LIBGNOMEUI_LIBS) \
|
||||
libbig-1.0.la \
|
||||
libtidy-1.0.la \
|
||||
libtray.la
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <libgnomeui-2.0/libgnomeui/gnome-thumbnail.h>
|
||||
|
||||
struct _ShellGlobal {
|
||||
GObject parent;
|
||||
@ -240,6 +242,57 @@ shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture,
|
||||
0, NULL);
|
||||
}
|
||||
|
||||
static GnomeThumbnailFactory *thumbnail_factory;
|
||||
|
||||
/**
|
||||
* shell_get_thumbnail_for_recent_info:
|
||||
*
|
||||
* @recent_info: #GtkRecentInfo for which to return a thumbnail
|
||||
*
|
||||
* Return value: #GdkPixbuf containing a thumbnail for the file described by #GtkRecentInfo
|
||||
* if the thumbnail exists or can be generated, %NULL otherwise
|
||||
*/
|
||||
GdkPixbuf *
|
||||
shell_get_thumbnail_for_recent_info(GtkRecentInfo *recent_info)
|
||||
{
|
||||
char *existing_thumbnail;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
const gchar *uri = gtk_recent_info_get_uri (recent_info);
|
||||
time_t mtime = gtk_recent_info_get_modified (recent_info);
|
||||
const gchar *mime_type = gtk_recent_info_get_mime_type (recent_info);
|
||||
GError *error = NULL;
|
||||
|
||||
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_can_thumbnail (thumbnail_factory, uri, mime_type, mtime))
|
||||
{
|
||||
pixbuf = gnome_thumbnail_factory_generate_thumbnail (thumbnail_factory, uri, mime_type);
|
||||
if (pixbuf == NULL)
|
||||
{
|
||||
g_warning ("Could not generate thumbnail for %s", uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_global_get:
|
||||
*
|
||||
@ -402,4 +455,4 @@ shell_global_reexec_self (ShellGlobal *global)
|
||||
execvp (arr->pdata[0], (char**)arr->pdata);
|
||||
g_warning ("failed to reexec: %s", g_strerror (errno));
|
||||
g_ptr_array_free (arr, TRUE);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <clutter/clutter.h>
|
||||
#include <glib-object.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -30,9 +31,10 @@ struct _ShellGlobalClass
|
||||
|
||||
GType shell_global_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean
|
||||
shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture,
|
||||
GdkPixbuf *pixbuf);
|
||||
gboolean shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture,
|
||||
GdkPixbuf *pixbuf);
|
||||
|
||||
GdkPixbuf *shell_get_thumbnail_for_recent_info(GtkRecentInfo *recent_info);
|
||||
|
||||
ShellGlobal *shell_global_get (void);
|
||||
|
||||
|
Reference in New Issue
Block a user