📄 mmsdemo1engine.cpp
字号:
}
iMessageReady = ETrue;
return ETrue;
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::SetSubjectL()
Description: Set the subject of the current message.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::SetSubjectL(const TDesC& aSubject)
{
iMmsMtm->SetSubjectL(aSubject);
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::DeleteMessageL()
Description: Delete a message. The caller will provide IDs for the parent
and the message entry to be deleted.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::DeleteMessageL(TMsvId aParent, TMsvId aMessage)
{
// Point our entry to the parent of the message to be deleted
CMsvEntry* cEntry = iSession->GetEntryL(aParent); // change context
CleanupStack::PushL(cEntry);
// Delete selected message
cEntry->DeleteL(aMessage);
CleanupStack::PopAndDestroy(); // cEntry
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::GetObjectsL()
Description: Read the attachment file paths and return them in a descriptor
array.
Return value: N/A, attachment file paths in an array
-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::GetObjectsL(CDesC16ArrayFlat& aArray)
{
TBool returnValue = EFalse;
// Read attachments into parameters
CMsvEntrySelection* att = iMmsMtm->GetAttachmentsL();
CleanupStack::PushL(att);
if(att->Count() > 0)
{
for(TInt i = 0; i < att->Count(); i++)
{
TFileName fileName;
// this is given a TMsvId of the att entry and the descriptor for path name
iMmsMtm->GetAttachmentPathL(att->At(i), fileName );
aArray.InsertL(i, fileName);
}
returnValue = ETrue;
}
CleanupStack::PopAndDestroy(); // att
return returnValue;
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::ReadMessagesL()
Description: Read all MMS messages in a folder. Read message IDs are returned
in a CMsvEntrySelection list. Message index entry descriptions
and details are written into parameter list.
Note: This method changes the context!
Return value: CMsvEntrySelection, caller has to free memory after use!
A list of message descriptions is returned in aDescriptorList
-------------------------------------------------------------------------------
*/
CMsvEntrySelection* CMMSDemo1Engine::ReadMessagesL(TMsvId aFolder, CDesC16Array& aDescriptorList)
{
// first take a handle to folder
TMsvSelectionOrdering sort;
sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries
// Take a handle to the folder entry
CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession, aFolder, sort);
CleanupStack::PushL(parentEntry);
// A selection of all MMS entries
CMsvEntrySelection* entries = parentEntry->ChildrenWithMtmL(KUidMsgTypeMultimedia);
CleanupStack::PushL(entries);
// go through the selection and read descriptions into a list
for(TInt i = 0; i < entries->Count(); i++)
{
// we can use the mtm to go through the selection.
iMmsMtm->SwitchCurrentEntryL( (*entries)[i] );
aDescriptorList.AppendL(iMmsMtm->Entry().Entry().iDetails);
aDescriptorList.AppendL(iMmsMtm->Entry().Entry().iDescription);
}
CleanupStack::Pop(2); // parentEntry, entries
delete parentEntry;
return entries; // Caller must free this memory after use!
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::MessageReady()
Description: This returns true if the engine has a message loaded, ready
for sending.
Return value: ETrue / EFalse
-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::MessageReady()
{
return iMessageReady;
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::NewMessages()
Description: This returns true if there are new MMS messages in the Inbox.
Return value: ETrue / EFalse
-------------------------------------------------------------------------------
*/
TInt CMMSDemo1Engine::NewMessages()
{
return iNewMessages;
}
/*
-----------------------------------------------------------------------------
CMMSDemo1Engine::HandleSessionEventL()
Receives session events from observer and calls event handling functions.
The type of event is indicated by the value of aEvent. The
interpretation of the TAny arguments depends on this type. For most
event types, the action that is taken, for example updating the
display, is client-specific.
-----------------------------------------------------------------------------
*/
void CMMSDemo1Engine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
{
switch (aEvent)
{
// Message events handling, e.g. receiving
case EMsvEntriesCreated:
// We are interested in messages that are created in Inbox
TMsvId* parentId;
parentId = static_cast<TMsvId*>(aArg2); // parent entry id from the session event
if ( *parentId == KMsvGlobalInBoxIndexEntryId ) // new entry has been created in Inbox folder
{
// We take the created entries into a selection
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
// entry pointer for making changes in the actual message contexts
CMsvEntry* entry;
//Process each created entry, one at a time.
for(TInt i = 0; i < entries->Count(); i++)
{
entry = iSession->GetEntryL( entries->At(i) ); // this reserves memory for a new CMsvEntry
CleanupStack::PushL(entry);
TMsvEntry msvEntry(entry->Entry());
if(msvEntry.iMtm == KUidMsgTypeMultimedia) // message is a MMS
{
// We could also check that message is of correct content
// but as this is the mms engine and message handling is designed to
// be only general, we don't do it. One possibility to id a message content
// would be to check the subject field if it has some application specific value etc.
iNewMessages++;
}
CleanupStack::PopAndDestroy(entry);
}
}
break;
// This event tells us that the session has been opened
case EMsvServerReady:
CompleteConstructL(); // Construct the mtm registry & MMS mtm
break;
default:
// All other events are ignored
break;
}
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::GetAddresseesL()
Description: Get message addressees of a given type (To or Cc).
Return value: CDesCArray&
-------------------------------------------------------------------------------
*/
const CDesCArray& CMMSDemo1Engine::GetAddresseesL(TAddresseeType aType)
{
// Read addressees
return iMmsMtm->TypedAddresseeList((TMmsRecipients)aType);
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::SetObjectTypeL()
Description: Set the MIME type for a given attachment.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::SetObjectTypeL(TMsvId aAttId, TDesC8& aMimeType)
{
iMmsMtm->SetAttachmentTypeL(aAttId, aMimeType);
}
//
// protected methods
//
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::MessageSize()
Description: Returns the size of the message. Returned value is valid for
the last message state saved by SaveMessageL(). Any changes
after that are not counted in the returned size value.
Return value: TInt32
-------------------------------------------------------------------------------
*/
TInt32 CMMSDemo1Engine::MessageSize()
{
return iMmsMtm->MessageSize();
}
//
// Additional methods to be implemented in a future MMS demo
//
void CMMSDemo1Engine::GetObjectSizeL()
{
}
void CMMSDemo1Engine::ValidateMessageL()
{
}
void CMMSDemo1Engine::GetServiceL()
{
}
void CMMSDemo1Engine::SetService() // not supported
{
}
void CMMSDemo1Engine::RemoveAddresseeL()
{
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::MoveMessageL()
Description: Move current message to another folder.
Return value: TBool
-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::MoveMessageL(TMsvId aTarget)
{
TMsvId parentId = iMmsMtm->Entry().Entry().Parent();
TMsvId currentId = iMmsMtm->Entry().Entry().Id();
if(aTarget == parentId)
{
// no need to move
return EFalse;
}
// Set up our entry to the parent folder so that we can move
// the message.
CMsvEntry* cEntry = iSession->GetEntryL( parentId );
CleanupStack::PushL(cEntry);
// view all entries (also invisible ones)
cEntry->SetSortTypeL( TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
// wait object for the operation (move)
CMsvOperationWait* wait = CMsvOperationWait::NewLC(); // left in CS
wait->Start();
// new move operation
CMsvOperation* oper = cEntry->MoveL( currentId, aTarget, wait->iStatus );
CleanupStack::PushL(oper);
// Start a new wait loop
CActiveScheduler::Start();
if( wait->iStatus.Int() != KErrNone )
{
CleanupStack::PopAndDestroy(3); // oper, wait, cEntry
return EFalse;
}
CleanupStack::PopAndDestroy(3); // oper, wait, cEntry
return ETrue;
}
//
// private methods
//
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::ConstructL()
Description: 2nd phase Constructor.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::ConstructL()
{
// Open a connection to messaging server
InitServerSessionL();
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::CompleteConstructL()
Description: 2nd phase Constructor. This method completes construction
after the server session has been opened.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::CompleteConstructL()
{
// create client MTM
InitClientMTML();
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::CMMSDemo1Engine()
Description: Constructor.
Return value: N/A
-------------------------------------------------------------------------------
*/
CMMSDemo1Engine::CMMSDemo1Engine()
{
iNewMessages = 0; // New messages count tells only the amount of messages
// received while running. (not the actual state of Inbox)
iMessageReady = EFalse;
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::InitServerSessionL()
Description: Initialising a session to the messaging server. This is done
in async and the execution is returned to the ConstructL()
immediately.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::InitServerSessionL()
{
// Create CMsvSession
iSession = CMsvSession::OpenAsyncL(*this);
// New session is opened asynchronously
// CompleteConstructL() is called when async call is finished.
}
/*
-------------------------------------------------------------------------------
CMMSDemo1Engine::InitClientMTML()
Description: Initialising a client MTM registry and the actual
MMS client MTM.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::InitClientMTML()
{
// We call our session for a MtmClientRegistry
iMtmReg = CClientMtmRegistry::NewL(*iSession);
// This registry is used to instantiate a new mtm.
iMmsMtm = (CMmsClientMtm*) iMtmReg->NewMtmL( KUidMsgTypeMultimedia );
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -