示例#1
0
static void ebookpull_cb(EBook *book, EBookStatus estatus, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GString *string = g_string_new("");
	unsigned int count = 0, maxcount;
	GList *l;

	if (estatus == E_BOOK_ERROR_CANCELLED) {
		error("E-Book operation was cancelled: status %d", estatus);
		goto fail;
	}

	if (estatus != E_BOOK_ERROR_OK) {
		error("E-Book query failed: status %d", estatus);
		goto done;
	}

	/*
	 * When MaxListCount is zero, PCE wants to know the number of used
	 * indexes in the phonebook of interest. All other parameters that
	 * may be present in the request shall be ignored.
	 */
	maxcount = data->params->maxlistcount;
	if (maxcount == 0) {
		count = g_list_length(contacts);
		goto done;
	}

	l = g_list_nth(contacts, data->params->liststartoffset);

	/* FIXME: Missing 0.vcf */

	for (; l && count < maxcount; l = g_list_next(l), count++) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		char *vcard;

		vcard = evcard_to_string(evcard, data->params->format,
						data->params->filter);

		string = g_string_append(string, vcard);
		string = g_string_append(string, "\r\n");
		g_free(vcard);
	}
	DBG("collected %d vcards", count);


done:
	data->completed = TRUE;
	data->contacts_cb(string->str, string->len, count, 0, TRUE,
							data->user_data);

fail:
	g_string_free(string, TRUE);

	if (data->completed)
		g_free(data);
}
示例#2
0
static void ebook_entry_cb(EBook *book, const GError *gerr,
				EContact *contact, void *user_data)
{
	struct query_context *data = user_data;
	EVCard *evcard;
	char *vcard;
	size_t len;

	data->queued_calls--;

	if (data->canceled)
		goto done;

	if (gerr != NULL) {
		error("E-Book query failed: %s", gerr->message);
		goto done;
	}

	DBG("");

	evcard = E_VCARD(contact);

	vcard = evcard_to_string(evcard, EVC_FORMAT_VCARD_30,
					data->params->filter);

	len = vcard ? strlen(vcard) : 0;

	data->count++;
	data->contacts_cb(vcard, len, 1, 0, TRUE, data->user_data);

	g_free(vcard);
	g_object_unref(contact);

	return;

done:
	if (data->queued_calls == 0) {
		if (data->count == 0)
			data->contacts_cb(NULL, 0, 1, 0, TRUE,
						data->user_data);
		else if (data->canceled)
			free_query_context(data);
	}
}
示例#3
0
static void ebook_entry_cb(EBook *book, EBookStatus estatus,
			EContact *contact, void *user_data)
{
	struct query_context *data = user_data;
	EVCard *evcard;
	char *vcard;
	size_t len;

	if (estatus == E_BOOK_ERROR_CANCELLED) {
		error("E-Book operation was cancelled: status %d", estatus);
		goto fail;
	}

	data->completed = TRUE;

	if (estatus != E_BOOK_ERROR_OK) {
		error("E-Book query failed: status %d", estatus);
		data->contacts_cb(NULL, 0, 1, 0, TRUE, data->user_data);
		goto fail;
	}

	evcard = E_VCARD(contact);

	vcard = evcard_to_string(evcard, data->params->format,
					data->params->filter);

	len = vcard ? strlen(vcard) : 0;

	data->contacts_cb(vcard, len, 1, 0, TRUE, data->user_data);

	g_free(vcard);

fail:
	if (data->completed)
		g_free(data);
}
示例#4
0
static void ebookpull_cb(EBook *book, const GError *gerr, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GList *l;
	unsigned int count, maxcount;

	data->queued_calls--;

	if (data->canceled)
		goto canceled;

	if (gerr != NULL) {
		error("E-Book query failed: %s", gerr->message);
		goto done;
	}

	DBG("");

	/*
	 * When MaxListCount is zero, PCE wants to know the number of used
	 * indexes in the phonebook of interest. All other parameters that
	 * may be present in the request shall be ignored.
	 */
	maxcount = data->params->maxlistcount;
	if (maxcount == 0) {
		data->count += g_list_length(contacts);
		goto done;
	}

	l = g_list_nth(contacts, data->params->liststartoffset);

	for (count = 0; l && count + data->count < maxcount; l = g_list_next(l),
								count++) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		char *vcard;

		vcard = evcard_to_string(evcard, EVC_FORMAT_VCARD_30,
						data->params->filter);

		data->buf = g_string_append(data->buf, vcard);
		data->buf = g_string_append(data->buf, "\r\n");
		g_free(vcard);
	}

	DBG("collected %d vcards", count);

	data->count += count;

	g_list_free_full(contacts, g_object_unref);

done:
	if (data->queued_calls == 0) {
		GString *buf = data->buf;
		data->buf = NULL;

		data->contacts_cb(buf->str, buf->len, data->count,
						0, TRUE, data->user_data);

		g_string_free(buf, TRUE);

	}

	return;

canceled:
	if (data->queued_calls == 0)
		free_query_context(data);
}