don't reset the mime-type info when we can't load a thumbnail.
2008-03-24 Sven Neumann <sven@gimp.org> * libgimpthumb/gimpthumbnail.c: don't reset the mime-type info when we can't load a thumbnail. * app/core/gimpimagefile.c (gimp_imagefile_get_new_pixbuf): don't set a stock-id depending on the state. * app/widgets/gimpviewrendererimagefile.[ch]: removed commented out hack that used to access semi-private API from GtkFilesystem. Instead lifted some code from GtkRecentManager that looks up icons by mime-type. svn path=/trunk/; revision=25195
This commit is contained in:

committed by
Sven Neumann

parent
8876b879d3
commit
3adca61a80
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
2008-03-24 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* libgimpthumb/gimpthumbnail.c: don't reset the mime-type info
|
||||||
|
when we can't load a thumbnail.
|
||||||
|
|
||||||
|
* app/core/gimpimagefile.c (gimp_imagefile_get_new_pixbuf): don't
|
||||||
|
set a stock-id depending on the state.
|
||||||
|
|
||||||
|
* app/widgets/gimpviewrendererimagefile.[ch]: removed commented
|
||||||
|
out hack that used to access semi-private API from GtkFilesystem.
|
||||||
|
Instead lifted some code from GtkRecentManager that looks up icons
|
||||||
|
by mime-type.
|
||||||
|
|
||||||
2008-03-24 Michael Natterer <mitch@gimp.org>
|
2008-03-24 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
Renamed folders in plug-ins/. Unfortunately it's impossible to
|
Renamed folders in plug-ins/. Unfortunately it's impossible to
|
||||||
|
@ -417,8 +417,6 @@ gimp_imagefile_name_changed (GimpObject *object)
|
|||||||
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
|
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
|
||||||
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
|
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
|
||||||
|
|
||||||
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
|
|
||||||
|
|
||||||
gimp_thumbnail_set_uri (imagefile->thumbnail, gimp_object_get_name (object));
|
gimp_thumbnail_set_uri (imagefile->thumbnail, gimp_object_get_name (object));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,39 +452,11 @@ gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
|
|||||||
gint height)
|
gint height)
|
||||||
{
|
{
|
||||||
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
||||||
GdkPixbuf *pixbuf;
|
|
||||||
const gchar *stock_id = NULL;
|
|
||||||
|
|
||||||
if (! GIMP_OBJECT (imagefile)->name)
|
if (! gimp_object_get_name (GIMP_OBJECT (imagefile)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pixbuf = gimp_imagefile_load_thumb (imagefile, width, height);
|
return gimp_imagefile_load_thumb (imagefile, width, height);
|
||||||
|
|
||||||
switch (imagefile->thumbnail->image_state)
|
|
||||||
{
|
|
||||||
case GIMP_THUMB_STATE_REMOTE:
|
|
||||||
stock_id = "gtk-network";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GIMP_THUMB_STATE_FOLDER:
|
|
||||||
stock_id = "gtk-directory";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GIMP_THUMB_STATE_SPECIAL:
|
|
||||||
stock_id = "gtk-harddisk";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GIMP_THUMB_STATE_NOT_FOUND:
|
|
||||||
stock_id = "gtk-dialog-question";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), stock_id);
|
|
||||||
|
|
||||||
return pixbuf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
|
@ -35,14 +35,12 @@
|
|||||||
#include "gimpviewrendererimagefile.h"
|
#include "gimpviewrendererimagefile.h"
|
||||||
#include "gimpviewrenderer-frame.h"
|
#include "gimpviewrenderer-frame.h"
|
||||||
|
|
||||||
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
|
||||||
#define GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED
|
|
||||||
#include <gtk/gtkfilesystem.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
static void gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
||||||
|
GtkWidget *widget);
|
||||||
|
|
||||||
static void gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
static GdkPixbuf * gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
|
||||||
GtkWidget *widget);
|
gint size);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpViewRendererImagefile, gimp_view_renderer_imagefile,
|
G_DEFINE_TYPE (GimpViewRendererImagefile, gimp_view_renderer_imagefile,
|
||||||
@ -62,9 +60,6 @@ gimp_view_renderer_imagefile_class_init (GimpViewRendererImagefileClass *klass)
|
|||||||
static void
|
static void
|
||||||
gimp_view_renderer_imagefile_init (GimpViewRendererImagefile *renderer)
|
gimp_view_renderer_imagefile_init (GimpViewRendererImagefile *renderer)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
|
||||||
renderer->file_system = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -75,30 +70,14 @@ gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
|||||||
renderer->width,
|
renderer->width,
|
||||||
renderer->height);
|
renderer->height);
|
||||||
|
|
||||||
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
if (! pixbuf)
|
||||||
if (! pixbuf &&
|
|
||||||
GIMP_VIEW_RENDERER_IMAGEFILE (renderer)->file_system)
|
|
||||||
{
|
{
|
||||||
const gchar *uri;
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (renderer->viewable);
|
||||||
|
|
||||||
uri = gimp_object_get_name (GIMP_OBJECT (renderer->viewable));
|
pixbuf = gimp_view_renderer_imagefile_get_icon (imagefile,
|
||||||
if (uri)
|
MIN (renderer->width,
|
||||||
{
|
renderer->height));
|
||||||
GtkFileSystem *file_system;
|
|
||||||
GtkFilePath *path;
|
|
||||||
|
|
||||||
file_system = GIMP_VIEW_RENDERER_IMAGEFILE (renderer)->file_system;
|
|
||||||
|
|
||||||
path = gtk_file_system_uri_to_path (file_system, uri);
|
|
||||||
|
|
||||||
pixbuf = gtk_file_system_render_icon (file_system, path, widget,
|
|
||||||
MIN (renderer->width,
|
|
||||||
renderer->height),
|
|
||||||
NULL);
|
|
||||||
gtk_file_path_free (path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_FILE_SYSTEM_ICONS */
|
|
||||||
|
|
||||||
if (pixbuf)
|
if (pixbuf)
|
||||||
{
|
{
|
||||||
@ -112,3 +91,102 @@ gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
|||||||
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
|
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The code to get an icon for a mime-type is lifted from GtkRecentManager. */
|
||||||
|
|
||||||
|
static GdkPixbuf *
|
||||||
|
get_icon_for_mime_type (const char *mime_type,
|
||||||
|
gint pixel_size)
|
||||||
|
{
|
||||||
|
GtkIconTheme *icon_theme;
|
||||||
|
const gchar *separator;
|
||||||
|
GString *icon_name;
|
||||||
|
GdkPixbuf *pixbuf;
|
||||||
|
|
||||||
|
separator = strchr (mime_type, '/');
|
||||||
|
if (! separator)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
icon_theme = gtk_icon_theme_get_default ();
|
||||||
|
|
||||||
|
/* try with the three icon name variants for MIME types */
|
||||||
|
|
||||||
|
/* canonicalize MIME type: foo/x-bar -> foo-x-bar */
|
||||||
|
icon_name = g_string_new (NULL);
|
||||||
|
g_string_append_len (icon_name, mime_type, separator - mime_type);
|
||||||
|
g_string_append_c (icon_name, '-');
|
||||||
|
g_string_append (icon_name, separator + 1);
|
||||||
|
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
|
||||||
|
pixel_size,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
g_string_free (icon_name, TRUE);
|
||||||
|
if (pixbuf)
|
||||||
|
return pixbuf;
|
||||||
|
|
||||||
|
/* canonicalize MIME type, and prepend "gnome-mime-" */
|
||||||
|
icon_name = g_string_new ("gnome-mime-");
|
||||||
|
g_string_append_len (icon_name, mime_type, separator - mime_type);
|
||||||
|
g_string_append_c (icon_name, '-');
|
||||||
|
g_string_append (icon_name, separator + 1);
|
||||||
|
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
|
||||||
|
pixel_size,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
g_string_free (icon_name, TRUE);
|
||||||
|
if (pixbuf)
|
||||||
|
return pixbuf;
|
||||||
|
|
||||||
|
/* try the MIME family icon */
|
||||||
|
icon_name = g_string_new ("gnome-mime-");
|
||||||
|
g_string_append_len (icon_name, mime_type, separator - mime_type);
|
||||||
|
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
|
||||||
|
pixel_size,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
g_string_free (icon_name, TRUE);
|
||||||
|
|
||||||
|
return pixbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GdkPixbuf *
|
||||||
|
get_icon_fallback (const gchar *icon_name,
|
||||||
|
gint size)
|
||||||
|
{
|
||||||
|
return gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon_name,
|
||||||
|
size,
|
||||||
|
GTK_ICON_LOOKUP_USE_BUILTIN,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GdkPixbuf *
|
||||||
|
gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
|
||||||
|
gint size)
|
||||||
|
{
|
||||||
|
GdkPixbuf *retval = NULL;
|
||||||
|
|
||||||
|
if (! gimp_object_get_name (GIMP_OBJECT (imagefile)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (imagefile->thumbnail->image_mimetype)
|
||||||
|
{
|
||||||
|
retval = get_icon_for_mime_type (imagefile->thumbnail->image_mimetype,
|
||||||
|
size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! retval)
|
||||||
|
{
|
||||||
|
const gchar *icon_name = GTK_STOCK_FILE;
|
||||||
|
|
||||||
|
if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_FOLDER)
|
||||||
|
icon_name = GTK_STOCK_DIRECTORY;
|
||||||
|
|
||||||
|
retval = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
||||||
|
icon_name, size,
|
||||||
|
GTK_ICON_LOOKUP_USE_BUILTIN,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
#include "gimpviewrenderer.h"
|
#include "gimpviewrenderer.h"
|
||||||
|
|
||||||
/* #define ENABLE_FILE_SYSTEM_ICONS 1 */
|
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_VIEW_RENDERER_IMAGEFILE (gimp_view_renderer_imagefile_get_type ())
|
#define GIMP_TYPE_VIEW_RENDERER_IMAGEFILE (gimp_view_renderer_imagefile_get_type ())
|
||||||
#define GIMP_VIEW_RENDERER_IMAGEFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_VIEW_RENDERER_IMAGEFILE, GimpViewRendererImagefile))
|
#define GIMP_VIEW_RENDERER_IMAGEFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_VIEW_RENDERER_IMAGEFILE, GimpViewRendererImagefile))
|
||||||
@ -41,10 +39,6 @@ typedef struct _GimpViewRendererImagefileClass GimpViewRendererImagefileClass;
|
|||||||
struct _GimpViewRendererImagefile
|
struct _GimpViewRendererImagefile
|
||||||
{
|
{
|
||||||
GimpViewRenderer parent_instance;
|
GimpViewRenderer parent_instance;
|
||||||
|
|
||||||
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
|
||||||
gpointer file_system;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpViewRendererImagefileClass
|
struct _GimpViewRendererImagefileClass
|
||||||
|
Reference in New Issue
Block a user