Example #1
0
/**
 * get_uuid_from_component:
 * @source: an {@link ESource}
 * @component: an {@link ECalComponent}
 *
 * Obtains the uuid from a component in the form
 * "source_uid:event_uid:event_rid" or "source:uid:event_uid" if the
 * component doesn't hold a recurrence event
 *
 * Returns: (Transfer full) a new allocated string with the description
 **/
gchar*
get_uuid_from_component (ESource       *source,
                         ECalComponent *component)
{
  gchar *uuid;
  ECalComponentId *id;

  id = e_cal_component_get_id (component);
  if (id->rid != NULL)
    {
      uuid = g_strdup_printf ("%s:%s:%s",
                              e_source_get_uid (source),
                              id->uid,
                              id->rid);
    }
  else
    {
      uuid = g_strdup_printf ("%s:%s",
                              e_source_get_uid (source),
                              id->uid);
    }
  e_cal_component_free_id (id);

  return uuid;
}
static void
gcal_week_view_component_removed (ECalDataModelSubscriber *subscriber,
                                  ECalClient              *client,
                                  const gchar             *uid,
                                  const gchar             *rid)
{
  GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
  ESource *source;
  gchar *uuid;

  GCAL_ENTRY;

  source = e_client_get_source (E_CLIENT (client));

  if (rid != NULL)
    uuid = g_strdup_printf ("%s:%s:%s", e_source_get_uid (source), uid, rid);
  else
    uuid = g_strdup_printf ("%s:%s", e_source_get_uid (source), uid);

  gcal_week_header_remove_event (GCAL_WEEK_HEADER (self->header), uuid);
  gcal_week_grid_remove_event (GCAL_WEEK_GRID (self->week_grid), uuid);

  g_free (uuid);

  GCAL_EXIT;
}
Example #3
0
gchar *
eab_book_and_contact_list_to_string (EBookClient *book_client,
                                     const GSList *contacts)
{
	gchar *s0, *s1;

	s0 = eab_contact_list_to_string (contacts);
	if (!s0)
		s0 = g_strdup ("");

	if (book_client != NULL) {
		EClient *client;
		ESource *source;
		const gchar *uid;

		client = E_CLIENT (book_client);
		source = e_client_get_source (client);
		uid = e_source_get_uid (source);
		s1 = g_strconcat ("Book: ", uid, "\r\n", s0, NULL);
	} else
		s1 = g_strdup (s0);

	g_free (s0);
	return s1;
}
static void
calendar_appointment_init (CalendarAppointment  *appointment,
                           icalcomponent        *ical,
                           ECalClient           *cal,
                           icaltimezone         *default_zone)
{
  const char *source_uid;

  appointment->uid          = get_ical_uid (ical);
  appointment->rid          = get_ical_rid (ical);
  appointment->backend_name = get_source_backend_name (cal);
  appointment->summary      = get_ical_summary (ical);
  appointment->description  = get_ical_description (ical);
  appointment->color_string = get_source_color (cal);
  appointment->start_time   = get_ical_start_time (ical, default_zone);
  appointment->end_time     = get_ical_end_time (ical, default_zone);
  appointment->is_all_day   = get_ical_is_all_day (ical,
                                                   appointment->start_time,
                                                   default_zone);

  /* While the UID is usually enough to identify an event, only the triple
   * of (source,UID,RID) is fully unambiguous; neither may contain '\n',
   * so we can safely use it to create a unique ID from the triple
   */
  source_uid = e_source_get_uid (e_client_get_source (E_CLIENT (cal)));
  appointment->id = g_strdup_printf ("%s\n%s\n%s",
                                     source_uid,
                                     appointment->uid,
                                     appointment->rid ? appointment->rid : "");
}
static void
action_task_new_cb (GtkAction *action,
                    ETaskShellView *task_shell_view)
{
	EShellView *shell_view;
	EShellWindow *shell_window;
	ETaskShellContent *task_shell_content;
	ETaskTable *task_table;
	EClient *client = NULL;
	GSList *list;

	shell_view = E_SHELL_VIEW (task_shell_view);
	shell_window = e_shell_view_get_shell_window (shell_view);

	task_shell_content = task_shell_view->priv->task_shell_content;
	task_table = e_task_shell_content_get_task_table (task_shell_content);

	list = e_task_table_get_selected (task_table);
	if (list) {
		ECalModelComponent *comp_data;

		comp_data = list->data;
		client = g_object_ref (comp_data->client);
		g_slist_free (list);
	}

	e_cal_ops_new_component_editor (shell_window, E_CAL_CLIENT_SOURCE_TYPE_TASKS,
		client ? e_source_get_uid (e_client_get_source (client)) : NULL, FALSE);

	g_clear_object (&client);
}
static void
source_viewer_delete_button_clicked_cb (GtkButton *delete_button,
                                        ESourceViewer *viewer)
{
	ESource *source;
	const gchar *uid;

	g_return_if_fail (viewer->delete_operation == NULL);

	source = e_source_viewer_ref_selected_source (viewer);
	g_return_if_fail (source != NULL);

	uid = e_source_get_uid (source);
	gtk_label_set_text (GTK_LABEL (viewer->deleting_label), uid);

	gtk_notebook_set_current_page (
		GTK_NOTEBOOK (viewer->top_panel), PAGE_DELETING);
	gtk_widget_set_sensitive (viewer->tree_view, FALSE);

	viewer->delete_operation = g_cancellable_new ();

	e_source_remove (
		source,
		viewer->delete_operation,
		source_viewer_delete_done_cb,
		g_object_ref (viewer));

	g_object_unref (source);
}
static void
action_calendar_taskpad_new_cb (GtkAction *action,
                                ECalShellView *cal_shell_view)
{
	EShellView *shell_view;
	EShellWindow *shell_window;
	ECalShellContent *cal_shell_content;
	ECalModelComponent *comp_data;
	ETaskTable *task_table;
	GSList *list;

	shell_view = E_SHELL_VIEW (cal_shell_view);
	shell_window = e_shell_view_get_shell_window (shell_view);

	cal_shell_content = cal_shell_view->priv->cal_shell_content;
	task_table = e_cal_shell_content_get_task_table (cal_shell_content);

	list = e_task_table_get_selected (task_table);
	g_return_if_fail (list != NULL);
	comp_data = list->data;
	g_slist_free (list);

	e_cal_ops_new_component_editor (shell_window, E_CAL_CLIENT_SOURCE_TYPE_TASKS,
		e_source_get_uid (e_client_get_source (E_CLIENT (comp_data->client))), FALSE);
}
Example #8
0
/* The clients are just created here but not loaded */
static void
create_client_for_source (ESource              *source,
		          ECalClientSourceType  source_type,
		          CalendarSourceData   *source_data)
{
  ClientData *data;
  ECalClient *client;
  GError *error = NULL;

  client = g_hash_table_lookup (source_data->clients, source);
  g_return_if_fail (client == NULL);

  client = e_cal_client_new (source, source_type, &error);
  if (!client)
    {
      g_warning ("Could not load source '%s': %s",
		 e_source_get_uid (source),
		 error->message);
      g_clear_error(&error);
      return;
    }

  data = g_slice_new0 (ClientData);
  data->client = client;  /* takes ownership */
  data->backend_died_id = g_signal_connect (client,
                                            "backend-died",
                                            G_CALLBACK (backend_died_cb),
                                            source_data);

  g_hash_table_insert (source_data->clients, g_object_ref (source), data);
}
Example #9
0
static void
rename_mbox_dir (ESource *mbox_source,
                 const gchar *mail_data_dir)
{
	gchar *old_mail_dir;
	gchar *new_mail_dir;
	gboolean need_rename;
	const gchar *mbox_uid;

	mbox_uid = e_source_get_uid (mbox_source);

	old_mail_dir = g_build_filename (mail_data_dir, "local", NULL);
	new_mail_dir = g_build_filename (mail_data_dir, mbox_uid, NULL);

	/* Rename if old directory exists and new directory does not. */
	need_rename =
		g_file_test (old_mail_dir, G_FILE_TEST_EXISTS) &&
		!g_file_test (new_mail_dir, G_FILE_TEST_EXISTS);

	if (need_rename) {
		if (g_rename (old_mail_dir, new_mail_dir) == -1)
			g_warning (
				"%s: Failed to rename '%s' to '%s': %s",
				G_STRFUNC, old_mail_dir, new_mail_dir, g_strerror (errno));
	}

	g_free (old_mail_dir);
	g_free (new_mail_dir);
}
Example #10
0
GCancellable *
mail_receive_account (EMailSession *session,
                      ESource *account)
{
	CamelService *service;

	service = camel_session_ref_service (
		CAMEL_SESSION (session), e_source_get_uid(account));

	return mail_receive_service (service);
}
Example #11
0
static void
gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber,
                                  ECalClient              *client,
                                  const gchar             *uid,
                                  const gchar             *rid)
{
  GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (subscriber)->priv;
  GList *children, *l;
  ESource *source;
  gchar *uuid;
  gboolean update_sidebar_needed = FALSE;

  source = e_client_get_source (E_CLIENT (client));
  if (rid != NULL)
    uuid = g_strdup_printf ("%s:%s:%s", e_source_get_uid (source), uid, rid);
  else
    uuid = g_strdup_printf ("%s:%s", e_source_get_uid (source), uid);

  children = gtk_container_get_children (GTK_CONTAINER (priv->events_sidebar));
  for (l = children; l != NULL; l = g_list_next (l))
    {
      GcalEventWidget *child_widget = GCAL_EVENT_WIDGET (gtk_bin_get_child (GTK_BIN (l->data)));
      if (child_widget != NULL && g_strcmp0 (uuid, gcal_event_widget_peek_uuid (child_widget)) == 0)
        {
          if (g_list_length (children) == 1)
            update_sidebar_needed = TRUE;
          gtk_widget_destroy (GTK_WIDGET (l->data));
        }
    }
  g_list_free (children);
  g_free (uuid);

  if (update_sidebar_needed)
    {
      update_no_events_page (GCAL_YEAR_VIEW (subscriber));
      gtk_stack_set_visible_child_name (GTK_STACK (priv->navigator_stack), "no-events");
    }
}
Example #12
0
static void
auto_account_removed (ESourceRegistry *registry,
                      ESource *source,
                      gpointer dummy)
{
	struct _auto_data *info = g_object_get_data((GObject *)source, "mail-autoreceive");

	g_return_if_fail (info != NULL);

	if (info->timeout_id) {
		g_source_remove (info->timeout_id);
		info->timeout_id = 0;
	}
	if (data_session)
		e_mail_session_emit_account_removed (data_session, e_source_get_uid(source));		
}
static void
source_viewer_update_row (ESourceViewer *viewer,
                          ESource *source)
{
	GHashTable *source_index;
	GtkTreeRowReference *reference;
	GtkTreeModel *model;
	GtkTreePath *path;
	GtkTreeIter iter;
	const gchar *display_name;
	const gchar *source_uid;
	gboolean removable;
	gboolean writable;
	gboolean remote_creatable;
	gboolean remote_deletable;

	source_index = viewer->source_index;
	reference = g_hash_table_lookup (source_index, source);

	/* We show all sources, so the reference should be valid. */
	g_return_if_fail (gtk_tree_row_reference_valid (reference));

	model = gtk_tree_row_reference_get_model (reference);
	path = gtk_tree_row_reference_get_path (reference);
	gtk_tree_model_get_iter (model, &iter, path);
	gtk_tree_path_free (path);

	source_uid = e_source_get_uid (source);
	display_name = e_source_get_display_name (source);
	removable = e_source_get_removable (source);
	writable = e_source_get_writable (source);
	remote_creatable = e_source_get_remote_creatable (source);
	remote_deletable = e_source_get_remote_deletable (source);

	gtk_tree_store_set (
		GTK_TREE_STORE (model), &iter,
		COLUMN_DISPLAY_NAME, display_name,
		COLUMN_SOURCE_UID, source_uid,
		COLUMN_REMOVABLE, removable,
		COLUMN_WRITABLE, writable,
		COLUMN_REMOTE_CREATABLE, remote_creatable,
		COLUMN_REMOTE_DELETABLE, remote_deletable,
		COLUMN_SOURCE, source,
		-1);
}
Example #14
0
static inline void
debug_dump_ecal_list (GHashTable *clients)
{
#ifdef CALENDAR_ENABLE_DEBUG
  GList *list, *link;

  dprintf ("Loaded clients:\n");
  list = g_hash_table_get_keys (clients);
  for (link = list; link != NULL; link = g_list_next (link))
    {
      ESource *source = E_SOURCE (link->data);

      dprintf ("  %s %s\n",
	       e_source_get_uid (source),
	       e_source_get_display_name (source));
    }
#endif
}
Example #15
0
static void
auto_account_added (ESourceRegistry *registry,
                    ESource *source,
                    EMailSession *session)
{
	struct _auto_data *info;

	if (!e_source_get_enabled(source))
		return;

	info = g_malloc0 (sizeof (*info));
	info->account = source;
	info->session = g_object_ref (session);
	g_object_set_data_full (
		G_OBJECT (source), "mail-autoreceive", info,
		(GDestroyNotify) auto_account_finalized);
	auto_account_commit (info);
	if (data_session)
		e_mail_session_emit_account_added (data_session, e_source_get_uid(source));	
}
static void
cursor_data_source_added (ESourceRegistry *registry,
                          ESource *source,
                          gpointer data)
{
	GError    *error = NULL;
	GMainLoop *loop = (GMainLoop *) data;

	if (g_strcmp0 (e_source_get_uid (source), CURSOR_DATA_SOURCE_ID) != 0)
		return;

	/* Open the address book */
	address_book = (EBookClient *) e_book_client_connect_sync (source, 30, NULL, &error);
	if (!address_book)
		g_error ("Unable to create the test book: %s", error->message);

	address_book_source = g_object_ref (source);

	if (loop)
		g_main_loop_quit (loop);
}
Example #17
0
static CamelService *
ref_default_transport (EMailSession *session)
{
	ESource *source;
	CamelService *service;
	const gchar *extension_name;
	const gchar *uid;

	source = e_source_registry_ref_default_mail_identity (source_registry);

	if (source == NULL)
		return NULL;

	extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
	if (e_source_has_extension (source, extension_name)) {
		ESourceMailSubmission *extension;
		gchar *uid;

		extension = e_source_get_extension (source, extension_name);
		uid = e_source_mail_submission_dup_transport_uid (extension);

		g_object_unref (source);
		source = e_source_registry_ref_source (source_registry, uid);

		g_free (uid);
	} else {
		g_object_unref (source);
		source = NULL;
	}

	if (source == NULL)
		return NULL;

	uid = e_source_get_uid (source);
	service = camel_session_ref_service (CAMEL_SESSION (session), uid);

	g_object_unref (source);

	return service;
}
Example #18
0
static gboolean
auto_timeout (gpointer data)
{
	EMailSession *session;
	struct _auto_data *info = data;
	CamelService *service;
	const char *uid;

	session = info->session;
	uid = e_source_get_uid (info->account);
	
	service = camel_session_ref_service (
		CAMEL_SESSION (session), uid);
	printf("Timeout for %s: %p\n", uid, service);
	g_return_val_if_fail (CAMEL_IS_SERVICE (service), TRUE);


	if (camel_session_get_online (CAMEL_SESSION (session)))
		mail_receive_service (service);

	return TRUE;
}
static void
memo_shell_content_table_foreach_cb (gint model_row,
                                     gpointer user_data)
{
	ECalModelComponent *comp_data;
	icalcomponent *clone;
	icalcomponent *vcal;
	gchar *string;

	struct {
		ECalModel *model;
		GSList *list;
	} *foreach_data = user_data;

	comp_data = e_cal_model_get_component_at (
		foreach_data->model, model_row);

	vcal = e_cal_util_new_top_level ();
	clone = icalcomponent_new_clone (comp_data->icalcomp);
	e_cal_util_add_timezones_from_component (vcal, comp_data->icalcomp);
	icalcomponent_add_component (vcal, clone);

	/* String is owned by libical; do not free. */
	string = icalcomponent_as_ical_string (vcal);
	if (string != NULL) {
		ESource *source;
		const gchar *source_uid;

		source = e_client_get_source (E_CLIENT (comp_data->client));
		source_uid = e_source_get_uid (source);

		foreach_data->list = g_slist_prepend (
			foreach_data->list,
			g_strdup_printf ("%s\n%s", source_uid, string));
	}

	icalcomponent_free (vcal);
}
static void
source_viewer_selection_changed_cb (GtkTreeSelection *selection,
                                    ESourceViewer *viewer)
{
	ESource *source;
	const gchar *uid = NULL;
	gboolean removable = FALSE;

	source = e_source_viewer_ref_selected_source (viewer);

	source_viewer_set_text (viewer, source);

	if (source != NULL) {
		uid = e_source_get_uid (source);
		removable = e_source_get_removable (source);
	}

	gtk_label_set_text (GTK_LABEL (viewer->viewing_label), uid);
	gtk_widget_set_visible (viewer->delete_button, removable);

	if (source != NULL)
		g_object_unref (source);
}
Example #21
0
gint
main (gint argc,
      gchar *argv[])
{
	CamelSession *session;
	CamelService *service;
	ESourceRegistry *registry;
	GList *list, *link;
	const gchar *extension_name;

	g_type_init ();
	
	system ("rm -rf /tmp/test-map");
	camel_init ("/tmp/test-map", TRUE);
	e_source_camel_register_types ();

	session = g_object_new (
		CAMEL_TYPE_SESSION,
		"user-data-dir", "/tmp/test-map", 
		"user-cache-dir", "/tmp/test-map/cache", NULL);


	/* Browse through the ESource registry to find out the MAP account */
	registry = e_source_registry_new_sync (NULL, NULL);
	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
	list = e_source_registry_list_sources (registry, extension_name);

	for (link = list; link != NULL; link = g_list_next (link)) {
		ESource *source = E_SOURCE (link->data);
		const gchar *uid;
		const gchar *backend_name = "INVALID";
		const gchar *display_name;
		ESourceBackend *extension;
		
		if (!e_source_get_enabled (source))
			continue;
		uid = e_source_get_uid (source);
		display_name = e_source_get_display_name (source);
		printf("Looking for: %s\n", display_name);

		extension = e_source_get_extension (source, extension_name);
		backend_name = e_source_backend_get_backend_name (extension);

		if (strcmp (backend_name, "map") == 0) {
			/* Lets add just map backend to the session. */
			CamelFolderInfo *info;
			CamelFolder *folder;
			GPtrArray *uids;
			int i;
			GError *error=NULL;
			service = camel_session_add_service (
				CAMEL_SESSION (session), uid,
				backend_name, CAMEL_PROVIDER_STORE, NULL);
			e_source_camel_configure_service (source, service);
			camel_service_connect_sync (service, NULL, NULL);
			info = camel_store_get_folder_info_sync (
				CAMEL_STORE (service), "", 0, NULL, NULL);
			print_folder_info (info, 0);
			folder = camel_store_get_folder_sync (
				CAMEL_STORE (service), "inbox", 0, NULL, NULL);
			camel_folder_refresh_info_sync (folder, NULL, &error);
			if (error)
				printf("Refresh info failed: %s\n", error->message);

			uids = camel_folder_get_uids (folder);
			printf("Length of messages: %p %d\n", folder, uids->len);
			for (i=0; i<uids->len; i++)
				printf("UID: %s\n", (char *)uids->pdata[i]);
		}
		


	}
	
	return 0;
}
Example #22
0
static void
do_save_calendar_rdf (FormatHandler *handler,
                      ESourceSelector *selector,
                      ECalClientSourceType type,
                      gchar *dest_uri)
{

	/*
	 * According to some documentation about CSV, newlines 'are' allowed
	 * in CSV-files. But you 'do' have to put the value between quotes.
	 * The helper 'string_needsquotes' will check for that
	 *
	 * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
	 * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl
	 */

	ESource *primary_source;
	EClient *source_client;
	GError *error = NULL;
	GSList *objects = NULL;
	gchar *temp = NULL;
	GOutputStream *stream;

	if (!dest_uri)
		return;

	/* open source client */
	primary_source = e_source_selector_ref_primary_selection (selector);
	source_client = e_cal_client_connect_sync (
		primary_source, type, NULL, &error);
	g_object_unref (primary_source);

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

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

	stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error);

	if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) {
		GSList *iter;

		xmlBufferPtr buffer = xmlBufferCreate ();
		xmlDocPtr doc = xmlNewDoc ((xmlChar *) "1.0");
		xmlNodePtr fnode;

		doc->children = xmlNewDocNode (doc, NULL, (const guchar *)"rdf:RDF", NULL);
		xmlSetProp (doc->children, (const guchar *)"xmlns:rdf", (const guchar *)"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
		xmlSetProp (doc->children, (const guchar *)"xmlns", (const guchar *)"http://www.w3.org/2002/12/cal/ical#");

		fnode = xmlNewChild (doc->children, NULL, (const guchar *)"Vcalendar", NULL);

		/* Should Evolution publicise these? */
		xmlSetProp (fnode, (const guchar *)"xmlns:x-wr", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#");
		xmlSetProp (fnode, (const guchar *)"xmlns:x-lic", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#");

		/* Not sure if it's correct like this */
		xmlNewChild (fnode, NULL, (const guchar *)"prodid", (const guchar *)"-//" PACKAGE_STRING "//iCal 1.0//EN");

		/* Assuming GREGORIAN is the only supported calendar scale */
		xmlNewChild (fnode, NULL, (const guchar *)"calscale", (const guchar *)"GREGORIAN");

		temp = calendar_config_get_timezone ();
		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:timezone", (guchar *) temp);
		g_free (temp);

		xmlNewChild (fnode, NULL, (const guchar *)"method", (const guchar *)"PUBLISH");

		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:relcalid", (guchar *) e_source_get_uid (primary_source));

		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:calname", (guchar *) e_source_get_display_name (primary_source));

		/* Version of this RDF-format */
		xmlNewChild (fnode, NULL, (const guchar *)"version", (const guchar *)"2.0");

		for (iter = objects; iter; iter = iter->next) {
			ECalComponent *comp = iter->data;
			const gchar *temp_constchar;
			gchar *tmp_str = NULL;
			GSList *temp_list;
			ECalComponentDateTime temp_dt;
			struct icaltimetype *temp_time;
			gint *temp_int;
			ECalComponentText temp_comptext;
			xmlNodePtr c_node = xmlNewChild (fnode, NULL, (const guchar *)"component", NULL);
			xmlNodePtr node = xmlNewChild (c_node, NULL, (const guchar *)"Vevent", NULL);

			/* Getting the stuff */
			e_cal_component_get_uid (comp, &temp_constchar);
			tmp_str = g_strdup_printf ("#%s", temp_constchar);
			xmlSetProp (node, (const guchar *)"about", (guchar *) tmp_str);
			g_free (tmp_str);
			add_string_to_rdf (node, "uid",temp_constchar);

			e_cal_component_get_summary (comp, &temp_comptext);
			add_string_to_rdf (node, "summary", temp_comptext.value);

			e_cal_component_get_description_list (comp, &temp_list);
			add_list_to_rdf (node, "description", temp_list, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_categories_list (comp, &temp_list);
			add_list_to_rdf (node, "categories", temp_list, CONSTCHAR);
			if (temp_list)
				e_cal_component_free_categories_list (temp_list);

			e_cal_component_get_comment_list (comp, &temp_list);
			add_list_to_rdf (node, "comment", temp_list, ECALCOMPONENTTEXT);

			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_completed (comp, &temp_time);
			add_time_to_rdf (node, "completed", temp_time);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_created (comp, &temp_time);
			add_time_to_rdf (node, "created", temp_time);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_contact_list (comp, &temp_list);
			add_list_to_rdf (node, "contact", temp_list, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_dtstart (comp, &temp_dt);
			add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_dtend (comp, &temp_dt);
			add_time_to_rdf (node, "dtend", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_due (comp, &temp_dt);
			add_time_to_rdf (node, "due", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_percent (comp, &temp_int);
			add_nummeric_to_rdf (node, "percentComplete", temp_int);

			e_cal_component_get_priority (comp, &temp_int);
			add_nummeric_to_rdf (node, "priority", temp_int);

			e_cal_component_get_url (comp, &temp_constchar);
			add_string_to_rdf (node, "URL", temp_constchar);

			if (e_cal_component_has_attendees (comp)) {
				e_cal_component_get_attendee_list (comp, &temp_list);
				add_list_to_rdf (node, "attendee", temp_list, ECALCOMPONENTATTENDEE);
				if (temp_list)
					e_cal_component_free_attendee_list (temp_list);
			}

			e_cal_component_get_location (comp, &temp_constchar);
			add_string_to_rdf (node, "location", temp_constchar);

			e_cal_component_get_last_modified (comp, &temp_time);
			add_time_to_rdf (node, "lastModified",temp_time);

			/* Important note!
			 * The documentation is not requiring this!
			 *
			 * if (temp_time) e_cal_component_free_icaltimetype (temp_time);
			 *
			 * Please uncomment and fix documentation if untrue
			 * http://www.gnome.org/projects/evolution/developer-doc/libecal/ECalComponent.html
			 *	#e-cal-component-get-last-modified
			 */
		}

		/* I used a buffer rather than xmlDocDump: I want gio support */
		xmlNodeDump (buffer, doc, doc->children, 2, 1);

		g_output_stream_write_all (stream, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL, NULL, &error);
		g_output_stream_close (stream, NULL, NULL);

		e_cal_client_free_ecalcomp_slist (objects);

		xmlBufferFree (buffer);
		xmlFreeDoc (doc);
	}

	if (stream)
		g_object_unref (stream);

	g_object_unref (source_client);

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
	}
}
static void
app_load_events (App *app)
{
  GList *clients;
  GList *l;
  GList *ll;
  gchar *since_iso8601;
  gchar *until_iso8601;

  /* out with the old */
  g_hash_table_remove_all (app->appointments);
  /* nuke existing views */
  for (ll = app->live_views; ll != NULL; ll = ll->next)
    {
      ECalClientView *view = E_CAL_CLIENT_VIEW (ll->data);
      g_signal_handlers_disconnect_by_func (view, on_objects_added, app);
      g_signal_handlers_disconnect_by_func (view, on_objects_modified, app);
      g_signal_handlers_disconnect_by_func (view, on_objects_removed, app);
      e_cal_client_view_stop (view, NULL);
      g_object_unref (view);
    }
  g_list_free (app->live_views);
  app->live_views = NULL;

  /* timezone could have changed */
  app_update_timezone (app);

  since_iso8601 = isodate_from_time_t (app->since);
  until_iso8601 = isodate_from_time_t (app->until);

  print_debug ("Loading events since %s until %s",
               since_iso8601,
               until_iso8601);

  clients = calendar_sources_get_appointment_clients (app->sources);
  for (l = clients; l != NULL; l = l->next)
    {
      ECalClient *cal = E_CAL_CLIENT (l->data);
      GError *error;
      gchar *query;
      GSList *objects, *j;
      ECalClientView *view;

      e_cal_client_set_default_timezone (cal, app->zone);

      error = NULL;
      if (!e_client_open_sync (E_CLIENT (cal), TRUE, NULL, &error))
        {
          ESource *source = e_client_get_source (E_CLIENT (cal));
          g_warning ("Error opening calendar %s: %s\n",
		     e_source_get_uid (source), error->message);
          g_error_free (error);
          continue;
        }

      query = g_strdup_printf ("occur-in-time-range? (make-time \"%s\") "
                               "(make-time \"%s\")",
                               since_iso8601,
                               until_iso8601);
      error = NULL;
      objects = NULL;
      if (!e_cal_client_get_object_list_sync (cal,
					      query,
					      &objects,
					      NULL, /* cancellable */
					      &error))
        {
          ESource *source = e_client_get_source (E_CLIENT (cal));
          g_warning ("Error querying calendar %s: %s\n",
		     e_source_get_uid (source), error->message);
          g_error_free (error);
          g_free (query);
          continue;
        }

      for (j = objects; j != NULL; j = j->next)
        {
          icalcomponent *ical = j->data;
          CalendarAppointment *appointment;

          appointment = calendar_appointment_new (ical, cal, app->zone);
          if (appointment == NULL)
            continue;

          calendar_appointment_generate_occurrences (appointment,
                                                     ical,
                                                     cal,
                                                     app->since,
                                                     app->until,
                                                     app->zone);
          g_hash_table_insert (app->appointments, g_strdup (appointment->uid), appointment);
        }

      e_cal_client_free_icalcomp_slist (objects);

      error = NULL;
      if (!e_cal_client_get_view_sync (cal,
				       query,
				       &view,
				       NULL, /* cancellable */
				       &error))
        {
          g_warning ("Error setting up live-query on calendar: %s\n", error->message);
          g_error_free (error);
        }
      else
        {
          g_signal_connect (view,
                            "objects-added",
                            G_CALLBACK (on_objects_added),
                            app);
          g_signal_connect (view,
                            "objects-modified",
                            G_CALLBACK (on_objects_modified),
                            app);
          g_signal_connect (view,
                            "objects-removed",
                            G_CALLBACK (on_objects_removed),
                            app);
          e_cal_client_view_start (view, NULL);
          app->live_views = g_list_prepend (app->live_views, view);
        }

      g_free (query);
    }
  g_list_free (clients);
  g_free (since_iso8601);
  g_free (until_iso8601);
  app->cache_invalid = FALSE;
}
Example #24
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;
}
Example #25
0
static gboolean
migrate_mbox_to_maildir (EShell *shell,
                         CamelSession *session,
                         ESource *mbox_source)
{
	ESourceRegistry *registry;
	ESourceExtension *extension;
	const gchar *extension_name;
	CamelService *mbox_service = NULL;
	CamelService *maildir_service = NULL;
	CamelSettings *settings;
	const gchar *data_dir;
	const gchar *mbox_uid;
	gchar *path;
	struct MigrateStore ms;
	GThread *thread;
	GError *error = NULL;

	registry = e_shell_get_registry (shell);

	data_dir = camel_session_get_user_data_dir (session);

	mbox_uid = e_source_get_uid (mbox_source);
	e_source_set_display_name (mbox_source, "local_mbox");

	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
	extension = e_source_get_extension (mbox_source, extension_name);

	e_source_backend_set_backend_name (
		E_SOURCE_BACKEND (extension), "mbox");

	extension_name = e_source_camel_get_extension_name ("mbox");
	extension = e_source_get_extension (mbox_source, extension_name);
	settings = e_source_camel_get_settings (E_SOURCE_CAMEL (extension));

	path = g_build_filename (data_dir, mbox_uid, NULL);
	g_object_set (settings, "path", path, NULL);
	g_free (path);

	e_source_registry_commit_source_sync (
		registry, mbox_source, NULL, &error);

	if (error == NULL)
		mbox_service = camel_session_add_service (
			session, mbox_uid, "mbox",
			CAMEL_PROVIDER_STORE, &error);

	if (error == NULL)
		maildir_service = camel_session_add_service (
			session, "local", "maildir",
			CAMEL_PROVIDER_STORE, &error);

	if (error != NULL) {
		if (mbox_service != NULL)
			g_object_unref (mbox_service);
		if (maildir_service != NULL)
			g_object_unref (maildir_service);
		g_warning ("%s: %s", G_STRFUNC, error->message);
		g_error_free (error);
		return FALSE;
	}

	g_return_val_if_fail (CAMEL_IS_STORE (mbox_service), FALSE);
	g_return_val_if_fail (CAMEL_IS_STORE (maildir_service), FALSE);

	camel_service_set_settings (mbox_service, settings);

	settings = camel_service_ref_settings (maildir_service);

	path = g_build_filename (data_dir, "local", NULL);
	g_object_set (settings, "path", path, NULL);
	if (g_mkdir (path, 0700) == -1)
		g_warning (
			"%s: Failed to make directory '%s': %s",
			G_STRFUNC, path, g_strerror (errno));
	g_free (path);

	g_object_unref (settings);

	ms.mail_store = CAMEL_STORE (mbox_service);
	ms.maildir_store = CAMEL_STORE (maildir_service);
	ms.session = session;
	ms.complete = FALSE;

	thread = g_thread_new (NULL, (GThreadFunc) migrate_stores, &ms);
	/* coverity[loop_condition] */
	while (!ms.complete)
		g_main_context_iteration (NULL, TRUE);

	g_object_unref (mbox_service);
	g_object_unref (maildir_service);
	g_thread_unref (thread);

	return TRUE;
}
Example #26
0
GCancellable *
mail_send (EMailSession *session)
{
	CamelFolder *local_outbox;
	CamelService *service;
	struct _send_info *info;
	struct _send_data *data;
	send_info_t type = SEND_INVALID;
	const gchar *transport_uid;
	ESource *account;
	const gchar *extension_name;

	account = e_source_registry_ref_default_mail_identity (source_registry);

	if (account == NULL)
		return NULL;

	extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
	if (e_source_has_extension (account, extension_name)) {
		ESourceMailSubmission *extension;
		gchar *uid;

		extension = e_source_get_extension (account, extension_name);
		uid = e_source_mail_submission_dup_transport_uid (extension);

		g_object_unref (account);
		account = e_source_registry_ref_source (source_registry, uid);

		g_free (uid);
	} else {
		g_object_unref (account);
		account = NULL;
	}

	if (account == NULL)
		return NULL;

	transport_uid = e_source_get_uid (account);

	data = setup_send_data (session);
	info = g_hash_table_lookup (data->active, SEND_URI_KEY);
	if (info != NULL) {
		info->again++;
		d(printf("send of %s still in progress\n", transport_uid));
		return info->cancellable;
	}

	service = camel_session_ref_service (
		CAMEL_SESSION (session), transport_uid);
	if (!CAMEL_IS_TRANSPORT (service)) {
 		return NULL;
	}

	d(printf("starting non-interactive send of '%s'\n", account->transport->url));
	type = get_receive_type (service);

	if (type == SEND_INVALID) {
		return NULL;
	}

	info = g_malloc0 (sizeof (*info));
	info->type = SEND_SEND;
	info->session = g_object_ref (session);
	info->service = g_object_ref (service);
	info->keep_on_server = FALSE;
	info->cancellable = camel_operation_new();
	info->data = data;
	info->state = SEND_ACTIVE;
	info->timeout_id = 0;

	d(printf("Adding new info %p\n", info));

	g_hash_table_insert (data->active, g_strdup(SEND_URI_KEY), info);

	/* todo, store the folder in info? */
	local_outbox =
		e_mail_session_get_local_folder (
		session, E_MAIL_LOCAL_FOLDER_OUTBOX);

	mail_send_queue (
		session, local_outbox,
		CAMEL_TRANSPORT (service),
		E_FILTER_SOURCE_OUTGOING,
		info->cancellable,
		receive_get_folder, info,
		receive_status, info,
		send_done, info);

	return info->cancellable;
}
Example #27
0
static struct _send_data *
build_infra (EMailSession *session, gboolean allow_send)
{
	struct _send_data *data;
	struct _send_info *info;
	CamelService *transport = NULL;
	GList *link;
	GList *list = NULL;
	GList *accounts=NULL;

	transport = ref_default_transport (session);

	accounts = mail_get_all_accounts();

	data = setup_send_data (session);

	link = accounts;
	while (link) {
		ESource *source;
		CamelService *service;
		const gchar *uid;

		
		source = (ESource *)link->data;
		if (!e_source_get_enabled(source)) {
			link = link->next;
			continue;
		}

		uid = e_source_get_uid (source);
		service = camel_session_ref_service (
			CAMEL_SESSION (session), uid);

		/* see if we have an outstanding download active */
		info = g_hash_table_lookup (data->active, uid);
		if (info == NULL) {
			send_info_t type = SEND_INVALID;

			type = get_receive_type (service);

			if (type == SEND_INVALID || type == SEND_SEND) {
				link = link->next;
				continue;
			}

			info = g_malloc0 (sizeof (*info));
			info->type = type;
			info->session = g_object_ref (session);

			d(printf("adding source %s\n", source->url));
			info->service = g_object_ref (service);
			info->keep_on_server = mail_get_keep_on_server (service);
			info->cancellable = camel_operation_new ();
			info->state = allow_send ? SEND_ACTIVE : SEND_COMPLETE;
			info->timeout_id = g_timeout_add (
				STATUS_TIMEOUT, operation_status_timeout, info);

			g_signal_connect (
				info->cancellable, "status",
				G_CALLBACK (operation_status), info);

			g_hash_table_insert (
				data->active, g_strdup(uid), info);
			list = g_list_prepend (list, info);

		} else if (info->timeout_id == 0)
			info->timeout_id = g_timeout_add (
				STATUS_TIMEOUT, operation_status_timeout, info);

		info->data = data;

		link = link->next;
	}

	g_list_free_full (accounts, (GDestroyNotify) g_object_unref);


	/* Skip displaying the SMTP row if we've got no outbox,
	 * outgoing account or unsent mails. */
	CamelFolder *local_outbox;
	local_outbox =
		e_mail_session_get_local_folder (
		session, E_MAIL_LOCAL_FOLDER_OUTBOX);
	
	if (allow_send && local_outbox && CAMEL_IS_TRANSPORT (transport)
	 && (camel_folder_get_message_count (local_outbox) -
		camel_folder_get_deleted_message_count (local_outbox)) != 0) {
		info = g_hash_table_lookup (data->active, SEND_URI_KEY);
		if (info == NULL) {
			info = g_malloc0 (sizeof (*info));
			info->type = SEND_SEND;

			info->service = g_object_ref (transport);
			info->keep_on_server = FALSE;
			info->cancellable = camel_operation_new ();
			info->state = SEND_ACTIVE;
			info->timeout_id = g_timeout_add (
				STATUS_TIMEOUT, operation_status_timeout, info);

			g_signal_connect (
				info->cancellable, "status",
				G_CALLBACK (operation_status), info);

			g_hash_table_insert (data->active, g_strdup(SEND_URI_KEY), info);
			list = g_list_prepend (list, info);
		} else if (info->timeout_id == 0)
			info->timeout_id = g_timeout_add (
				STATUS_TIMEOUT, operation_status_timeout, info);

		info->data = data;

	}

	data->infos = list;

	return data;
}