Esempio n. 1
0
static void
ical_import (EImport *ei,
             EImportTarget *target,
             EImportImporter *im)
{
	gchar *filename;
	gchar *contents;
	icalcomponent *icalcomp;
	EImportTargetURI *s = (EImportTargetURI *) target;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (!filename) {
		e_import_complete (ei, target);
		return;
	}

	if (!g_file_get_contents (filename, &contents, NULL, NULL)) {
		g_free (filename);
		e_import_complete (ei, target);
		return;
	}
	g_free (filename);

	icalcomp = e_cal_util_parse_ics_string (contents);
	g_free (contents);

	if (icalcomp)
		ivcal_import (ei, target, icalcomp);
	else
		e_import_complete (ei, target);
}
Esempio n. 2
0
static void
csv_import (EImport *ei,
            EImportTarget *target,
            EImportImporter *im)
{
	CSVImporter *gci;
	ESource *source;
	gchar *filename;
	FILE *file;
	gint errn;
	EImportTargetURI *s = (EImportTargetURI *) target;
	GError *error = NULL;

	filename = g_filename_from_uri (s->uri_src, NULL, &error);
	if (filename == NULL) {
		e_import_complete (ei, target, error);
		g_clear_error (&error);

		return;
	}

	file = g_fopen (filename, "r");
	errn = errno;
	g_free (filename);

	if (file == NULL) {
		error = g_error_new_literal (G_IO_ERROR, g_io_error_from_errno (errn), _("Can’t open .csv file"));
		e_import_complete (ei, target, error);
		g_clear_error (&error);

		return;
	}

	gci = g_malloc0 (sizeof (*gci));
	g_datalist_set_data (&target->data, "csv-data", gci);
	gci->import = g_object_ref (ei);
	gci->target = target;
	gci->file = file;
	gci->fields_map = NULL;
	gci->count = 0;
	fseek (file, 0, SEEK_END);
	gci->size = ftell (file);
	fseek (file, 0, SEEK_SET);

	source = g_datalist_get_data (&target->data, "csv-source");

	e_book_client_connect (source, 30, NULL, book_client_connect_cb, gci);
}
static void
vcard_import (EImport *ei,
              EImportTarget *target,
              EImportImporter *im)
{
	VCardImporter *gci;
	ESource *source;
	EImportTargetURI *s = (EImportTargetURI *) target;
	gchar *filename;
	gchar *contents;
	VCardEncoding encoding;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename == NULL) {
		g_message(G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
		e_import_complete (ei, target);
		return;
	}
	encoding = guess_vcard_encoding (filename);
	if (encoding == VCARD_ENCODING_NONE) {
		g_free (filename);
		/* This check is superfluous, we've already
		 * checked otherwise we can't get here ... */
		e_import_complete (ei, target);
		return;
	}

	if (!g_file_get_contents (filename, &contents, NULL, NULL)) {
		g_message (G_STRLOC ":Couldn't read file.");
		g_free (filename);
		e_import_complete (ei, target);
		return;
	}

	g_free (filename);
	gci = g_malloc0 (sizeof (*gci));
	g_datalist_set_data(&target->data, "vcard-data", gci);
	gci->import = g_object_ref (ei);
	gci->target = target;
	gci->encoding = encoding;
	gci->contents = contents;

	source = g_datalist_get_data (&target->data, "vcard-source");

	e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
		e_client_utils_authenticate_handler, NULL,
		book_loaded_cb, gci);
}
Esempio n. 4
0
static void
gc_import_events (ECalClient *cal_client,
                  const GError *error,
                  ICalIntelligentImporter *ici)
{
	g_return_if_fail (ici != NULL);

	if (error != NULL) {
		g_warning (
			"%s: Failed to open events calendar: %s",
			G_STRFUNC, error->message);
		if (ici->tasks)
			open_default_source (
				ici, E_CAL_CLIENT_SOURCE_TYPE_TASKS,
				gc_import_tasks);
		else
			e_import_complete (ici->ei, ici->target);
		return;
	}

	e_import_status (ici->ei, ici->target, _("Importing..."), 0);

	update_objects (
		cal_client, ici->icalcomp, ici->cancellable,
		ici->tasks ? continue_tasks_cb : continue_done_cb, ici);
}
Esempio n. 5
0
static void
elm_import(EImport *ei, EImportTarget *target, EImportImporter *im)
{
	if (GPOINTER_TO_INT(g_datalist_get_data(&target->data, "elm-do-mail")))
		mail_importer_elm_import(ei, target);
	else
		e_import_complete(ei, target);
}
Esempio n. 6
0
static void
continue_done_cb (gpointer user_data)
{
	ICalIntelligentImporter *ici = user_data;

	g_return_if_fail (ici != NULL);

	e_import_complete (ici->ei, ici->target);
}
Esempio n. 7
0
static void
pine_import (EImport *ei,
             EImportTarget *target,
             EImportImporter *im)
{
	if (GPOINTER_TO_INT (g_datalist_get_data (&target->data, "pine-do-mail"))
	    || GPOINTER_TO_INT (g_datalist_get_data (&target->data, "pine-do-addr")))
		mail_importer_pine_import (ei, target);
	else
		e_import_complete (ei, target, NULL);
}
Esempio n. 8
0
static void
ivcal_import_done (ICalImporter *ici)
{
	if (ici->cal_client)
		g_object_unref (ici->cal_client);
	icalcomponent_free (ici->icalcomp);

	e_import_complete (ici->import, ici->target);
	g_object_unref (ici->import);
	g_object_unref (ici->cancellable);
	g_free (ici);
}
static void
mbox_import_done(void *data, CamelException *ex)
{
	MboxImporter *importer = data;

	g_source_remove(importer->status_timeout_id);
	g_free(importer->status_what);
	g_mutex_free(importer->status_lock);
	camel_operation_unref(importer->cancel);

	e_import_complete(importer->import, importer->target);
	g_free(importer);
}
Esempio n. 10
0
static void
vcal_import (EImport *ei,
             EImportTarget *target,
             EImportImporter *im)
{
	gchar *filename;
	icalcomponent *icalcomp;
	EImportTargetURI *s = (EImportTargetURI *) target;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (!filename) {
		e_import_complete (ei, target);
		return;
	}

	icalcomp = load_vcalendar_file (filename);
	g_free (filename);
	if (icalcomp)
		ivcal_import (ei, target, icalcomp);
	else
		e_import_complete (ei, target);
}
Esempio n. 11
0
static void
vcard_import_done (VCardImporter *gci)
{
	if (gci->idle_id)
		g_source_remove (gci->idle_id);

	g_free (gci->contents);
	g_object_unref (gci->book_client);
	e_client_util_free_object_slist (gci->contactlist);

	e_import_complete (gci->import, gci->target);
	g_object_unref (gci->import);
	g_free (gci);
}
static void
mbox_import_done (gpointer data,
                  GError **error)
{
	MboxImporter *importer = data;

	g_source_remove (importer->status_timeout_id);
	g_free (importer->status_what);
	g_mutex_clear (&importer->status_lock);
	g_object_unref (importer->cancellable);

	e_import_complete (importer->import, importer->target, error ? *error : NULL);
	g_free (importer);
}
Esempio n. 13
0
static void
gnome_calendar_import (EImport *ei,
                       EImportTarget *target,
                       EImportImporter *im)
{
	icalcomponent *icalcomp = NULL;
	gchar *filename;
	gint do_calendar, do_tasks;
	ICalIntelligentImporter *ici;

	/* This is pretty shitty, everything runs in the gui thread and can block
	 * for quite some time */

	do_calendar = GPOINTER_TO_INT (g_datalist_get_data (&target->data, "gnomecal-do-cal"));
	do_tasks = GPOINTER_TO_INT (g_datalist_get_data (&target->data, "gnomecal-do-tasks"));

	/* If neither is selected, just return. */
	if (!do_calendar && !do_tasks)
		return;

	/* Load the Gnome Calendar file and convert to iCalendar. */
	filename = g_build_filename (g_get_home_dir (), "user-cal.vcf", NULL);
	icalcomp = load_vcalendar_file (filename);
	g_free (filename);

	/* If we couldn't load the file, just return. FIXME: Error message? */
	if (icalcomp) {
		ici = g_malloc0 (sizeof (*ici));
		ici->ei = ei;
		ici->target = target;
		ici->cancellable = g_cancellable_new ();
		ici->icalcomp = icalcomp;

		g_datalist_set_data_full (&target->data, "gnomecal-data", ici, free_ici);

		prepare_events (ici->icalcomp, &ici->tasks);
		if (do_calendar) {
			open_default_source (ici, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, gc_import_events);
			return;
		}

		prepare_tasks (ici->icalcomp, ici->tasks);
		if (do_tasks) {
			open_default_source (ici, E_CAL_CLIENT_SOURCE_TYPE_TASKS, gc_import_tasks);
			return;
		}
	}

	e_import_complete (ei, target);
}
Esempio n. 14
0
static void
elm_import_done(struct _elm_import_msg *m)
{
	printf("importing complete\n");

	if (!camel_exception_is_set(&m->base.ex)) {
		GConfClient *gconf;

		gconf = gconf_client_get_default();
		gconf_client_set_bool(gconf, "/apps/evolution/importer/elm/mail", TRUE, NULL);
		g_object_unref(gconf);
	}

	e_import_complete(m->import, (EImportTarget *)m->target);
}
Esempio n. 15
0
static void
csv_import_done (CSVImporter *gci)
{
	if (gci->idle_id)
		g_source_remove (gci->idle_id);

	fclose (gci->file);
	g_object_unref (gci->book_client);
	g_slist_foreach (gci->contacts, (GFunc) g_object_unref, NULL);
	g_slist_free (gci->contacts);

	if (gci->fields_map)
		g_hash_table_destroy (gci->fields_map);

	e_import_complete (gci->import, gci->target, NULL);
	g_object_unref (gci->import);

	g_free (gci);
}
Esempio n. 16
0
static void
ldif_import (EImport *ei,
             EImportTarget *target,
             EImportImporter *im)
{
	LDIFImporter *gci;
	ESource *source;
	FILE *file = NULL;
	EImportTargetURI *s = (EImportTargetURI *) target;
	gchar *filename;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename != NULL) {
		file = g_fopen(filename, "r");
		g_free (filename);
	}
	if (file == NULL) {
		g_message(G_STRLOC ":Can't open .ldif file");
		e_import_complete (ei, target);
		return;
	}

	gci = g_malloc0 (sizeof (*gci));
	g_datalist_set_data(&target->data, "ldif-data", gci);
	gci->import = g_object_ref (ei);
	gci->target = target;
	gci->file = file;
	fseek (file, 0, SEEK_END);
	gci->size = ftell (file);
	fseek (file, 0, SEEK_SET);
	gci->dn_contact_hash = g_hash_table_new_full (
		g_str_hash, g_str_equal,
		(GDestroyNotify) g_free,
		(GDestroyNotify) NULL);

	source = g_datalist_get_data (&target->data, "ldif-source");

	e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
		e_client_utils_authenticate_handler, NULL,
		book_loaded_cb, gci);
}
static void
csv_import (EImport *ei,
            EImportTarget *target,
            EImportImporter *im)
{
	CSVImporter *gci;
	ESource *source;
	gchar *filename;
	FILE *file;
	EImportTargetURI *s = (EImportTargetURI *) target;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename == NULL) {
		g_message (G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
		return;
	}

	file = g_fopen (filename, "r");
	g_free (filename);
	if (file == NULL) {
		g_message ("Can't open .csv file");
		e_import_complete (ei, target);
		return;
	}

	gci = g_malloc0 (sizeof (*gci));
	g_datalist_set_data (&target->data, "csv-data", gci);
	gci->import = g_object_ref (ei);
	gci->target = target;
	gci->file = file;
	gci->fields_map = NULL;
	gci->count = 0;
	fseek (file, 0, SEEK_END);
	gci->size = ftell (file);
	fseek (file, 0, SEEK_SET);

	source = g_datalist_get_data (&target->data, "csv-source");

	e_book_client_connect (source, 30, NULL, book_client_connect_cb, gci);
}
Esempio n. 18
0
static void
gc_import_tasks (ECalClient *cal_client,
                 const GError *error,
                 ICalIntelligentImporter *ici)
{
	g_return_if_fail (ici != NULL);

	if (error != NULL) {
		g_warning (
			"%s: Failed to open tasks: %s",
			G_STRFUNC, error->message);
		e_import_complete (ici->ei, ici->target);
		return;
	}

	e_import_status (ici->ei, ici->target, _("Importing..."), 0);

	prepare_tasks (ici->icalcomp, ici->tasks);

	update_objects (
		cal_client, ici->icalcomp,
		ici->cancellable, continue_done_cb, ici);
}
Esempio n. 19
0
static void
dbx_import_imported (DbxImporter *m)
{
	e_import_complete (m->target->import, (EImportTarget *) m->target, m->base.error);
}
Esempio n. 20
0
static void
pine_import_done (struct _pine_import_msg *m)
{
	e_import_complete (m->import, (EImportTarget *) m->target, m->base.error);
}