uiservicetab/vimpstdetailsviewplugin/src/cvimpstdetailsheadercontrol.cpp
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     1 /*
       
     2 * Copyright (c) 2008-2008 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 the header part control(s) of the details view layout
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cvimpstdetailsheadercontrol.h"
       
    20 
       
    21 #include "cvimpstdetailsimagedecoder.h"
       
    22 #include "mvimpstdetailspresencehandler.h"
       
    23 #include "cvimpstdetailsviewbrandhandler.h"
       
    24 #include <vimpstui.mbg>
       
    25 #include <conversations.mbg>
       
    26 #include <eikimage.h> 
       
    27 #include <eiklabel.h> 
       
    28 #include <AknUtils.h>
       
    29 #include <layoutmetadata.cdl.h>
       
    30 #include <applayout.cdl.h> //cdl
       
    31 #include <aknlayoutscalable_apps.cdl.h>
       
    32 #include <AknsUtils.h>
       
    33 
       
    34 // virtual phonebook
       
    35 #include <MVPbkStoreContactField.h>
       
    36 #include <MVPbkContactFieldData.h>
       
    37 #include <MVPbkFieldType.h>
       
    38 #include <MVPbkContactFieldBinaryData.h>
       
    39 #include <VPbkEng.rsg>
       
    40 #include <MVPbkStoreContact.h>
       
    41 
       
    42 #include "uiservicetabtracer.h"
       
    43 // constants declaration
       
    44 const TInt KLabelLineCount = 3;
       
    45 
       
    46 // Size of thumbnail images stored to contacts
       
    47 #define KPbkPersonalImageSize TSize(80,96)
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // NewL, two-phase construction
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CVIMPSTDetailsHeaderControl* CVIMPSTDetailsHeaderControl::NewL(CVIMPSTDetailsViewBrandHandler& aBrandHandler,
       
    54 												MVIMPSTDetailsPresenceHandler& aPresenceHandler)
       
    55     {
       
    56     CVIMPSTDetailsHeaderControl* self= new (ELeave) CVIMPSTDetailsHeaderControl(aBrandHandler, aPresenceHandler );
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop(self);
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // C++ (first phase) constructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CVIMPSTDetailsHeaderControl::CVIMPSTDetailsHeaderControl(CVIMPSTDetailsViewBrandHandler& aBrandHandler, 
       
    68 							MVIMPSTDetailsPresenceHandler& aPresenceHandler)
       
    69    : iBrandHandler( aBrandHandler),
       
    70    iPresenceHandler( aPresenceHandler )
       
    71     {
       
    72     // No implementation required
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // ConstructL, second phase constructor
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CVIMPSTDetailsHeaderControl::ConstructL()
       
    80 	{ 
       
    81 	TRACER_AUTO;
       
    82 	// Create the header image
       
    83 	iImage = new (ELeave) CEikImage();
       
    84 	iImage->SetPictureOwnedExternally(ETrue); //EHLeftVCenter
       
    85 	iImage->SetAlignment(EHCenterVCenter);
       
    86 	// Create the header labels
       
    87     for (TInt i=0; i < KLabelLineCount; i++)
       
    88         {
       
    89         CEikLabel* label = new(ELeave) CEikLabel;
       
    90         CleanupStack::PushL(label);
       
    91         label->SetTextL(KNullDesC());
       
    92         label->SetAlignment(EHLeftVCenter);// EHCenterVCenter, EHLeftVCenter        
       
    93         iLabels.AppendL(label);
       
    94         CleanupStack::Pop(label);
       
    95         }
       
    96     iContactImageSize = KPbkPersonalImageSize;
       
    97    	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Destructor
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CVIMPSTDetailsHeaderControl::~CVIMPSTDetailsHeaderControl()
       
   104     {
       
   105     iLabels.ResetAndDestroy();
       
   106   
       
   107     if (iImageDecoder)
       
   108         {
       
   109         if (iImageDecoder->IsActive())
       
   110             {
       
   111             iImageDecoder->Cancel();
       
   112             }
       
   113         delete iImageDecoder;
       
   114         iImageDecoder = NULL;
       
   115         }
       
   116     delete iHeaderField;
       
   117        
       
   118     if (iImage)
       
   119         {
       
   120         delete iImage;
       
   121         iImage = NULL;
       
   122         }
       
   123   
       
   124     if (iBitmap)
       
   125         {
       
   126         delete iBitmap;
       
   127         iBitmap = NULL;
       
   128         }
       
   129     if (iMask)
       
   130         {
       
   131         delete iMask;
       
   132         iMask = NULL;
       
   133         }
       
   134      }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // From CCoeControl, returns the number of child controls to the framework
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 TInt CVIMPSTDetailsHeaderControl::CountComponentControls() const
       
   142     {
       
   143     // image control + Label Count
       
   144     return 1 + iLabels.Count();
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // From CCoeControl, returns the child controls to the framework by index
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 CCoeControl* CVIMPSTDetailsHeaderControl::ComponentControl(TInt aIndex)  const
       
   152     {
       
   153     if (aIndex == 0)
       
   154         {
       
   155         return iImage;
       
   156         }
       
   157     else if (aIndex - 1 < iLabels.Count())
       
   158         {
       
   159         return iLabels[aIndex-1];
       
   160         }
       
   161     else
       
   162         {
       
   163         return NULL;
       
   164         }
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // From CCoeControl, called when the control's size changes, handles portrait-landscape switch
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CVIMPSTDetailsHeaderControl::SizeChanged()
       
   172     {
       
   173     TInt isLandscape = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
   174     
       
   175     AknLayoutUtils::LayoutImage(
       
   176             iImage, Rect(), AknLayoutScalable_Apps::cl_header_pane_g1(isLandscape));
       
   177    
       
   178     TPoint position = iImage->Position();
       
   179     TSize size = iImage->Size();
       
   180     
       
   181     const TPoint newImagePosition = TPoint( position.iX/2, position.iY/2 );
       
   182     iImage->SetPosition( newImagePosition );
       
   183     
       
   184     const TSize newImageSize = TSize( size.iWidth + 2*( position.iX - newImagePosition.iX ) ,
       
   185             size.iHeight + 2*( position.iY - newImagePosition.iY ) );
       
   186     
       
   187     iImage->SetSize( newImageSize );
       
   188     
       
   189     iContactImageSize = newImageSize;
       
   190     
       
   191     if ( iImageDecoder )
       
   192         {
       
   193         // if bitmap was set resize it
       
   194         if (iImageDecoder->IsActive())
       
   195             {
       
   196             iImageDecoder->Cancel();
       
   197             }
       
   198         TRAP_IGNORE( iImageDecoder->StartL( iContactImageSize ) );
       
   199         }
       
   200     
       
   201     TAknLayoutRect labelsRect;
       
   202     labelsRect.LayoutRect(Rect(), AknLayoutScalable_Apps::cl_header_name_pane(isLandscape));
       
   203     
       
   204     AknLayoutUtils::LayoutLabel(iLabels[0], labelsRect.Rect(), AknLayoutScalable_Apps::cl_header_name_pane_t1(2));
       
   205     AknLayoutUtils::LayoutLabel(iLabels[1], labelsRect.Rect(), AknLayoutScalable_Apps::cl_header_name_pane_t2(2));
       
   206     
       
   207     AknLayoutUtils::LayoutLabel(iLabels[2], labelsRect.Rect(), AknLayoutScalable_Apps::cl_header_name_pane_t3(2));
       
   208     
       
   209     TRAP_IGNORE(LabelsSizeChangedL());
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CVIMPSTDetailsHeaderControl::LabelsSizeChangedL()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CVIMPSTDetailsHeaderControl::LabelsSizeChangedL()
       
   217     {
       
   218     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   219     TRgb color;
       
   220     AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   221         
       
   222     if (iLabels.Count() > 0)
       
   223         {
       
   224          for (TInt i=0; i < iLabels.Count(); i++)
       
   225             {
       
   226             iLabels[i]->SetTextL( iPresenceHandler.GetHeaderLabelDataL(i) );
       
   227             iLabels[i]->CropText();
       
   228             iLabels[i]->OverrideColorL( EColorLabelText, color );
       
   229             iLabels[i]->DrawDeferred();
       
   230             }
       
   231          }
       
   232     }
       
   233 // ---------------------------------------------------------------------------
       
   234 // CVIMPSTDetailsHeaderControl::HeaderSizeChangedL()
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CVIMPSTDetailsHeaderControl::HeaderSizeChangedL()
       
   238     {
       
   239     CFbsBitmap* bmp = NULL;
       
   240     CFbsBitmap* bmpMask = NULL;
       
   241     TVIMPSTEnums::TOnlineStatus onlineStatus = iPresenceHandler.GetPresenceStatus();
       
   242     if(TVIMPSTEnums::EPending == onlineStatus)
       
   243         {
       
   244         iBrandHandler.LoadBitMapLC(bmp, 
       
   245                 bmpMask,
       
   246                 EMbmVimpstuiQgn_prop_service_friend_request_sent ,
       
   247                 EMbmVimpstuiQgn_prop_service_friend_request_sent_mask  );
       
   248         }
       
   249     else if(TVIMPSTEnums::EBlocked == onlineStatus)
       
   250         {
       
   251         iBrandHandler.LoadBitMapLC(bmp, 
       
   252                 bmpMask,
       
   253                 EMbmVimpstuiQgn_servtab_avatar_blocked ,
       
   254                 EMbmVimpstuiQgn_servtab_avatar_blocked_mask  );
       
   255         }
       
   256      else
       
   257         {
       
   258         iBrandHandler.LoadBitMapLC(bmp, 
       
   259                 bmpMask,
       
   260                 EMbmVimpstuiQgn_prop_service_default_avatar ,
       
   261                 EMbmVimpstuiQgn_prop_service_default_avatar_mask  );
       
   262         }
       
   263     SetBitmap(bmp, bmpMask);//ownership transferred
       
   264     CleanupStack::Pop(2); // bitmap,bmpMask 
       
   265     SizeChanged();
       
   266 
       
   267     }
       
   268 // ---------------------------------------------------------------------------
       
   269 // From CCoeControl, overridden to set the container windows for the child
       
   270 // controls of this control (labels and image)
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void CVIMPSTDetailsHeaderControl::SetContainerWindowL(const CCoeControl& aContainer)
       
   274     {
       
   275     CCoeControl::SetContainerWindowL(aContainer);
       
   276     iImage->SetContainerWindowL(aContainer);
       
   277     for (TInt i=0; i < iLabels.Count(); i++)
       
   278         {
       
   279         iLabels[i]->SetContainerWindowL(aContainer);
       
   280         }
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CVIMPSTDetailsHeaderControl :: SetBitmap
       
   285 // Sets the bitmap shown in the header image 
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CVIMPSTDetailsHeaderControl::SetBitmap(CFbsBitmap* aBmp, CFbsBitmap* aMask )
       
   289     {
       
   290     if (iBitmap)
       
   291         {
       
   292         delete iBitmap;
       
   293         iBitmap = NULL;
       
   294         }
       
   295     if (iMask)
       
   296         {
       
   297         delete iMask;
       
   298         iMask = NULL;
       
   299         }
       
   300     iBitmap = aBmp;
       
   301     iMask = aMask;
       
   302     
       
   303     iImage->SetPicture(aBmp, NULL);
       
   304     iImage->DrawDeferred();
       
   305     
       
   306     TRAP_IGNORE( LabelsSizeChangedL() );
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CVIMPSTDetailsHeaderControl :: ClearL
       
   311 // Clears the header texts & image to blank
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CVIMPSTDetailsHeaderControl::ClearL()
       
   315     {
       
   316     iImage->SetPicture(NULL, NULL);
       
   317     if (iBitmap)
       
   318         {
       
   319         delete iBitmap;
       
   320         iBitmap = NULL;
       
   321         }
       
   322     if (iMask)
       
   323         {
       
   324         delete iMask;
       
   325         iMask = NULL;
       
   326         }
       
   327     for (TInt i = 0; i < iLabels.Count(); i++)
       
   328         {
       
   329         iLabels[i]->SetTextL(KNullDesC());
       
   330         }
       
   331   
       
   332     }
       
   333 // ---------------------------------------------------------------------------
       
   334 // CVIMPSTDetailsHeaderControl :: CreateHeaderPresentationL
       
   335 // Clears the header texts & image to blank
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CVIMPSTDetailsHeaderControl::CreateHeaderPresentationL(MVPbkStoreContact& aContact )
       
   339 	{
       
   340 	TRACER_AUTO;
       
   341 	if( iHeaderField )
       
   342 		{
       
   343 		delete iHeaderField;
       
   344 		iHeaderField = NULL	;
       
   345 		}
       
   346 				
       
   347 	MVPbkStoreContactFieldCollection& fieldCollection = aContact.Fields();
       
   348 	
       
   349 	TInt fieldCount = fieldCollection.FieldCount();
       
   350 	
       
   351 	for( TInt i=0; i< fieldCount; i++ )
       
   352 		{
       
   353 		MVPbkStoreContactField& field = fieldCollection.FieldAt( i );	
       
   354 		const MVPbkFieldType* type = field.BestMatchingFieldType() ;
       
   355 		if( R_VPBK_FIELD_TYPE_THUMBNAILPIC == type->FieldTypeResId() )
       
   356 			{
       
   357 			iHeaderField = field.CloneLC();
       
   358 			CleanupStack::Pop();
       
   359 			break;	
       
   360 			}
       
   361 		}
       
   362 	if( iHeaderField )
       
   363 		{
       
   364 		// field available	
       
   365 		const MVPbkContactFieldData& fieldData = iHeaderField->FieldData();
       
   366 		if( fieldData.DataType() == EVPbkFieldStorageTypeBinary )
       
   367 			{
       
   368 			TPtrC8 data = MVPbkContactFieldBinaryData::Cast(fieldData).BinaryData();
       
   369 	       	if (iImageDecoder)
       
   370 	            {
       
   371 	            if (iImageDecoder->IsActive())
       
   372 	                {
       
   373 	                iImageDecoder->Cancel();
       
   374 	                }
       
   375 	            delete iImageDecoder;
       
   376 	            iImageDecoder = NULL;
       
   377 	            }
       
   378 	        iImageDecoder = CVIMPSTDetailsImageDecoder::NewL(*this, data );
       
   379 	        iImageDecoder->StartL(iContactImageSize);
       
   380 			}
       
   381 		}
       
   382 	
       
   383      }
       
   384 
       
   385 // end of file
       
   386