Using Debian Wheezy, I found that trying to use Evolution as my task source for hamster-applet was not working.

I enabled Evolution as my source for tasks in Hamster. When executing hamster-time-tracker from the CLI, an error would appear in my terminal:

** (Time Tracker:14088): WARNING **: Failed to open calendar (type 1): Authentication required

I first thought that the problem was with hamster, that it was an outdated version. So I downloaded the source from github, re-built it and installed it on my system (after removing the old hamster). This didn’t help. But, as I had the source handy, I thought I’d take a look.

In the hamster-master/src/hamster directory is a file called external.py and, in that, this:

try:
import evolution
from evolution import ecal
except:
evolution = None

So, I know I have found the right area to start investigating this issue further.

For python applications to interface to Evolution, which is written in C, some interfacing software is required. This is installed generally in the form of the package “python-evolution” (http://packages.debian.org/wheezy/python-evolution). As shown at the top of that page, the source for this binary package is gnome-python-desktop (http://packages.debian.org/source/wheezy/gnome-python-desktop).

The next step was to search for the source package responsible for interfacing to Evolution’s calendar. I soon found this. From the Packages Debian page (packages.debian.org) you would click the Developer Information (PTS) link (http://packages.qa.debian.org/gnome-python-desktop). Once there, on the right hand side, click browse source code (http://sources.debian.net/src/gnome-python-desktop/2.32.0%2Bdfsg-3). You end up at a page listing folders containing source files. Simply click into evolution and then click on evo-calendar.c (http://sources.debian.net/src/gnome-python-desktop/2.32.0%2Bdfsg-3/evolution/evo-calendar.c).

I don’t profess to know programming in C, or even how to read much of it really, but you learn by doing – so let’s give it a go. Around lines 24-34, we see the declaration of what I believe is a structure:

#include “evo-calendar.h”

ECal *
evo_cal_source_open_source(const char *uri, ECalSourceType type)
{
ESourceList *sources = NULL;
ESource *source = NULL;
ECal *cal = NULL;
GError *gerror = NULL;

g_debug(“Opening calendar source uri: %s\n”, uri);

This looks like what we need – some code that is trying to open the calendar. It’s also including the header file, evo-calendar.h, which we may need to look at in a sec. So, the main purpose of this code is to open a calendar:

if (strcmp(uri, “default”)) {
if (!e_cal_get_sources(&sources, type, &gerror)) {
g_warning(“Unable to get sources for calendar (type %u): %s”,
type, gerror && gerror->message ? gerror->message : “None”);
g_clear_error(&gerror);
return NULL;
}

source = evo_environment_find_source(sources, uri);
if (!source) {
g_warning(“Unable to find source for calendar (type %u)”, type);
return NULL;
}

cal = e_cal_new(source, type);
if(!cal) {
g_warning(“Failed to create new calendar (type %u)”, type);
return NULL;
}

if(!e_cal_open(cal, FALSE, &gerror)) {
g_warning(“Failed to open calendar (type %u): %s”,
type, gerror && gerror->message? gerror->message : “None”);
g_object_unref(cal);
g_clear_error(&gerror);
return NULL;
}
} else {
if (!e_cal_open_default (&cal, type, NULL, NULL, &gerror)) {
g_warning(“Failed to open default calendar: %s”,
gerror && gerror->message ? gerror->message : “None”);
g_clear_error(&gerror);
return NULL;
}
}

return cal;

If you read closely, you’ll see that we have an IF statement, followed immediately by another IF statement:

if (strcmp(uri, “default”)) {
if (!e_cal_get_sources(&sources, type, &gerror)) {
g_warning(“Unable to get sources for calendar (type %u): %s”,

strcmp may be a string-compare function. Regardless, because of our error message in the terminal, cited previously, it’s fair to say that this strcmp is returning a TRUE. In other words, a basic test is conducted based on the URI that is being passed in to this function, and an error is being returned.

The error returned, “Failed to open calendar”, is a string within the C source code in this same file, at around line 57:

if(!e_cal_open(cal, FALSE, &gerror)) {
g_warning(“Failed to open calendar (type %u): %s”,
type, gerror && gerror->message? gerror->message : “None”);
g_object_unref(cal);
g_clear_error(&gerror);
return NULL;
}

This is the error message we are seeing! The (type %u) bit after the message is probably the return code (a general rule is that if the return code is 0, everything is ok, and any valyue other than 0 means there’s a problem)  and the  : %s bit is the string returned from the function trying to open the calendar, giving a reason why.

So, to reiterate our error message:

** (Time Tracker:14088): WARNING **: Failed to open calendar (type 1): Authentication required

The function e_cal_open() is returning this error code.  To understand this function more, and what’s happening in this code, we need to look at the source for this function and also understand what data we’re passing to it.

Firstly, our call to the function is this:

e_cal_open(cal, FALSE, &gerror)

We can come back to what we’re passing to this function in a moment.  Firstly, though, where is the e_cal_open function?  We need to find out how it works!

Remember earlier that our file evo-calendar.c has an “include” pointing to the file evo-calendar.h?  Well, that means “grab the file evo-calendar.h and make its resources available to me”.  Within evo-calendar.h, there is no e_cal_open() function, but there are other includes, including one pointing to libecal/e-cal.h.

On debian, lib-ecal is another package installed along with Evolution.  So, finding the file e-cal.h is as simple as using find or locate.  On my system, the complete path to the file is /usr/include/evolution-data-server-3.4/libecal/e-cal.h. Hurrah – let’s go searching that C for e_cal_open:

$ grep -i e_cal_open /usr/include/evolution-data-server-3.4/libecal/e-cal.h

gboolean e_cal_open (ECal *ecal, gboolean only_if_exists, GError **error);
void e_cal_open_async (ECal *ecal, gboolean only_if_exists);
gboolean    e_cal_open_default (ECal **ecal, ECalSourceType type, ECalAuthFunc func, gpointer data, GError **error);

The first one is the one we’re interested in at present: e_cal_open.

[ Sorry.  This is an incomplete post, published for completeness instead of binned.]