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