phonebookui/Phonebook2/NamesListExtension/src/CPbk2NameslistUiControlExtension.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Phonebook 2 Nameslist UI control composite UI extension.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2NameslistUiControlExtension.h"
       
    20 
       
    21 #include <CPbk2IconArray.h>
       
    22 #include <TPbk2IconId.h>
       
    23 #include <Pbk2IconId.hrh>
       
    24 #include <Pbk2Commands.hrh>
       
    25 #include <Pbk2UID.h>
       
    26 #include <MPbk2ContactUiControlUpdate.h>
       
    27 #include <MVPbkViewContact.h>
       
    28 #include <MVPbkContactLink.h>
       
    29 #include <CVPbkContactManager.h>
       
    30 #include <MVPbkBaseContactFieldCollection.h>
       
    31 #include <MVPbkBaseContactField.h>
       
    32 #include <MVPbkFieldType.h>
       
    33 #include <MVPbkContactFieldData.h>
       
    34 #include <VPbkEng.rsg>
       
    35 #include <CVPbkTopContactManager.h>
       
    36 #include <Pbk2InternalUID.h>
       
    37 #include <mpbk2commanditemupdater.h>
       
    38 
       
    39 //ECE
       
    40 #include <gulicon.h>
       
    41 #include <fbs.h>
       
    42 #include <AknUtils.h>
       
    43 #include <aknlayoutscalable_avkon.cdl.h>
       
    44 #include <aknlayoutscalable_apps.cdl.h>
       
    45 
       
    46 #include "CPbk2UIExtensionInformation.h"
       
    47 #include <CPbk2UIExtensionPlugin.h>
       
    48 #include <Pbk2UIExtension.hrh>
       
    49 #include <TPbk2IconId.h>
       
    50 #include "Pbk2NamesListExUID.h"
       
    51 #include "CPbk2EcePresenceEngine.h"
       
    52 
       
    53 enum TNlxPanicCodes
       
    54     {
       
    55     ENlxPanicEmptyPackage,
       
    56     ENlxPanicIconNull,
       
    57     ENlxPanicNoLinks,
       
    58     ENlxPanicStrayIcon,
       
    59     ENlxPanicStrayIconInfo
       
    60     };
       
    61 
       
    62 /// Unnamed namespace for local definitions
       
    63 namespace {
       
    64 
       
    65 TSize CalculateListIconSize()
       
    66     {
       
    67     TRect mainPane;
       
    68     AknLayoutUtils::LayoutMetricsRect(
       
    69         AknLayoutUtils::EMainPane, mainPane );
       
    70     TAknLayoutRect listLayoutRect;
       
    71     listLayoutRect.LayoutRect(
       
    72         mainPane,
       
    73         AknLayoutScalable_Apps::list_double_large_graphic_phob2_pane_g2( 0 ).LayoutLine() );
       
    74     return listLayoutRect.Rect().Size();
       
    75     }
       
    76 }
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CPbk2NameslistUiControlExtension::CPbk2NameslistUiControlExtension
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CPbk2NameslistUiControlExtension::CPbk2NameslistUiControlExtension
       
    84         ( CVPbkContactManager& aContactManager,
       
    85           CSpbContentProvider& aContentProvider,
       
    86           CPbk2MyCard* aMyCard )  :
       
    87             iContactManager( aContactManager ),
       
    88             iContentProvider( aContentProvider ),
       
    89             iMyCard( aMyCard ),
       
    90             iIconId( TPbk2IconId() )
       
    91     {
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CPbk2NameslistUiControlExtension::ConstructL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CPbk2NameslistUiControlExtension::ConstructL()
       
    99     {
       
   100 	// if my card is provided
       
   101 	if( iMyCard )
       
   102 		{
       
   103 		// set this to be observer of the my card
       
   104 		iMyCard->SetObserverL( *this );
       
   105 		// check if the mycard has already a thumbnail
       
   106 		iBitmap = iMyCard->MyCardBitmap();
       
   107 		}
       
   108 	
       
   109 	iPresenceEngine = CPbk2EcePresenceEngine::NewL(
       
   110             iContactManager,
       
   111             *this,
       
   112             CalculateListIconSize() );
       
   113     iContentProvider.AddObserverL( *this );
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CPbk2NameslistUiControlExtension::NewL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 CPbk2NameslistUiControlExtension* CPbk2NameslistUiControlExtension::NewL
       
   121         ( CVPbkContactManager& aContactManager,
       
   122           CSpbContentProvider& aContentProvider,
       
   123           CPbk2MyCard* aMyCard )
       
   124     {
       
   125     CPbk2NameslistUiControlExtension* self =
       
   126         new ( ELeave ) CPbk2NameslistUiControlExtension
       
   127             ( aContactManager, aContentProvider, aMyCard );
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL();
       
   130     CleanupStack::Pop( self );
       
   131     return self;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CPbk2NameslistUiControlExtension::~CPbk2NameslistUiControlExtension
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 CPbk2NameslistUiControlExtension::~CPbk2NameslistUiControlExtension()
       
   139     {
       
   140     delete iPresenceEngine;
       
   141     iDummyArray.Close();
       
   142     iContentProvider.RemoveObserver( *this );
       
   143     // if my card is provided
       
   144     if( iMyCard )
       
   145     	{
       
   146     	iMyCard->RemoveObserver( *this );
       
   147     	}
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CPbk2NameslistUiControlExtension::DoRelease
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CPbk2NameslistUiControlExtension::DoRelease()
       
   155     {
       
   156     delete this;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CPbk2NameslistUiControlExtension::GetDynamicIconsL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 const TArray<TPbk2IconId> CPbk2NameslistUiControlExtension::GetDynamicIconsL
       
   164     ( const MVPbkViewContact* aContactHandle )
       
   165     {
       
   166     //Add here the values of TPbk2IconId that are preferred to be shown
       
   167     //in the list. Icons must already be present in the icon array.
       
   168     iDummyArray.Reset();
       
   169 
       
   170     if ( aContactHandle )
       
   171         {
       
   172         // first check presence icon, highest priority
       
   173         MVPbkContactLink* link = aContactHandle->CreateLinkLC();
       
   174         if ( link )
       
   175             {
       
   176             // Requests presence notifications, if hasn't already done so.
       
   177             iPresenceEngine->SubscribeContactPresenceL( *link );
       
   178 
       
   179             TPbk2IconId iconId;
       
   180             TBool found = iPresenceEngine->GetIconIdForContact( *link, iconId );
       
   181             if ( found )
       
   182                 {
       
   183                 // The icon has already been fetched from the presence server etc.
       
   184                 if ( iIconArray->FindIcon( iconId ) == KErrNotFound )
       
   185                     {
       
   186                     // The icon is not yet in the array. Add it.
       
   187                     CGulIcon* gulIcon = iPresenceEngine->CreateIconCopyLC( iconId );
       
   188                     iIconArray->AppendIconL( gulIcon, iconId );
       
   189                     CleanupStack::Pop( gulIcon );
       
   190                     }
       
   191                 iDummyArray.AppendL( iconId );
       
   192                 }
       
   193             CleanupStack::PopAndDestroy(); // link
       
   194             }
       
   195 
       
   196         //Top contact indicator
       
   197         if ( CVPbkTopContactManager::IsTopContact( *aContactHandle ) )
       
   198             {
       
   199             iDummyArray.AppendL( TPbk2IconId(
       
   200                 TUid::Uid(KPbk2UID3), EPbk2qgn_prop_pb_topc ));
       
   201             }
       
   202         }
       
   203 
       
   204     //Presence indicator
       
   205     return iDummyArray.Array();
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CPbk2NameslistUiControlExtension::SetContactUiControlUpdate
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CPbk2NameslistUiControlExtension::SetContactUiControlUpdate
       
   213         ( MPbk2ContactUiControlUpdate* aContactUpdator )
       
   214     {
       
   215     //Register observer interface (MPbk2ContactUiControlUpdate) of aContactUpdator
       
   216     //In case changes in data, call  UpdateContact(const MVPbkContactLink& aContactLink )
       
   217     iContactUpdator = aContactUpdator;
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CPbk2NameslistUiControlExtension::ContactUiControlExtensionExtension
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 TAny* CPbk2NameslistUiControlExtension::ContactUiControlExtensionExtension(
       
   225     TUid aExtensionUid )
       
   226     {
       
   227     if ( aExtensionUid == KMPbk2ContactUiControlExtensionExtension2Uid )
       
   228         {
       
   229         return static_cast<MPbk2ContactUiControlExtension2*>( this );
       
   230         }
       
   231     else if( aExtensionUid == TUid::Uid( KPbk2ContactUiControlExtensionExtensionUID ) ) 
       
   232         {
       
   233         return static_cast<MPbk2ContactUiControlDoubleListboxExtension*>( this );
       
   234         }
       
   235     return NULL;
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CPbk2NameslistUiControlExtension::SetIconArray
       
   240 //
       
   241 // For use via ContactUiControlExtensionExtension
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CPbk2NameslistUiControlExtension::SetIconArray(CPbk2IconArray& aIconArray)
       
   245     {
       
   246     iIconArray = &aIconArray;
       
   247     // if bitmap is allready set. MyCardEvent - event has come before this one or there was an image on creation
       
   248     if( iBitmap && iMyCard )
       
   249     	{
       
   250 		AddThumbnailToIconArrayL();
       
   251     	}
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CPbk2NameslistUiControlExtension::ContactPresenceChanged
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CPbk2NameslistUiControlExtension::ContactPresenceChanged(
       
   259     const MVPbkContactLink& aLink )
       
   260     {
       
   261     if ( iContactUpdator )
       
   262         {
       
   263         iContactUpdator->UpdateContact( aLink );
       
   264         }
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CPbk2NameslistUiControlExtension::FormatDataL
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CPbk2NameslistUiControlExtension::FormatDataL(
       
   272         const MVPbkViewContact& aViewContact,
       
   273         MPbk2DoubleListboxDataElement& aDataElement )
       
   274     {
       
   275     MVPbkContactLink* link = aViewContact.CreateLinkLC();
       
   276     if( link )
       
   277         {
       
   278         HBufC* txt = NULL;
       
   279         TPbk2IconId iconId;
       
   280         CSpbContentProvider::TSpbContentType type = CSpbContentProvider::ETypeNone; 
       
   281         iContentProvider.GetContentL( *link, txt, iconId, type );
       
   282 
       
   283         // select proper element type based on content type
       
   284         MPbk2DoubleListboxDataElement::TTextDataType elemType = 
       
   285             MPbk2DoubleListboxDataElement::ETypeGenericText;
       
   286         if( type == CSpbContentProvider::ETypePhoneNumber )
       
   287             {
       
   288             elemType = MPbk2DoubleListboxDataElement::ETypePhoneNumber;
       
   289             }
       
   290         
       
   291         aDataElement.SetText(
       
   292             MPbk2DoubleListboxDataElement::EStatusText, txt, elemType );
       
   293 
       
   294         CleanupStack::PopAndDestroy();  // link
       
   295         }
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CPbk2NameslistUiControlExtension::SetCommandItemUpdater
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void CPbk2NameslistUiControlExtension::SetCommandItemUpdater(
       
   303     MPbk2CommandItemUpdater* aCommandUpdater )
       
   304     {
       
   305     // Register command item updater interface
       
   306     iCommandUpdater = aCommandUpdater;
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CPbk2NameslistUiControlExtension::ContentUpdated
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CPbk2NameslistUiControlExtension::ContentUpdated(
       
   314     MVPbkContactLink& aLink,
       
   315     MSpbContentProviderObserver::TSpbContentEvent aEvent )
       
   316     {
       
   317     if( aEvent == MSpbContentProviderObserver::EContentChanged )
       
   318         {
       
   319         MVPbkContactLink* mylink = iMyCard ? iMyCard->MyCardLink() : NULL;
       
   320         if( mylink && mylink->IsSame( aLink ) )
       
   321             {
       
   322             // mycard updated -> update mycard command item instead of contact
       
   323             if( iCommandUpdater )
       
   324                 {
       
   325                 iCommandUpdater->UpdateCommandItem( EPbk2CmdOpenMyCard );
       
   326                 }
       
   327             }
       
   328         else if( iContactUpdator )
       
   329             {
       
   330             // some other contactB
       
   331             iContactUpdator->UpdateContact( aLink );
       
   332             }
       
   333         }
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CPbk2NameslistUiControlExtension::MyCardEvent
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CPbk2NameslistUiControlExtension::MyCardEvent( TMyCardStatusEvent aEvent )
       
   341 	{
       
   342 	// thumbnail is loaded
       
   343 	if( aEvent == EStateThumbnailLoaded && iMyCard )    
       
   344 		{
       
   345 		// get bitmap
       
   346 		iBitmap = iMyCard->MyCardBitmap();
       
   347 			
       
   348 		// if icon array is already set, add icon
       
   349 		if( iIconArray )
       
   350 			{
       
   351 			AddThumbnailToIconArrayL();
       
   352 			}
       
   353 		}
       
   354 	}
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CPbk2NameslistUiControlExtension::AddThumbnailToIconArrayL
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CPbk2NameslistUiControlExtension::AddThumbnailToIconArrayL( )
       
   361 	{
       
   362 	if( iMyCard )
       
   363 		{
       
   364 		iIconId = iMyCard->MyCardIconId();
       
   365 		}
       
   366 	
       
   367 	// if thumb icon is not created, create it and append to array
       
   368 	if( !iThumbIcon )
       
   369 		{
       
   370 		iThumbIcon = CGulIcon::NewLC();
       
   371 		CleanupStack::Pop( iThumbIcon );
       
   372 		iThumbIcon->SetBitmap( iBitmap );
       
   373 		iBitmap = NULL;
       
   374 		// takes ownership
       
   375 		iIconArray->AppendIconL( iThumbIcon, iIconId );
       
   376 		}
       
   377 	    
       
   378 	// else change the bitmap. This is to prevent 
       
   379 	// thumbnail indexes on thumbnail manager to get out of sync
       
   380 	else
       
   381 		{
       
   382 		iThumbIcon->SetBitmap( iBitmap );
       
   383 		iBitmap = NULL;
       
   384 		}
       
   385 	}
       
   386 
       
   387 
       
   388 // End of File