email/email/pop/src/T_CopyPopSelection.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // [TestStep Name]
       
    15 // CopyPopSelection
       
    16 // [Paramaters]
       
    17 // PopAccountName				:	Name of the Pop account
       
    18 // TargetFolderName				:   Name of the target folder to which the entries need to be copied 				
       
    19 // Copies the entries to the target.
       
    20 // [APIs Used]
       
    21 // CMsvEntry::SetEntryL
       
    22 // CMsvEntry::CopyL
       
    23 // 
       
    24 //
       
    25 
       
    26 
       
    27 
       
    28 /**
       
    29  @file
       
    30 */
       
    31 
       
    32 // User includes
       
    33 #include "T_CopyPopSelection.h"
       
    34 #include <t_utilscentralrepository.h>
       
    35 #include <t_utils.h>
       
    36 #include <t_utilsenumconverter.h>
       
    37 #include "T_MsgSharedDataPop.h"
       
    38 
       
    39 
       
    40 // Literals Used
       
    41 _LIT(KPopAccountName,"PopAccountName");
       
    42 _LIT(KTargetFolderName,"TargetFolderName");
       
    43 _LIT(KMove, "Move");
       
    44 _LIT(KCopyWithinService, "CopyWithinService");
       
    45 
       
    46 /**
       
    47 CT_MsgCopyPopSelection()
       
    48 Sets the teststep name to KCopyPopSelection
       
    49 
       
    50 @param aSharedDataPOP
       
    51 Data shared across the POP test steps. Ex. Session
       
    52 */
       
    53 CT_MsgCopyPopSelection::CT_MsgCopyPopSelection(CT_MsgSharedDataPop& aSharedDataPOP)
       
    54 :	CT_MsgAsyncStepPOP(aSharedDataPOP) 
       
    55 ,	iOperation(NULL)
       
    56 	{
       
    57 	SetTestStepName(KCopyPopSelection);
       
    58 	}
       
    59 
       
    60 /**
       
    61 NewL()
       
    62 Allocates and creates a new CT_MsgCopyPopSelection object
       
    63   
       
    64 @param aSharedDataPOP
       
    65 Data shared across the POP test steps. Ex. Session
       
    66 
       
    67 @leave KErrNoMemory
       
    68 @return
       
    69 Returns pointer to an object of CT_MsgComparePopEmailMsgs
       
    70 */
       
    71 CT_MsgCopyPopSelection* CT_MsgCopyPopSelection::NewL(CT_MsgSharedDataPop& aSharedDataPOP)
       
    72 	{
       
    73 	CT_MsgCopyPopSelection* self = new(ELeave) CT_MsgCopyPopSelection(aSharedDataPOP);
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL(); 					 // Call CT_AsyncStep::ConstructL()
       
    76 	CleanupStack::Pop(self);
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 
       
    81 /**
       
    82 ~CT_MsgCopyPopSelection()
       
    83 Destructor
       
    84 */
       
    85 CT_MsgCopyPopSelection::~CT_MsgCopyPopSelection()
       
    86 	{
       
    87 	delete iOperation;
       
    88 	iOperation=NULL;
       
    89 	}
       
    90 
       
    91 
       
    92 /**
       
    93 ProgressL()
       
    94 
       
    95 @param
       
    96 */
       
    97 void CT_MsgCopyPopSelection::ProgressL(TBool bFinal)
       
    98 	{
       
    99 	//	TODO
       
   100 	if (bFinal)
       
   101 		{
       
   102 		//	Display final progress iOperation
       
   103 		}
       
   104 	else
       
   105 		{
       
   106 		//	Display current progress iOperation
       
   107 		}
       
   108 	}
       
   109 
       
   110 
       
   111 /**
       
   112 CancelStep()
       
   113 
       
   114 */
       
   115 void CT_MsgCopyPopSelection::CancelStep()
       
   116 	{
       
   117 	iOperation->Cancel();
       
   118 	}
       
   119 
       
   120 
       
   121 /**
       
   122 doTestStepL()
       
   123 A connection with the POP server is established in the doTestStepPreambleL of the 
       
   124 base class. Reads the Pop account name from the ini file. It obtains a selection of
       
   125 the entires under POP account given. It copies these entries into the specified target folder.
       
   126  
       
   127 @return
       
   128 Returns the test step result
       
   129 */
       
   130 TVerdict CT_MsgCopyPopSelection::doTestStepL()
       
   131 	{
       
   132 	INFO_PRINTF1(_L("TestStep : CopyPopSelection"));
       
   133 	// Read the POP account name from the ini file
       
   134 	TPtrC popAccountName;
       
   135 	if(!GetStringFromConfig(ConfigSection(), KPopAccountName, popAccountName))
       
   136 		{
       
   137 		ERR_PRINTF1(_L("Pop Account Name is not specified"));
       
   138 		SetTestStepResult(EFail);
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		// Retrieving the Pop service Id for the given Pop account
       
   143 		TMsvId popServiceId = CT_MsgUtilsCentralRepository::GetPopServiceIdL((TDes&)popAccountName);
       
   144 		INFO_PRINTF2(_L("Pop service id is %d"),popServiceId);
       
   145 
       
   146 		if(popServiceId == KMsvNullIndexEntryId)
       
   147 			{
       
   148 			ERR_PRINTF1(_L("Invalid POP account name specified"));
       
   149 			SetTestStepResult(EFail);
       
   150 			}
       
   151 		else
       
   152 			{
       
   153 			TMsvId targetFolderId = KErrNotFound;
       
   154 			TBool copyWithinService = EFalse;
       
   155 			GetBoolFromConfig(ConfigSection(), KCopyWithinService, copyWithinService);
       
   156 
       
   157 			if (!copyWithinService)
       
   158 				{
       
   159 				TPtrC targetFolderName;
       
   160 				if(!GetStringFromConfig(ConfigSection(), KTargetFolderName, targetFolderName))
       
   161 					{
       
   162 					ERR_PRINTF1(_L("Target Folder is not specified"));
       
   163 					SetTestStepResult(EFail);
       
   164 					}
       
   165 				else
       
   166 					{
       
   167 					// Retrieves the folder Id based on the local folder name read from the ini file
       
   168 					targetFolderId = CT_MsgUtilsEnumConverter::FindFolderIdByName(targetFolderName);
       
   169 					if(targetFolderId == KErrNotFound)
       
   170 						{
       
   171 						ERR_PRINTF1(_L("Invalid local folder name specified"));
       
   172 						SetTestStepResult(EFail);
       
   173 						}
       
   174 					}
       
   175 				}
       
   176 
       
   177 			if (copyWithinService || targetFolderId != KErrNotFound)
       
   178 				{
       
   179 				// Get a selection of the children entries for the Pop account
       
   180 				CMsvEntrySelection* selection =  CT_MsgUtils::CreateChildrenSelectionL(iSharedDataPOP.iSession,
       
   181 																			popServiceId);
       
   182 				CleanupStack::PushL(selection);
       
   183 					
       
   184 				// Check if there are no entries under the remote folder 
       
   185 				TInt count = selection->Count();
       
   186 				if (count == 0)
       
   187 					{
       
   188 					User::Leave(KErrArgument);
       
   189 					}
       
   190 				// Fetch the Id of the first entry
       
   191 				TMsvId entryId = (*selection)[0];
       
   192 
       
   193 				// Creates a new CMsvEntry for the specified entry ID.
       
   194 				CMsvEntry* entry = CMsvEntry::NewL(*iSharedDataPOP.iSession,entryId,TMsvSelectionOrdering());
       
   195 				CleanupStack::PushL(entry);
       
   196 						
       
   197 				// Sets the context to the parent of the specified entry.
       
   198 				entry->SetEntryL(entryId);
       
   199 				entry->SetEntryL(entry->Entry().Parent());
       
   200 
       
   201 				TBool isMove = EFalse;
       
   202 				if(GetBoolFromConfig(ConfigSection(), KMove, isMove))
       
   203 					{
       
   204 					INFO_PRINTF1(_L("Is move"));
       
   205 					}
       
   206 
       
   207 				CT_MsgActive&	active=Active();
       
   208 
       
   209 				if (copyWithinService)
       
   210 					{
       
   211 					if (isMove)
       
   212 						{
       
   213 						iOperation = entry->MoveL(*selection,popServiceId, active.iStatus);
       
   214 						}
       
   215 					else
       
   216 						{
       
   217 						iOperation = entry->CopyL(*selection,popServiceId, active.iStatus);						
       
   218 						}
       
   219 					}
       
   220 				else
       
   221 					{
       
   222 					if (isMove)
       
   223 						{
       
   224 						iOperation = entry->MoveL(*selection,targetFolderId, active.iStatus);
       
   225 						}
       
   226 					else
       
   227 						{
       
   228 						iOperation = entry->CopyL(*selection,targetFolderId, active.iStatus);						
       
   229 						}
       
   230 					}
       
   231 
       
   232 				active.Activate();
       
   233 				CActiveScheduler::Start();
       
   234 
       
   235 				// Get the error code from TPop3Progress
       
   236 				TPop3Progress temp;
       
   237 				TPckgC<TPop3Progress> paramPack(temp);
       
   238 				paramPack.Set(iOperation->ProgressL());
       
   239 				TPop3Progress progress=paramPack();
       
   240 				SetTestStepError(progress.iErrorCode);
       
   241 
       
   242 				delete iOperation;
       
   243 				iOperation=NULL;
       
   244 				CleanupStack::PopAndDestroy(2,selection); //operation,entry,selection
       
   245 				User::LeaveIfError(active.Result());
       
   246 				}		
       
   247 			}
       
   248 		}
       
   249 	return TestStepResult();
       
   250 	}