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

icalerrorenum icaldirset_add_component ( icalset *  set,
icalcomponent *  comp 
)

This assumes that the top level component is a VCALENDAR, and there is an inner component of type VEVENT, VTODO or VJOURNAL. The inner component must have a DSTAMP property

Definition at line 421 of file icaldirset.c.

{
    char clustername[ICAL_PATH_MAX];
    icalproperty *dt = 0;
    icalvalue *v;
    struct icaltimetype tm;
    icalerrorenum error = ICAL_NO_ERROR;
    icalcomponent *inner;
    icaldirset *dset = (icaldirset*) set;

    icalerror_check_arg_rz( (dset!=0), "dset");
    icalerror_check_arg_rz( (comp!=0), "comp");

    icaldirset_add_uid(comp);

    /* Determine which cluster this object belongs in. This is a HACK */

    for(inner = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
      inner != 0;
      inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
  
      dt = icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY);
      
      if (dt != 0)
          break; 
      }     

    if (dt == 0) {
      for(inner = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
          inner != 0;
          inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
          
          dt = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
          
        if (dt != 0)
            break; 
          } 
      }

    if (dt == 0){
      icalerror_warn("The component does not have a DTSTAMP or DTSTART property, so it cannot be added to the store");
      icalerror_set_errno(ICAL_BADARG_ERROR);
      return ICAL_BADARG_ERROR;
    }

    v = icalproperty_get_value(dt);
    tm = icalvalue_get_datetime(v);

    snprintf(clustername,ICAL_PATH_MAX,"%s/%04d%02d",dset->dir, tm.year, tm.month);

    /* Load the cluster and insert the object */
    if(dset->cluster != 0 && 
       strcmp(clustername,icalcluster_key(dset->cluster)) != 0 ){
      icalcluster_free(dset->cluster);
      dset->cluster = 0;
    }

    if (dset->cluster == 0){
      dset->cluster = icalfileset_produce_icalcluster(clustername);

      if (dset->cluster == 0){
          error = icalerrno;
      }
    }
    
    if (error != ICAL_NO_ERROR){
      icalerror_set_errno(error);
      return error;
    }

    /* Add the component to the cluster */
    icalcluster_add_component(dset->cluster,comp);
    
    /* icalcluster_mark(impl->cluster); */

    return ICAL_NO_ERROR;    
}


Generated by  Doxygen 1.6.0   Back to index