clock2/clockui/uilayer/clockmainview/src/clockmaincontainer.cpp
changeset 0 f979ecb2b13e
child 30 d68a4b5d5885
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 CClockMainContainer 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 <AknSkinnableClock.h>
       
    24 #include <csxhelp/clk.hlp.hrh>
       
    25 #include <aknlayoutscalable_apps.cdl.h>
       
    26 #include <aknlayoutscalable_avkon.cdl.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <clock.rsg>
       
    29 #include <StringLoader.h>
       
    30 #include <aknlists.h>
       
    31 #include <gulicon.h>
       
    32 #include <AknIconArray.h>
       
    33 #include <AknsConstants.h>
       
    34 #include <AknDef.h>
       
    35 #include <clockapp.mbg>
       
    36 #include <avkon.mbg>
       
    37 #include <tz.h>
       
    38 #include <tzlocalizer.h>
       
    39 #include <tzlocalizationdatatypes.h>
       
    40 #include <vtzrules.h>
       
    41 
       
    42 // User includes
       
    43 #include "clockmaincontainer.h"
       
    44 #include "clockmainview.h"
       
    45 #include "clockalarmarray.h"
       
    46 #include "clockserverclt.h"
       
    47 #include "clockmarqueelabel.h"
       
    48 #include "clkcommon.h"
       
    49 #include "clock.hrh"
       
    50 #include "clock.h"
       
    51 #include "clock_debug.h"
       
    52 #include "clockappui.h"
       
    53 
       
    54 // Constants
       
    55 const TInt KNumOfIcons( 3 );
       
    56 const TInt KHour( 60 );
       
    57 const TInt KZerothRule( 0 );
       
    58 const TInt KOffsetStringLength( 64 );
       
    59 const TInt KLocationNameLength( 100 );
       
    60 const TInt KDayNames[] =
       
    61     {
       
    62     R_QTN_WEEK_LONG_MONDAY,
       
    63     R_QTN_WEEK_LONG_TUESDAY,
       
    64     R_QTN_WEEK_LONG_WEDNESDAY,
       
    65     R_QTN_WEEK_LONG_THURSDAY,
       
    66     R_QTN_WEEK_LONG_FRIDAY,
       
    67     R_QTN_WEEK_LONG_SATURDAY,
       
    68     R_QTN_WEEK_LONG_SUNDAY
       
    69     };
       
    70 
       
    71 // Literals
       
    72 _LIT( KIconFileName, "\\resource\\apps\\clockapp.mif" );
       
    73 _LIT( KPlusGMT, " \x202A+" );
       
    74 _LIT( KMinusGMT, " \x202A" );
       
    75 _LIT( KPDF, " \x202C" );
       
    76 _LIT( KZero, "0" );
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CClockMainContainer::NewL
       
    80 // rest of the details are commented in the header
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CClockMainContainer* CClockMainContainer::NewL( CClockMainView* aView, const TRect& aRect, CClockAlarmArray* aAlarmArray )
       
    84     {
       
    85 	__PRINTS( "CClockMainContainer::NewL - Entry" );
       
    86 	
       
    87     CClockMainContainer* self = new ( ELeave ) CClockMainContainer;
       
    88     CleanupStack::PushL( self );
       
    89     
       
    90     self->ConstructL( aView, aRect, aAlarmArray );
       
    91     
       
    92     CleanupStack::Pop( self );
       
    93 	
       
    94 	__PRINTS( "CClockMainContainer::NewL - Exit" );
       
    95 	
       
    96     return self;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CClockMainContainer::~CClockMainContainer
       
   101 // rest of the details are commented in the header
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 CClockMainContainer::~CClockMainContainer()
       
   105     {
       
   106 	__PRINTS( "CClockMainContainer::~CClockMainContainer - Entry" );
       
   107 	
       
   108 	if( iBgContext )
       
   109 	    {
       
   110 	    delete iBgContext;
       
   111 	    iBgContext = NULL;
       
   112 	    }
       
   113 	if( iSkinnableClock )
       
   114 	    {
       
   115 	    delete iSkinnableClock;
       
   116 	    iSkinnableClock = NULL;
       
   117 	    }
       
   118 	if( iListBox )
       
   119 	    {
       
   120 	    delete iListBox;
       
   121 	    iListBox = NULL;
       
   122 	    }
       
   123 	if( iDateString )
       
   124 	    {
       
   125 	    delete iDateString;
       
   126 	    iDateString = NULL;
       
   127 	    }
       
   128 	if( iDstIndicator )
       
   129 	    {
       
   130 	    delete iDstIndicator;
       
   131 	    iDstIndicator = NULL;
       
   132 	    }
       
   133 	if( iDstIndicatorMask )
       
   134 	    {
       
   135 	    delete iDstIndicatorMask;
       
   136 	    iDstIndicatorMask = NULL;
       
   137 	    }
       
   138 	if( iDayNameString )
       
   139         {
       
   140         delete iDayNameString;
       
   141         iDayNameString = NULL;
       
   142         }
       
   143 	if( iLocationString )
       
   144 	    {
       
   145 	    delete iLocationString;
       
   146 	    iLocationString = NULL;
       
   147 	    }
       
   148 	if( iLocationLabel )
       
   149 	    {
       
   150 	    delete iLocationLabel;
       
   151 	    iLocationLabel = NULL;
       
   152 	    }
       
   153 	if( iTimeZoneString )
       
   154 	    {
       
   155 	    delete iTimeZoneString;
       
   156 	    iTimeZoneString = NULL;
       
   157 	    }
       
   158 		
       
   159 	__PRINTS( "CClockMainContainer::~CClockMainContainer - Exit" );
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CClockMainContainer::OfferKeyEventL
       
   164 // rest of the details are commented in the header
       
   165 // ---------------------------------------------------------
       
   166 //    
       
   167 TKeyResponse CClockMainContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   168                                                   TEventCode aType )
       
   169     {
       
   170 	__PRINTS( "CClockMainContainer::OfferKeyEventL - Entry" );
       
   171 	
       
   172     TKeyResponse retVal( EKeyWasNotConsumed );
       
   173 
       
   174     if( EEventKey == aType )
       
   175         {
       
   176         if( EStdKeyNo == aKeyEvent.iScanCode )
       
   177             {
       
   178             // This indicates that Call End key was pressed.
       
   179             // The timer is stopped and app is hidden in the background.
       
   180             iView->ClockApplicationUi()->HandleCommandL( EClockMainViewExit );
       
   181 
       
   182             retVal = EKeyWasConsumed;
       
   183 
       
   184             __PRINTS( "CClockMainContainer::OfferKeyEventL - Exit" );
       
   185 
       
   186             return retVal;
       
   187             }
       
   188         
       
   189         if( EKeyUpArrow == aKeyEvent.iCode ||
       
   190             EKeyDownArrow == aKeyEvent.iCode )
       
   191             {
       
   192             if( iListBox )
       
   193                 {
       
   194     
       
   195                     
       
   196                 // Send the event to the listbox to handle the event.
       
   197                 retVal = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   198                 }
       
   199             }
       
   200 
       
   201         if( ( EKeyBackspace == aKeyEvent.iCode || EKeyDelete == aKeyEvent.iCode ) &&
       
   202             ( KZeroAlarms < iListBox->Model()->ItemTextArray()->MdcaCount() ) )
       
   203             {
       
   204             // Handle backspace command. Deletes the selected alarm.
       
   205 			//Single click integration
       
   206             if ( iView->MenuBar()->ItemSpecificCommandsEnabled() )
       
   207                 {
       
   208                 // if highlighted
       
   209                 iView->HandleCommandL( EClockRemoveAlarm );
       
   210                 retVal = EKeyWasConsumed;
       
   211                 }
       
   212             // otherwise do nothing and don't consume key
       
   213 
       
   214             }
       
   215 		//Single click integration
       
   216         if ( aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter )
       
   217             {
       
   218             // Send the event to the listbox to handle the event.
       
   219             iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   220             }
       
   221 
       
   222         }
       
   223 		
       
   224 	__PRINTS( "CClockMainContainer::OfferKeyEventL - Exit" );
       
   225 		
       
   226     return retVal;
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------
       
   230 // CClockMainContainer::Draw
       
   231 // rest of the details are commented in the header
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 void CClockMainContainer::Draw( const TRect& aRect ) const
       
   235     {
       
   236 	__PRINTS( "CClockMainContainer::Draw - Entry" );
       
   237 	
       
   238     CWindowGc& windowGc = SystemGc();
       
   239     windowGc.Clear( aRect );
       
   240     
       
   241     if( iBgContext )
       
   242         {
       
   243         MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   244         AknsDrawUtils::Background( skinInstance, iBgContext, this, windowGc, aRect );
       
   245         }
       
   246     
       
   247     // Draw the date and day text.
       
   248     DrawMainViewText( windowGc );
       
   249     
       
   250     // TODO: Change the LCT when the new LCT data is available.
       
   251     // Check if the DST is ON. If so, display the DST indicator icon.
       
   252     if( iDSTOn )
       
   253         {
       
   254         TAknLayoutRect dstIndicatorRect;
       
   255         
       
   256         if( Layout_Meta_Data::IsLandscapeOrientation() )
       
   257             {
       
   258             dstIndicatorRect.LayoutRect( Rect(),
       
   259                                          AknLayoutScalable_Apps::main_clock2_pane_g1( KVGALandscapeVariant ).LayoutLine() );
       
   260             }
       
   261         else
       
   262             {
       
   263             dstIndicatorRect.LayoutRect( Rect(),
       
   264                                          AknLayoutScalable_Apps::main_clock2_pane_g1( KVGAPortraitVariant ).LayoutLine() );
       
   265             }
       
   266        
       
   267         AknIconUtils::SetSize( iDstIndicator, dstIndicatorRect.Rect().Size() );
       
   268         dstIndicatorRect.DrawImage( windowGc, iDstIndicator, iDstIndicatorMask );
       
   269         }
       
   270 
       
   271 	__PRINTS( "CClockMainContainer::Draw - Exit" );
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------
       
   275 // CClockMainContainer::FocusChanged
       
   276 // rest of the details are commented in the header
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 void CClockMainContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   280     {
       
   281 	__PRINTS( "CClockMainContainer::FocusChanged - Entry" );
       
   282 	
       
   283     if( iListBox )
       
   284         {
       
   285         iListBox->SetFocus( IsFocused() );
       
   286         }
       
   287 		
       
   288 	__PRINTS( "CClockMainContainer::FocusChanged - Exit" );
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------
       
   292 // CClockMainContainer::HandlePointerEventL
       
   293 // rest of the details are commented in the header
       
   294 // ---------------------------------------------------------
       
   295 //
       
   296 void CClockMainContainer::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   297     {
       
   298 	__PRINTS( "CClockMainContainer::HandlePointerEventL - Entry" );
       
   299 	
       
   300     // Check first wheather touch is supported or not.
       
   301     if( !AknLayoutUtils::PenEnabled() )
       
   302         {
       
   303 		__PRINTS( "CClockMainContainer::HandlePointerEventL - Exit" );
       
   304 		
       
   305         return;
       
   306         }
       
   307 
       
   308     // Let the listbox handle the event.
       
   309     iListBox->HandlePointerEventL( aPointerEvent );
       
   310 		
       
   311 	__PRINTS( "CClockMainContainer::HandlePointerEventL - Exit" );
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------
       
   315 // CClockMainContainer::HandleListBoxEventL
       
   316 // rest of the details are commented in the header
       
   317 // ---------------------------------------------------------
       
   318 //
       
   319 void CClockMainContainer::HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType )
       
   320     {
       
   321     __PRINTS( "CClockMainContainer::HandleListBoxEventL - Entry" );
       
   322 
       
   323     if( aListBox == iListBox &&
       
   324         aEventType == EEventItemSingleClicked )
       
   325         {
       
   326         // Check if the user has double clicked on the list item.
       
   327         if( !iView->IsAlarmEditorOpen() )
       
   328             {
       
   329             // If the user has selected the first item, launch alarm editor.
       
   330             if( KErrNone == aListBox->CurrentItemIndex() )
       
   331                 {
       
   332                 iView->HandleCommandL( EClockNewAlarm );
       
   333                 }
       
   334             else
       
   335                 {
       
   336 				//Single click integration
       
   337                 iView->HandleCommandL( EClockResetAlarm ); 
       
   338 
       
   339                 }
       
   340             }
       
   341         }
       
   342 	//Single click integration
       
   343     else if ( aListBox == iListBox && aEventType == EEventEnterKeyPressed )
       
   344         {
       
   345         if( !iView->IsAlarmEditorOpen() )
       
   346             {
       
   347             if ( iListBox->CurrentItemIndex() == 0 ) 
       
   348                 {
       
   349                 iView->HandleCommandL( EClockNewAlarm );
       
   350                 }
       
   351             else 
       
   352                 {
       
   353                 iView->HandleCommandL( EClockResetAlarm ); 
       
   354                 }
       
   355             }
       
   356         }
       
   357 
       
   358     
       
   359     __PRINTS( "CClockMainContainer::HandleListBoxEventL - Entry" );
       
   360     }
       
   361 
       
   362 // ---------------------------------------------------------
       
   363 // CClockMainContainer::UpdateAlarmListL
       
   364 // rest of the details are commented in the header
       
   365 // ---------------------------------------------------------
       
   366 //
       
   367 void CClockMainContainer::UpdateAlarmListL( SClkAlarmInfo& /*aAlarmInfo*/, TAlarmId aAlarmId )
       
   368     {
       
   369 	__PRINTS( "CClockMainContainer::UpdateAlarmListL - Entry" );
       
   370 	
       
   371     // Reinitialize the alarm id array.
       
   372     iAlarmArray->InitIdList();
       
   373     iListBox->HandleItemAdditionL();
       
   374     
       
   375     // Get the index of the new alarm added.
       
   376     TInt itemIndex( iAlarmArray->ListBoxIndex( aAlarmId ) );
       
   377     
       
   378     // Update the listbox.
       
   379     iListBox->ScrollToMakeItemVisible( itemIndex );
       
   380     iListBox->SetCurrentItemIndexAndDraw( itemIndex );
       
   381 	
       
   382 	__PRINTS( "CClockMainContainer::UpdateAlarmListL - Exit" );
       
   383     }
       
   384 
       
   385 // ---------------------------------------------------------
       
   386 // CClockMainContainer::RemoveAlarmL
       
   387 // rest of the details are commented in the header
       
   388 // ---------------------------------------------------------
       
   389 //
       
   390 void CClockMainContainer::RemoveAlarmL( TInt aIndex )
       
   391     {
       
   392 	__PRINTS( "CClockMainContainer::RemoveAlarmL - Entry" );
       
   393 	
       
   394     // Reinitialize the alarm list.
       
   395     iAlarmArray->InitIdList();
       
   396     
       
   397     if( ( KZeroAlarms <= aIndex ) &&
       
   398         ( aIndex == iListBox->Model()->ItemTextArray()->MdcaCount() ) )
       
   399         {
       
   400         // Last alarm in the list is deleted hence set the previous alarm.
       
   401         iListBox->ScrollToMakeItemVisible( aIndex - 1 );
       
   402         iListBox->SetCurrentItemIndexAndDraw( aIndex - 1 );
       
   403         
       
   404         
       
   405         }
       
   406     else if( ( KZeroAlarms <= aIndex ) &&
       
   407              ( KZeroAlarms < iListBox->Model()->ItemTextArray()->MdcaCount() ) )
       
   408         {
       
   409         // Highlight the alarm item replacing the deleted element
       
   410         iListBox->ScrollToMakeItemVisible( aIndex );
       
   411         iListBox->SetCurrentItemIndexAndDraw( aIndex );
       
   412         }
       
   413     
       
   414     // Update the listbox.
       
   415     iListBox->HandleItemRemovalL();
       
   416     DrawNow();
       
   417 	
       
   418 	__PRINTS( "CClockMainContainer::RemoveAlarmL - Exit" );
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------
       
   422 // CClockMainContainer::ListBox
       
   423 // rest of the details are commented in the header
       
   424 // ---------------------------------------------------------
       
   425 //
       
   426 //Single click integration
       
   427 CAknDoubleStyleListBox* CClockMainContainer::ListBox()
       
   428     {
       
   429 	__PRINTS( "CClockMainContainer::ListBox - Entry" );
       
   430 	
       
   431 	__PRINTS( "CClockMainContainer::ListBox - Exit" );
       
   432 	
       
   433     return iListBox;
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // CClockMainContainer::SetDayInfoL
       
   438 // rest of the details are commented in the header
       
   439 // ---------------------------------------------------------
       
   440 //
       
   441 void CClockMainContainer::SetDayInfoL()
       
   442     {
       
   443 	__PRINTS( "CClockMainContainer::SetDayInfoL - Entry" );
       
   444 	
       
   445     // First get the current time.
       
   446     TTime homeTime;
       
   447     homeTime.HomeTime();
       
   448 	
       
   449 	TDateString dateBuffer;
       
   450     
       
   451     // Construct the date string.
       
   452     HBufC* formatString = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO, iCoeEnv );
       
   453     // Format the time to get the date.
       
   454     homeTime.FormatL( dateBuffer, *formatString );
       
   455     // Cleanup.
       
   456     CleanupStack::PopAndDestroy( formatString );
       
   457     
       
   458     // Get the date string.
       
   459     if( iDateString )
       
   460     	{
       
   461     	delete iDateString;
       
   462     	iDateString = NULL;
       
   463     	}
       
   464     iDateString = HBufC::NewL( dateBuffer.Length() );
       
   465     TPtr dateStringPtr = iDateString->Des();
       
   466     dateStringPtr.Append( dateBuffer );
       
   467     
       
   468     // Get the day name string.
       
   469     if( iDayNameString )
       
   470         {
       
   471         delete iDayNameString;
       
   472         iDayNameString = NULL;
       
   473         }
       
   474     iDayNameString = StringLoader::LoadL( KDayNames[ homeTime.DayNoInWeek() ], iCoeEnv );
       
   475     
       
   476 	__PRINTS( "CClockMainContainer::SetDayInfoL - Exit" );
       
   477     }
       
   478 
       
   479 // ---------------------------------------------------------
       
   480 // CClockMainContainer::UpdateDSTStateL
       
   481 // rest of the details are commented in the header
       
   482 // ---------------------------------------------------------
       
   483 //
       
   484 void CClockMainContainer::UpdateDSTStateL()
       
   485     {
       
   486 	__PRINTS( "CClockMainContainer::UpdateDSTStateL - Entry" );
       
   487 	
       
   488     RTz tzHandle;
       
   489     User::LeaveIfError( tzHandle.Connect() );
       
   490     CleanupClosePushL( tzHandle );
       
   491 
       
   492     CTzId* timezoneId = tzHandle.GetTimeZoneIdL();
       
   493     CleanupStack::PushL( timezoneId );
       
   494 
       
   495     if( tzHandle.IsDaylightSavingOnL( *timezoneId ) )
       
   496         {
       
   497         iDSTOn = ETrue;
       
   498         }
       
   499     else 
       
   500         {
       
   501         iDSTOn = EFalse;
       
   502         }
       
   503 
       
   504     CleanupStack::PopAndDestroy( timezoneId );
       
   505     CleanupStack::PopAndDestroy( &tzHandle );
       
   506 	
       
   507 	__PRINTS( "CClockMainContainer::UpdateDSTStateL - Exit" );
       
   508     }
       
   509 
       
   510 // ---------------------------------------------------------
       
   511 // CClockMainContainer::SetZoneInfoL
       
   512 // rest of the details are commented in the header
       
   513 // ---------------------------------------------------------
       
   514 //
       
   515 void CClockMainContainer::SetZoneInfoL()
       
   516     {
       
   517 	__PRINTS( "CClockMainContainer::SetZoneInfoL - Entry" );
       
   518 	
       
   519     TBuf< KOffsetStringLength > offsetString;
       
   520     TBuf< KLocationNameLength > locationName;
       
   521     TInt gmtOffset( KErrNone );
       
   522 
       
   523     RArray< TInt > timeZones;
       
   524     RArray< TInt > timeZoneOffsets;
       
   525 
       
   526     // Connect to the timezone server.
       
   527     RTz tzHandle;
       
   528     User::LeaveIfError( tzHandle.Connect() );
       
   529     CleanupClosePushL( tzHandle );
       
   530 
       
   531     // Get the current timezone ID.
       
   532     CTzId* timeZoneId;
       
   533     timeZoneId = tzHandle.GetTimeZoneIdL();
       
   534     CleanupStack::PushL( timeZoneId );
       
   535 
       
   536     // Get all the timezone offsets corresponding to the current timezone ID.
       
   537     timeZones.Append( timeZoneId->TimeZoneNumericID() );
       
   538     tzHandle.GetOffsetsForTimeZoneIdsL( timeZones, timeZoneOffsets );
       
   539 
       
   540     // The offset of the current zone.
       
   541     TInt currentOffset( timeZoneOffsets[ KErrNone ] );
       
   542     gmtOffset = currentOffset;
       
   543 
       
   544     // Check if the DST is on for the current timezone.
       
   545     if( IsDstOnL( timeZones[ 0 ] ) )
       
   546         {
       
   547         TInt32 dstOffset;
       
   548 
       
   549         // Get the offset
       
   550         GetOffSetWithDstL( dstOffset, *timeZoneId );
       
   551 
       
   552         // Update the gmt offset with DST offset.
       
   553         gmtOffset = dstOffset;
       
   554         }
       
   555     
       
   556     // Cleanup.
       
   557     timeZones.Close();
       
   558     timeZoneOffsets.Close();
       
   559 
       
   560     // Get all the localized timezones for the current timezone ID.
       
   561     CTzLocalizedTimeZone* localizedTimeZone( NULL );
       
   562     CTzLocalizer* tzLocalizer( NULL ); 
       
   563     TRAPD( errVal, tzLocalizer = CTzLocalizer::NewL() );
       
   564     if( tzLocalizer && ( !errVal ) )
       
   565         {
       
   566         // Get the currently set localized timezone.
       
   567         CleanupStack::PushL( tzLocalizer );
       
   568         TRAPD( errVal, localizedTimeZone = tzLocalizer->GetLocalizedTimeZoneL( timeZoneId->TimeZoneNumericID() ) );
       
   569 
       
   570         if( ( localizedTimeZone ) && ( !errVal ) )
       
   571             {
       
   572             CleanupStack::PushL( localizedTimeZone );
       
   573     
       
   574             // Get the frequently used localized city.
       
   575             CTzLocalizedCity* localizedCity = tzLocalizer->GetFrequentlyUsedZoneCityL( CTzLocalizedTimeZone::ECurrentZone );
       
   576             CleanupStack::PushL( localizedCity );
       
   577 
       
   578             // Get all the city groups.
       
   579             CTzLocalizedCityGroupArray* cityGroupArray = tzLocalizer->GetAllCityGroupsL( CTzLocalizer::ETzAlphaNameAscending );
       
   580             CleanupStack::PushL( cityGroupArray );
       
   581 
       
   582             // Get the index of the country corresponding to the city group ID.
       
   583             TInt countryIndex( 1 );
       
   584     
       
   585             for( TInt index( KErrNone ); index < cityGroupArray->Count(); index++ )
       
   586                 {       
       
   587                 if( localizedCity->GroupId() == cityGroupArray->At( index ).Id() )
       
   588                     {
       
   589                     countryIndex = index;
       
   590                     }
       
   591                 }
       
   592 
       
   593             // Get all the cities within the currently set country.
       
   594             CTzLocalizedCityArray* cityList = tzLocalizer->GetCitiesInGroupL( ( cityGroupArray->At( countryIndex ) ).Id(), 
       
   595                                                                               CTzLocalizer::ETzAlphaNameAscending );
       
   596             CleanupStack::PushL( cityList );
       
   597             
       
   598             // Check if automatic time update is enabled.
       
   599             TBool timeUpdateOn( EFalse );       
       
   600             RClkSrvInterface clkSrvIf;  
       
   601 
       
   602             // Connect to clockserver
       
   603             TInt errorVal( clkSrvIf.Connect() );
       
   604 
       
   605             if( KErrNone == errorVal )
       
   606                 {
       
   607                 // First check if automatic time update is enabled.   
       
   608                 errorVal = clkSrvIf.IsAutoTimeUpdateOn( timeUpdateOn );
       
   609                 }
       
   610 
       
   611             // Check if the country contains only one city or if automatic time update is on.
       
   612             if( 1 == cityList->Count() || timeUpdateOn )
       
   613                 {
       
   614                 // If yes, then display only the country name.
       
   615                 locationName.Copy( cityGroupArray->At( countryIndex ).Name() );
       
   616                 }
       
   617             else
       
   618                 {
       
   619                 // Automatic time update is disabled. Display the city name.
       
   620                 locationName.Copy( localizedCity->Name() );
       
   621                 }
       
   622             
       
   623             // Close the handle to the clockserver.
       
   624             clkSrvIf.Close();
       
   625 
       
   626             // Cleanup.
       
   627             CleanupStack::PopAndDestroy( cityList );
       
   628             CleanupStack::PopAndDestroy( cityGroupArray );
       
   629             CleanupStack::PopAndDestroy( localizedCity );
       
   630             CleanupStack::PopAndDestroy( localizedTimeZone );
       
   631             }
       
   632         // Cleanup.
       
   633         CleanupStack::PopAndDestroy( tzLocalizer );
       
   634         }
       
   635     
       
   636     // Cleanup.
       
   637     CleanupStack::PopAndDestroy( timeZoneId );
       
   638     CleanupStack::PopAndDestroy( &tzHandle );
       
   639 
       
   640     // Now construct the GMT +/-X string.
       
   641     TInt tempOffset( gmtOffset );
       
   642     TInt offsetHours( tempOffset / KHour );
       
   643     TInt offsetMinutes( KErrNone );
       
   644     TGmtOffsetText offsetText;
       
   645 
       
   646     if( KErrNone < tempOffset )
       
   647         {
       
   648         // We have a positive offset. Append the + character.
       
   649         offsetMinutes = gmtOffset - offsetHours * KHour;
       
   650         offsetString += KPlusGMT;
       
   651         }
       
   652     else if( KErrNone > tempOffset )
       
   653         {
       
   654         // Negative offset. Append the - character.
       
   655         offsetMinutes = -( gmtOffset - offsetHours * KHour );
       
   656         offsetString += KMinusGMT;
       
   657         }
       
   658     else
       
   659         {
       
   660         // We dont have an offset. We are at GMT zone.
       
   661         offsetString += KSingleSpace;
       
   662         }
       
   663     // Append the hour component.
       
   664     offsetText.Num( offsetHours );
       
   665     offsetString += offsetText;
       
   666     
       
   667     // Append the time separator.
       
   668     const TInt KSeparIndex( 1 );
       
   669     offsetString.Append( TLocale().TimeSeparator( KSeparIndex ) );
       
   670     
       
   671     // If the minute component is less than 10, append a '0'
       
   672     if ( KErrNone <= offsetMinutes && offsetMinutes < 10 )
       
   673         {
       
   674         offsetString += KZero;
       
   675         }
       
   676     // Append the minute component.
       
   677     offsetText.Num( offsetMinutes );
       
   678     offsetString += offsetText;
       
   679     offsetString += KPDF;
       
   680 
       
   681     // These will hold the complete zone information displayed on the main view.
       
   682     if( iLocationString )
       
   683         {
       
   684         delete iLocationString;
       
   685         iLocationString = NULL;
       
   686         }
       
   687     if( iTimeZoneString )
       
   688         {
       
   689         delete iTimeZoneString;
       
   690         iTimeZoneString = NULL;
       
   691         }
       
   692     
       
   693     // The GMT prefix which is prepended before the offset and zone information.
       
   694     HBufC* gmtPrefixText = StringLoader::LoadLC( R_QTN_CLK_NITZ_GMT, iCoeEnv );
       
   695     
       
   696     // Construct the strings to the displayed.
       
   697     iTimeZoneString = HBufC::NewL( gmtPrefixText->Length() + offsetString.Length() );
       
   698     iLocationString = HBufC::NewL( locationName.Length() );
       
   699     // First the timezone string.    
       
   700     TPtr timeZonePtr = iTimeZoneString->Des();
       
   701     timeZonePtr += *gmtPrefixText;
       
   702     timeZonePtr += offsetString;
       
   703     
       
   704     // Then the location name.
       
   705     TPtr zoneInfoPtr = iLocationString->Des();
       
   706     if( locationName.Length() )
       
   707         {
       
   708         zoneInfoPtr += locationName;
       
   709         }
       
   710     
       
   711     // Cleanup.
       
   712     CleanupStack::PopAndDestroy( gmtPrefixText );
       
   713 	
       
   714 	__PRINTS( "CClockMainContainer::SetZoneInfoL - Exit" );
       
   715     }
       
   716 
       
   717 // ---------------------------------------------------------
       
   718 // CClockMainContainer::ResetMarqueeLabelL
       
   719 // rest of the details are commented in the header
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 void CClockMainContainer::ResetMarqueeLabelL()
       
   723     {
       
   724     __PRINTS( "CClockMainContainer::ResetMarqueeLabelL - Entry" );
       
   725     
       
   726     // Reset the label so that it marquees again.
       
   727     if( iLocationLabel )
       
   728         {
       
   729         iLocationLabel->ResetMarquee();
       
   730         }
       
   731     
       
   732     __PRINTS( "CClockMainContainer::ResetMarqueeLabelL - Exit" );
       
   733     }
       
   734 
       
   735 // ---------------------------------------------------------
       
   736 // CClockMainContainer::SizeChanged
       
   737 // rest of the details are commented in the header
       
   738 // ---------------------------------------------------------
       
   739 //
       
   740 void CClockMainContainer::SizeChanged()
       
   741     {
       
   742 	__PRINTS( "CClockMainContainer::SizeChanged - Entry" );
       
   743 	
       
   744     TRect paneRect = this->Rect();
       
   745     // Update the background context.
       
   746     iBgContext->SetRect( paneRect );
       
   747     
       
   748     // The clock main rect.
       
   749     TAknLayoutRect mainRect;
       
   750     // The rect for the skinnable clock.
       
   751     TAknLayoutRect skinClockRect;
       
   752     // The rect for the listbox.
       
   753     TAknLayoutRect listBoxRect;
       
   754     
       
   755     // Get the layout for the main rect.
       
   756     mainRect.LayoutRect( paneRect, AknLayoutScalable_Apps::main_clock2_pane().LayoutLine() );
       
   757     
       
   758     if( Layout_Meta_Data::IsLandscapeOrientation() )
       
   759         {
       
   760         listBoxRect.LayoutRect( mainRect.Rect(), AknLayoutScalable_Apps::listscroll_gen_pane_cp06( 1 ).LayoutLine() );
       
   761         skinClockRect.LayoutRect( mainRect.Rect(),
       
   762                                   AknLayoutScalable_Apps::popup_clock_analogue_window_cp03( KVGALandscapeVariant ).LayoutLine() );
       
   763         }
       
   764     else
       
   765         {
       
   766         listBoxRect.LayoutRect( mainRect.Rect(), AknLayoutScalable_Apps::listscroll_gen_pane_cp06( 0 ).LayoutLine() );
       
   767         skinClockRect.LayoutRect( mainRect.Rect(),
       
   768                                   AknLayoutScalable_Apps::popup_clock_analogue_window_cp03( KVGAPortraitVariant ).LayoutLine() );
       
   769         }
       
   770     
       
   771     // Update the skinnable clock.
       
   772     iSkinnableClock->SetExtent( skinClockRect.Rect().iTl, skinClockRect.Rect().Size() );
       
   773     iSkinnableClock->UpdateDisplay();
       
   774     
       
   775     // Update the listbox.
       
   776     iListBox->SetExtent( listBoxRect.Rect().iTl, listBoxRect.Rect().Size() );
       
   777 	
       
   778 	__PRINTS( "CClockMainContainer::SizeChanged - Exit" );
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------
       
   782 // CClockMainContainer::CountComponentControls
       
   783 // rest of the details are commented in the header
       
   784 // ---------------------------------------------------------
       
   785 //
       
   786 TInt CClockMainContainer::CountComponentControls() const
       
   787     {
       
   788 	__PRINTS( "CClockMainContainer::CountComponentControls - Entry" );
       
   789 	
       
   790 	__PRINTS( "CClockMainContainer::CountComponentControls - Exit" );
       
   791 	
       
   792     return 2;
       
   793     }
       
   794 
       
   795 // ---------------------------------------------------------
       
   796 // CClockMainContainer::ComponentControl
       
   797 // rest of the details are commented in the header
       
   798 // ---------------------------------------------------------
       
   799 //  
       
   800 CCoeControl* CClockMainContainer::ComponentControl( TInt aIndex ) const
       
   801     {
       
   802 	__PRINTS( "CClockMainContainer::ComponentControl - Entry" );
       
   803 	
       
   804     switch( aIndex )
       
   805         {
       
   806         case 0:
       
   807             {
       
   808 			__PRINTS( "CClockMainContainer::ComponentControl - Exit" );
       
   809 			
       
   810             // Return the skinnable clock.
       
   811             return iSkinnableClock;
       
   812             }
       
   813             
       
   814         case 1:
       
   815             {
       
   816 			__PRINTS( "CClockMainContainer::ComponentControl - Exit" );
       
   817 			
       
   818             // Return the listbox.
       
   819             return iListBox;
       
   820             }
       
   821         
       
   822         default:
       
   823             {
       
   824 			__PRINTS( "CClockMainContainer::ComponentControl - Exit" );
       
   825 			
       
   826             return NULL;
       
   827             }
       
   828         }
       
   829     }
       
   830 
       
   831 // ---------------------------------------------------------
       
   832 // CClockMainContainer::MopSupplyObject
       
   833 // rest of the details are commented in the header
       
   834 // ---------------------------------------------------------
       
   835 //
       
   836 TTypeUid::Ptr CClockMainContainer::MopSupplyObject( TTypeUid aId )
       
   837     {
       
   838 	__PRINTS( "CClockMainContainer::MopSupplyObject - Entry" );
       
   839 	
       
   840     if( MAknsControlContext::ETypeId == aId.iUid )
       
   841         {
       
   842 		__PRINTS( "CClockMainContainer::MopSupplyObject - Exit" );
       
   843 		
       
   844         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   845         }
       
   846 		
       
   847 	__PRINTS( "CClockMainContainer::MopSupplyObject - Exit" );
       
   848     
       
   849     return CCoeControl::MopSupplyObject( aId );
       
   850     }
       
   851 
       
   852 // ---------------------------------------------------------
       
   853 // CClockMainContainer::HandleResourceChange
       
   854 // rest of the details are commented in the header
       
   855 // ---------------------------------------------------------
       
   856 //
       
   857 void CClockMainContainer::HandleResourceChange( TInt aType )
       
   858     {
       
   859 	__PRINTS( "CClockMainContainer::HandleResourceChange - Entry" );
       
   860 	
       
   861     // If skinnable clock is present, let it handle the resource change.
       
   862     if( iSkinnableClock )
       
   863         {
       
   864         iSkinnableClock->HandleResourceChange( aType );
       
   865         }
       
   866     // Allow the listbox to handle the resource change.
       
   867     if( iListBox )
       
   868         {
       
   869         iListBox->HandleResourceChange( aType );
       
   870         }
       
   871     // Then let the controlenvironment handle the change.
       
   872     CCoeControl::HandleResourceChange( aType );
       
   873     
       
   874     switch( aType )
       
   875         {
       
   876 		case KEikMessageWindowsFadeChange:
       
   877         case KEikDynamicLayoutVariantSwitch:
       
   878             {
       
   879             SetRect( iView->ClientRect() );
       
   880 			// Destroy and reconstruct the label again so that it marquees whenever the orientation changes.
       
   881             ResetMarqueeLabelL();
       
   882             
       
   883           
       
   884             }
       
   885             break;
       
   886             
       
   887         case KAknsMessageSkinChange:
       
   888             {
       
   889             // First get the icon array from listbox item drawer.
       
   890             CArrayPtr< CGulIcon >* iconArray = iListBox->ItemDrawer()->FormattedCellData()->IconArray();
       
   891                      
       
   892             if( iconArray )
       
   893                 {
       
   894                 // Reset the iconArray.
       
   895                 iconArray->ResetAndDestroy();
       
   896                 delete iconArray;
       
   897                 iconArray = NULL;            
       
   898                 iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( NULL );
       
   899                 }
       
   900             
       
   901             // Reload the icons into the array.
       
   902             iconArray =  new( ELeave ) CAknIconArray( KNumOfIcons );
       
   903             CleanupStack::PushL( iconArray );
       
   904 
       
   905             CFbsBitmap* iconBitmap( NULL );
       
   906             CFbsBitmap* iconMask( NULL );
       
   907             CGulIcon* finalIcon( NULL );
       
   908 
       
   909             // First read the alarm icon.
       
   910             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
   911                     KAknsIIDQgnIndiAlarmAdd,
       
   912                     KAknsIIDQsnIconColors,
       
   913                     EAknsCIQsnIconColorsCG13,
       
   914                     iconBitmap,
       
   915                     iconMask,
       
   916                     AknIconUtils::AvkonIconFileName(),
       
   917                     EMbmAvkonQgn_indi_alarm_add,
       
   918                     EMbmAvkonQgn_indi_alarm_add_mask,
       
   919                     TRgb( NULL, NULL, 255 ) );
       
   920             CleanupStack::PushL( iconBitmap );
       
   921             CleanupStack::PushL( iconMask );
       
   922             // Construct the icon.
       
   923             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   924             CleanupStack::PushL( finalIcon );
       
   925             // Append the above icon to the array.
       
   926             iconArray->AppendL( finalIcon );
       
   927             // Cleanup.
       
   928             CleanupStack::Pop( finalIcon );
       
   929             CleanupStack::Pop( iconMask );
       
   930             CleanupStack::Pop( iconBitmap );
       
   931 
       
   932             // Now load the repeat icon.
       
   933             iconBitmap = NULL;
       
   934             iconMask = NULL;
       
   935 
       
   936             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
   937                     KAknsIIDQgnIndiRepeatAdd,
       
   938                     KAknsIIDQsnIconColors,
       
   939                     EAknsCIQsnIconColorsCG13,
       
   940                     iconBitmap,
       
   941                     iconMask,
       
   942                     KIconFileName,
       
   943                     EMbmClockappQgn_indi_repeat_add,
       
   944                     EMbmClockappQgn_indi_repeat_add_mask,
       
   945                     TRgb( NULL, NULL, 255 ) );
       
   946             CleanupStack::PushL( iconBitmap );
       
   947             CleanupStack::PushL( iconMask );
       
   948             // Construct the icon.
       
   949             finalIcon = NULL;
       
   950             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   951             CleanupStack::PushL( finalIcon );
       
   952             // Append the above icon to the array.
       
   953             iconArray->AppendL( finalIcon );
       
   954             // Cleanup.
       
   955             CleanupStack::Pop( finalIcon );
       
   956             CleanupStack::Pop( iconMask );
       
   957             CleanupStack::Pop( iconBitmap );
       
   958             
       
   959             // Read the inactive icon.
       
   960             iconBitmap = NULL;
       
   961             iconMask = NULL;
       
   962             
       
   963             // Create the color icon for the alarm inactive icon.
       
   964             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
   965                                          KAknsIIDQgnIndiAlarmInactiveAdd,
       
   966                                          KAknsIIDQsnIconColors,
       
   967                                          EAknsCIQsnIconColorsCG13,
       
   968                                          iconBitmap,
       
   969                                          iconMask,
       
   970                                          KIconFileName,
       
   971                                          EMbmClockappQgn_indi_alarm_inactive_add,
       
   972                                          EMbmClockappQgn_indi_alarm_inactive_add_mask,
       
   973                                          TRgb( NULL, NULL, 255 ) );
       
   974             CleanupStack::PushL( iconBitmap );
       
   975             CleanupStack::PushL( iconMask );
       
   976             
       
   977             // Construct the icon.
       
   978             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   979             CleanupStack::PushL( finalIcon );
       
   980             // Append the above icon to the array.
       
   981             iconArray->AppendL( finalIcon );
       
   982             // Cleanup.
       
   983             CleanupStack::Pop( finalIcon );
       
   984             CleanupStack::Pop( iconMask );
       
   985             CleanupStack::Pop( iconBitmap );
       
   986 
       
   987             // Now load a blank icon.
       
   988             iconBitmap = new( ELeave ) CFbsBitmap();
       
   989             CleanupStack::PushL( iconBitmap );
       
   990             iconMask = new( ELeave ) CFbsBitmap();
       
   991             CleanupStack::PushL( iconMask );
       
   992 
       
   993             iconBitmap->Create( TSize( NULL, NULL ), ENone );
       
   994             iconMask->Create( TSize( NULL, NULL ), ENone );
       
   995 
       
   996             // Construct the icon.
       
   997             finalIcon = NULL;
       
   998             finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
   999             CleanupStack::PushL( finalIcon );
       
  1000             // Append it to the icon array.
       
  1001             iconArray->AppendL( finalIcon );
       
  1002             // Cleanup.
       
  1003             CleanupStack::Pop( finalIcon );
       
  1004             CleanupStack::Pop( iconMask );
       
  1005             CleanupStack::Pop( iconBitmap );
       
  1006             
       
  1007             // Set the iconarray to the itemdrawer of the listbox.
       
  1008             iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );
       
  1009             CleanupStack::Pop( iconArray );
       
  1010             iconArray = NULL;
       
  1011             
       
  1012             // Delete the DST icon and refresh it again.
       
  1013             if( iDstIndicator )
       
  1014                 {
       
  1015                 delete iDstIndicator;
       
  1016                 iDstIndicator = NULL;
       
  1017                 }
       
  1018             if( iDstIndicatorMask )
       
  1019                 {
       
  1020                 delete iDstIndicatorMask;
       
  1021                 iDstIndicatorMask = NULL;
       
  1022                 }
       
  1023             AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
  1024                                          KAknsIIDQgnIndiDstAdd,
       
  1025                                          KAknsIIDQsnIconColors,
       
  1026                                          EAknsCIQsnIconColorsCG13,
       
  1027                                          iDstIndicator,
       
  1028                                          iDstIndicatorMask,
       
  1029                                          AknIconUtils::AvkonIconFileName(),
       
  1030                                          EMbmAvkonQgn_indi_dst_add,
       
  1031                                          EMbmAvkonQgn_indi_dst_add_mask,
       
  1032                                          TRgb( NULL, NULL, 255 ) );
       
  1033             }
       
  1034         }
       
  1035 		
       
  1036 	__PRINTS( "CClockMainContainer::HandleResourceChange - Exit" );
       
  1037     }
       
  1038 
       
  1039 // ---------------------------------------------------------
       
  1040 // CClockMainContainer::ConstructL
       
  1041 // rest of the details are commented in the header
       
  1042 // ---------------------------------------------------------
       
  1043 //    
       
  1044 void CClockMainContainer::ConstructL( CClockMainView* aView, const TRect& aRect, CClockAlarmArray* aAlarmArray )
       
  1045     {
       
  1046 	__PRINTS( "CClockMainContainer::ConstructL - Entry" );
       
  1047 	
       
  1048     iView = aView;
       
  1049     iAlarmArray = aAlarmArray;
       
  1050     
       
  1051 	CreateWindowL();
       
  1052     
       
  1053 	// Construct the basic skin context.
       
  1054 	iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,
       
  1055 	                                                       aRect,
       
  1056 	                                                       EFalse );
       
  1057 	
       
  1058 	// Here we load the two icons for alarm and repeated alarm.
       
  1059 	CArrayPtr< CGulIcon >* iconArray =  new( ELeave ) CAknIconArray( KNumOfIcons );
       
  1060 	CleanupStack::PushL( iconArray );
       
  1061 
       
  1062 	CFbsBitmap* iconBitmap( NULL );
       
  1063 	CFbsBitmap* iconMask( NULL );
       
  1064 	CGulIcon* finalIcon( NULL );
       
  1065 
       
  1066 	// First read the alarm icon.
       
  1067 	AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
  1068 	                             KAknsIIDQgnIndiAlarmAdd,
       
  1069 	                             KAknsIIDQsnIconColors,
       
  1070 	                             EAknsCIQsnIconColorsCG13,
       
  1071 	                             iconBitmap,
       
  1072 	                             iconMask,
       
  1073 	                             AknIconUtils::AvkonIconFileName(),
       
  1074 	                             EMbmAvkonQgn_indi_alarm_add,
       
  1075 	                             EMbmAvkonQgn_indi_alarm_add_mask,
       
  1076 	                             TRgb( NULL, NULL, 255 ) );
       
  1077 	CleanupStack::PushL( iconBitmap );
       
  1078 	CleanupStack::PushL( iconMask );
       
  1079 	// Construct the icon.
       
  1080 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
  1081 	CleanupStack::PushL( finalIcon );
       
  1082 	// Append the above icon to the array.
       
  1083 	iconArray->AppendL( finalIcon );
       
  1084 	// Cleanup.
       
  1085 	CleanupStack::Pop( finalIcon );
       
  1086 	CleanupStack::Pop( iconMask );
       
  1087 	CleanupStack::Pop( iconBitmap );
       
  1088 	
       
  1089 	// Now load the repeat icon.
       
  1090 	iconBitmap = NULL;
       
  1091 	iconMask = NULL;
       
  1092 	
       
  1093 	AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
  1094 	                             KAknsIIDQgnIndiRepeatAdd,
       
  1095 	                             KAknsIIDQsnIconColors,
       
  1096 	                             EAknsCIQsnIconColorsCG13,
       
  1097 	                             iconBitmap,
       
  1098 	                             iconMask,
       
  1099 	                             KIconFileName,
       
  1100 	                             EMbmClockappQgn_indi_repeat_add,
       
  1101 	                             EMbmClockappQgn_indi_repeat_add_mask,
       
  1102 	                             TRgb( NULL, NULL, 255 ) );
       
  1103 	CleanupStack::PushL( iconBitmap );
       
  1104 	CleanupStack::PushL( iconMask );
       
  1105 	// Construct the icon.
       
  1106 	finalIcon = NULL;
       
  1107 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
  1108 	CleanupStack::PushL( finalIcon );
       
  1109 	// Append the above icon to the array.
       
  1110 	iconArray->AppendL( finalIcon );
       
  1111 	// Cleanup.
       
  1112 	CleanupStack::Pop( finalIcon );
       
  1113 	CleanupStack::Pop( iconMask );
       
  1114 	CleanupStack::Pop( iconBitmap );
       
  1115 	
       
  1116 	// Read the inactive icon.
       
  1117     iconBitmap = NULL;
       
  1118     iconMask = NULL;
       
  1119     
       
  1120     // Create the color icon for the alarm inactive icon.
       
  1121     AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
  1122                                  KAknsIIDQgnIndiAlarmInactiveAdd,
       
  1123                                  KAknsIIDQsnIconColors,
       
  1124                                  EAknsCIQsnIconColorsCG13,
       
  1125                                  iconBitmap,
       
  1126                                  iconMask,
       
  1127                                  KIconFileName,
       
  1128                                  EMbmClockappQgn_indi_alarm_inactive_add,
       
  1129                                  EMbmClockappQgn_indi_alarm_inactive_add_mask,
       
  1130                                  TRgb( NULL, NULL, 255 ) );
       
  1131     CleanupStack::PushL( iconBitmap );
       
  1132     CleanupStack::PushL( iconMask );
       
  1133     
       
  1134     // Construct the icon.
       
  1135     finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
  1136     CleanupStack::PushL( finalIcon );
       
  1137     // Append the above icon to the array.
       
  1138     iconArray->AppendL( finalIcon );
       
  1139     // Cleanup.
       
  1140     CleanupStack::Pop( finalIcon );
       
  1141     CleanupStack::Pop( iconMask );
       
  1142     CleanupStack::Pop( iconBitmap );
       
  1143 	
       
  1144 	// Now load a blank icon.
       
  1145 	iconBitmap = new( ELeave ) CFbsBitmap();
       
  1146 	CleanupStack::PushL( iconBitmap );
       
  1147 	iconMask = new( ELeave ) CFbsBitmap();
       
  1148 	CleanupStack::PushL( iconMask );
       
  1149 	
       
  1150 	iconBitmap->Create( TSize( NULL, NULL ), ENone );
       
  1151 	iconMask->Create( TSize( NULL, NULL ), ENone );
       
  1152 	
       
  1153 	// Construct the icon.
       
  1154 	finalIcon = NULL;
       
  1155 	finalIcon = CGulIcon::NewL( iconBitmap, iconMask );
       
  1156 	CleanupStack::PushL( finalIcon );
       
  1157 	// Append it to the icon array.
       
  1158 	iconArray->AppendL( finalIcon );
       
  1159 	// Cleanup.
       
  1160 	CleanupStack::Pop( finalIcon );
       
  1161 	CleanupStack::Pop( iconMask );
       
  1162 	CleanupStack::Pop( iconBitmap );
       
  1163 	
       
  1164 	// Construct the listbox.
       
  1165 	//Single click integration
       
  1166     iListBox = new( ELeave ) CAknDoubleStyleListBox;
       
  1167 
       
  1168 	iListBox->ConstructL( this, NULL );
       
  1169 	iListBox->SetContainerWindowL( *this );
       
  1170 	
       
  1171 	// Set the display properties of the listbox.
       
  1172 	iListBox->CreateScrollBarFrameL( ETrue );
       
  1173 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
  1174 														 CEikScrollBarFrame::EAuto );
       
  1175 	iListBox->Model()->SetItemTextArray( iAlarmArray );
       
  1176 	iListBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray );
       
  1177 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1178 	
       
  1179 	// Set the observer of the listbox events.
       
  1180 	iListBox->SetListBoxObserver( this );
       
  1181 	//Single click integration
       
  1182     // Disable list stretching so alarm items are displayed correctly
       
  1183     iListBox->EnableStretching( EFalse ); 
       
  1184 
       
  1185 
       
  1186 
       
  1187 	// Set the listbox layout.
       
  1188 	TAknLayoutRect listBoxRect;
       
  1189 	TInt layoutOrientation = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
  1190 	
       
  1191 	TAknLayoutRect listRect;
       
  1192 	// Get the main clock rect.
       
  1193 	listRect.LayoutRect( aRect, AknLayoutScalable_Apps::listscroll_gen_pane_cp06( layoutOrientation ).LayoutLine() );
       
  1194 
       
  1195 	// Get the skinnable clock rect.
       
  1196 	listBoxRect.LayoutRect( listRect.Rect(), AknLayoutScalable_Apps::listscroll_gen_pane_cp06( layoutOrientation ).LayoutLine() );
       
  1197 	iListBox->SetRect( listBoxRect.Rect() );//.iTl, listBoxRect.Rect().Size() );
       
  1198 	
       
  1199     // Set the empty list text.
       
  1200     iListBox->View()->SetListEmptyTextL( _L("") );
       
  1201     iListBox->ActivateL();
       
  1202 	
       
  1203     // Cleanup.
       
  1204 	CleanupStack::Pop( iconArray );
       
  1205 	
       
  1206     // Add the icon for DST indicator.
       
  1207     AknsUtils::CreateColorIconL( AknsUtils::SkinInstance(),
       
  1208                                  KAknsIIDQgnIndiDstAdd,
       
  1209                                  KAknsIIDQsnIconColors,
       
  1210                                  EAknsCIQsnIconColorsCG13,
       
  1211                                  iDstIndicator,
       
  1212                                  iDstIndicatorMask,
       
  1213                                  AknIconUtils::AvkonIconFileName(),
       
  1214                                  EMbmAvkonQgn_indi_dst_add,
       
  1215                                  EMbmAvkonQgn_indi_dst_add_mask,
       
  1216                                  TRgb( NULL, NULL, 255 ) );
       
  1217     
       
  1218     iLocationLabel = new ( ELeave ) CClockMarqueeLabel();
       
  1219     iLocationLabel->SetContainerWindowL( *this );
       
  1220     iLocationLabel->ConstructL( ETrue );
       
  1221     iLocationLabel->SetTextL( KNullDesC );
       
  1222     iLocationLabel->SetBackground( iBgContext );
       
  1223     iLocationLabel->MakeVisible( ETrue );
       
  1224     
       
  1225     TAknLayoutRect mainRect;
       
  1226     // Get the main clock rect.
       
  1227     mainRect.LayoutRect( aRect, AknLayoutScalable_Apps::main_clock2_pane().LayoutLine() );
       
  1228 
       
  1229     TAknLayoutRect skinClockRect;
       
  1230     TInt displayOrientation( Layout_Meta_Data::IsLandscapeOrientation() ? KVGALandscapeVariant : KVGAPortraitVariant );
       
  1231     // Get the skinnable clock rect.
       
  1232     skinClockRect.LayoutRect( mainRect.Rect(),
       
  1233             AknLayoutScalable_Apps::popup_clock_analogue_window_cp03( displayOrientation ).LayoutLine() );
       
  1234 
       
  1235     // Construct the skinnable clock.
       
  1236     iSkinnableClock = CAknSkinnableClock::NewL( this, ETrue, EFalse );
       
  1237     // Set the size of the clock.
       
  1238     iSkinnableClock->SetExtent( skinClockRect.Rect().iTl, skinClockRect.Rect().Size() );
       
  1239     
       
  1240     SetRect( aRect );
       
  1241     
       
  1242     iSkinnableClock->ActivateL();
       
  1243     							 
       
  1244 	__PRINTS( "CClockMainContainer::ConstructL - Exit" );
       
  1245     }
       
  1246 
       
  1247 // ---------------------------------------------------------
       
  1248 // CClockMainContainer::CClockMainContainer
       
  1249 // rest of the details are commented in the header
       
  1250 // ---------------------------------------------------------
       
  1251 //    
       
  1252 CClockMainContainer::CClockMainContainer()
       
  1253     {
       
  1254 	__PRINTS( "CClockMainContainer::CClockMainContainer - Entry" );
       
  1255 	
       
  1256     // No implementation yet.
       
  1257 	
       
  1258 	__PRINTS( "CClockMainContainer::CClockMainContainer - Exit" );
       
  1259     }
       
  1260 
       
  1261 // ---------------------------------------------------------
       
  1262 // CClockMainContainer::DrawMainViewText
       
  1263 // rest of the details are commented in the header
       
  1264 // ---------------------------------------------------------
       
  1265 //  
       
  1266 void CClockMainContainer::DrawMainViewText( CWindowGc& aWindowGc ) const
       
  1267     {
       
  1268 	__PRINTS( "CClockMainContainer::DrawMainViewText - Entry" );
       
  1269 	
       
  1270     TAknLayoutText layoutText;
       
  1271     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  1272     TRgb cachedColor;
       
  1273     TInt displayOrientation( Layout_Meta_Data::IsLandscapeOrientation() ? KVGALandscapeVariant : KVGAPortraitVariant );
       
  1274 
       
  1275     // Get the cached color.
       
  1276     AknsUtils::GetCachedColor( skinInstance, cachedColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
  1277 
       
  1278     TAknLayoutRect parentRect;
       
  1279     parentRect.LayoutRect( Rect(), AknLayoutScalable_Apps::main_clock2_pane().LayoutLine() );
       
  1280         
       
  1281     TRect mainClockPane( parentRect.Rect() );
       
  1282    
       
  1283     // Get the layout for the day string.
       
  1284     layoutText.LayoutText( mainClockPane, AknLayoutScalable_Apps::main_clock2_pane_t1( displayOrientation ).LayoutLine() );
       
  1285 
       
  1286     TPtr dayStringPtr = iDayNameString->Des();
       
  1287     // Day long format.
       
  1288     layoutText.DrawText( aWindowGc, *iDayNameString, ETrue, cachedColor );
       
  1289     
       
  1290     // Get the layout for the datestring.
       
  1291     layoutText.LayoutText( mainClockPane, AknLayoutScalable_Apps::main_clock2_pane_t2( displayOrientation ).LayoutLine() );
       
  1292 
       
  1293     TPtr dateStringPtr = iDateString->Des();
       
  1294     // For mirrored languages.
       
  1295     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( dateStringPtr );
       
  1296     // Date long format
       
  1297     layoutText.DrawText( aWindowGc, *iDateString, ETrue, cachedColor );
       
  1298     
       
  1299     // Get the layout for the timezone string.
       
  1300     layoutText.LayoutText( mainClockPane, AknLayoutScalable_Apps::main_clock2_pane_t3( Layout_Meta_Data::IsLandscapeOrientation() ).LayoutLine() );
       
  1301 
       
  1302     TPtr timeZonePtr = iTimeZoneString->Des();
       
  1303     // This is for mirrored languages.
       
  1304     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( timeZonePtr );
       
  1305     // The timezone string.
       
  1306     layoutText.DrawText( aWindowGc, *iTimeZoneString, ETrue, cachedColor );
       
  1307     
       
  1308     // Get the layout for the country string.
       
  1309     TAknTextComponentLayout labelLayout;
       
  1310     labelLayout = AknLayoutScalable_Apps::main_clock2_pane_t4( Layout_Meta_Data::IsLandscapeOrientation() );
       
  1311     AknLayoutUtils::LayoutLabel( iLocationLabel, parentRect.Rect(), labelLayout.LayoutLine() );
       
  1312     
       
  1313     // Set the label for the text and start marqueeing.
       
  1314     iLocationLabel->SetLabelTextL( *iLocationString );
       
  1315     iLocationLabel->StartMarquee();
       
  1316     iLocationLabel->RedrawRect( iLocationLabel->Rect() );
       
  1317 
       
  1318 	// We display empty text only if there are no alarms set.
       
  1319 	// if( !iAlarmArray->MdcaCount() )
       
  1320 		// {
       
  1321 		// Set the listbox layout.
       
  1322 		// TAknLayoutRect listRect;
       
  1323 		// Get the main clock rect.
       
  1324 		// listRect.LayoutRect( mainClockPane, AknLayoutScalable_Apps::listscroll_gen_pane_cp06( Layout_Meta_Data::IsLandscapeOrientation() ).LayoutLine() );
       
  1325 		
       
  1326 		// Get the rect for the empty text.
       
  1327 		// layoutText.LayoutText( listRect.Rect(), AknLayoutScalable_Apps::listscroll_gen_pane_cp06_t1( Layout_Meta_Data::IsLandscapeOrientation() ).LayoutLine() );
       
  1328 		// Draw the text.
       
  1329 		// layoutText.DrawText( aWindowGc, *iNoAlarmsText, ETrue, cachedColor );
       
  1330 		//}
       
  1331     
       
  1332 	__PRINTS( "CClockMainContainer::DrawMainViewText - Exit" );
       
  1333     }
       
  1334 
       
  1335 // ---------------------------------------------------------
       
  1336 // CClockMainContainer::IsDstOnL
       
  1337 // rest of the details are commented in the header
       
  1338 // ---------------------------------------------------------
       
  1339 // 
       
  1340 TBool CClockMainContainer::IsDstOnL( TInt aTimeZoneId )
       
  1341     {
       
  1342 	__PRINTS( "CClockMainContainer::IsDstOnL - Entry" );
       
  1343 	
       
  1344     TBool returnVal( EFalse );
       
  1345     CTzId* timeZoneId = CTzId::NewL( aTimeZoneId );
       
  1346     CleanupStack::PushL( timeZoneId );
       
  1347     
       
  1348     RTz tzHandle;
       
  1349     User::LeaveIfError( tzHandle.Connect() );
       
  1350     CleanupClosePushL( tzHandle );
       
  1351     
       
  1352     returnVal = tzHandle.IsDaylightSavingOnL( *timeZoneId );
       
  1353 
       
  1354     tzHandle.Close();
       
  1355     CleanupStack::PopAndDestroy( &tzHandle );
       
  1356     CleanupStack::PopAndDestroy( timeZoneId );
       
  1357 	
       
  1358 	__PRINTS( "CClockMainContainer::IsDstOnL - Exit" );
       
  1359     
       
  1360     return returnVal;
       
  1361     }
       
  1362 
       
  1363 // ---------------------------------------------------------
       
  1364 // CClockMainContainer::GetOffSetWithDstL
       
  1365 // rest of the details are commented in the header
       
  1366 // ---------------------------------------------------------
       
  1367 // 
       
  1368 void CClockMainContainer::GetOffSetWithDstL( TInt32& aDstOffset, const CTzId& aTzId )
       
  1369     {
       
  1370 	__PRINTS( "CClockMainContainer::GetOffSetWithDstL - Entry" );
       
  1371 	
       
  1372     RTz rTz;
       
  1373     User::LeaveIfError( rTz.Connect() );
       
  1374     CleanupClosePushL( rTz );
       
  1375     
       
  1376     // Local time
       
  1377     TTime homeTime;
       
  1378     homeTime.HomeTime();    
       
  1379     
       
  1380     TDateTime dateTime;
       
  1381     dateTime = homeTime.DateTime();
       
  1382     
       
  1383     // Get the CTzRules for the current year and for the given time zone id.
       
  1384     CTzRules* tzRules = rTz.GetTimeZoneRulesL( aTzId, 
       
  1385                                                dateTime.Year(), 
       
  1386                                                dateTime.Year(), 
       
  1387                                                ETzWallTimeReference );
       
  1388     CleanupStack::PushL( tzRules );
       
  1389     
       
  1390     // Get the Actualised rules for the same year. These are the DST rules from which we get the iNewOffset.
       
  1391     CVTzActualisedRules *vActualisedRules = CVTzActualisedRules::NewL(
       
  1392                                                     homeTime.DateTime().Year(), 
       
  1393                                                     homeTime.DateTime().Year() );
       
  1394     CleanupStack::PushL( vActualisedRules );
       
  1395     tzRules->GetActualisedRulesL( *vActualisedRules );
       
  1396     
       
  1397     // This way of fetching initial offset is being used rather than tzRules->InitialStdTimeOffset()
       
  1398     // because in some cases, the offset returned is incorrect. (For ex: Argentina and Canada/Iqaluit)
       
  1399     RArray< TInt > timeZones;
       
  1400     RArray< TInt > zoneOffsets;
       
  1401 
       
  1402     // Append the current timezone ID and request for the standard offset
       
  1403     timeZones.Append( aTzId.TimeZoneNumericID() );
       
  1404     rTz.GetOffsetsForTimeZoneIdsL( timeZones, zoneOffsets );
       
  1405     
       
  1406     // The initial offset or the standard offset (w/o DST)
       
  1407     TInt initialTimeZoneOffset = zoneOffsets[ 0 ];
       
  1408     
       
  1409     // Close the resource handles
       
  1410     timeZones.Close();
       
  1411     zoneOffsets.Close();
       
  1412     
       
  1413     // The number of actualised rules
       
  1414     TInt ruleCount = vActualisedRules->Count();
       
  1415     
       
  1416     for( TInt ruleIndex( KZerothRule ); ruleIndex < ruleCount; ruleIndex++ )
       
  1417         {
       
  1418         const TVTzActualisedRule& tVTzactRule = ( *vActualisedRules )[ ruleIndex ];
       
  1419         
       
  1420         // If the standard offset and the new offset do not match then we have a dst offset.
       
  1421         // Technically if a timezone has DST then it can have a max of two offsets. One is the standard which doesn't show the 
       
  1422         // DST usage, and the other is the DST offset which is standard offset + the amount of DST
       
  1423         if( initialTimeZoneOffset != tVTzactRule.iNewOffset )
       
  1424             {
       
  1425             aDstOffset = tVTzactRule.iNewOffset;
       
  1426             CleanupStack::PopAndDestroy( vActualisedRules );
       
  1427             CleanupStack::PopAndDestroy( tzRules );
       
  1428             CleanupStack::PopAndDestroy( &rTz );
       
  1429 			
       
  1430 			__PRINTS( "CClockMainContainer::GetOffSetWithDstL - Exit" );
       
  1431 			
       
  1432             return;
       
  1433             }
       
  1434         }
       
  1435     CleanupStack::PopAndDestroy( vActualisedRules );
       
  1436     CleanupStack::PopAndDestroy( tzRules );
       
  1437     CleanupStack::PopAndDestroy( &rTz );
       
  1438 	
       
  1439 	__PRINTS( "CClockMainContainer::GetOffSetWithDstL - Exit" );
       
  1440     }
       
  1441 
       
  1442 // ---------------------------------------------------------
       
  1443 // CClockMainContainer::GetHelpContext
       
  1444 // rest of the details are commented in the header
       
  1445 // ---------------------------------------------------------
       
  1446 //
       
  1447 void CClockMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1448 {
       
  1449     aContext.iMajor = KClockAppUid;
       
  1450     if( GetAutoTimeUpdateState () )
       
  1451         {
       
  1452         aContext.iContext = KCLK_HLP_REAL_TIME_CLOCK_AN;
       
  1453         }
       
  1454     else
       
  1455         {
       
  1456         aContext.iContext = KCLK_HLP_REAL_TIME_CLOCK_IN;
       
  1457         }
       
  1458 }
       
  1459 
       
  1460 // ---------------------------------------------------------
       
  1461 // CClockMainContainer::GetAutoTimeUpdateState
       
  1462 // rest of the details are commented in the header
       
  1463 // ---------------------------------------------------------
       
  1464 //
       
  1465 TBool CClockMainContainer::GetAutoTimeUpdateState() const
       
  1466 {
       
  1467         // Check if automatic time update is enabled.
       
  1468         TBool timeUpdateOn( EFalse );       
       
  1469         RClkSrvInterface clkSrvIf;  
       
  1470 
       
  1471         // Connect to clockserver
       
  1472         TInt errorVal( clkSrvIf.Connect() );
       
  1473 
       
  1474         if( KErrNone == errorVal )
       
  1475             {
       
  1476             // First check if automatic time update is enabled.   
       
  1477             errorVal = clkSrvIf.IsAutoTimeUpdateOn( timeUpdateOn );
       
  1478             }
       
  1479         return timeUpdateOn;
       
  1480 }
       
  1481 
       
  1482 // End of file