Ejemplo n.º 1
0
static gboolean
csv_import_contacts (gpointer d)
{
	CSVImporter *gci = d;
	EContact *contact = NULL;

	while ((contact = getNextCSVEntry (gci, gci->file))) {
		gchar *uid = NULL;

		e_book_client_add_contact_sync (
			gci->book_client, contact, &uid, NULL, NULL);
		if (uid != NULL) {
			e_contact_set (contact, E_CONTACT_UID, uid);
			g_free (uid);
		}
		gci->contacts = g_slist_prepend (gci->contacts, contact);
	}
	if (contact == NULL) {
		gci->state = 1;
	}
	if (gci->state == 1) {
		csv_import_done (gci);
		return FALSE;
	}
	else {
		e_import_status (
			gci->import, gci->target, _("Importing..."),
			ftell (gci->file) * 100 / gci->size);
		return TRUE;
	}
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
static gboolean
vcard_import_contacts (gpointer data)
{
	VCardImporter *gci = data;
	gint count = 0;
	GSList *iterator = gci->iterator;

	if (gci->state == 0) {
		while (count < 50 && iterator) {
			vcard_import_contact (gci, iterator->data);
			count++;
			iterator = iterator->next;
		}
		gci->count += count;
		gci->iterator = iterator;
		if (iterator == NULL)
			gci->state = 1;
	}
	if (gci->state == 1) {
		vcard_import_done (gci);
		return FALSE;
	} else {
		e_import_status (
			gci->import, gci->target, _("Importing..."),
			gci->count * 100 / gci->total);
		return TRUE;
	}
}
Ejemplo n.º 4
0
static void
ivcal_connect_cb (GObject *source_object,
                  GAsyncResult *result,
                  gpointer user_data)
{
	EClient *client;
	ICalImporter *ici = user_data;
	GError *error = NULL;

	g_return_if_fail (ici != NULL);

	client = e_cal_client_connect_finish (result, &error);

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

	if (error != NULL) {
		g_warning ("%s: %s", G_STRFUNC, error->message);
		g_error_free (error);
		ivcal_import_done (ici);
		return;
	}

	ici->cal_client = E_CAL_CLIENT (client);

	e_import_status (ici->import, ici->target, _("Importing..."), 0);
	ici->idle_id = g_idle_add (ivcal_import_items, ici);
}
Ejemplo n.º 5
0
static void
open_default_source (ICalIntelligentImporter *ici,
                     ECalClientSourceType source_type,
                     void (* opened_cb) (ECalClient *cal_client,
                                         const GError *error,
                                         ICalIntelligentImporter *ici))
{
	EShell *shell;
	ESource *source;
	ESourceRegistry *registry;
	struct OpenDefaultSourceData *odsd;

	g_return_if_fail (ici != NULL);
	g_return_if_fail (opened_cb != NULL);

	shell = e_shell_get_default ();
	registry = e_shell_get_registry (shell);

	switch (source_type) {
		case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
			source = e_source_registry_ref_default_calendar (registry);
			break;
		case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
			source = e_source_registry_ref_default_task_list (registry);
			break;
		case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
			source = e_source_registry_ref_default_memo_list (registry);
			break;
		default:
			g_return_if_reached ();
	}

	odsd = g_new0 (struct OpenDefaultSourceData, 1);
	odsd->ici = ici;
	odsd->opened_cb = opened_cb;

	e_import_status (ici->ei, ici->target, _("Opening calendar"), 0);

	e_cal_client_connect (
		source, source_type, 30, ici->cancellable,
		default_client_connect_cb, odsd);

	g_object_unref (source);
}
Ejemplo n.º 6
0
static gboolean
elm_status_timeout(void *data)
{
	struct _elm_import_msg *importer = data;
	int pc;
	char *what;

	if (importer->status_what) {
		g_mutex_lock(importer->status_lock);
		what = importer->status_what;
		importer->status_what = NULL;
		pc = importer->status_pc;
		g_mutex_unlock(importer->status_lock);

		e_import_status(importer->import, (EImportTarget *)importer->target, what, pc);
	}

	return TRUE;
}
static gboolean
mbox_status_timeout (gpointer data)
{
	MboxImporter *importer = data;
	gint pc;
	gchar *what;

	if (importer->status_what) {
		g_mutex_lock (&importer->status_lock);
		what = importer->status_what;
		importer->status_what = NULL;
		pc = importer->status_pc;
		g_mutex_unlock (&importer->status_lock);

		e_import_status (
			importer->import, (EImportTarget *)
			importer->target, what, pc);
	}

	return TRUE;
}
Ejemplo n.º 8
0
static gboolean
pine_status_timeout (gpointer user_data)
{
	struct _pine_import_msg *importer = user_data;
	gint pc;
	gchar *what;

	if (importer->status_what) {
		g_mutex_lock (&importer->status_lock);
		what = importer->status_what;
		importer->status_what = NULL;
		pc = importer->status_pc;
		g_mutex_unlock (&importer->status_lock);

		e_import_status (
			importer->import, (EImportTarget *)
			importer->target, what, pc);
	}

	return TRUE;
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
static void
ivcal_import (EImport *ei,
              EImportTarget *target,
              icalcomponent *icalcomp)
{
	ECalClientSourceType type;
	ICalImporter *ici = g_malloc0 (sizeof (*ici));

	type = GPOINTER_TO_INT (g_datalist_get_data (&target->data, "primary-type"));

	ici->import = ei;
	g_datalist_set_data (&target->data, "ivcal-data", ici);
	g_object_ref (ei);
	ici->target = target;
	ici->icalcomp = icalcomp;
	ici->cal_client = NULL;
	ici->source_type = type;
	ici->cancellable = g_cancellable_new ();
	e_import_status (ei, target, _("Opening calendar"), 0);

	e_cal_client_connect (
		g_datalist_get_data (&target->data, "primary-source"),
		type, 30, ici->cancellable, ivcal_connect_cb, ici);
}
Ejemplo n.º 11
0
static gboolean
ldif_import_contacts (gpointer d)
{
	LDIFImporter *gci = d;
	EContact *contact;
	GSList *iter;
	gint count = 0;

	/* We process all normal cards immediately and keep the list
	 * ones till the end */

	if (gci->state == 0) {
		while (count < 50 && (contact = getNextLDIFEntry (
			gci->dn_contact_hash, gci->file))) {
			if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
				gci->list_contacts = g_slist_prepend (
					gci->list_contacts, contact);
			} else {
				gchar *uid = NULL;

				add_to_notes (contact, E_CONTACT_OFFICE);
				add_to_notes (contact, E_CONTACT_SPOUSE);
				add_to_notes (contact, E_CONTACT_BLOG_URL);
				if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
					e_contact_set (contact, E_CONTACT_UID, uid);
					g_free (uid);
				}
				gci->contacts = g_slist_prepend (gci->contacts, contact);
			}
			count++;
		}
		if (contact == NULL) {
			gci->state = 1;
			gci->list_iterator = gci->list_contacts;
		}
	}
	if (gci->state == 1) {
		for (iter = gci->list_iterator; count < 50 && iter; iter = iter->next) {
			gchar *uid = NULL;

			contact = iter->data;
			resolve_list_card (gci, contact);
			if (e_book_client_add_contact_sync (gci->book_client, contact, &uid, NULL, NULL) && uid) {
				e_contact_set (contact, E_CONTACT_UID, uid);
				g_free (uid);
			}
			count++;
		}
		gci->list_iterator = iter;
		if (iter == NULL)
			gci->state = 2;
	}
	if (gci->state == 2) {
		ldif_import_done (gci);
		return FALSE;
	} else {
		e_import_status (
			gci->import, gci->target, _("Importing..."),
			ftell (gci->file) * 100 / gci->size);
		return TRUE;
	}
}