phonebookui/Phonebook2/ccapplication/ccamycardplugin/src/ccappmycardheadercontrol.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2009-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:  Header UI control of the mycard plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ccappmycardheadercontrol.h"
       
    20 #include "ccappmycardcommon.h"
       
    21 #include <eikimage.h>
       
    22 #include <eiklabel.h>
       
    23 #include <AknIconUtils.h>
       
    24 #include <AknUtils.h>
       
    25 #include <avkon.mbg>
       
    26 #include <aknstyluspopupmenu.h>
       
    27 #include <ccappmycardpluginrsc.rsg>
       
    28 #include <barsread.h>
       
    29 #include <touchfeedback.h>
       
    30 #include "ccappmycardplugin.h"
       
    31 #include <aknlayoutscalable_apps.cdl.h>
       
    32 #include "spbcontentprovider.h"
       
    33 #include <CPbk2ApplicationServices.h>
       
    34 #include <featmgr.h>
       
    35 #include <AknIconUtils.h>
       
    36 #include "ccappstatuscontrol.h"
       
    37 #include <phonebook2ece.mbg>
       
    38 #include <gulicon.h>
       
    39 #include <layoutmetadata.cdl.h>
       
    40 #include <StringLoader.h>
       
    41 #include <AknsUtils.h>
       
    42 
       
    43 namespace {
       
    44 /// Amount of child UI components
       
    45 const TInt KControlCount = 4;
       
    46 _LIT( KMyCardIconDefaultFileName, "\\resource\\apps\\phonebook2ece.mif" );
       
    47 }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CCCAppMyCardHeaderControl::NewL
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CCCAppMyCardHeaderControl* CCCAppMyCardHeaderControl::NewL( 
       
    54         MCCAStatusControlObserver& aObserver )
       
    55     {
       
    56     CCCAppMyCardHeaderControl* self = new(ELeave) CCCAppMyCardHeaderControl();
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL(aObserver);
       
    59     CleanupStack::Pop(self);
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CCCAppMyCardHeaderControl::CCCAppMyCardHeaderControl
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CCCAppMyCardHeaderControl::CCCAppMyCardHeaderControl()
       
    68     {
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CCCAppMyCardHeaderControl::ConstructL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CCCAppMyCardHeaderControl::ConstructL( 
       
    76         MCCAStatusControlObserver& aObserver )
       
    77     {
       
    78     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardHeaderControl::ConstructL()"));    
       
    79     
       
    80     iAppServices = CPbk2ApplicationServices::InstanceL();
       
    81     CVPbkContactManager& contactManager = iAppServices->ContactManager();
       
    82 
       
    83     FeatureManager::InitializeLibL();
       
    84     const TBool isFeatureIdFfContactsSocial =
       
    85             FeatureManager::FeatureSupported( KFeatureIdFfContactsSocial );
       
    86     FeatureManager::UnInitializeLib();
       
    87 
       
    88     if( isFeatureIdFfContactsSocial )
       
    89         {
       
    90         iProvider = CSpbContentProvider::NewL( contactManager, 
       
    91             iAppServices->StoreManager(),
       
    92             CSpbContentProvider::EStatusMessage | CSpbContentProvider::EServiceIcon );
       
    93         iStatusControl = CCCAppStatusControl::NewL( *iProvider, aObserver, CCCAppStatusControl::EMyCardContact );
       
    94         iStatusControl->SetContainerWindowL( *this );
       
    95         iStatusControl->MakeVisible( EFalse );
       
    96         
       
    97         CFbsBitmap* bmp = NULL;
       
    98         CFbsBitmap* bmpMask = NULL;
       
    99                       
       
   100         AknsUtils::CreateIconL(
       
   101             AknsUtils::SkinInstance(),
       
   102             KAknsIIDQgnPropSocialCommunities,
       
   103             bmp,
       
   104             bmpMask,
       
   105             KMyCardIconDefaultFileName,
       
   106             EMbmPhonebook2eceQgn_prop_social_communities,
       
   107             EMbmPhonebook2eceQgn_prop_social_communities_mask );     
       
   108                 
       
   109         CGulIcon* guiIcon = CGulIcon::NewL( bmp, bmpMask );
       
   110         iStatusControl->SetDefaultStatusIconL( guiIcon );
       
   111         HBufC* defaultText = StringLoader::LoadL( R_QTN_CCA_SOCIAL_NETWORKS );                                            
       
   112         iStatusControl->SetDefaultStatusTextL( defaultText );        
       
   113         }
       
   114     
       
   115     
       
   116     // Create portrait image
       
   117     iPortraitImage = new(ELeave) CEikImage;
       
   118     iPortraitImage->SetAlignment(EHCenterVCenter);
       
   119     iPortraitImage->SetBrushStyle( CGraphicsContext::ENullBrush ); // transparent
       
   120     iPortraitImage->SetPictureOwnedExternally( ETrue );
       
   121       
       
   122     // Create my name label
       
   123     iLabel1 = new(ELeave) CEikLabel;
       
   124     iLabel1->SetAlignment(EHLeftVCenter);
       
   125     iLabel1->SetTextL( KNullDesC ); // CEikLabel will panic without text
       
   126     iLabel2 = new(ELeave) CEikLabel;
       
   127     iLabel2->SetAlignment(EHLeftVCenter);
       
   128     iLabel2->SetTextL( KNullDesC );
       
   129       
       
   130     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardHeaderControl::ConstructL()"));    
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CCCAppMyCardHeaderControl::~CCCAppMyCardHeaderControl
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CCCAppMyCardHeaderControl::~CCCAppMyCardHeaderControl()
       
   138     {
       
   139     delete iStatusControl;
       
   140     delete iProvider;
       
   141     Release( iAppServices );    
       
   142     delete iPortraitImage;
       
   143     delete iLabel1;
       
   144     delete iLabel2;
       
   145     delete iPortraitBitmap;
       
   146     delete iPortraitMask;
       
   147 	iObserverArray.Reset();
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CCCAppMyCardHeaderControl::CountComponentControls
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TInt CCCAppMyCardHeaderControl::CountComponentControls() const
       
   155     {
       
   156     if(iStatusControl)
       
   157         {
       
   158         return KControlCount;
       
   159         }
       
   160     else
       
   161         {
       
   162         return (KControlCount - 1);
       
   163         }
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CCCAppMyCardHeaderControl::ComponentControl
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 CCoeControl* CCCAppMyCardHeaderControl::ComponentControl( TInt aIndex ) const
       
   171     {
       
   172     switch( aIndex )
       
   173         {
       
   174         case 0:
       
   175             {
       
   176             return iPortraitImage;
       
   177             }
       
   178         case 1:
       
   179         	{
       
   180         	return iLabel1;
       
   181         	}
       
   182         case 2:
       
   183             {
       
   184             return iLabel2;
       
   185             }
       
   186         case 3:
       
   187             {
       
   188             return iStatusControl;
       
   189             }
       
   190         }
       
   191     return NULL;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CCCAppMyCardHeaderControl::SizeChanged
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CCCAppMyCardHeaderControl::SizeChanged()
       
   199     {
       
   200     const TRect rect(Rect()); 
       
   201     /**
       
   202      * Option0, Parent Variety :1 (w button, lsc)
       
   203      * Option2, Parent Variety :3 (w/o button, lsc)
       
   204      * Option0, Parent Variety :0 (w button, prt)
       
   205      * Option1, Parent Variety :2 (w/o button, prt)
       
   206      */
       
   207     
       
   208     const TBool isLandscape( Layout_Meta_Data::IsLandscapeOrientation() );
       
   209     
       
   210     // (w/o button)
       
   211     TInt option( isLandscape ? 2 : 1 );
       
   212     if( iStatusControl && iStatusControl->IsVisible() )
       
   213         {
       
   214         // (w button)
       
   215         if( isLandscape )
       
   216             {
       
   217             option = 0;
       
   218             }
       
   219         else
       
   220             {
       
   221             option = 0;
       
   222             }
       
   223         
       
   224         TAknWindowComponentLayout statusPaneLayout(
       
   225             AknLayoutScalable_Apps::phob2_cc_button_pane( option ) );
       
   226         
       
   227         TAknLayoutRect statusPaneLayoutRect;
       
   228         statusPaneLayoutRect.LayoutRect( rect, statusPaneLayout.LayoutLine() );
       
   229         TRect statusPaneRect( statusPaneLayoutRect.Rect() );
       
   230         iStatusControl->SetRect( statusPaneRect );
       
   231         }
       
   232     
       
   233     
       
   234     // image
       
   235     TAknWindowComponentLayout imageLayout( 
       
   236         AknLayoutScalable_Apps::phob2_cc_data_pane_g1( option ) );    
       
   237     
       
   238     TAknLayoutRect imageLayoutRect;
       
   239     imageLayoutRect.LayoutRect( rect, imageLayout.LayoutLine() );
       
   240     TRect imageRect( imageLayoutRect.Rect() );
       
   241     
       
   242     iPortraitImage->SetRect( imageRect );
       
   243     iPortraitImageSize = imageRect.Size();
       
   244 
       
   245     
       
   246     // label 1
       
   247     AknLayoutUtils::LayoutLabel( 
       
   248             iLabel1, 
       
   249             rect, 
       
   250             AknLayoutScalable_Apps::phob2_cc_data_pane_t1( option ) );
       
   251     
       
   252     // label 2
       
   253     AknLayoutUtils::LayoutLabel( 
       
   254             iLabel2, 
       
   255             rect, 
       
   256             AknLayoutScalable_Apps::phob2_cc_data_pane_t2( option ) );
       
   257 
       
   258     TRgb color;
       
   259     AknsUtils::GetCachedColor( 
       
   260             AknsUtils::SkinInstance(), 
       
   261             color, 
       
   262             KAknsIIDQsnTextColors, 
       
   263             EAknsCIQsnTextColorsCG6 );
       
   264     
       
   265     TRAP_IGNORE(
       
   266         {
       
   267         iLabel1->OverrideColorL( EColorLabelText, color );        
       
   268         iLabel2->OverrideColorL( EColorLabelText, color );
       
   269         } );
       
   270     
       
   271     
       
   272     // resize images for new resolution
       
   273     if( iPortraitBitmap ) 
       
   274         {
       
   275         AknIconUtils::SetSize( iPortraitBitmap, 
       
   276                 iPortraitImageSize, EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   277         }
       
   278     if( iPortraitMask )
       
   279         {
       
   280         AknIconUtils::SetSize( iPortraitMask, 
       
   281             iPortraitImageSize, EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   282         }
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // CCCAppMyCardHeaderControl::HandlePointerEventL
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CCCAppMyCardHeaderControl::HandlePointerEventL(
       
   290         const TPointerEvent& aPointerEvent)
       
   291     {
       
   292     CCoeControl::HandlePointerEventL( aPointerEvent );
       
   293     switch(aPointerEvent.iType)
       
   294         {
       
   295         case TPointerEvent::EButton1Down:
       
   296  
       
   297             // Image selection popup. If image is not set, then don't report
       
   298             // touch events
       
   299         	if ( iPortraitImage->Bitmap() &&
       
   300         	     iPortraitImage->Rect().Contains(aPointerEvent.iPosition) )
       
   301         		{
       
   302 				// Show the feedback
       
   303 				MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   304 				if ( feedback )
       
   305 					{
       
   306 					feedback->InstantFeedback( ETouchFeedbackBasic );
       
   307 					}
       
   308 				// check the pointer position so that menu can be opened
       
   309 				// to the correct place
       
   310 				NotifyObservers( aPointerEvent.iPosition );
       
   311         		}     	
       
   312             break;    
       
   313         default:
       
   314             break;
       
   315         }
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CCCAppMyCardHeaderControl::SetContainerWindowL
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CCCAppMyCardHeaderControl::SetContainerWindowL( 
       
   323     const CCoeControl& aContainer )
       
   324     {
       
   325     CCoeControl::SetContainerWindowL( aContainer );
       
   326 
       
   327     // Assign window for child controls too
       
   328     TInt childCount = CountComponentControls();
       
   329     for( TInt i = 0; i < childCount; ++i )
       
   330         {
       
   331         ComponentControl( i )->SetContainerWindowL( *this );
       
   332         }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CCCAppMyCardHeaderControl::SetPortraitIcon
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CCCAppMyCardHeaderControl::SetPortraitIcon( 
       
   340     CFbsBitmap* aImage, CFbsBitmap* aMask )
       
   341     {
       
   342     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardHeaderControl::SetPortraitIcon()"));    
       
   343 
       
   344     delete iPortraitBitmap;
       
   345     iPortraitBitmap = aImage;
       
   346 
       
   347     delete iPortraitMask;
       
   348     iPortraitMask = aMask;
       
   349            
       
   350     // resize and assign
       
   351     if( iPortraitImageSize != TSize() )
       
   352         {
       
   353         AknIconUtils::SetSize( 
       
   354             iPortraitBitmap, 
       
   355             iPortraitImageSize, 
       
   356             EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   357 
       
   358         AknIconUtils::SetSize( 
       
   359             iPortraitMask, 
       
   360             iPortraitImageSize, 
       
   361             EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   362         }
       
   363     
       
   364     iPortraitImage->SetPicture( iPortraitBitmap, iPortraitMask );
       
   365     iPortraitImage->DrawDeferred();
       
   366 
       
   367     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardHeaderControl::SetPortraitIcon()"));    
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // CCCAppMyCardHeaderControl::SetPortraitBitmapL
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CCCAppMyCardHeaderControl::SetPortraitBitmapL( CFbsBitmap* aImage )
       
   375     {
       
   376     CCA_DP(KMyCardLogFile, CCA_L("->CCCAppMyCardHeaderControl::SetPortraitBitmapL()"));    
       
   377 
       
   378     // create scalable image
       
   379     aImage = AknIconUtils::CreateIconL( aImage );
       
   380     delete iPortraitBitmap;
       
   381     iPortraitBitmap = aImage;
       
   382     
       
   383     delete iPortraitMask;
       
   384     iPortraitMask = NULL;
       
   385     
       
   386     // resize and assign
       
   387     if( iPortraitImageSize != TSize() )
       
   388         {
       
   389         AknIconUtils::SetSize( 
       
   390             iPortraitBitmap, 
       
   391             iPortraitImageSize, 
       
   392             EAspectRatioPreservedAndUnusedSpaceRemoved );
       
   393 
       
   394         }
       
   395     
       
   396     iPortraitImage->SetPicture( iPortraitBitmap );
       
   397     iPortraitImage->DrawDeferred();
       
   398 
       
   399     CCA_DP(KMyCardLogFile, CCA_L("<-CCCAppMyCardHeaderControl::SetPortraitBitmapL()"));    
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CCCAppMyCardHeaderControl::SetNameTextL
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CCCAppMyCardHeaderControl::SetLabel1TextL( const TDesC& aTxt )
       
   407     {
       
   408     iLabel1->SetTextL( aTxt );
       
   409     iLabel1->CropText();
       
   410     iLabel1->DrawDeferred();
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // CCCAppMyCardHeaderControl::SetLabel2TextL
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CCCAppMyCardHeaderControl::SetLabel2TextL( const TDesC& aTxt )
       
   418     {
       
   419     iLabel2->SetTextL( aTxt );
       
   420     iLabel2->CropText();
       
   421     iLabel2->DrawDeferred();
       
   422     }
       
   423 
       
   424  // ---------------------------------------------------------------------------
       
   425  // CCCAppMyCardHeaderControl::AddObserverL
       
   426  // ---------------------------------------------------------------------------
       
   427  //
       
   428  void CCCAppMyCardHeaderControl::AddObserverL( 
       
   429          MMyCardHeaderControlObserver* aObserver )
       
   430      {
       
   431      if( aObserver )
       
   432          {
       
   433 		 iObserverArray.AppendL( aObserver );
       
   434          }
       
   435      }
       
   436  
       
   437  // ---------------------------------------------------------------------------
       
   438  // CCCAppMyCardHeaderControl::NotifyObservers
       
   439  // ---------------------------------------------------------------------------
       
   440  //
       
   441  void CCCAppMyCardHeaderControl::NotifyObservers( TPoint aPoint)
       
   442 	 {
       
   443 	 const TInt count(iObserverArray.Count());
       
   444 	 for(TInt i = 0 ; i < count ; ++i)
       
   445 		{
       
   446 		TRAP_IGNORE( iObserverArray[i]->MyCardHeaderControlClickL( aPoint ) );
       
   447 		}
       
   448 	 }
       
   449 // End of file