uiservicetab/vimpstcmdprocess/src/cvimpstcmdaddcontact.cpp
changeset 0 5e5d6b214f4f
child 14 9fdee5e1da30
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     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:   VIMPST command for add contact
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cvimpstcmdaddcontact.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 "mvimpstenginecontactmgmtextention.h"
       
    29 #include "mvimpstengineextentionfeatures.h"
       
    30 #include <MVPbkStoreContact.h>
       
    31 #include <MVPbkFieldType.h>
       
    32 #include <MVPbkContactFieldTextData.h>
       
    33 #include <MVPbkContactFieldUriData.h>
       
    34 
       
    35 #include "cvimpststoragemanagerfactory.h"
       
    36 #include "mvimpststorageserviceview.h"
       
    37 #include "mvimpststoragecontact.h"
       
    38 #include "tvimpstenums.h" 
       
    39 #include "tvimpstconsts.h"
       
    40 #include "mvimpstenginesubservice.h"
       
    41 #include "mvimpstenginepresencesubservice.h"
       
    42 
       
    43 // Constants
       
    44 _LIT( KListNameAllBuddy ,"buddylist" );
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CVIMPSTCmdAddContact::CVIMPSTCmdAddContact
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 CVIMPSTCmdAddContact::CVIMPSTCmdAddContact( 
       
    51         const TInt aCommandId ,const TDesC& aContactId,
       
    52         MVIMPSTEngine& aEngine) :            
       
    53             iCommandId( aCommandId ),
       
    54             iContactId( aContactId ),
       
    55             iEngine(aEngine)
       
    56     {
       
    57     }
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CVIMPSTCmdAddContact::~CVIMPSTCmdAddContact
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CVIMPSTCmdAddContact::~CVIMPSTCmdAddContact()
       
    64     {    
       
    65     
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CVIMPSTCmdAddContact::NewL
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 CVIMPSTCmdAddContact* CVIMPSTCmdAddContact::NewL( 
       
    73         const TInt aCommandId,const TDesC& aContactId,
       
    74         MVIMPSTEngine& aEngine)
       
    75     {
       
    76     CVIMPSTCmdAddContact* self = new (ELeave ) CVIMPSTCmdAddContact( aCommandId ,aContactId, aEngine);
       
    77     self->ConstructL(); //use contsurctL if necessary
       
    78     return self;
       
    79     }
       
    80 // --------------------------------------------------------------------------
       
    81 // CVIMPSTCmdAddContact::ConstructL
       
    82 // --------------------------------------------------------------------------
       
    83 //
       
    84 void CVIMPSTCmdAddContact::ConstructL()
       
    85     {    
       
    86     iError = KErrNone;
       
    87     }
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CVIMPSTCmdAddContact::ExecuteLD
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 void CVIMPSTCmdAddContact::ExecuteLD()
       
    94     {
       
    95    	CHAT_DP_FUNC_ENTER("CVIMPSTEnableServiceCmd::ExecuteLD");
       
    96     //push to the cleanupstack
       
    97     CleanupStack::PushL( this );
       
    98     MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iEngine.ServiceId()) ;
       
    99     if(storage )
       
   100         {
       
   101         if( !IsContactBlocked(iContactId) )
       
   102 	        {
       
   103 	        MVIMPSTStorageContact* alreadyExist = storage->FindContactByUserId( iContactId );
       
   104 	        if( !alreadyExist )
       
   105 				{
       
   106 				iError = KErrNone;
       
   107 				MVIMPSTEngineExtentionFeatures* feature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement);
       
   108 				if (feature)	
       
   109 					{
       
   110 					MVIMPSTEngineContactMgmtExtention& contactMgr = 
       
   111 											MVIMPSTEngineContactMgmtExtention::Cast (*feature);
       
   112 					// if there is a scenario when the user enters only the firstname , then userid is null.
       
   113 					//In this case don't send it to the server, Add the contact to the servicetab and 
       
   114 					//presence will not be visible.
       
   115 					// check if contact is in the blocked list.
       
   116 					// iError already exist
       
   117 					if( iContactId.Length() )
       
   118 						{
       
   119 						iError = contactMgr.AddServerContactL(KListNameAllBuddy,iContactId, KNullDesC() );
       
   120 						}//End if(iContactId)
       
   121 					}	//End if(feature)
       
   122 				if(KErrNone == iError)
       
   123 					{
       
   124 					storage->CreateNewContactL( iContactId );	
       
   125 					}
       
   126 				}//End if(alreadyExist)
       
   127 		    else	
       
   128 	            {
       
   129 	            iError = EErrExistInContactList;		
       
   130 	            }
       
   131 	        }
       
   132         else
       
   133 	        {
       
   134 	        iError = EErrExistInBlockList;		
       
   135 	        }
       
   136         }//End  if(storage)
       
   137    			
       
   138     CHAT_DP_FUNC_ENTER("CVIMPSTEnableServiceCmd:: CommandFinished");
       
   139 
       
   140     if(iObserver)
       
   141 	    {
       
   142 	    iObserver->CommandFinishedL(*this);
       
   143 	    }
       
   144 	CHAT_DP_FUNC_ENTER("CVIMPSTEnableServiceCmd:: CommandFinished");	
       
   145 	CleanupStack::PopAndDestroy();	
       
   146 	CHAT_DP_FUNC_DONE("CVIMPSTEnableServiceCmd::ExecuteLD");	
       
   147     }
       
   148 
       
   149 // --------------------------------------------------------------------------
       
   150 // CVIMPSTCmdAddContact::IsContactBlocked
       
   151 // --------------------------------------------------------------------------
       
   152 TBool CVIMPSTCmdAddContact::IsContactBlocked(const TDesC& aUserId)
       
   153 	{
       
   154    	MVIMPSTEngineSubService* subService =    	   
       
   155    	   					(iEngine.SubService(TVIMPSTEnums::EPresence));
       
   156     if(subService)
       
   157         {
       
   158         MVIMPSTEnginePresenceSubService& presence = 
       
   159         		MVIMPSTEnginePresenceSubService::Cast (*subService);
       
   160         		
       
   161         RPointerArray<HBufC> *blockedlist = presence .GetBlockedList();
       
   162         
       
   163         if(blockedlist)
       
   164 	        {
       
   165 	        for(TInt i=0; i<blockedlist->Count(); ++i)
       
   166 				{
       
   167 				if(0 == aUserId.CompareC((*blockedlist)[i]->Des()))
       
   168 					{
       
   169 					return ETrue;
       
   170 					}
       
   171 				}
       
   172 	        }
       
   173         }
       
   174     return EFalse;  
       
   175 	}
       
   176 
       
   177 // --------------------------------------------------------------------------
       
   178 // CVIMPSTCmdAddContact::AddObserver
       
   179 // --------------------------------------------------------------------------
       
   180 //
       
   181 void CVIMPSTCmdAddContact::AddObserver( MVIMPSTCmdObserver& aObserver )
       
   182     {
       
   183     // store the observer to notify the command completion
       
   184     iObserver = &aObserver;
       
   185     }
       
   186 
       
   187 
       
   188 // --------------------------------------------------------------------------
       
   189 // CVIMPSTCmdAddContact::CommandId
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 TInt CVIMPSTCmdAddContact::CommandId() const
       
   193 	{
       
   194 	return iCommandId;	
       
   195 	}
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // CVIMPSTCmdAddContact::Result
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 TInt CVIMPSTCmdAddContact::Result() const
       
   202 	{
       
   203 	//return valid data regd the command operation
       
   204 	return iError;
       
   205 	}
       
   206 
       
   207 // End of File