?? bodytexttransport.cpp
字號(hào):
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.
#include "bodytexttransport.h"
CBodyTextTransport::CBodyTextTransport(MTransportObserver& aObserver, TUid aSendMtm)
/**
Record this object's observer and MTM.
@param aObserver Observer to notify about transport events.
This is managed by the CTransport superclass.
@param aSendMtm UID identifies MTM which is used to construct
messages with RSendAsMessage.
*/
: CMessageTransport(aObserver),
iSendMtm(aSendMtm)
{
// empty.
}
void CBodyTextTransport::ConstructL(const TDesC& aAddress, TBool aInitListen)
/**
Second-phase constructor initializes the message transport superclass
and connects to the sendas server.
@param aAddress Remote device's address. The format depends
on the type of MTM. E.g., it could be an email
address or a string containing a telephone number.
@param aInitListen If true, this object should start by listening
for an incoming payload. Otherwise, it should
wait for its owner to send a payload to the remote
device.
*/
{
CMessageTransport::ConstructL(aAddress, aInitListen);
User::LeaveIfError(iSendAs.Connect());
}
CBodyTextTransport::~CBodyTextTransport()
/**
This destructor cancels any outstanding requests and closes
the connection to the sendas server.
*/
{
Cancel();
iSendAsMessage.Close();
iSendAs.Close();
}
// -------- implement CMessageTransport --------
void CBodyTextTransport::BuildAndSendMessageL(const TDesC& aPayloadText)
/**
Implement CMessageTransport by constructing a message with the
supplied payload as its body text. This function creates the message
and sets its recipient and body text before calling DoBuildMessageL,
which can be re-implemented by a subclass to add fields which are
specific to that transport.
@param aPayloadText Payload to send to remote device.
@post The message send request has been queued. This object will
be completed when it has been sent.
*/
{
iSendAsMessage.Close();
iSendAsMessage.CreateL(iSendAs, iSendMtm);
iSendAsMessage.AddRecipientL(*iRemoteAddress, RSendAsMessage::ESendAsRecipientTo);
iSendAsMessage.SetBodyTextL(aPayloadText);
DoBuildMessageL();
iSendAsMessage.SendMessage(iStatus);
// SetActive is called by CTransport::DoSendPayload
}
void CBodyTextTransport::DoBuildMessageL()
/**
Empty default implementation does nothing. When this function is called
the message (iSendAsMessage) has been created and the recipient and body
text have been added. A subclass can override this implementation to
add extra fields. Specifically, CEMailTransport overrides this function to
add a subject field.
*/
{
// empty.
}
HBufC* CBodyTextTransport::ExtractPlainTextLC(CMsvStore& aStore) const
/**
Implement CMessageTransport by extracting the body text from
the incoming message.
@param aStore The incoming message's store. This should
contain the body text.
@return Heap descriptor with plaintext from body.
This is placed on the cleanup stack and owned
by the caller. Note this may contain additional
material, not just the payload text.
@leave KErrOandXMessageNotFound The supplied store does not have
any body text. This can happen if an incoming
message has only been partially constructed.
*/
{
if (! aStore.HasBodyTextL())
User::Leave(KErrOandXMessageNotFound);
// the body text is extracted as rich text and then
// converted to plaintext.
CParaFormatLayer* pfl = CParaFormatLayer::NewL();
CleanupStack::PushL(pfl);
CCharFormatLayer* cfl = CCharFormatLayer::NewL();
CleanupStack::PushL(cfl);
CRichText* rt = CRichText::NewL(pfl, cfl);
CleanupStack::PushL(rt);
aStore.RestoreBodyTextL(*rt);
// the document length includes non-printing characters, and so
// establishes an upper limit on the number of plaintext characters.
TInt docLen = rt->DocumentLength();
HBufC* plainText = HBufC::NewL(docLen);
TPtr ptDes = plainText->Des();
rt->Extract(ptDes);
CleanupStack::PopAndDestroy(3, pfl);
CleanupStack::PushL(plainText);
return plainText;
}
// -------- partially implement CActive, override CMessageTransport --------
void CBodyTextTransport::DoCancel()
/**
Implement CActive and override CMessageTransport by cancelling
any outstanding send operation. If no message is being sent, i.e.
if waiting for an incoming message, then delegate to CMessageTransport,
which stops listening for incoming messages.
*/
{
// if sending a message then cancel that...
if (! iListening)
iSendAsMessage.Cancel();
// ...else if waiting for an incoming message then use the base class
else
CMessageTransport::DoCancel();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -