contact.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 1,171 行 · 第 1/2 页

CPP
1,171
字号
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	aOplAPI.Push((TInt16)iPtrs->iField->IsHidden());
	}

void CCntOpx::ContactFieldIsReadOnly(OplAPI& aOplAPI)                
// returns whether field is read only
// COContactFieldIsReadOnly%:
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	aOplAPI.Push((TInt16)iPtrs->iField->IsReadOnly());
	}


void CCntOpx::ContactFieldSetHidden(OplAPI& aOplAPI)                
// set whether field is hidden
// COContactFieldSetHidden:(aHidden%)
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TBool hidden = aOplAPI.PopInt16();
	if ((hidden!=1) && (hidden!=0))
		User::Leave(KOplErrSubs);

	iPtrs->iField->SetHidden(hidden);

	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldSetReadOnly(OplAPI& aOplAPI)        
// set whether field is read only
// COContactFieldSetReadOnly:(aReadOnly%)
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TBool readOnly = aOplAPI.PopInt16();
	if ((readOnly!=1) && (readOnly!=0))
		User::Leave(KOplErrSubs);

	iPtrs->iField->SetReadOnly(readOnly);

	aOplAPI.Push(0.0);
	}


void CCntOpx::ContactFieldLabel(OplAPI& aOplAPI)                        
// returns the label of the field
// COContactFieldLabel$: 
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TPtrC labelString = iPtrs->iField->Label();

	aOplAPI.PushL(labelString);
	}

void CCntOpx::ContactFieldSetLabel(OplAPI& aOplAPI)                
// sets the label of the field
// COContactFieldSetLabel:(label$)
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TPtrC tempLabel = aOplAPI.PopString();

	HBufC* label = tempLabel.AllocL();

	iPtrs->iField->SetLabel(label);

	aOplAPI.Push(0.0);
	}


void CCntOpx::ContactFieldAddType(OplAPI& aOplAPI)                
// adds a type to the field
// COContactFieldAddType:(aType&)
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	iPtrs->iField->AddFieldTypeL(TUid::Uid(aOplAPI.PopInt32()));
	
	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldSetMapping(OplAPI& aOplAPI)                
// sets a mapping for the field
// COContactFieldSetMapping:(aMapping&)
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	iPtrs->iField->SetMapping(TUid::Uid(aOplAPI.PopInt32()));

	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldSetText(OplAPI& aOplAPI)                
// sets the text of the field
// COContactFieldSetText:(aString$)
	{        
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TPtrC fieldString = aOplAPI.PopString();

	HBufC* textData = fieldString.AllocL();
	CleanupStack::PushL(textData);
	
	STATIC_CAST(CContactTextField*,iPtrs->iField->Storage())->SetTextL(fieldString); //textData);

	CleanupStack::PopAndDestroy(); //textData
	// delete textData;

	aOplAPI.Push(0.0);
	}
	
void CCntOpx::ContactFieldSetLong(OplAPI& aOplAPI)                
// sets the text of the field
// COContactFieldSetLong:(aStringAddr&,aLength&)
	{        
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TInt length = aOplAPI.PopInt32();

	TInt32* aBuf= aOplAPI.PopPtrInt32();

	TPtrC fieldText((const TText*)aBuf,length);

	HBufC* textData = fieldText.AllocL();
	CleanupStack::PushL(textData);
	
	STATIC_CAST(CContactTextField*,iPtrs->iField->Storage())->SetTextL(fieldText); //textData);

	CleanupStack::PopAndDestroy(); //textData

	//delete textData;

	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldText(OplAPI& aOplAPI)                        
// returns the test in the field
// COContactFieldText$: 
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	TPtrC fieldString = STATIC_CAST(CContactTextField*,iPtrs->iField->Storage())->Text();
	
	if (fieldString.Length()>255)
		User::Leave(KOplErrStrTooLong);

	aOplAPI.PushL(fieldString);
	}

void CCntOpx::ContactFieldLength(OplAPI& aOplAPI)                        
// returns the test in the field
// COContactFieldLength&: 
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	TPtrC fieldString = STATIC_CAST(CContactTextField*,iPtrs->iField->Storage())->Text();
		
	aOplAPI.Push((TInt32)fieldString.Length());
	}

void CCntOpx::ContactFieldLong(OplAPI& aOplAPI)                        
// returns the test in the field
// COContactFieldLong:(abufHandle&) 
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	TPtr* buffer = REINTERPRET_CAST(TPtr*,aOplAPI.PopPtrInt32());  

	TPtrC fieldString = STATIC_CAST(CContactTextField*,iPtrs->iField->Storage())->Text();
	TInt length = fieldString.Length();

	if (fieldString!=TPtrC())  // NOT NULL
		Mem::Copy(buffer,fieldString.Ptr(),length);

	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldDisable(OplAPI& aOplAPI)
// sets the templates field disabled
// COContactFieldDisable:(aBool%) 
	{
	LeaveIfNoWriteableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);
	
	TBool disabled = aOplAPI.PopInt16();
	if ((disabled!=1) && (disabled!=0))
		User::Leave(KOplErrSubs);

	iPtrs->iField->SetDisabled(disabled);
	iPtrs->iField=NULL;

	aOplAPI.Push(0.0);
	}

void CCntOpx::ContactFieldIsDisabled(OplAPI& aOplAPI)
// test the templates field to see if disabled
// COContactFieldIsDisabled%: 
	{
	LeaveIfNoReadableItemL();
	if (iPtrs->iField==NULL)
		User::Leave(KOplErrNotExists);

	aOplAPI.Push((TInt16)iPtrs->iField->IsDisabled());
	}

void CCntOpx::DoOpenItemL(TInt acontactItemId)
// opens a contact
	{        
	iPtrs->iCurrentItem = iDbHandle->OpenContactL(acontactItemId); // takes ownership
	}

void CCntOpx::DoCloseItemL()
// close contact
	{
	LeaveIfNoWriteableItemL();
	TInt contactItemId = iPtrs->iCurrentItem->Id();
	if (!iPtrs->iDeleted)
		iDbHandle->CommitContactL(*iPtrs->iCurrentItem);
	iDbHandle->CloseContactL(contactItemId);
	delete iPtrs->iCurrentItem;
	iPtrs->iCurrentItem=NULL;
	iPtrs->iField=NULL;
	}

// Additional code for Crystal onwards

void CCntOpx::GroupCountL(OplAPI& aOplAPI)
	{
	CContactGroup* group = STATIC_CAST(CContactGroup*,iPtrs->iCurrentItem);
	TInt32 count = group->ItemsContained()->Count(); 
	aOplAPI.Push(count);
	}

void CCntOpx::GroupItemIdAtL(OplAPI& aOplAPI)
	{
	TInt32 index = aOplAPI.PopInt32();
	CContactGroup* group = STATIC_CAST(CContactGroup*,iPtrs->iCurrentItem);
	const CContactIdArray* items = group->ItemsContained(); // pointer to array owned by cntmodel
	TContactItemId id = (*items)[OpxUtil::CppIndex(index)];
	aOplAPI.Push(id);
	}

void CCntOpx::GroupAddItemL(OplAPI& aOplAPI)
	{
	LeaveIfNoOpenDbL();
	TInt itemId = aOplAPI.PopInt32();
	TInt groupId = aOplAPI.PopInt32();
	iDbHandle->AddContactToGroupL(groupId,itemId);
	aOplAPI.Push(0.0);
	}

void CCntOpx::GroupRemoveItemL(OplAPI& aOplAPI)
	{
	LeaveIfNoOpenDbL();
	TInt itemId = aOplAPI.PopInt32();
	TInt groupId = aOplAPI.PopInt32();
	iDbHandle->RemoveContactFromGroupL(groupId,itemId);
	aOplAPI.Push(0.0);
	}

void CCntOpx::TemplateGoldenIdL(OplAPI& aOplAPI)
	{
	LeaveIfNoOpenDbL();
	aOplAPI.Push(iDbHandle->TemplateId());
	}

void CCntOpx::OwnCardIdL(OplAPI& aOplAPI)
	{
	LeaveIfNoOpenDbL();
	TInt32 ownCardId=iDbHandle->OwnCardId();
	aOplAPI.Push(ownCardId);
	}

void CCntOpx::ItemTypeL(OplAPI& aOplAPI)
	{
	LeaveIfNoReadableItemL();
	TUid itemUid = iPtrs->iCurrentItem->Type();
	TInt32 itemType;
	if (itemUid==KUidContactCard)
		{
		itemType = EContact;
		}
	else if (itemUid==KUidContactGroup)
		{
		itemType = EGroup;
		}
	else if (itemUid==KUidContactTemplate)
		{
		itemType = ETemplate;
		}
	else if (itemUid==KUidContactOwnCard)
		{
		itemType = EOwnCard;
		}
	else if (itemUid==KUidContactCardTemplate)
		{
		itemType = ECardTemplate;
		}
	else 
		{
		itemType=NULL;
		User::Leave(KOplErrTypeViol);
		}
	aOplAPI.Push(itemType);
	}

void CCntOpx::LeaveIfNoOpenDbL()
	{
	if (iPtrs==NULL)
		User::Leave(KErrBadHandle);
	if (iDbHandle==NULL)
		User::Leave(KOplErrNotOpen);
	}
		
void CCntOpx::LeaveIfNoReadableItemL()
	{
	LeaveIfNoOpenDbL();
	if (!iPtrs->iCurrentItem)
		User::Leave(KOplErrRead);
	}

void CCntOpx::LeaveIfNoWriteableItemL()
	{
	LeaveIfNoOpenDbL();
	LeaveIfNoReadableItemL();
	if (iPtrs->iOpenedForRead)
		User::Leave(KOplErrWrite);
	}


///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

CTlsDataCCntOPX* CTlsDataCCntOPX::NewL(OplAPI& aOplAPI)
	{
    CTlsDataCCntOPX* This=new(ELeave) CTlsDataCCntOPX(aOplAPI);
    CleanupStack::PushL(This);
	This->ConstructL();
    CleanupStack::Pop();
    return This;
    }

CTlsDataCCntOPX::CTlsDataCCntOPX(OplAPI& aOplAPI) : COpxBase(aOplAPI)
    {
	}

void CTlsDataCCntOPX::ConstructL()
    {
	iCntHandle = new(ELeave) CCntOpx;
    } 

CTlsDataCCntOPX::~CTlsDataCCntOPX()
    {
	delete iCntHandle;
	Dll::FreeTls();                // Required so that Tls is set to zero on unloading the OPX in UNLOADM#
//	__UHEAP_MARKENDC(1);  // created & cleaned up by OPL
	}

void CTlsDataCCntOPX::RunL(TInt aProcNum)
// Run a language extension procedure
	{
	switch (aProcNum)
		{
	case ECreateContactFile:
		iCntHandle->CreateContactFileL(iOplAPI);
		break;
	case EOpenContactFile:
		iCntHandle->OpenContactFileL(iOplAPI);
		break;
	case ECloseContactFile:
		iCntHandle->CloseContactFileL(iOplAPI);
		break;
	case ESortItems:
		iCntHandle->SortItemsL(iOplAPI);
		break;
	case ESortedItemsAt:
		iCntHandle->SortedItemsAtL(iOplAPI);
		break;
	case ECompressContactFile:
		iCntHandle->CompressContactFile(iOplAPI);
		break;
	case ECompressNeeded:
		iCntHandle->CompressNeeded(iOplAPI);
		break;
	case ECountItems:
		iCntHandle->CountItemsL(iOplAPI);
		break;
	case EAddNewItem:
		iCntHandle->AddNewItemL(iOplAPI);
		break;
	case EDeleteItem:
		iCntHandle->DeleteItemL(iOplAPI);
		break;
	case EReadItem:
		iCntHandle->ReadItemL(iOplAPI);
		break;
	case EOpenItem:
		iCntHandle->OpenItemL(iOplAPI);
		break;
	case ECloseItem:
		iCntHandle->CloseItemL(iOplAPI);
		break;
	case EItemId:
		iCntHandle->ItemIdL(iOplAPI);
		break;
	case ESetItemHidden:
		iCntHandle->SetItemHiddenL(iOplAPI);
		break;
	case ESetItemSystem:
		iCntHandle->SetItemSystemL(iOplAPI);
		break;
	case EIsItemHidden:
		iCntHandle->IsItemHiddenL(iOplAPI);
		break;
	case EIsItemSystem:
		iCntHandle->IsItemSystemL(iOplAPI);
		break;
	case EFindItem:
		iCntHandle->FindItemL(iOplAPI);
		break;
	case ECreateItem:
		iCntHandle->CreateItemL(iOplAPI);
		break;
	case EContactFieldArrayAt:
		iCntHandle->ContactFieldArrayAt(iOplAPI);
		break;
	case EContactFieldFind:
		iCntHandle->ContactFieldFind(iOplAPI);
		break;
	case EContactFieldCount:
		iCntHandle->ContactFieldCount(iOplAPI);
		break;
	case EContactFieldReset:
		iCntHandle->ContactFieldReset(iOplAPI);
		break;
	case EContactFieldAdd:
		iCntHandle->ContactFieldAdd(iOplAPI);
		break;
	case EContactFieldDelete:
		iCntHandle->ContactFieldDelete(iOplAPI);
		break;
	case EContactFieldInsert:
		iCntHandle->ContactFieldInsert(iOplAPI);
		break;
	case EContactFieldMove:
		iCntHandle->ContactFieldMove(iOplAPI);
		break;
	case EContactFieldCreate:
		iCntHandle->ContactFieldCreate(iOplAPI);
		break;
	case EContactFieldContent:
		iCntHandle->ContactFieldContent(iOplAPI);
		break;
	case EContactFieldIsHidden:
		iCntHandle->ContactFieldIsHidden(iOplAPI);
		break;
	case EContactFieldIsReadOnly:
		iCntHandle->ContactFieldIsReadOnly(iOplAPI);
		break;
	case EContactFieldSetHidden:
		iCntHandle->ContactFieldSetHidden(iOplAPI);
		break;
	case EContactFieldSetReadOnly:
		iCntHandle->ContactFieldSetReadOnly(iOplAPI);
		break;
	case EContactFieldLabel:
		iCntHandle->ContactFieldLabel(iOplAPI);
		break;
	case EContactFieldSetLabel:
		iCntHandle->ContactFieldSetLabel(iOplAPI);
		break;
	case EContactFieldAddType:
		iCntHandle->ContactFieldAddType(iOplAPI);
		break;
	case EContactFieldSetMapping:
		iCntHandle->ContactFieldSetMapping(iOplAPI);
		break;
	case EContactFieldSetText:
		iCntHandle->ContactFieldSetText(iOplAPI);
		break;
	case EContactFieldSetLong:
		iCntHandle->ContactFieldSetLong(iOplAPI);
		break;
	case EContactFieldText:
		iCntHandle->ContactFieldText(iOplAPI);
		break;
	case EContactFieldLength:
		iCntHandle->ContactFieldLength(iOplAPI);
		break;
	case EContactFieldLong:
		iCntHandle->ContactFieldLong(iOplAPI);
		break;
	case EContactFieldDisable:
		iCntHandle->ContactFieldDisable(iOplAPI);
		break;
	case EContactFieldIsDisabled:
		iCntHandle->ContactFieldIsDisabled(iOplAPI);
		break;
	case ETemplateGoldenId:
		iCntHandle->TemplateGoldenIdL(iOplAPI);
		break;
	case EOwnCardId:
		iCntHandle->OwnCardIdL(iOplAPI);
		break;
	case EItemType:
		iCntHandle->ItemTypeL(iOplAPI);
		break;
	default:
		User::Leave(KOplErrOpxProcNotFound);
		}
	}

//-------------------------------------------------------------- Check version
TBool CTlsDataCCntOPX::CheckVersion( TInt aVersion )
	{
	if ((aVersion & 0xFF00) > (KOpxContactVersion & 0xFF00))
		return EFalse;
	else
		return ETrue;
	}

//---------------------------------------------------------------- Constructor

//-------------------------------------------------------------------- Version
EXPORT_C TUint Version()
	{
	return KOpxContactVersion;
	}

//------------------------------------------------------------------------ New


EXPORT_C COpxBase* NewOpxL(OplAPI& aOplAPI)
// Creates a COpxBase instance as required by the OPL runtime
// This object is to be stored in the OPX's TLS as shown below
	{
//	__UHEAP_MARK;
	CTlsDataCCntOPX* tls=((CTlsDataCCntOPX*)Dll::Tls());
	if (tls==NULL)                // tls is NULL on loading an OPX DLL (also after unloading it)
		{
		tls=CTlsDataCCntOPX::NewL(aOplAPI);
		CleanupStack::PushL(tls);
	    TInt ret=Dll::SetTls(tls);
		User::LeaveIfError(ret);
		CleanupStack::Pop();        // tls
	}
    return (COpxBase *)tls;
	}

GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
//
// DLL entry point
//
	{
	return(KErrNone);
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?