sendas.cpp
来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 927 行 · 第 1/2 页
CPP
927 行
// Save message
mtm->SaveMessageL();
// Set the time and make visible
TMsvEntry entry = mtm->Entry().Entry();
entry.iDate.HomeTime();
entry.SetVisible(ETrue);
entry.SetAttachment(iAttachmentFileNamesArray != NULL);
entry.SetInPreparation(EFalse);
// entry.iBioType = aBioTypeUid.iUid;
mtm->Entry().ChangeL(entry);
const TMsvId messageId = entry.Id();
draftEntry = iSession->GetEntryL(KMsvDraftEntryId);
CleanupStack::PushL(draftEntry);
#if defined(__UIQ__)
TVwsViewId id(KUidMsgAppUid,KUidMsgListViewUid);
TQMappDnlViewBuf viewMessage;
viewMessage().iMessageId = messageId;
CEikonEnv::Static()->EikAppUi()->ActivateViewL(id,KUidQMappViewMessage ,viewMessage );
#else
TMsvEntry messageEntry = draftEntry->ChildDataL(messageId);
// Edit the message
CMsvOperationWait* waiter = CMsvOperationWait::NewLC();
CBaseMtmUi& mtmUi = iMtmStore->GetMtmUiAndSetContextLC(messageEntry);
CMsvOperation* op = mtmUi.EditL(waiter->iStatus);
CleanupStack::PushL(op);
waiter->iStatus = KRequestPending;
waiter->Start();
CActiveScheduler::Start();
const TDesC8& progressBuf = op->ProgressL();
mtmUi.DisplayProgressSummary(progressBuf);
CleanupStack::PopAndDestroy(op);
CleanupStack::PopAndDestroy(); //mtmui releaser
CleanupStack::PopAndDestroy(waiter);
#endif
CleanupStack::PopAndDestroy(draftEntry);
CleanupStack::PopAndDestroy(mtm);
// Tidy up after sending - reset member data in preparation for the next send
delete iAttachmentFileNamesArray;
iAttachmentFileNamesArray=NULL;
delete iRealAddressesArray;
iRealAddressesArray=NULL;
delete iSubject;
iSubject=NULL;
iCurrentChosenMtmUid=KNullUid;
}
void COpxSendAsEngine::AddIrAttachmentsL(CBaseMtm* aMtm, MDesC16Array* aAttachments)
{
if (aMtm->Type() != KUidMsgTypeIR)
User::Leave(KErrNotReady);
CMsvEntrySelection* selection = new(ELeave) CMsvEntrySelection();
CleanupStack::PushL(selection);
selection->AppendL(aMtm->Entry().EntryId());
TBuf8<1> nullParamater;
aMtm->InvokeSyncFunctionL(CIrClientMtm::ESendasCmdStartExternalise, *selection, nullParamater);
for (TInt i = 0; i < aAttachments->MdcaCount(); ++i)
{
TFileName name(aAttachments->MdcaPoint(i));
TPtr8 ptr8((TUint8*)name.Ptr(), name.Size());
ptr8.SetLength(name.Size());
aMtm->InvokeSyncFunctionL(CIrClientMtm::ESendasCmdExternaliseFileName, *selection, ptr8);
}
aMtm->InvokeSyncFunctionL(CIrClientMtm::ESendasCmdCommitExternalise, *selection, nullParamater);
CleanupStack::PopAndDestroy(selection);
}
void COpxSendAsEngine::SetBodyDuringSendingL(CBaseMtm* aMtm, const CRichText& aMessageBody)
{
// Set the picture factory !!!
MPictureFactory* pictureFactory = aMessageBody.PictureFactory();
if (pictureFactory)
aMtm->Body().SetPictureFactory(pictureFactory, this);
// Save and restore the rich text
TStreamId id = aMessageBody.StoreL(*iStore);
aMtm->Body().RestoreL(*iStore, id);
// Get access to protected data
CSendAsMtm* mtm = (CSendAsMtm*)aMtm;
mtm->SetCharFormatL(*aMessageBody.GlobalCharFormatLayer());
mtm->SetParaFormatL(*aMessageBody.GlobalParaFormatLayer());
}
const CStreamStore& COpxSendAsEngine::StreamStoreL(TInt) const
{
return *iStore;
}
void COpxSendAsEngine::SetBodyL(CRichText* aMessageBody)
{
ScanIfNeededL();
if ((iCurrentChosenMtmUid==KNullUid) || (!&aMessageBody))
User::Leave(KOplErrNotExists);
#if defined(__UIQ__)
delete iUiMtmData;
iUiMtmData =NULL;
iUiMtmData= iUiDataRegistry->NewMtmUiDataLayerL(iCurrentChosenMtmUid);//=iMtmStore->MtmUiDataL(mtmTypeUid);
CBaseMtmUiData& mtmUiData=*iUiMtmData;
#else
CBaseMtmUiData& mtmUiData = iMtmStore->MtmUiDataL(iCurrentChosenMtmUid);
#endif
TInt response = 0;
if (mtmUiData.QueryCapability(KUidMtmQuerySupportedBody, response) == KErrNone)
{
if (iBody!=aMessageBody)
{
delete iBody;
iBody=NULL;
iBody=aMessageBody;
}
}
else
User::Leave(KOplErrNotSupported);
}
CRichText* COpxSendAsEngine::NewBodyL(const OplAPI& aOplAPI)
{
if (iBody)
User::Leave(KOplErrExists);
CEikonEnv& env=aOplAPI.EikonEnv();
iBody=CRichText::NewL(env.SystemParaFormatLayerL(),env.SystemCharFormatLayerL());
iBody->InsertL(0,KNullDesC);
return iBody;
}
void COpxSendAsEngine::DeleteBodyL()
{
if (!iBody)
User::Leave(KOplErrNotExists);
delete iBody;
iBody=NULL;
}
void COpxSendAsEngine::AppendToMessageBodyL(const TDesC& aString)
{
if (!iBody)
User::Leave(KOplErrNotExists);
iBody->InsertL(iBody->DocumentLength(),aString);
}
void COpxSendAsEngine::ResetMessageBodyL()
{
if (!iBody)
User::Leave(KOplErrNotExists);
iBody->Reset();
}
void COpxSendAsEngine::ScanIfNeededL()
{
if (!iScannedAlready)
ScanMtmsL();
}
void COpxSendAsEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
{
switch (aEvent)
{
case EMsvServerReady:
{
#if !defined(__UIQ__)
iMtmStore = CMtmStore::NewL(*iSession);
#endif
iUiDataRegistry = CMtmUiDataRegistry::NewL(*iSession);
iClientRegistry = CClientMtmRegistry::NewL(*iSession);
iScannedAlready=EFalse;
ScanMtmsL();
break;
}
case EMsvCorruptedIndexRebuilt:
case EMsvMtmGroupInstalled:
case EMsvMtmGroupDeInstalled:
{
ScanMtmsL();
break;
}
case EMsvCloseSession:
case EMsvServerTerminated:
{
iScannedAlready=EFalse;
#if !defined(__UIQ__)
delete iMtmStore;
iMtmStore=NULL;
#endif
delete iUiDataRegistry;
iUiDataRegistry=NULL;
delete iClientRegistry;
iClientRegistry=NULL;
delete iSession; // delete Session last after all things which use it
iSession=NULL;
delete iBody;
iBody=NULL;
delete iAttachmentFileNamesArray;
iAttachmentFileNamesArray=NULL;
delete iRealAddressesArray;
iRealAddressesArray=NULL;
delete iSubject;
iSubject=NULL;
//
// delete iStore too? SendNorm.cpp doesn't
//
break;
}
default:
break;
}
}
//////////////////////////////////////////////////////////////////////////////
//
// COpxSendAs - the OPX 'wrapper' and function handler, etc.
//
//////////////////////////////////////////////////////////////////////////////
COpxSendAs::COpxSendAs(OplAPI& aOplAPI)
:COpxBase(aOplAPI)
{
}
COpxSendAs* COpxSendAs::NewLC(OplAPI& aOplAPI)
{
COpxSendAs* This=new(ELeave) COpxSendAs(aOplAPI);
CleanupStack::PushL(This);
This->ConstructL();
return This;
}
void COpxSendAs::ConstructL()
{
iEngine = COpxSendAsEngine::NewL();
}
COpxSendAs::~COpxSendAs()
{
delete iEngine;
Dll::FreeTls();
}
void COpxSendAs::ScanTypesL() const
{
iEngine->ScanMtmsL();
iOplAPI.Push(0.0);
}
void COpxSendAs::MaximumTypesL() const
{
iOplAPI.Push(TInt32(iEngine->NumberOfMtmsL()));
}
void COpxSendAs::CapabilityCheckL() const
{
TSendingCapabilities aCapability(KSendAsMaxBodySizeNotUsed,KSendAsMaxMessageSizeNotUsed,iOplAPI.PopInt32());
TInt32 aIndex = OpxUtil::CppIndex(iOplAPI.PopInt32());
iOplAPI.Push(OpxUtil::OplBool16(iEngine->DoesMtmHaveCapabilityL(aIndex,aCapability)));
}
void COpxSendAs::CascNameL() const
{
TInt32 aIndex = OpxUtil::CppIndex(iOplAPI.PopInt32());
TPtrC text;
TRAPD(err,text.Set(iEngine->CascNameForMtmL(aIndex)));
if (err!=KErrNone)
{
iOplAPI.PushL(KNullDesC);
}
else
{
iOplAPI.PushL(text);
}
}
void COpxSendAs::HotkeyValueL() const
{
TInt32 aIndex = OpxUtil::CppIndex(iOplAPI.PopInt32());
iOplAPI.Push(iEngine->HotkeyForMtmL(aIndex));
}
void COpxSendAs::NextAvailableHotkeyL() const
{
iOplAPI.Push(iEngine->NextAvailableHotkeyL());
}
void COpxSendAs::UidOfMtmL() const
{
TInt32 aIndex = OpxUtil::CppIndex(iOplAPI.PopInt32());
iOplAPI.Push(iEngine->UidForMtmL(aIndex));
}
void COpxSendAs::PrepareMessageL() const
{
TInt32 aIndex = OpxUtil::CppIndex(iOplAPI.PopInt32());
iEngine->PrepareMessageL(aIndex);
iOplAPI.Push(0.0);
}
void COpxSendAs::SetSubject() const
{
TPtrC aSubject = iOplAPI.PopString();
TRAPD(ret,iEngine->SetSubjectL(aSubject));
iOplAPI.Push((TInt16)(ret));
}
void COpxSendAs::AddFileL() const
{
TFileName aFileName=iOplAPI.PopString();
if (!ConeUtils::FileExists(aFileName))
User::Leave(KOplErrNotExists);
iEngine->AddFileL(aFileName);
iOplAPI.Push(0.0);
}
void COpxSendAs::AddRecipientL() const
{
TPtrC aRecipient=iOplAPI.PopString();
iEngine->AddRecipientL(aRecipient);
iOplAPI.Push(0.0);
}
void COpxSendAs::NewBodyL() const
{
CRichText* text=iEngine->NewBodyL(iOplAPI);
iOplAPI.Push(TInt32(text));
}
void COpxSendAs::DeleteBodyL() const
{
iEngine->DeleteBodyL();
iOplAPI.Push(0.0);
}
void COpxSendAs::AppendToBodyL() const
{
TPtrC aString = iOplAPI.PopString();
iEngine->AppendToMessageBodyL(aString);
iOplAPI.Push(0.0);
}
void COpxSendAs::ResetBodyL() const
{
iEngine->ResetMessageBodyL();
iOplAPI.Push(0.0);
}
void COpxSendAs::SetBodyL() const
{
TInt32 aRichTextPointer = iOplAPI.PopInt32();
if((aRichTextPointer & 0x3) !=0) // check its on a word boundary
{
User::Leave(KOplErrInvalidArgs);
}
iEngine->SetBodyL((CRichText*)aRichTextPointer); //*(CRichText*)aRichTextPointer);
iOplAPI.Push(0.0);
}
void COpxSendAs::LaunchSendL() const
{
iEngine->LaunchSendL(iOplAPI);
iOplAPI.Push(0.0);
}
void COpxSendAs::RunL(const TInt aProcNum)
{
switch (aProcNum)
{
case EMaximumTypes:
MaximumTypesL();
break;
case ECapabilityCheck:
CapabilityCheckL();
break;
case ECascName:
CascNameL();
break;
case EHotkeyValue:
HotkeyValueL();
break;
case ENextAvailableHotkey:
NextAvailableHotkeyL();
break;
case EUidOfMtm:
UidOfMtmL();
break;
case EPrepareMessage:
PrepareMessageL();
break;
case ESetSubject:
SetSubject();
break;
case EAddFile:
AddFileL();
break;
case EAddRecipient:
AddRecipientL();
break;
case ENewBody:
NewBodyL();
break;
case EDeleteBody:
DeleteBodyL();
break;
case EAppendToBody:
AppendToBodyL();
break;
case EResetBody:
ResetBodyL();
break;
case ESetBody:
SetBodyL();
break;
case ELaunchSend:
LaunchSendL();
break;
case EScanTypes:
ScanTypesL();
break;
default:
User::Leave(KOplErrOpxProcNotFound);
}
}
TBool COpxSendAs::CheckVersion(const TInt aVersion)
{
if ((aVersion & 0xFF00) > (KOpxVersion & 0xFF00))
return EFalse;
else
return ETrue;
}
EXPORT_C COpxBase* NewOpxL(OplAPI& iOplAPI)
{
COpxSendAs* tls=((COpxSendAs*)Dll::Tls());
if (tls==NULL) // tls is NULL on loading an OPX DLL (also after unloading it)
{
tls=COpxSendAs::NewLC(iOplAPI);
User::LeaveIfError(Dll::SetTls(tls));
CleanupStack::Pop(); // tls
}
return (COpxBase *)tls;
}
EXPORT_C TUint Version()
{
return KOpxVersion;
}
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return(KErrNone);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?