It’s time for another round on the Ubuntu Technical Board’s review of the top ranked items on Ubuntu Brainstorm. This time I’m reviewing a brainstorm about a Unity Lens for contacts, together with Neil Patel from Canonical’s DX team. I volunteered to participate in this reply because I’d already been thinking about how to do it before I saw the brainstorm. I mainly keep my contacts in Gmail these days, for sync to my Android phone and tablet. But, with around 700 contacts, I find the Gmail interface pretty clunky.
The first key to a Contacts Lens is a standard format for contacts, and a path for contact synchronization. For the Oneiric release, coming up in a couple of weeks, Thunderbird is the new default email client, and as part of that, the Thunderbird developers (especially Mike Conley) added support to Thunderbird for the existing standard for contacts in GNOME, which is EDS (Evolution Data Server). Supporting EDS not only provides access to Evolution contacts from Thunderbird, which is important for users migrating from Evolution to Thunderbird, but also provides access to Gmail contacts and UbuntuOne contacts.
The second key is integrating EDS with a Unity Lens. The DX team isn’t working on a Contacts Lens for this in Oneiric or 12.04, but writing a lens is an accessible task for anyone with a little skill in Vala or Python, and is a great way to learn more about how Unity works. I’ll outline how to get started here, for more details see the wiki documentation on lenses. The architecture of a Unity Lens is pretty simple, I’d even say elegant. Writing a Lens doesn’t involve any GUI code at all, you only write a small backend that supplies the data to be displayed. This means that all lenses work for both Unity and Unity 2D, without any changes.
A Lens is a daemon that talks over D-Bus. To build one, you start with 3 files. (Throughout this illustration, I’ll pretend we’re working on a Launchpad project called ‘unity-lens-contacts’.) The first file is the Lens itself, and the core of that file is a few lines that create a Lens object from libunity, and then set some default properties for it. In Vala, that would be:
lens = new Unity.Lens("/net/launchpad/lens/contacts", "contacts");
To go along with the Lens, you need a ‘contacts.lens’ file to tell Unity where to find your daemon, and a ‘contacts.service’ file to register the D-Bus service that your Lens provides. The ‘contacts.lens’ file is installed in ‘/usr/share/unity/lenses/contacts/’, and looks like:
[Lens] DBusName=net.launchpad.Lens.Contacts DBusPath=/net/launchpad/lens/contacts Name=Contacts Icon=/usr/share/unity-lens-contacts/data/lens-nav-contacts.svg Description=A Lens to search contacts SearchHint=Search Contacts Shortcut=c [Desktop Entry] X-Ubuntu-Gettext-Domain=unity-lens-contacts
The ‘contacts.service’ file is installed in ‘/usr/share/dbus-1/services/’, and looks like:
[D-BUS Service] Name=net.launchpad.Lens.Contacts Exec=/usr/lib/unity-lens-contacts/unity-lens-contacts
A Lens daemon handles requests for data, but it doesn’t actually do the searching. For that, you need to define a Scope (if it helps, think about searching the ocean through a periscope). A Lens can have more than one Scope, and when it does, each Scope collects results from a different source, so the Lens can combine them into one full set of results. Start with one Scope for one datasource: EDS contacts. A Scope is just another libunity object, and creating one in Vala looks like:
scope = new Unity.Scope ("/net/launchpad/scope/edscontacts");
The search functionality goes in the ‘perform_search’ method. For EDS contacts, you could use the EDS APIs directly, but Neil recommends libfolks.
A Scope can run locally inside the Lens daemon, in which case you add it directly to the Lens object:
Or, a Scope can run in a separate daemon, in which case you’ll also need an ‘edscontacts.scope’ file, so the Lens knows where to find the Scope. This file is installed in the same folder as ‘contacts.lens’ (‘/usr/share/unity/lenses/contacts/’), and looks like:
[Scope] DBusName=net.launchpad.Scope.edscontacts DBusPath=/net/launchpad/scope/edscontacts
That’s the basic anatomy of a Lens, and enough to get a new project started. To see how it all fits together, there are several good examples of other lenses. The Unity Music Lens is the most relevant example for the Contacts Lens, and a fairly straightforward one to start looking at. For more complex examples, see the Applications or Files lenses. There’s also a Sample Lens, which is a working tutorial. And, once you get the core of the Contacts Lens working, and are looking for what to add next, read up more on Categories and Filters in the wiki.
If this sounds like an interesting project to you, drop us a line. You’ll find a lot of enthusiasm, and willingness to help out where you need it.
I totally like the idea of a contact lens (and not only because of the funny name). I even thought about writing one if noone else picks up this task. But doing it together with a bunch of motivated people might be more fun than everyone trying things out alone.
So what would be a good way to start? Register a launchpad project, create a team, start a mailing list? I’d be willing to join in, then.
As a starting point, there is already an early attempt by Seif Lotfy: https://code.launchpad.net/~seif/+junk/unity-ppl
And I wrote a deskbar plugin which searches EDS and displays the results in a small dialog: http://my.opera.com/freedo/blog/2009/09/10/deskbook-deskbar-meets-adressbuchsuche
The dialog itself is a python port of the old GNOME contacts lookup applet.
There are also some design issues to discuss, like pure EDS vs. libfolks, python vs. vala, GNOME Contacts integration, etc.
I can help you with this lens (I’m Unity Mail developer, so I have some experience in Unity API).
I think libfolks is a good library to use because we have a gir for it (see https://launchpad.net/ubuntu/+source/folks), so it’ll be easy to integrate it.
Opening contacts Gnome Documents is a must-have thing, if it’s possible.
And… I’ll prefer Python, but also this is a good opportunity for me to learn something different :))
You can contact me using mail/jabber (mitya57 at gmail.com), though I’ll have no free time in the nearest 2 or 3 days.
Guys, I have started some basic (very basic) work on it, you can find it here:
it’s based on the Music Lens, and I managed to fetch the list of contacts using libfolks and show it in the dash. It still have a lot of work to be done, but if you want to start off it, I’ll glad to help.
great to hear that there are some people willing to help with this.
I created a launchpad team and project for this:
I thought this might be the easiest way to share some ideas (via the team mailing list) and code. So feel free to join the team, we could then continue the discussion in more detail there.
I personally would be happy with Python, since I am not familiar with vala. Nevertheless, if Python and Libfolks are a viable solution, we might easily port the working parts of Pablos code. But I’d suggest to discuss this on the team list.
I’d use libfolks (and Vala is probably a good choice for doing that), since that would automatically aggregate from telepathy and e-d-s. It can also benefit from merging, like GNOME contacts do.
As for the project, I think someone could create a Unity Lenses project, where we can host several ones.