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