Пример #1
0
bool
BContact::HasField(BContactField* field)
{
	if (fInitCheck != B_OK)
		return fInitCheck;

	int count = fList.CountItems();
	BContactField* ret;
	for (int i = 0; i < count; i++) {
		ret = fList.ItemAt(i);
		if (ret->IsEqual(field))
			return true;
	}
	return B_ERROR;
}
BContactField*
BContactField::Duplicate(BContactField* from)
{
	BContactField* child = NULL;
	type_code childType = from->FieldType();
	ObjectDeleter<BContactField> deleter;

	child = BContactField::InstantiateChildClass(childType);

	if (child != NULL && child->CopyDataFrom(from) == B_OK)
		return child;

	deleter.SetTo(child);
	return NULL;
}
Пример #3
0
status_t
BContact::ReplaceField(BContactField* field)
{
	if (fInitCheck != B_OK)
		return fInitCheck;

	int count = fList.CountItems();
	for (int i = 0; i < count; i++) {
		BContactField* ret = fList.ItemAt(i);
		if (ret->IsEqual(field)) {
			if (fList.ReplaceItem(i, field))
				return B_OK;
			else
				return B_ERROR;
		}
	}
	return B_ERROR;
}
Пример #4
0
int32
BContact::CountFields(field_type type) const
{
	if (fInitCheck != B_OK)
		return 0;

	int32 count = CountFields();
	int32 fieldsCount = 0;
	for (int i = 0; i < count; i++) {
		printf("%d\n", i);
		BContactField* ret = fList.ItemAt(count);
		if (ret != NULL && ret->FieldType() == type) {
			printf("++\n");
			fieldsCount++;
		}
	}

	return fieldsCount;
}
Пример #5
0
// TODO improve performances sorting
// fList's objects by type
BContactField*
BContact::FieldByType(field_type type, int32 index)
{
	if (fInitCheck != B_OK)
		return NULL;

	int32 count = CountFields();
	int32 fieldsCount = 0;
	for (int i = 0; i < count; i++) {
		BContactField* ret = fList.ItemAt(count);
		if (ret->TypeCode() == type) {
			fieldsCount++;
			if (fieldsCount == index)
				return ret;
		}
	}

	return NULL;
}
Пример #6
0
// You cannot instantiate a pure BContactField
// so this method help to unflatten the correct 
// derived class
BContactField*
BContactField::UnflattenChildClass(const void* from, ssize_t size)
{
	BMemoryIO data(from, size);

	type_code childType;
	data.Read(&childType, sizeof(childType));
	ObjectDeleter<BContactField> deleter;
	BContactField* child = NULL;
	switch (childType) {
		case B_CONTACT_NAME:
		case B_CONTACT_NICKNAME:
		case B_CONTACT_EMAIL:
		case B_CONTACT_NOTE:
		case B_CONTACT_ORGANIZATION:
		case B_CONTACT_IM:
		case B_CONTACT_URL:
		case B_CONTACT_PHONE:
			child = new BStringContactField(childType);
			break;
		case B_CONTACT_ADDRESS:
			child = new BAddressContactField();
			break;
		case B_CONTACT_PHOTO:
			child = new BPhotoContactField();
			break;

		default:
			return NULL;
	}

	if (child == NULL)
		return NULL;

	status_t ret = child->Unflatten(B_CONTACT_FIELD_TYPE, from, size);
	if (ret == B_OK)
		return child;

	deleter.SetTo(child);
	return NULL;
}
// You cannot instantiate a pure BContactField
// so this method help to unflatten the correct 
// derived class
BContactField*
BContactField::UnflattenChildClass(const void* from, ssize_t size)
{
	BMemoryIO data(from, size);

	type_code childType;
	data.Read(&childType, sizeof(childType));
	ObjectDeleter<BContactField> deleter;
	BContactField* child = NULL;

	child = BContactField::InstantiateChildClass(childType);

	if (child == NULL)
		return NULL;

	status_t ret = child->Unflatten(B_CONTACT_FIELD_TYPE, from, size);
	if (ret == B_OK)
		return child;

	deleter.SetTo(child);
	return NULL;
}
Пример #8
0
status_t
BContact::_FlattenFields(BMessage* msg) const
{
	int count = fList.CountItems();
	status_t ret;

	for (int i = 0; i < count; i++) {
		BContactField* object = fList.ItemAt(i);
		ssize_t size = object->FlattenedSize();

		void* buffer = new char[size];
		MemoryDeleter deleter(buffer);
		if (buffer == NULL)
			return B_NO_MEMORY;

		ret = object->Flatten(buffer, size);

		ret = msg->AddData(CONTACT_FIELD_IDENT, object->TypeCode(),
			buffer, size, false);
		if (ret != B_OK)
			return ret;
	}
	return B_OK;
}