Interface Icon
- All Superinterfaces:
Proxy
- All Known Subinterfaces:
LoadableIcon
- All Known Implementing Classes:
BytesIcon,DmabufTexture,Emblem,EmblemedIcon,FileIcon,GLTexture,Icon.Icon$Impl,LoadableIcon.LoadableIcon$Impl,MemoryTexture,Pixbuf,Texture,Texture.Texture$Impl,ThemedIcon
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 ThemedIcon), or the path to an icon
(see LoadableIcon).
To obtain a hash of a GIcon, see hash().
To check if two GIcons are equal, see equal(org.gnome.gio.Icon).
For serializing a GIcon, use serialize() and
deserialize(org.gnome.glib.Variant).
If you want to consume GIcon (for example, in a toolkit) you must
be prepared to handle at least the three following cases:
LoadableIcon, ThemedIcon and EmblemedIcon.
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 LoadableIcon.
If your application or library provides one or more GIcon
implementations you need to ensure that your new implementation also
implements LoadableIcon. Additionally, you must provide an
implementation of serialize() that gives a result that is
understood by deserialize(org.gnome.glib.Variant), yielding one of the built-in
icon types.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classThe Icon$Impl type represents a native instance of the Icon interface.static classGIconIface is used to implement GIcon types for various different systems. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Icondeserialize(Variant value) Deserializes aGIconpreviously serialized using g_icon_serialize().default booleanChecks if two icons are equal.static @Nullable TypegetType()Get the GType of the Icon classdefault inthash()Gets a hash for an icon.static IconnewForString(String str) Generate aGIconinstance fromstr.This function can fail ifstris not valid - see g_icon_to_string() for discussion.default @Nullable VariantSerializes aGIconinto aGVariant.default @Nullable StringGenerates a textual representation of this Icon that can be used for serialization such as when passing this Icon to a different process or saving it to persistent storage.
-
Method Details
-
getType
-
deserialize
-
newForString
Generate aGIconinstance fromstr.This function can fail ifstris not valid - see g_icon_to_string() for discussion.If your application or library provides one or more
GIconimplementations you need to ensure that eachGTypeis registered with the type system prior to calling g_icon_new_for_string().- Parameters:
str- A string obtained via g_icon_to_string().- Returns:
- An object implementing the
GIconinterface ornulliferroris set. - Throws:
GErrorException- seeGError- Since:
- 2.20
-
equal
Checks if two icons are equal.- Parameters:
icon2- pointer to the secondGIcon.- Returns:
trueif this Icon is equal toicon2.falseotherwise.
-
hash
default int hash()Gets a hash for an icon.- Returns:
- a
guintcontaining a hash for theicon,suitable for use in aGHashTableor similar data structure.
-
serialize
Serializes aGIconinto aGVariant. An equivalentGIconcan be retrieved back by calling g_icon_deserialize() on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer theGVariantbetween processes on the same machine, (as opposed to over the network), and within the same file system namespace.- Returns:
- a
GVariant, ornullwhen serialization fails. TheGVariantwill not be floating. - Since:
- 2.38
-
serializeToString
Generates a textual representation of this Icon that can be used for serialization such as when passing this Icon to a different process or saving it to persistent storage. Use g_icon_new_for_string() to get this Icon back from the returned string.The encoding of the returned string is proprietary to
GIconexcept in the following two cases- If this Icon is a
GFileIcon, the returned string is a native path (such as/path/to/my icon.png) without escaping if theGFilefor this Icon is a native file. If the file is not native, the returned string is the result of g_file_get_uri() (such assftp://path/to/my%20icon.png).
- If this Icon is a
GThemedIconwith exactly one name and no fallbacks, the encoding is simply the name (such asnetwork-server).
- Returns:
- An allocated NUL-terminated UTF8 string or
nullif this Icon can't be serialized. Use g_free() to free. - Since:
- 2.20
- If this Icon is a
-