Logo Search packages:      
Sourcecode: libical version File versions  Download package

icalspanlist* icalspanlist_new ( icalset *  set,
struct icaltimetype  start,
struct icaltimetype  end 
)

Constructor Make a free list from a set of component. Start and end should be in UTC.

Constructor Make a free list from a set of component. Start and end should be in UTC.

Parameters:
set A valid icalset containing VEVENTS
start The free list starts at this date/time
end The free list ends at this date/time
Returns:
A spanlist corresponding to the VEVENTS
Given a set of components, a start time and an end time return a spanlist that contains the free/busy times.

Definition at line 111 of file icalspanlist.c.

References icaltime_span::end, icaltime_span::is_busy, and icaltime_span::start.

{
    struct icaltime_span range;
    pvl_elem itr;
    icalcomponent *c,*inner;
    icalcomponent_kind kind, inner_kind;
    icalspanlist *sl; 
    struct icaltime_span *freetime;

    if ( ( sl = (struct icalspanlist_impl*)
         malloc(sizeof(struct icalspanlist_impl))) == 0) {
      icalerror_set_errno(ICAL_NEWFAILED_ERROR);
      return 0;
    }

    sl->spans =  pvl_newlist();
    sl->start =  start;
    sl->end   =  end;

    range.start = icaltime_as_timet(start);
    range.end = icaltime_as_timet(end);

    /* Get a list of spans of busy time from the events in the set
       and order the spans based on the start time */

   for(c = icalset_get_first_component(set);
      c != 0;
      c = icalset_get_next_component(set)){

       kind  = icalcomponent_isa(c);
       inner = icalcomponent_get_inner(c);

       if(!inner){
         continue;
       }

       inner_kind = icalcomponent_isa(inner);

       if( kind != ICAL_VEVENT_COMPONENT &&
         inner_kind != ICAL_VEVENT_COMPONENT){
         continue;
       }
       
       icalerror_clear_errno();
       
       icalcomponent_foreach_recurrence(c, start, end, 
                              icalspanlist_new_callback, 
                              (void*)sl);
       
   }
    
    /* Now Fill in the free time spans. loop through the spans. if the
       start of the range is not within the span, create a free entry
       that runs from the start of the range to the start of the
       span. */

     for( itr = pvl_head(sl->spans);
       itr != 0;
       itr = pvl_next(itr))
    {
      struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr);

      if ((freetime=(struct icaltime_span *)
           malloc(sizeof(struct icaltime_span))) == 0){
          icalerror_set_errno(ICAL_NEWFAILED_ERROR);
          return 0;
          }

      if(range.start < s->start){
          freetime->start = range.start; 
          freetime->end = s->start;
          
          freetime->is_busy = 0;


          pvl_insert_ordered(sl->spans,compare_span,(void*)freetime);
      } else {
          free(freetime);
      }
      
      range.start = s->end;
    }
     
     /* If the end of the range is null, then assume that everything
        after the last item in the calendar is open and add a span
        that indicates this */

     if( icaltime_is_null_time(end)){
       struct icaltime_span* last_span;

       last_span = (struct icaltime_span*)pvl_data(pvl_tail(sl->spans));

       if (last_span != 0){

           if ((freetime=(struct icaltime_span *)
              malloc(sizeof(struct icaltime_span))) == 0){
             icalerror_set_errno(ICAL_NEWFAILED_ERROR);
             return 0;
           }      
      
           freetime->is_busy = 0;
           freetime->start = last_span->end;
           freetime->end = freetime->start;
           pvl_insert_ordered(sl->spans,compare_span,(void*)freetime);
       }
     }


     return sl;
}


Generated by  Doxygen 1.6.0   Back to index