예제 #1
0
파일: inventory.cpp 프로젝트: astrellon/GPP
	bool Inventory::removeItem(Item *item)
	{
		if (item == NULL)
		{
			return false;
		}
		
		int index = findItem(item);
		if (index < 0)
		{
			return false;
		}

		InventorySpot &spot = mSpots[index];
		int xEnd = spot.getX() + spot.getItem()->getInventorySizeX();
		int yEnd = spot.getY() + spot.getItem()->getInventorySizeY();

		for (int j = spot.getY(); j < yEnd; j++)
		{
			int jOffset = j * mSpacesX;
			for (int i = spot.getX(); i < xEnd; i++)
			{
				mSpotMap[i + jOffset] = NULL;
			}
		}
		// Keep items alive while event fires.
		Handle<Item> itemHandle(item);
		mSpots.erase(mSpots.begin() + index);

		item->setItemLocation(Item::GROUND);
		fireEvent<InventoryEvent>(new InventoryEvent(INVENTORY_REMOVE, this, item, spot.getX(), spot.getY()));

		return true;
	}
// -----------------------------------------------------------------------------
// CPIMSerializer::FromSerialFormatL
// forwards the request to the versit module
// -----------------------------------------------------------------------------
//
jintArray CPIMSerializer::FromSerialFormatL(JNIEnv* aJniEnv,
        const TDesC8& aBuffer, TEncoding aEncoding)
{
    JELOG2(EPim);
    Versit::TVersitCharSet charSet = MapEncodingL(aEncoding);
    RPointerArray<CPIMItem>* itemArray = iVersit->StringToItemL(aBuffer,
                                         charSet);
    CleanupDeletePushL(itemArray);
    CleanupClosePushL(*itemArray);

    // calculate the length of the needed array
    TInt arrayLength = 0;
    TInt itemCount = itemArray->Count();
    TInt i = 0;
    for (i = 0; i < itemCount; i++)
    {
        switch ((*itemArray)[i]->ItemType())
        {
        case EPIMContactList:
        case EPIMToDoList:
        {
            arrayLength += 2;
            break;
        }
        case EPIMEventList:
        {
            arrayLength += 4;
            break;
        }
        default:
        {
            User::Leave(KErrNoMemory);
        }
        }
    }

    jintArray itemHandles = aJniEnv->NewIntArray(arrayLength);
    if (!itemHandles)
    {
        User::Leave(KErrNoMemory);
    }
    jint* handles = aJniEnv->GetIntArrayElements(itemHandles, 0);
    jint* handlePointer = handles;
    for (i = 0; i < itemCount; i++)
    {
        pimbaseitem* item = (*itemArray)[i];
        TInt itemHandle(reinterpret_cast<int>(item));
        TInt itemType = ((*itemArray)[i])->ItemType();
        *handlePointer++ = itemType;
        *handlePointer++ = itemHandle;
        if (itemType == EPIMEventList)
        {

            int baseRepeatRuleHandle = item->getRepeatHandle();
            if (baseRepeatRuleHandle < KErrNone)
                throw baseRepeatRuleHandle;

            *handlePointer++ = baseRepeatRuleHandle;
            handlePointer++;
        }
    }
    aJniEnv->ReleaseIntArrayElements(itemHandles, handles, 0);

    CleanupStack::PopAndDestroy(2);
    return itemHandles;
}