phonebookui/Phonebook2/spbcontentprovider/src/spbcontent.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 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: Content info container
       
    15 *
       
    16 */
       
    17 
       
    18 #include "spbcontent.h"
       
    19 #include "spbstatusprovider.h"
       
    20 #include "spbserviceiconprovider.h"
       
    21 #include "spbphonenumberparser.h"
       
    22 
       
    23 // LOCAL METHODS AND CONSTANTS
       
    24 namespace {
       
    25 
       
    26 inline TBool IsFlag( TInt aFlags, TInt aFlag ) 
       
    27     {
       
    28     return ( aFlags & aFlag );
       
    29     }
       
    30 }
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CSpbContent::NewLC
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 CSpbContent* CSpbContent::NewLC(
       
    37     const CSpbContent::TParameters& aParameters,
       
    38     const MVPbkContactLink& aLink)
       
    39     {
       
    40     CSpbContent* self = new (ELeave) CSpbContent( aParameters );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL(aLink);
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // CSpbContent::~CSpbContent
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CSpbContent::~CSpbContent()
       
    51     {
       
    52     delete iBuddyId;
       
    53     delete iLink;
       
    54     delete iText;
       
    55     delete iPhoneNumberParser;
       
    56     }
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CSpbContent::ConstructL
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 inline void CSpbContent::ConstructL(const MVPbkContactLink& aLink)
       
    63     {
       
    64     iLink = aLink.CloneLC();
       
    65     CleanupStack::Pop(); // iLink
       
    66     
       
    67     if( IsFlag(iParameters.iFeatures, CSpbContentProvider::EPhoneNumber) )
       
    68         {
       
    69         iPhoneNumberParser = CSpbPhoneNumberParser::NewL(
       
    70             *(iParameters.iContactManager), *this );
       
    71         }
       
    72 
       
    73     iAsyncCallBack.CallBack();
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CSpbContent::CSpbContent
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 inline CSpbContent::CSpbContent(
       
    81     const CSpbContent::TParameters& aParameters ) :
       
    82     iParameters(aParameters),
       
    83     iAsyncCallBack( TCallBack( CSpbContent::StartFetchContent, this ), 
       
    84         CActive::EPriorityStandard ),
       
    85     iType( CSpbContentProvider::ETypeNone )
       
    86     {
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CSpbContent::RefreshNumber
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 void CSpbContent::RefreshNumber()
       
    94 	{
       
    95 	// if no status text
       
    96 	if( iType != CSpbContentProvider::ETypeSocialStatus && iPhoneNumberParser )
       
    97 		{
       
    98 		// re-fetch phonenumber
       
    99 		iPhoneNumberParser->FetchPhoneNumber( Link() );
       
   100 		}
       
   101 	}
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CSpbContent::StartFetchContent
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CSpbContent::StartFetchContent( TAny* aPtr )
       
   108     {
       
   109     static_cast<CSpbContent*>(aPtr)->DoStartFetchContent();
       
   110     return 0;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CSpbContent::PhoneNumberUpdatedL
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 void CSpbContent::DoStartFetchContent()
       
   118     {
       
   119     if(iParameters.iStatusProvider)
       
   120         {
       
   121         iParameters.iStatusProvider->FetchStatusDataL(*this);
       
   122         }
       
   123     else if(iPhoneNumberParser)
       
   124         {
       
   125         iPhoneNumberParser->FetchPhoneNumber(Link());
       
   126         }
       
   127     else
       
   128         {
       
   129         NotifyObservers( MSpbContentProviderObserver::EContentNotAvailable );
       
   130         }
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CSpbContent::PhoneNumberUpdatedL
       
   135 // ----------------------------------------------------------------------------
       
   136 //
       
   137 void CSpbContent::PhoneNumberUpdatedL( const TDesC& aPhoneNumber )
       
   138     {
       
   139     delete iText;
       
   140     iText = NULL;
       
   141     iType = CSpbContentProvider::ETypeNone;
       
   142     iReady = EFalse;
       
   143     
       
   144     if( aPhoneNumber.Length() )
       
   145         {
       
   146         iText = aPhoneNumber.AllocL();
       
   147         iReady = ETrue;
       
   148         iType = CSpbContentProvider::ETypePhoneNumber;
       
   149         }
       
   150     NotifyObservers(MSpbContentProviderObserver::EContentChanged);
       
   151     }
       
   152     
       
   153 // ----------------------------------------------------------------------------
       
   154 // CSpbContent::StatusDataUpdatedL
       
   155 // ----------------------------------------------------------------------------
       
   156 //
       
   157 void CSpbContent::StatusDataUpdatedL(
       
   158         const TDesC& aStatusMessage, 
       
   159         const TDesC8& aBrandId,
       
   160         const TDesC8& aIconEntry )
       
   161     {
       
   162     if(!aStatusMessage.Length() && iPhoneNumberParser )
       
   163         {
       
   164         iPhoneNumberParser->FetchPhoneNumber(Link());
       
   165         return;
       
   166         }
       
   167     
       
   168     delete iText;
       
   169     iText = NULL;
       
   170     if(aStatusMessage.Length())
       
   171         {
       
   172         if(iParameters.iIconProvider && aBrandId.Length() && aIconEntry.Length() )
       
   173             {
       
   174             MSpbServiceIcon* icon = 
       
   175                 iParameters.iIconProvider->GetBrandedIconL( aBrandId, aIconEntry );
       
   176             iIconId = icon->IconId();
       
   177             }
       
   178         
       
   179         iText = aStatusMessage.AllocL();
       
   180         iReady = ETrue;
       
   181         iType = CSpbContentProvider::ETypeSocialStatus;
       
   182         NotifyObservers(MSpbContentProviderObserver::EContentChanged);
       
   183         }
       
   184     else
       
   185         {
       
   186         iReady = EFalse;
       
   187         iType = CSpbContentProvider::ETypeNone;
       
   188         NotifyObservers(MSpbContentProviderObserver::EContentNotAvailable);
       
   189         }
       
   190     }
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // CSpbContent::NotifyObservers
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 void CSpbContent::NotifyObservers(
       
   197         MSpbContentProviderObserver::TSpbContentEvent aEvent)
       
   198     {
       
   199     const TInt count(iParameters.iObservers->Count());
       
   200     for(TInt i = 0 ; i < count ; ++i)
       
   201         {
       
   202         (*iParameters.iObservers)[i]->ContentUpdated(*iLink,aEvent);
       
   203         }
       
   204     }
       
   205 
       
   206 // end of file