Question

I'm using the GAppInfo/GDesktopAppInfo.

GIcon *icon = gtk_app_info_get_icon (G_APP_INFO(appinfo));

Now I need to put it on a GtkIconView but I found that there is no way to create a GdkPixbuf from GIcon. Anyone knows this? Thanks very much!

EDIT 1: Actually it's GThemedIcon.

Était-ce utile?

La solution

From the docs:

GIcon does not provide the actual pixmap for the icon as this is out of GIO's scope, however implementations of GIcon may contain the name of an icon (see GThemedIcon), or the path to an icon (see GLoadableIcon).

However, knowing icon name may facilitate in obtaining actual pixmap. For example, file-roller project uses the following function to obtain pixbuf from GtkIconTheme and GThemedIcon:

GdkPixbuf *
get_icon_pixbuf (GtkIconTheme *icon_theme,
         GThemedIcon  *icon,
         int           size) 
{
    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);
    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);
    }

    gtk_icon_info_free (icon_info);
    g_strfreev (icon_names);

    return pixbuf;
}

Autres conseils

Please see the following code for how to get icons file from GIcon:

GtkIconInfo *pGtkIconInfo;
Gicon *pgIcon=gtk_app_info_get_icon (G_APP_INFO(appinfo));

GtkIconTheme *pGtkIconTheme= gtk_icon_theme_get_default();
pGtkIconInfo=gtk_icon_theme_lookup_by_gicon(pGtkIconTheme,pgIcon,256,GTK_ICON_LOOKUP_USE_BUILTIN);

//get icon filename if icone 256*256 exist.

printf("%s\n",gtk_icon_info_get_filename(pGtkIconInfo));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top