meetingrequest/mrgui/src/cesmrtodotimevalidator.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ESMR time and date sanity checks and saving
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <eikmfne.h>
       
    21 #include <calentry.h>
       
    22 #include <calalarm.h>
       
    23 #include <e32std.h>
       
    24 
       
    25 #include "cesmrtodotimevalidator.h"
       
    26 #include "cesmrglobalnote.h"
       
    27 #include "mesmrfieldstorage.h"
       
    28 #include "mesmrcalentry.h"
       
    29 
       
    30 // Unnamed namespace for local definitions
       
    31 namespace {
       
    32 
       
    33 // Definition fom max possible time
       
    34 #define KMaxTTime (TTime(TDateTime(2100, EDecember, 31-2, 23, 59, 59, 999999)))
       
    35 
       
    36 // Definition fom min possible time
       
    37 #define KMinTTime (TTime(TDateTime(1900, EJanuary, 2-1, 0, 0, 0, 0)))
       
    38 
       
    39 // Definition for max alarm duration
       
    40 #define KMaxAlarmTime TTimeIntervalDays(31)
       
    41 
       
    42 // Definition for zero
       
    43 const TInt KZero( 0 );
       
    44 
       
    45 // Definition for half day
       
    46 const TInt KNoon( 12 );
       
    47 
       
    48 // Definition for max hours in day
       
    49 const TInt KMaxHours(23);
       
    50 
       
    51 // Definition for max minutes in day
       
    52 const TInt KMaxMinutes(59);
       
    53 
       
    54 // Definition for max seconsds in day
       
    55 const TInt KMaxSeconds(00);
       
    56 
       
    57 #ifdef _DEBUG
       
    58 
       
    59 // Literal for panics
       
    60 _LIT( KESMRAnnivTimeValidator, "ESMRAnnivTimeValidator" );
       
    61 
       
    62 /** Panic code definitions */
       
    63 enum TESMRAnnivTimeValidator
       
    64     {
       
    65     /** Start date field not set */
       
    66     EESMRAnnivValidatorNullStartDate,
       
    67     /** Start date field not set */
       
    68     EESMRAnnivValidatorNullAlarmTime,
       
    69     /** Start date field not set */
       
    70     EESMRAnnivValidatorNullAlarmDate,
       
    71     /** Relative alarm called for non-relative alarm event */
       
    72     EESMRAnnivValidatorRelativeAlarm
       
    73 
       
    74     };
       
    75 
       
    76 /**
       
    77  * Raises system panic.
       
    78  * @param aPanic Panic code
       
    79  * @see TESMRRecurrentEditValidatorPanic
       
    80  */
       
    81 void Panic( TESMRAnnivTimeValidator aPanic )
       
    82     {
       
    83     User::Panic( KESMRAnnivTimeValidator, aPanic );
       
    84     }
       
    85 
       
    86 #endif // _DEBUG
       
    87 
       
    88 /**
       
    89  * Sets time to editor. Time is checked and adjusted
       
    90  * between min and max before setting
       
    91  * @param aEditor Reference to time editor
       
    92  * @param aTime On return contains the set time.
       
    93  */
       
    94 void SetTimeToEditor(
       
    95         CEikTimeEditor& aEditor,
       
    96         TTime& aTime )
       
    97     {
       
    98     if ( aTime < KMinTTime )
       
    99         {
       
   100         aTime = KMinTTime;
       
   101         }
       
   102     else if ( aTime > KMaxTTime )
       
   103         {
       
   104         aTime = KMaxTTime;
       
   105         }
       
   106 
       
   107     aEditor.SetTime( aTime );
       
   108     }
       
   109 
       
   110 /**
       
   111  * Sets date to editor. Date is checked and adjusted
       
   112  * between min and max before setting
       
   113  * @param aEditor Reference to time editor
       
   114  * @param aDate On return contains the set date.
       
   115  */
       
   116 void SetDateToEditor(
       
   117         CEikDateEditor& aEditor,
       
   118         TTime& aDate )
       
   119     {
       
   120     if ( aDate < KMinTTime )
       
   121         {
       
   122         aDate = KMinTTime;
       
   123         }
       
   124     else if ( aDate > KMaxTTime )
       
   125         {
       
   126         aDate = KMaxTTime;
       
   127         }
       
   128     aEditor.SetDate( aDate );
       
   129     }
       
   130 
       
   131 /**
       
   132  * Returns the default alarm time for to-do
       
   133  * @param allday event start time
       
   134  * @return alarm time
       
   135  */
       
   136 TTime DefaultToDoAlarmL( TTime& aTodoDueDate )
       
   137     {
       
   138     TDateTime alarmTime = aTodoDueDate.DateTime();
       
   139     alarmTime.SetHour( KNoon );
       
   140     alarmTime.SetMinute( KZero );
       
   141     alarmTime.SetSecond( KZero );
       
   142 
       
   143     TTime defaultAlarmTime = alarmTime;
       
   144 
       
   145     if ( defaultAlarmTime < KMinTTime )
       
   146         {
       
   147         defaultAlarmTime = KMinTTime;
       
   148         }
       
   149 
       
   150     return defaultAlarmTime;
       
   151     }
       
   152 
       
   153 }
       
   154 
       
   155 // ======== MEMBER FUNCTIONS ========
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CESMRTodoTimeValidator::CESMRAnnivTimeValidator()
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 inline CESMRTodoTimeValidator::CESMRTodoTimeValidator()
       
   162 :   iCurrentDueDate( Time::NullTTime() ),
       
   163     iCurrentAlarmTime( Time::NullTTime() ),
       
   164     iAlarmOnOff( EFalse ),
       
   165     iInitialAlarmTime( Time::NullTTime() ),
       
   166     iInitialAlarmOnOff( EFalse ),
       
   167     iInitialDueDate( Time::NullTTime() )
       
   168     
       
   169     {
       
   170     FUNC_LOG;
       
   171     // Do nothing
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CESMRTodoTimeValidator::~CESMRTodoTimeValidator
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 CESMRTodoTimeValidator::~CESMRTodoTimeValidator( )
       
   179     {
       
   180     FUNC_LOG;
       
   181     // Do nothing
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CESMRTodoTimeValidator::NewL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 CESMRTodoTimeValidator* CESMRTodoTimeValidator::NewL()
       
   189     {
       
   190     FUNC_LOG;
       
   191     CESMRTodoTimeValidator* self = new (ELeave) CESMRTodoTimeValidator();
       
   192     return self;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CESMRTodoTimeValidator::ValidateL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 MESMRFieldValidator::TESMRFieldValidatorError
       
   200         CESMRTodoTimeValidator::ValidateL( TBool aCorrectAutomatically )
       
   201     {
       
   202     FUNC_LOG;
       
   203     const MESMRFieldValidator::TESMRFieldValidatorError KErrorNone(
       
   204             MESMRFieldValidator::EErrorNone );
       
   205 
       
   206     MESMRFieldValidator::TESMRFieldValidatorError error( KErrorNone );
       
   207 
       
   208     if ( aCorrectAutomatically )
       
   209         {
       
   210         ForceValuesL();
       
   211         }
       
   212     else
       
   213         {
       
   214         if ( iAlarmOnOff )
       
   215             {
       
   216             TTime currentTime; currentTime.HomeTime();
       
   217 
       
   218             TTime start = DueDateTimeL();
       
   219             TTime alarm = AlarmDateTimeL();
       
   220 
       
   221             if ( currentTime > alarm )
       
   222                 {
       
   223                 error = MESMRFieldValidator::EErrorAlarmInPast;
       
   224                 }
       
   225 
       
   226             if ( start < alarm )
       
   227                 {
       
   228                 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   229                 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   230 
       
   231                 error = MESMRFieldValidator::EErrorAlarmLaterThanStart;
       
   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                 
       
   243             }
       
   244         }
       
   245     return error;
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CESMRTodoTimeValidator::ReadValuesFromEntryL
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CESMRTodoTimeValidator::ReadValuesFromEntryL(
       
   253         MESMRCalEntry& aEntry )
       
   254     {
       
   255     FUNC_LOG;
       
   256     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
       
   257         {
       
   258         __ASSERT_DEBUG( iDueDate, Panic(EESMRAnnivValidatorNullStartDate) );
       
   259         __ASSERT_DEBUG( iAlarmTime, Panic(EESMRAnnivValidatorNullAlarmTime) );
       
   260         __ASSERT_DEBUG( iAlarmDate, Panic(EESMRAnnivValidatorNullAlarmDate) );
       
   261 
       
   262         iEntry = &aEntry;
       
   263         CCalEntry& entry( aEntry.Entry() );
       
   264 
       
   265         TCalTime dueDate = entry.EndTimeL();
       
   266         iCurrentDueDate = dueDate.TimeLocalL();
       
   267         SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   268         
       
   269         iInitialDueDate = iDueDate->Date();
       
   270 
       
   271         TDateTime dueDt = iCurrentDueDate.DateTime();
       
   272 
       
   273         CCalAlarm* alarm = entry.AlarmL();
       
   274         CleanupStack::PushL( alarm );
       
   275 
       
   276         if  ( alarm )
       
   277             {
       
   278             iCurrentAlarmTime = iCurrentDueDate - alarm->TimeOffset();
       
   279             iAlarmOnOff = ETrue;
       
   280             iInitialAlarmOnOff = iAlarmOnOff;
       
   281 
       
   282             SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   283             SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   284             
       
   285             iInitialAlarmTime = iAlarmTime->Time();
       
   286             iInitialAlarmDate = iAlarmDate->Date();
       
   287             }
       
   288 
       
   289         CleanupStack::PopAndDestroy( alarm );
       
   290         alarm = NULL;
       
   291 
       
   292         DrawEditorsDeferred();
       
   293         }
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CESMRTodoTimeValidator::StoreValuesToEntryL
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 void CESMRTodoTimeValidator::StoreValuesToEntryL(
       
   301         MESMRCalEntry& aEntry )
       
   302     {
       
   303     FUNC_LOG;
       
   304     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
       
   305         {
       
   306         PreValidateEditorContent();
       
   307         CCalEntry& entry( aEntry.Entry() );
       
   308 
       
   309         // If entry has been modified, we will write new values to entry.
       
   310         // Otherwise entry will not be modified and thus saved 
       
   311         // (ex. new entry and press only Done )
       
   312         if( IsModifiedL( aEntry ) )
       
   313             {
       
   314             TTime toEditorDueDate = DueDateTimeL();
       
   315             TCalTime todoDueDate;
       
   316     
       
   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() )
       
   322                 {
       
   323                 TCalTime::TTimeMode timeMode =
       
   324                                 aEntry.Entry().StartTimeL().TimeMode();
       
   325     
       
   326                 switch ( timeMode )
       
   327                     {
       
   328                     case TCalTime::EFixedUtc:
       
   329                         {
       
   330                         todoDueDate.SetTimeUtcL( toEditorDueDate );
       
   331                         break;
       
   332                         }
       
   333                     case TCalTime::EFixedTimeZone:
       
   334                         {
       
   335                         todoDueDate.SetTimeLocalL( toEditorDueDate );
       
   336                         break;
       
   337                         }
       
   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 );
       
   374                 }
       
   375             }
       
   376         }
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CESMRTodoTimeValidator::SetStartTimeFieldL
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CESMRTodoTimeValidator::SetStartTimeFieldL(
       
   384         CEikTimeEditor& /*aStartTime*/ )
       
   385     {
       
   386     FUNC_LOG;
       
   387     // No implementation for memo
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // CESMRTodoTimeValidator::SetEndTimeFieldL
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CESMRTodoTimeValidator::SetEndTimeFieldL(
       
   395         CEikTimeEditor& /*aEndTime*/ )
       
   396     {
       
   397     FUNC_LOG;
       
   398     // No implementation for to-do
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CESMRTodoTimeValidator::SetStartDateFieldL
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CESMRTodoTimeValidator::SetStartDateFieldL(
       
   406         CEikDateEditor& /*aStartDate*/ )
       
   407     {
       
   408     FUNC_LOG;
       
   409     // No implementation for to-do
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CESMRTodoTimeValidator::SetEndDateFieldL
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CESMRTodoTimeValidator::SetEndDateFieldL(
       
   417         CEikDateEditor& aEndDate )
       
   418     {
       
   419     FUNC_LOG;
       
   420     iDueDate = &aEndDate;
       
   421     
       
   422     if ( Time::NullTTime() != iCurrentDueDate )
       
   423         {
       
   424         SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   425         }  
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // CESMRTodoTimeValidator::SetAlarmTimeFieldL
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CESMRTodoTimeValidator::SetAlarmTimeFieldL(
       
   433         CEikTimeEditor& aAlarmTime )
       
   434     {
       
   435     FUNC_LOG;
       
   436     iAlarmTime = &aAlarmTime;
       
   437     
       
   438     if ( iAlarmOnOff )
       
   439         {
       
   440         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   441         }
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CESMRTodoTimeValidator::SetAlarmDateFieldL
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CESMRTodoTimeValidator::SetAlarmDateFieldL(
       
   449         CEikDateEditor& aAlarmDate )
       
   450     {
       
   451     FUNC_LOG;
       
   452     iAlarmDate = &aAlarmDate;
       
   453     
       
   454     if ( iAlarmOnOff )
       
   455         {
       
   456         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   457         }
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 void CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL(
       
   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*/ )
       
   477     {
       
   478     FUNC_LOG;
       
   479     // No implementation for to-do
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // CESMRTodoTimeValidator::StartTimeChangedL
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 void CESMRTodoTimeValidator::StartTimeChangedL()
       
   487     {
       
   488     FUNC_LOG;
       
   489     StartDateChandedL();
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // CESMRTodoTimeValidator::EndTimeChangedL
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 void CESMRTodoTimeValidator::EndTimeChangedL()
       
   497     {
       
   498     FUNC_LOG;
       
   499     // No implementation for to-do
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // CESMRTodoTimeValidator::StartDateChandedL
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 void CESMRTodoTimeValidator::StartDateChandedL()
       
   507     {
       
   508     FUNC_LOG;
       
   509     // No implementation for to-do
       
   510     }
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 // CESMRTodoTimeValidator::EndDateChangedL
       
   514 // ---------------------------------------------------------------------------
       
   515 //
       
   516 void CESMRTodoTimeValidator::EndDateChangedL()
       
   517     {
       
   518     FUNC_LOG;
       
   519     PreValidateEditorContent();
       
   520 
       
   521     TTime due = DueDateTimeL();
       
   522     TTimeIntervalDays diff =  due.DaysFrom( iCurrentDueDate );
       
   523     iCurrentDueDate = due;
       
   524     SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   525 
       
   526     if ( iAlarmOnOff )
       
   527         {
       
   528         TTime alarm = AlarmDateTimeL();
       
   529         alarm += diff;
       
   530 
       
   531         iCurrentAlarmTime = alarm;
       
   532 
       
   533         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   534         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   535         }
       
   536 
       
   537     DrawEditorsDeferred();
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // CESMRTodoTimeValidator::AlarmTimeChangedL
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CESMRTodoTimeValidator::AlarmTimeChangedL()
       
   545     {
       
   546     FUNC_LOG;
       
   547     AlarmDateChangedL();
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CESMRTodoTimeValidator::AlarmDateChangedL
       
   552 // ---------------------------------------------------------------------------
       
   553 //
       
   554 void CESMRTodoTimeValidator::AlarmDateChangedL()
       
   555     {
       
   556     FUNC_LOG;
       
   557     TInt err( KErrNone );
       
   558     PreValidateEditorContent();
       
   559 
       
   560     TTime due = DueDateTimeL();
       
   561     TTime alarm = AlarmDateTimeL();
       
   562 
       
   563     if ( alarm > due )
       
   564         {
       
   565         err = KErrArgument;
       
   566         }
       
   567     else
       
   568         {
       
   569         iCurrentAlarmTime = alarm;
       
   570         }
       
   571 
       
   572     SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   573     SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   574 
       
   575     DrawEditorsDeferred();
       
   576 
       
   577     User::LeaveIfError( err );
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // CESMRTodoTimeValidator::RelativeAlarmChangedL
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CESMRTodoTimeValidator::RelativeAlarmChangedL(
       
   585         TTimeIntervalMinutes /*aCurrentAlarmTimeOffset*/,
       
   586         TBool /*aHandleAlarmChange*/,
       
   587         TBool& /*aRelativeAlarmValid*/ )
       
   588     {
       
   589     FUNC_LOG;
       
   590     // No implementation for To-do
       
   591     }
       
   592 
       
   593 
       
   594 // ---------------------------------------------------------------------------
       
   595 // CESMRTodoTimeValidator::SetAllDayEventL
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 void CESMRTodoTimeValidator::SetAllDayEventL(
       
   599         TBool /*aAlldayEvent*/ )
       
   600     {
       
   601     FUNC_LOG;
       
   602     // No implementation for to-do
       
   603     }
       
   604 
       
   605 // ---------------------------------------------------------------------------
       
   606 // CESMRTodoTimeValidator::SetAlarmOnOffL
       
   607 // ---------------------------------------------------------------------------
       
   608 //
       
   609 void CESMRTodoTimeValidator::SetAlarmOnOffL(
       
   610         TBool aAlarmOn )
       
   611     {
       
   612     FUNC_LOG;
       
   613     iAlarmOnOff = aAlarmOn;
       
   614     
       
   615     if ( iAlarmOnOff )
       
   616         {
       
   617         if ( iCurrentAlarmTime == Time::NullTTime() ||
       
   618              iCurrentAlarmTime > iCurrentDueDate )
       
   619             {
       
   620             iCurrentAlarmTime = DefaultToDoAlarmL( iCurrentDueDate );
       
   621             }
       
   622 
       
   623         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   624         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   625 
       
   626         DrawEditorsDeferred();
       
   627         }
       
   628     }
       
   629 
       
   630 // ---------------------------------------------------------------------------
       
   631 // CESMRTodoTimeValidator::RecurrenceChangedL
       
   632 // ---------------------------------------------------------------------------
       
   633 //
       
   634 void CESMRTodoTimeValidator::RecurrenceChangedL(
       
   635         TESMRRecurrenceValue /*aRecurrence*/ )
       
   636     {
       
   637     FUNC_LOG;
       
   638     // No implementation for to-do
       
   639     }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // CESMRTodoTimeValidator::RecurrenceEndDateChangedL
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 void CESMRTodoTimeValidator::RecurrenceEndDateChangedL()
       
   646     {
       
   647     FUNC_LOG;
       
   648     // No implementation for to-do
       
   649     }
       
   650 
       
   651 // ---------------------------------------------------------------------------
       
   652 // CESMRTodoTimeValidator::IsRelativeAlarmValid
       
   653 // ---------------------------------------------------------------------------
       
   654 //
       
   655 TBool CESMRTodoTimeValidator::IsRelativeAlarmValid(
       
   656 		TTimeIntervalMinutes /*aAlarmTimeOffset*/ )
       
   657     {
       
   658     FUNC_LOG;
       
   659     __ASSERT_DEBUG( ETrue, Panic( EESMRAnnivValidatorRelativeAlarm ) );
       
   660     return EFalse;
       
   661     }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // CESMRTodoTimeValidator::PreValidateEditorContent
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 TInt CESMRTodoTimeValidator::PreValidateEditorContent()
       
   668     {
       
   669     FUNC_LOG;
       
   670     TInt err( KErrNone );
       
   671     TRAP( err, PreValidateEditorContentL() );
       
   672     return err;
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------------------------
       
   676 // CESMRTodoTimeValidator::PreValidateEditorContentL
       
   677 // ---------------------------------------------------------------------------
       
   678 //
       
   679 void CESMRTodoTimeValidator::PreValidateEditorContentL()
       
   680     {
       
   681     FUNC_LOG;
       
   682     if ( iDueDate && iDueDate->IsVisible() )
       
   683         {
       
   684         iDueDate->PrepareForFocusLossL();
       
   685         }
       
   686 
       
   687     if ( iAlarmOnOff && iAlarmTime && iAlarmTime->IsVisible() )
       
   688         {
       
   689         iAlarmTime->PrepareForFocusLossL();
       
   690         }
       
   691 
       
   692     if ( iAlarmOnOff && iAlarmDate && iAlarmDate->IsVisible() )
       
   693         {
       
   694         iAlarmDate->PrepareForFocusLossL();
       
   695         }
       
   696     }
       
   697 
       
   698 // ---------------------------------------------------------------------------
       
   699 // CESMRTodoTimeValidator::DrawEditorsDeferred
       
   700 // ---------------------------------------------------------------------------
       
   701 //
       
   702 void CESMRTodoTimeValidator::DrawEditorsDeferred()
       
   703     {
       
   704     FUNC_LOG;
       
   705     if ( iDueDate && iDueDate->IsVisible() )
       
   706         {
       
   707         iDueDate->DrawDeferred();
       
   708         }
       
   709 
       
   710     if ( iAlarmTime && iAlarmTime->IsVisible() )
       
   711         {
       
   712         iAlarmTime->DrawDeferred();
       
   713         }
       
   714 
       
   715     if ( iAlarmDate && iAlarmDate->IsVisible() )
       
   716         {
       
   717         iAlarmDate->DrawDeferred();
       
   718         }
       
   719     }
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // CESMRTodoTimeValidator::DueStartDateL
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 TDateTime CESMRTodoTimeValidator::DueStartDateL()
       
   726     {
       
   727     FUNC_LOG;
       
   728     return iDueDate->Date().DateTime();
       
   729     }
       
   730 
       
   731 // ---------------------------------------------------------------------------
       
   732 // CESMRTodoTimeValidator::DueDateTimeL
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 TDateTime CESMRTodoTimeValidator::DueDateTimeL()
       
   736     {
       
   737     FUNC_LOG;
       
   738     TDateTime todoDueDate = iDueDate->Date().DateTime();
       
   739 
       
   740     // We want to set 23 h 59 min 00 sec for new entries
       
   741     if( !iEntry->IsStoredL() )
       
   742         {
       
   743         todoDueDate.SetHour( KMaxHours );
       
   744         todoDueDate.SetMinute( KMaxMinutes );
       
   745         todoDueDate.SetSecond( KMaxSeconds );
       
   746         }
       
   747     // But for existing entries, we want to use existing values to avoid 
       
   748     // problems when saving the values to entry
       
   749     else
       
   750    	    {
       
   751         todoDueDate.SetHour( 
       
   752             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Hour() );
       
   753         todoDueDate.SetMinute( 
       
   754             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Minute() );
       
   755         todoDueDate.SetSecond( 
       
   756             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Second() );
       
   757         }
       
   758 
       
   759     return todoDueDate;
       
   760     }
       
   761 
       
   762 // ---------------------------------------------------------------------------
       
   763 // CESMRTodoTimeValidator::AlarmDateTimeL
       
   764 // ---------------------------------------------------------------------------
       
   765 //
       
   766 TDateTime CESMRTodoTimeValidator::AlarmDateTimeL()
       
   767     {
       
   768     FUNC_LOG;
       
   769     TDateTime alarmDateTime = iAlarmDate->Date().DateTime();
       
   770     TDateTime alarmTime = iAlarmTime->Time().DateTime();
       
   771 
       
   772     alarmDateTime.SetHour( alarmTime.Hour() );
       
   773     alarmDateTime.SetMinute( alarmTime.Minute() );
       
   774     alarmDateTime.SetSecond( alarmTime.Second() );
       
   775 
       
   776     return alarmDateTime;
       
   777     }
       
   778 
       
   779 // ---------------------------------------------------------------------------
       
   780 // CESMRTodoTimeValidator::ForceValuesL
       
   781 // ---------------------------------------------------------------------------
       
   782 //
       
   783 void CESMRTodoTimeValidator::ForceValuesL()
       
   784     {
       
   785     FUNC_LOG;
       
   786     if ( iAlarmOnOff )
       
   787         {
       
   788         TTime dueDate = DueDateTimeL();
       
   789         TTime alarm = AlarmDateTimeL();
       
   790 
       
   791         // For alarm following cehcks and corrections are made:
       
   792         // - Alarm is more that 31 days before start
       
   793         //    --> Alarm is adjusted to be 30,5 half days before
       
   794         // - Alarm is later than start time
       
   795         //     --> Default alarm time is set for alarm
       
   796         // - Alarm occurs in past
       
   797         //    --> For unsaved entries alarm is set off
       
   798         //
       
   799         TTimeIntervalDays alarmBefore = dueDate.DaysFrom(alarm);
       
   800         if ( alarmBefore > KMaxAlarmTime )
       
   801             {
       
   802             // Adjust alarm time to 30,5 half days earlier
       
   803             alarm = dueDate - KMaxAlarmTime + TTimeIntervalHours(KNoon);
       
   804             TDateTime alarmTime = alarm.DateTime();
       
   805             alarmTime.SetHour( KNoon );
       
   806             alarmTime.SetMinute( KZero );
       
   807             alarmTime.SetSecond( KZero );
       
   808             alarm = alarmTime;
       
   809             }
       
   810 
       
   811         if ( alarm > dueDate )
       
   812             {
       
   813             // Setting alarm to default value
       
   814             alarm = DefaultToDoAlarmL( dueDate );
       
   815             }
       
   816 
       
   817         TTime currentTime; 
       
   818         currentTime.HomeTime();
       
   819         if ( alarm < currentTime )
       
   820             {
       
   821             if ( !iEntry->IsStoredL() )
       
   822                 {
       
   823                 // Setting alarm to default value if entry is not stored
       
   824                 iAlarmOnOff = EFalse;
       
   825                 }
       
   826             // For stored entries the alarm can remain as it is if it 
       
   827             // not adjusted by two earlier checks.
       
   828             }
       
   829 
       
   830         SetTimeToEditor( *iAlarmTime, alarm );
       
   831         SetDateToEditor( *iAlarmDate, alarm );
       
   832 
       
   833         iCurrentAlarmTime = alarm;
       
   834         }
       
   835     }
       
   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 
       
   869 // EOF