uiservicetab/vimpstengine/src/cvimpstenginecvlistener.cpp
branchRCL_3
changeset 23 9a48e301e94b
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     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 "uiservicetabtracer.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 	TRACER_AUTO;
       
    53     
       
    54     // subscribing for the property published by conversation view.
       
    55     // attach the properties.
       
    56     User::LeaveIfError( iProperty.Attach(KConvViewUID,KXspIdServiceIDKey  ) );
       
    57     //start listening property published by CV (to get Contact link and Display name.).
       
    58     iProperty.Subscribe( iStatus );
       
    59     SetActive();
       
    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 	TRACER_AUTO;
       
    92     // resubscribe before processing new value to prevent missing updates
       
    93     //TBuf <KMaxSerIdXspIdLen> serId_usrId;
       
    94     HBufC16* serId_usrId = HBufC16::NewLC(KMaxSerIdXspIdLen);
       
    95     if ( serId_usrId )
       
    96         {
       
    97         TPtr serId_usrIdPtr(serId_usrId->Des());
       
    98         iProperty.Get(KConvViewUID,KXspIdServiceIDKey,serId_usrIdPtr);
       
    99         }
       
   100     // parse the service id and userid form the buf and get the 
       
   101     // contactlink and first name and publish it.
       
   102     TInt posOfDelimiter  = serId_usrId->Find(KDelimiter);
       
   103     if(KErrNotFound != posOfDelimiter )
       
   104         {
       
   105         TInt serviceId = KErrNotFound;
       
   106         TBuf<KMaxServiceIdLength> servIdBuf;
       
   107         TPtrC ptr(serId_usrId->Left(posOfDelimiter));
       
   108         servIdBuf = ptr;
       
   109         TLex16 lex(servIdBuf);
       
   110         lex.Val(serviceId);
       
   111        
       
   112         // Check if this service id belongs to us. If there is customized 
       
   113         // service with own service tab, we MUST not handle this callback.
       
   114         RArray<TUint32> supportedServices;
       
   115         CleanupClosePushL( supportedServices );
       
   116         iServiceTableFetcher.GetMasterServiceIdsL( supportedServices );
       
   117         TInt ourService = supportedServices.Find( serviceId );
       
   118         if( KErrNotFound != ourService )
       
   119             {
       
   120             MVIMPSTStorageServiceView* storage =  CVIMPSTStorageManagerFactory::ContactListInterfaceL((TUint32)serviceId);
       
   121             __ASSERT_ALWAYS( storage, User::Leave( KErrGeneral ));
       
   122             TPtrC useridPtr = serId_usrId->Right(serId_usrId->Length() - (posOfDelimiter+ 1) );
       
   123             MVIMPSTStorageContact* contact = storage->FindContactByUserId(useridPtr);
       
   124             if(contact)
       
   125                 {
       
   126                 TBuf8<KMaxPackedContactLinkLength> link;
       
   127                 link = contact->ContactLink()->PackLC()->Des();
       
   128      
       
   129                 CleanupStack::PopAndDestroy(); //pop and destroy the hbufc8*
       
   130                                
       
   131                 TInt length = KMaxServiceIdLength + useridPtr.Length() + link.Length()
       
   132                                + contact->Name().Length() + (KDelimiter().Length() * 3);
       
   133                 TPtrC fullname = contact->Name();
       
   134                 HBufC* dispName = NULL;
       
   135                 posOfDelimiter = fullname.Find(KDelimiter);
       
   136                 TInt displayIndex = fullname.Length() - (posOfDelimiter+ 1);
       
   137                 if(KErrNotFound != posOfDelimiter && (displayIndex > 0))
       
   138                     {
       
   139                     dispName = fullname.Right( displayIndex  ).AllocLC() ;
       
   140                     }
       
   141                 else
       
   142                     {
       
   143                     dispName= fullname.AllocLC();
       
   144                     }
       
   145                 HBufC16* contactLink = HBufC16::NewLC(link.Length());
       
   146                 TPtr16 ptr = contactLink->Des();
       
   147                 ptr.Copy(link);
       
   148                 HBufC* userDetails = HBufC::NewLC(length);
       
   149                 TPtr userDetailsPtr = userDetails->Des();
       
   150          
       
   151                 userDetailsPtr.Zero();
       
   152                 userDetailsPtr.AppendNum(serviceId);
       
   153                 userDetailsPtr.Append(KDelimiter());
       
   154                 userDetailsPtr.Append(useridPtr);
       
   155                 userDetailsPtr.Append(KDelimiter());
       
   156                 userDetailsPtr.Append(*dispName);
       
   157                 userDetailsPtr.Append(KDelimiter());
       
   158                 userDetailsPtr.Append( *contactLink );
       
   159                 
       
   160                 TRACE( " publishing = %S",&(*userDetails)); 
       
   161                 
       
   162                 iProperty.Set(KConvViewUID,KContactLinkDisplayNameKey,*userDetails);
       
   163                 CleanupStack::PopAndDestroy(3);//userDetails,contactLink,dispName
       
   164               
       
   165                 }
       
   166             // contact not found
       
   167             else
       
   168                 {
       
   169             TRACE( "publishing null display name"); 
       
   170                 iProperty.Set(KConvViewUID,KContactLinkDisplayNameKey,KNullDesC());
       
   171                 }
       
   172             }
       
   173         CleanupStack::PopAndDestroy( &supportedServices );
       
   174         }
       
   175         
       
   176     if(serId_usrId)
       
   177     		{
       
   178     		CleanupStack::PopAndDestroy( serId_usrId );
       
   179     		}  
       
   180     iProperty.Subscribe( iStatus );
       
   181     SetActive();
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------
       
   185 // CVIMPSTEngineCVListener::RunL()
       
   186 // ---------------------------------------------------------
       
   187 //
       
   188 void CVIMPSTEngineCVListener::DoCancel()
       
   189     {    
       
   190 	TRACER_AUTO;
       
   191     iProperty.Cancel();
       
   192     }
       
   193   		     
       
   194 // ---------------------------------------------------------
       
   195 // CIMCVEngineStorageListener::StopListening()
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 TInt CVIMPSTEngineCVListener::RunError( TInt aError )
       
   199     {
       
   200     TRACER_AUTO;
       
   201     if ( KErrCancel != aError )
       
   202         {
       
   203         iProperty.Subscribe( iStatus );
       
   204         SetActive();
       
   205         }
       
   206     return KErrNone;
       
   207     }
       
   208 //  End of File  
       
   209