clock2/clockui/uilayer/clockworldview/src/clockworldcontainer.cpp
changeset 0 f979ecb2b13e
child 15 9711e452b5e9
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 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:   This is the source file for the CClockWorldContainer class.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AknsBasicBackgroundControlContext.h>
       
    20 #include <AknsSkinInstance.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <AknsDrawUtils.h>
       
    23 #include <csxhelp/clk.hlp.hrh>
       
    24 #include <AknDef.h>
       
    25 #include <aknlists.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <avkon.mbg>
       
    28 #include <gulicon.h>
       
    29 #include <StringLoader.h>
       
    30 #include <AknsConstants.h>
       
    31 #include <clock.rsg>
       
    32 #include <clockapp.mbg>
       
    33 
       
    34 // User includes
       
    35 #include "clockworldcontainer.h"
       
    36 #include "clockworldview.h"
       
    37 #include "clockworldarray.h"
       
    38 #include "clock.hrh"
       
    39 #include "clockappui.h"
       
    40 #include "clock_debug.h"
       
    41 #include "clockserverclt.h"
       
    42 #include "clock.h"
       
    43 
       
    44 // Constants
       
    45 const TInt KNumOfIcons( 19 );
       
    46 const TInt KControlListBox( 1 );
       
    47 const TInt KHomeCityImageIndex( 0 );
       
    48 const TInt KDefaultImageIndex( 1 );
       
    49 const TInt KDstIconIndex( 2 );
       
    50 const TInt KBlankIcon( 3 );
       
    51 const TInt KImageStartIndex( 4 );
       
    52 
       
    53 // Literals
       
    54 _LIT( KHomeCityIconFile, "\\resource\\apps\\clockapp.mbm" );
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CClockWorldContainer::NewL
       
    58 // rest of the details are commented in the header
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 CClockWorldContainer* CClockWorldContainer::NewL( CClockWorldView* aView,
       
    62 												  const TRect& aRect,
       
    63 												  CClockWorldArray* aWorldArray )
       
    64 	{
       
    65 	__PRINTS( "CClockWorldContainer::NewL - Entry" );
       
    66 	
       
    67 	CClockWorldContainer* self = new( ELeave ) CClockWorldContainer;
       
    68 	CleanupStack::PushL( self );
       
    69 	
       
    70 	self->ConstructL( aView, aRect, aWorldArray );
       
    71 	
       
    72 	CleanupStack::Pop( self );
       
    73 	
       
    74 	__PRINTS( "CClockWorldContainer::NewL - Exit" );
       
    75 	
       
    76 	return self;
       
    77 	}
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CClockWorldContainer::~CClockWorldContainer
       
    81 // rest of the details are commented in the header
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CClockWorldContainer::~CClockWorldContainer()
       
    85     {
       
    86     __PRINTS( "CClockWorldContainer::~CClockWorldContainer - Entry" );
       
    87     
       
    88 	if( iBgContext )
       
    89 	    {
       
    90 	    delete iBgContext;
       
    91 	    iBgContext = NULL;
       
    92 	    }
       
    93 	if( iListBox )
       
    94 	    {
       
    95 	    delete iListBox;
       
    96 	    iListBox = NULL;
       
    97 	    }
       
    98 	    
       
    99 	__PRINTS( "CClockWorldContainer::~CClockWorldContainer - Exit" );
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // CClockWorldContainer::OfferKeyEventL
       
   104 // rest of the details are commented in the header
       
   105 // ---------------------------------------------------------
       
   106 //    
       
   107 TKeyResponse CClockWorldContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   108                                                    TEventCode aType )
       
   109     {
       
   110     __PRINTS( "CClockWorldContainer::OfferKeyEventL - Entry" );
       
   111     
       
   112     TKeyResponse returnVal( EKeyWasNotConsumed );
       
   113 
       
   114     if( EEventKey == aType )
       
   115         {
       
   116         if( EStdKeyNo == aKeyEvent.iScanCode )
       
   117             {
       
   118             // This indicates that Call End key was pressed.
       
   119             // The application is hidden in the background.
       
   120             iView->ClockApplicationUi()->HandleCommandL( EClockWorldExit );
       
   121 
       
   122             returnVal = EKeyWasConsumed;
       
   123 
       
   124             __PRINTS( "CClockWorldContainer::OfferKeyEventL - Exit" );
       
   125 
       
   126             return returnVal;
       
   127             }
       
   128 			
       
   129 		// Check if automatic-time update is On.
       
   130 		RClkSrvInterface clockServerClt;
       
   131 		// Connect to clockserver
       
   132 		TInt errorVal( clockServerClt.Connect() );
       
   133 		// Check if timeupdate is On.
       
   134 		TBool timeUpdateOn( EFalse );
       
   135 		if( KErrNone == errorVal )
       
   136 			{
       
   137 			errorVal = clockServerClt.IsAutoTimeUpdateOn( timeUpdateOn );
       
   138 			}
       
   139 		// Close the session with the server.
       
   140 		clockServerClt.Close();
       
   141         
       
   142         if( EKeyUpArrow == aKeyEvent.iCode ||
       
   143             EKeyDownArrow == aKeyEvent.iCode )
       
   144             {
       
   145             if( iListBox )
       
   146                 {
       
   147                 returnVal = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   148 		        }
       
   149             }
       
   150 
       
   151         if( EKeyBackspace == aKeyEvent.iCode ||
       
   152             EKeyDelete == aKeyEvent.iCode )
       
   153             {
       
   154             if( KZerothIndex != iListBox->CurrentItemIndex() || timeUpdateOn )
       
   155             	{
       
   156 				//Single click integration
       
   157                 if ( iView->MenuBar()->ItemSpecificCommandsEnabled() )
       
   158                     {
       
   159                     // if highlighted
       
   160                     iView->HandleCommandL( EClockWorldRemoveRegion );
       
   161                     }
       
   162                 // originally key was consumed anyway
       
   163 
       
   164             	}
       
   165 			returnVal = EKeyWasConsumed;
       
   166             }
       
   167 
       
   168         if( EKeyOK == aKeyEvent.iCode || EKeyEnter == aKeyEvent.iCode )
       
   169             {
       
   170 			//Single click integration
       
   171             return iListBox->OfferKeyEventL( aKeyEvent, aType ); 
       
   172 
       
   173             }
       
   174         }
       
   175     
       
   176     __PRINTS( "CClockWorldContainer::OfferKeyEventL - Exit" );
       
   177     
       
   178     return returnVal;	
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CClockWorldContainer::Draw
       
   183 // rest of the details are commented in the header
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 void CClockWorldContainer::Draw( const TRect& aRect ) const
       
   187     {
       
   188     __PRINTS( "CClockWorldContainer::Draw - Entry" );
       
   189     
       
   190     CWindowGc&  gc = SystemGc();
       
   191     gc.Clear( aRect );
       
   192     
       
   193     if( iBgContext )
       
   194         {
       
   195         MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   196         AknsDrawUtils::Background( skinInstance, iBgContext, this, gc, aRect );
       
   197         }
       
   198     
       
   199     __PRINTS( "CClockWorldContainer::Draw - Exit" );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CClockWorldContainer::FocusChanged
       
   204 // rest of the details are commented in the header
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void CClockWorldContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   208     {
       
   209     __PRINTS( "CClockWorldContainer::FocusChanged - Entry" );
       
   210     
       
   211 	if( iListBox )
       
   212 		{
       
   213 		iListBox->SetFocus( IsFocused() );
       
   214 		}
       
   215 	
       
   216 	__PRINTS( "CClockWorldContainer::FocusChanged - Exit" );
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------
       
   220 // CClockWorldContainer::HandlePointerEventL
       
   221 // rest of the details are commented in the header
       
   222 // ---------------------------------------------------------
       
   223 //
       
   224 void CClockWorldContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   225     {
       
   226     __PRINTS( "CClockWorldContainer::HandlePointerEventL - Entry" );
       
   227     
       
   228     // Check if touch is enabled or not.
       
   229     if( !AknLayoutUtils::PenEnabled() )
       
   230         {
       
   231         __PRINTS( "CClockWorldContainer::HandlePointerEventL - Exit" );
       
   232         
       
   233         return;
       
   234         }
       
   235     
       
   236    
       
   237 
       
   238     // Let the lisbox handle the events.
       
   239     iListBox->HandlePointerEventL( aPointerEvent );
       
   240     
       
   241     __PRINTS( "CClockWorldContainer::HandlePointerEventL - Exit" );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------
       
   245 // CClockWorldContainer::HandleListBoxEventL
       
   246 // rest of the details are commented in the header
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 void CClockWorldContainer::HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType )
       
   250     {
       
   251     __PRINTS( "CClockWorldContainer::HandleListBoxEventL - Entry" );
       
   252 
       
   253     if( aListBox == iListBox &&
       
   254 		//Single click integration
       
   255         aEventType == EEventItemSingleClicked )
       
   256 
       
   257         {
       
   258 		//Single click integration
       
   259         iView->HandleCommandL( EClockWorldMyRegion ); 
       
   260         }
       
   261 	//Single click integration
       
   262     else if ( aListBox == iListBox && aEventType == EEventEnterKeyPressed )
       
   263         {
       
   264         if( !iView->IsSelectionListOpen() || !iView->IsGalleryOpen() &&
       
   265             iListBox->CurrentItemIndex() > 0 ) 
       
   266             {
       
   267             iView->HandleCommandL( EClockWorldMyRegion ); 
       
   268             }
       
   269         }
       
   270 
       
   271         
       
   272     __PRINTS( "CClockWorldContainer::HandleListBoxEventL - Entry" );
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CClockWorldContainer::ListBox
       
   277 // rest of the details are commented in the header
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 CAknDoubleLargeStyleListBox* CClockWorldContainer::ListBox()
       
   281 	{
       
   282 	__PRINTS( "CClockWorldContainer::ListBox - Entry" );
       
   283 	
       
   284 	__PRINTS( "CClockWorldContainer::ListBox - Exit" );
       
   285 	
       
   286 	return iListBox;
       
   287 	}
       
   288 
       
   289 // ---------------------------------------------------------
       
   290 // CClockWorldContainer::SizeChanged
       
   291 // rest of the details are commented in the header
       
   292 // ---------------------------------------------------------
       
   293 //
       
   294 void CClockWorldContainer::SizeChanged()
       
   295     {
       
   296     __PRINTS( "CClockWorldContainer::SizeChanged - Entry" );
       
   297     
       
   298     TRect paneRect( this->Rect() );
       
   299     // Update the background context.
       
   300     iBgContext->SetRect( paneRect );
       
   301 	// Update the listbox.
       
   302     // Set the top item index so that the list is updated correctly.
       
   303     iListBox->SetTopItemIndex( KZerothIndex );
       
   304 	iListBox->SetExtent( this->Rect().iTl, this->Rect().Size() );
       
   305     
       
   306 	__PRINTS( "CClockWorldContainer::SizeChanged - Exit" );
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CClockWorldContainer::CountComponentControls
       
   311 // rest of the details are commented in the header
       
   312 // ---------------------------------------------------------
       
   313 //
       
   314 TInt CClockWorldContainer::CountComponentControls() const
       
   315     {
       
   316     __PRINTS( "CClockWorldContainer::CountComponentControls - Entry" );
       
   317     
       
   318     __PRINTS( "CClockWorldContainer::CountComponentControls - Exit" );
       
   319     
       
   320     return KControlListBox;
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------
       
   324 // CClockWorldContainer::ComponentControl
       
   325 // rest of the details are commented in the header
       
   326 // ---------------------------------------------------------
       
   327 //  
       
   328 CCoeControl* CClockWorldContainer::ComponentControl( TInt aIndex ) const
       
   329     {
       
   330     __PRINTS( "CClockWorldContainer::ComponentControl - Entry" );
       
   331     
       
   332 	CCoeControl* coeControl( NULL );
       
   333     switch( aIndex )
       
   334         {
       
   335 		case KErrNone:
       
   336 			{
       
   337 			coeControl = iListBox;
       
   338 			}
       
   339 			break;
       
   340 
       
   341         default:
       
   342             {
       
   343             // No implementation yet.
       
   344             }
       
   345             break;
       
   346         }
       
   347     
       
   348     __PRINTS( "CClockWorldContainer::ComponentControl - Exit" );
       
   349     
       
   350 	return coeControl;
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------
       
   354 // CClockWorldContainer::MopSupplyObject
       
   355 // rest of the details are commented in the header
       
   356 // ---------------------------------------------------------
       
   357 //
       
   358 TTypeUid::Ptr CClockWorldContainer::MopSupplyObject( TTypeUid aId )
       
   359     {
       
   360     __PRINTS( "CClockWorldContainer::MopSupplyObject - Entry" );
       
   361     
       
   362     if( MAknsControlContext::ETypeId == aId.iUid )
       
   363         {
       
   364         __PRINTS( "CClockWorldContainer::MopSupplyObject - Exit" );
       
   365         
       
   366         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   367         }
       
   368     
       
   369     __PRINTS( "CClockWorldContainer::MopSupplyObject - Exit" );
       
   370     
       
   371     return CCoeControl::MopSupplyObject( aId );
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 // CClockWorldContainer::HandleResourceChange
       
   376 // rest of the details are commented in the header
       
   377 // ---------------------------------------------------------
       
   378 //
       
   379 void CClockWorldContainer::HandleResourceChange( TInt aType )
       
   380     {
       
   381     __PRINTS( "CClockWorldContainer::HandleResourceChange - Entry" );
       
   382     
       
   383     CCoeControl::HandleResourceChange( aType );
       
   384     // Update the listbox.
       
   385     iListBox->HandleResourceChange( aType );
       
   386     
       
   387     switch( aType )
       
   388         {
       
   389         case KEikDynamicLayoutVariantSwitch:
       
   390             {
       
   391             SetRect( iView->ClientRect() );
       
   392             }
       
   393             break;
       
   394             
       
   395         case KAknsMessageSkinChange:
       
   396             {
       
   397             // First get the icon array from listbox item drawer.
       
   398             CArrayPtr< CGulIcon >* iconArray = iListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   399             CleanupStack::PushL( iconArray );                     
       
   400             
       
   401             // Delete the first three the icons from the array.
       
   402             iconArray->Delete( KHomeCityImageIndex, KImageStartIndex );	
       
   403           
       
   404             CFbsBitmap* iconBitmap( NULL );
       
   405             CFbsBitmap* iconMask( NULL );
       
   406             CGulIcon* finalIcon( NULL );
       
   407             
       
   408             // Construct the home city image.
       
   409             AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   410                                     KAknsIIDQgnPropClockHomecity,
       
   411                                     iconBitmap,
       
   412                                     iconMask,
       
   413                                     KHomeCityIconFile,
       
   414                                     EMbmClockappQgn_prop_clock_homecity,
       
   415                                     EMbmClockappQgn_prop_clock_homecity_mask );
       
   416             
       
   417             CleanupStack::PushL( iconBitmap );
       
   418             CleanupStack::PushL( iconMask );
       
   419             // Construct the icon.
       
   420             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   421             CleanupStack::PushL( finalIcon );
       
   422             // Append the above icon to the array.
       
   423             iconArray->InsertL( KHomeCityImageIndex, finalIcon );
       
   424                 
       
   425             CleanupStack::Pop( finalIcon );
       
   426             CleanupStack::Pop( iconMask );
       
   427             CleanupStack::Pop( iconBitmap );
       
   428 
       
   429             // Construct the default image.
       
   430             AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   431                                     KAknsIIDQgnPropClockDefault,
       
   432                                     iconBitmap,
       
   433                                     iconMask,
       
   434                                     KHomeCityIconFile,
       
   435                                     EMbmClockappQgn_prop_clock_default,
       
   436                                     EMbmClockappQgn_prop_clock_default_mask );
       
   437             
       
   438             CleanupStack::PushL( iconBitmap );
       
   439             CleanupStack::PushL( iconMask );
       
   440             // Construct the icon.
       
   441             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   442             CleanupStack::PushL( finalIcon );
       
   443             // Append the above icon to the array.
       
   444             iconArray->InsertL( KDefaultImageIndex, finalIcon );
       
   445                 
       
   446             CleanupStack::Pop( finalIcon );
       
   447             CleanupStack::Pop( iconMask );
       
   448             CleanupStack::Pop( iconBitmap );
       
   449 
       
   450             // Reset.
       
   451             iconBitmap = NULL ;
       
   452             iconMask = NULL ;
       
   453             finalIcon = NULL;
       
   454 
       
   455             // Construct the DST icon.
       
   456             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
   457 					                     KAknsIIDQgnIndiDstAdd,
       
   458 					                     KAknsIIDQsnIconColors,
       
   459 					                     EAknsCIQsnIconColorsCG13,
       
   460 					                     iconBitmap,
       
   461 					                     iconMask,
       
   462 					                     AknIconUtils::AvkonIconFileName(),
       
   463 					                     EMbmAvkonQgn_indi_dst_add,
       
   464 					                     EMbmAvkonQgn_indi_dst_add_mask,
       
   465 					                     TRgb( NULL, NULL, 255 ) );
       
   466             CleanupStack::PushL( iconBitmap );
       
   467             CleanupStack::PushL( iconMask );
       
   468             // Construct the icon.
       
   469             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   470             CleanupStack::PushL( finalIcon );
       
   471             // Append the above icon to the array.
       
   472             iconArray->InsertL( KDstIconIndex, finalIcon );
       
   473 
       
   474             CleanupStack::Pop( finalIcon );
       
   475             CleanupStack::Pop( iconMask );
       
   476             CleanupStack::Pop( iconBitmap );
       
   477 
       
   478             // Reset.
       
   479             iconBitmap = NULL ;
       
   480             iconMask = NULL ;
       
   481             finalIcon = NULL;
       
   482 
       
   483             // Now load a blank icon.
       
   484             iconBitmap = new( ELeave ) CFbsBitmap();
       
   485             CleanupStack::PushL( iconBitmap );
       
   486             iconMask = new( ELeave ) CFbsBitmap();
       
   487             CleanupStack::PushL( iconMask );
       
   488 
       
   489             iconBitmap->Create( TSize( NULL, NULL ), ENone );
       
   490             iconMask->Create( TSize( NULL, NULL ), ENone );
       
   491 
       
   492             // Construct the icon.
       
   493             finalIcon = NULL;
       
   494             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   495             CleanupStack::PushL( finalIcon );
       
   496             // Append it to the icon array.
       
   497             iconArray->InsertL( KBlankIcon, finalIcon );
       
   498             // Cleanup.
       
   499             CleanupStack::Pop( finalIcon );
       
   500             CleanupStack::Pop( iconMask );
       
   501             CleanupStack::Pop( iconBitmap );
       
   502 
       
   503             // Set the above iconarray as the icon holder for the listbox.
       
   504             iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );
       
   505             CleanupStack::Pop( iconArray );
       
   506             }
       
   507             break;
       
   508             
       
   509         default:
       
   510         	{
       
   511         	// No implementation yet.
       
   512         	}
       
   513         	break;
       
   514         }
       
   515     
       
   516     __PRINTS( "CClockWorldContainer::HandleResourceChange - Exit" );
       
   517     }
       
   518 
       
   519 // ---------------------------------------------------------
       
   520 // CClockWorldContainer::ConstructL
       
   521 // rest of the details are commented in the header
       
   522 // ---------------------------------------------------------
       
   523 //    
       
   524 void CClockWorldContainer::ConstructL( CClockWorldView* aView,
       
   525 									   const TRect& aRect,
       
   526 									   CClockWorldArray* aWorldArray )
       
   527     {
       
   528     __PRINTS( "CClockWorldContainer::ConstructL - Entry" );
       
   529     
       
   530 	// The view owning the container.
       
   531     iView = aView;
       
   532     iWorldArray = aWorldArray;
       
   533         
       
   534 	CreateWindowL();
       
   535     
       
   536 	// Construct the basic skin context.
       
   537 	iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,
       
   538 	                                                       aRect,
       
   539 	                                                       EFalse );
       
   540 
       
   541 	// Let us construct the listbox and prepare it for displaying.
       
   542 	iListBox = new ( ELeave ) CAknDoubleLargeStyleListBox;
       
   543     iListBox->ConstructL( this, NULL );
       
   544     // Set the container control.
       
   545     iListBox->SetContainerWindowL( *this );
       
   546     // Add scrollbars to listbox
       
   547     iListBox->CreateScrollBarFrameL( ETrue );
       
   548     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   549 														 CEikScrollBarFrame::EAuto );
       
   550    	// Set items to the model and the ownership.
       
   551 	iListBox->Model()->SetItemTextArray( aWorldArray );
       
   552 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   553 	// Enable Marquee for the list.
       
   554 	iListBox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   555 	// Set the listbox event observer.
       
   556 	iListBox->SetListBoxObserver( this );
       
   557 	
       
   558 	// Construct icon array with granularity 3. 1 for the image, 1 for the DST icon and 1 for blank.
       
   559 	CArrayPtr< CGulIcon >* iconArray = new ( ELeave ) CAknIconArray( KNumOfIcons );
       
   560 	CleanupStack::PushL( iconArray );
       
   561 	
       
   562 	// These hold the icons and their corresponding masks.
       
   563 	CFbsBitmap* iconBitmap( NULL );
       
   564 	CFbsBitmap* iconMask( NULL );
       
   565 	CGulIcon* finalIcon( NULL );
       
   566 	
       
   567 	// Construct the home city image.
       
   568     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   569                             KAknsIIDQgnPropClockHomecity,
       
   570                             iconBitmap,
       
   571                             iconMask,
       
   572                             KHomeCityIconFile,
       
   573                             EMbmClockappQgn_prop_clock_homecity,
       
   574                             EMbmClockappQgn_prop_clock_homecity_mask );
       
   575     
       
   576     CleanupStack::PushL( iconBitmap );
       
   577     CleanupStack::PushL( iconMask );
       
   578     // Construct the icon.
       
   579     finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   580     CleanupStack::PushL( finalIcon );
       
   581     // Append the above icon to the array.
       
   582     iconArray->InsertL( KHomeCityImageIndex, finalIcon );
       
   583         
       
   584     CleanupStack::Pop( finalIcon );
       
   585     CleanupStack::Pop( iconMask );
       
   586     CleanupStack::Pop( iconBitmap );
       
   587 
       
   588 	// Construct the default image.
       
   589     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   590                             KAknsIIDQgnPropClockDefault,
       
   591                             iconBitmap,
       
   592                             iconMask,
       
   593                             KHomeCityIconFile,
       
   594                             EMbmClockappQgn_prop_clock_default,
       
   595                             EMbmClockappQgn_prop_clock_default_mask );
       
   596     
       
   597     CleanupStack::PushL( iconBitmap );
       
   598 	CleanupStack::PushL( iconMask );
       
   599 	// Construct the icon.
       
   600 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   601 	CleanupStack::PushL( finalIcon );
       
   602 	// Append the above icon to the array.
       
   603 	iconArray->AppendL( finalIcon );
       
   604 	
       
   605 	CleanupStack::Pop( finalIcon );
       
   606 	CleanupStack::Pop( iconMask );
       
   607 	CleanupStack::Pop( iconBitmap );
       
   608 	
       
   609 	// Reset.
       
   610 	iconBitmap = NULL ;
       
   611 	iconMask = NULL ;
       
   612 	finalIcon = NULL;
       
   613 	
       
   614 	// Construct the DST icon.
       
   615 	AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
   616                                  KAknsIIDQgnIndiDstAdd,
       
   617                                  KAknsIIDQsnIconColors,
       
   618                                  EAknsCIQsnIconColorsCG13,
       
   619                                  iconBitmap,
       
   620                                  iconMask,
       
   621                                  AknIconUtils::AvkonIconFileName(),
       
   622                                  EMbmAvkonQgn_indi_dst_add,
       
   623                                  EMbmAvkonQgn_indi_dst_add_mask,
       
   624                                  TRgb( NULL, NULL, 255 ) );
       
   625 	CleanupStack::PushL( iconBitmap );
       
   626 	CleanupStack::PushL( iconMask );
       
   627 	// Construct the icon.
       
   628 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   629 	CleanupStack::PushL( finalIcon );
       
   630 	// Append the above icon to the array.
       
   631 	iconArray->AppendL( finalIcon );
       
   632 
       
   633 	CleanupStack::Pop( finalIcon );
       
   634 	CleanupStack::Pop( iconMask );
       
   635 	CleanupStack::Pop( iconBitmap );
       
   636 
       
   637 	// Reset.
       
   638 	iconBitmap = NULL ;
       
   639 	iconMask = NULL ;
       
   640 	finalIcon = NULL;
       
   641 	
       
   642 	// Now load a blank icon.
       
   643 	iconBitmap = new( ELeave ) CFbsBitmap();
       
   644 	CleanupStack::PushL( iconBitmap );
       
   645 	iconMask = new( ELeave ) CFbsBitmap();
       
   646 	CleanupStack::PushL( iconMask );
       
   647 	
       
   648 	iconBitmap->Create( TSize( NULL, NULL ), ENone );
       
   649 	iconMask->Create( TSize( NULL, NULL ), ENone );
       
   650 	
       
   651 	// Construct the icon.
       
   652 	finalIcon = NULL;
       
   653 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   654 	CleanupStack::PushL( finalIcon );
       
   655 	// Append it to the icon array.
       
   656 	iconArray->AppendL( finalIcon );
       
   657 	// Cleanup.
       
   658 	CleanupStack::Pop( finalIcon );
       
   659 	CleanupStack::Pop( iconMask );
       
   660 	CleanupStack::Pop( iconBitmap );
       
   661 
       
   662 	// Set the above iconarray as the icon holder for the listbox.
       
   663 	iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );
       
   664     CleanupStack::Pop( iconArray );
       
   665     
       
   666     RClkSrvInterface clkSrvInterface;
       
   667     User::LeaveIfError( clkSrvInterface.Connect() );
       
   668     TBool timeUpdateOn( EFalse );
       
   669     // Get the state of the plugin.
       
   670     clkSrvInterface.IsAutoTimeUpdateOn( timeUpdateOn );
       
   671     clkSrvInterface.Close();
       
   672 
       
   673     
       
   674 	
       
   675 	// Display no locations only when Automatic time update is on and there are no cities added.
       
   676 	if( timeUpdateOn && ( KErrNone == iWorldArray->MdcaCount() ) )
       
   677 	    {
       
   678 	    HBufC* noLocationBuf = StringLoader::LoadLC( R_WRLD_CLK_EMPTY_VIEW, iCoeEnv );
       
   679 	    iListBox->View()->SetListEmptyTextL( noLocationBuf->Des() );
       
   680 	    CleanupStack::PopAndDestroy( noLocationBuf );
       
   681 	    }
       
   682 	        
       
   683     SetRect( aRect );
       
   684     iListBox->ActivateL();
       
   685     
       
   686     __PRINTS( "CClockWorldContainer::ConstructL - Exit" );
       
   687     }
       
   688 
       
   689 // ---------------------------------------------------------
       
   690 // CClockWorldContainer::CClockMainContainer
       
   691 // rest of the details are commented in the header
       
   692 // ---------------------------------------------------------
       
   693 //    
       
   694 CClockWorldContainer::CClockWorldContainer()
       
   695     {
       
   696     __PRINTS( "CClockWorldContainer::CClockWorldContainer - Entry" );
       
   697     
       
   698     // No implementation yet.
       
   699     
       
   700     __PRINTS( "CClockWorldContainer::CClockWorldContainer - Exit" );
       
   701     }
       
   702 
       
   703 // ---------------------------------------------------------
       
   704 // CClockWorldContainer::UpdateImageL
       
   705 // rest of the details are commented in the header
       
   706 // ---------------------------------------------------------
       
   707 //    
       
   708 void CClockWorldContainer::UpdateImageL( TPtrC aFileName, TInt aIndex )
       
   709     {
       
   710 	__PRINTS( "CClockWorldContainer::UpdateImage - Entry" );
       
   711     
       
   712     TInt imageIndex ( KErrNotFound );
       
   713              
       
   714     // Get the stored city information for the selected list item.
       
   715     TCityInfo cityInfo( iWorldArray->GetCity( aIndex ) );
       
   716     TInt oldImageIndex( iWorldArray->GetImageIndex( aIndex ) );
       
   717     
       
   718     if( aFileName.Compare( cityInfo.iImagePath ) ) 
       
   719         {
       
   720         // Check whether the selected image is loaded by any of the list items.
       
   721         imageIndex = iWorldArray->CheckIfImageLoaded( aFileName, aIndex );    
       
   722         }
       
   723     else
       
   724         {
       
   725         // User has chosen the same image as loaded for the listitem.
       
   726         imageIndex = oldImageIndex;
       
   727         }
       
   728     
       
   729     // In case the selected image is not found,get a new thumbnail. 	
       
   730     if( KErrNotFound == imageIndex )
       
   731         {
       
   732         iWorldArray->GetThumbnailL( aFileName, aIndex );
       
   733         imageIndex = oldImageIndex;
       
   734         if( KDefaultImageIndex != oldImageIndex )
       
   735             {
       
   736             iOldImagePath = HBufC::NewL( KImagePathLength );
       
   737             iOldImagePath->Des().Copy(cityInfo.iImagePath );
       
   738                                   
       
   739             }
       
   740         }
       
   741     
       
   742     // Update the new image index and path for the selected list item.
       
   743     iWorldArray->UpdateImageInListItem( imageIndex, aIndex, aFileName );
       
   744 	
       
   745     
       
   746     __PRINTS( "CClockWorldContainer::UpdateImage - Exit" );
       
   747     }
       
   748 
       
   749 // ---------------------------------------------------------
       
   750 // CClockWorldContainer::RedrawItem
       
   751 // rest of the details are commented in the header
       
   752 // ---------------------------------------------------------
       
   753 //    
       
   754 TBool CClockWorldContainer::RedrawItem( TInt aIndex )
       
   755     {
       
   756     __PRINTS( "CClockWorldContainer::RedrawItem - Entry" );
       
   757     
       
   758     TBool retValue( EFalse );
       
   759  
       
   760     // Check whether the current list index is less than the total list count.
       
   761     if( aIndex < iWorldArray->MdcaCount() )
       
   762         {    	
       
   763         TCityInfo city ( iWorldArray->GetCity( aIndex ) );
       
   764 	   
       
   765 	    // Check whether the image loaded is not a default image
       
   766 	    if( city.iImagePath.Compare( KDefaultImagePath ) )
       
   767 	        {       
       
   768             // Add the thumbnail icon and redraw the item
       
   769 	        LoadThumbnailL( city.iThumbnailBitmap ,aIndex  );              	        
       
   770 	        }
       
   771 	    retValue = ETrue;
       
   772 	    }
       
   773     
       
   774     __PRINTS( "CClockWorldContainer::RedrawItem - Exit" ); 
       
   775 	
       
   776 	return retValue;
       
   777 	}
       
   778 
       
   779 // ---------------------------------------------------------
       
   780 // CClockWorldContainer::RemoveImage
       
   781 // rest of the details are commented in the header
       
   782 // ---------------------------------------------------------
       
   783 //    
       
   784 void CClockWorldContainer::RemoveImage( TPtrC aFileName, TInt aImageIndex, TInt aListIndex )
       
   785     {
       
   786     __PRINTS( "CClockWorldContainer::RemoveImage - Entry" );
       
   787     
       
   788     // Check whether  the selected image is not the default image.
       
   789     // In case of a match the default image is not be deleted     	
       
   790     if( aFileName.Compare( KDefaultImagePath ) )
       
   791 		{  	
       
   792 		TInt loadedImageIndex ( KErrNotFound );
       
   793 
       
   794 		// Check whether the selected image is loaded by any of the listitems.
       
   795 		loadedImageIndex = iWorldArray->CheckIfImageLoaded( aFileName, aListIndex );
       
   796 
       
   797 		// If image is not loaded then delete the image from the iconArray.
       
   798 		if( ( KErrNotFound == loadedImageIndex ) && ( KImageStartIndex <= aImageIndex ) )
       
   799 			{
       
   800 			CArrayPtr< CGulIcon >* iconArray = iListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   801 			CGulIcon* tempIcon ( iconArray->At( aImageIndex ) );
       
   802 
       
   803 			// Decrement the image index of the lisitems by one
       
   804 			// which have image index greater than aImageIndex in the iconArray
       
   805 			// The reason is that delete resizes the iconArray.
       
   806 			for( TInt item( FALSE ); item < iWorldArray->MdcaCount(); item++ )
       
   807 				{
       
   808 				TInt itemImageIndex ( iWorldArray->GetImageIndex( item ) );
       
   809 
       
   810 				if( itemImageIndex > aImageIndex )
       
   811 					{
       
   812 					TCityInfo cityInfo = iWorldArray->GetCity( item ); 
       
   813 					iWorldArray->UpdateImageInListItem( itemImageIndex - 1, item, cityInfo.iImagePath );	
       
   814 					}
       
   815 				}
       
   816              
       
   817 			// Delete thumbnail for the given item.
       
   818 			iWorldArray->DeleteThumbnailL( aFileName );
       
   819 			
       
   820 			// Delete the icon from the iconArray.
       
   821 			iconArray->Delete( aImageIndex );
       
   822 			iconArray->Compress();
       
   823 			delete tempIcon;
       
   824 			tempIcon = NULL;
       
   825 			iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );	
       
   826 			}
       
   827 		}
       
   828 
       
   829     __PRINTS( "CClockWorldContainer::RemoveImage - Exit" );
       
   830     }
       
   831 
       
   832 // ----------------------------------------------------------------------------
       
   833 // CClockWorldContainer::LoadThumbnailL
       
   834 // rest of the details are commented in the header
       
   835 // ----------------------------------------------------------------------------
       
   836 //
       
   837 void CClockWorldContainer::LoadThumbnailL( CFbsBitmap* aBitmap, TInt aIndex )
       
   838     {
       
   839     TInt imageIndex ( KErrNotFound );
       
   840     TCityInfo city ( iWorldArray->GetCity( aIndex ) );
       
   841         
       
   842     // Check if the request for fetching thumbnail is complete.
       
   843     if(( KErrNotFound == city.iThumbnailRequestId ))
       
   844          {
       
   845          // Create an icon for the set thumbnail bitmap.
       
   846          if( aBitmap )
       
   847              {
       
   848              // Check whether the selected image is loaded by any of the list items.
       
   849              imageIndex = iWorldArray->CheckIfImageLoaded( city.iImagePath, aIndex );
       
   850 
       
   851              if( KImageStartIndex > imageIndex )        
       
   852                  { 
       
   853                  CArrayPtr< CGulIcon >* iconArray = iListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   854                  CleanupStack::PushL( iconArray );
       
   855             
       
   856                  CGulIcon* newIcon = CGulIcon::NewL( aBitmap );
       
   857                  CleanupStack::PushL( newIcon );
       
   858                  iconArray->AppendL( newIcon );
       
   859               
       
   860                  // Set the above iconarray as the icon holder for the listbox.
       
   861                  iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );
       
   862                  imageIndex = iconArray->Count() - 1;
       
   863                 
       
   864                  // Cleanup.
       
   865                  CleanupStack::Pop( newIcon );
       
   866                  CleanupStack::Pop( iconArray );
       
   867                  }            
       
   868                            
       
   869              TInt oldImageIndex( iWorldArray->GetImageIndex( aIndex ) );
       
   870              iWorldArray->UpdateImageInListItem( imageIndex, aIndex, city.iImagePath );
       
   871             
       
   872              // Check if the old image index is not the default image index and then remove the old image.
       
   873              if(( KDefaultImageIndex != oldImageIndex ) && ( iOldImagePath ) )
       
   874                   {
       
   875                   // Delete the old image if it is not used by any of the list items.
       
   876                   RemoveImage( iOldImagePath->Des(), oldImageIndex, aIndex );  
       
   877                   delete iOldImagePath;
       
   878                   iOldImagePath = NULL;             
       
   879                   }                                
       
   880              }
       
   881          else
       
   882              {
       
   883              // In case bitmap does not exist then load the default image.
       
   884              TPtrC defaultFilePath( KDefaultImagePath );
       
   885                
       
   886              // Set to the default image in case thumbnail is not found or is corrupt.
       
   887              imageIndex = KDefaultImageIndex;       
       
   888              iWorldArray->UpdateImageInListItem( imageIndex, aIndex, defaultFilePath );            
       
   889              }
       
   890          iListBox->RedrawItem( aIndex );
       
   891          }        
       
   892     }
       
   893 
       
   894 // ---------------------------------------------------------
       
   895 // CClockWorldContainer::Refresh
       
   896 // rest of the details are commented in the header
       
   897 // ---------------------------------------------------------
       
   898 // 
       
   899 void CClockWorldContainer::Refresh()
       
   900     {
       
   901     __PRINTS( "CClockWorldContainer::Refresh - Entry" );
       
   902     
       
   903     if ( iWorldArray )
       
   904         {
       
   905         iWorldArray->UpdateTimeEntryList();
       
   906         }
       
   907     DrawNow();
       
   908     
       
   909     __PRINTS( "CClockWorldContainer::Refresh - Exit" );
       
   910     }
       
   911 	
       
   912 // ----------------------------------------------------------------------------
       
   913 // CClockWorldContainer::GetHelpContext
       
   914 // rest of the details are commented in the header
       
   915 // ----------------------------------------------------------------------------
       
   916 //
       
   917 void CClockWorldContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   918     {
       
   919     __PRINTS( "CClockWorldContainer::GetHelpContext - Entry" );
       
   920 
       
   921     aContext.iMajor = KClockAppUid;
       
   922 
       
   923     // This is specified in HRH file.
       
   924     aContext.iContext = KCLK_HLP_WRLD_CLK;
       
   925 
       
   926     __PRINTS( "CClockWorldContainer::GetHelpContext - Exit" );
       
   927     }
       
   928 
       
   929 // End of file