cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_remove.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "certtool_commands.h"
       
    20 #include "certtool_controller.h"
       
    21 
       
    22 /*static*/ CCertToolRemove* CCertToolRemove::NewLC(CCertToolController* aController)
       
    23 	{
       
    24 	CCertToolRemove* self = new (ELeave) CCertToolRemove(aController);
       
    25 	CleanupStack::PushL(self);
       
    26 	self->ConstructL();
       
    27 	return self;	
       
    28 	}
       
    29 	
       
    30 /*static*/ CCertToolRemove* CCertToolRemove::NewL(CCertToolController* aController)
       
    31 	{
       
    32 	CCertToolRemove* self = CCertToolRemove::NewLC(aController);
       
    33 	CleanupStack::Pop(self);
       
    34 	return self;	  
       
    35 	}
       
    36 	
       
    37 CCertToolRemove::CCertToolRemove(CCertToolController* aController) : CCertToolList(aController)
       
    38 	{
       
    39 	
       
    40 	}
       
    41 	
       
    42 CCertToolRemove::~CCertToolRemove()
       
    43 	{
       
    44 	Cancel();
       
    45 	}
       
    46 	
       
    47 void CCertToolRemove::RunL()
       
    48 	{
       
    49 	if (iStatus.Int() != KErrNone)
       
    50 		{
       
    51 		User::Leave(iStatus.Int());
       
    52 		}	
       
    53 	switch (iState)
       
    54 		{	 
       
    55 		case EListCerts:
       
    56 			{
       
    57 			// Look for a specific certificate					
       
    58 			TInt certIndex = -1;
       
    59 			for (TInt j = 0; j < iCertInfos.Count(); j++)
       
    60 				{
       
    61 				if (iCertInfos[j]->Label() == *iParams->iDefault) 
       
    62 					{
       
    63 					certIndex = j;
       
    64 					break;
       
    65 					}
       
    66 				}	
       
    67 				
       
    68 			if (certIndex != -1)
       
    69 				{
       
    70 				iState = EFinished;
       
    71 				SetActive();				
       
    72 				iCertStore->Remove(*iCertInfos[certIndex], iStatus);
       
    73 				}
       
    74 			else 
       
    75 				{
       
    76 				User::Leave(KErrNotFound);
       
    77 				}			
       
    78 			}
       
    79 			break;
       
    80 		case EFinished:
       
    81 			{
       
    82 			// We are done!
       
    83 			iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE_SUCCESS);			
       
    84 			CActiveScheduler::Stop();
       
    85 			}
       
    86 			break;
       
    87 		default:
       
    88 			{
       
    89 			User::Panic(_L("REMOVE action: Illegal state."), 1);					
       
    90 			}			
       
    91 		}
       
    92 	}