D-BUS and accessibility

After porting kdelibs to D-BUS and Thiago's blog entry about controlling a KDE application via D-BUS, I decided to give it a try. After a bit of playing, I came up with a solution that automatically exports a com.trolltech.AccessibleObject interface for every widget (see screenshot).

D-BUS view on an accessible user interface

The command dbus :1.63 /Window1/CurrentValue com.trolltech.AccessibleObject.description (where :1.63 is the app's bus ID) returns the accessible description of that widget:

sending message: QDBusMessage(type=MethodCall, service=":1.63", path="/Window1/CurrentValue", interface="com.trolltech.AccessibleObject", name="description", signature="", contents=( ) )
got message: QDBusMessage(type=MethodReturn, service=":1.63", path="", interface="", name="", signature="", contents=(QString("The current value") ) )

All my code does is to wait for a widget's create event and attaches a QDBusAdaptor to the newly created widget. The neat thing is that D-BUS takes ownership of that adaptor, so whenever the widgets gets deleted, the D-BUS interface vanishes as well. The total code to export the accessible information is less than 100 lines of code. And the best thing: The code is readable. The accessible information can be accessed from any language without hassle, even from command line (I can imagine some pretty handy scripts emerging).