uiservicetab/vimpstengine/src/cvimpstenginecvlistener.cpp
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  active object class for interacting with conversation view
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "cvimpstenginecvlistener.h"
       
    21 #include "cvimpststoragemanagerfactory.h"
       
    22 #include "mvimpststorageserviceview.h"
       
    23 #include "mvimpststoragecontact.h"
       
    24 #include "cvimpstengineservicetablefetcher.h"
       
    25 #include "vimpstdebugtrace.h"
       
    26 
       
    27 //system includes
       
    28 #include <e32base.h>
       
    29 #include <MVPbkContactLink.h>
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // --------------------------------------------------------------------------
       
    34 // CVIMPSTEngineCVListener::CVIMPSTEngineCVListener
       
    35 // --------------------------------------------------------------------------
       
    36 //
       
    37 CVIMPSTEngineCVListener::CVIMPSTEngineCVListener(
       
    38     CVIMPSTEngineServiceTableFetcher& aServiceTableFetcher ): 
       
    39     CActive( CActive::EPriorityStandard ),
       
    40     iServiceTableFetcher( aServiceTableFetcher )
       
    41     {
       
    42     CActiveScheduler::Add( this );
       
    43     }
       
    44 
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CVIMPSTEngineCVListener::ConstructL
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 void CVIMPSTEngineCVListener::ConstructL()
       
    51     {
       
    52     TRACE( T_LIT("CVIMPSTEngineCVListener::ConstructL() start"));
       
    53     // subscribing for the property published by conversation view.
       
    54     // attach the properties.
       
    55     User::LeaveIfError( iProperty.Attach(KConvViewUID,KXspIdServiceIDKey  ) );
       
    56     //start listening property published by CV (to get Contact link and Display name.).
       
    57     iProperty.Subscribe( iStatus );
       
    58     SetActive();
       
    59     TRACE( T_LIT("CVIMPSTEngineCVListener::ConstructL() end"));
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CVIMPSTEngineCVListener::NewL
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CVIMPSTEngineCVListener* CVIMPSTEngineCVListener::NewL(
       
    67         CVIMPSTEngineServiceTableFetcher& aServiceTableFetcher )
       
    68     {
       
    69     CVIMPSTEngineCVListener* self = new(ELeave) CVIMPSTEngineCVListener( aServiceTableFetcher );
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75 // ---------------------------------------------------------
       
    76 // CVIMPSTEngineCVListener::~CVIMPSTEngineCVListener()
       
    77 // C++ Destructor 
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 CVIMPSTEngineCVListener::~CVIMPSTEngineCVListener()
       
    81     {
       
    82     Cancel();
       
    83     iProperty.Close();
       
    84     }
       
    85 // ---------------------------------------------------------
       
    86 // CVIMPSTEngineCVListener::RunL()
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CVIMPSTEngineCVListener::RunL()
       
    90     {
       
    91     TRACE( T_LIT("CVIMPSTEngineCVListener::RunL() start"));
       
    92     // resubscribe before processing new value to prevent missing updates
       
    93     //TBuf <KMaxSerIdXspIdLen> serId_usrId;
       
    94     HBufC16* serId_usrId = HBufC16::NewLC(KMaxSerIdXspIdLen);
       
    95     TPtr serId_usrIdPtr(serId_usrId->Des());
       
    96     
       
    97     iProperty.Get(KConvViewUID,KXspIdServiceIDKey,serId_usrIdPtr);
       
    98     // parse the service id and userid form the buf and get the 
       
    99     // contactlink and first name and publish it.
       
   100     TInt posOfDelimiter  = serId_usrId->Find(KDelimiter);
       
   101     if(KErrNotFound != posOfDelimiter )
       
   102         {
       
   103         TInt serviceId = KErrNotFound;
       
   104         TBuf<KMaxServiceIdLength> servIdBuf;
       
   105         TPtrC ptr(serId_usrId->Left(posOfDelimiter));
       
   106         servIdBuf = ptr;
       
   107         TLex16 lex(servIdBuf);
       
   108         lex.Val(serviceId);
       
   109        
       
   110         // Check if this service id belongs to us. If there is customized 
       
   111         // service with own service tab, we MUST not handle this callback.
       
   112         RArray<TUint32> supportedServices;
       
   113         CleanupClosePushL( supportedServices );
       
   114         iServiceTableFetcher.GetMasterServiceIdsL( supportedServices );
       
   115         TInt ourService = supportedServices.Find( serviceId );
       
   116         if( KErrNotFound != ourService )
       
   117             {
       
   118             MVIMPSTStorageServiceView* storage =  CVIMPSTStorageManagerFactory::ContactListInterfaceL((TUint32)serviceId);
       
   119             __ASSERT_ALWAYS( storage, User::Leave( KErrGeneral ));
       
   120             TPtrC useridPtr = serId_usrId->Right(serId_usrId->Length() - (posOfDelimiter+ 1) );
       
   121             MVIMPSTStorageContact* contact = storage->FindContactByUserId(useridPtr);
       
   122             if(contact)
       
   123                 {
       
   124                 TBuf8<KMaxPackedContactLinkLength> link;
       
   125                 link = contact->ContactLink()->PackLC()->Des();
       
   126      
       
   127                 CleanupStack::PopAndDestroy(); //pop and destroy the hbufc8*
       
   128                                
       
   129                 TInt length = KMaxServiceIdLength + useridPtr.Length() + link.Length()
       
   130                                + contact->Name().Length() + (KDelimiter().Length() * 3);
       
   131                 TPtrC fullname = contact->Name();
       
   132                 HBufC* dispName = NULL;
       
   133                 posOfDelimiter = fullname.Find(KDelimiter);
       
   134                 TInt displayIndex = fullname.Length() - (posOfDelimiter+ 1);
       
   135                 if(KErrNotFound != posOfDelimiter && (displayIndex > 0))
       
   136                     {
       
   137                     dispName = fullname.Right( displayIndex  ).AllocLC() ;
       
   138                     }
       
   139                 else
       
   140                     {
       
   141                     dispName= fullname.AllocLC();
       
   142                     }
       
   143                 HBufC16* contactLink = HBufC16::NewLC(link.Length());
       
   144                 TPtr16 ptr = contactLink->Des();
       
   145                 ptr.Copy(link);
       
   146                 HBufC* userDetails = HBufC::NewLC(length);
       
   147                 TPtr userDetailsPtr = userDetails->Des();
       
   148          
       
   149                 userDetailsPtr.Zero();
       
   150                 userDetailsPtr.AppendNum(serviceId);
       
   151                 userDetailsPtr.Append(KDelimiter());
       
   152                 userDetailsPtr.Append(useridPtr);
       
   153                 userDetailsPtr.Append(KDelimiter());
       
   154                 userDetailsPtr.Append(*dispName);
       
   155                 userDetailsPtr.Append(KDelimiter());
       
   156                 userDetailsPtr.Append( *contactLink );
       
   157                 
       
   158                 TRACE( T_LIT("CVIMPSTEngineCVListener::RunL publishing = %S"),&(*userDetails));        
       
   159                 
       
   160                 iProperty.Set(KConvViewUID,KContactLinkDisplayNameKey,*userDetails);
       
   161                 CleanupStack::PopAndDestroy(3);//userDetails,contactLink,dispName
       
   162               
       
   163                 }
       
   164             // contact not found
       
   165             else
       
   166                 {
       
   167                 TRACE( T_LIT("CVIMPSTEngineCVListener::RunL publishing null display name"));        
       
   168                 iProperty.Set(KConvViewUID,KContactLinkDisplayNameKey,KNullDesC());
       
   169                 }
       
   170             }
       
   171         CleanupStack::PopAndDestroy( &supportedServices );
       
   172         }
       
   173     CleanupStack::PopAndDestroy( serId_usrId );
       
   174     iProperty.Subscribe( iStatus );
       
   175     SetActive();
       
   176     TRACE( T_LIT("CVIMPSTEngineCVListener::RunL() end"));
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CVIMPSTEngineCVListener::RunL()
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CVIMPSTEngineCVListener::DoCancel()
       
   184     {    
       
   185     TRACE( T_LIT("CVIMPSTEngineCVListener::DoCancel() start"));
       
   186     iProperty.Cancel();
       
   187     }
       
   188   		     
       
   189 // ---------------------------------------------------------
       
   190 // CIMCVEngineStorageListener::StopListening()
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 TInt CVIMPSTEngineCVListener::RunError( TInt aError )
       
   194     {
       
   195     TRACE( T_LIT("CVIMPSTEngineCVListener::RunError() start"));
       
   196     if ( KErrCancel != aError )
       
   197         {
       
   198         iProperty.Subscribe( iStatus );
       
   199         SetActive();
       
   200         }
       
   201     return KErrNone;
       
   202     }
       
   203 //  End of File  
       
   204