/**
 * 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;
}
static gchar *
get_source_backend_name (ECalClient *esource)
{
  ESource *source;
  ECalClientSourceType source_type;
  ESourceBackend *extension;
  const gchar *extension_name;

  g_return_val_if_fail (E_IS_CAL_CLIENT (esource), NULL);

  source = e_client_get_source (E_CLIENT (esource));
  source_type = e_cal_client_get_source_type (esource);

  switch (source_type)
    {
      case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
        extension_name = E_SOURCE_EXTENSION_CALENDAR;
        break;
      case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
        extension_name = E_SOURCE_EXTENSION_TASK_LIST;
        break;
      default:
        g_return_val_if_reached (NULL);
    }

  extension = e_source_get_extension (source, extension_name);

  return e_source_backend_dup_backend_name (extension);
}
/* synchronously in idle with main-loop running */
static gboolean
test_sync_in_idle (gpointer user_data)
{
	ECalClient *cal_client = user_data;
	icalcomponent *icalcomp;

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

	if (!test_sync (cal_client)) {
		stop_main_loop (1);
		return FALSE;
	}

	icalcomp = create_object ();
	if (!icalcomp) {
		stop_main_loop (1);
		return FALSE;
	}

	e_cal_client_send_objects (cal_client, icalcomp, NULL, async_send_result_ready, NULL);

	icalcomponent_free (icalcomp);

	return FALSE;
}
Ejemplo n.º 4
0
static ECompEditor *
get_component_editor (EShell *shell,
                      ECalClient *client,
                      ECalComponent *comp,
                      gboolean is_new,
                      GError **error)
{
	ECompEditorFlags flags = 0;
	ECompEditor *comp_editor = NULL;
	ESourceRegistry *registry;

	g_return_val_if_fail (E_IS_SHELL (shell), NULL);
	g_return_val_if_fail (E_IS_CAL_CLIENT (client), NULL);
	g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);

	registry = e_shell_get_registry (shell);

	if (is_new) {
		flags |= E_COMP_EDITOR_FLAG_IS_NEW;
	} else {
		comp_editor = e_comp_editor_find_existing_for (
			e_client_get_source (E_CLIENT (client)),
			e_cal_component_get_icalcomponent (comp));
	}

	if (!comp_editor) {
		if (itip_organizer_is_user (registry, comp, client))
			flags |= E_COMP_EDITOR_FLAG_ORGANIZER_IS_USER;
		if (e_cal_component_has_attendees (comp))
			flags |= E_COMP_EDITOR_FLAG_WITH_ATTENDEES;

		comp_editor = e_comp_editor_open_for_component (NULL,
			shell, e_client_get_source (E_CLIENT (client)),
			e_cal_component_get_icalcomponent (comp), flags);

		if (comp_editor) {
			/* request save for new events */
			e_comp_editor_set_changed (comp_editor, is_new);
		}
	}

	return comp_editor;
}
/* synchronously in idle with main-loop running */
static gboolean
test_sync_in_idle (gpointer user_data)
{
	ECalClient *cal_client = user_data;

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

	if (!test_sync (cal_client)) {
		stop_main_loop (1);
		return FALSE;
	}

	g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (cal_client)) ? "yes" : "no");

	e_client_refresh (E_CLIENT (cal_client), NULL, async_refresh_result_ready, NULL);

	return FALSE;
}
/* synchronously in idle with main-loop running */
static gboolean
test_sync_in_idle (gpointer user_data)
{
	ECalClient *cal_client = user_data;
	const gchar *uid;

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

	if (!test_sync (cal_client)) {
		stop_main_loop (1);
		return FALSE;
	}

	uid = g_object_get_data (G_OBJECT (cal_client), "use-uid");

	e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, NULL);

	return FALSE;
}
Ejemplo n.º 7
0
/* Stores information about actually shown component and
 * returns whether component in the preview changed */
static gboolean
update_comp_info (ECalComponentPreview *preview,
                  ECalClient *client,
                  ECalComponent *comp,
                  icaltimezone *zone,
                  gboolean use_24_hour_format)
{
	ECalComponentPreviewPrivate *priv;
	gboolean changed;

	g_return_val_if_fail (preview != NULL, TRUE);
	g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), TRUE);

	priv = preview->priv;

	if (!E_IS_CAL_COMPONENT (comp) || !E_IS_CAL_CLIENT (client)) {
		changed = !priv->cal_uid;
		clear_comp_info (preview);
	} else {
		ESource *source;
		const gchar *uid;
		gchar *cal_uid;
		gchar *comp_uid;
		struct icaltimetype comp_last_modified, *itm = NULL;
		gint *sequence = NULL;
		gint comp_sequence;

		source = e_client_get_source (E_CLIENT (client));
		cal_uid = g_strdup (e_source_get_uid (source));
		e_cal_component_get_uid (comp, &uid);
		comp_uid = g_strdup (uid);
		e_cal_component_get_last_modified (comp, &itm);
		if (itm) {
			comp_last_modified = *itm;
			e_cal_component_free_icaltimetype (itm);
		} else
			comp_last_modified = icaltime_null_time ();
		e_cal_component_get_sequence (comp, &sequence);
		if (sequence) {
			comp_sequence = *sequence;
			e_cal_component_free_sequence (sequence);
		} else
			comp_sequence = 0;

		changed = !priv->cal_uid || !priv->comp_uid || !cal_uid || !comp_uid ||
			  !g_str_equal (priv->cal_uid, cal_uid) ||
			  !g_str_equal (priv->comp_uid, comp_uid) ||
			  priv->comp_sequence != comp_sequence ||
			  icaltime_compare (priv->comp_last_modified, comp_last_modified) != 0;

		clear_comp_info (preview);

		priv->cal_uid = cal_uid;
		priv->comp_uid = comp_uid;
		priv->comp_sequence = comp_sequence;
		priv->comp_last_modified = comp_last_modified;

		priv->comp = g_object_ref (comp);
		priv->client = g_object_ref (client);
		priv->timezone = icaltimezone_copy (zone);
		priv->use_24_hour_format = use_24_hour_format;
	}

	return changed;
}
Ejemplo n.º 8
0
static CompEditor *
get_component_editor (EShell *shell,
                      ECalClient *client,
                      ECalComponent *comp,
                      gboolean is_new,
                      GError **error)
{
	ECalComponentId *id;
	CompEditorFlags flags = 0;
	CompEditor *editor = NULL;
	ESourceRegistry *registry;

	g_return_val_if_fail (E_IS_SHELL (shell), NULL);
	g_return_val_if_fail (E_IS_CAL_CLIENT (client), NULL);
	g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);

	registry = e_shell_get_registry (shell);

	id = e_cal_component_get_id (comp);
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (id->uid != NULL, NULL);

	if (is_new) {
		flags |= COMP_EDITOR_NEW_ITEM;
	} else {
		editor = comp_editor_find_instance (id->uid);
	}

	if (!editor) {
		if (itip_organizer_is_user (registry, comp, client))
			flags |= COMP_EDITOR_USER_ORG;

		switch (e_cal_component_get_vtype (comp)) {
		case E_CAL_COMPONENT_EVENT:
			if (e_cal_component_has_attendees (comp))
				flags |= COMP_EDITOR_MEETING;

			editor = event_editor_new (client, shell, flags);

			if (flags & COMP_EDITOR_MEETING)
				event_editor_show_meeting (EVENT_EDITOR (editor));
			break;
		case E_CAL_COMPONENT_TODO:
			if (e_cal_component_has_attendees (comp))
				flags |= COMP_EDITOR_IS_ASSIGNED;

			editor = task_editor_new (client, shell, flags);

			if (flags & COMP_EDITOR_IS_ASSIGNED)
				task_editor_show_assignment (TASK_EDITOR (editor));
			break;
		case E_CAL_COMPONENT_JOURNAL:
			if (e_cal_component_has_organizer (comp))
				flags |= COMP_EDITOR_IS_SHARED;

			editor = memo_editor_new (client, shell, flags);
			break;
		default:
			g_warn_if_reached ();
			break;
		}

		if (editor) {
			comp_editor_edit_comp (editor, comp);

			/* request save for new events */
			comp_editor_set_changed (editor, is_new);
		}
	}

	e_cal_component_free_id (id);

	return editor;
}