void GaduContactListService::handleEventUserlistGetReply(struct gg_event *e)
{
	char *content = e->event.userlist.reply;
	if (!content)
	{
		kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "error!\n");

		emit contactListImported(false, BuddyList());
		return;
	}

	if (content[0] != 0)
		ImportReply.append(content);

	if (e->event.userlist.type == GG_USERLIST_GET_MORE_REPLY)
	{
		kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "next portion\n");
		return;
	}

	kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "\n%s\n", ImportReply.data());

	BuddyList buddies = GaduListHelper::byteArrayToBuddyList(Protocol->account(), ImportReply);
	emit contactListImported(true, buddies);

	// cleanup references, so buddy and contact instances can be removed
	// this is really a hack, we need to call aboutToBeRemoved someway for non-manager contacts and buddies too
	// or just only store managed only, i dont know yet
	foreach (Buddy buddy, buddies)
	{
		foreach (Contact contact, buddy.contacts())
			contact.data()->aboutToBeRemoved();
		buddy.data()->aboutToBeRemoved();
	}
void GaduContactListService::importContactList()
{
	ImportReply.truncate(0);

	if (-1 == gg_userlist_request(Protocol->gaduSession(), GG_USERLIST_GET, 0))
		emit contactListImported(false, ContactList());
}
void GaduContactListService::handleEventUserlistGetReply(struct gg_event *e)
{
	char *content = e->event.userlist.reply;
	if (!content)
	{
		kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "error!\n");

		emit contactListImported(false, ContactList());
		return;
	}

	if (content[0] != 0)
		ImportReply += cp2unicode(content);

	if (e->event.userlist.type == GG_USERLIST_GET_MORE_REPLY)
	{
		kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "next portion\n");
		return;
	}

	kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "\n%s\n", unicode2latin(ImportReply).data());

	emit contactListImported(true, GaduListHelper::stringToContactList(Protocol->account(), ImportReply));
}