simpledatamodeladapter/src/presencepluginauthorization.cpp
changeset 12 e6a66db4e9d0
parent 0 c8caa15ef882
equal deleted inserted replaced
0:c8caa15ef882 12:e6a66db4e9d0
     1 /*
     1 /*
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    45 #include "presencepluginwatcher.h"
    45 #include "presencepluginwatcher.h"
    46 #include "presenceplugindata.h"
    46 #include "presenceplugindata.h"
    47 #include "presencepluginutility.h"
    47 #include "presencepluginutility.h"
    48 #include "presenceplugingroup.h"
    48 #include "presenceplugingroup.h"
    49 #include "presencepluginvirtualgroup.h"
    49 #include "presencepluginvirtualgroup.h"
    50 #include "presenceplugincontacts.h"
       
    51 
    50 
    52 
    51 
    53 // ======== MEMBER FUNCTIONS ========
    52 // ======== MEMBER FUNCTIONS ========
    54 
    53 
    55 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    59 CPresencePluginAuthorization::CPresencePluginAuthorization(
    58 CPresencePluginAuthorization::CPresencePluginAuthorization(
    60     MPresencePluginConnectionObs& aObs,
    59     MPresencePluginConnectionObs& aObs,
    61     CPresencePluginData* aPresenceData )
    60     CPresencePluginData* aPresenceData )
    62     : CActive( CActive::EPriorityStandard ),
    61     : CActive( CActive::EPriorityStandard ),
    63     iConnObs(aObs), iSubscribed( EFalse ),
    62     iConnObs(aObs), iSubscribed( EFalse ),
    64     iOperation( ENoOperation ), iXdmOk( EFalse ),
    63     iOperation( ENoOperation ),
    65     iComplete( EFalse ), iPresenceData( aPresenceData ),
    64     iXdmOk( EFalse ), iComplete( EFalse ),iPresenceData( aPresenceData )
    66     iContactIsStored( ETrue )
    65     {
    67     {
    66     CActiveScheduler::Add(this); 
    68     CActiveScheduler::Add(this);
       
    69     }
    67     }
    70 
    68 
    71 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
    72 // CPresencePluginAuthorization::NewL()
    70 // CPresencePluginAuthorization::NewL()
    73 // ---------------------------------------------------------------------------
    71 // ---------------------------------------------------------------------------
    77     CPresencePluginData* aPresenceData )
    75     CPresencePluginData* aPresenceData )
    78     {
    76     {
    79     DP_SDA("CPresencePluginAuthorization::NewL ");
    77     DP_SDA("CPresencePluginAuthorization::NewL ");
    80     CPresencePluginAuthorization* self =
    78     CPresencePluginAuthorization* self =
    81         new( ELeave ) CPresencePluginAuthorization( aObs, aPresenceData );
    79         new( ELeave ) CPresencePluginAuthorization( aObs, aPresenceData );
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     CleanupStack::Pop( self );
       
    85     return self;
    80     return self;
    86     }
    81     }
    87 
    82 
    88 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    89 // CPresencePluginAuthorization::ConstructL()
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CPresencePluginAuthorization::ConstructL()
       
    93     {
       
    94     HBufC* serviceName =
       
    95         iPresenceData->ServiceNameLC( iPresenceData->ServiceId() );
       
    96     iContacts = CPresencePluginContacts::NewL(
       
    97         iPresenceData->ServiceId(), *serviceName, *this );
       
    98     CleanupStack::PopAndDestroy( serviceName );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CPresencePluginAuthorization::~CPresencePluginAuthorization()
    84 // CPresencePluginAuthorization::~CPresencePluginAuthorization()
   103 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
   104 //
    86 //
   105 CPresencePluginAuthorization::~CPresencePluginAuthorization()
    87 CPresencePluginAuthorization::~CPresencePluginAuthorization()
   106     {
    88     {
   107     delete iPresIdentity;
    89     delete iPresIdentity;
   108     delete iContacts;
       
   109     }
    90     }
   110 
    91 
   111 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
   112 // CPresencePluginAuthorization::SetDataHost()
    93 // CPresencePluginAuthorization::SetDataHost()
   113 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   464                 }
   445                 }
   465                 break;
   446                 break;
   466             
   447             
   467             case EStateBlocked:
   448             case EStateBlocked:
   468                 {
   449                 {
   469                 DP_SDA( "CPresencePluginAuthorization::RunL - Blocked" );
       
   470                 SetPresentityBlockedToXIMPL();
   450                 SetPresentityBlockedToXIMPL();
   471                 iAuthState = EStateIdle;
   451                 iAuthState = EStateIdle;
   472                 CompleteXIMPReq( myStatus );
   452                 CompleteXIMPReq( myStatus );
   473                 }
   453                 }
   474                 break;
   454                 break;
   475 
   455                 
   476             case EStateIsContactBlockedBuddyRequest:
   456             case EStateDoUnBlock:
   477                 {
   457                 {
   478                 DP_SDA( "CPresencePluginAuthorization::RunL - Resolve contact type" );
   458                 DP_SDA( "CPresencePluginAuthorization::RunL - Grant presence for presentity" );  
   479                 // resolve is contact blocked friend request
   459                 GrantPresenceForPresentityL();
   480                 HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
   460                 iAuthState = EStatePresenceGranted;
   481                 IsBlockedContactFriendRequestL( *withoutPrefix, *this, iStatus );
       
   482                 CleanupStack::PopAndDestroy( withoutPrefix );
       
   483                 SetActive();
       
   484                 iAuthState = EStateDoUnBlock;
       
   485                 }
   461                 }
   486                 break;
   462                 break;
   487                 
   463                 
   488             case EStateDoUnBlock:
       
   489                 {
       
   490                 if ( iContactIsStored )
       
   491                     {
       
   492                     DP_SDA( "CPresencePluginAuthorization::RunL - Grant presence for presentity" );
       
   493                     GrantPresenceForPresentityL();
       
   494                     iAuthState = EStatePresenceGranted;
       
   495                     }
       
   496                 else
       
   497                     {
       
   498                     DP_SDA( "CPresencePluginAuthorization::RunL - Complete unblock" );
       
   499                     iAuthState = EStateIdle;
       
   500                     CompleteXIMPReq( myStatus );
       
   501                     }
       
   502                 }
       
   503                 break;
       
   504             
       
   505             case EStatePresenceGranted:
   464             case EStatePresenceGranted:
   506                 {
   465                 {
   507                 DP_SDA( "CPresencePluginAuthorization::RunL -Subscribe presentity presence" );  
   466                 DP_SDA( "CPresencePluginAuthorization::RunL -Subscribe presentity presence" );  
       
   467                 
   508                 MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
   468                 MXIMPIdentity* identity = iConnObs.ObjectFactory().NewIdentityLC();
   509                 identity->SetIdentityL( iPresIdentity->Des() ); 
   469                 identity->SetIdentityL( iPresIdentity->Des() ); 
   510                 iConnObs.WatcherHandlerL()->DoPerformSubscribePresentityPresenceL( *identity, iStatus );
   470                 iConnObs.WatcherHandlerL()->DoPerformSubscribePresentityPresenceL( *identity, iStatus );
   511                 CleanupStack::PopAndDestroy( ); //identity 
   471                 CleanupStack::PopAndDestroy( ); //identity 
   512                 iAuthState = EStateIdle;
   472                 iAuthState = EStateIdle;
  1264     HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
  1224     HBufC* withoutPrefix = iPresenceData->RemovePrefixLC( *iPresIdentity );
  1265     identity->SetIdentityL( *withoutPrefix );
  1225     identity->SetIdentityL( *withoutPrefix );
  1266     CleanupStack::PopAndDestroy( withoutPrefix );
  1226     CleanupStack::PopAndDestroy( withoutPrefix );
  1267     iDataHost->HandlePresenceBlockCanceledL( identity );
  1227     iDataHost->HandlePresenceBlockCanceledL( identity );
  1268     CleanupStack::Pop();// >> identity
  1228     CleanupStack::Pop();// >> identity
  1269     iAuthState = EStateIsContactBlockedBuddyRequest;
  1229     iAuthState = EStateDoUnBlock;
  1270     SetActive();
  1230     SetActive();
  1271     
  1231     
  1272     DP_SDA( "CPresencePluginAuthorization::UnblockPresentityL -Exit" );
  1232     DP_SDA( "CPresencePluginAuthorization::UnblockPresentityL -Exit" );
  1273     }
  1233     }
  1274 
  1234 
  1275 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 // CPresencePluginAuthorization::IsBlockedContactFriendRequest()
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //
       
  1280 void CPresencePluginAuthorization::IsBlockedContactFriendRequestL(
       
  1281     const TDesC& aPresenceId,
       
  1282     MPresencePluginContactsObs& aObserver,
       
  1283     TRequestStatus& aStatus )
       
  1284     {
       
  1285     DP_SDA( "CPresencePluginAuthorization::IsBlockedContactFriendRequest" );
       
  1286 
       
  1287     delete iContacts;
       
  1288     iContacts = NULL;
       
  1289 
       
  1290     HBufC* serviceName =
       
  1291         iPresenceData->ServiceNameLC( iPresenceData->ServiceId() );
       
  1292 
       
  1293     iContacts = CPresencePluginContacts::NewL(
       
  1294         iPresenceData->ServiceId(), *serviceName, aObserver );
       
  1295 
       
  1296     CleanupStack::PopAndDestroy( serviceName );
       
  1297 
       
  1298     iContacts->IsPresenceIdStoredL( aPresenceId, aStatus );
       
  1299 
       
  1300     DP_SDA( "CPresencePluginAuthorization::IsBlockedContactFriendRequest -exit" );
       
  1301     }
       
  1302 
       
  1303 
       
  1304 // ---------------------------------------------------------------------------
       
  1305 // From base class MPresencePluginContactsObs
       
  1306 // CPresencePluginAuthorization::RequestComplete()
       
  1307 // ---------------------------------------------------------------------------
       
  1308 //
       
  1309 void CPresencePluginAuthorization::RequestComplete( TAny* aResult,
       
  1310     TPresenceContactsOperation aOperation, TInt aError )
       
  1311     {
       
  1312     DP_SDA( "CPresencePluginAuthorization::RequestComplete" );
       
  1313     
       
  1314     switch( aOperation )
       
  1315         {
       
  1316         case EOperationIsPresenceStoredToContacts:
       
  1317             if ( aResult != NULL && KErrNone == aError  )
       
  1318                 {
       
  1319                 iContactIsStored = *static_cast<TBool*>( aResult );
       
  1320                 }
       
  1321             break;
       
  1322         default:
       
  1323             break;
       
  1324         }
       
  1325     DP_SDA2( "CPresencePluginAuthorization::RequestComplete - iContactIsStored = %d", iContactIsStored );
       
  1326     }
       
  1327 
       
  1328 // End of file
  1235 // End of file