static gboolean
deserialize (ScalixObject * object, const char *string)
{
    ScalixAppointmentPrivate *priv;
    icalcomponent *icomp, *subcomp;
    icalcomponent_kind kind;
    icaltimezone *zone;

    priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object));

    icomp = icalparser_parse_string (string);

    if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) {
        g_warning ("No VCALENAR while deserializing! (%s)\n", string);
        icalcomponent_free (icomp);
        return FALSE;
    }

    /* Grab the timezone if any */
    subcomp = icalcomponent_get_first_component (icomp,
                                                 ICAL_VTIMEZONE_COMPONENT);
    if (subcomp != NULL) {
        zone = icaltimezone_new ();
        icalcomponent_remove_component (icomp, subcomp);
        if (icaltimezone_set_component (zone, subcomp))
            priv->timezone = zone;
    }

    kind = ICAL_VEVENT_COMPONENT;
    /* Grab the main VEVENT */
    subcomp = icalcomponent_get_first_component (icomp, kind);

    if (subcomp == NULL) {
        icalcomponent_free (icomp);
        return FALSE;
    }

    icalcomponent_remove_component (icomp, subcomp);
    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp);
    e_cal_component_commit_sequence (E_CAL_COMPONENT (object));

    priv->exceptions = NULL;
    while ((subcomp = icalcomponent_get_next_component (icomp, kind))) {
        icalcomponent_remove_component (icomp, subcomp);
        priv->exceptions = g_slist_prepend (priv->exceptions, subcomp);
    }

    icalcomponent_free (icomp);

    return TRUE;
}
Esempio n. 2
0
/* This removes all components except VTODOs and VTIMEZONEs from the toplevel
   icalcomponent, and adds the given list of VTODO components. The list is
   freed afterwards. */
static void
prepare_tasks (icalcomponent *icalcomp, GList *vtodos)
{
	icalcomponent *subcomp;
	GList *elem;
	icalcompiter iter;

	iter = icalcomponent_begin_component (icalcomp, ICAL_ANY_COMPONENT);
	while ((subcomp = icalcompiter_deref (&iter)) != NULL) {
		icalcomponent_kind child_kind = icalcomponent_isa (subcomp);
		if (child_kind != ICAL_VTODO_COMPONENT
		    && child_kind != ICAL_VTIMEZONE_COMPONENT) {
			icalcompiter_next (&iter);
			icalcomponent_remove_component (icalcomp, subcomp);
			icalcomponent_free (subcomp);
		} else {
			icalcompiter_next (&iter);
		}
	}

	for (elem = vtodos; elem; elem = elem->next) {
		icalcomponent_add_component (icalcomp, elem->data);
	}
	g_list_free (vtodos);
}
Esempio n. 3
0
/* This removes all components except VEVENTs and VTIMEZONEs from the toplevel */
static void
prepare_events (icalcomponent *icalcomp, GList **vtodos)
{
	icalcomponent *subcomp;
	icalcompiter iter;

	if (vtodos)
		*vtodos = NULL;

	iter = icalcomponent_begin_component (icalcomp, ICAL_ANY_COMPONENT);
	while ((subcomp = icalcompiter_deref (&iter)) != NULL) {
		icalcomponent_kind child_kind = icalcomponent_isa (subcomp);
		if (child_kind != ICAL_VEVENT_COMPONENT
		    && child_kind != ICAL_VTIMEZONE_COMPONENT) {

			icalcompiter_next (&iter);

			icalcomponent_remove_component (icalcomp, subcomp);
			if (child_kind == ICAL_VTODO_COMPONENT && vtodos)
				*vtodos = g_list_prepend (*vtodos, subcomp);
			else
                                icalcomponent_free (subcomp);
		} else {
			icalcompiter_next (&iter);
		}
	}
}
/** Loads the builtin VTIMEZONE data for the given timezone. */
static void
icaltimezone_load_builtin_timezone	(icaltimezone	*zone)
{
    char *filename;
    unsigned int filename_len;
    FILE *fp;
    icalparser *parser;
    icalcomponent *comp, *subcomp;

	    /* If the location isn't set, it isn't a builtin timezone. */
    if (!zone->location || !zone->location[0])
	return;

    filename_len = strlen (get_zone_directory()) + strlen (zone->location) + 6;

    filename = (char*) malloc (filename_len);
    if (!filename) {
	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
	return;
    }

    snprintf (filename, filename_len, "%s/%s.ics", get_zone_directory(),
	      zone->location);

    fp = fopen (filename, "r");
    free (filename);
    if (!fp) {
	icalerror_set_errno(ICAL_FILE_ERROR);
	return;
    }

	
	/* ##### B.# Sun, 11 Nov 2001 04:04:29 +1100 
	this is where the MALFORMEDDATA error is being set, after the call to 'icalparser_parse'
	fprintf(stderr, "** WARNING ** %s: %d %s\n", __FILE__, __LINE__, icalerror_strerror(icalerrno));
	*/

    parser = icalparser_new ();
	icalparser_set_gen_data (parser, fp);
	comp = icalparser_parse (parser, icaltimezone_load_get_line_fn);
    icalparser_free (parser);
	fclose (fp);

	
	
    /* Find the VTIMEZONE component inside the VCALENDAR. There should be 1. */
    subcomp = icalcomponent_get_first_component (comp,
						 ICAL_VTIMEZONE_COMPONENT);
    if (!subcomp) {
	icalerror_set_errno(ICAL_PARSE_ERROR);
	return;
    }

    icaltimezone_get_vtimezone_properties (zone, subcomp);

	icalcomponent_remove_component(comp,subcomp);

	icalcomponent_free(comp);

}
Esempio n. 5
0
icalerrorenum icalcluster_remove_component(icalcluster *impl, icalcomponent* child) {

	icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR);
	icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR);

	icalcomponent_remove_component(impl->data,child);
	icalcluster_mark(impl);

	return ICAL_NO_ERROR;
}
Esempio n. 6
0
icalerrorenum icalbdbset_remove_component(icalset *set, icalcomponent *child)
{
    icalbdbset *bset = (icalbdbset *) set;

    icalerror_check_arg_re((bset != 0), "bset", ICAL_BADARG_ERROR);
    icalerror_check_arg_re((child != 0), "child", ICAL_BADARG_ERROR);

    icalcomponent_remove_component(bset->cluster, child);

    icalbdbset_mark(set);

    return ICAL_NO_ERROR;
}
Esempio n. 7
0
void icalcomponent_remove_invitee(icalcomponent *comp, icalproperty *prop)
{
    if (icalcomponent_isa(comp) == ICAL_VPOLL_COMPONENT) {
        icalcomponent *vvoter = icalproperty_get_parent(prop);

        icalcomponent_remove_component(comp, vvoter);
        icalcomponent_free(vvoter);
    }
    else {
        icalcomponent_remove_property(comp, prop);
        icalproperty_free(prop);
    }
}
void remove_vevent_sub_components(icalcomponent* comp){
    
    icalcomponent *c, *next;

    for( c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT);
	 c != 0;
	 c = next)
    {
	next  = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT);

	icalcomponent_remove_component(comp,c);

	do_something(c);
    }

}
Esempio n. 9
0
void MainWindow::saveToIcsFile(icalcomponent *comp, std::string uid)
{
    icalset* file = icalfileset_new("/home/quentin/Public/test.ics");
    icalfileset *fset = (icalfileset*) file;

    icalcomponent* old = fetch(file, uid.c_str());
    if (old != NULL)
    {
        icalcomponent_remove_component(icalcomponent_get_first_component(fset->cluster, ICAL_ANY_COMPONENT), old);
    }

    icalcomponent_add_component(icalcomponent_get_first_component(fset->cluster, ICAL_ANY_COMPONENT), comp);

    icalfileset_mark(file);

    icalfileset_commit(file);
    icalfileset_free(file);
}
Esempio n. 10
0
static gboolean
scalix_appointment_from_string (ScalixObject * object, const char *string)
{
    icalcomponent *icomp, *subcomp;

    icomp = icalparser_parse_string (string);
    if (icalcomponent_isa (icomp) == ICAL_VCALENDAR_COMPONENT) {
        subcomp = icalcomponent_get_first_component (icomp,
                                                     ICAL_VEVENT_COMPONENT);
        icalcomponent_remove_component (icomp, subcomp);
        icalcomponent_free (icomp);
        icomp = subcomp;

    }

    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), icomp);

    return TRUE;
}
Esempio n. 11
0
void delete_event(icalcomponent* calendar)
{
  icalcomponent* event = find_event(calendar);
   
  if (!yes_no_prompt("Are you sure you want to delete this event? (y/n"))
  {
    return;
  }
  
  //Find the event in the components
  icalcomponent* c = icalcomponent_get_first_component(calendar, ICAL_VEVENT_COMPONENT);
  
  bool found_event = false;
  
  while((c=icalcomponent_get_current_component(c)) != 0 )
  { 
    if(icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT)
    {
      if (c == event)
      {
        icalcomponent_remove_component(calendar, c);
        found_event = true;
      }
    }else
    { 
      icalcomponent_get_next_component(calendar, ICAL_VEVENT_COMPONENT); 
    }
  }
  
  if (!found_event)
  {
    append_action_to_closed_log("Delete event", false);
    return;
  }
  
  append_action_to_closed_log("Delete event", true);
}