phonebookui/Phonebook2/ccapplication/ccamycardplugin/src/ccappmycardcontainer.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:  Implementation of mycard plugin control container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ccaextensionfactory.h>
       
    21 
       
    22 #include <aknlists.h>
       
    23 #include <eiktxlbm.h>
       
    24 #include <barsread.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 #include <AknsBasicBackgroundControlContext.h>
       
    27 #include <AknUtils.h>
       
    28 
       
    29 #include <MPbk2ContactNameFormatter.h>
       
    30 #include <MVPbkStoreContact.h>
       
    31 #include <CPbk2IconArray.h>
       
    32 #include <Pbk2UIControls.rsg>
       
    33 #include <mpbk2command.h>
       
    34 #include <pbk2menufilteringflags.hrh>
       
    35 #include <mvpbkcontactlink.h>
       
    36 
       
    37 #include "ccappmycard.hrh"
       
    38 #include "ccappmycard.h"
       
    39 #include "ccappmycardcontainer.h"
       
    40 #include "ccappmycardcommon.h"
       
    41 #include "ccappmycardheadercontrol.h"
       
    42 #include "ccappmycardlistboxmodel.h"
       
    43 #include "ccappmycardplugin.h"
       
    44 #include "ccafactoryextensionnotifier.h"
       
    45 #include "spbcontentprovider.h"
       
    46 
       
    47 #include <MVPbkContactFieldTextData.h>
       
    48 #include <ccaextensionfactory.hrh>
       
    49 
       
    50 #include <aknlayoutscalable_avkon.cdl.h>
       
    51 #include <layoutmetadata.cdl.h>
       
    52 #include <AknsUtils.h>
       
    53 #include <ccappmycardpluginrsc.rsg>
       
    54 #include <gulicon.h>
       
    55 #include <phonebook2ece.mbg>
       
    56 #include <VPbkEng.rsg>
       
    57 #include "MVPbkFieldType.h"
       
    58 #include <aknstyluspopupmenu.h>
       
    59 #include <e32std.h>
       
    60 #include <aknlayoutscalable_apps.cdl.h>
       
    61 #include <Pbk2PresentationUtils.h>
       
    62 #include <Pbk2Presentation.rsg>
       
    63 #include <RPbk2LocalizedResourceFile.h>
       
    64 #include <Pbk2DataCaging.hrh>
       
    65 #include <pbk2nameordercenrep.h>
       
    66 #include <centralrepository.h>
       
    67 #include <Phonebook2PrivateCRKeys.h>
       
    68 
       
    69 // unnamed namespace
       
    70 namespace
       
    71 {
       
    72 _LIT( KMyCardIconDefaultFileName, "\\resource\\apps\\phonebook2ece.mif" );
       
    73 const TText KLineChange = '\n';
       
    74 const TInt KSubComponentCount = 2;
       
    75 const TInt KNumberOfContacts = 1;
       
    76 const TInt KNoContacts = 0;
       
    77 const TInt KPbk2UiSpecNameOrderFirstNameLastName = 0;
       
    78 const TInt KPbk2UiSpecNameOrderLastNameFirstName = 1;
       
    79 }
       
    80 
       
    81 // =========================== MEMBER FUNCTIONS ===============================
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CCCAppMyCardContainer::CCCAppMyCardContainer()
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CCCAppMyCardContainer::CCCAppMyCardContainer(
       
    88     CCCAppMyCardPlugin& aPlugin ) :
       
    89     iPlugin( aPlugin ),
       
    90     iNameOrder(KPbk2UiSpecNameOrderFirstNameLastName)
       
    91     {
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CCCAppMyCardContainer::~CCCAppMyCardContainer()
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 CCCAppMyCardContainer::~CCCAppMyCardContainer()
       
    99     {
       
   100 	iPlugin.MyCard().RemoveObserver( this );
       
   101 	delete iBackground;
       
   102     delete iHeaderCtrl;
       
   103     delete iListBox;
       
   104     delete iImageLoader;
       
   105     delete iFactoryExtensionNotifier;
       
   106     delete iViewLauncher;
       
   107     delete iImageSelectionPopup;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // CCCAppMyCardContainer::ConstructL()
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 void CCCAppMyCardContainer::ConstructL()
       
   115     {
       
   116     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardContainer::ConstructL()"));
       
   117 
       
   118     iPlugin.MyCard().AddObserverL( this );
       
   119 
       
   120     ResolveNameOrderL();
       
   121     
       
   122     // Header UI control
       
   123     iHeaderCtrl = CCCAppMyCardHeaderControl::NewL( *this );
       
   124     iHeaderCtrl->SetContainerWindowL( *this );
       
   125     iHeaderCtrl->AddObserverL( this );
       
   126 
       
   127     // Details list UI control
       
   128     iListBox = new(ELeave) CAknFormDoubleGraphicStyleListBox;
       
   129     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   130     iListBox->SetContainerWindowL( *this );
       
   131 
       
   132     // Setup listbox
       
   133     iListBox->View()->SetListEmptyTextL( KNullDesC );
       
   134     iListBox->CreateScrollBarFrameL( ETrue );
       
   135     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   136         CEikScrollBarFrame::EOff,
       
   137         CEikScrollBarFrame::EAuto );
       
   138 
       
   139     // Create icons for listbox.
       
   140     TResourceReader reader;
       
   141     iCoeEnv->CreateResourceReaderLC( reader, R_PBK2_FIELDTYPE_ICONS );
       
   142     CPbk2IconArray* iconArray = CPbk2IconArray::NewL( reader );
       
   143     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   144     CleanupStack::PopAndDestroy(); // reader
       
   145 
       
   146     // Create listbox model
       
   147     iModel = CCCAppMyCardListBoxModel::NewL(
       
   148         iPlugin.MyCard(), *iCoeEnv, *iListBox, *iconArray );
       
   149     iListBox->Model()->SetItemTextArray( iModel );
       
   150 
       
   151     // Get the skin background for the view
       
   152     iBackground = CAknsBasicBackgroundControlContext::NewL(
       
   153         KAknsIIDQsnBgAreaMain, TRect(0, 0, 0, 0), EFalse );
       
   154 
       
   155     // Start observing now that the class is ready
       
   156     iListBox->SetListBoxObserver( this );
       
   157     iPlugin.MyCard().AddObserverL( this );
       
   158 
       
   159 
       
   160     if( iPlugin.MyCard().IsContactLinkReady() )
       
   161     	{
       
   162         CCCAppStatusControl* statusControl = iHeaderCtrl->StatusControl();
       
   163     	if( statusControl )
       
   164     	    {
       
   165             statusControl->SetContactLinkL( iPlugin.MyCard().ContactLink() );
       
   166     	    }
       
   167 		iControlLink = ETrue;
       
   168     	}
       
   169     iFactoryExtensionNotifier = CCCaFactoryExtensionNotifier::NewL();
       
   170 
       
   171     TCallBack callBack( CCCAppMyCardContainer::CheckExtensionFactoryL, this );
       
   172     iFactoryExtensionNotifier->ObserveExtensionFactory( callBack );
       
   173     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardContainer::ConstructL()"));
       
   174     }
       
   175 
       
   176 
       
   177 /**
       
   178  * Gets a digit from a descriptor.
       
   179  *
       
   180  * @param aReaderToBuf  Resource reader pointed to a descriptor resource.
       
   181  * @return  The digit.
       
   182  */
       
   183 inline TInt GetDigitFromDescriptorL( TResourceReader& aReaderToBuf )
       
   184     {
       
   185     HBufC* orderBuf = aReaderToBuf.ReadHBufCL();
       
   186     CleanupStack::PushL( orderBuf );
       
   187 
       
   188     TInt result = KPbk2UiSpecNameOrderFirstNameLastName;
       
   189     TPtrC ptr( orderBuf->Des() );
       
   190     if ( ptr.Length() > 0 && TChar(ptr[0]).IsDigit() )
       
   191         {
       
   192         result = TChar(ptr[0]).GetNumericValue();
       
   193         }
       
   194 
       
   195     CleanupStack::PopAndDestroy( orderBuf );
       
   196     return result;
       
   197     }
       
   198 
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // CCCAppMyCardContainer::ResolveNameOrderL()
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 inline void CCCAppMyCardContainer::ResolveNameOrderL()
       
   205     {
       
   206     TInt orderInCenRep = EPbk2CenRepNameOrderUndefined;
       
   207 
       
   208     CRepository* sortOrderSettings = CRepository::NewLC(TUid::Uid(KCRUidPhonebook));
       
   209     sortOrderSettings->Get(KPhonebookNameOrdering, orderInCenRep);
       
   210     CleanupStack::PopAndDestroy(sortOrderSettings);    
       
   211     
       
   212     
       
   213     if( orderInCenRep == EPbk2CenRepLastNameFirstName ||
       
   214         orderInCenRep == EPbk2CenRepFirstNameLastName )
       
   215         {
       
   216         iNameOrder = KPbk2UiSpecNameOrderFirstNameLastName;
       
   217         if( orderInCenRep == EPbk2CenRepLastNameFirstName )
       
   218             {
       
   219             iNameOrder = KPbk2UiSpecNameOrderLastNameFirstName;
       
   220             }
       
   221         }
       
   222     else
       
   223         {
       
   224         // Read order from resource
       
   225         
       
   226         // Open resource file for reading language specific default values
       
   227         RPbk2LocalizedResourceFile resFile;
       
   228         resFile.OpenLC( KPbk2RomFileDrive,
       
   229                 KDC_RESOURCE_FILES_DIR, 
       
   230                 Pbk2PresentationUtils::PresentationResourceFile() );
       
   231 
       
   232         // Read the name order value from the resource file
       
   233         TResourceReader reader;
       
   234         reader.SetBuffer( resFile.AllocReadLC( R_QTN_PHOB_NAME_ORDER ) );
       
   235         TInt digit = GetDigitFromDescriptorL( reader );
       
   236         CleanupStack::PopAndDestroy( 2 ); // reader & resFile
       
   237         if( ( digit == KPbk2UiSpecNameOrderFirstNameLastName ) ||
       
   238             ( digit == KPbk2UiSpecNameOrderLastNameFirstName ) )
       
   239             {
       
   240             iNameOrder = digit;
       
   241             }    
       
   242         }
       
   243     }
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CCCAppMyCardContainer::Draw()
       
   247 // ----------------------------------------------------------------------------
       
   248 //
       
   249 void CCCAppMyCardContainer::Draw(const TRect& /*aRect*/) const
       
   250     {
       
   251     // Draw the background using skin
       
   252     if (iBackground)
       
   253         {
       
   254         AknsDrawUtils::Background(
       
   255             AknsUtils::SkinInstance(), iBackground, this, SystemGc(), Rect());
       
   256         }
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------------------------------
       
   260 // CCCAppMyCardContainer::SizeChanged()
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 void CCCAppMyCardContainer::SizeChanged()
       
   264     {
       
   265     TRect rect( Rect() );
       
   266 
       
   267     // Background skin
       
   268     iBackground->SetRect( rect );
       
   269 
       
   270     /**
       
   271      * Option0 (w button, prt)
       
   272      * Option2 (w/o button, prt)
       
   273      * Option1 (w button, lsc)
       
   274      * Option3 (w/o button, lsc)
       
   275      */
       
   276     
       
   277     const TBool isLandscape( Layout_Meta_Data::IsLandscapeOrientation() );
       
   278     
       
   279     TInt option( isLandscape ? 3 : 2 ); // (w/o button)
       
   280     CCCAppStatusControl* statusControl = iHeaderCtrl->StatusControl();
       
   281     if( statusControl && statusControl->IsVisible() )
       
   282         {
       
   283         // (w button)
       
   284         if( isLandscape )
       
   285             {
       
   286             option = 1;
       
   287             }
       
   288         else
       
   289             {
       
   290             option = 0;
       
   291             }
       
   292         }
       
   293     
       
   294     // contact card pane layout
       
   295     TAknWindowComponentLayout contactCardPaneLayout( 
       
   296             TAknWindowComponentLayout::Compose( 
       
   297                     AknLayoutScalable_Apps::main_phob2_pane( 0 ),
       
   298                     AknLayoutScalable_Apps::phob2_contact_card_pane( 1 ) ) );
       
   299     
       
   300     // header layout
       
   301     TAknWindowComponentLayout headerPaneLayout( 
       
   302         TAknWindowComponentLayout::Compose( 
       
   303             contactCardPaneLayout,
       
   304             AknLayoutScalable_Apps::phob2_cc_data_pane( option ) ) );
       
   305     
       
   306     TAknLayoutRect headerPaneLayoutRect;
       
   307     headerPaneLayoutRect.LayoutRect( Rect(), headerPaneLayout.LayoutLine() );
       
   308     TRect headerPaneRect( headerPaneLayoutRect.Rect() );
       
   309     iHeaderCtrl->SetRect( headerPaneRect );
       
   310     
       
   311     // list layout
       
   312     TAknWindowComponentLayout listPaneLayout( 
       
   313         TAknWindowComponentLayout::Compose( 
       
   314             contactCardPaneLayout,
       
   315             AknLayoutScalable_Apps::phob2_cc_listscroll_pane( option ) ) );
       
   316     
       
   317     TAknLayoutRect listPaneLayoutRect;
       
   318     listPaneLayoutRect.LayoutRect( Rect(), listPaneLayout.LayoutLine() );
       
   319     TRect listPaneRect( listPaneLayoutRect.Rect() );
       
   320     iListBox->SetRect( listPaneRect );
       
   321     
       
   322 	delete iImageSelectionPopup;
       
   323 	iImageSelectionPopup = NULL;
       
   324 	
       
   325     DrawDeferred();
       
   326     }
       
   327 
       
   328 // ----------------------------------------------------------------------------
       
   329 // CCCAppMyCardContainer::CheckExtensionFactoryL()
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 TInt CCCAppMyCardContainer::CheckExtensionFactoryL(TAny* aPtr)
       
   333     {
       
   334     CCCAppMyCardContainer* self = static_cast<CCCAppMyCardContainer*>( aPtr );
       
   335     self->DoCheckExtensionFactoryL();
       
   336     return 0;
       
   337     }
       
   338 
       
   339 // ----------------------------------------------------------------------------
       
   340 // CCCAppMyCardContainer::DoCheckExtensionFactoryL()
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 void CCCAppMyCardContainer::DoCheckExtensionFactoryL()
       
   344     {
       
   345     CCCAExtensionFactory* extension = iFactoryExtensionNotifier->ExtensionFactory();
       
   346     // if extension is not null, extensionfactory plugins are available ->
       
   347     // show statuscontrol
       
   348     TBool visible = EFalse;
       
   349     if( extension )
       
   350         {
       
   351         if ( !iViewLauncher )
       
   352             {
       
   353             iViewLauncher = extension->CreateViewLauncherL();
       
   354             }
       
   355         visible = ETrue;
       
   356         }
       
   357     else
       
   358         {
       
   359         delete iViewLauncher;
       
   360         iViewLauncher = NULL;
       
   361         }
       
   362     
       
   363     CCCAppStatusControl* statusControl = iHeaderCtrl->StatusControl();
       
   364     if( statusControl )
       
   365         {
       
   366         statusControl->MakeVisible( visible );
       
   367         }
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // CCCAppMyCardContainer::CountComponentControls()
       
   372 // ----------------------------------------------------------------------------
       
   373 //
       
   374 TInt CCCAppMyCardContainer::CountComponentControls() const
       
   375     {
       
   376     return KSubComponentCount;
       
   377     }
       
   378 
       
   379 // ----------------------------------------------------------------------------
       
   380 // CCCAppMyCardContainer::ComponentControl()
       
   381 // ----------------------------------------------------------------------------
       
   382 //
       
   383 CCoeControl* CCCAppMyCardContainer::ComponentControl( TInt aIndex ) const
       
   384     {
       
   385     switch( aIndex )
       
   386         {
       
   387         case 0:
       
   388             {
       
   389             return iHeaderCtrl;
       
   390             }
       
   391         case 1:
       
   392         	{
       
   393 			return iListBox;
       
   394 			}
       
   395         }
       
   396     return NULL;
       
   397     }
       
   398 
       
   399 // ----------------------------------------------------------------------------
       
   400 // CCCAppMyCardContainer::MopSupplyObject()
       
   401 // ----------------------------------------------------------------------------
       
   402 //
       
   403 TTypeUid::Ptr CCCAppMyCardContainer::MopSupplyObject(TTypeUid aId)
       
   404     {
       
   405     // For skinning
       
   406     if( iBackground && aId.iUid == MAknsControlContext::ETypeId )
       
   407         {
       
   408         return MAknsControlContext::SupplyMopObject( aId, iBackground );
       
   409         }
       
   410 
       
   411     return CCoeControl::MopSupplyObject(aId);
       
   412     }
       
   413 
       
   414 // ----------------------------------------------------------------------------
       
   415 // CCCAppMyCardContainer::OfferKeyEventL()
       
   416 // ----------------------------------------------------------------------------
       
   417 //
       
   418 TKeyResponse CCCAppMyCardContainer::OfferKeyEventL(
       
   419     const TKeyEvent& aKeyEvent,
       
   420     TEventCode aType )
       
   421     {
       
   422     TKeyResponse resp = CCCAppViewPluginAknContainer::OfferKeyEventL( aKeyEvent, aType );
       
   423     if( iListBox && resp == EKeyWasNotConsumed )
       
   424         {
       
   425         resp = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   426         }
       
   427     return resp;
       
   428     }
       
   429 
       
   430 // ----------------------------------------------------------------------------
       
   431 // CCCAppMyCardContainer::MyCardEventL()
       
   432 // ----------------------------------------------------------------------------
       
   433 //
       
   434 void CCCAppMyCardContainer::MyCardEventL( MMyCardObserver::TEvent aEvent )
       
   435     {
       
   436     if( aEvent == MMyCardObserver::EEventContactLoaded )
       
   437         {    
       
   438         // Set own contact name
       
   439         CCCAppMyCard& mycard = iPlugin.MyCard();
       
   440           
       
   441         SetNameForHeaderControlL();
       
   442         
       
   443         // start loading image
       
   444         if( !iImageLoader )
       
   445             {
       
   446             // lazy initialization
       
   447             iImageLoader = CCCAppMyCardImageLoader::NewL(
       
   448                 mycard.ContactManager(), *this );
       
   449             }
       
   450         iImageLoader->LoadContactImageL( mycard.StoreContact() );
       
   451         }
       
   452 
       
   453     if( iPlugin.MyCard().IsContactLinkReady() && !iControlLink )
       
   454 		{
       
   455         CCCAppStatusControl* statusControl = iHeaderCtrl->StatusControl();
       
   456 		if(statusControl)
       
   457 		    {
       
   458             statusControl->SetContactLinkL( iPlugin.MyCard().ContactLink() );
       
   459 		    }
       
   460 		iControlLink = ETrue;
       
   461 		}
       
   462     }
       
   463 
       
   464 
       
   465 // ----------------------------------------------------------------------------
       
   466 // CCCAppMyCardContainer::ThumbnailReady()
       
   467 // ----------------------------------------------------------------------------
       
   468 //
       
   469 void CCCAppMyCardContainer::ThumbnailReady( CFbsBitmap* aThumbnail )
       
   470     {
       
   471     // takes ownership
       
   472     TRAPD( err, iHeaderCtrl->SetPortraitBitmapL( aThumbnail ) );
       
   473     if( err )
       
   474         {
       
   475         // TODO: how to handle? ignore? show note?
       
   476         }
       
   477     // Contact Image set. Set the flag.
       
   478     iMyCardImageSet = ETrue;
       
   479     }
       
   480 
       
   481 // ----------------------------------------------------------------------------
       
   482 // CCCAppMyCardContainer::ThumbnailLoadError()
       
   483 // ----------------------------------------------------------------------------
       
   484 //
       
   485 void CCCAppMyCardContainer::ThumbnailLoadError( TInt /*aError*/ )
       
   486     {
       
   487     CFbsBitmap* bitmap = NULL;
       
   488     CFbsBitmap* mask = NULL;
       
   489     TRAPD( err, AknIconUtils::CreateIconL(
       
   490         bitmap,
       
   491         mask,
       
   492         KMyCardIconDefaultFileName,
       
   493         EMbmPhonebook2eceQgn_prop_pb_thump_mycard,
       
   494         EMbmPhonebook2eceQgn_prop_pb_thump_mycard_mask ) );
       
   495     if( !err )
       
   496         {
       
   497         iHeaderCtrl->SetPortraitIcon( bitmap, mask ); // takes ownership
       
   498         }
       
   499     // Default contact image used.
       
   500     iMyCardImageSet = EFalse;
       
   501     }
       
   502 
       
   503 // ----------------------------------------------------------------------------
       
   504 // CCCAppMyCardContainer::HandleListBoxEventL
       
   505 // ----------------------------------------------------------------------------
       
   506 //
       
   507 void CCCAppMyCardContainer::HandleListBoxEventL(
       
   508     CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   509     {
       
   510     switch( aEventType )
       
   511         {
       
   512         case EEventEnterKeyPressed:
       
   513         case EEventItemDoubleClicked:
       
   514         case EEventItemSingleClicked:
       
   515             {
       
   516             // start the editor and pass tapped field index
       
   517             iPlugin.EditL( FocusedFieldIndex() );
       
   518             break;
       
   519             }
       
   520         default:
       
   521             {
       
   522             // ignored
       
   523             }
       
   524         }
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CCCAppMyCardContainer::Plugin
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 CCCAppMyCardPlugin& CCCAppMyCardContainer::Plugin()
       
   532     {
       
   533     return iPlugin;
       
   534     }
       
   535 
       
   536 
       
   537 /************************ FUNCTIONS FROM UI CONTROL ************************/
       
   538 
       
   539 // --------------------------------------------------------------------------
       
   540 // CCCAppMyCardContainer::ParentControl
       
   541 // --------------------------------------------------------------------------
       
   542 //
       
   543 MPbk2ContactUiControl* CCCAppMyCardContainer::ParentControl() const
       
   544 	{
       
   545     // Contact info control has no parent control
       
   546     return NULL;
       
   547 	}
       
   548 
       
   549 
       
   550 
       
   551 // --------------------------------------------------------------------------
       
   552 // CCCAppMyCardContainer::NumberOfContacts
       
   553 // --------------------------------------------------------------------------
       
   554 //
       
   555 TInt CCCAppMyCardContainer::NumberOfContacts() const
       
   556 	{
       
   557     return KNumberOfContacts;
       
   558 	}
       
   559 
       
   560 // --------------------------------------------------------------------------
       
   561 // CCCAppMyCardContainer::FocusedContactL
       
   562 // --------------------------------------------------------------------------
       
   563 //
       
   564 const MVPbkBaseContact* CCCAppMyCardContainer::FocusedContactL() const
       
   565 	{
       
   566     return static_cast<MVPbkBaseContact*>( &iPlugin.MyCard().StoreContact() );
       
   567 	}
       
   568 
       
   569 // --------------------------------------------------------------------------
       
   570 // CCCAppMyCardContainer::FocusedViewContactL
       
   571 // --------------------------------------------------------------------------
       
   572 //
       
   573 const MVPbkViewContact* CCCAppMyCardContainer::FocusedViewContactL() const
       
   574 	{
       
   575     return NULL;
       
   576 	}
       
   577 
       
   578 
       
   579 // --------------------------------------------------------------------------
       
   580 // CCCAppMyCardContainer::FocusedStoreContact
       
   581 // --------------------------------------------------------------------------
       
   582 //
       
   583 const MVPbkStoreContact* CCCAppMyCardContainer::FocusedStoreContact() const
       
   584 	{
       
   585 	return &iPlugin.MyCard().StoreContact();
       
   586     }
       
   587 
       
   588 // --------------------------------------------------------------------------
       
   589 // CCCAppMyCardContainer::SetFocusedContactL
       
   590 // --------------------------------------------------------------------------
       
   591 //
       
   592 void CCCAppMyCardContainer::SetFocusedContactL(
       
   593     const MVPbkBaseContact& /*aContact*/ )
       
   594 	{
       
   595     // do nothing
       
   596 	}
       
   597 
       
   598 
       
   599 // --------------------------------------------------------------------------
       
   600 // CCCAppMyCardContainer::SetFocusedContactL
       
   601 // --------------------------------------------------------------------------
       
   602 //
       
   603 void CCCAppMyCardContainer::SetFocusedContactL(
       
   604     const MVPbkContactBookmark& /*aContactBookmark*/)
       
   605 	{
       
   606     // Do nothing
       
   607 	}
       
   608 
       
   609 // --------------------------------------------------------------------------
       
   610 // CCCAppMyCardContainer::SetFocusedContactL
       
   611 // --------------------------------------------------------------------------
       
   612 //
       
   613 void CCCAppMyCardContainer::SetFocusedContactL(
       
   614     const MVPbkContactLink& /*aContactLink*/ )
       
   615 	{
       
   616 	}
       
   617 
       
   618 // --------------------------------------------------------------------------
       
   619 // CCCAppMyCardContainer::FocusedContactIndex
       
   620 // --------------------------------------------------------------------------
       
   621 //
       
   622 TInt CCCAppMyCardContainer::FocusedContactIndex() const
       
   623 	{
       
   624     return KErrNotSupported;
       
   625 	}
       
   626 
       
   627 // --------------------------------------------------------------------------
       
   628 // CCCAppMyCardContainer::SetFocusedContactIndexL
       
   629 // --------------------------------------------------------------------------
       
   630 //
       
   631 void CCCAppMyCardContainer::SetFocusedContactIndexL(TInt /*aIndex*/)
       
   632 	{
       
   633     // Do nothing
       
   634 	}
       
   635 
       
   636 // --------------------------------------------------------------------------
       
   637 // CCCAppMyCardContainer::NumberOfContactFields
       
   638 // --------------------------------------------------------------------------
       
   639 //
       
   640 TInt CCCAppMyCardContainer::NumberOfContactFields() const
       
   641 	{
       
   642     TInt cnt = KErrNotSupported;
       
   643     cnt =  iPlugin.MyCard().StoreContact().Fields().FieldCount();
       
   644     return cnt;
       
   645 	}
       
   646 
       
   647 // --------------------------------------------------------------------------
       
   648 // CCCAppMyCardContainer::FocusedField
       
   649 // --------------------------------------------------------------------------
       
   650 //
       
   651 const MVPbkBaseContactField* CCCAppMyCardContainer::FocusedField() const
       
   652 	{
       
   653 	TInt index = FocusedFieldIndex();
       
   654 	if( index != KErrNotFound )
       
   655 		{
       
   656 		return &iPlugin.MyCard().StoreContact().Fields().FieldAt(index);
       
   657 		}
       
   658     return NULL;
       
   659 	}
       
   660 
       
   661 // --------------------------------------------------------------------------
       
   662 // CCCAppMyCardContainer::FocusedFieldIndex
       
   663 // --------------------------------------------------------------------------
       
   664 //
       
   665 TInt CCCAppMyCardContainer::FocusedFieldIndex() const
       
   666 	{
       
   667 	if( iModel )
       
   668 		{
       
   669 		return iModel->FieldIndex( iListBox->CurrentItemIndex() );
       
   670 		}
       
   671 	return KErrNotFound;
       
   672 	}
       
   673 
       
   674 // --------------------------------------------------------------------------
       
   675 // CCCAppMyCardContainer::SetFocusedFieldIndex
       
   676 // --------------------------------------------------------------------------
       
   677 //
       
   678 void CCCAppMyCardContainer::SetFocusedFieldIndex( TInt /*aIndex*/ )
       
   679 	{
       
   680 	// do nothing
       
   681 	}
       
   682 
       
   683 // --------------------------------------------------------------------------
       
   684 // CCCAppMyCardContainer::ContactsMarked
       
   685 // --------------------------------------------------------------------------
       
   686 //
       
   687 TBool CCCAppMyCardContainer::ContactsMarked() const
       
   688 	{
       
   689     // This control does not support contacts marking
       
   690     return EFalse;
       
   691 	}
       
   692 
       
   693 // --------------------------------------------------------------------------
       
   694 // CCCAppMyCardContainer::SelectedContactsL
       
   695 // --------------------------------------------------------------------------
       
   696 //
       
   697 MVPbkContactLinkArray* CCCAppMyCardContainer::SelectedContactsL() const
       
   698 	{
       
   699     // No selection support in contact info control
       
   700     return NULL;
       
   701 	}
       
   702 
       
   703 
       
   704 
       
   705 // --------------------------------------------------------------------------
       
   706 // CCCAppMyCardContainer::SelectedContactsOrFocusedContactL
       
   707 // --------------------------------------------------------------------------
       
   708 //
       
   709 MVPbkContactLinkArray*
       
   710 CCCAppMyCardContainer::SelectedContactsOrFocusedContactL() const
       
   711 	{
       
   712     CVPbkContactLinkArray* array = CVPbkContactLinkArray::NewLC();
       
   713     const MVPbkBaseContact* focusedContact = FocusedContactL();
       
   714 
       
   715     if( focusedContact )
       
   716     	{
       
   717         MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   718         CleanupStack::Pop(); // link
       
   719         array->AppendL(link);
       
   720     	}
       
   721     CleanupStack::Pop(array);
       
   722     return array;
       
   723 	}
       
   724 
       
   725 // --------------------------------------------------------------------------
       
   726 // CCCAppMyCardContainer::SelectedContactsIteratorL
       
   727 // --------------------------------------------------------------------------
       
   728 //
       
   729 MPbk2ContactLinkIterator*
       
   730 CCCAppMyCardContainer::SelectedContactsIteratorL() const
       
   731 	{
       
   732     // No selection support in contact info control
       
   733     return NULL;
       
   734 	}
       
   735 
       
   736 // --------------------------------------------------------------------------
       
   737 // CCCAppMyCardContainer::SelectedContactStoresL
       
   738 // --------------------------------------------------------------------------
       
   739 //
       
   740 CArrayPtr<MVPbkContactStore>*
       
   741 CCCAppMyCardContainer::SelectedContactStoresL() const
       
   742 	{
       
   743     // This is not a contact store control
       
   744     return NULL;
       
   745 	}
       
   746 
       
   747 // --------------------------------------------------------------------------
       
   748 // CCCAppMyCardContainer::ClearMarks
       
   749 // --------------------------------------------------------------------------
       
   750 //
       
   751 
       
   752 void CCCAppMyCardContainer::ClearMarks()
       
   753 	{
       
   754 	// Do nothing
       
   755 	}
       
   756 
       
   757 // --------------------------------------------------------------------------
       
   758 // CCCAppMyCardContainer::SetSelectedContactL
       
   759 // --------------------------------------------------------------------------
       
   760 //
       
   761 void CCCAppMyCardContainer::SetSelectedContactL(
       
   762     TInt /*aIndex*/,
       
   763     TBool /*aSelected*/)
       
   764 	{
       
   765     // Not supported in Contact Info
       
   766 	}
       
   767 
       
   768 // --------------------------------------------------------------------------
       
   769 // CCCAppMyCardContainer::SetSelectedContactL
       
   770 // --------------------------------------------------------------------------
       
   771 //
       
   772 void CCCAppMyCardContainer::SetSelectedContactL(
       
   773     const MVPbkContactBookmark& /*aContactBookmark*/,
       
   774     TBool /*aSelected*/)
       
   775 	{
       
   776     // Not supported
       
   777 	}
       
   778 
       
   779 // --------------------------------------------------------------------------
       
   780 // CCCAppMyCardContainer::SetSelectedContactL
       
   781 // --------------------------------------------------------------------------
       
   782 //
       
   783 void CCCAppMyCardContainer::SetSelectedContactL(
       
   784     const MVPbkContactLink& /*aContactLink*/,
       
   785     TBool /*aSelected*/)
       
   786 	{
       
   787     // Not supported
       
   788 	}
       
   789 
       
   790 
       
   791 
       
   792 // --------------------------------------------------------------------------
       
   793 // CCCAppMyCardContainer::DynInitMenuPaneL
       
   794 // --------------------------------------------------------------------------
       
   795 //
       
   796 void CCCAppMyCardContainer::DynInitMenuPaneL(
       
   797     TInt /*aResourceId*/,
       
   798     CEikMenuPane* /*aMenuPane*/) const
       
   799     {
       
   800     // Nothing to do
       
   801     }
       
   802 
       
   803 // --------------------------------------------------------------------------
       
   804 // CCCAppMyCardContainer::ProcessCommandL
       
   805 // --------------------------------------------------------------------------
       
   806 //
       
   807 void CCCAppMyCardContainer::ProcessCommandL(TInt /*aCommandId*/) const
       
   808 	{
       
   809     // Nothing to do
       
   810 	}
       
   811 
       
   812 // --------------------------------------------------------------------------
       
   813 // CCCAppMyCardContainer::UpdateAfterCommandExecution
       
   814 // --------------------------------------------------------------------------
       
   815 //
       
   816 void CCCAppMyCardContainer::UpdateAfterCommandExecution()
       
   817 	{
       
   818     if (iCommand)
       
   819     	{
       
   820         /// Reset command pointer, command has completed
       
   821         iCommand->ResetUiControl(*this);
       
   822         iCommand = NULL;
       
   823     	}
       
   824 	}
       
   825 
       
   826 // --------------------------------------------------------------------------
       
   827 // CCCAppMyCardContainer::GetMenuFilteringFlagsL
       
   828 // --------------------------------------------------------------------------
       
   829 //
       
   830 TInt CCCAppMyCardContainer::GetMenuFilteringFlagsL() const
       
   831 	{
       
   832     const TInt fieldCount =
       
   833 		 iPlugin.MyCard().StoreContact().Fields().FieldCount();
       
   834     // If negative will leave
       
   835     User::LeaveIfError( fieldCount );
       
   836 
       
   837     TInt ret = KPbk2MenuFilteringFlagsNone;
       
   838     if( fieldCount > KNoContacts )
       
   839     	{
       
   840         ret |= KPbk2ListContainsItems;
       
   841     	}
       
   842     return ret;
       
   843 	}
       
   844 
       
   845 // --------------------------------------------------------------------------
       
   846 // CCCAppMyCardContainer::ControlStateL
       
   847 // --------------------------------------------------------------------------
       
   848 //
       
   849 CPbk2ViewState* CCCAppMyCardContainer::ControlStateL() const
       
   850 	{
       
   851     return NULL;
       
   852 	}
       
   853 
       
   854 // --------------------------------------------------------------------------
       
   855 // CCCAppMyCardContainer::RestoreControlStateL
       
   856 // --------------------------------------------------------------------------
       
   857 //
       
   858 void CCCAppMyCardContainer::RestoreControlStateL(
       
   859     CPbk2ViewState* /*aState*/)
       
   860 	{
       
   861     // Do nothing
       
   862 	}
       
   863 
       
   864 // --------------------------------------------------------------------------
       
   865 // CCCAppMyCardContainer::FindTextL
       
   866 // --------------------------------------------------------------------------
       
   867 //
       
   868 const TDesC& CCCAppMyCardContainer::FindTextL()
       
   869 	{
       
   870     // No find box in this control
       
   871     return KNullDesC;
       
   872 	}
       
   873 
       
   874 
       
   875 
       
   876 // --------------------------------------------------------------------------
       
   877 // CCCAppMyCardContainer::ResetFindL
       
   878 // --------------------------------------------------------------------------
       
   879 //
       
   880 void CCCAppMyCardContainer::ResetFindL()
       
   881 	{
       
   882     // Do nothing
       
   883 	}
       
   884 
       
   885 // --------------------------------------------------------------------------
       
   886 // CCCAppMyCardContainer::ShowThumbnail
       
   887 // --------------------------------------------------------------------------
       
   888 //
       
   889 void CCCAppMyCardContainer::ShowThumbnail()
       
   890 	{
       
   891     // Do nothing
       
   892 	}
       
   893 
       
   894 // --------------------------------------------------------------------------
       
   895 // CCCAppMyCardContainer::HideThumbnail
       
   896 // --------------------------------------------------------------------------
       
   897 //
       
   898 void CCCAppMyCardContainer::HideThumbnail()
       
   899 	{
       
   900     // Do nothing
       
   901 	}
       
   902 
       
   903 
       
   904 // --------------------------------------------------------------------------
       
   905 // CCCAppMyCardContainer::SetBlank
       
   906 // --------------------------------------------------------------------------
       
   907 //
       
   908 void CCCAppMyCardContainer::SetBlank( TBool /*aBlank*/ )
       
   909 	{
       
   910     // This control does not support blanking
       
   911 	}
       
   912 
       
   913 
       
   914 // --------------------------------------------------------------------------
       
   915 // CCCAppMyCardContainer::RegisterCommand
       
   916 // --------------------------------------------------------------------------
       
   917 //
       
   918 void CCCAppMyCardContainer::RegisterCommand( MPbk2Command* aCommand )
       
   919 	{
       
   920     iCommand = aCommand;
       
   921 	}
       
   922 
       
   923 
       
   924 // --------------------------------------------------------------------------
       
   925 // CCCAppMyCardContainer::SetTextL
       
   926 // --------------------------------------------------------------------------
       
   927 //
       
   928 void CCCAppMyCardContainer::SetTextL( const TDesC& /*aText*/ )
       
   929 	{
       
   930     // Do nothing
       
   931 	}
       
   932 
       
   933 // --------------------------------------------------------------------------
       
   934 // CCCAppMyCardContainer::ContactUiControlExtension
       
   935 // --------------------------------------------------------------------------
       
   936 //
       
   937 TAny* CCCAppMyCardContainer::ContactUiControlExtension( TUid /*aExtensionUid*/ )
       
   938 	{
       
   939     return NULL;
       
   940 	}
       
   941 
       
   942 //-----------------------------------------------------------------------------
       
   943 // void CCCAppMyCardContainer::StatusClickedL()
       
   944 //-----------------------------------------------------------------------------
       
   945 //
       
   946 void CCCAppMyCardContainer::StatusClickedL()
       
   947 	{
       
   948     if ( iViewLauncher )
       
   949 		{
       
   950         iViewLauncher->LaunchViewL( MCCAViewLauncher::EMyCardView );
       
   951 		}		
       
   952 	}
       
   953 
       
   954 //------------------------------------------------------------------------------
       
   955 // void CCCAppMyCardContainer::SetNameForHeaderContorl()
       
   956 //------------------------------------------------------------------------------
       
   957 //
       
   958 void CCCAppMyCardContainer::SetNameForHeaderControlL()
       
   959 	{
       
   960     // Set own contact name
       
   961     CCCAppMyCard& mycard = iPlugin.MyCard();
       
   962     // Get the myCard store and the field set 
       
   963     MVPbkStoreContact& storeContact = mycard.StoreContact();
       
   964     MVPbkStoreContactFieldCollection& fields = storeContact.Fields();
       
   965                     
       
   966     TInt fieldCount = fields.FieldCount();                           
       
   967     
       
   968     TPtrC firstName( KNullDesC );
       
   969     TPtrC lastName( KNullDesC );
       
   970     
       
   971     // Check all the fields and store first and last name
       
   972     for ( TInt i = 0; i < fieldCount;  ++i )
       
   973     	{
       
   974 		MVPbkStoreContactField& field = fields.FieldAt( i );	
       
   975 		const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
       
   976 		
       
   977 		if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_FIRSTNAME )
       
   978 			{
       
   979 			MVPbkContactFieldData& contactField = field.FieldData();            
       
   980 			firstName.Set( MVPbkContactFieldTextData::Cast(contactField).Text());
       
   981 			}
       
   982 		
       
   983 		if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_LASTNAME )
       
   984 			{
       
   985 			MVPbkContactFieldData& contactField = field.FieldData();			            
       
   986 			lastName.Set( MVPbkContactFieldTextData::Cast(contactField).Text());
       
   987 			}		
       
   988     	}
       
   989     
       
   990     switch ( iNameOrder )
       
   991         {
       
   992         case KPbk2UiSpecNameOrderFirstNameLastName:
       
   993             {
       
   994             iHeaderCtrl->SetLabel1TextL( firstName );
       
   995             iHeaderCtrl->SetLabel2TextL( lastName );
       
   996             break;
       
   997             }
       
   998         case KPbk2UiSpecNameOrderLastNameFirstName: // FALL THROUGH
       
   999         default:
       
  1000             {
       
  1001             iHeaderCtrl->SetLabel2TextL( firstName );
       
  1002             iHeaderCtrl->SetLabel1TextL( lastName );
       
  1003             break;
       
  1004             }
       
  1005         }
       
  1006     
       
  1007 	}
       
  1008 
       
  1009 //------------------------------------------------------------------------------
       
  1010 // void CCCAppMyCardContainer::MyCardHeaderControlClickL()
       
  1011 //------------------------------------------------------------------------------
       
  1012 //
       
  1013 void CCCAppMyCardContainer::MyCardHeaderControlClickL( TPoint aPos )
       
  1014 {
       
  1015     if ( !iImageSelectionPopup )
       
  1016         {
       
  1017         iImageSelectionPopup = CAknStylusPopUpMenu::NewL( &iPlugin, aPos );
       
  1018         TInt resourceReaderId = R_MYCARD_CONTACT_IMAGE_STYLUS_MENU; 
       
  1019         TResourceReader reader;
       
  1020         iCoeEnv->CreateResourceReaderLC( reader , resourceReaderId );
       
  1021         iImageSelectionPopup->ConstructFromResourceL( reader );
       
  1022         CleanupStack::PopAndDestroy(); // reader
       
  1023         }
       
  1024     
       
  1025     // MyCard image has been set. Dim optiosn menu items accordingly
       
  1026     if( iMyCardImageSet )
       
  1027         {
       
  1028         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusViewImageCmd, EFalse);
       
  1029         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusChangeImageCmd, EFalse);
       
  1030         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusRemoveImageCmd, EFalse);
       
  1031         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusAddImageCmd, ETrue);
       
  1032         }
       
  1033     // MyCard image has not been set
       
  1034     else
       
  1035         {
       
  1036         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusViewImageCmd, ETrue);
       
  1037         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusChangeImageCmd, ETrue);
       
  1038         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusRemoveImageCmd, ETrue);
       
  1039         iImageSelectionPopup->SetItemDimmed(ECCAppMyCardCmdStylusAddImageCmd, EFalse);
       
  1040         } 
       
  1041           
       
  1042     PosToScreenCoordinates( this, aPos );
       
  1043    
       
  1044     iImageSelectionPopup->SetPosition( aPos );
       
  1045     iImageSelectionPopup->ShowMenu();   
       
  1046 }
       
  1047 
       
  1048 // ---------------------------------------------------------------------------
       
  1049 // PosToScreenCoordinates
       
  1050 // ---------------------------------------------------------------------------
       
  1051 //
       
  1052 void CCCAppMyCardContainer::PosToScreenCoordinates( 
       
  1053         CCoeControl* aControl, TPoint& aPos )
       
  1054      {
       
  1055      TPoint leftUpperPos = aControl->PositionRelativeToScreen();
       
  1056      aPos += leftUpperPos;
       
  1057      }
       
  1058 
       
  1059 // End of File