GTK surprises on Maemo

Sometimes the creation of the contact chooser used on the N900 can be slow so, using callgrind and kcachegrind, I tried to understand what is the source of the slowness. This lead me to find some unexpected, and apparently undocumented, differences between upstream GTK and the Maemo version.

The Maemo 5 contact chooser
The Maemo 5 contact chooser

The widget contains a GtkTreeView that uses a model with just one column for the contact objects. How can its creation be so slow? To my surprise most of the time was spent decompressing the avatar images!
The avatars of the contacts are loaded, scaled and cropped in the cell data function of the GtkTreeViewColumn as, for various reasons, we cannot cache on disk the resulting image or generate it before the creation of the widget. Following calls of the cell data function for the same row won’t need to generate the avatar anymore. Doing non-trivial operations in the cell data function is not the nicest thing to do, but this should not be a problem as the cell data function is called only for the visible rows, right? No, at least not on Maemo!
To verify it just try this example program: on Maemo the cell_func() function is called once per item in the model plus once per visible item, elsewhere only once per visible item.

After a bit of investigation together with Claudio, we discovered that on Maemo there is a function called gtk_&#8203tree_&#8203view_&#8203column_&#8203get_&#8203cell_&#8203data_&#8203hint() that returns GTK_&#8203TREE_&#8203CELL_&#8203DATA_&#8203HINT_&#8203KEY_&#8203FOCUS, GTK_&#8203TREE_&#8203CELL_&#8203DATA_&#8203HINT_&#8203SENSITIVITY or GTK_&#8203TREE_&#8203CELL_&#8203DATA_&#8203HINT_&#8203ALL. The hint tells you why the function was called; in the example code the function is called on the hidden rows only to get their sensitivity so there is no need to set the “pixbuf” property of the cell at this point.

Just this tiny change in the address book code makes the contact chooser open much faster if you have a lot of contacts with big avatars, like the ones that Hermes creates. On the other hand the delayed loading made the scrolling become non-smooth :(
To fix the scrolling I had to implement some asynchronous loading of the avatars. The contact chooser now tries to load as many avatars as possible in idle moments and also tries to load first the avatars for the contacts that the user is more likely to see. The results seem quite good; now the contact list is fast, scrolling is smooth and the delayed loading of avatars should not be visible in normal cases.

jid-to-email

During the Christmas holidays I managed to find some time to write a couple of small programs related to the address book on the N900; they are nothing too fancy (no UI, no proper packaging, not the best code quality, etc.) as I wrote them for my personal use, but I still think it could be useful to share them with other people.

The one I’m talking about today is a simple command-line utility that adds an email address to your contacts based on the Jabber ID (or on the ID of other protocols). This is very useful to me as in Collabora we all have a roster automatically filled with the other Collaborans, this way I can automatically have their email addresses in my address book.

This cannot be done automatically for all the contact as, usually, it’s not true that a Jabber ID is also a valid email address (for instance it’s not true for jabber.org users), but it’s true at least for the GMail and Collabora servers.

If you want to try jid-to-email get the already compiled arm executable or the source code. Remember to take a backup before trying it, I don’t want to be blamed if something goes horribly wrong ;).

The program accepts two arguments: the vcard field for the IM protocol and a regular expression. For instance, if you cd to the directory where the program is and do “./jid-to-email X-JABBER @collabora.co.uk”, an email address will be added to all the contacts that have a Jabber ID containing “@collabora.co.uk”. Similarly “./jid-to-email X-JABBER ‘@g(oogle)?mail.com’” will add an email address to all the contacts with a Jabber ID containing “@gmail.com” or “@googlemail.com”. You could also try using “X-MSN” to do the same thing for contacts that use their GMail address as MSN ID.

Please, let me know if you know any other server where the Jabber ID is always a valid email address.

By the way, this week-end I’m going to Brussels for FOSDEM: hope to meet a lot of GNOME people there!

I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting

Contacts on Maemo

After the Maemo Summit the details on the address book application and framework in Maemo 5 are finally completely public so I can openly talk about what I worked on during the past year and, even better, I actually have a smartphone that runs this software! (Thanks to Nokia that gave out 300 N900s, but I will talk about this in my next post)

Contacts on the N900
Contacts on the N900

Contact details
Contact details

As you can see from the screenshots, the Contacts application has everything you would expect from a normal phone address book but it also tightly integrates IM. Your local, Jabber/GTalk and Skype contacts will appear in the same address book and, if you have a friend on multiple IM protocols, you can easily merge all the contacts into a single entity.

My main task has been making the component responsible for the IM part of the address book work properly, this component is an evolution-data-server backend (recently released under LGPL) that acts as a bridge between the Telepathy IM framework and evolution-data-server. See the README file for more details.
Sadly the library on top of evolution-data-server that does the magic contact merging and contains the widgets used on Maemo is not open, but there is some hope for it.

Address book components
Address book components

At the Maemo Summit I also gave a talk on Telepathy and how it’s used on Maemo, both for messaging/VOIP and for the contacts integration. The slides are available in PDF or in OpenOffice.org format (but for some reason colours look wrong in some recent versions of OpenOffice).