clock2/clockui/uilayer/clockmainview/src/clockalarmarray.cpp
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     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 CClockAlarmArray class.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <coemain.h>
       
    20 #include <AknUtils.h>
       
    21 #include <clock.rsg>
       
    22 #include <centralrepository.h>
       
    23 #include <AknFepInternalCRKeys.h>
       
    24 #include <StringLoader.h>
       
    25 
       
    26 // User includes
       
    27 #include "clockalarmarray.h"
       
    28 #include "clkuialarmmodel.h"
       
    29 #include "clock_debug.h"
       
    30 
       
    31 // Constants
       
    32 const TInt KTimeStringLength( 25 );
       
    33 const TInt KFirstAlarmIndex( 0 );
       
    34 
       
    35 // Literals
       
    36 _LIT( KFieldSeparator, "\t" );
       
    37 _LIT( KReplaceWhitespaceChars, "\x0009\x000A\x000B\x000C\x000D\x2028\x2029" );
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CClockAlarmArray::NewL
       
    41 // rest of the details are commented in the header
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44 CClockAlarmArray* CClockAlarmArray::NewL( CClkUiAlarmModel* aAlarmModel, CCoeEnv* aCoeEnv )
       
    45     {
       
    46 	__PRINTS( "CClockAlarmArray::NewL - Entry" );
       
    47 	
       
    48     CClockAlarmArray* self = new( ELeave ) CClockAlarmArray;
       
    49     CleanupStack::PushL( self );
       
    50     
       
    51     self->ConstructL( aAlarmModel, aCoeEnv );
       
    52     
       
    53     CleanupStack::Pop( self );
       
    54 	
       
    55 	__PRINTS( "CClockAlarmArray::NewL - Exit" );
       
    56     
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CClockAlarmArray::~CClockAlarmArray
       
    62 // rest of the details are commented in the header
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 CClockAlarmArray::~CClockAlarmArray()
       
    66     {
       
    67 	__PRINTS( "CClockAlarmArray::~CClockAlarmArray - Entry" );
       
    68 	
       
    69     if( iOccuranceList )
       
    70         {
       
    71         delete iOccuranceList;
       
    72         iOccuranceList = NULL;
       
    73         }
       
    74     if( iWorkDaysList )
       
    75         {
       
    76         delete iWorkDaysList;
       
    77         iWorkDaysList = NULL;
       
    78         }
       
    79     if( iShortWorkDaysList )
       
    80         {
       
    81         delete iShortWorkDaysList;
       
    82         iShortWorkDaysList = NULL;
       
    83         }
       
    84     if( iListBoxEntry )
       
    85         {
       
    86         delete iListBoxEntry;
       
    87         iListBoxEntry = NULL;
       
    88         }
       
    89     if( iAlarmInactiveText )
       
    90         {
       
    91         delete iAlarmInactiveText;
       
    92         iAlarmInactiveText = NULL;
       
    93         }
       
    94     if( iTimeFormat )
       
    95         {
       
    96         delete iTimeFormat;
       
    97         iTimeFormat = NULL;
       
    98         }
       
    99     if( iDate )
       
   100         {
       
   101         delete iDate;
       
   102         iDate = NULL;
       
   103         }
       
   104     if( iNewAlarmText )
       
   105         {
       
   106         delete iNewAlarmText;
       
   107         iNewAlarmText = NULL;
       
   108         }
       
   109     
       
   110     iAlarmIdArray.Close();
       
   111 	
       
   112 	__PRINTS( "CClockAlarmArray::~CClockAlarmArray - Exit" );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------
       
   116 // CClockAlarmArray::MdcaCount
       
   117 // rest of the details are commented in the header
       
   118 // ---------------------------------------------------------
       
   119 //
       
   120 TInt CClockAlarmArray::MdcaCount() const
       
   121     {
       
   122 	__PRINTS( "CClockAlarmArray::MdcaCount - Entry" );
       
   123 	
       
   124     TInt itemCount( KFirstAlarmIndex );
       
   125     // Iterate through the list and add only the active alarms.
       
   126     for( TInt index( KFirstAlarmIndex ); index < iAlarmIdArray.Count() && iAlarmIdArray[ index ] != 0; index++ )
       
   127         {
       
   128         SClkAlarmInfo alarmInformation;      
       
   129         TInt errorValue( iAlarmModel->ClockAlarmInfo( iAlarmIdArray[ index ], alarmInformation ) );
       
   130 
       
   131         // We return only active alarms.
       
   132         if( ( KErrNone == errorValue ) &&
       
   133             ( EAlarmStateInPreparation != alarmInformation.iState &&
       
   134               EAlarmStateNotified != alarmInformation.iState ) )
       
   135             {
       
   136             itemCount++;
       
   137             }
       
   138         }
       
   139 		
       
   140 	__PRINTS( "CClockAlarmArray::MdcaCount - Exit" );
       
   141 		
       
   142     return itemCount;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CClockAlarmArray::MdcaPoint
       
   147 // rest of the details are commented in the header
       
   148 // ---------------------------------------------------------
       
   149 //
       
   150 TPtrC16 CClockAlarmArray::MdcaPoint( TInt aIndex ) const
       
   151     {
       
   152 	__PRINTS( "CClockAlarmArray::MdcaPoint - Entry" );
       
   153     SClkAlarmInfo alarmInfo;
       
   154     TBuf< KTimeStringLength > timeString;
       
   155     TAlarmId alarmId;
       
   156 
       
   157     // First get the sorted alarm information for the given index.
       
   158     GetSortedAlmIdInfo( aIndex, alarmId, alarmInfo );
       
   159     // Re-initialize the item to construct a new listbox entry.
       
   160     iListBoxEntry->Des().Zero();
       
   161 
       
   162     TPtr listEntryPtr = iListBoxEntry->Des();
       
   163     
       
   164     // First format and construct the time part.
       
   165     TTime alarmTime = alarmInfo.iOrigExpiryTime;
       
   166     TDateTime alarmDateTime  = alarmInfo.iAlarmTime.DateTime();   
       
   167     TInt alarmDay = alarmTime.DayNoInWeek();    
       
   168 
       
   169     // The timestring formatter.
       
   170     HBufC* formatString( NULL );
       
   171     TRAP_IGNORE(
       
   172             formatString = StringLoader::LoadL( R_QTN_TIME_USUAL_WITH_ZERO, iEnv );
       
   173             alarmTime.FormatL( timeString, *formatString ); );
       
   174 
       
   175     AknTextUtils::LanguageSpecificNumberConversion( timeString );
       
   176     
       
   177     // Go to the first item.
       
   178     listEntryPtr.Append( KFieldSeparator );
       
   179     // First append the alarm expiry time.
       
   180     listEntryPtr.Append( timeString );
       
   181     // Then append a space.
       
   182     listEntryPtr.Append( KSingleSpace );
       
   183     
       
   184     // Here we append date or text depending on the type of the alarm.
       
   185     switch( alarmInfo.iRepeat )
       
   186         {
       
   187         case EAlarmRepeatDefintionRepeatOnce:
       
   188         case EAlarmRepeatDefintionRepeatNext24Hours:
       
   189             {
       
   190             // For once only alarm, the date will have to be appended to the list item.
       
   191             TDateString dateString;
       
   192             alarmTime.FormatL( dateString, *iDate );
       
   193             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( dateString );
       
   194 
       
   195             CRepository* cenRep( NULL );
       
   196             cenRep = CRepository::NewLC( KCRUidAknFep );
       
   197             TInt displayLanguage;
       
   198             // Get the current display language from CenRep.
       
   199             cenRep->Get( KAknFepLastUsedUILanguage, displayLanguage );
       
   200 
       
   201             // If Japanese
       
   202             if( displayLanguage == ELangJapanese )
       
   203                 {
       
   204                 // First the date and
       
   205                 listEntryPtr.Append( dateString );
       
   206                 listEntryPtr.Append( KSingleSpace );
       
   207                 // then the day.
       
   208                 listEntryPtr.Append( ( *iShortWorkDaysList )[ alarmDay ] );
       
   209                 }
       
   210             else
       
   211                 {
       
   212                 // First the day and
       
   213                 listEntryPtr.Append( ( *iShortWorkDaysList )[ alarmDay ] );
       
   214                 listEntryPtr.Append( KSingleSpace );
       
   215                 // then the date.
       
   216                 listEntryPtr.Append( dateString );
       
   217                 }
       
   218             // Cleanup.
       
   219             CleanupStack::PopAndDestroy( cenRep );
       
   220             }
       
   221             break;
       
   222             
       
   223         case EAlarmRepeatDefintionRepeatWeekly:
       
   224             {
       
   225             listEntryPtr.Append( ( *iWorkDaysList )[ alarmDay ] );
       
   226             }
       
   227             break;
       
   228             
       
   229         case EAlarmRepeatDefintionRepeatDaily:
       
   230             {
       
   231             listEntryPtr.Append( ( *iOccuranceList )[ 1 ] );
       
   232             }
       
   233             break;
       
   234             
       
   235         case EAlarmRepeatDefintionRepeatWorkday:
       
   236             {
       
   237             listEntryPtr.Append( ( *iOccuranceList )[ 2 ]);
       
   238             }
       
   239             break;
       
   240             
       
   241         default:
       
   242             {
       
   243             // Error if control comes here. addding space to avoid crash.
       
   244             listEntryPtr.Append( KSingleSpace );
       
   245             }
       
   246             break;
       
   247         }
       
   248     // Go to the next item.
       
   249     listEntryPtr.Append( KFieldSeparator );
       
   250     
       
   251     // Append the description.
       
   252     if( EAlarmStatusDisabled == alarmInfo.iStatus )
       
   253         {
       
   254         listEntryPtr.Append( iAlarmInactiveText->Des() );
       
   255         }
       
   256     else if( EAlarmStateSnoozed == alarmInfo.iState )
       
   257         {
       
   258         // Reset the strings.
       
   259         timeString.Zero();
       
   260         
       
   261         alarmInfo.iAlarmTime.FormatL( timeString, *iTimeFormat );
       
   262         
       
   263         HBufC* alarmSnoozedText( NULL );
       
   264         alarmSnoozedText = StringLoader::LoadL( R_QTN_CLK_ALARMS_VIEW_SNOOZED_ALARM, timeString, iEnv );     
       
   265         TPtr alarmSnoozedTextPtr = alarmSnoozedText->Des();
       
   266 
       
   267         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( alarmSnoozedTextPtr );
       
   268         
       
   269         listEntryPtr.Append( alarmSnoozedText->Des() );       
       
   270 
       
   271         // Cleanup.
       
   272         delete alarmSnoozedText;
       
   273         alarmSnoozedText = NULL;
       
   274         }
       
   275     else if( KErrNone < alarmInfo.iMessage.Length() ) 
       
   276         {
       
   277         // Remove any extra white spaces or line feed and replace it with a blank character.
       
   278         TAlarmMessage alarmDescription( alarmInfo.iMessage );
       
   279                
       
   280         AknTextUtils::ReplaceCharacters( alarmDescription, KReplaceWhitespaceChars, TChar(' ') );
       
   281         alarmDescription.TrimAll();
       
   282         
       
   283         listEntryPtr.Append( alarmDescription );
       
   284         }
       
   285     else
       
   286         {
       
   287         listEntryPtr.Append( KSingleSpace );
       
   288         }
       
   289 
       
   290     // Go to the next item.
       
   291     listEntryPtr.Append( KFieldSeparator );
       
   292     
       
   293     // Append the icon.
       
   294     if( EAlarmRepeatDefintionRepeatWeekly == alarmInfo.iRepeat || 
       
   295         EAlarmRepeatDefintionRepeatDaily == alarmInfo.iRepeat ||
       
   296         EAlarmRepeatDefintionRepeatWorkday == alarmInfo.iRepeat )
       
   297         {
       
   298         // For repeat icon.
       
   299         listEntryPtr.AppendNum( EAlarmRepeatIconIndex );
       
   300         }
       
   301     else
       
   302         {
       
   303         listEntryPtr.AppendNum( EBlankIconIndex );
       
   304         }
       
   305 
       
   306     // Go to the next item.
       
   307     listEntryPtr.Append( KFieldSeparator );
       
   308     
       
   309     if( EAlarmStatusEnabled == alarmInfo.iStatus )
       
   310         {
       
   311         // Show alarm icon.
       
   312         listEntryPtr.AppendNum( EAlarmActiveIconIndex );
       
   313         }
       
   314     else
       
   315         {
       
   316         // Show nothing.
       
   317         listEntryPtr.AppendNum( EAlarmInActiveIconIndex ); 
       
   318         }
       
   319 
       
   320     // Cleanup.
       
   321     delete formatString;
       
   322 	
       
   323 	__PRINTS( "CClockAlarmArray::MdcaPoint - Exit" );
       
   324     
       
   325     // Return the constructed descriptor.
       
   326     return listEntryPtr;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------
       
   330 // CClockAlarmArray::ListBoxIndex
       
   331 // rest of the details are commented in the header
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 TInt CClockAlarmArray::ListBoxIndex( TAlarmId aAlarmId )
       
   335     {
       
   336 	__PRINTS( "CClockAlarmArray::ListBoxIndex - Entry" );
       
   337 	
       
   338     // First get the alarm info.
       
   339     SClkAlarmInfo alarmInfo;
       
   340     TInt errorValue( iAlarmModel->ClockAlarmInfo( aAlarmId, alarmInfo ) );
       
   341     
       
   342     if( ( KErrNone == errorValue ) &&
       
   343         ( EAlarmStateInPreparation != alarmInfo.iState &&
       
   344           EAlarmStateNotified != alarmInfo.iState &&
       
   345           EAlarmStatusEnabled == alarmInfo.iStatus ) )
       
   346         {
       
   347         // Returns enabled alarm's index.
       
   348         return GetEnabledAlarmIndex( aAlarmId, errorValue );
       
   349         }
       
   350     else
       
   351         {
       
   352         // Returns disabled alarm's index. 
       
   353         return GetDisabledAlarmIndex( aAlarmId, errorValue );
       
   354         }
       
   355     }
       
   356     
       
   357     
       
   358 // ---------------------------------------------------------
       
   359 // CClockAlarmArray::GetEnabledAlarmIndex
       
   360 // rest of the details are commented in the header
       
   361 // ---------------------------------------------------------
       
   362 //
       
   363 TInt CClockAlarmArray::GetEnabledAlarmIndex( TAlarmId aAlarmId, TInt aErrorValue )
       
   364 	{
       
   365 	TInt listItemIndex( KFirstAlarmIndex );
       
   366 	TInt enabledAlarmIndex( KErrNotFound );
       
   367 	TInt alarmCount( iAlarmIdArray.Count() );
       
   368 
       
   369 	// The order of alarms in the listbox is not always the same in the alarmarray 
       
   370 	// because disabled alarms are displayed in the end of the list and the next alarm 
       
   371 	// to expire is on top of the list.
       
   372 	for( TInt index( KFirstAlarmIndex ); index < alarmCount; index++ )
       
   373 		{
       
   374 		SClkAlarmInfo alarmInfo;
       
   375 		TInt errorVal( iAlarmModel->ClockAlarmInfo( iAlarmIdArray[ index ], alarmInfo) );
       
   376 
       
   377 		if( ( KErrNone == aErrorValue ) &&
       
   378 			( EAlarmStateInPreparation != alarmInfo.iState &&
       
   379 			  EAlarmStateNotified != alarmInfo.iState &&
       
   380 			  EAlarmStatusEnabled == alarmInfo.iStatus ) )
       
   381 			{
       
   382 			if( aAlarmId == iAlarmIdArray[ index ] )
       
   383 				{
       
   384 				enabledAlarmIndex = listItemIndex;
       
   385 				}
       
   386 			else
       
   387 				{
       
   388 				listItemIndex++;
       
   389 				}
       
   390 			}
       
   391 		}
       
   392 
       
   393 	return enabledAlarmIndex;	
       
   394 	}
       
   395    
       
   396  // ---------------------------------------------------------
       
   397 // CClockAlarmArray::GetDisabledAlarmIndex
       
   398 // rest of the details are commented in the header
       
   399 // ---------------------------------------------------------
       
   400 //
       
   401 TInt CClockAlarmArray::GetDisabledAlarmIndex( TAlarmId aAlarmId, TInt aErrorValue )
       
   402 	{
       
   403 	TInt listItemIndex( KFirstAlarmIndex );
       
   404 	TInt disabledAlarmIndex( KErrNotFound );
       
   405 	
       
   406     // Calculate the index of deactivated alarm.
       
   407     // Get the enabled alarms count first and start counting from there for deactivated alarms.
       
   408     // The order of alarms in the listbox is not always the same in the alarmarray 
       
   409     // because disabled alarms are displayed in the end of the list and the next alarm 
       
   410     // to expire is on top of the list.
       
   411     for( TInt index( KFirstAlarmIndex ); index < iAlarmIdArray.Count(); index++ )
       
   412         {
       
   413         SClkAlarmInfo alarmInfo;
       
   414         TInt errorVal( iAlarmModel->ClockAlarmInfo( iAlarmIdArray[ index ], alarmInfo ) );
       
   415         
       
   416         if( ( KErrNone == aErrorValue ) &&
       
   417             ( EAlarmStateInPreparation != alarmInfo.iState &&
       
   418               EAlarmStateNotified != alarmInfo.iState &&
       
   419               EAlarmStatusEnabled == alarmInfo.iStatus ) )
       
   420             {           
       
   421             listItemIndex++; 
       
   422             }
       
   423         }
       
   424         
       
   425     // ListItemIndex contains the count of enabled alarms. Now count from here.
       
   426     for( TInt index( KFirstAlarmIndex ); index < iAlarmIdArray.Count(); index++ )
       
   427         {
       
   428         SClkAlarmInfo alarmInfo;
       
   429         TInt errorVal( iAlarmModel->ClockAlarmInfo( iAlarmIdArray[ index ], alarmInfo ) );
       
   430         
       
   431         if( ( KErrNone == aErrorValue ) &&
       
   432             ( EAlarmStateInPreparation != alarmInfo.iState &&
       
   433               EAlarmStateNotified != alarmInfo.iState &&
       
   434               EAlarmStatusEnabled != alarmInfo.iStatus ) )
       
   435             {
       
   436             if( aAlarmId == iAlarmIdArray[ index ] )
       
   437                 {
       
   438                 disabledAlarmIndex = listItemIndex;
       
   439                 }
       
   440             else
       
   441                 {
       
   442                 listItemIndex++;
       
   443                 }
       
   444             }
       
   445         }
       
   446         
       
   447 	return disabledAlarmIndex;           
       
   448 	}
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CClockAlarmArray::InitIdList
       
   452 // rest of the details are commented in the header
       
   453 // ---------------------------------------------------------
       
   454 //
       
   455 void CClockAlarmArray::InitIdList()
       
   456     {
       
   457 	__PRINTS( "CClockAlarmArray::InitIdList - Entry" );
       
   458 	
       
   459     // Reset the array.
       
   460     iAlarmIdArray.Close();
       
   461     // Get the ids from alarmserver.
       
   462     iAlarmModel->GetClkAlarmIds( iAlarmIdArray );
       
   463     
       
   464     
       
   465     SClkAlarmInfo alarmInfo;      
       
   466     TInt alarmCount( iAlarmIdArray.Count() );
       
   467 
       
   468     // Set all alarm id entries which are notified/invalid to '0'.
       
   469     for( TInt index( KFirstAlarmIndex ); index < alarmCount; index++ )
       
   470         {
       
   471         TInt errorValue( iAlarmModel->ClockAlarmInfo( iAlarmIdArray[ index ], alarmInfo ) );
       
   472         
       
   473         if( ( KErrNone != errorValue ) ||
       
   474             ( EAlarmStateInPreparation == alarmInfo.iState ||
       
   475               EAlarmStateNotified == alarmInfo.iState ) )
       
   476             {
       
   477             iAlarmIdArray[ index ] = KErrNone;
       
   478             }
       
   479         }
       
   480     
       
   481     // Delete all the alarm entries in the alarm id array with value '0', as marked above.
       
   482     for( TInt index( KFirstAlarmIndex ); index < iAlarmIdArray.Count(); )
       
   483         {
       
   484         if( KErrNone == iAlarmIdArray[ index ] )
       
   485             {
       
   486             iAlarmIdArray.Remove( index );
       
   487             index = KFirstAlarmIndex;
       
   488             }
       
   489         else
       
   490             {
       
   491             index++;
       
   492             }
       
   493         }  
       
   494 
       
   495 	__PRINTS( "CClockAlarmArray::InitIdList - Exit" );
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------
       
   499 // CClockAlarmArray::GetSortedAlmIdInfo
       
   500 // rest of the details are commented in the header
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 void CClockAlarmArray::GetSortedAlmIdInfo( TInt aIndex, TAlarmId& aAlarmId, SClkAlarmInfo& aAlarmInfo ) const
       
   504     {
       
   505 	__PRINTS( "CClockAlarmArray::NewL - Entry" );
       
   506 	
       
   507     // Function is declared as const. So using a local array instead of the data member.
       
   508     // First get the alarm id list from the alarm server.
       
   509     RArray< TAlarmId > alarmIdArray;
       
   510     iAlarmModel->GetClkAlarmIds( alarmIdArray );
       
   511 
       
   512     // This will hold the count of alarms currently enabled( active ).
       
   513     TInt alarmIdCount( alarmIdArray.Count() );
       
   514 
       
   515     // Get the alarms which are enabled and active.
       
   516     TInt enabledAlarmCount( GetEnabledAlarmCount() );
       
   517         
       
   518     // If info of an active alarm is needed.       
       
   519     if( aIndex < enabledAlarmCount )
       
   520     	{
       
   521     	GetActiveAlarmInfo( aIndex, aAlarmId , aAlarmInfo );
       
   522     	}
       
   523     // Info of a disabled alarm is needed.
       
   524     else
       
   525     	{
       
   526     	GetInActiveAlarmInfo( aIndex, aAlarmId , aAlarmInfo );
       
   527     	}
       
   528     
       
   529     // Sanity check, control should never come here.
       
   530     alarmIdArray.Close();
       
   531     
       
   532     return;
       
   533     }
       
   534     
       
   535 // ---------------------------------------------------------
       
   536 // CClockAlarmArray::GetEnabledAlarmCount
       
   537 // rest of the details are commented in the header
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 TInt CClockAlarmArray::GetEnabledAlarmCount() const     
       
   541 	{
       
   542 	// First get the alarm id list from the alarm server.
       
   543 	RArray< TAlarmId > alarmIdArray;
       
   544 	iAlarmModel->GetClkAlarmIds( alarmIdArray );
       
   545 
       
   546 	// This will hold the count of alarms currently enabled( active ).
       
   547 	TInt alarmCount( NULL );
       
   548 	TInt alarmIdCount( alarmIdArray.Count() );
       
   549 
       
   550 	// Get the alarms which are enabled and active.
       
   551 	for( TInt index( NULL ); index < alarmIdCount; index++ )
       
   552 		{
       
   553 		// Get information of each alarm.
       
   554 		SClkAlarmInfo alarmInfo;
       
   555 		TInt errorValue( iAlarmModel->ClockAlarmInfo( alarmIdArray[ index ], alarmInfo ) );
       
   556 
       
   557 		if( ( KErrNone == errorValue ) &&
       
   558 			( EAlarmStateInPreparation != alarmInfo.iState &&
       
   559 			  EAlarmStateNotified != alarmInfo.iState &&
       
   560 		      EAlarmStatusEnabled == alarmInfo.iStatus ) )
       
   561 			{
       
   562 			alarmCount++;
       
   563 			}
       
   564 		}
       
   565 
       
   566 	alarmIdArray.Close();  
       
   567 
       
   568 	return alarmCount;
       
   569 	}
       
   570     
       
   571 // ---------------------------------------------------------
       
   572 // CClockAlarmArray::GetActiveAlarmInfo
       
   573 // rest of the details are commented in the header
       
   574 // ---------------------------------------------------------
       
   575 //
       
   576 void CClockAlarmArray::GetActiveAlarmInfo(  TInt aIndex, TAlarmId& aAlarmId, SClkAlarmInfo& aAlarmInfo ) const
       
   577     {
       
   578     // First get the alarm id list from the alarm server.
       
   579     RArray< TAlarmId > alarmIdArray;
       
   580     iAlarmModel->GetClkAlarmIds( alarmIdArray );
       
   581     
       
   582     TInt alarmIdCount( alarmIdArray.Count() );
       
   583     TInt alarmIndex( 0 );
       
   584         
       
   585 	for( TInt index( 0 ); index < alarmIdCount; index++ )
       
   586 	    {
       
   587 	    // Get information of each alarm.
       
   588 	    SClkAlarmInfo alarmInfo;
       
   589 	    TInt errorValue( iAlarmModel->ClockAlarmInfo( alarmIdArray[ index ], alarmInfo ) );
       
   590 	    
       
   591 	    if(  !( ( KErrNone == errorValue ) &&
       
   592 	        ( EAlarmStateInPreparation != alarmInfo.iState &&
       
   593 	          EAlarmStateNotified != alarmInfo.iState &&
       
   594 	          EAlarmStatusEnabled == alarmInfo.iStatus ) ) )
       
   595 	        {
       
   596 	        continue;
       
   597 	        }
       
   598 	    
       
   599 	    if( aIndex == alarmIndex )
       
   600 	        {
       
   601 	        // We have a match, return the values.
       
   602 	        aAlarmId = alarmIdArray[ index ];
       
   603 	        aAlarmInfo = alarmInfo;
       
   604 	        alarmIdArray.Close();
       
   605 	        
       
   606 	        // Break the loop.
       
   607 	        return;
       
   608 	        }
       
   609 	    alarmIndex++;
       
   610 	    }
       
   611    	}
       
   612     
       
   613 // ---------------------------------------------------------
       
   614 // CClockAlarmArray::GetInActiveAlarmInfo
       
   615 // rest of the details are commented in the header
       
   616 // ---------------------------------------------------------
       
   617 //
       
   618 void CClockAlarmArray::GetInActiveAlarmInfo(  TInt aIndex, TAlarmId& aAlarmId, SClkAlarmInfo& aAlarmInfo ) const
       
   619     {
       
   620     RArray< TAlarmId > alarmIdArray;
       
   621     iAlarmModel->GetClkAlarmIds( alarmIdArray );
       
   622     
       
   623     TInt alarmIdCount( alarmIdArray.Count() );
       
   624 	TInt alarmIndex( NULL );
       
   625 	
       
   626     // Get the alarms which are enabled and active.
       
   627     TInt enabledAlarmCount = GetEnabledAlarmCount();
       
   628     
       
   629     for( TInt index( 0 ); index < alarmIdCount; index++ )
       
   630         {
       
   631         // Get information of each alarm.
       
   632         SClkAlarmInfo alarmInfo;
       
   633         TInt errorValue( iAlarmModel->ClockAlarmInfo( alarmIdArray[ index ], alarmInfo ) );
       
   634 
       
   635         if( !( ( KErrNone == errorValue ) &&
       
   636             ( EAlarmStateInPreparation != alarmInfo.iState &&
       
   637               EAlarmStateNotified != alarmInfo.iState &&
       
   638               EAlarmStatusEnabled != alarmInfo.iStatus ) ) )
       
   639             {
       
   640             continue;
       
   641             }
       
   642         // Disabled alarms are always indexed after the enabled alarms.
       
   643         if( ( enabledAlarmCount + alarmIndex ) == aIndex )
       
   644             {
       
   645             aAlarmId = alarmIdArray[ index ];
       
   646             aAlarmInfo = alarmInfo;
       
   647             alarmIdArray.Close();
       
   648             
       
   649             // Break the loop.
       
   650             return;
       
   651             }
       
   652         alarmIndex++;
       
   653         }
       
   654    	 }
       
   655     
       
   656 // ---------------------------------------------------------
       
   657 // CClockAlarmArray::ConstructL
       
   658 // rest of the details are commented in the header
       
   659 // ---------------------------------------------------------
       
   660 //
       
   661 void CClockAlarmArray::ConstructL( CClkUiAlarmModel* aAlarmModel, CCoeEnv* aCoeEnv )
       
   662     {
       
   663 	__PRINTS( "CClockAlarmArray::ConstructL - Entry" );
       
   664 	
       
   665     // Save the alarm model and the environment.
       
   666     iAlarmModel = aAlarmModel;
       
   667     iEnv = aCoeEnv;
       
   668     
       
   669     // The listbox item.
       
   670     iListBoxEntry = HBufC::NewLC( 175 );
       
   671     CleanupStack::Pop( iListBoxEntry );
       
   672 
       
   673     // Initialize the alarm id array.
       
   674     InitIdList();
       
   675 
       
   676     // Read the string resources.
       
   677     iWorkDaysList = iEnv->ReadDesCArrayResourceL( R_CLOCK_WEEK_DAYS_ARRAY );
       
   678     iShortWorkDaysList = iEnv->ReadDesCArrayResourceL( R_CLOCK_WEEK_DAYS_SHORT_ARRAY );
       
   679     iOccuranceList = iEnv->ReadDesCArrayResourceL( R_CLOCK_ALARM_EDITOR_OCCU_ARRAY );
       
   680     iNewAlarmText = StringLoader::LoadL( R_QTN_CLK_COMMAND_NEW_ALARM, iEnv );
       
   681     iAlarmInactiveText = StringLoader::LoadL( R_QTN_CLOCK_ALARMS_VIEW_INACTIVE_ALARM, iEnv );
       
   682     iDate = StringLoader::LoadL( R_QTN_DATE_WITHOUT_YEAR_WITH_ZERO, iEnv );                     
       
   683     iTimeFormat = StringLoader::LoadL( R_QTN_TIME_USUAL_WITH_ZERO,iEnv );      
       
   684 
       
   685 	__PRINTS( "CClockAlarmArray::ConstructL - Exit" );
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------
       
   689 // CClockAlarmArray::CClockAlarmArray
       
   690 // rest of the details are commented in the header
       
   691 // ---------------------------------------------------------
       
   692 //
       
   693 CClockAlarmArray::CClockAlarmArray()
       
   694     {
       
   695 	__PRINTS( "CClockAlarmArray::CClockAlarmArray - Entry" );
       
   696 	
       
   697     // No implementation yet.
       
   698 	
       
   699 	__PRINTS( "CClockAlarmArray::CClockAlarmArray - Exit" );
       
   700     }
       
   701 
       
   702 // ---------------------------------------------------------
       
   703 // CClockAlarmArray::Power
       
   704 // rest of the details are commented in the header
       
   705 // ---------------------------------------------------------
       
   706 //
       
   707 TInt CClockAlarmArray::Power( TInt aNum ) const
       
   708     {
       
   709 	__PRINTS( "CClockAlarmArray::Power - Entry" );
       
   710 	
       
   711     TInt returnValue( 1 );
       
   712     
       
   713     // If 0, send the 1st item.
       
   714     if( KErrNone == aNum )
       
   715         {
       
   716 		__PRINTS( "CClockAlarmArray::Power - Exit" );
       
   717 		
       
   718         return returnValue;
       
   719         }
       
   720         
       
   721     // Iterate through the list for the match.
       
   722     for( TInt index( KErrNone ); index < aNum; index++ )
       
   723         {
       
   724         returnValue = returnValue * 2;
       
   725         }
       
   726 		
       
   727 	__PRINTS( "CClockAlarmArray::Power - Exit" );
       
   728 
       
   729     return returnValue;
       
   730     }
       
   731 
       
   732 HBufC* CClockAlarmArray::NewAlarmText() const
       
   733         {
       
   734         return iNewAlarmText;
       
   735         }
       
   736 // End of file