Logo Search packages:      
Sourcecode: libical version File versions

icalspanlist* icalspanlist_from_vfreebusy ( icalcomponent *  comp  ) 

Construct an icalspanlist from a VFREEBUSY component.

Construct an icalspanlist from a VFREEBUSY component.

Parameters:
c A valid icalcomponent.
Returns:
A valid icalspanlist or NULL if no VFREEBUSY section.

Todo:
calculate start/end limits.. fill in holes?

Definition at line 516 of file icalspanlist.c.

References icaltime_span::end, icaltimezone_get_utc_timezone(), icaltime_span::is_busy, and icaltime_span::start.

{
  icalcomponent *inner;
  icalproperty  *prop;
  icalspanlist  *sl;

  icalerror_check_arg_rz((comp != NULL), "comp");
  
  inner = icalcomponent_get_inner(comp);
  if (!inner) return NULL;

  if ( ( sl = (icalspanlist*) malloc(sizeof(icalspanlist))) == 0) {
    icalerror_set_errno(ICAL_NEWFAILED_ERROR);
    return 0;
  }
  sl->spans =  pvl_newlist();

  /* cycle through each FREEBUSY property, adding to the spanlist */
  for (prop = icalcomponent_get_first_property(inner, ICAL_FREEBUSY_PROPERTY);
       prop != NULL;
       prop = icalcomponent_get_next_property(inner, ICAL_FREEBUSY_PROPERTY)) {
    icaltime_span *s = (icaltime_span *) malloc(sizeof(icaltime_span));
    icalparameter *param;
    struct icalperiodtype period;
    icalparameter_fbtype fbtype;

    if (s == 0) {
      icalerror_set_errno(ICAL_NEWFAILED_ERROR);
      return 0;
    }
    
    param = icalproperty_get_first_parameter(prop, ICAL_FBTYPE_PARAMETER);
    fbtype = (param) ? icalparameter_get_fbtype(param) : ICAL_FBTYPE_BUSY;

    switch (fbtype) {
    case ICAL_FBTYPE_FREE:
    case ICAL_FBTYPE_NONE:
    case ICAL_FBTYPE_X:
      s->is_busy = 1;
    default:
      s->is_busy = 0;
    }
    
    period = icalproperty_get_freebusy(prop);
    s->start = icaltime_as_timet_with_zone(period.start, icaltimezone_get_utc_timezone());
    s->end = icaltime_as_timet_with_zone(period.end, icaltimezone_get_utc_timezone());
;
    pvl_insert_ordered(sl->spans, compare_span, (void*)s);
  }
  /** @todo calculate start/end limits.. fill in holes? **/
  return sl;
}


Generated by  Doxygen 1.6.0   Back to index