email/testutils/src/T_UtilsDeleteAllChildren.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 // This is the Cpp file which contains the utility functions to delete all children in the
       
    15 // message store
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 
       
    26 // User includes
       
    27 #include <t_utilsdeleteallchildren.h>
       
    28 	
       
    29 // Epoc includes
       
    30 #include <msvapi.h>
       
    31 #include <msvuids.h>
       
    32 
       
    33 /**
       
    34 CT_MsgUtilsDeleteAllChildren()
       
    35 Constructor
       
    36 
       
    37 @param aSession
       
    38 An object of CMsvSession
       
    39 
       
    40 @param aParentId
       
    41 Entry ID of whose children would be deleted
       
    42 */
       
    43 EXPORT_C CT_MsgUtilsDeleteAllChildren::CT_MsgUtilsDeleteAllChildren(CMsvSession* aSession,TMsvId aParentId) 
       
    44 : CActive(EPriorityNormal), iSession(aSession), iParentId(aParentId) 
       
    45 	{
       
    46 	CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 
       
    50 /**
       
    51 ~CT_MsgUtilsDeleteAllChildren()
       
    52 Destructor
       
    53 */
       
    54 CT_MsgUtilsDeleteAllChildren::~CT_MsgUtilsDeleteAllChildren()
       
    55 	{
       
    56 	delete iEntry;
       
    57 	delete iSelection;
       
    58 	}
       
    59 
       
    60 
       
    61 /**
       
    62 StartL()
       
    63 Deletes the children entries of the specified parent
       
    64 
       
    65 @param aStatus			
       
    66 */
       
    67 EXPORT_C void CT_MsgUtilsDeleteAllChildren::StartL(TRequestStatus& aStatus)
       
    68 	{
       
    69 	StartL(EFalse, aStatus);
       
    70 	}
       
    71 
       
    72 /**
       
    73 StartL()
       
    74 Deletes the children entries of the specified parent
       
    75 
       
    76 @param aBlockDelete Delete all in one go
       
    77 @param aStatus			
       
    78 */
       
    79 EXPORT_C void CT_MsgUtilsDeleteAllChildren::StartL(TBool aBlockDelete, TRequestStatus& aStatus)
       
    80 	{
       
    81 	iRequestStatus = &aStatus;
       
    82 	aStatus = KRequestPending;
       
    83 
       
    84 	// Creates a new CMsvEntry for the specified parent entry ID nad sets the context
       
    85 	// to that entry.
       
    86 	if(iEntry==NULL)
       
    87 	{
       
    88 	iEntry = CMsvEntry::NewL(*iSession,iParentId,TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
       
    89 	}
       
    90 	iEntry->SetEntryL(iParentId);
       
    91 	
       
    92 	// Gets a selection containing the IDs of children
       
    93 	iSelection = iEntry->ChildrenL();
       
    94 	iTotalChildren = iSelection->Count();
       
    95 	
       
    96 	// If the entry has no children entries, then signals the thread that the asynchronous request 
       
    97 	// is complete.
       
    98 	if (iTotalChildren == 0)
       
    99 		{
       
   100 		User::RequestComplete(iRequestStatus,KErrNone);
       
   101 		}
       
   102 		
       
   103 	
       
   104 	// If the entry has children entries then,delete child entries of the context
       
   105 	// recursively through all the descendants
       
   106 	else
       
   107 		{
       
   108 		if (aBlockDelete)
       
   109 			{
       
   110 			iOperation = iEntry->DeleteL(*iSelection ,iStatus);
       
   111 			iState = EBlockDelete;
       
   112 			}
       
   113 		else
       
   114 			{
       
   115 			iOperation = iEntry->DeleteL((*iSelection)[iCurrentChild],iStatus);
       
   116 			iState = EStateThisLevel;
       
   117 			}
       
   118 		
       
   119 		SetActive();
       
   120 		}
       
   121 	}
       
   122 
       
   123 
       
   124 /**
       
   125 DoCancel()
       
   126 Implements cancellation of an outstanding request
       
   127 
       
   128 @see CActive::Cancel()
       
   129 */
       
   130 void CT_MsgUtilsDeleteAllChildren::DoCancel()
       
   131 	{
       
   132 	switch (iState)
       
   133 		{
       
   134 		case EStateThisLevel:
       
   135 		case EBlockDelete:
       
   136 			iOperation->Cancel();
       
   137 			break;
       
   138 
       
   139 		case EStateNextLevel:
       
   140 			iNextLevel->Cancel();
       
   141 			break;
       
   142 		}
       
   143 	}
       
   144 
       
   145 
       
   146 /**
       
   147 RunL()
       
   148 Handles an active object's request completion event
       
   149 
       
   150 @see CActive::RunL()
       
   151 */
       
   152 void CT_MsgUtilsDeleteAllChildren::RunL()
       
   153 	{
       
   154 	TInt err;
       
   155 
       
   156 	switch (iState)
       
   157 		{
       
   158 		case EStateThisLevel:
       
   159 			
       
   160 			err = CT_MsgUtilsDeleteAllChildren::FinalProgressStatus(*iOperation,iStatus);
       
   161 			delete iOperation;
       
   162 			iOperation = NULL;
       
   163 
       
   164 			switch (err)
       
   165 				{
       
   166 				case KErrAccessDenied:
       
   167 					iUndeletedChildren++;
       
   168 					if(iNextLevel==NULL)
       
   169 					{
       
   170 					iNextLevel = new (ELeave) CT_MsgUtilsDeleteAllChildren(iSession,(*iSelection)[iCurrentChild]);
       
   171 					}
       
   172 					iNextLevel->StartL(iStatus);
       
   173 					SetActive();
       
   174 					iState = EStateNextLevel;
       
   175 					break;
       
   176 				
       
   177 				case KErrNone:
       
   178 					if (++iCurrentChild == iTotalChildren)
       
   179 						{
       
   180 						User::RequestComplete(iRequestStatus,KErrNone);
       
   181 						}
       
   182 					else
       
   183 						{
       
   184 						iOperation = iEntry->DeleteL((*iSelection)[iCurrentChild],iStatus);
       
   185 						SetActive();
       
   186 						}
       
   187 					break;
       
   188 					
       
   189 				default:
       
   190 					User::RequestComplete(iRequestStatus,err);
       
   191 					break;			
       
   192 				}
       
   193 				break;
       
   194 
       
   195 		case EStateNextLevel:
       
   196 			err = iStatus.Int();
       
   197 			iUndeletedChildren += iNextLevel->Undeleted();
       
   198 			delete iNextLevel;
       
   199 			iNextLevel = NULL;
       
   200 
       
   201 			switch (err)
       
   202 				{
       
   203 				case KErrNone:
       
   204 					if (++iCurrentChild == iTotalChildren)
       
   205 						{
       
   206 						User::RequestComplete(iRequestStatus,KErrNone);
       
   207 						}
       
   208 					else
       
   209 						{
       
   210 						iOperation = iEntry->DeleteL((*iSelection)[iCurrentChild],iStatus);
       
   211 						SetActive();
       
   212 						iState = EStateThisLevel;
       
   213 						}
       
   214 					break;
       
   215 				default:
       
   216 					User::RequestComplete(iRequestStatus,err);
       
   217 					break;
       
   218 				}
       
   219 			break;
       
   220 
       
   221 		case EBlockDelete:
       
   222 			{
       
   223 			err = CT_MsgUtilsDeleteAllChildren::FinalProgressStatus(*iOperation,iStatus);
       
   224 			delete iOperation;
       
   225 			iOperation = NULL;
       
   226 
       
   227 			User::RequestComplete(iRequestStatus,err);
       
   228 			break;
       
   229 			}
       
   230 		}
       
   231 	}
       
   232 
       
   233 	
       
   234 /**
       
   235 FinalProgressStatus()
       
   236 This function gets the information about a completed operation for the local entries..
       
   237 
       
   238 @param aOperation	
       
   239 Used to get progress information about the operation
       
   240 
       
   241 @param aStatus	
       
   242 @return
       
   243 The error code
       
   244 */
       
   245 EXPORT_C TInt CT_MsgUtilsDeleteAllChildren::FinalProgressStatus(CMsvOperation& aOperation,const TRequestStatus& aStatus)
       
   246 	{
       
   247 	TInt err = KErrNone;
       
   248 
       
   249 	if (aOperation.Mtm() == KUidMsvLocalServiceMtm)
       
   250 		{
       
   251 		TPckgBuf<TMsvLocalOperationProgress> progress;
       
   252 		progress.Copy(aOperation.FinalProgress());
       
   253 		err = progress().iError;
       
   254 		}
       
   255 	else
       
   256 		{
       
   257 		if (iState == EBlockDelete)
       
   258 			{
       
   259 			TRAP_IGNORE(err = McliUtils::GetProgressErrorL(aOperation));
       
   260 			}
       
   261 		else
       
   262 			{
       
   263 			err = aStatus.Int();
       
   264 			}
       
   265 		}
       
   266 	return (err);
       
   267 	}