📄 nqmtmsengine.cpp
字号:
void CNqMtmsEngine::GetMessageFromAddressL( TMsvId aMessageId, TDes& aAddress )
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
// Remember to load before using the SmsHeader
iSmsMtm->LoadMessageL();
CSmsHeader& header = iSmsMtm->SmsHeader();
TPtrC add = header.FromAddress();
if(add.Length() == 0)
{
CArrayPtrFlat<CSmsNumber>& smsnums = header.Recipients();
for(TInt i=0; i<smsnums.Count(); i++)
{
CSmsNumber* item = smsnums[i];
TPtrC address = item->Address();
if(address.Length() > aAddress.MaxLength())
aAddress.Append(address.Left(aAddress.MaxLength()));
else
aAddress.Append(address);
return;
}
}
else
{
if(add.Length() > aAddress.MaxLength())
aAddress.Copy(add.Left(aAddress.MaxLength()));
else
aAddress.Copy(add);
}
}
void CNqMtmsEngine::GetMessageTextL( TMsvId aMessageId, TDes& aMessage)
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
if ( iSmsMtm->Entry().HasStoreL() )
{
CMsvStore* store = iSmsMtm->Entry().ReadStoreL();
CleanupStack::PushL(store);
if (store->HasBodyTextL())
{
CRichText* richText = CRichText::NewL(
CEikonEnv::Static()->SystemParaFormatLayerL(),
CEikonEnv::Static()->SystemCharFormatLayerL());
richText->Reset();
CleanupStack::PushL(richText);
// Get the SMS body text.
store->RestoreBodyTextL(*richText);
const TInt length = richText->DocumentLength();
TInt len = (length > aMessage.MaxLength()) ? aMessage.MaxLength() : length;
aMessage.Copy( richText->Read(0, len) );
CleanupStack::PopAndDestroy(richText);
}
CleanupStack::PopAndDestroy(store);
}
}
void CNqMtmsEngine::GetMessageAddressAliasL( TMsvId aMessageId, TDes& aName )
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
TPtrC ptr = iSmsMtm->Entry().Entry().iDetails;
if(ptr.Length() > aName.MaxLength())
aName.Copy(ptr.Left(aName.MaxLength()));
else
aName.Copy( ptr );
}
void CNqMtmsEngine::GetMessageIndexBodyTextL( TMsvId aMessageId, TDes& aDescription)
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
TPtrC txt = iSmsMtm->Entry().Entry().iDescription;
if(txt.Length() > aDescription.MaxLength())
aDescription.Copy(txt.Left(aDescription.MaxLength()));
else
aDescription.Copy(txt);
}
void CNqMtmsEngine::DeleteMessageL( TMsvId aMessageId )
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
TMsvId parent = iSmsMtm->Entry().Entry().Parent();
iSmsMtm->SwitchCurrentEntryL( parent );
iSmsMtm->Entry().DeleteL( aMessageId );
}
void CNqMtmsEngine::MoveToFolderL( TMsvId aMessageId, TMsvId aFolder )
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
TMsvSelectionOrdering selection;
selection.SetShowInvisibleEntries(ETrue);
CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(),
iSmsMtm->Entry().Entry().Parent(), selection );
CleanupStack::PushL(parentEntry);
// Move the message
parentEntry->MoveL( aMessageId, aFolder );
CleanupStack::PopAndDestroy(parentEntry); // parentEntry
}
void CNqMtmsEngine::CopyMessageL( TMsvId aMessageId, TMsvId aFolder )
{
iSmsMtm->SwitchCurrentEntryL( aMessageId );
TMsvSelectionOrdering selection;
selection.SetShowInvisibleEntries(ETrue);
CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(),
iSmsMtm->Entry().Entry().Parent(), selection );
CleanupStack::PushL(parentEntry);
// iSmsMtm points to the parent
parentEntry->CopyL( aMessageId, aFolder );
CleanupStack::PopAndDestroy(); // parentEntry
}
void CNqMtmsEngine::SetUnread(TMsvId aId, TBool aUnread)
{
CMsvEntry* serverEntry = iSession->GetEntryL( aId ); // current entry
CleanupStack::PushL( serverEntry );
TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
entry.SetNew( ETrue );
entry.SetUnread( aUnread );
entry.SetVisible( ETrue );
serverEntry->ChangeL( entry ); // commit changes
CleanupStack::PopAndDestroy( serverEntry );
}
TBool CNqMtmsEngine::Unread(TMsvId aId)
{
TBool read = EFalse;
CMsvEntry* serverEntry = iSession->GetEntryL( aId ); // current entry
CleanupStack::PushL( serverEntry );
TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
read = entry.Unread();
CleanupStack::PopAndDestroy( serverEntry );
return read;
}
TBool CNqMtmsEngine::New(TMsvId aId)
{
TBool read = EFalse;
CMsvEntry* serverEntry = iSession->GetEntryL( aId ); // current entry
CleanupStack::PushL( serverEntry );
TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
read = entry.New();
read = entry.InPreparation();
read = entry.OffPeak();
read = entry.Visible();
CleanupStack::PopAndDestroy( serverEntry );
return read;
}
TMsvId CNqMtmsEngine::CreateSMSMessageL(TInt aFolderId, const TDesC& aAddress, const TDesC& aName, const TDesC& aMessage)
{
if(aFolderId != KMsvGlobalInBoxIndexEntryId
&& aFolderId != KMsvSentEntryId
&& aFolderId != KMsvDraftEntryId)
return 0;
// Set SMS parameters
TMsvEntry indexEntry;
indexEntry.SetInPreparation(ETrue);
#ifdef EKA2
indexEntry.iDate.UniversalTime();
#else
indexEntry.iDate.HomeTime();
#endif
// This is an SMS message
indexEntry.iMtm = KUidMsgTypeSMS;
indexEntry.iType = KUidMsvMessageEntry;
//Gets the ID of the current SMS service.
//in 3rd edition crashes here if capabilities are wrong
indexEntry.iServiceId = iSmsMtm->ServiceId();
// Create entry to drafts
iSmsMtm->SwitchCurrentEntryL(aFolderId);
//iSmsMtm->SwitchCurrentEntryL(KMsvSentEntryId); //test!
// Creates a new child entry owned by the context synchronously.
iSmsMtm->Entry().CreateL(indexEntry);
// Set the MTM's active context to the new message
TMsvId iSmsId = indexEntry.Id();
iSmsMtm->SwitchCurrentEntryL(iSmsId);
// Add message body. Body is set twice because index entry keeps a copy
// of some summary information. Index entry and full stored entry
// must be in sync.
CRichText& body = iSmsMtm->Body();
body.Reset();
body.InsertL(0, aMessage);
indexEntry.iDescription.Set(aMessage);
if(aFolderId == KMsvDraftEntryId)
{
iSmsMtm->AddAddresseeL(aAddress, aName);
}
// else if(aFolderId == KMsvGlobalInBoxIndexEntryId )
// {
// CSmsHeader& header = iSmsMtm->SmsHeader();
// header.SetFromAddressL(aAddress);
// }
else
{
CSmsHeader& header = iSmsMtm->SmsHeader();
header.SetFromAddressL(KNullDesC);
CArrayPtrFlat<CSmsNumber>& smsnums = header.Recipients();
CSmsNumber* number = CSmsNumber::NewL();
number->SetAddressL(aAddress);
number->SetNameL(aName);
smsnums.AppendL(number);
}
indexEntry.iDetails.Set(aName);
if (aFolderId == KMsvGlobalInBoxIndexEntryId)
indexEntry.SetUnread(ETrue);
// Commit changes because index entry is only a local variable
iSmsMtm->Entry().ChangeL(indexEntry);
// Save full message data to the store
iSmsMtm->SaveMessageL();
return iSmsId;
}
void CNqMtmsEngine::TimerExpired(TInt aIdentity)
{
if(iSendQueue.Count() > 0)
{
TMsvId id = iSendQueue[0];
iSendQueue.Remove(0);
TMsvSelectionOrdering selection;
CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(), KMsvDraftEntryId, selection );
CleanupStack::PushL( parentEntry );
// Move message to Outbox.
iOperation = parentEntry->MoveL( id, KMsvGlobalOutBoxIndexEntryId, iStatus );
CleanupStack::PopAndDestroy( parentEntry );
iState = EWaitingForMoving;
SetActive();
}
}
TBool CNqMtmsEngine::IsSms(TMsvId aId)
{
TRAPD(err, iSmsMtm->SwitchCurrentEntryL( aId ));
if(err == KErrNone)
{
TMsvEntry * iEntry = (TMsvEntry *)&(iSmsMtm->Entry().Entry());
return (iEntry->iMtm == KUidMsgTypeSMS);
}
return EFalse;
}
TBool CNqMtmsEngine::IsCompleted(TMsvId aId)
{
TRAPD(err, iSmsMtm->SwitchCurrentEntryL( aId ));
if(err == KErrNone)
{
TMsvEntry * iEntry = (TMsvEntry *)&(iSmsMtm->Entry().Entry());
return iEntry->Complete();
}
return EFalse;
}
TInt CNqMtmsEngine::SendingState(TMsvId aId)
{
TInt state = KMsvSendStateUnknown;
TRAPD(err, iSmsMtm->SwitchCurrentEntryL( aId ));
if(err == KErrNone)
{
TMsvEntry * iEntry = (TMsvEntry *)&(iSmsMtm->Entry().Entry());
state = iEntry->SendingState();
}
return state;
}
TBool CNqMtmsEngine::ResendSmsL(TMsvId aId)
{
if(IsActive())
return EFalse;
CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection;
CleanupStack::PushL( selection );
selection->AppendL( aId ); // add message to selection
#ifdef EKA2
CMsvEntry* entry = iSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
TRAPD(err, iOperation = entry->CopyL(aId, iSmsMtm->ServiceId(), iStatus) );
#else
// Add entry to task scheduler.
TBuf8<1> dummyParams; // dummy parameters needed for InvokeAsyncFunctionL
TRAPD(err, iOperation = iSmsMtm->InvokeAsyncFunctionL( ESmsMtmCommandScheduleCopy, *selection, dummyParams, iStatus ));
#endif
CleanupStack::PopAndDestroy( selection );
if(err == KErrNone)
{
iState = EWaitingForScheduling;
SetActive();
return ETrue;
}
return EFalse;
}
TBool CNqMtmsEngine::IsSending()
{
return IsActive();
}
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -