Ejemplo n.º 1
0
static void
insert_tz_comps (icalparameter *param,
                 gpointer cb_data)
{
	const gchar *tzid;
	CompTzData *tdata = cb_data;
	icaltimezone *zone = NULL;
	icalcomponent *tzcomp;
	GError *error = NULL;

	tzid = icalparameter_get_tzid (param);

	if (g_hash_table_lookup (tdata->zones, tzid))
		return;

	e_cal_client_get_timezone_sync (
		tdata->client, tzid, &zone, NULL, &error);

	if (error != NULL) {
		g_warning (
			"Could not get the timezone information for %s: %s",
			tzid, error->message);
		g_error_free (error);
		return;
	}

	tzcomp = icalcomponent_new_clone (icaltimezone_get_component (zone));
	g_hash_table_insert (tdata->zones, (gpointer) tzid, (gpointer) tzcomp);
}
/**
 * e_cal_client_tzlookup:
 * @tzid: ID of the timezone to lookup
 * @ecalclient: must be a valid #ECalClient pointer
 * @cancellable: an optional #GCancellable to use, or %NULL
 * @error: an error description in case of a failure
 *
 * An implementation of the tzlookup callback which clients
 * can use. Calls e_cal_client_get_timezone_sync().
 *
 * Returns: A timezone object, or %NULL on failure. This object is owned
 *   by the @ecalclient, thus do not free it.
 *
 * Since: 3.2
 */
icaltimezone *
e_cal_client_tzlookup (const gchar *tzid,
                       gconstpointer ecalclient,
                       GCancellable *cancellable,
                       GError **error)
{
	ECalClient *cal_client = (ECalClient *) ecalclient;
	icaltimezone *zone = NULL;
	GError *local_error = NULL;

	g_return_val_if_fail (cal_client != NULL, NULL);
	g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), NULL);

	if (e_cal_client_get_timezone_sync (cal_client, tzid, &zone, cancellable, &local_error)) {
		g_warn_if_fail (local_error == NULL);
		return zone;
	}

	if (g_error_matches (local_error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND)) {
		/* We had to trigger this error to check for the
		 * timezone existance, clear it and return NULL. */
		g_clear_error (&local_error);
	}

	if (local_error)
		g_propagate_error (error, local_error);

	return NULL;
}
Ejemplo n.º 3
0
/* Converts a time_t to a string, relative to the specified timezone */
static gchar *
timet_to_str_with_zone (ECalComponentDateTime *dt,
                        ECalClient *client,
                        icaltimezone *default_zone,
                        gboolean use_24_hour_format)
{
	struct icaltimetype itt;
	icaltimezone *zone = NULL;
	struct tm tm;
	gchar buf[256];

	if (dt->tzid != NULL) {
		e_cal_client_get_timezone_sync (
			client, dt->tzid, &zone, NULL, NULL);
	} else if (dt->value->is_utc) {
		zone = icaltimezone_get_utc_timezone ();
	}

	itt = *dt->value;
	if (zone != NULL)
		icaltimezone_convert_time (&itt, zone, default_zone);
	tm = icaltimetype_to_tm (&itt);

	e_time_format_date_and_time (
		&tm, use_24_hour_format,
		FALSE, FALSE, buf, sizeof (buf));

	return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
}
static icaltimezone *
resolve_timezone_id (const char *tzid,
                     ECalClient *source)
{
  icaltimezone *retval;

  retval = icaltimezone_get_builtin_timezone_from_tzid (tzid);
  if (!retval)
    {
      e_cal_client_get_timezone_sync (source, tzid, &retval, NULL, NULL);
    }

  return retval;
}
static gboolean
cal_searching_got_instance_cb (ECalComponent *comp,
                               time_t instance_start,
                               time_t instance_end,
                               gpointer user_data)
{
	struct GenerateInstancesData *gid = user_data;
	ECalShellViewPrivate *priv;
	ECalComponentDateTime dt;
	time_t *value;

	g_return_val_if_fail (gid != NULL, FALSE);

	if (g_cancellable_is_cancelled (gid->cancellable))
		return FALSE;

	g_return_val_if_fail (gid->cal_shell_view != NULL, FALSE);
	g_return_val_if_fail (gid->cal_shell_view->priv != NULL, FALSE);

	e_cal_component_get_dtstart (comp, &dt);

	if (dt.tzid && dt.value) {
		icaltimezone *zone = NULL;

		e_cal_client_get_timezone_sync (
			gid->client, dt.tzid, &zone, gid->cancellable, NULL);

		if (g_cancellable_is_cancelled (gid->cancellable))
			return FALSE;

		if (zone)
			instance_start = icaltime_as_timet_with_zone (*dt.value, zone);
	}

	e_cal_component_free_datetime (&dt);

	priv = gid->cal_shell_view->priv;
	value = g_new (time_t, 1);
	*value = instance_start;
	if (!g_slist_find_custom (priv->search_hit_cache, value, cal_time_t_ptr_compare))
		priv->search_hit_cache = g_slist_append (priv->search_hit_cache, value);
	else
		g_free (value);

	return TRUE;
}
Ejemplo n.º 6
0
/* Converts a time_t to a string, relative to the specified timezone */
static gchar *
timet_to_str_with_zone (ECalComponentDateTime *dt,
                        ECalClient *client,
                        icaltimezone *default_zone)
{
	struct icaltimetype itt;
	icaltimezone *zone = NULL;
	struct tm tm;

	if (dt->tzid != NULL) {
		e_cal_client_get_timezone_sync (
			client, dt->tzid, &zone, NULL, NULL);
	} else if (dt->value->is_utc) {
		zone = icaltimezone_get_utc_timezone ();
	}

	itt = *dt->value;
	if (zone != NULL)
		icaltimezone_convert_time (&itt, zone, default_zone);
	tm = icaltimetype_to_tm (&itt);

	return e_datetime_format_format_tm ("calendar", "table", itt.is_date ? DTFormatKindDate : DTFormatKindDateTime, &tm);
}
Ejemplo n.º 7
0
static ECellDateEditValue *
get_dtend (ECalModelCalendar *model,
           ECalModelComponent *comp_data)
{
	struct icaltimetype tt_end;

	if (!comp_data->dtend) {
		icalproperty *prop;
		icaltimezone *zone = NULL, *model_zone = NULL;
		gboolean got_zone = FALSE;

		prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTEND_PROPERTY);
		if (!prop)
			return NULL;

		tt_end = icalproperty_get_dtend (prop);

		if (icaltime_get_tzid (tt_end)
		    && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_end), &zone, NULL, NULL))
			got_zone = TRUE;

		model_zone = e_cal_model_get_timezone (E_CAL_MODEL (model));

		if (got_zone) {
			tt_end = icaltime_from_timet_with_zone (comp_data->instance_end, tt_end.is_date, zone);
			if (model_zone)
				icaltimezone_convert_time (&tt_end, zone, model_zone);
		} else {
			tt_end = icaltime_from_timet_with_zone (
				comp_data->instance_end,
				tt_end.is_date, model_zone);
		}

		if (!icaltime_is_valid_time (tt_end) || icaltime_is_null_time (tt_end))
			return NULL;

		if (tt_end.is_date && icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY)) {
			struct icaltimetype tt_start;
			icaltimezone *start_zone = NULL;
			gboolean got_start_zone = FALSE;

			tt_start = icalproperty_get_dtstart (prop);

			if (icaltime_get_tzid (tt_start)
			    && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_start), &start_zone, NULL, NULL))
				got_start_zone = TRUE;

			if (got_start_zone) {
				tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, start_zone);
				if (model_zone)
					icaltimezone_convert_time (&tt_start, start_zone, model_zone);
			} else {
				tt_start = icaltime_from_timet_with_zone (
					comp_data->instance_start,
					tt_start.is_date, model_zone);
			}

			icaltime_adjust (&tt_start, 1, 0, 0, 0);

			/* Decrease by a day only if the DTSTART will still be before, or the same as, DTEND */
			if (icaltime_compare (tt_start, tt_end) <= 0)
				icaltime_adjust (&tt_end, -1, 0, 0, 0);
		}

		comp_data->dtend = g_new0 (ECellDateEditValue, 1);
		comp_data->dtend->tt = tt_end;

		if (got_zone)
			comp_data->dtend->zone = zone;
		else
			comp_data->dtend->zone = NULL;
	}

	return e_cal_model_copy_cell_date_value (comp_data->dtend);
}