QList<CContactItemField *> CntTransformPresence::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactPresence::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to presence
	const QContactPresence &presenceDetail(static_cast<const QContactPresence&>(detail));
	
    HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength);
    detailCount->Des().AppendNum(m_detailCounter);

    // Transform presence informaiton
	if(presenceDetail.presenceState() != QContactPresence::PresenceUnknown) {
        QString presence = QString::number(presenceDetail.presenceState());
        CContactItemField* presenceField = CContactItemField::NewLC(KStorageTypeText);
        TPtrC presenceEncodedText(reinterpret_cast<const TUint16*>(presence.utf16()));
        presenceField->TextStorage()->SetTextL(presenceEncodedText);
        presenceField->AddFieldTypeL(KUidContactFieldPresence);
        presenceField->SetLabelL(*detailCount);
        fieldList.append(presenceField);
        CleanupStack::Pop(presenceField);
    }
	         
    // Transform statusMessage
    TPtrC statusMsgText(reinterpret_cast<const TUint16*>(presenceDetail.presenceStateText().utf16()));
    if(statusMsgText.Length()) {
        CContactItemField* statusMsgField = CContactItemField::NewLC(KStorageTypeText);
        statusMsgField->TextStorage()->SetTextL(statusMsgText);
        statusMsgField->AddFieldTypeL(KUidContactFieldStatusMsg);
        statusMsgField->SetLabelL(*detailCount);
        fieldList.append(statusMsgField);
        CleanupStack::Pop(statusMsgField);
	}

    CleanupStack::PopAndDestroy(detailCount);
    
	if(fieldList.count() > 0) {
        m_detailCounter++;
	}
	    
	return fieldList;
}
Example #2
0
void CAccessCountTests::AddAgentFieldL(const TContactItemId aCid)
	{
	_LIT(KAgentName, "ImAnAgent");
	CContactItemField * field = CContactItemField::NewLC(KStorageTypeContactItemId, KUidContactFieldVCardMapAGENT );
	field->SetMapping(KUidContactFieldVCardMapAGENT);
	field->SetLabelL(KAgentName);
	field->AgentStorage()->SetAgentId(aCid);
	iFields->AddL(*field);
	CleanupStack::Pop(field);
	field = NULL;
	}
QList<CContactItemField *> CntTransformOnlineAccount::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactOnlineAccount::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactOnlineAccount &onlineAccount(static_cast<const QContactOnlineAccount&>(detail));

	//get the subType
	QStringList subTypes = onlineAccount.subTypes();

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(onlineAccount.accountUri().utf16()));
	if(fieldText.Length()) {
        HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength);
        detailCount->Des().AppendNum(m_detailCounter);
	
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText);
	    newField->TextStorage()->SetTextL(fieldText);

	    //no subtype
	    if(!subTypes.count())
	    {
	        User::LeaveIfError(KErrArgument);
	    }

	    // online account
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeImpp))
	    {
	        newField->AddFieldTypeL(KUidContactFieldIMPP);
	        newField->SetMapping(KUidContactFieldVCardMapUnknown);
	    }

	    //internet
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSipVoip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapVOIP);
	    }

	    //share video
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeVideoShare))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSWIS);
	    }

	    //sip
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSIPID);
	    }

	    else
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(onlineAccount, *newField);

	    newField->SetLabelL(*detailCount);
	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	    
        // Transform Service Provider Text
	    TPtrC ServiceProviderText(reinterpret_cast<const TUint16*>(onlineAccount.serviceProvider().utf16()));
	    if(ServiceProviderText.Length()) {
            CContactItemField* serviceProviderField = CContactItemField::NewLC(KStorageTypeText);
	        serviceProviderField->TextStorage()->SetTextL(ServiceProviderText);
	        serviceProviderField->AddFieldTypeL(KUidContactFieldServiceProvider);
	        serviceProviderField->SetLabelL(*detailCount);
	        fieldList.append(serviceProviderField);
	        CleanupStack::Pop(serviceProviderField);
	    }
	    CleanupStack::PopAndDestroy(detailCount);
	}

	if(fieldList.count() > 0) {
        m_detailCounter++;
	}
	    
	return fieldList;
}
Example #4
0
LOCAL_C void TestRecoverWhenViewReadyL()
    {
	test.Next(_L("Recover database when view is ready"));

    CTestResources* res = CTestResources::NewLC(EFalse);
	
	//Creating a contact to test recovery
	_LIT(KPhoneNumLabel,"Phone Number");
	_LIT(KPhoneNum,		"+440000000000");

	CContactCard* contact		= CContactCard::NewLC();
	CContactItemField* field	= CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
	
	field->SetLabelL(KPhoneNumLabel());
	field->TextStorage()->SetTextL(KPhoneNum());
	
	contact->AddFieldL(*field);
	
	TContactItemId aContactId = res->iDb->AddNewContactL(*contact);
	
	CleanupStack::Pop(field);

    // Wait 5 seconds for the view to get ready
    TContactViewEvent event;
    test(res->iViewEventQueue->ListenForEvent(5,event));
    test(event.iEventType == TContactViewEvent::EReady);

    // Damage the DB
	test.Next(_L("Damage the open database"));

    res->iDb->DamageDatabaseL(0x666);
    test(res->iDb->IsDamaged());
   
    // Damaging should not send view events
    test(!res->iViewEventQueue->ListenForEvent(5,event));

	//Attempt to read contact from the damaged database - this should fail with KErrNotReady
	test.Next(_L("Attempting to read from damaged database"));

	CContactItem* testCard = NULL;
	TRAPD(ret,testCard = res->iDb->ReadContactLC(aContactId));
	test(ret == KErrNotReady);
		
	// Recover the DB
	test.Next(_L("Recover the damaged database"));

    res->iDb->RecoverL();
		
    // View should be unavailable here
    test(res->iViewEventQueue->ListenForEvent(5,event));
    test(event.iEventType == TContactViewEvent::EUnavailable);

	//View should now be ready for use again
	test(res->iViewEventQueue->ListenForEvent(5,event));
	test(event.iEventType == TContactViewEvent::EReady);

	//Line below included to fix ARMV5 minor build warnings.
	testCard = res->iDb->ReadContactLC(aContactId);
	test(testCard != NULL);
	
	CleanupStack::PopAndDestroy(testCard);
	CleanupStack::PopAndDestroy(contact);
    CleanupStack::PopAndDestroy(res);
    }