messagingfw/msgurlhandler/test/ui/src/TestMsgUrlHandlerDoc.CPP
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file contains the implementation for the class defined in 
       
    15 // TestMsgUrlHandlerApp.h
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @see	TestMsgUrlHandlerApp.h
       
    22 */
       
    23 #include <e32test.h>
       
    24 #include "smstestutils.h"
       
    25 #include <cemailaccounts.h>
       
    26 #include <csmsaccount.h>
       
    27 #include <pop3set.h>
       
    28 #include <smtpset.h>
       
    29 #include <iapprefs.h>
       
    30 
       
    31 #include "TestMsgUrlHandlerApp.H"
       
    32 
       
    33 //             The constructor of the document class just passes the
       
    34 //             supplied reference to the constructor initialisation list.
       
    35 //             The document has no real work to do in this application.
       
    36 //
       
    37 
       
    38 CTestMsgUrlHandlerDocument* CTestMsgUrlHandlerDocument::NewL(CEikApplication& aApp)
       
    39     {
       
    40     CTestMsgUrlHandlerDocument* self = new (ELeave) CTestMsgUrlHandlerDocument(aApp);
       
    41 	self->ConstructL();
       
    42     return self;
       
    43     }
       
    44 
       
    45 void CTestMsgUrlHandlerDocument::ConstructL()
       
    46     {
       
    47 	// Ensure there are default service settings.
       
    48 	CreateSMSServiceL();
       
    49 	CreateEmailServiceL();
       
    50 
       
    51     }
       
    52 
       
    53 void CTestMsgUrlHandlerDocument::CreateSMSServiceL()
       
    54 	{
       
    55 	RTest aTest(_L("URL Handler UI Test"));
       
    56 	CSmsTestUtils* testUtils = CSmsTestUtils::NewL(aTest);
       
    57 	CleanupStack::PushL(testUtils);
       
    58 	testUtils->SetEntryL(testUtils->iSmsServiceId);
       
    59 	CSmsAccount* account = CSmsAccount::NewLC();
       
    60 	account->LoadSettingsL(*testUtils->iServiceSettings);
       
    61 	// Remove the default service centres from the service settings
       
    62 	TInt count = testUtils->iServiceSettings->ServiceCenterCount();
       
    63 	while( count-- )
       
    64 		{
       
    65 		testUtils->iServiceSettings->RemoveServiceCenter(count);
       
    66 		}
       
    67 	// Add the Vodafone service centre - store the settings.
       
    68 	testUtils->iServiceSettings->AddServiceCenterL(_L("Vodafone"), _L("+447785016005"));
       
    69 	// Set delivery options - do matching and make reports visible.	
       
    70 	testUtils->iServiceSettings->SetDeliveryReport(ETrue);
       
    71 	testUtils->iServiceSettings->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisibleAndMatch);
       
    72 	account->SaveSettingsL(*testUtils->iServiceSettings);
       
    73 	CleanupStack::PopAndDestroy(2, testUtils); // account, testUtils
       
    74 	aTest.Close();
       
    75 	}
       
    76 
       
    77 void CTestMsgUrlHandlerDocument::CreateEmailServiceL()
       
    78 	{	
       
    79 	TMsvId popServiceId = 0;
       
    80 	TRAPD(err, ServiceIdL(KUidMsgTypePOP3, popServiceId));
       
    81 
       
    82 	if (err)
       
    83 		{
       
    84 		CEmailAccounts* account = CEmailAccounts::NewLC();
       
    85 
       
    86 		CImPop3Settings* popSettings = new(ELeave) CImPop3Settings();
       
    87 		CleanupStack::PushL(popSettings);
       
    88 		CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
    89 		CleanupStack::PushL(smtpSettings);
       
    90 		
       
    91 		CImIAPPreferences* popIAP = CImIAPPreferences::NewLC();
       
    92 		CImIAPPreferences* smtpIAP = CImIAPPreferences::NewLC();
       
    93 				
       
    94 		account->PopulateDefaultPopSettingsL(*popSettings, *popIAP); 
       
    95 		account->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIAP);
       
    96 
       
    97 		_LIT(KSmtpServer, "smtp.dial.pipex.com");
       
    98 		smtpSettings->SetServerAddressL(KSmtpServer);
       
    99 		smtpSettings->SetEmailAliasL(_L("Messaging Test1"));
       
   100 		_LIT(KSmtpEmailAddress, "msgtest1@internet-test.plc.psion.com");
       
   101 		smtpSettings->SetEmailAddressL(KSmtpEmailAddress);
       
   102 		smtpSettings->SetReplyToAddressL(KSmtpEmailAddress);
       
   103 		smtpSettings->SetBodyEncoding(EMsgOutboxMIME);
       
   104 		smtpSettings->SetReceiptAddressL(KSmtpEmailAddress);
       
   105 		smtpSettings->SetPort(25);
       
   106 	
       
   107 		TPopAccount popAccount= account->CreatePopAccountL(KNullDesC, *popSettings, *popIAP, EFalse);
       
   108 		
       
   109 		account->CreateSmtpAccountL(popAccount, *smtpSettings, *smtpIAP, EFalse);
       
   110 		
       
   111 		CleanupStack::PopAndDestroy(5, account); // smtpIAP, popIAP, smtpSettings, popSettings, account
       
   112 		}
       
   113 	}
       
   114 
       
   115 void CTestMsgUrlHandlerDocument::ServiceIdL(TUid aMtm, TMsvId& rFirstId)
       
   116 	{
       
   117 	//Returns the Service IDs of MTM aMtm
       
   118 	CDummyObserver* ob1 = new(ELeave) CDummyObserver;
       
   119 	CleanupStack::PushL(ob1);
       
   120 
       
   121 	CMsvSession* session = CMsvSession::OpenSyncL(*ob1);
       
   122 	CleanupStack::PushL(session);
       
   123 	
       
   124 	CMsvEntry* cEntry = session->GetEntryL(KMsvRootIndexEntryId);
       
   125 	CleanupStack::PushL(cEntry);
       
   126 
       
   127 	rFirstId = KMsvNullIndexEntryId;
       
   128 
       
   129 	TMsvSelectionOrdering order;
       
   130 	order.SetShowInvisibleEntries(ETrue);
       
   131 	cEntry->SetSortTypeL(order);
       
   132 
       
   133 	//Get the children on the Root Index Entry
       
   134 	CMsvEntrySelection* selection = cEntry->ChildrenWithTypeL(KUidMsvServiceEntry);
       
   135 	CleanupStack::PushL(selection);
       
   136 
       
   137 	TInt count = selection->Count();
       
   138 
       
   139 	//Find an entry for MTM aMtm
       
   140 	for (TInt curChild = 0; curChild < count && (rFirstId == KMsvNullIndexEntryId); curChild++)
       
   141 		{
       
   142 		cEntry->SetEntryL(selection->At(curChild));
       
   143 
       
   144 		if (cEntry->Entry().iMtm == aMtm)
       
   145 			{
       
   146 			TMsvId id = cEntry->Entry().Id();
       
   147 
       
   148 			if (rFirstId == KMsvNullIndexEntryId)
       
   149 				rFirstId = id;
       
   150 			}
       
   151 		}
       
   152 
       
   153 	//Leave if no Service Entry found for MTM aMtm
       
   154 	if (rFirstId == KMsvNullIndexEntryId)
       
   155 		{
       
   156 		CleanupStack::PopAndDestroy(); //selection
       
   157 		User::Leave(KErrNotFound);
       
   158 		}
       
   159 
       
   160 	CleanupStack::PopAndDestroy(4, ob1); //selection, cMsvEntry, session, ob1
       
   161 	}
       
   162 
       
   163 CTestMsgUrlHandlerDocument::CTestMsgUrlHandlerDocument(CEikApplication& aApp)
       
   164 		: CEikDocument(aApp)
       
   165 	{
       
   166 	}
       
   167 
       
   168 
       
   169 //             This is called by the UI framework as soon as the 
       
   170 //             document has been created. It creates an instance
       
   171 //             of the ApplicationUI. The Application UI class is
       
   172 //             an instance of a CEikAppUi derived class.
       
   173 //
       
   174 CEikAppUi* CTestMsgUrlHandlerDocument::CreateAppUiL()
       
   175 	{
       
   176 	return new (ELeave) CTestMsgUrlHandlerAppUi;
       
   177 	}