clock2/clockui/uilayer/clockmainview/src/clockmainview.cpp
branchRCL_3
changeset 27 55d60436f00b
parent 5 42814f902fe6
child 30 d68a4b5d5885
equal deleted inserted replaced
21:9711e452b5e9 27:55d60436f00b
    39 #include "clkuialarmidleobserver.h"
    39 #include "clkuialarmidleobserver.h"
    40 #include "clkcommon.h"
    40 #include "clkcommon.h"
    41 #include "clock_debug.h"
    41 #include "clock_debug.h"
    42 
    42 
    43 // Constants
    43 // Constants
       
    44 const TInt KMaxCharsInNote( 32 );
       
    45 const TInt KZerothRule( 0 );
       
    46 const TInt KDaysInWeek( 7 );
       
    47 const TInt KOneMinuteInMicrosecond( 1000000 * 60 );
       
    48 const TInt KOneHourInMinute( 60 );
       
    49 const TInt KOneMinute( 1 );
       
    50 const TInt KOneHour( 1 );
       
    51 const TInt KNoDifference( 0 );
       
    52 
       
    53 _LIT( KDateTimeFormatter, "%-B%:0%J%:1%T%:3%+B" );  // For the date and time displayed in the rollover note.
       
    54 
       
    55 
    44 
    56 
    45 // Literals
    57 // Literals
    46 
    58 
    47 // ---------------------------------------------------------
    59 // ---------------------------------------------------------
    48 // CClockMainView::NewL
    60 // CClockMainView::NewL
   181     if( KErrNone != iAlarmId )
   193     if( KErrNone != iAlarmId )
   182         {
   194         {
   183         // Update the latest alarm details.
   195         // Update the latest alarm details.
   184         iAlarmModel->ClockAlarmInfo( iAlarmId, iAlarmInfo );
   196         iAlarmModel->ClockAlarmInfo( iAlarmId, iAlarmInfo );
   185         
   197         
       
   198         if(CheckForDstChangesL())
       
   199             {
       
   200             DisplayRemainingTimeL();
       
   201             }
       
   202 
   186         // First update the model with the latest alarm id.
   203         // First update the model with the latest alarm id.
   187         iAlarmModel->SaveLatestAlarmId( iAlarmId );
   204         iAlarmModel->SaveLatestAlarmId( iAlarmId );
   188         
   205         
   189         // Update the container with the newly added alarm.
   206         // Update the container with the newly added alarm.
   190         iContainer->UpdateAlarmListL( iAlarmInfo, iAlarmId );
   207         iContainer->UpdateAlarmListL( iAlarmInfo, iAlarmId );
   397         iContainer->RemoveAlarmL( itemIndex );
   414         iContainer->RemoveAlarmL( itemIndex );
   398         
   415         
   399         // Update the latest alarm details.
   416         // Update the latest alarm details.
   400         iAlarmModel->ClockAlarmInfo( iAlarmId, iAlarmInfo );
   417         iAlarmModel->ClockAlarmInfo( iAlarmId, iAlarmInfo );
   401         
   418         
       
   419 		if(CheckForDstChangesL())
       
   420             {
       
   421             DisplayRemainingTimeL();
       
   422             }
       
   423 
   402         // First update the model with the latest alarm id.
   424         // First update the model with the latest alarm id.
   403         iAlarmModel->SaveLatestAlarmId( iAlarmId );
   425         iAlarmModel->SaveLatestAlarmId( iAlarmId );
   404         
   426         
   405         // Update the container with the new alarm.
   427         // Update the container with the new alarm.
   406         iContainer->UpdateAlarmListL( iAlarmInfo, iAlarmId );
   428         iContainer->UpdateAlarmListL( iAlarmInfo, iAlarmId );
   877     __PRINTS( "CClockMainView::ClockApplicationUi - Exit" );
   899     __PRINTS( "CClockMainView::ClockApplicationUi - Exit" );
   878     
   900     
   879     return static_cast< CClockAppUi* > ( AppUi() );
   901     return static_cast< CClockAppUi* > ( AppUi() );
   880     }
   902     }
   881 
   903 
       
   904 // ---------------------------------------------------------
       
   905 // CClockAlarmEditorImpl::DisplayRemainingTimeL
       
   906 // rest of the details are commented in the header
       
   907 // ---------------------------------------------------------
       
   908 //
       
   909 void CClockMainView::DisplayRemainingTimeL()
       
   910     {
       
   911     __PRINTS( "CClockAlarmEditorImpl::DisplayRemainingTimeL - Entry" );
       
   912     
       
   913     HBufC* stringHolder( NULL );
       
   914 
       
   915     TTime currentTime;
       
   916     currentTime.HomeTime();     
       
   917 
       
   918     TTime alarmTime = iAlarmInfo.iOrigExpiryTime;
       
   919     TBool oneDayDifference( EFalse );    
       
   920 
       
   921     // Check for the day of the alarm.
       
   922     if( currentTime < alarmTime )
       
   923         {
       
   924         currentTime += TTimeIntervalDays( 1 );
       
   925         // Check if the alarm is for the current day.
       
   926         oneDayDifference = ( currentTime < alarmTime )? ETrue : EFalse;
       
   927         }
       
   928 
       
   929     TInt alarmDay( alarmTime.DayNoInWeek() );
       
   930     const TInt KTimeStringLength( 10 );
       
   931     TBuf< KTimeStringLength > timeString;
       
   932 
       
   933     HBufC* timeFormat = StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO, iCoeEnv );
       
   934     CleanupStack::Pop( timeFormat );
       
   935 
       
   936     alarmTime.FormatL( timeString, *timeFormat );
       
   937 
       
   938     CDesCArrayFlat* stringArray = new( ELeave ) CDesCArrayFlat( 2 );
       
   939     CDesCArrayFlat* workDaysList = iCoeEnv->ReadDesCArrayResourceL( R_CLOCK_WEEK_DAYS_ARRAY );
       
   940 
       
   941     // The day on which alarm is set.
       
   942     stringArray->AppendL( ( *workDaysList )[ alarmDay ] );
       
   943     // The time string.
       
   944     stringArray->AppendL( timeString );
       
   945 
       
   946     // Choose the appropriate Repeat type.
       
   947     switch( iAlarmInfo.iRepeat )
       
   948         {
       
   949         case EAlarmRepeatDefintionRepeatNext24Hours:
       
   950         case EAlarmRepeatDefintionRepeatOnce:
       
   951             {
       
   952             if( oneDayDifference )
       
   953                 {
       
   954                 stringHolder = StringLoader::LoadLC( R_QTN_CLOCK_ALARM_NOTE_ONCE_NEXT, *stringArray, iEikonEnv );
       
   955                 }
       
   956             }
       
   957             break;
       
   958         
       
   959         case EAlarmRepeatDefintionRepeatDaily:
       
   960             {
       
   961             stringHolder = StringLoader::LoadLC( R_QTN_CLOCK_ALARM_NOTE_DAY_CLK, timeString, iEikonEnv );
       
   962             }
       
   963             break;
       
   964             
       
   965         case EAlarmRepeatDefintionRepeatWeekly:
       
   966             {
       
   967             stringHolder = StringLoader::LoadLC( R_QTN_CLOCK_ALARM_NOTE_WEEK_CLK, *stringArray, iEikonEnv );
       
   968             }
       
   969             break;
       
   970             
       
   971         case EAlarmRepeatDefintionRepeatWorkday:
       
   972             {
       
   973             stringHolder = StringLoader::LoadLC( R_QTN_CLOCK_ALARM_NOTE_WDAY_CLK, timeString, iEikonEnv );
       
   974             }
       
   975             break;
       
   976             
       
   977         default:
       
   978             {
       
   979             // No implementation yet.
       
   980             }
       
   981             break;
       
   982         }
       
   983     
       
   984     // Cleanup.
       
   985     delete timeFormat;
       
   986     delete stringArray;
       
   987     delete workDaysList;        
       
   988 
       
   989     // Need to show the confirmation note.
       
   990     if( ( EAlarmStatusEnabled == iAlarmInfo.iStatus ) && stringHolder )
       
   991         {
       
   992         // TODO: to be verified todo this or not.
       
   993         CAknConfirmationNote* confirmationNote = new( ELeave ) CAknConfirmationNote( ETrue );
       
   994 
       
   995         TPtr stringHolderPtr = stringHolder->Des();
       
   996         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( stringHolderPtr );    
       
   997 
       
   998         confirmationNote->ExecuteLD( *stringHolder );
       
   999 
       
  1000         // Cleanup
       
  1001         CleanupStack::PopAndDestroy( stringHolder );
       
  1002         } 
       
  1003 
       
  1004     // Dislpay the second note.
       
  1005     if( !oneDayDifference )
       
  1006         {
       
  1007         TTime homeTime;
       
  1008         homeTime.HomeTime();
       
  1009 
       
  1010         TDateTime currentDate( homeTime.DateTime() );
       
  1011         TDateTime alarmDate( iAlarmInfo.iAlarmTime.DateTime() );
       
  1012 
       
  1013         alarmDate.SetYear( currentDate.Year() );
       
  1014         alarmDate.SetMonth( currentDate.Month() );
       
  1015         alarmDate.SetDay( currentDate.Day() );
       
  1016 
       
  1017         TTime newAlarmTime( alarmDate );
       
  1018 
       
  1019         if( newAlarmTime < homeTime )
       
  1020             {
       
  1021             newAlarmTime += TTimeIntervalDays( 1 );
       
  1022             }
       
  1023 
       
  1024         // Construct the remaining time.            
       
  1025         TTimeIntervalMicroSeconds remainingTime( newAlarmTime.MicroSecondsFrom( homeTime ) );
       
  1026         TInt64 tempInt = ( remainingTime.Int64() ) / KOneMinuteInMicrosecond;
       
  1027         TInt remainingMinutes = I64INT( tempInt );
       
  1028 
       
  1029         CArrayFix< TInt >* timeArray = new( ELeave ) CArrayFixFlat< TInt >( 2 );
       
  1030         CleanupStack::PushL( timeArray );
       
  1031 
       
  1032         TInt remainingHours( remainingMinutes / KOneHourInMinute );
       
  1033 
       
  1034         remainingMinutes -= remainingHours * KOneHourInMinute;
       
  1035 
       
  1036         timeArray->AppendL( remainingHours );
       
  1037         timeArray->AppendL( remainingMinutes );
       
  1038 
       
  1039         // Alarm is with in 1 day. Choose the appropriate strings to be displayed.
       
  1040         switch( remainingHours )
       
  1041             {
       
  1042             case KOneMinute:
       
  1043                 {
       
  1044                 if( KOneMinute == remainingMinutes )
       
  1045                     {
       
  1046                     stringHolder = StringLoader::LoadLC( R_CLOCK_ALARM_CONF_SINGULAR, *timeArray, iEikonEnv );
       
  1047                     }
       
  1048                 else
       
  1049                     {
       
  1050                     stringHolder = StringLoader::LoadLC( R_CLOCK_ALARM_CONF_HOUR_SEV_MIN, *timeArray, iEikonEnv );
       
  1051                     }
       
  1052                 }
       
  1053                 break;
       
  1054                 
       
  1055             default:
       
  1056                 {
       
  1057                 if( KOneMinute == remainingMinutes )
       
  1058                     {
       
  1059                     stringHolder = StringLoader::LoadLC( R_CLOCK_ALARM_CONF_SEV_HOURS_MIN, *timeArray, iEikonEnv );
       
  1060                     }
       
  1061                 else
       
  1062                     {
       
  1063                     stringHolder = StringLoader::LoadLC( R_CLOCK_ALARM_CONF_PLURAL, *timeArray, iEikonEnv );
       
  1064                     }
       
  1065                 }
       
  1066                 break;
       
  1067             }
       
  1068         
       
  1069         // TODO: to be verified todo this or not.
       
  1070         if( ( EAlarmStatusEnabled == iAlarmInfo.iStatus )  && stringHolder )
       
  1071             {
       
  1072             CAknConfirmationNote* confirmationNote = new( ELeave ) CAknConfirmationNote( ETrue );
       
  1073 
       
  1074             TPtr stringHolderPtr = stringHolder->Des();
       
  1075             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( stringHolderPtr );    
       
  1076 
       
  1077             confirmationNote->ExecuteLD( *stringHolder ); 
       
  1078             }
       
  1079 
       
  1080         // Cleanup.        
       
  1081         CleanupStack::PopAndDestroy( stringHolder );
       
  1082         CleanupStack::PopAndDestroy( timeArray );
       
  1083         }
       
  1084     
       
  1085     __PRINTS( "CClockAlarmEditorImpl::DisplayRemainingTimeL - Exit" );
       
  1086     }
       
  1087 
       
  1088 // ---------------------------------------------------------
       
  1089 // CClockAlarmEditorImpl::CheckForDstChangesL
       
  1090 // rest of the details are commented in the header
       
  1091 // ---------------------------------------------------------
       
  1092 //
       
  1093 TBool CClockMainView::CheckForDstChangesL()
       
  1094     {
       
  1095     __PRINTS( "CClockAlarmEditorImpl::CheckForDstChangesL - Entry" );
       
  1096     
       
  1097     // User to be notified whether DST rollover happens in a day or 
       
  1098     // has happen within a day if he tries to change the time.
       
  1099     TBool returnValue( ETrue );
       
  1100     
       
  1101     // Establish connection with RTz to get the timezone ID
       
  1102     RTz tzHandle;
       
  1103     User::LeaveIfError( tzHandle.Connect() );
       
  1104     CleanupClosePushL( tzHandle );
       
  1105 
       
  1106     // The timezone ID (current)
       
  1107     CTzId* currentTZId = tzHandle.GetTimeZoneIdL();
       
  1108     CleanupStack::PushL( currentTZId );
       
  1109 
       
  1110     // The current time in UTC
       
  1111     TTime currentTime;
       
  1112     currentTime.UniversalTime();
       
  1113 
       
  1114     // hometime (local time)
       
  1115     TTime homeTime;
       
  1116     homeTime.HomeTime();
       
  1117 
       
  1118     //(Year, Month, Day, Hour, Minute, Second, Micrsecond)
       
  1119     TDateTime dateTime( homeTime.DateTime().Year(), EJanuary, 1, FALSE, FALSE, FALSE, FALSE );
       
  1120 
       
  1121     TTime tempTime( dateTime ); 
       
  1122 
       
  1123     // Get the current rules for the timezone
       
  1124     CTzRules* currentRules = tzHandle.GetTimeZoneRulesL( *currentTZId, tempTime, currentTime, ETzUtcTimeReference );
       
  1125     CleanupStack::PushL( currentRules );
       
  1126 
       
  1127     // CVTzActualisedRules encapsulates the rules for a specific year.
       
  1128     // Every year has a dummy rule and further DST rules if DST is applicable (if Ohlson provides them)
       
  1129     CVTzActualisedRules *vActualisedRules = CVTzActualisedRules::NewL(
       
  1130             homeTime.DateTime().Year(), 
       
  1131             homeTime.DateTime().Year());
       
  1132     CleanupStack::PushL( vActualisedRules );
       
  1133 
       
  1134     // The dummy rule is always the begining of the year.
       
  1135     // For example there is only 1 rule for India/NewDelhi but USA/Atlanta has 3 rules.
       
  1136     currentRules->GetActualisedRulesL( *vActualisedRules );
       
  1137 
       
  1138     const TInt ruleCount( vActualisedRules->Count() );
       
  1139     TInt ruleMatchIndex( KNoDifference );
       
  1140 
       
  1141     TTimeIntervalSeconds secondsDifference;
       
  1142     TTime ruleMatchTime;
       
  1143 
       
  1144     // Fetch lowest time offset for the year residing at aTime. 
       
  1145     // This is used to determine if DST is on.
       
  1146     for( TInt ruleIndex( FALSE ); ruleIndex < ruleCount; ++ruleIndex )
       
  1147         {
       
  1148         const TVTzActualisedRule& actualisedRule = ( *vActualisedRules )[ ruleIndex ];
       
  1149 
       
  1150         // Only check for the same year as requested (aTime)
       
  1151         if( actualisedRule.iTimeOfChange.DateTime().Year() == homeTime.DateTime().Year() )
       
  1152             {               
       
  1153             iAlarmInfo.iAlarmTime.SecondsFrom( actualisedRule.iTimeOfChange, secondsDifference );
       
  1154             // Considering the time reference is important as America (North & South) uses
       
  1155             // the Wall time (local time) reference where as whole of Europe refers to time
       
  1156             // in terms of UTC time. Correspondingly, the choise of local time or utc time 
       
  1157             // has to be made.
       
  1158             TTime ruleTime;
       
  1159 
       
  1160             if( ETzUtcTimeReference == actualisedRule.iTimeReference )
       
  1161                 {
       
  1162                 ruleTime = currentTime;
       
  1163                 }
       
  1164             else if( ETzWallTimeReference == actualisedRule.iTimeReference )
       
  1165                 {
       
  1166                 ruleTime = homeTime;
       
  1167                 }
       
  1168             else if( ETzStdTimeReference == actualisedRule.iTimeReference )
       
  1169                 {
       
  1170                 // TODO: Testing so far hasn't encountered a rule in this time reference. 
       
  1171                 // If in case an error is found, corresponding code can be added here.
       
  1172                 // No support from symbian for this.
       
  1173                 }
       
  1174 
       
  1175             TDateTime sevenDays( FALSE, EJanuary, KDaysInWeek, FALSE, FALSE, FALSE, FALSE );
       
  1176             TTime tempTime( sevenDays );
       
  1177             TTime newTime( ruleTime.Int64() + tempTime.Int64() );
       
  1178 
       
  1179             TTimeIntervalDays temp;
       
  1180             temp = newTime.DaysFrom( ruleTime );
       
  1181 
       
  1182             if( ( secondsDifference.Int() >= KNoDifference ) &&
       
  1183                 ( newTime > iAlarmInfo.iAlarmTime ) && 
       
  1184                 ( actualisedRule.iTimeOfChange < iAlarmInfo.iAlarmTime ) && 
       
  1185                 ( ruleTime < actualisedRule.iTimeOfChange ) )
       
  1186                 {
       
  1187                 // If there is a match, save the index and break.
       
  1188                 // We've got the rule and there's no need to continue with other rules.
       
  1189                 ruleMatchIndex = ruleIndex;
       
  1190                 ruleMatchTime = actualisedRule.iTimeOfChange;
       
  1191                 break;
       
  1192                 }
       
  1193             }
       
  1194         }
       
  1195 
       
  1196     if( ruleMatchIndex > KZerothRule )
       
  1197         {
       
  1198         // There's a match, display the information note about DST change.
       
  1199         TTime displayTime;
       
  1200         TTimeIntervalHours oneHour( KOneHour );         
       
  1201 
       
  1202         displayTime = iAlarmInfo.iAlarmTime;
       
  1203 
       
  1204         TBuf< KMaxCharsInNote > dateTimeString;
       
  1205 
       
  1206         // dateString will have "11:59 pm" - as above, but no seconds
       
  1207         displayTime.FormatL( dateTimeString, KDateTimeFormatter );
       
  1208 
       
  1209         // If This note is displayed,
       
  1210         CAknInformationNote* informationNote = new( ELeave ) CAknInformationNote( ETrue );
       
  1211 
       
  1212         HBufC* noteText = StringLoader::LoadLC(
       
  1213                 R_QTN_CLOCK_NOTE_ALARM_DST_ROLLOVER, 
       
  1214                 dateTimeString, 
       
  1215                 iCoeEnv);               
       
  1216         TInt error = informationNote->ExecuteLD( noteText->Des() );
       
  1217 
       
  1218         // Don't display the second note. Not necessary to show both notes.
       
  1219         returnValue = ETrue;
       
  1220         CleanupStack::PopAndDestroy( noteText );                                
       
  1221         } 
       
  1222 
       
  1223     tzHandle.Close();
       
  1224     CleanupStack::PopAndDestroy( vActualisedRules);
       
  1225     CleanupStack::PopAndDestroy( currentRules );
       
  1226     CleanupStack::PopAndDestroy( currentTZId );
       
  1227     CleanupStack::PopAndDestroy( &tzHandle );
       
  1228     
       
  1229     __PRINTS( "CClockAlarmEditorImpl::CheckForDstChangesL - Exit" );
       
  1230 
       
  1231     return returnValue;
       
  1232     }
       
  1233 
   882 // End of file
  1234 // End of file