I'm trying to develop a small application that updates the Evolution calendar every few minutes. I know that there is a set of APIs (libecal) for managing, adding, etc.
I found the snippet attached to this question as an example to add a new object and set an alarm to it, however after trying endless times i can't seem to be able to change the code to allow me to add a new event on the date and time desired by my users. the format is not very clear.
i tried converting a struct tm into a format that libcal can understand but no luck.
anyone has a working snippet to add a calendar event at a specific date/time (and set its duration)?
void NewObj(ECal *ecal)
time_t t1, t2;
ECalComponent *ec; //ECAL component
ECalComponentText tx; //the text for the new component
ECalComponentDateTime st, et; //date/time info for the component
struct icaltimetype x1, x2, temp;
struct icalcomponent *ic;
st.value = malloc(sizeof(struct icaltimetype));
et.value = malloc(sizeof(struct icaltimetype));
time(&t1); //get current time
t1 += (time_t) (60 * 60); //initial time (in this case from current time)
t2 += (time_t) (120 * 60); //duration (in this case 2hs)
ec = e_cal_component_new(); //create a new cal component
e_cal_component_set_new_vtype(ec, E_CAL_COMPONENT_EVENT); //set the type to "event"
tx.value = g_strdup("New event"); //set the text of the object to be added
tx.altrep = NULL; //set the Alternate representation URI to NULL (we don't use it now)
e_cal_component_set_summary(ec, &tx); //set the object with the information we just entered
st.tzid = (char *) strdup(tzid);
temp = icaltime_from_timet(t1, FALSE);
x1 = icaltime_convert_to_zone(temp, tzone);
st.value = &x1;
e_cal_component_set_dtstart(ec, &st); //Sets the date/time start property of the component
et.tzid = (char *) strdup(tzid);
temp = icaltime_from_timet(t2, FALSE);
x2 = icaltime_convert_to_zone(temp, tzone);
et.value = &x2;
e_cal_component_set_dtend(ec, &et); //Sets the date/time end property of a calendar component
ic = e_cal_component_get_icalcomponent(ec); //get the structure where all the cal info resides
//create the object
rv = e_cal_create_object(ecal, ic, &uid, &ge);
printf ("Error: Event not created\n");