Ejemplo n.º 1
0
static GdkPixbuf *
get_themed_icon_pixbuf (GThemedIcon  *icon,
		        int           size,
		        GtkIconTheme *icon_theme)
{
	char        **icon_names;
	GtkIconInfo  *icon_info;
	GdkPixbuf    *pixbuf;
	GError       *error = NULL;

	g_object_get (icon, "names", &icon_names, NULL);

	icon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)icon_names, size, 0);
	if (icon_info == NULL)
		icon_info = gtk_icon_theme_lookup_icon (icon_theme, "text-x-generic", size, GTK_ICON_LOOKUP_USE_BUILTIN);

	pixbuf = gtk_icon_info_load_icon (icon_info, &error);
	if (pixbuf == NULL) {
		g_warning ("could not load icon pixbuf: %s\n", error->message);
		g_clear_error (&error);
	}

	g_object_unref (icon_info);
	g_strfreev (icon_names);

	return pixbuf;
}
Ejemplo n.º 2
0
static GdkPixbuf *
get_themed_icon_pixbuf (GThemedIcon *icon, int size, GtkIconTheme *icon_theme)
{
    char **icon_names = NULL;
    g_object_get (icon, "names", &icon_names, NULL);

    GtkIconInfo *icon_info = gtk_icon_theme_choose_icon (icon_theme,
                                            (const char **)icon_names,
                                            size,
                                            GTK_ICON_LOOKUP_FORCE_SIZE);
    if (icon_info == NULL) {
        icon_info = gtk_icon_theme_lookup_icon (icon_theme,
                                                "text-x-generic",
                                                size,
                                                GTK_ICON_LOOKUP_FORCE_SIZE);
    }

    GError * error = NULL;
    GdkPixbuf *pixbuf = gtk_icon_info_load_icon (icon_info, &error);
    if (pixbuf == NULL) {
        g_warning ("Could not load icon pixbuf: %s\n", error->message);
        g_clear_error (&error);
    }

#if GTK_CHECK_VERSION (3, 8, 0)
    g_object_unref (icon_info);
#else
    gtk_icon_info_free (icon_info);
#endif
    g_strfreev (icon_names);

    return pixbuf;
}
Ejemplo n.º 3
0
ASImage* GIcon2ASImage (GIcon *icon)
{
	char        **icon_names;
	ASImage* asim = NULL;

	if (icon == NULL)
		return NULL;
	g_object_get (icon, "names", &icon_names, NULL);

#if 0
	{
		GdkPixbuf* iconPixbuf;
		GtkIconInfo  *icon_info;
		GtkIconTheme *icon_theme;
		GError       *error = NULL;
		icon_info = gtk_icon_theme_choose_icon (gtk_icon_theme_get_default(), (const char **)icon_names, DEFAULT_TILE_WIDTH, 0);
		icon_theme = gtk_icon_theme_get_for_screen (gdk_screen_get_default());
  	icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, v->icon, DEFAULT_TILE_WIDTH, GTK_ICON_LOOKUP_USE_BUILTIN);

		iconPixbuf = gtk_icon_info_load_icon (icon_info, &error);
		gtk_icon_info_free (icon_info);

		if (iconPixbuf )
			asim = GdkPixbuf2ASImage (iconPixbuf);
		else {
			g_warning ("could not load icon pixbuf: %s\n", error->message);
	  	g_clear_error (&error);
		}
	}
#else	
	{
		int i;
		for (i = 0 ; icon_names[i] ; ++i)
			if ((asim = load_environment_icon ("devices", icon_names[i], DEFAULT_TILE_WIDTH)) != NULL)
				break;
	}
#endif
	g_strfreev (icon_names);
	return asim;
}
Ejemplo n.º 4
0
static GdkPixbuf*
anjuta_docman_get_pixbuf_for_file (GFile* file)
{
	/* add a nice mime-type icon if we can */
	const gchar** icon_names;
	GtkIconInfo* icon_info;
	GIcon* icon;
	GdkPixbuf* pixbuf;
	GFileInfo* file_info;
	GError* err = NULL;

	g_return_val_if_fail (file != NULL, NULL);

	file_info = g_file_query_info (file,
								   "standard::*",
								   G_FILE_QUERY_INFO_NONE,
								   NULL,
								   &err);
	if (err)
		DEBUG_PRINT ("GFile-Error %s", err->message);

	if (file_info != NULL)
	{
		icon = g_file_info_get_icon (file_info);
		g_object_get (icon, "names", &icon_names, NULL);
		icon_info = gtk_icon_theme_choose_icon (gtk_icon_theme_get_default(),
												icon_names,
												GTK_ICON_SIZE_MENU,
												GTK_ICON_LOOKUP_GENERIC_FALLBACK);
		pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
		gtk_icon_info_free(icon_info);
		g_object_unref (icon);

		if (pixbuf != NULL)
		{
			return pixbuf;
		}
	}
	return NULL;
}
Ejemplo n.º 5
0
NautilusIconInfo *
nautilus_icon_info_lookup (GIcon *icon,
			   int size)
{
	NautilusIconInfo *icon_info;
	GdkPixbuf *pixbuf;
	
	if (G_IS_LOADABLE_ICON (icon)) {
		LoadableIconKey lookup_key;
		LoadableIconKey *key;
		GInputStream *stream;
		
		if (loadable_icon_cache == NULL) {
			loadable_icon_cache =
				g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash,
						       (GEqualFunc)loadable_icon_key_equal,
						       (GDestroyNotify) loadable_icon_key_free,
						       (GDestroyNotify) g_object_unref);
		}
		
		lookup_key.icon = icon;
		lookup_key.size = size;

		icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
		if (icon_info) {
			return g_object_ref (icon_info);
		}

		pixbuf = NULL;
		stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
					       size,
					       NULL, NULL, NULL);
		if (stream) {
			pixbuf = eel_gdk_pixbuf_load_from_stream_at_size (stream, size);
			g_object_unref (stream);
		}

		icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf);

		key = loadable_icon_key_new (icon, size);
		g_hash_table_insert (loadable_icon_cache, key, icon_info);

		return g_object_ref (icon_info);
	} else if (G_IS_THEMED_ICON (icon)) {
		const char * const *names;
		ThemedIconKey lookup_key;
		ThemedIconKey *key;
		GtkIconTheme *icon_theme;
		GtkIconInfo *gtkicon_info;
		const char *filename;

		if (themed_icon_cache == NULL) {
			themed_icon_cache =
				g_hash_table_new_full ((GHashFunc)themed_icon_key_hash,
						       (GEqualFunc)themed_icon_key_equal,
						       (GDestroyNotify) themed_icon_key_free,
						       (GDestroyNotify) g_object_unref);
		}
		
		names = g_themed_icon_get_names (G_THEMED_ICON (icon));

		icon_theme = gtk_icon_theme_get_default ();
		gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0);

		if (gtkicon_info == NULL) {
			return nautilus_icon_info_new_for_pixbuf (NULL);
		}

		filename = gtk_icon_info_get_filename (gtkicon_info);

		lookup_key.filename = (char *)filename;
		lookup_key.size = size;

		icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
		if (icon_info) {
			gtk_icon_info_free (gtkicon_info);
			return g_object_ref (icon_info);
		}
		
		icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info);
		
		key = themed_icon_key_new (filename, size);
		g_hash_table_insert (themed_icon_cache, key, icon_info);

		gtk_icon_info_free (gtkicon_info);

		return g_object_ref (icon_info);
	} else {
                GdkPixbuf *pixbuf;
                GtkIconInfo *gtk_icon_info;

                gtk_icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                                                icon,
                                                                size,
                                                                GTK_ICON_LOOKUP_GENERIC_FALLBACK);
                if (gtk_icon_info != NULL) {
                        pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL);
                        gtk_icon_info_free (gtk_icon_info);
                } else {
                        pixbuf = NULL;
                }

                return nautilus_icon_info_new_for_pixbuf (pixbuf);
        }
}
Ejemplo n.º 6
0
NautilusIconInfo *
nautilus_icon_info_lookup (GIcon *icon,
			   int size)
{
	NautilusIconInfo *icon_info;
	GdkPixbuf *pixbuf;
	
	if (G_IS_LOADABLE_ICON (icon)) {
		LoadableIconKey lookup_key;
		LoadableIconKey *key;
		GInputStream *stream;
		
		if (loadable_icon_cache == NULL) {
			loadable_icon_cache =
				g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash,
						       (GEqualFunc)loadable_icon_key_equal,
						       (GDestroyNotify) loadable_icon_key_free,
						       (GDestroyNotify) g_object_unref);
		}
		
		lookup_key.icon = icon;
		lookup_key.size = size;

		icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
		if (icon_info) {
			return g_object_ref (icon_info);
		}

		pixbuf = NULL;
		stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
					       size,
					       NULL, NULL, NULL);
		if (stream) {
			GdkPixbuf *scaled_pixbuf;
		        int w, h, s;
			double scale;
			
			pixbuf = eel_gdk_pixbuf_load_from_stream (stream);
			g_object_unref (stream);
			
			w = gdk_pixbuf_get_width (pixbuf);
			h = gdk_pixbuf_get_height (pixbuf);
			s = MAX (w, h);

			if (size != s) {
				scale = (double)size / s;
				scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
									 w * scale, h * scale,
									 GDK_INTERP_BILINEAR);
				g_object_unref (pixbuf);
				pixbuf = scaled_pixbuf;
			}
		}

		icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf);

		key = loadable_icon_key_new (icon, size);
		g_hash_table_insert (loadable_icon_cache, key, icon_info);

		return g_object_ref (icon_info);
	} else if (G_IS_THEMED_ICON (icon)) {
		const char * const *names;
		ThemedIconKey lookup_key;
		ThemedIconKey *key;
		GtkIconTheme *icon_theme;
		GtkIconInfo *gtkicon_info;
		const char *filename;

		if (themed_icon_cache == NULL) {
			themed_icon_cache =
				g_hash_table_new_full ((GHashFunc)themed_icon_key_hash,
						       (GEqualFunc)themed_icon_key_equal,
						       (GDestroyNotify) themed_icon_key_free,
						       (GDestroyNotify) g_object_unref);
		}
		
		names = g_themed_icon_get_names (G_THEMED_ICON (icon));

		icon_theme = gtk_icon_theme_get_default ();
		gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0);

		if (gtkicon_info == NULL) {
			return nautilus_icon_info_new_for_pixbuf (NULL);
		}

		filename = gtk_icon_info_get_filename (gtkicon_info);

		lookup_key.filename = (char *)filename;
		lookup_key.size = size;

		icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
		if (icon_info) {
			gtk_icon_info_free (gtkicon_info);
			return g_object_ref (icon_info);
		}
		
		icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info);
		
		key = themed_icon_key_new (filename, size);
		g_hash_table_insert (themed_icon_cache, key, icon_info);

		gtk_icon_info_free (gtkicon_info);

		return g_object_ref (icon_info);
	} 
	return nautilus_icon_info_new_for_pixbuf (NULL);
}