meetingrequest/mrgui/src/cesmrtodotimevalidator.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   102     else if ( aTime > KMaxTTime )
   102     else if ( aTime > KMaxTTime )
   103         {
   103         {
   104         aTime = KMaxTTime;
   104         aTime = KMaxTTime;
   105         }
   105         }
   106 
   106 
   107     if ( aEditor.IsVisible() )
   107     aEditor.SetTime( aTime );
   108         {
       
   109         aEditor.SetTime( aTime );
       
   110         }
       
   111     }
   108     }
   112 
   109 
   113 /**
   110 /**
   114  * Sets date to editor. Date is checked and adjusted
   111  * Sets date to editor. Date is checked and adjusted
   115  * between min and max before setting
   112  * between min and max before setting
   126         }
   123         }
   127     else if ( aDate > KMaxTTime )
   124     else if ( aDate > KMaxTTime )
   128         {
   125         {
   129         aDate = KMaxTTime;
   126         aDate = KMaxTTime;
   130         }
   127         }
   131 
   128     aEditor.SetDate( aDate );
   132     if ( aEditor.IsVisible() )
       
   133         {
       
   134         aEditor.SetDate( aDate );
       
   135         }
       
   136     }
   129     }
   137 
   130 
   138 /**
   131 /**
   139  * Returns the default alarm time for all day event
   132  * Returns the default alarm time for to-do
   140  * @param allday event start time
   133  * @param allday event start time
   141  * @return alarm time
   134  * @return alarm time
   142  */
   135  */
   143 TTime DefaultToDoAlarmL( TTime& aTodoDueDate )
   136 TTime DefaultToDoAlarmL( TTime& aTodoDueDate )
   144     {
   137     {
   166 // ---------------------------------------------------------------------------
   159 // ---------------------------------------------------------------------------
   167 //
   160 //
   168 inline CESMRTodoTimeValidator::CESMRTodoTimeValidator()
   161 inline CESMRTodoTimeValidator::CESMRTodoTimeValidator()
   169 :   iCurrentDueDate( Time::NullTTime() ),
   162 :   iCurrentDueDate( Time::NullTTime() ),
   170     iCurrentAlarmTime( Time::NullTTime() ),
   163     iCurrentAlarmTime( Time::NullTTime() ),
   171     iAlarmOnOff( EFalse )
   164     iAlarmOnOff( EFalse ),
       
   165     iInitialAlarmTime( Time::NullTTime() ),
       
   166     iInitialAlarmOnOff( EFalse ),
       
   167     iInitialDueDate( Time::NullTTime() )
       
   168     
   172     {
   169     {
   173     FUNC_LOG;
   170     FUNC_LOG;
   174     // Do nothing
   171     // Do nothing
   175     }
   172     }
   176 
   173 
   231                 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
   228                 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
   232                 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
   229                 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
   233 
   230 
   234                 error = MESMRFieldValidator::EErrorAlarmLaterThanStart;
   231                 error = MESMRFieldValidator::EErrorAlarmLaterThanStart;
   235                 }
   232                 }
       
   233 
       
   234 			if ( alarm < start )
       
   235 				{
       
   236 				TTimeIntervalDays alarmBefore = start.DaysFrom(alarm);
       
   237 				if ( alarmBefore > KMaxAlarmTime )
       
   238 					{
       
   239 					error =  MESMRFieldValidator::EErrorAlarmTooMuchInPast;
       
   240 					}
       
   241 				}
       
   242                 
   236             }
   243             }
   237         }
   244         }
   238     return error;
   245     return error;
   239     }
   246     }
   240 
   247 
   256         CCalEntry& entry( aEntry.Entry() );
   263         CCalEntry& entry( aEntry.Entry() );
   257 
   264 
   258         TCalTime dueDate = entry.EndTimeL();
   265         TCalTime dueDate = entry.EndTimeL();
   259         iCurrentDueDate = dueDate.TimeLocalL();
   266         iCurrentDueDate = dueDate.TimeLocalL();
   260         SetDateToEditor( *iDueDate, iCurrentDueDate );
   267         SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   268         
       
   269         iInitialDueDate = iDueDate->Date();
   261 
   270 
   262         TDateTime dueDt = iCurrentDueDate.DateTime();
   271         TDateTime dueDt = iCurrentDueDate.DateTime();
   263 
   272 
   264         CCalAlarm* alarm = entry.AlarmL();
   273         CCalAlarm* alarm = entry.AlarmL();
   265         CleanupStack::PushL( alarm );
   274         CleanupStack::PushL( alarm );
   266 
   275 
   267         if  ( alarm )
   276         if  ( alarm )
   268             {
   277             {
   269             iCurrentAlarmTime = iCurrentDueDate - alarm->TimeOffset();
   278             iCurrentAlarmTime = iCurrentDueDate - alarm->TimeOffset();
   270             iAlarmOnOff = ETrue;
   279             iAlarmOnOff = ETrue;
       
   280             iInitialAlarmOnOff = iAlarmOnOff;
   271 
   281 
   272             SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
   282             SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
   273             SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
   283             SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   284             
       
   285             iInitialAlarmTime = iAlarmTime->Time();
       
   286             iInitialAlarmDate = iAlarmDate->Date();
   274             }
   287             }
   275 
   288 
   276         CleanupStack::PopAndDestroy( alarm );
   289         CleanupStack::PopAndDestroy( alarm );
   277         alarm = NULL;
   290         alarm = NULL;
   278 
   291 
   291     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
   304     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
   292         {
   305         {
   293         PreValidateEditorContent();
   306         PreValidateEditorContent();
   294         CCalEntry& entry( aEntry.Entry() );
   307         CCalEntry& entry( aEntry.Entry() );
   295 
   308 
   296         TTime toEditorDueDate = DueDateTimeL();
   309         // If entry has been modified, we will write new values to entry.
   297         TCalTime todoDueDate;
   310         // Otherwise entry will not be modified and thus saved 
   298 
   311         // (ex. new entry and press only Done )
   299         // The default mode for To-do is EFloating,
   312         if( IsModifiedL( aEntry ) )
   300         // But some 3rd party application might have saved a different type
       
   301         // for one reason or another. In that case we are using
       
   302         // the existing value.
       
   303         if ( aEntry.IsStoredL() )
       
   304             {
   313             {
   305             TCalTime::TTimeMode timeMode =
   314             TTime toEditorDueDate = DueDateTimeL();
   306                             aEntry.Entry().StartTimeL().TimeMode();
   315             TCalTime todoDueDate;
   307 
   316     
   308             switch ( timeMode )
   317             // The default mode for To-do is EFloating,
       
   318             // But some 3rd party application might have saved a different type
       
   319             // for one reason or another. In that case we are using
       
   320             // the existing value.
       
   321             if ( aEntry.IsStoredL() )
   309                 {
   322                 {
   310                 case TCalTime::EFixedUtc:
   323                 TCalTime::TTimeMode timeMode =
   311                 	{
   324                                 aEntry.Entry().StartTimeL().TimeMode();
   312                     todoDueDate.SetTimeUtcL( toEditorDueDate );
   325     
   313                     break;
   326                 switch ( timeMode )
   314                 	}
   327                     {
   315                 case TCalTime::EFixedTimeZone:
   328                     case TCalTime::EFixedUtc:
   316                 	{
   329                         {
   317                     todoDueDate.SetTimeLocalL( toEditorDueDate );
   330                         todoDueDate.SetTimeUtcL( toEditorDueDate );
   318                     break;
   331                         break;
   319                 	}
   332                         }
   320                 case TCalTime::EFloating: // Fall through
   333                     case TCalTime::EFixedTimeZone:
   321                 default:
   334                         {
   322                 	{
   335                         todoDueDate.SetTimeLocalL( toEditorDueDate );
   323                     todoDueDate.SetTimeLocalFloatingL( toEditorDueDate );
   336                         break;
   324                     break;
   337                         }
   325                 	}
   338                     case TCalTime::EFloating: // Fall through
       
   339                     default:
       
   340                         {
       
   341                         todoDueDate.SetTimeLocalFloatingL( toEditorDueDate );
       
   342                         break;
       
   343                         }
       
   344                     }
       
   345                 }
       
   346             else
       
   347                 {
       
   348                 todoDueDate.SetTimeLocalFloatingL( toEditorDueDate );
       
   349                 }
       
   350     
       
   351             entry.SetStartAndEndTimeL( todoDueDate, todoDueDate );
       
   352     
       
   353             if ( iAlarmOnOff )
       
   354                 {
       
   355                 TTimeIntervalMinutes diff;
       
   356     
       
   357                 TTime alarm = AlarmDateTimeL();
       
   358                 toEditorDueDate.MinutesFrom( alarm, diff );
       
   359     
       
   360                 CCalAlarm* alarmObject = entry.AlarmL();
       
   361                 if ( !alarmObject )
       
   362                     {
       
   363                     alarmObject = CCalAlarm::NewL();
       
   364                     }
       
   365                 CleanupStack::PushL( alarmObject );
       
   366                 alarmObject->SetTimeOffset( diff );
       
   367                 entry.SetAlarmL( alarmObject );
       
   368                 CleanupStack::PopAndDestroy( alarmObject );
       
   369                 alarmObject = NULL;
       
   370                 }
       
   371             else
       
   372                 {
       
   373                 entry.SetAlarmL( NULL );
   326                 }
   374                 }
   327             }
   375             }
   328         else
       
   329             {
       
   330             todoDueDate.SetTimeLocalFloatingL( toEditorDueDate );
       
   331             }
       
   332 
       
   333         entry.SetStartAndEndTimeL( todoDueDate, todoDueDate );
       
   334 
       
   335         if ( iAlarmOnOff )
       
   336             {
       
   337             TTimeIntervalMinutes diff;
       
   338 
       
   339             TTime alarm = AlarmDateTimeL();
       
   340             toEditorDueDate.MinutesFrom( alarm, diff );
       
   341 
       
   342             CCalAlarm* alarmObject = entry.AlarmL();
       
   343             if ( !alarmObject )
       
   344                 {
       
   345                 alarmObject = CCalAlarm::NewL();
       
   346                 }
       
   347             CleanupStack::PushL( alarmObject );
       
   348             alarmObject->SetTimeOffset( diff );
       
   349             entry.SetAlarmL( alarmObject );
       
   350             CleanupStack::PopAndDestroy( alarmObject );
       
   351             alarmObject = NULL;
       
   352             }
       
   353         else
       
   354             {
       
   355             entry.SetAlarmL( NULL );
       
   356             }
       
   357         }
   376         }
   358     }
   377     }
   359 
   378 
   360 // ---------------------------------------------------------------------------
   379 // ---------------------------------------------------------------------------
   361 // CESMRTodoTimeValidator::SetStartTimeFieldL
   380 // CESMRTodoTimeValidator::SetStartTimeFieldL
   397 void CESMRTodoTimeValidator::SetEndDateFieldL(
   416 void CESMRTodoTimeValidator::SetEndDateFieldL(
   398         CEikDateEditor& aEndDate )
   417         CEikDateEditor& aEndDate )
   399     {
   418     {
   400     FUNC_LOG;
   419     FUNC_LOG;
   401     iDueDate = &aEndDate;
   420     iDueDate = &aEndDate;
       
   421     
       
   422     if ( Time::NullTTime() != iCurrentDueDate )
       
   423         {
       
   424         SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   425         }  
   402     }
   426     }
   403 
   427 
   404 // ---------------------------------------------------------------------------
   428 // ---------------------------------------------------------------------------
   405 // CESMRTodoTimeValidator::SetAlarmTimeFieldL
   429 // CESMRTodoTimeValidator::SetAlarmTimeFieldL
   406 // ---------------------------------------------------------------------------
   430 // ---------------------------------------------------------------------------
   408 void CESMRTodoTimeValidator::SetAlarmTimeFieldL(
   432 void CESMRTodoTimeValidator::SetAlarmTimeFieldL(
   409         CEikTimeEditor& aAlarmTime )
   433         CEikTimeEditor& aAlarmTime )
   410     {
   434     {
   411     FUNC_LOG;
   435     FUNC_LOG;
   412     iAlarmTime = &aAlarmTime;
   436     iAlarmTime = &aAlarmTime;
       
   437     
       
   438     if ( iAlarmOnOff )
       
   439         {
       
   440         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   441         }
   413     }
   442     }
   414 
   443 
   415 // ---------------------------------------------------------------------------
   444 // ---------------------------------------------------------------------------
   416 // CESMRTodoTimeValidator::SetAlarmDateFieldL
   445 // CESMRTodoTimeValidator::SetAlarmDateFieldL
   417 // ---------------------------------------------------------------------------
   446 // ---------------------------------------------------------------------------
   419 void CESMRTodoTimeValidator::SetAlarmDateFieldL(
   448 void CESMRTodoTimeValidator::SetAlarmDateFieldL(
   420         CEikDateEditor& aAlarmDate )
   449         CEikDateEditor& aAlarmDate )
   421     {
   450     {
   422     FUNC_LOG;
   451     FUNC_LOG;
   423     iAlarmDate = &aAlarmDate;
   452     iAlarmDate = &aAlarmDate;
       
   453     
       
   454     if ( iAlarmOnOff )
       
   455         {
       
   456         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   457         }
   424     }
   458     }
   425 
   459 
   426 // ---------------------------------------------------------------------------
   460 // ---------------------------------------------------------------------------
   427 // CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL
   461 // CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL
   428 // ---------------------------------------------------------------------------
   462 // ---------------------------------------------------------------------------
   429 //
   463 //
   430 void CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL(
   464 void CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL(
   431             CEikDateEditor& /*aRecurrenceUntil*/ )
   465             CEikDateEditor& /*aRecurrenceUntil*/ )
       
   466     {
       
   467     FUNC_LOG;
       
   468     // No implementation for to-do
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // CESMRTodoTimeValidator::SetAbsoluteAlarmOnOffFieldL
       
   473 // ---------------------------------------------------------------------------
       
   474 //
       
   475 void CESMRTodoTimeValidator::SetAbsoluteAlarmOnOffFieldL( 
       
   476         MMRAbsoluteAlarmController& /*aAbsoluteAlarmController*/ )
   432     {
   477     {
   433     FUNC_LOG;
   478     FUNC_LOG;
   434     // No implementation for to-do
   479     // No implementation for to-do
   435     }
   480     }
   436 
   481 
   564 void CESMRTodoTimeValidator::SetAlarmOnOffL(
   609 void CESMRTodoTimeValidator::SetAlarmOnOffL(
   565         TBool aAlarmOn )
   610         TBool aAlarmOn )
   566     {
   611     {
   567     FUNC_LOG;
   612     FUNC_LOG;
   568     iAlarmOnOff = aAlarmOn;
   613     iAlarmOnOff = aAlarmOn;
   569 
   614     
   570     if ( iAlarmOnOff )
   615     if ( iAlarmOnOff )
   571         {
   616         {
   572         if ( iCurrentAlarmTime == Time::NullTTime() ||
   617         if ( iCurrentAlarmTime == Time::NullTTime() ||
   573              iCurrentAlarmTime > iCurrentDueDate )
   618              iCurrentAlarmTime > iCurrentDueDate )
   574             {
   619             {
   637     if ( iDueDate && iDueDate->IsVisible() )
   682     if ( iDueDate && iDueDate->IsVisible() )
   638         {
   683         {
   639         iDueDate->PrepareForFocusLossL();
   684         iDueDate->PrepareForFocusLossL();
   640         }
   685         }
   641 
   686 
   642     if ( iAlarmTime && iAlarmTime->IsVisible() )
   687     if ( iAlarmOnOff && iAlarmTime && iAlarmTime->IsVisible() )
   643         {
   688         {
   644         iAlarmTime->PrepareForFocusLossL();
   689         iAlarmTime->PrepareForFocusLossL();
   645         }
   690         }
   646 
   691 
   647     if ( iAlarmDate && iAlarmDate->IsVisible() )
   692     if ( iAlarmOnOff && iAlarmDate && iAlarmDate->IsVisible() )
   648         {
   693         {
   649         iAlarmDate->PrepareForFocusLossL();
   694         iAlarmDate->PrepareForFocusLossL();
   650         }
   695         }
   651     }
   696     }
   652 
   697 
   787 
   832 
   788         iCurrentAlarmTime = alarm;
   833         iCurrentAlarmTime = alarm;
   789         }
   834         }
   790     }
   835     }
   791 
   836 
       
   837 // ---------------------------------------------------------------------------
       
   838 // CESMRTodoTimeValidator::IsModifiedL
       
   839 // ---------------------------------------------------------------------------
       
   840 //
       
   841 TBool CESMRTodoTimeValidator::IsModifiedL( MESMRCalEntry& aEntry )
       
   842     {
       
   843     // Checks if any of the editor fields have changed from the original /
       
   844     // initial values
       
   845     TBool isEdited( EFalse );
       
   846     
       
   847     TBool isSame = aEntry.Entry().CompareL( aEntry.OriginalEntry() );
       
   848         
       
   849     if( !isSame ||
       
   850             iInitialAlarmOnOff != iAlarmOnOff ||
       
   851                 iDueDate->Date() != iInitialDueDate )
       
   852         {
       
   853         isEdited = ETrue;
       
   854         }
       
   855 
       
   856     // If alarm is on, we will check alarm time and date also for changes
       
   857     if( iAlarmOnOff )
       
   858         {
       
   859         if( iAlarmTime->Time() != iInitialAlarmTime ||
       
   860                 iAlarmDate->Date() != iInitialAlarmDate )
       
   861             {
       
   862             isEdited = ETrue;
       
   863             }
       
   864         }
       
   865 
       
   866     return isEdited;
       
   867     }
       
   868 
   792 // EOF
   869 // EOF
   793