GIcon

## GIcon GIcon — Interface for icons |

## Synopsis

    #include <gio/gio.h>

                        GIcon;
    struct              GIconIface;
    guint               g_icon_hash                         (gconstpointer icon);
    gboolean            g_icon_equal                        (GIcon *icon1,
                                                             GIcon *icon2);
    gchar *             g_icon_to_string                    (GIcon *icon);
    GIcon *             g_icon_new_for_string               (const gchar *str,
                                                             GError **error);

## Object Hierarchy

      GInterface
       +----GIcon

## Prerequisites

GIcon requires GObject.

## Known Derived Interfaces

GIcon is required by GLoadableIcon.

## Known Implementations

GIcon is implemented by GEmblem, GEmblemedIcon, GFileIcon and GThemedIcon.

## Description

GIcon is a very minimal interface for icons. It provides functions for checking the equality of two icons, hashing of icons and serializing an icon to and from strings.

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).

To obtain a hash of a GIcon, see `g_icon_hash()`.

To check if two GIcons are equal, see `g_icon_equal()`.

For serializing a GIcon, use `g_icon_to_string()` and `g_icon_new_for_string()`.

If your application or library provides one or more GIcon implementations you need to ensure that each GType is registered with the type system prior to calling `g_icon_new_for_string()`.

## Details

### GIcon

    typedef struct _GIcon GIcon;

An abstract type that specifies an icon.

### struct GIconIface

    struct GIconIface {
      GTypeInterface g_iface;

      /* Virtual Table */

      guint       (* hash)        (GIcon   *icon);
      gboolean    (* equal)       (GIcon   *icon1,
                                   GIcon   *icon2);
      gboolean    (* to_tokens)   (GIcon   *icon,
    			       GPtrArray *tokens,
                                   gint    *out_version);
      GIcon *     (* from_tokens) (gchar  **tokens,
                                   gint     num_tokens,
                                   gint     version,
                                   GError **error);
    };

GIconIface is used to implement GIcon types for various different systems. See GThemedIcon and GLoadableIcon for examples of how to implement this interface.

GTypeInterface `g_iface`; | The parent interface.
`hash` () | A hash for a given GIcon.
`equal` () | Checks if two GIcons are equal.
`to_tokens` () | Serializes a GIcon into tokens. The tokens must not contain any whitespace. Don't implement if the GIcon can't be serialized (Since 2.20).
`from_tokens` () | Constructs a GIcon from tokens. Set the GError if the tokens are malformed. Don't implement if the GIcon can't be serialized (Since 2.20).

### g_icon_hash ()

    guint               g_icon_hash                         (gconstpointer icon);

Gets a hash for an icon.

Virtual: hash

`icon` : | gconstpointer to an icon object.
Returns : | a guint containing a hash for the `icon`, suitable for use in a GHashTable or similar data structure.

### g_icon_equal ()

    gboolean            g_icon_equal                        (GIcon *icon1,
                                                             GIcon *icon2);

Checks if two icons are equal.

`icon1` : | pointer to the first GIcon.
`icon2` : | pointer to the second GIcon.
Returns : | `TRUE` if `icon1` is equal to `icon2`. `FALSE` otherwise.

### g_icon_to_string ()

    gchar *             g_icon_to_string                    (GIcon *icon);

Generates a textual representation of `icon` that can be used for serialization such as when passing `icon` to a different process or saving it to persistent storage. Use `g_icon_new_for_string()` to get `icon` back from the returned string.

The encoding of the returned string is proprietary to GIcon except in the following two cases

- If `icon` is a GFileIcon, the returned string is a native path (such as `/path/to/my icon.png`) without escaping if the GFile for `icon` is a native file. If the file is not native, the returned string is the result of `g_file_get_uri()` (such as `sftp://path/to/my%20icon.png`).

- If `icon` is a GThemedIcon with exactly one name, the encoding is simply the name (such as `network-server`).

Virtual: to_tokens

`icon` : | a GIcon.
Returns : | An allocated NUL-terminated UTF8 string or `NULL` if `icon` can't be serialized. Use `g_free()` to free.

Since 2.20

### g_icon_new_for_string ()

    GIcon *             g_icon_new_for_string               (const gchar *str,
                                                             GError **error);

Generate a GIcon instance from `str`. This function can fail if `str` is not valid - see `g_icon_to_string()` for discussion.

If your application or library provides one or more GIcon implementations you need to ensure that each GType is registered with the type system prior to calling `g_icon_new_for_string()`.

`str` : | A string obtained via `g_icon_to_string()`.
`error` : | Return location for error.
Returns : | An object implementing the GIcon interface or `NULL` if `error` is set. [transfer full]

Since 2.20