GDBus, GVariant, GTK+ 3, and Vala

Vala 0.9.2 has just been released. Tarballs are available from the GNOME FTP servers. We try to keep up with changes in the GTK+ stack and are pleased to announce that Vala 0.9.2 already comes with initial support for GDBus and GTK+ 3 and enhanced support for GVariant.

GVariant

While we’ve already had GVariant bindings for quite some time now, this release integrates support for GVariant conversions. Numbers, strings, structs, arrays, and hashtables are implicitly converted to GVariant and can explicitly be converted back using the cast operator. This should make it a lot more convenient to use GVariant in Vala code.

void main () {
	Variant v = "hello, world";
	print ("%s\n", (string) v);
}

GDBus

Until now, Vala’s integrated D-Bus support has been using libdbus and bits of dbus-glib. While we will continue to support this to not break existing code, Vala 0.9.2 now also has initial support for GDBus. The supported feature set is nearly equivalent to the previous D-Bus support.
It includes client and server support, asynchronous methods on both sides, properties, signals, and error handling. The dynamic client support is still very limited, but I hope that we can complete that soon. One of the advantages of using GDBus is that you can easily use GVariant parameters for variant types instead of the incomplete GValue support we had before.

Client

[DBus (name = "org.example.Test")]
interface Test : Object {
	public abstract string test_property { owned get; set; }

	public abstract int test_int (int i, out int j) throws IOError;
}

void main () {
	Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");

	int j, k;
	k = test.test_int (42, out j);

	string t;
	test.test_property = "hello";
	t = test.test_property;
}

Server

[DBus (name = "org.example.Test")]
class Test : Object {
	public string test_property { owned get; set; }

	public int test_int (int i, out int j) {
		j = 23;
		return 11;
	}
}

void main () {
	var conn = Bus.get_sync (BusType.SESSION);
	conn.register_object ("/org/example/test", new Test ());

	var app = new Application ("org.example.Test");
	app.run ();
}

GTK+ 3

This release also brings initial bindings for GTK+ 3, so that Vala applications can prepare for GNOME 3.0. As with the C library, the API of the bindings stays mostly compatible with GTK+ 2. The biggest changes are dropping of deprecated or sealed types and members.

One thought on “GDBus, GVariant, GTK+ 3, and Vala”

Leave a Reply

Your email address will not be published. Required fields are marked *