Пример #1
0
static void
book_client_connect_cb (GObject *source_object,
                        GAsyncResult *result,
                        gpointer user_data)
{
	LDIFImporter *gci = user_data;
	EClient *client;

	client = e_book_client_connect_finish (result, NULL);

	if (client == NULL) {
		ldif_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);
	gci->idle_id = g_idle_add (ldif_import_contacts, gci);
}
Пример #2
0
static void
book_loaded_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	ESource *source = E_SOURCE (source_object);
	LDIFImporter *gci = user_data;
	EClient *client = NULL;

	e_client_utils_open_new_finish (source, result, &client, NULL);

	if (client == NULL) {
		ldif_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);
	gci->idle_id = g_idle_add (ldif_import_contacts, gci);
}
Пример #3
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;
	}
}