2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-03-03 20:39:19 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-26 22:20:30 +08:00
|
|
|
* gimpviewrendererimagefile.c
|
2004-03-03 20:39:19 +08:00
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-03-03 20:39:19 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-03-03 20:39:19 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-03-03 20:39:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-04-22 03:41:36 +08:00
|
|
|
#include <gegl.h>
|
2004-03-03 20:39:19 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpthumb/gimpthumb.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpimagefile.h"
|
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrendererimagefile.h"
|
2004-09-28 03:40:12 +08:00
|
|
|
#include "gimpviewrenderer-frame.h"
|
2014-05-08 15:11:31 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2004-03-03 22:00:00 +08:00
|
|
|
|
2008-03-25 00:41:42 +08:00
|
|
|
static void gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2008-03-25 00:41:42 +08:00
|
|
|
static GdkPixbuf * gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
|
2008-06-29 04:44:57 +08:00
|
|
|
GtkWidget *widget,
|
2008-03-25 00:41:42 +08:00
|
|
|
gint size);
|
2004-03-03 20:39:19 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE (GimpViewRendererImagefile, gimp_view_renderer_imagefile,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_VIEW_RENDERER)
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_view_renderer_imagefile_parent_class
|
2004-03-03 20:39:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_imagefile_class_init (GimpViewRendererImagefileClass *klass)
|
2004-03-03 20:39:19 +08:00
|
|
|
{
|
2004-09-09 19:58:49 +08:00
|
|
|
GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass);
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
renderer_class->render = gimp_view_renderer_imagefile_render;
|
2004-03-03 20:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_imagefile_init (GimpViewRendererImagefile *renderer)
|
2004-03-03 20:39:19 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_imagefile_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2004-03-03 20:39:19 +08:00
|
|
|
{
|
2004-09-28 03:40:12 +08:00
|
|
|
GdkPixbuf *pixbuf = gimp_view_renderer_get_frame_pixbuf (renderer, widget,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2008-03-25 00:41:42 +08:00
|
|
|
if (! pixbuf)
|
2004-09-27 07:44:24 +08:00
|
|
|
{
|
2008-03-25 00:41:42 +08:00
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (renderer->viewable);
|
2004-09-28 03:40:12 +08:00
|
|
|
|
2008-03-25 00:41:42 +08:00
|
|
|
pixbuf = gimp_view_renderer_imagefile_get_icon (imagefile,
|
2008-06-29 04:44:57 +08:00
|
|
|
widget,
|
2008-03-25 00:41:42 +08:00
|
|
|
MIN (renderer->width,
|
|
|
|
renderer->height));
|
2004-09-27 07:44:24 +08:00
|
|
|
}
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
2015-09-03 03:12:59 +08:00
|
|
|
gimp_view_renderer_render_pixbuf (renderer, widget, pixbuf);
|
2004-11-03 08:48:06 +08:00
|
|
|
g_object_unref (pixbuf);
|
2004-09-27 07:44:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-07 07:01:56 +08:00
|
|
|
const gchar *icon_name = gimp_viewable_get_icon_name (renderer->viewable);
|
2004-03-03 20:39:19 +08:00
|
|
|
|
2014-05-07 07:01:56 +08:00
|
|
|
gimp_view_renderer_render_icon (renderer, widget, icon_name);
|
2004-03-03 20:39:19 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-25 00:41:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* The code to get an icon for a mime-type is lifted from GtkRecentManager. */
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
2014-05-08 15:11:31 +08:00
|
|
|
get_icon_for_mime_type (const gchar *mime_type,
|
2016-12-21 11:05:32 +08:00
|
|
|
gint pixel_size)
|
2008-03-25 00:41:42 +08:00
|
|
|
{
|
|
|
|
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,
|
2014-05-08 15:11:31 +08:00
|
|
|
pixel_size, 0, NULL);
|
2008-03-25 00:41:42 +08:00
|
|
|
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,
|
2014-05-08 15:11:31 +08:00
|
|
|
pixel_size, 0, NULL);
|
2008-03-25 00:41:42 +08:00
|
|
|
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,
|
2014-05-08 15:11:31 +08:00
|
|
|
pixel_size, 0, NULL);
|
2008-03-25 00:41:42 +08:00
|
|
|
g_string_free (icon_name, TRUE);
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
|
2008-06-29 04:44:57 +08:00
|
|
|
GtkWidget *widget,
|
2008-03-25 00:41:42 +08:00
|
|
|
gint size)
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
GdkScreen *screen = gtk_widget_get_screen (widget);
|
|
|
|
GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen (screen);
|
|
|
|
GimpThumbnail *thumbnail = gimp_imagefile_get_thumbnail (imagefile);
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
2008-03-25 00:41:42 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
if (! gimp_object_get_name (imagefile))
|
2008-03-25 00:41:42 +08:00
|
|
|
return NULL;
|
|
|
|
|
2008-06-29 04:44:57 +08:00
|
|
|
if (! pixbuf)
|
2008-03-25 00:41:42 +08:00
|
|
|
{
|
2011-06-20 05:06:33 +08:00
|
|
|
GIcon *icon = gimp_imagefile_get_gicon (imagefile);
|
2008-06-29 04:44:57 +08:00
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
if (icon)
|
2008-07-22 22:50:37 +08:00
|
|
|
{
|
2011-06-20 05:06:33 +08:00
|
|
|
GtkIconInfo *info;
|
2008-06-29 04:44:57 +08:00
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);
|
|
|
|
|
|
|
|
if (info)
|
2011-11-04 08:32:50 +08:00
|
|
|
{
|
|
|
|
pixbuf = gtk_icon_info_load_icon (info, NULL);
|
|
|
|
|
2018-05-20 11:27:19 +08:00
|
|
|
g_object_unref (info);
|
2011-11-04 08:32:50 +08:00
|
|
|
}
|
2011-06-20 05:06:33 +08:00
|
|
|
}
|
2008-06-29 04:44:57 +08:00
|
|
|
}
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
if (! pixbuf && thumbnail->image_mimetype)
|
2008-06-29 04:44:57 +08:00
|
|
|
{
|
2014-05-08 15:11:31 +08:00
|
|
|
pixbuf = get_icon_for_mime_type (thumbnail->image_mimetype, size);
|
2008-03-25 00:41:42 +08:00
|
|
|
}
|
|
|
|
|
2008-06-29 04:44:57 +08:00
|
|
|
if (! pixbuf)
|
2008-03-25 00:41:42 +08:00
|
|
|
{
|
2014-05-12 04:49:22 +08:00
|
|
|
const gchar *icon_name = "text-x-generic";
|
2008-03-25 00:41:42 +08:00
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_FOLDER)
|
2014-05-12 04:49:22 +08:00
|
|
|
icon_name = "folder";
|
2008-03-25 00:41:42 +08:00
|
|
|
|
2008-06-29 04:44:57 +08:00
|
|
|
pixbuf = gtk_icon_theme_load_icon (icon_theme,
|
2008-03-25 00:41:42 +08:00
|
|
|
icon_name, size,
|
|
|
|
GTK_ICON_LOOKUP_USE_BUILTIN,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2008-06-29 04:44:57 +08:00
|
|
|
return pixbuf;
|
2008-03-25 00:41:42 +08:00
|
|
|
}
|