⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmsutils.cpp

📁 Symbian OS C++ for Mobile Phones Volume 3 源码
💻 CPP
字号:
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.

#include "mmsutils.h"


void MmsUtils::FileNameFromPrivateDirL(RFs& aFs, TDes& aFullName, const TDesC& aNameAndExt)
/**
	Converts a filename and extension to a fully qualified filename using the
	current current process' private directory.
	
	@param	aFs				File server session, used to get private path.
	@param	aFullName		On success this contains the fully qualified filename.
							To ensure the filename will fit this should have at least
							KMaxFileName characters.
	@param	aNameAndExt		The filename to convert to a fully qualified filename.
 */
	{
	TRAN_LOG1(">MmsUtils::FileNameFromPrivateDirL,nae=\"%S\"", &aNameAndExt);
	
	// For the emulator, the app is installed to Z; for hardware it is installed
	// to a writable media.
	aFullName.Zero();
#ifdef __WINS__
	TText drvLtr = 'Z';
#else
	TText drvLtr = RProcess().FileName()[0];
#endif
	aFullName.Append(drvLtr);
	aFullName.Append(':');
	
	// get the application's private directory
	TFileName fnAppFileName;
	TInt r = aFs.PrivatePath(fnAppFileName);
	User::LeaveIfError(r);
	
	const TParsePtrC prvDir(fnAppFileName);
	aFullName.Append(prvDir.Path());
	aFullName.Append(aNameAndExt);
	
	TRAN_LOG1("<MmsUtils::FileNameFromPrivateDirL,fn=\"%S\"", &aFullName);
	}

HBufC8* MmsUtils::BuildFramedPayloadLC(const TDesC& aPayload)
/**
	Takes the supplied payload text and converts it to a framed 8 bit descriptor.
	(The "frame" in this case is extraneous text.  It is unrelated to the KMtPrefix
	string which is included in the supplied payload.)
	
	@param	aPayload		Native-width text to frame.
	@return					Framed payload text suitable for attaching to an MMS.
							This is owned by the caller.
 */
	{
	HBufC8* pyl8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aPayload);
	CleanupStack::PushL(pyl8);
	
	static const TInt KFrameLen = 27;	// matches KPayloadFormat below
	HBufC8* framedPayload = HBufC8::NewL(KFrameLen + pyl8->Length());
	
	// write payload text into a text file.  RFC2046 specifies "The canonical form
	// of any MIME "text" subtype MUST always represent a line break as a CRLF sequence."
	_LIT8(KFrameFormat, "OandX move\r\n%S\r\nend of move\r\n");
	framedPayload->Des().Format(KFrameFormat, pyl8);
	
	CleanupStack::PopAndDestroy(pyl8);
	CleanupStack::PushL(framedPayload);
	
	return framedPayload;
	}

HBufC* MmsUtils::ExtractPlainTextLC(CMsvStore& aStore)
/**
	Extract the contents of the payload file attachment.
	This may contain extraneous data, not just the payload.
	
	@param	aStore			Store contains the entry's attachments.
	@return					Newly-allocated descriptor which contains the
							text in the payload attachment.  The caller owns
							this object.
	@leave KErrOandXMessageNotFound Payload not found in any attachment.
		Otherwise, any Symbian OS error code.
 */
	{
	MMsvAttachmentManager& attachMan = aStore.AttachmentManagerL();
	TInt attachCount = attachMan.AttachmentCount();
	
	for (TInt i = 0; i < attachCount; ++i)
		{
		// is this a text file attachment with the expected name?
		CMsvAttachment* msva = attachMan.GetAttachmentInfoL(i);
		TBool payloadFile =
				msva->Type() == CMsvAttachment::EMsvFile
			&&	msva->MimeType() == KMmsTextPlain
			&&	msva->AttachmentName() == KPayloadAttachmentName;
		delete msva;
		
		if (payloadFile)
			return ExtractPlainTextFromFileLC(attachMan.GetAttachmentFileL(i));
		}
	
	// payload not found in any attachment
	User::Leave(KErrOandXMessageNotFound);
	return NULL;		// avoid "return value expected" warning
	}

HBufC* MmsUtils::ExtractPlainTextFromFileLC(RFile aFile)
/**
	Extract the contents of the supplied attachment file.
	
	@param	aFile			File which contains the payload text.  This file
							is open on entry, and this function must close it.
	@return					Entire file contents.  The caller owns this object
							which is on the cleanup stack.
 */
	{
	CleanupClosePushL(aFile);
	
	TInt fileSize;
	User::LeaveIfError(aFile.Size(fileSize));
	
	HBufC8* contents8 = HBufC8::NewLC(fileSize);
	TPtr8 ptr8 = contents8->Des();
	User::LeaveIfError(aFile.Read(ptr8));
	
	HBufC16* contents = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*contents8);
	
	CleanupStack::PopAndDestroy(2, &aFile);	// contents8, aFile
	CleanupStack::PushL(contents);
	
	return contents;
	}

⌨️ 快捷键说明

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