2.18 <GIcon>

Interface: <GIcon>

<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 icon:hash.

To check if two <GIcon>s are equal, see icon:equal?.

For serializing a <GIcon>, use icon:serialize and icon:deserialize.

If you want to consume <GIcon> (for example, in a toolkit) you must be prepared to handle at least the three following cases: <GLoadableIcon>, <GThemedIcon> and <GEmblemedIcon>. It may also make sense to have fast-paths for other cases (like handling ‘GdkPixbuf‘ directly, for example) but all compliant <GIcon> implementations outside of GIO must implement <GLoadableIcon>.

If your application or library provides one or more <GIcon> implementations you need to ensure that your new implementation also implements <GLoadableIcon>. Additionally, you must provide an implementation of icon:serialize that gives a result that is understood by icon:deserialize, yielding one of the built-in icon types.

Procedures

Procedure: icon:deserialize value ⇒ %return

Deserializes a <GIcon> previously serialized using icon:serialize.

value

Passed: a <GVariant>.

a <GVariant> created with icon:serialize

%return

Returned: a <GIcon>, or #f.

a <GIcon>, or #f when deserialization fails.

Method: icon:equal? self [icon2] ⇒ %return
Method: equal? self [icon2] ⇒ %return

Checks if two icons are equal.

self

Passed: a <GIcon>.

pointer to the first <GIcon>.

icon2

Passed, or left out: a <GIcon>, or #f.

pointer to the second <GIcon>.

%return

Returned: a boolean.

#t if self is equal to icon2. #f otherwise.

Method: icon:hash self ⇒ %return
Method: hash self ⇒ %return

Gets a hash for an icon.

self

Passed: a <GIcon>.

gconstpointer to an icon object.

%return

Returned: an unsigned 32-bit integer.

a guint containing a hash for the self, suitable for use in a <GHashTable> or similar data structure.

Procedure: icon:new-for-string str ⇒ %return

Generate a <GIcon> instance from str. This function can fail if str is not valid - see 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 icon-new-for-string.

str

Passed: a string.

A string obtained via icon:to-string.

%return

Returned: a <GIcon>.

An object implementing the <GIcon> interface or #f if error is set.

Method: icon:serialize self ⇒ %return
Method: serialize self ⇒ %return

Serializes a <GIcon> into a <GVariant>. An equivalent <GIcon> can be retrieved back by calling icon-deserialize on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer the <GVariant> between processes on the same machine, (as opposed to over the network), and within the same file system namespace.

self

Passed: a <GIcon>.

a <GIcon>

%return

Returned: a <GVariant>, or #f.

a <GVariant>, or #f when serialization fails. The <GVariant> will not be floating.

Method: icon:to-string self ⇒ %return
Method: to-string self ⇒ %return

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

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

  • If self is a <GFileIcon>, the returned string is a native path (such as /path/to/my icon.png) without escaping if the <GFile> for self is a native file. If the file is not native, the returned string is the result of file:get-uri (such as sftp://path/to/my%20icon.png).
  • If self is a <GThemedIcon> with exactly one name and no fallbacks, the encoding is simply the name (such as network-server).
self

Passed: a <GIcon>.

a <GIcon>.

%return

Returned: a string, or #f.

An allocated NUL-terminated UTF8 string or #f if self can’t be serialized. Use byte-array:free to free.

Virtual methods

Virtual method: icon:do-equal implementor self [icon2] ⇒ %return

Checks if two icons are equal.

To override it in a new class, give register-type #:vfuncs `((equal . ,procedure)). The procedure is called as (procedure self icon2) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GIcon>, or its GType number.

self

Passed: a <GIcon>.

pointer to the first <GIcon>.

icon2

Passed, or left out: a <GIcon>, or #f.

pointer to the second <GIcon>.

%return

Returned: a boolean.

#t if self is equal to icon2. #f otherwise.

Virtual method: icon:do-hash implementor self ⇒ %return

Gets a hash for an icon.

To override it in a new class, give register-type #:vfuncs `((hash . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GIcon>, or its GType number.

self

Passed: a <GIcon>.

gconstpointer to an icon object.

%return

Returned: an unsigned 32-bit integer.

a guint containing a hash for the self, suitable for use in a <GHashTable> or similar data structure.

Virtual method: icon:do-serialize implementor self ⇒ %return

Serializes a <GIcon> into a <GVariant>. An equivalent <GIcon> can be retrieved back by calling icon-deserialize on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer the <GVariant> between processes on the same machine, (as opposed to over the network), and within the same file system namespace.

To override it in a new class, give register-type #:vfuncs `((serialize . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GIcon>, or its GType number.

self

Passed: a <GIcon>.

a <GIcon>

%return

Returned: a <GVariant>, or #f.

a <GVariant>, or #f when serialization fails. The <GVariant> will not be floating.

Virtual method: icon:do-to-tokens implementor self tokens ⇒ %return tokens out-version

Serializes the self into string tokens. This is can be invoked when icon-new-for-string is called.

To override it in a new class, give register-type #:vfuncs `((to-tokens . ,procedure)). The procedure is called as (procedure self tokens) ⇒ %return out-version.

implementor

Passed: the class whose implementation to call: a class that implements <GIcon>, or its GType number.

self

Passed: a <GIcon>.

The <GIcon>

tokens

Passed: a list or vector, each a string. It is filled in, and returned: a vector, each a string.

The array to fill with tokens

%return

Returned: a boolean.

#t if serialization took place, #f otherwise

out-version

Returned: a 32-bit integer.

version of serialized tokens