uiservicetab/vimpstcmdprocess/src/cvimpstcmdprocessselectedcontact.cpp
changeset 0 5e5d6b214f4f
child 9 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:  command process for selected contact
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //include files
       
    20 #include "cvimpstcmdprocessselectedcontact.h"
       
    21 
       
    22 #include <MVPbkStoreContact.h>
       
    23 #include <MVPbkFieldType.h>
       
    24 #include <MVPbkContactFieldTextData.h>
       
    25 #include <MVPbkContactFieldUriData.h>
       
    26 
       
    27 #include "vimpstcmd.hrh"
       
    28 #include "mvimpstcmdobserver.h"
       
    29 #include "vimpstdebugprint.h"
       
    30 
       
    31 #include <e32def.h>
       
    32 #include <MVPbkContactLinkArray.h>
       
    33 #include "mvimpstengine.h"
       
    34 
       
    35 #include "mvimpststorageserviceview.h"
       
    36 #include "cvimpststoragemanagerfactory.h"
       
    37 #include "mvimpstenginecontactmgmtextention.h"
       
    38 #include "tvimpstconsts.h"
       
    39 #include "mvimpstenginesubservice.h"
       
    40 #include "mvimpstenginepresencesubservice.h"
       
    41 
       
    42 // Constants
       
    43 _LIT( KListNameAllBuddy ,"buddylist" );
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact
       
    47 // --------------------------------------------------------------------------
       
    48 //
       
    49 CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact( const TInt aCommandId ,
       
    50                                                                     TVPbkSelectedData& aSelectedEntries,
       
    51                                                                     MVIMPSTEngine& aEngine ):            
       
    52                                                                     iCommandId( aCommandId ),
       
    53                                                                     iSelectedEntries( aSelectedEntries ),
       
    54                                                                     iEngine(aEngine)
       
    55     {
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact()
       
    63     {    
       
    64     
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CVIMPSTCmdProcessSelectedContact::NewL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CVIMPSTCmdProcessSelectedContact* CVIMPSTCmdProcessSelectedContact::NewL( const TInt aCommandId,
       
    72                                                                           TVPbkSelectedData& aSelectedEntries,
       
    73                                                                           MVIMPSTEngine& aEngine )
       
    74     {
       
    75     CVIMPSTCmdProcessSelectedContact* self = new (ELeave ) CVIMPSTCmdProcessSelectedContact( aCommandId ,aSelectedEntries, aEngine);
       
    76     self->ConstructL(); //use contsurctL if necessary
       
    77     return self;
       
    78     }
       
    79 // --------------------------------------------------------------------------
       
    80 // CVIMPSTCmdProcessSelectedContact::ConstructL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 void CVIMPSTCmdProcessSelectedContact::ConstructL()
       
    84     {    
       
    85     iError = KErrNone;
       
    86     }
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CVIMPSTCmdProcessSelectedContact::ExecuteLD
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 void CVIMPSTCmdProcessSelectedContact::ExecuteLD()
       
    93     {
       
    94     CHAT_DP_FUNC_ENTER("CVIMPSTCmdProcessSelectedContact::ExecuteLD");
       
    95     //push to the cleanupstack
       
    96     CleanupStack::PushL( this );
       
    97     MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL( iEngine.ServiceId() ) ;
       
    98     if(storage)
       
    99         {
       
   100         TBool localStore = storage->IsLocalStore();
       
   101         //retrieve contact from links  
       
   102         TPtrC8 pacledLinks = iSelectedEntries.iPackedLinks->Des();
       
   103         TInt  count = storage->RetriveLinkXSPIdsL( pacledLinks  );
       
   104         if( !count )
       
   105             {
       
   106             iError = KErrGeneral;	
       
   107             }
       
   108 	    if( (iCommandId == ECmdProcessSelectedContactNew  ||
       
   109 	            iCommandId == ECmdProcessSelectedContactExist )&& 
       
   110 	            iError == KErrNone )
       
   111 	        {
       
   112 	        MVIMPSTEngineExtentionFeatures* contactFeature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement);
       
   113 	        MVIMPSTEngineSubService* presenceService = iEngine.SubService(TVIMPSTEnums::EPresence);
       
   114             for(TInt index = 0; index < count; index++ )
       
   115 	            {
       
   116 	            TPtrC xspIdPtr = storage->GetRetrieveXSPIdL( index ); // xspId is owned here
       
   117 	            if( localStore )
       
   118 					{
       
   119 					iError = KErrNone;
       
   120 					if( xspIdPtr.Length() )
       
   121 						{
       
   122 						if( IsContactBlocked( xspIdPtr ) )
       
   123 							{
       
   124 							iError = EErrExistInBlockList;	
       
   125 							}
       
   126 						else if( storage->FindContactByUserId( xspIdPtr ) )
       
   127 							{
       
   128 							iError = EErrExistInContactList;	
       
   129 							}
       
   130 						else if( contactFeature  )
       
   131 							{
       
   132 							// add to server and store if sucess
       
   133 							MVIMPSTEngineContactMgmtExtention& contactMgr = 
       
   134 											MVIMPSTEngineContactMgmtExtention::Cast (*contactFeature);
       
   135 							iError = contactMgr.AddServerContactL( KListNameAllBuddy, xspIdPtr ,KNullDesC );			            
       
   136 							}
       
   137 						}
       
   138 					if(KErrNone == iError )
       
   139 						{
       
   140 						iError = storage->CreateNewContactFromRetrivedIdL( index );
       
   141 						}
       
   142 					else if( iCommandId == ECmdProcessSelectedContactNew  )
       
   143 					    {
       
   144 					    // delete the contact which got created in phonebook but failed to add in servicetab
       
   145 					    storage->DeleteNewContactFromRetrivedIdL( index );
       
   146 					    }
       
   147 					}
       
   148 		         else if( xspIdPtr.Length() )
       
   149 					{
       
   150 					// xspId ownership is transfered to iXSPList
       
   151 					iSelectedEntries.iXSPList.AppendL( xspIdPtr.AllocL() );
       
   152 					}
       
   153 	           	}
       
   154 	        }
       
   155        else if( ( iCommandId == ECmdProcessAcceptedContactNew || 
       
   156                iCommandId == ECmdProcessAcceptedContactExist )&& 
       
   157                iError == KErrNone )// for accepted contact 
       
   158 	       {
       
   159 	       // just add and return
       
   160 	       // contact is already added in storage in RetrieveContactL
       
   161 	       // if sucess ,storage will take ownership else we need to delete contact
       
   162 	       iError = storage->CreateNewContactFromRetrivedIdL( 0 ); // for accepting invitation take the first contact which is retirved
       
   163 	       if( iError != KErrNone && iCommandId == ECmdProcessAcceptedContactNew )
       
   164 	           {
       
   165 	           // delete the contact which got created in phonebook but failed to add in servicetab
       
   166 	           storage->DeleteNewContactFromRetrivedIdL( 0 );
       
   167 	           }
       
   168 	       }
       
   169 	  if( !localStore )
       
   170 		  {
       
   171 		  // in case of server we have a selection dialog 
       
   172 		  // so this error does not matter 
       
   173 		  // set to 0
       
   174 		  iError = KErrNone;	
       
   175 		  }
       
   176 	    }
       
   177     else
       
   178         {
       
   179         iError = KErrGeneral;
       
   180         }
       
   181     if(iObserver)
       
   182         {
       
   183         iObserver->CommandFinishedL(*this);
       
   184         }
       
   185     CHAT_DP_FUNC_ENTER("CVIMPSTCmdProcessSelectedContact:: CommandFinished");    
       
   186     CleanupStack::PopAndDestroy();  
       
   187     CHAT_DP_FUNC_DONE("CVIMPSTCmdProcessSelectedContact::ExecuteLD");    
       
   188     }
       
   189 
       
   190 
       
   191 // --------------------------------------------------------------------------
       
   192 // CVIMPSTCmdProcessSelectedContact::AddObserver
       
   193 // --------------------------------------------------------------------------
       
   194 //
       
   195 void CVIMPSTCmdProcessSelectedContact::AddObserver( MVIMPSTCmdObserver& aObserver )
       
   196     {
       
   197     // store the observer to notify the command completion
       
   198     iObserver = &aObserver;
       
   199     }
       
   200 
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CVIMPSTCmdProcessSelectedContact::CommandId
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 TInt CVIMPSTCmdProcessSelectedContact::CommandId() const
       
   207     {
       
   208     return iCommandId;  
       
   209     }
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CVIMPSTCmdProcessSelectedContact::Result
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 TInt CVIMPSTCmdProcessSelectedContact::Result() const
       
   216     {
       
   217     //return valid data regd the command operation
       
   218     return iError;
       
   219     }
       
   220  
       
   221  // --------------------------------------------------------------------------
       
   222 // CVIMPSTCmdProcessSelectedContact::Result
       
   223 // --------------------------------------------------------------------------
       
   224 //
       
   225 // --------------------------------------------------------------------------
       
   226 // CVIMPSTCmdProcessSelectedContact::IsContactBlocked
       
   227 // --------------------------------------------------------------------------
       
   228 TBool CVIMPSTCmdProcessSelectedContact::IsContactBlocked(const TDesC& aUserId)
       
   229 	{
       
   230    	MVIMPSTEngineSubService* subService =    	   
       
   231    	   					(iEngine.SubService(TVIMPSTEnums::EPresence));
       
   232     if(subService)
       
   233         {
       
   234         MVIMPSTEnginePresenceSubService& presence = 
       
   235         		MVIMPSTEnginePresenceSubService::Cast (*subService);
       
   236         		
       
   237         RPointerArray<HBufC> *blockedlist = presence .GetBlockedList();
       
   238         
       
   239         if(blockedlist)
       
   240 	        {
       
   241 	        for(TInt i=0; i<blockedlist->Count(); ++i)
       
   242 				{
       
   243 				if(0 == aUserId.CompareC((*blockedlist)[i]->Des()))
       
   244 					{
       
   245 					return ETrue;
       
   246 					}
       
   247 				}
       
   248 	        }
       
   249         }
       
   250     return EFalse;  
       
   251 	}       
       
   252 // End of File