Icon 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.
Icon does not provide the actual pixmap for the icon as this is out of GIO's scope, however implementations of Icon may contain the name of an icon (see ThemedIcon), or the path to an icon (see LoadableIcon).
To obtain a hash of a Icon, see hash.
To check if two Icons are equal, see equal.
For serializing a Icon, use serialize and deserialize.
If you want to consume Icon (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 Icon implementations
outside of GIO must implement LoadableIcon.
If your application or library provides one or more Icon 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, yielding one of the built-in icon types.
Example: FileInfo, async:
public static int main (string[] args) {
if (args.length != 2) {
print ("%s FILE\n", args[0]);
return 0;
}
MainLoop loop = new MainLoop ();
File file = File.new_for_commandline_arg (args[1]);
file.query_info_async.begin ("standard::icon", 0, Priority.DEFAULT, null, (obj, res) => {
try {
FileInfo info = file.query_info_async.end (res);
Icon icon = info.get_icon ();
print ("%s\n", icon.to_string ());
} catch (Error e) {
print ("Error: %s\n", e.message);
}
loop.quit ();
});
loop.run ();
return 0;
}
valac --pkg gio-2.0 GLib.File.query_info_async.vala