Solved

Adding a calendar event to Evolution programatically (Linux)

Posted on 2008-10-26
2
345 Views
Last Modified: 2008-10-26
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)?

thanks
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;
       gboolean rv;
       char *uid;
       GError *ge;
 
       st.value = malloc(sizeof(struct icaltimetype));
       et.value = malloc(sizeof(struct icaltimetype));
   
       time(&t1);  //get current time
       time(&t2);
       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
       
       //add alarm
       add_alarm(ec);  
       
       //create the object
       rv = e_cal_create_object(ecal, ic, &uid, &ge);
       if (!rv)
       {
          printf ("Error: Event not created\n");
       }
}

Open in new window

0
Comment
Question by:urif
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
urif earned 0 total points
ID: 22806540
ok, i found this snippet. now i am passing 2 time_t as follow to set the start and end date/time to Nov 9, 2008 12:00 pm and Nov 9, 2008 14:00 (for start and end times respectively):

       struct tm timestart;
       struct tm timeend;
       time_t res1, res2;

       timestart.tm_year = 2008 - 1900;
       timestart.tm_mon = 11 - 1;
       timestart.tm_mday = 9;
       timestart.tm_hour = 12;
       timestart.tm_min = 00;
       timestart.tm_sec = 00;
       timestart.tm_isdst = -1;
       res1 = mktime ( &timestart );

       timeend.tm_year = 2008 - 1900;
       timeend.tm_mon = 11 - 1;
       timeend.tm_mday = 9;
       timeend.tm_hour = 14;
       timeend.tm_min = 00;
       timeend.tm_sec = 00;
       timeend.tm_isdst = -1;
       res2 = mktime ( &timeend );


the snippet adds the object to the calendar but it always adds it with 2 hrs difference, so in this case if i wanted to start at 12 pm it adds it as 10 pm. if i set it with daylight time saving then it's 3 hrs....

is this an evolution problem? or the OS clock? if yes, then is this constant? can i just add a +2 to the value?

thanks
void addobj(time_t start, time_t end, char *summary)
{
    ECalComponent *ec;
    ECalComponentText tx;
    ECalComponentDateTime st, et;
    struct icaltimetype x1, x2, temp;
    struct icalcomponent *ic;
    gboolean rv;
    GError *ge;
    char *uid;
 
    st.value = malloc(sizeof(struct icaltimetype));
    et.value = malloc(sizeof(struct icaltimetype));
 
    ec = e_cal_component_new();
    e_cal_component_set_new_vtype(ec, E_CAL_COMPONENT_EVENT);
    
    tx.value = g_strdup(summary ? summary : "Unknown description");
    tx.altrep = NULL;
    e_cal_component_set_summary(ec, &tx);
    
    st.tzid = (char *) strdup(tzid);
    temp = icaltime_from_timet(start, FALSE);
    
    x1 = icaltime_convert_to_zone(temp, tzone);
    st.value = &x1;
    e_cal_component_set_dtstart(ec, &st);
    
    et.tzid = (char *) strdup(tzid);
    temp = icaltime_from_timet(end, FALSE);
    
    x2 = icaltime_convert_to_zone(temp, tzone);
    et.value = &x2;
    e_cal_component_set_dtend(ec, &et);
    
    ic = (icalcomponent *) e_cal_component_get_icalcomponent(ec);
    rv = e_cal_create_object(ecal, (icalcomponent*)ic, &uid, &ge);
    
    if (rv) 
    {
       printf ("yes on rv\n");
    } 
    else 
    {
       printf ("no on rv\n");
    }
}

Open in new window

0
 

Author Comment

by:urif
ID: 22806586
oh, never mind it's because of the UTC that i was setting...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question