imservices/ossprotocoladaptation/src/cosscontactmanager.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2007-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:  contact manager
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cosscontactmanager.h"
       
    19 #include "mossprotocolconnectionmanager.h"
       
    20 
       
    21 #include <ximpobjectfactory.h>
       
    22 #include <ximpprotocolconnectionhost.h>
       
    23 #include <ximpidentity.h>
       
    24 #include <ximpobjectcollection.h>
       
    25 #include <presenceobjectfactory.h>
       
    26 #include <protocolpresencedatahost.h>
       
    27 #include <protocolpresentitygroupsdatahost.h>
       
    28 #include <presentitygroupinfo.h>
       
    29 #include <presentitygroupmemberinfo.h>
       
    30 #include <presencegrantrequestinfo.h>
       
    31 #include <protocolpresenceauthorizationdatahost.h>
       
    32 #include <mpresencebuddyinfo2.h>
       
    33 #include <presencecachewriter2.h>
       
    34 #include <avabilitytext.h>
       
    35 #include "cossprotocolconnectionmanager.h"
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // COSSContactManager::COSSContactManager()
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 COSSContactManager::COSSContactManager(MOSSProtocolConnectionManager& aConnMan):
       
    43     iConnMan ( aConnMan )
       
    44 	{
       
    45 	
       
    46 	}
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // COSSContactManager::ConstructL()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void COSSContactManager::ConstructL()
       
    54 	{	
       
    55 	iFetchContactsFirstTime  = EFalse;
       
    56 	iFetchInvitationsFirstTime = EFalse;	
       
    57 	}
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // COSSContactManager::NewL()
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 COSSContactManager* COSSContactManager::NewL(MOSSProtocolConnectionManager& aConnMan)
       
    65 	{
       
    66 
       
    67 	COSSContactManager* self = new ( ELeave )COSSContactManager(aConnMan);
       
    68 
       
    69 	CleanupStack::PushL ( self );
       
    70 
       
    71 	self->ConstructL();
       
    72 	CleanupStack::Pop ( self );
       
    73 
       
    74 	return self;
       
    75 	}
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // COSSContactManager::~COSSProtocolConnectionManager()
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 COSSContactManager::~COSSContactManager()
       
    83 	{	
       
    84 	iContacts.ResetAndDestroy();
       
    85 	iInvitationList.ResetAndDestroy();
       
    86 	}
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // COSSContactManager::IsFetchForFirstTime()
       
    90 // ---------------------------------------------------------------------------
       
    91 //  
       
    92 TBool COSSContactManager::IsFetchContactsFirstTime()
       
    93     { 
       
    94     return iFetchContactsFirstTime;    
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // COSSContactManager::IsFetchInvitationsForFirstTime()
       
    99 // ---------------------------------------------------------------------------
       
   100 //  
       
   101 TBool COSSContactManager::IsFetchInvitationsForFirstTime()
       
   102     { 
       
   103     return iFetchInvitationsFirstTime;    
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // COSSContactManager::SetFetchForFirstTime()
       
   108 // ---------------------------------------------------------------------------
       
   109 //  
       
   110 void COSSContactManager::SetFetchContactsFirstTime(TBool aValue)
       
   111     { 
       
   112     iFetchContactsFirstTime = aValue;    
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // COSSContactManager::SetFetchInvitationsForFirstTime()
       
   117 // ---------------------------------------------------------------------------
       
   118 //  
       
   119 void COSSContactManager::SetFetchInvitationsForFirstTime(TBool aValue)
       
   120     { 
       
   121     iFetchInvitationsFirstTime = aValue;    
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // COSSContactManager::GetContactsListL()
       
   126 // ---------------------------------------------------------------------------
       
   127 //  
       
   128 RPointerArray<HBufC>& COSSContactManager::GetContactsListL()
       
   129     {
       
   130     return iContacts;
       
   131     }
       
   132 // ---------------------------------------------------------------------------
       
   133 // COSSContactManager::GetInvitationListL()
       
   134 // ---------------------------------------------------------------------------
       
   135 //  
       
   136 RPointerArray<HBufC>& COSSContactManager::GetInvitationListL()
       
   137     {
       
   138     return iInvitationList;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // COSSContactManager::ReturnContactsListL()
       
   143 // ---------------------------------------------------------------------------
       
   144 //  
       
   145 void COSSContactManager::ReturnInvitationListL()
       
   146     {
       
   147     MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   148 
       
   149     MPresenceObjectFactory& prObjFact = iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory();
       
   150 
       
   151     MXIMPIdentity* AuthReqIdentity = NULL ;
       
   152     MPresenceGrantRequestInfo* presenceGrant = NULL;
       
   153 
       
   154     MXIMPObjectCollection* listOfInvitations =  prfwObjFact.NewObjectCollectionLC();
       
   155     
       
   156     for ( TInt i = 0; i<iInvitationList.Count(); i++ )
       
   157         {
       
   158         presenceGrant = prObjFact.NewPresenceGrantRequestInfoLC();//1
       
   159         AuthReqIdentity = prfwObjFact.NewIdentityLC();//2
       
   160         AuthReqIdentity->SetIdentityL(*(iInvitationList[ i ] ));
       
   161         iInvitationList[i]->Des().Fold();
       
   162         presenceGrant->SetRequestorIdL(AuthReqIdentity);
       
   163         listOfInvitations->AddObjectL( presenceGrant );
       
   164         CleanupStack::Pop ( 2 );//presenceGrant, AuthReqIdentity      
       
   165         }
       
   166     
       
   167     iConnMan.HandleToHost().ProtocolPresenceDataHost().AuthorizationDataHost().HandlePresenceGrantRequestListL( listOfInvitations );
       
   168     CleanupStack::Pop ( 1 );//listOfInvitations
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // COSSContactManager::ReturnContactsListL()
       
   173 // ---------------------------------------------------------------------------
       
   174 //  
       
   175 void COSSContactManager::ReturnContactsListL()
       
   176     {
       
   177     MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   178 
       
   179     MPresenceObjectFactory& prObjFact = iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory();
       
   180 
       
   181     MXIMPIdentity* contactIdentity = NULL;
       
   182     MPresentityGroupMemberInfo* groupMemberInfo = NULL;
       
   183 
       
   184     MXIMPObjectCollection* listOfContacts =  prfwObjFact.NewObjectCollectionLC();
       
   185     for(TInt i = 0;i<iContacts.Count();i++)
       
   186         {
       
   187         contactIdentity = prfwObjFact.NewIdentityLC();
       
   188         groupMemberInfo = prObjFact.NewPresentityGroupMemberInfoLC();
       
   189         contactIdentity->SetIdentityL ( *(iContacts[ i ] ));
       
   190         groupMemberInfo->SetGroupMemberIdL ( contactIdentity );
       
   191         groupMemberInfo->SetGroupMemberDisplayNameL ( *(iContacts[ i ] ) );
       
   192         listOfContacts->AddObjectL ( groupMemberInfo ); 
       
   193         CleanupStack::Pop ( 2 );//groupMemberInfo, contactIdentity
       
   194         }
       
   195     MXIMPIdentity* groupIdentity = prfwObjFact.NewIdentityLC();    
       
   196     groupIdentity->SetIdentityL ( iConnMan.GroupId() );    
       
   197     iConnMan.HandleToHost().ProtocolPresenceDataHost().GroupsDataHost().HandlePresentityGroupContentL ( groupIdentity, listOfContacts );
       
   198     CleanupStack::Pop ( 2 );//groupIdentity,listOfContacts 
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // COSSContactManager::RemoveContactFromLocalL()
       
   203 // ---------------------------------------------------------------------------
       
   204 //  
       
   205 void COSSContactManager::RemoveContactFromLocalL(const TDesC& aContactName)
       
   206     {
       
   207     HBufC* contactName = aContactName.AllocLC();
       
   208     MXIMPObjectFactory& ximpObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   209     MXIMPIdentity* contactIdentity = ximpObjFact.NewIdentityLC();
       
   210     MXIMPIdentity* groupIdentity = ximpObjFact.NewIdentityLC();    
       
   211     groupIdentity->SetIdentityL ( iConnMan.GroupId());
       
   212     contactIdentity->SetIdentityL(*contactName);
       
   213     //removing from the local copy of the contacts
       
   214     for(TInt i = 0; i<iContacts.Count(); i++)
       
   215         {                    
       
   216         if (!contactName->Compare(*(iContacts[i])))
       
   217             {                                                
       
   218             iContacts.Remove( i );
       
   219             //give info after removing. to ximp fw and client
       
   220             iConnMan.HandleToHost().ProtocolPresenceDataHost().GroupsDataHost().HandlePresentityGroupMemberRemovedL ( groupIdentity, contactIdentity );
       
   221             break;
       
   222             }
       
   223         }
       
   224     CleanupStack::Pop( 2 ); // contactIdentity , groupIdentity
       
   225     CleanupStack::PopAndDestroy( 1 ); //contactName
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // COSSContactManager::AddContactToLocalL()
       
   230 // ---------------------------------------------------------------------------
       
   231 //  
       
   232 void COSSContactManager::AddContactToLocalL(const TDesC& aContactName)
       
   233     {    
       
   234     HBufC* contactName = aContactName.AllocLC();
       
   235     MXIMPObjectFactory& ximpObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   236     MXIMPIdentity* contactIdentity = ximpObjFact.NewIdentityLC();
       
   237     MXIMPIdentity* groupIdentity = ximpObjFact.NewIdentityLC();    
       
   238     groupIdentity->SetIdentityL ( iConnMan.GroupId());
       
   239     contactIdentity->SetIdentityL(*contactName);    
       
   240     iContacts.AppendL(contactName);
       
   241     groupIdentity->SetIdentityL ( iConnMan.GroupId());
       
   242     contactIdentity->SetIdentityL(*contactName);
       
   243     MPresentityGroupMemberInfo* groupMemberInfo = iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory().NewPresentityGroupMemberInfoLC();   
       
   244     groupMemberInfo->SetGroupMemberIdL ( contactIdentity );
       
   245     groupMemberInfo->SetGroupMemberDisplayNameL ( *contactName );                
       
   246     iConnMan.HandleToHost().ProtocolPresenceDataHost().GroupsDataHost().HandlePresentityGroupMemberAddedL ( groupIdentity, groupMemberInfo );    
       
   247 
       
   248     //set presence as pending for the added contact
       
   249     MPresenceBuddyInfo2* buddyPresInfo = MPresenceBuddyInfo2::NewLC();
       
   250    
       
   251     MPresenceCacheWriter2* presenceCacheWriter = MPresenceCacheWriter2::CreateWriterL();
       
   252     CleanupDeletePushL(presenceCacheWriter);
       
   253     HBufC* name = HBufC::NewLC( aContactName.Length() + iConnMan.ServiceName().Length() + KColon().Length() );
       
   254     TPtr namePtr( name->Des() );
       
   255     namePtr.Zero();
       
   256     namePtr.Append(iConnMan.ServiceName() ); // prepend service name
       
   257     namePtr.Append(KColon);
       
   258     namePtr.Append(aContactName );
       
   259     buddyPresInfo->SetIdentityL(namePtr);
       
   260     buddyPresInfo->SetAnyFieldL(KExtensionKey,KPendingRequestExtensionValue());
       
   261     CleanupStack::PopAndDestroy(1);//name
       
   262 
       
   263     // Writing into Presence Cache
       
   264     TInt cacheerror = presenceCacheWriter->WritePresenceL(buddyPresInfo);
       
   265     User::LeaveIfError ( cacheerror);
       
   266     CleanupStack::PopAndDestroy(2);//presenceCacheWriter,buddyPresInfo
       
   267     CleanupStack::Pop( 4 ); // contactName, contactIdentity , groupIdentity , groupMemberInfo    
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // COSSContactManager::RemoveInvitationFromLocalL()
       
   272 // ---------------------------------------------------------------------------
       
   273 //  
       
   274 void COSSContactManager::RemoveInvitationFromLocalL(const TDesC& aContactName)
       
   275     {
       
   276     MXIMPObjectFactory& ObjFact = iConnMan.HandleToHost().ObjectFactory();
       
   277     MPresenceObjectFactory& prfwObjFact = iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory();
       
   278     MXIMPIdentity* authReqIdentity = ObjFact.NewIdentityLC();//1
       
   279     if( authReqIdentity )
       
   280         {
       
   281         authReqIdentity->SetIdentityL(aContactName);   
       
   282         for(TInt i = 0; i<iInvitationList.Count(); i++)
       
   283             {
       
   284             HBufC* findInvitation = iInvitationList[i];
       
   285             if ( findInvitation && !aContactName.Compare( *findInvitation) )
       
   286                 {                                                
       
   287                 iInvitationList.Remove( i ); 
       
   288                 delete findInvitation;
       
   289                 findInvitation = NULL;
       
   290                 iInvitationList.Compress();
       
   291                 iConnMan.HandleToHost().ProtocolPresenceDataHost().AuthorizationDataHost().HandlePresenceGrantRequestObsoletedL(authReqIdentity);
       
   292                 CleanupStack::Pop();   //AuthReqIdentity
       
   293                 return;
       
   294                 }
       
   295             }          
       
   296         CleanupStack::PopAndDestroy();   //AuthReqIdentity
       
   297         }
       
   298     }
       
   299 // End of File
       
   300 
       
   301