uiservicetab/vimpstcmdprocess/src/cvimpstcmddeletecontact.cpp
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  command process for delete contact
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cvimpstcmddeletecontact.h"
       
    21 
       
    22 #include "vimpstcmd.hrh"
       
    23 #include "mvimpstcmdobserver.h"
       
    24 #include "vimpstdebugprint.h" 
       
    25 
       
    26 #include <e32def.h>
       
    27 #include "mvimpstengine.h"
       
    28 #include "cvimpststoragemanagerfactory.h"
       
    29 #include "mvimpststorageserviceview.h"
       
    30 #include "mvimpstenginesubservice.h"
       
    31 #include "mvimpstenginecontactmgmtextention.h"
       
    32 #include "mvimpstengineextentionfeatures.h"
       
    33 #include "mvimpstengineimsubservice.h"
       
    34 #include "tvimpstenums.h"
       
    35 #include "tvimpstconsts.h"
       
    36 #include "mvimpstenginesubservice.h"
       
    37 #include "mvimpstenginepresencesubservice.h"
       
    38 #include "mvimpstenginepresencesubservice.h"
       
    39 
       
    40 // Constants
       
    41 _LIT( KListNameAllBuddy ,"buddylist" );
       
    42 _LIT( KPresenceBlockedList, "blockedcontacts");
       
    43 
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // CVIMPSTCmdDeleteContact::CVIMPSTCmdDeleteContact
       
    47 // --------------------------------------------------------------------------
       
    48 //
       
    49 CVIMPSTCmdDeleteContact::CVIMPSTCmdDeleteContact( 
       
    50         const TInt aCommandId , MVPbkContactLink* aContactLink,
       
    51         MVIMPSTEngine& aEngine) :            
       
    52             iCommandId( aCommandId ),
       
    53             iContactLink( aContactLink ),
       
    54             iEngine(aEngine)
       
    55     {
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CVIMPSTCmdDeleteContact::~CVIMPSTCmdDeleteContact
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 CVIMPSTCmdDeleteContact::~CVIMPSTCmdDeleteContact()
       
    63     {    
       
    64     
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CVIMPSTCmdDeleteContact::NewL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CVIMPSTCmdDeleteContact* CVIMPSTCmdDeleteContact::NewL( 
       
    72         const TInt aCommandId, MVPbkContactLink* aContactLink,
       
    73         MVIMPSTEngine& aEngine)
       
    74     {
       
    75     CVIMPSTCmdDeleteContact* self = new (ELeave ) CVIMPSTCmdDeleteContact( aCommandId ,aContactLink, aEngine);
       
    76     self->ConstructL(); //use contsurctL if necessary
       
    77     return self;
       
    78     }
       
    79 // --------------------------------------------------------------------------
       
    80 // CVIMPSTCmdDeleteContact::ConstructL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 void CVIMPSTCmdDeleteContact::ConstructL()
       
    84     {    
       
    85     iError = KErrNone;
       
    86     }
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CVIMPSTCmdDeleteContact::ExecuteLD
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 void CVIMPSTCmdDeleteContact::ExecuteLD()
       
    93     {
       
    94    	CHAT_DP_FUNC_ENTER("CVIMPSTCmdDeleteContact::ExecuteLD");
       
    95     //push to the cleanupstack
       
    96     CleanupStack::PushL( this );       
       
    97     iError = KErrNone;
       
    98     MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL( iEngine.ServiceId()) ;         
       
    99 	if(storage)
       
   100 		{
       
   101 		MVIMPSTStorageContact* contact = storage->FindContactByLink( *iContactLink );
       
   102 		if (contact  )
       
   103 			{
       
   104 			TBuf<KUsernameMaxLength> listId;
       
   105 			listId.Zero();
       
   106 			listId.Append(KListNameAllBuddy);
       
   107 			if(TVIMPSTEnums::EBlocked ==  contact->OnlineStatus())
       
   108 				{
       
   109 				listId.Zero();
       
   110 				listId.Append(KPresenceBlockedList);
       
   111 				}
       
   112 			TPtrC userIdPtr = contact->UserId();
       
   113 			MVIMPSTEngineSubService* subService = iEngine.SubService(TVIMPSTEnums::EPresence);
       
   114 			MVIMPSTEngineExtentionFeatures* feature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement);
       
   115 			//Get IM SubService     
       
   116 			MVIMPSTEngineSubService* imService =  iEngine.SubService(TVIMPSTEnums::EIM) ;   
       
   117 			//for each userid in the service details, unsubscribe 
       
   118 			if( userIdPtr.Length() )
       
   119 				{
       
   120 				if( subService )
       
   121 					{
       
   122 					MVIMPSTEnginePresenceSubService& presenceSubService = MVIMPSTEnginePresenceSubService::Cast(*subService);
       
   123 					presenceSubService.UnSubscribePresenceOfSingleContactL( userIdPtr );	
       
   124 					}
       
   125 				if (feature )	
       
   126 					{
       
   127 					MVIMPSTEngineContactMgmtExtention& contactMgr = MVIMPSTEngineContactMgmtExtention::Cast(*feature);
       
   128 					TRAP(iError, contactMgr.DeleteServerContactL(listId, userIdPtr ) );
       
   129 					}
       
   130 				if(imService )
       
   131 					{
       
   132 					MVIMPSTEngineIMSubService& imSubService = 
       
   133 												MVIMPSTEngineIMSubService::Cast (*imService);
       
   134 					TRAP_IGNORE( imSubService.CloseConversationL( userIdPtr ));
       
   135 					}		
       
   136 				}
       
   137 			if( iError == KErrNone )
       
   138 				{
       
   139 		 		storage->RemoveContactL( contact );	
       
   140        			}
       
   141 			} // contact
       
   142 		} // storage
       
   143 	CHAT_DP_FUNC_ENTER("CVIMPSTCmdDeleteContact:: CommandFinished");
       
   144 
       
   145     if(iObserver)
       
   146 	    {
       
   147 	    iObserver->CommandFinishedL(*this);
       
   148 	    }
       
   149 	CHAT_DP_FUNC_ENTER("CVIMPSTCmdDeleteContact:: CommandFinished");	
       
   150 	CleanupStack::PopAndDestroy();	
       
   151 	CHAT_DP_FUNC_DONE("CVIMPSTCmdDeleteContact::ExecuteLD");	
       
   152     }
       
   153 
       
   154 
       
   155 // --------------------------------------------------------------------------
       
   156 // CVIMPSTCmdDeleteContact::AddObserver
       
   157 // --------------------------------------------------------------------------
       
   158 //
       
   159 void CVIMPSTCmdDeleteContact::AddObserver( MVIMPSTCmdObserver& aObserver )
       
   160     {
       
   161     // store the observer to notify the command completion
       
   162     iObserver = &aObserver;
       
   163     }
       
   164 
       
   165 
       
   166 // --------------------------------------------------------------------------
       
   167 // CVIMPSTCmdDeleteContact::CommandId
       
   168 // --------------------------------------------------------------------------
       
   169 //
       
   170 TInt CVIMPSTCmdDeleteContact::CommandId() const
       
   171 	{
       
   172 	return iCommandId;	
       
   173 	}
       
   174 
       
   175 // --------------------------------------------------------------------------
       
   176 // CVIMPSTCmdDeleteContact::Result
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 TInt CVIMPSTCmdDeleteContact::Result() const
       
   180 	{
       
   181 	//return valid data regd the command operation
       
   182 	return iError;
       
   183 	}
       
   184 
       
   185 // End of File