Beispiel #1
0
TMsvPartList CTextMtmClient::Find(const TDesC& aTextToFind, TMsvPartList aPartList)
// Find text in entry 
	{
	__ASSERT_DEBUG(iMsvEntry!=NULL, gPanic(ETxtcNoCMsvEntrySet));
	TBool found=EFalse;
	if (aPartList & KMsvMessagePartBody)
		{
		CRichText *body = &Body();
		if (body != NULL)
			{
			TInt textSize = body->DocumentLength();
			// Get searchable text

			if (textSize>0)  // Symbian OS doesn't handle allocing zero byte arrays too
				{               
				TText *bodyText = new TText[textSize];
				if (bodyText != NULL)
					{
					// search the rich text
					TPtr p(bodyText,textSize,textSize);
					body->Extract(p);
					if (p.FindF( aTextToFind ) >= 0)
						{
						found = ETrue;
						}
					}
				delete bodyText;
				}
			}
		}

	if (aPartList & KMsvMessagePartOriginator)
		{
		if (iMsvEntry->Entry().iDetails.FindF( aTextToFind ) >= 0)
			{
			found=ETrue;
			}
		}
	
	if (aPartList & KMsvMessagePartDescription)
		{
		if (iMsvEntry->Entry().iDescription.FindF( aTextToFind ) >= 0)
			{
			found=ETrue;
			}
		}
	
	// Never searched - KMsvMessagePartAttachments, KMsvMessagePartRecipient 
	// and KMsvMessagePartDate
	return found;
	}
EXPORT_C void CMsvTestUtils::WriteBodyDataL(TMsvId aId, const TFileName& aFilepath, CMsvStore& fileStore, TBool aReplace)
	{
	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
	CRichText* body = CRichText::NewL(paraLayer,charLayer);

	fileStore.RestoreBodyTextL(*body);

	HBufC* pBodyText = HBufC::NewLC(body->DocumentLength()+(body->DocumentLength()/70)+1);
	TPtr pBody = pBodyText->Des();
	body->Extract(pBody, 0);

	RFile file;
	TFileName filename(aFilepath);
	filename.Append(KFileNameBodies);
	
	TInt err = KErrNone;
	if (aReplace)
		err = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
	else
		err = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
	if(err==KErrNotFound) // file does not exist - create it
		err=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);

	TInt offset=0;
	iRTest(file.Seek(ESeekEnd, offset)==KErrNone);

	TBuf<100> buf;
	buf.Zero();
	buf.AppendFormat(_L("*** %d *************** RichText Data ***************\n"), aId);
	buf.AppendFormat(_L("Size >>> %d\n"), body->DocumentLength());	
	WriteToFileL(file, buf);
	
	RemoveRichtextFormating(pBody);
	WriteToFileL(file, pBody);
	
	buf.Zero();
	buf.AppendFormat(_L("\n********************* end of Body ***********************\n"));
	WriteToFileL(file, buf);
	
	CleanupStack::PopAndDestroy(); // pBodyText
	file.Close();
	delete paraLayer;
	delete charLayer;
	delete body;
	}
/**
  ExecuteActionL
  Obtains the parameters for the test action. Get the Message Id at given index. The Message 
  Id is stored as output parameters of this Test Action
  @internalTechnology 
  @pre    None
  @post   None
  @leave  System wide errors
*/
void CMtfTestActionSendAsSetBodyText::ExecuteActionL()
	{
	if((TestCase().TestStepResult()) == EPass)
		{
		TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendAsSetBodyText);
	
		// Get test action input parameters
		RSendAsMessage sendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(),
														ActionParameters().Parameter(0));
		
		// Buffer type to be used for adding the body text 
		// 0 => Set body text using Descriptor 
		// 1 => Set body text using CRichText object (Default)	
		TInt bufferType = ObtainValueParameterL<TInt>(TestCase(),
														ActionParameters().Parameter(1),1);
	
		TInt index = ObtainValueParameterL<TInt>(TestCase(),
														ActionParameters().Parameter(2));
	
		// Get the body text configuration file name												
		TPtrC fileName = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfDataFile,index);

		// Create a Rich text object to store the Body text contents
		CPlainText::TTextOrganisation ttOrg = {CPlainText::EOrganiseByLine};

		CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer);
		CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
		CleanupStack::PushL(charFormatLayer);
		CRichText* bodyCRichText = CRichText::NewL(paraFormatLayer, charFormatLayer);
		CleanupStack::PushL(bodyCRichText);

		HBufC* bodyTextFileName = fileName.Alloc();
		CleanupStack::PushL(bodyTextFileName);

		// Read the body text contents into the Rich text object
		bodyCRichText->ImportTextFileL(0, bodyTextFileName->Des(), ttOrg);	
	
		TInt err = KErrNone;
		// Set body text using descriptor
		if( bufferType  == 0 )
			{
			// Create a heap buffer and copy the file contents
			TInt len1 = bodyCRichText->DocumentLength();
			HBufC* buf1 = HBufC::NewL(len1);
			CleanupStack::PushL(buf1);
			
			TPtr fileContents = buf1->Des();
			bodyCRichText->Extract(fileContents,0,(len1));
			
			// Set the body text to the message
			TRAP(err, sendAsMessage.SetBodyTextL(fileContents));
			
			if(err == KErrNone)
				{
				TestCase().INFO_PRINTF1(_L("SetBodyTextL using Descriptor was successful"));
				}
			else
				{
				TestCase().ERR_PRINTF2(_L("SetBodyTextL using Descriptor failed with error: %d"), err);
				TestCase().SetTestStepResult(EFail);
				}
				
			// destroy the temporary storage of the text
			CleanupStack::PopAndDestroy(buf1);
			}
		else if (bufferType  == 1)
			{
			// Set body text using CRichText
			TRAP(err, sendAsMessage.SetBodyTextL(*bodyCRichText));
			
			if(err == KErrNone)
				{
				TestCase().INFO_PRINTF1(_L("SetBodyTextL using Rich Text was successful"));
				}
			else
				{
				TestCase().ERR_PRINTF2(_L("SetBodyTextL using Rich Text failed with error: %d"), err);
				TestCase().SetTestStepResult(EFail);
				}
			}
	 	else
			{
			err = KErrArgument;
			TestCase().ERR_PRINTF2(_L("Incorrent input parameter: Buffer type value should be either 0 or 1. The value provided is  %d"),bufferType );
			TestCase().SetTestStepResult(EFail);
			}
		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
			
		CleanupStack::PopAndDestroy(4);	//bodyTextFileName, bodyCRichText, charFormatLayer, paraFormatLayer
		TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsSetBodyText);
		}
	TestCase().ActionCompletedL(*this);
	}
// ---------------------------------------------------------
// MsgStoreHandler::HandleClass0SmsL()
// ---------------------------------------------------------
//
void MsgStoreHandler::HandleClass0SmsL(CMsvEntry* aMsgEntry, TMsvId aMsgId)
{
    CleanupStack::PushL(aMsgEntry);

    CMsvStore* store = aMsgEntry->ReadStoreL();
    CleanupStack::PushL(store);

    CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
    CleanupStack::PushL(paraFormatLayer);

    CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
    CleanupStack::PushL(charFormatLayer);

    CRichText* richText = CRichText::NewL(paraFormatLayer, charFormatLayer);
    CleanupStack::PushL(richText);

    store->RestoreBodyTextL(*richText);

    TInt len = richText->DocumentLength();
    HBufC* bufBody = HBufC::NewLC(len * 2);

    // Get Body content of SMS message
    TPtr bufBodyPtr = bufBody->Des();
    richText->Extract(bufBodyPtr, 0, len);

    //convert bufbody to qstring..
    QString body = XQConversions::s60DescToQString(*bufBody);

    Class0Info class0Info;

    class0Info.body = body;
    CleanupStack::PopAndDestroy(bufBody);

    // Get From address of SMS message
    CPlainText* nullString = CPlainText::NewL();
    CleanupStack::PushL(nullString);

    CSmsHeader* smsheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *nullString);
    CleanupStack::PushL(smsheader);
    smsheader->RestoreL(*store);

    QString address = XQConversions::s60DescToQString(smsheader->FromAddress());
    class0Info.address = address;

    // Get alias of SMS message
    QString alias;
    int count;
    MsgContactHandler::resolveContactDisplayName(address, alias, count);
    class0Info.alias = alias;

    // Get timestamp of SMS message
    QDateTime timeStamp;
    TTime time = aMsgEntry->Entry().iDate;
    TTime unixEpoch(KUnixEpoch);
    TTimeIntervalSeconds seconds;
    time.SecondsFrom(unixEpoch, seconds);
    timeStamp.setTime_t(seconds.Int());

    const QString times = timeStamp.toString("dd/MM/yy hh:mm ap");
    class0Info.time = times;

    class0Info.messageId = aMsgId;
    CleanupStack::PopAndDestroy(7);
    aMsgEntry = NULL;

    // Show the SMS message..  
    iNotifier->ShowClass0Message(class0Info);
}