Libxfce4ui api review

Jannis Pohlmann jannis at xfce.org
Tue Jul 7 13:07:24 CEST 2009


On Tue, 7 Jul 2009 10:20:05 +0200
Nick Schermer <nickschermer at gmail.com> wrote:

> Another function that might be useful is the create_item_icon()
> function in the libxfce4menu test application [1]. I think we use that
> in a bunch of places to handle the (sometimes) weird Icon= values in
> desktop files. On the other hand I think we should ignore values that
> are not icon-names or absolute locations.

Not sure this still is the right approach to loading. What we could add
is a method to create a GIcon based on a string (either an icon name or
an absolute filename). Reasoning behind this is that it doesn't make
much sense to deal with pixbufs ourselves if all we have to do is
allocate meta information (GIcon) and let GTK+ resolve it into pixbufs
or whatever.

The basic implemntation could look like this:

  GIcon *
  xfce_gicon_new_for_icon_name (const gchar *icon_name)
  {
    GIcon *icon = NULL;
    GFile *file;

    if (g_path_is_absolute (icon_name)) 
      {
         file = g_file_new_for_path (icon_name);
         icon = g_file_icon_new (file);
         g_object_unref (file);
      }
    else 
      {
         icon = g_themed_icon_new (icon_name);
      }

    return icon;
  }

If we *really* need a pixbuf, we could add another method:

  GdkPixbuf *
  xfce_gdk_pixbuf_new_from_icon (GIcon        *icon,
                                 GtkIconTheme *icon_theme,
                                 gint          size)
  {
    GInputStream *stream;
    GtkIconInfo  *icon_info;
    GdkPixbuf    *pixbuf = NULL;

    if (G_IS_THEMED_ICON (icon))
      {
        icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,
                                                    size, 
                                                    GTK_ICON_LOOKUP_USE_BUILTIN);
        if (icon_info != NULL)
          {
            pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
            gtk_icon_info_free (icon_info);
          }
      }
    else if (G_IS_LOADABLE_ICON (icon))
      {
        stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), size,
                                       NULL, NULL, NULL);
        if (stream != NULL)
          {
            pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
            g_object_unref (stream);
          }
      }
  }

The problem with this is that g_loadable_icon_load() and
gdk_pixbuf_new_from_stream() are possibly blocking function calls,
which means we'd either have to pass a GCancellable to
xfce_gdk_pixbuf_new_from_icon() or just decide not do add this function
at all and rather let GTK+ handle the loading of icons.

  - Jannis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://mail.xfce.org/pipermail/xfce4-dev/attachments/20090707/33b8f0b8/attachment.pgp>


More information about the Xfce4-dev mailing list