コード例 #1
0
/**
 * e_cal_util_add_timezones_from_component:
 * @vcal_comp: A VCALENDAR component.
 * @icalcomp: An iCalendar component, of any type.
 *
 * Adds VTIMEZONE components to a VCALENDAR for all tzid's
 * in the given @icalcomp.
 */
void
e_cal_util_add_timezones_from_component (icalcomponent *vcal_comp,
                                         icalcomponent *icalcomp)
{
	ForeachTzidData f_data;

	g_return_if_fail (vcal_comp != NULL);
	g_return_if_fail (icalcomp != NULL);

	f_data.vcal_comp = vcal_comp;
	f_data.icalcomp = icalcomp;
	icalcomponent_foreach_tzid (icalcomp, add_timezone_cb, &f_data);
}
コード例 #2
0
GSList* EDSCalendarStorage::toICalComponentsList(const std::vector<std::string> & iCals,
                                                 const OpenAB::PIMItem::IDs& ids,
                                                 std::vector<icaltimezone*>& timezones)
{
  GSList * events = NULL;

  currentEventTimeZones.clear();
  for(unsigned int i = 0; i < iCals.size(); ++i)
  {
    std::stringstream ss(iCals[i]);

    //In case of recurring events one iCalendar can contain couple of VEVENT objects, get them all
    while (1)
    {
      std::string event = EDSCalendarStorageCommon::cutVObject(ss);

      if (event.empty())
      {
        break;
      }

      icalcomponent* newEvent = icalcomponent_new_from_string(event.c_str());
      if (!newEvent)
      {
        LOG_DEBUG() << "Cannot parse vevent" << std::endl;
        g_slist_free_full(events, (GDestroyNotify) icalcomponent_free);
        return NULL;
      }

      icalcomponent_foreach_tzid(newEvent, EDSCalendarStorage::findTimeZonesCb, newEvent);
      icalcomponent_strip_errors(newEvent);
      if (ids.size() > i)
        icalcomponent_set_uid(newEvent, ids[i].c_str());

      events = g_slist_append(events, newEvent);
    }
  }

  std::set<std::string>::iterator it;
  for(it = currentEventTimeZones.begin(); it != currentEventTimeZones.end(); ++it)
  {
    icaltimezone* tz = icaltimezone_get_builtin_timezone((*it).c_str());
    if (tz)
    {
      timezones.push_back(tz);
    }
  }

  return events;
}
コード例 #3
0
ファイル: ical-format.c プロジェクト: Distrotech/evolution
static void
do_save_calendar_ical (FormatHandler *handler,
                       ESourceSelector *selector,
		       EClientCache *client_cache,
                       gchar *dest_uri)
{
	ESource *primary_source;
	EClient *source_client;
	GError *error = NULL;
	GSList *objects = NULL;
	icalcomponent *top_level = NULL;

	if (!dest_uri)
		return;

	/* open source client */
	primary_source = e_source_selector_ref_primary_selection (selector);
	source_client = e_client_cache_get_client_sync (client_cache,
		primary_source, e_source_selector_get_extension_name (selector), 30, NULL, &error);
	g_object_unref (primary_source);

	/* Sanity check. */
	g_return_if_fail (
		((source_client != NULL) && (error == NULL)) ||
		((source_client == NULL) && (error != NULL)));

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
		return;
	}

	/* create destination file */
	top_level = e_cal_util_new_top_level ();

	e_cal_client_get_object_list_sync (
		E_CAL_CLIENT (source_client), "#t", &objects, NULL, &error);

	if (objects != NULL) {
		CompTzData tdata;
		GOutputStream *stream;
		GSList *iter;

		tdata.zones = g_hash_table_new (g_str_hash, g_str_equal);
		tdata.client = E_CAL_CLIENT (source_client);

		for (iter = objects; iter; iter = iter->next) {
			icalcomponent *icalcomp = icalcomponent_new_clone (iter->data);

			icalcomponent_foreach_tzid (icalcomp, insert_tz_comps, &tdata);
			icalcomponent_add_component (top_level, icalcomp);
		}

		g_hash_table_foreach (tdata.zones, (GHFunc) append_tz_to_comp, top_level);

		g_hash_table_destroy (tdata.zones);
		tdata.zones = NULL;

		/* save the file */
		stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error);

		if (stream) {
			gchar *ical_str = icalcomponent_as_ical_string_r (top_level);

			g_output_stream_write_all (stream, ical_str, strlen (ical_str), NULL, NULL, &error);
			g_output_stream_close (stream, NULL, NULL);

			g_object_unref (stream);
			g_free (ical_str);
		}

		e_cal_client_free_icalcomp_slist (objects);
	}

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
	}

	/* terminate */
	g_object_unref (source_client);
	icalcomponent_free (top_level);
}