meetingrequest/mrgui/src/cesmrtodotimevalidator.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-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     if ( aEditor.IsVisible() )
       
   108         {
       
   109         aEditor.SetTime( aTime );
       
   110         }
       
   111     }
       
   112 
       
   113 /**
       
   114  * Sets date to editor. Date is checked and adjusted
       
   115  * between min and max before setting
       
   116  * @param aEditor Reference to time editor
       
   117  * @param aDate On return contains the set date.
       
   118  */
       
   119 void SetDateToEditor(
       
   120         CEikDateEditor& aEditor,
       
   121         TTime& aDate )
       
   122     {
       
   123     if ( aDate < KMinTTime )
       
   124         {
       
   125         aDate = KMinTTime;
       
   126         }
       
   127     else if ( aDate > KMaxTTime )
       
   128         {
       
   129         aDate = KMaxTTime;
       
   130         }
       
   131 
       
   132     if ( aEditor.IsVisible() )
       
   133         {
       
   134         aEditor.SetDate( aDate );
       
   135         }
       
   136     }
       
   137 
       
   138 /**
       
   139  * Returns the default alarm time for all day event
       
   140  * @param allday event start time
       
   141  * @return alarm time
       
   142  */
       
   143 TTime DefaultToDoAlarmL( TTime& aTodoDueDate )
       
   144     {
       
   145     TDateTime alarmTime = aTodoDueDate.DateTime();
       
   146     alarmTime.SetHour( KNoon );
       
   147     alarmTime.SetMinute( KZero );
       
   148     alarmTime.SetSecond( KZero );
       
   149 
       
   150     TTime defaultAlarmTime = alarmTime;
       
   151 
       
   152     if ( defaultAlarmTime < KMinTTime )
       
   153         {
       
   154         defaultAlarmTime = KMinTTime;
       
   155         }
       
   156 
       
   157     return defaultAlarmTime;
       
   158     }
       
   159 
       
   160 }
       
   161 
       
   162 // ======== MEMBER FUNCTIONS ========
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CESMRTodoTimeValidator::CESMRAnnivTimeValidator()
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 inline CESMRTodoTimeValidator::CESMRTodoTimeValidator()
       
   169 :   iCurrentDueDate( Time::NullTTime() ),
       
   170     iCurrentAlarmTime( Time::NullTTime() ),
       
   171     iAlarmOnOff( EFalse )
       
   172     {
       
   173     FUNC_LOG;
       
   174     // Do nothing
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CESMRTodoTimeValidator::~CESMRTodoTimeValidator
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CESMRTodoTimeValidator::~CESMRTodoTimeValidator( )
       
   182     {
       
   183     FUNC_LOG;
       
   184     // Do nothing
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CESMRTodoTimeValidator::NewL
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 CESMRTodoTimeValidator* CESMRTodoTimeValidator::NewL()
       
   192     {
       
   193     FUNC_LOG;
       
   194     CESMRTodoTimeValidator* self = new (ELeave) CESMRTodoTimeValidator();
       
   195     return self;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CESMRTodoTimeValidator::ValidateL
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 MESMRFieldValidator::TESMRFieldValidatorError
       
   203         CESMRTodoTimeValidator::ValidateL( TBool aCorrectAutomatically )
       
   204     {
       
   205     FUNC_LOG;
       
   206     const MESMRFieldValidator::TESMRFieldValidatorError KErrorNone(
       
   207             MESMRFieldValidator::EErrorNone );
       
   208 
       
   209     MESMRFieldValidator::TESMRFieldValidatorError error( KErrorNone );
       
   210 
       
   211     if ( aCorrectAutomatically )
       
   212         {
       
   213         ForceValuesL();
       
   214         }
       
   215     else
       
   216         {
       
   217         if ( iAlarmOnOff )
       
   218             {
       
   219             TTime currentTime; currentTime.HomeTime();
       
   220 
       
   221             TTime start = DueDateTimeL();
       
   222             TTime alarm = AlarmDateTimeL();
       
   223 
       
   224             if ( currentTime > alarm )
       
   225                 {
       
   226                 error = MESMRFieldValidator::EErrorAlarmInPast;
       
   227                 }
       
   228 
       
   229             if ( start < alarm )
       
   230                 {
       
   231                 SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   232                 SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   233 
       
   234                 error = MESMRFieldValidator::EErrorAlarmLaterThanStart;
       
   235                 }
       
   236             }
       
   237         }
       
   238     return error;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CESMRTodoTimeValidator::ReadValuesFromEntryL
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 void CESMRTodoTimeValidator::ReadValuesFromEntryL(
       
   246         MESMRCalEntry& aEntry )
       
   247     {
       
   248     FUNC_LOG;
       
   249     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
       
   250         {
       
   251         __ASSERT_DEBUG( iDueDate, Panic(EESMRAnnivValidatorNullStartDate) );
       
   252         __ASSERT_DEBUG( iAlarmTime, Panic(EESMRAnnivValidatorNullAlarmTime) );
       
   253         __ASSERT_DEBUG( iAlarmDate, Panic(EESMRAnnivValidatorNullAlarmDate) );
       
   254 
       
   255         iEntry = &aEntry;
       
   256         CCalEntry& entry( aEntry.Entry() );
       
   257 
       
   258         TCalTime dueDate = entry.EndTimeL();
       
   259         iCurrentDueDate = dueDate.TimeLocalL();
       
   260         SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   261 
       
   262         TDateTime dueDt = iCurrentDueDate.DateTime();
       
   263 
       
   264         CCalAlarm* alarm = entry.AlarmL();
       
   265         CleanupStack::PushL( alarm );
       
   266 
       
   267         if  ( alarm )
       
   268             {
       
   269             iCurrentAlarmTime = iCurrentDueDate - alarm->TimeOffset();
       
   270             iAlarmOnOff = ETrue;
       
   271 
       
   272             SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   273             SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   274             }
       
   275 
       
   276         CleanupStack::PopAndDestroy( alarm );
       
   277         alarm = NULL;
       
   278 
       
   279         DrawEditorsDeferred();
       
   280         }
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CESMRTodoTimeValidator::StoreValuesToEntryL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CESMRTodoTimeValidator::StoreValuesToEntryL(
       
   288         MESMRCalEntry& aEntry )
       
   289     {
       
   290     FUNC_LOG;
       
   291     if ( MESMRCalEntry::EESMRCalEntryTodo == aEntry.Type() )
       
   292         {
       
   293         PreValidateEditorContent();
       
   294         CCalEntry& entry( aEntry.Entry() );
       
   295 
       
   296         TTime toEditorDueDate = DueDateTimeL();
       
   297         TCalTime todoDueDate;
       
   298 
       
   299         // The default mode for To-do is EFloating,
       
   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             {
       
   305             TCalTime::TTimeMode timeMode =
       
   306                             aEntry.Entry().StartTimeL().TimeMode();
       
   307 
       
   308             switch ( timeMode )
       
   309                 {
       
   310                 case TCalTime::EFixedUtc:
       
   311                 	{
       
   312                     todoDueDate.SetTimeUtcL( toEditorDueDate );
       
   313                     break;
       
   314                 	}
       
   315                 case TCalTime::EFixedTimeZone:
       
   316                 	{
       
   317                     todoDueDate.SetTimeLocalL( toEditorDueDate );
       
   318                     break;
       
   319                 	}
       
   320                 case TCalTime::EFloating: // Fall through
       
   321                 default:
       
   322                 	{
       
   323                     todoDueDate.SetTimeLocalFloatingL( toEditorDueDate );
       
   324                     break;
       
   325                 	}
       
   326                 }
       
   327             }
       
   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         }
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CESMRTodoTimeValidator::SetStartTimeFieldL
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CESMRTodoTimeValidator::SetStartTimeFieldL(
       
   365         CEikTimeEditor& /*aStartTime*/ )
       
   366     {
       
   367     FUNC_LOG;
       
   368     // No implementation for memo
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CESMRTodoTimeValidator::SetEndTimeFieldL
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CESMRTodoTimeValidator::SetEndTimeFieldL(
       
   376         CEikTimeEditor& /*aEndTime*/ )
       
   377     {
       
   378     FUNC_LOG;
       
   379     // No implementation for to-do
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CESMRTodoTimeValidator::SetStartDateFieldL
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CESMRTodoTimeValidator::SetStartDateFieldL(
       
   387         CEikDateEditor& /*aStartDate*/ )
       
   388     {
       
   389     FUNC_LOG;
       
   390     // No implementation for to-do
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CESMRTodoTimeValidator::SetEndDateFieldL
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CESMRTodoTimeValidator::SetEndDateFieldL(
       
   398         CEikDateEditor& aEndDate )
       
   399     {
       
   400     FUNC_LOG;
       
   401     iDueDate = &aEndDate;
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CESMRTodoTimeValidator::SetAlarmTimeFieldL
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 void CESMRTodoTimeValidator::SetAlarmTimeFieldL(
       
   409         CEikTimeEditor& aAlarmTime )
       
   410     {
       
   411     FUNC_LOG;
       
   412     iAlarmTime = &aAlarmTime;
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CESMRTodoTimeValidator::SetAlarmDateFieldL
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 void CESMRTodoTimeValidator::SetAlarmDateFieldL(
       
   420         CEikDateEditor& aAlarmDate )
       
   421     {
       
   422     FUNC_LOG;
       
   423     iAlarmDate = &aAlarmDate;
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 void CESMRTodoTimeValidator::SetRecurrenceUntilDateFieldL(
       
   431             CEikDateEditor& /*aRecurrenceUntil*/ )
       
   432     {
       
   433     FUNC_LOG;
       
   434     // No implementation for to-do
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CESMRTodoTimeValidator::StartTimeChangedL
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CESMRTodoTimeValidator::StartTimeChangedL()
       
   442     {
       
   443     FUNC_LOG;
       
   444     StartDateChandedL();
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CESMRTodoTimeValidator::EndTimeChangedL
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void CESMRTodoTimeValidator::EndTimeChangedL()
       
   452     {
       
   453     FUNC_LOG;
       
   454     // No implementation for to-do
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // CESMRTodoTimeValidator::StartDateChandedL
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 void CESMRTodoTimeValidator::StartDateChandedL()
       
   462     {
       
   463     FUNC_LOG;
       
   464     // No implementation for to-do
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // CESMRTodoTimeValidator::EndDateChangedL
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CESMRTodoTimeValidator::EndDateChangedL()
       
   472     {
       
   473     FUNC_LOG;
       
   474     PreValidateEditorContent();
       
   475 
       
   476     TTime due = DueDateTimeL();
       
   477     TTimeIntervalDays diff =  due.DaysFrom( iCurrentDueDate );
       
   478     iCurrentDueDate = due;
       
   479     SetDateToEditor( *iDueDate, iCurrentDueDate );
       
   480 
       
   481     if ( iAlarmOnOff )
       
   482         {
       
   483         TTime alarm = AlarmDateTimeL();
       
   484         alarm += diff;
       
   485 
       
   486         iCurrentAlarmTime = alarm;
       
   487 
       
   488         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   489         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   490         }
       
   491 
       
   492     DrawEditorsDeferred();
       
   493     }
       
   494 
       
   495 // ---------------------------------------------------------------------------
       
   496 // CESMRTodoTimeValidator::AlarmTimeChangedL
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 void CESMRTodoTimeValidator::AlarmTimeChangedL()
       
   500     {
       
   501     FUNC_LOG;
       
   502     AlarmDateChangedL();
       
   503     }
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 // CESMRTodoTimeValidator::AlarmDateChangedL
       
   507 // ---------------------------------------------------------------------------
       
   508 //
       
   509 void CESMRTodoTimeValidator::AlarmDateChangedL()
       
   510     {
       
   511     FUNC_LOG;
       
   512     TInt err( KErrNone );
       
   513     PreValidateEditorContent();
       
   514 
       
   515     TTime due = DueDateTimeL();
       
   516     TTime alarm = AlarmDateTimeL();
       
   517 
       
   518     if ( alarm > due )
       
   519         {
       
   520         err = KErrArgument;
       
   521         }
       
   522     else
       
   523         {
       
   524         iCurrentAlarmTime = alarm;
       
   525         }
       
   526 
       
   527     SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   528     SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   529 
       
   530     DrawEditorsDeferred();
       
   531 
       
   532     User::LeaveIfError( err );
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // CESMRTodoTimeValidator::RelativeAlarmChangedL
       
   537 // ---------------------------------------------------------------------------
       
   538 //
       
   539 void CESMRTodoTimeValidator::RelativeAlarmChangedL(
       
   540         TTimeIntervalMinutes /*aCurrentAlarmTimeOffset*/,
       
   541         TBool /*aHandleAlarmChange*/,
       
   542         TBool& /*aRelativeAlarmValid*/ )
       
   543     {
       
   544     FUNC_LOG;
       
   545     // No implementation for To-do
       
   546     }
       
   547 
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 // CESMRTodoTimeValidator::SetAllDayEventL
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CESMRTodoTimeValidator::SetAllDayEventL(
       
   554         TBool /*aAlldayEvent*/ )
       
   555     {
       
   556     FUNC_LOG;
       
   557     // No implementation for to-do
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // CESMRTodoTimeValidator::SetAlarmOnOffL
       
   562 // ---------------------------------------------------------------------------
       
   563 //
       
   564 void CESMRTodoTimeValidator::SetAlarmOnOffL(
       
   565         TBool aAlarmOn )
       
   566     {
       
   567     FUNC_LOG;
       
   568     iAlarmOnOff = aAlarmOn;
       
   569 
       
   570     if ( iAlarmOnOff )
       
   571         {
       
   572         if ( iCurrentAlarmTime == Time::NullTTime() ||
       
   573              iCurrentAlarmTime > iCurrentDueDate )
       
   574             {
       
   575             iCurrentAlarmTime = DefaultToDoAlarmL( iCurrentDueDate );
       
   576             }
       
   577 
       
   578         SetTimeToEditor( *iAlarmTime, iCurrentAlarmTime );
       
   579         SetDateToEditor( *iAlarmDate, iCurrentAlarmTime );
       
   580 
       
   581         DrawEditorsDeferred();
       
   582         }
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 // CESMRTodoTimeValidator::RecurrenceChangedL
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CESMRTodoTimeValidator::RecurrenceChangedL(
       
   590         TESMRRecurrenceValue /*aRecurrence*/ )
       
   591     {
       
   592     FUNC_LOG;
       
   593     // No implementation for to-do
       
   594     }
       
   595 
       
   596 // ---------------------------------------------------------------------------
       
   597 // CESMRTodoTimeValidator::RecurrenceEndDateChangedL
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 void CESMRTodoTimeValidator::RecurrenceEndDateChangedL()
       
   601     {
       
   602     FUNC_LOG;
       
   603     // No implementation for to-do
       
   604     }
       
   605 
       
   606 // ---------------------------------------------------------------------------
       
   607 // CESMRTodoTimeValidator::IsRelativeAlarmValid
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 TBool CESMRTodoTimeValidator::IsRelativeAlarmValid(
       
   611 		TTimeIntervalMinutes /*aAlarmTimeOffset*/ )
       
   612     {
       
   613     FUNC_LOG;
       
   614     __ASSERT_DEBUG( ETrue, Panic( EESMRAnnivValidatorRelativeAlarm ) );
       
   615     return EFalse;
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // CESMRTodoTimeValidator::PreValidateEditorContent
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 TInt CESMRTodoTimeValidator::PreValidateEditorContent()
       
   623     {
       
   624     FUNC_LOG;
       
   625     TInt err( KErrNone );
       
   626     TRAP( err, PreValidateEditorContentL() );
       
   627     return err;
       
   628     }
       
   629 
       
   630 // ---------------------------------------------------------------------------
       
   631 // CESMRTodoTimeValidator::PreValidateEditorContentL
       
   632 // ---------------------------------------------------------------------------
       
   633 //
       
   634 void CESMRTodoTimeValidator::PreValidateEditorContentL()
       
   635     {
       
   636     FUNC_LOG;
       
   637     if ( iDueDate && iDueDate->IsVisible() )
       
   638         {
       
   639         iDueDate->PrepareForFocusLossL();
       
   640         }
       
   641 
       
   642     if ( iAlarmTime && iAlarmTime->IsVisible() )
       
   643         {
       
   644         iAlarmTime->PrepareForFocusLossL();
       
   645         }
       
   646 
       
   647     if ( iAlarmDate && iAlarmDate->IsVisible() )
       
   648         {
       
   649         iAlarmDate->PrepareForFocusLossL();
       
   650         }
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // CESMRTodoTimeValidator::DrawEditorsDeferred
       
   655 // ---------------------------------------------------------------------------
       
   656 //
       
   657 void CESMRTodoTimeValidator::DrawEditorsDeferred()
       
   658     {
       
   659     FUNC_LOG;
       
   660     if ( iDueDate && iDueDate->IsVisible() )
       
   661         {
       
   662         iDueDate->DrawDeferred();
       
   663         }
       
   664 
       
   665     if ( iAlarmTime && iAlarmTime->IsVisible() )
       
   666         {
       
   667         iAlarmTime->DrawDeferred();
       
   668         }
       
   669 
       
   670     if ( iAlarmDate && iAlarmDate->IsVisible() )
       
   671         {
       
   672         iAlarmDate->DrawDeferred();
       
   673         }
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // CESMRTodoTimeValidator::DueStartDateL
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 TDateTime CESMRTodoTimeValidator::DueStartDateL()
       
   681     {
       
   682     FUNC_LOG;
       
   683     return iDueDate->Date().DateTime();
       
   684     }
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // CESMRTodoTimeValidator::DueDateTimeL
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 TDateTime CESMRTodoTimeValidator::DueDateTimeL()
       
   691     {
       
   692     FUNC_LOG;
       
   693     TDateTime todoDueDate = iDueDate->Date().DateTime();
       
   694 
       
   695     // We want to set 23 h 59 min 00 sec for new entries
       
   696     if( !iEntry->IsStoredL() )
       
   697         {
       
   698         todoDueDate.SetHour( KMaxHours );
       
   699         todoDueDate.SetMinute( KMaxMinutes );
       
   700         todoDueDate.SetSecond( KMaxSeconds );
       
   701         }
       
   702     // But for existing entries, we want to use existing values to avoid 
       
   703     // problems when saving the values to entry
       
   704     else
       
   705    	    {
       
   706         todoDueDate.SetHour( 
       
   707             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Hour() );
       
   708         todoDueDate.SetMinute( 
       
   709             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Minute() );
       
   710         todoDueDate.SetSecond( 
       
   711             iEntry->Entry().EndTimeL().TimeLocalL().DateTime().Second() );
       
   712         }
       
   713 
       
   714     return todoDueDate;
       
   715     }
       
   716 
       
   717 // ---------------------------------------------------------------------------
       
   718 // CESMRTodoTimeValidator::AlarmDateTimeL
       
   719 // ---------------------------------------------------------------------------
       
   720 //
       
   721 TDateTime CESMRTodoTimeValidator::AlarmDateTimeL()
       
   722     {
       
   723     FUNC_LOG;
       
   724     TDateTime alarmDateTime = iAlarmDate->Date().DateTime();
       
   725     TDateTime alarmTime = iAlarmTime->Time().DateTime();
       
   726 
       
   727     alarmDateTime.SetHour( alarmTime.Hour() );
       
   728     alarmDateTime.SetMinute( alarmTime.Minute() );
       
   729     alarmDateTime.SetSecond( alarmTime.Second() );
       
   730 
       
   731     return alarmDateTime;
       
   732     }
       
   733 
       
   734 // ---------------------------------------------------------------------------
       
   735 // CESMRTodoTimeValidator::ForceValuesL
       
   736 // ---------------------------------------------------------------------------
       
   737 //
       
   738 void CESMRTodoTimeValidator::ForceValuesL()
       
   739     {
       
   740     FUNC_LOG;
       
   741     if ( iAlarmOnOff )
       
   742         {
       
   743         TTime dueDate = DueDateTimeL();
       
   744         TTime alarm = AlarmDateTimeL();
       
   745 
       
   746         // For alarm following cehcks and corrections are made:
       
   747         // - Alarm is more that 31 days before start
       
   748         //    --> Alarm is adjusted to be 30,5 half days before
       
   749         // - Alarm is later than start time
       
   750         //     --> Default alarm time is set for alarm
       
   751         // - Alarm occurs in past
       
   752         //    --> For unsaved entries alarm is set off
       
   753         //
       
   754         TTimeIntervalDays alarmBefore = dueDate.DaysFrom(alarm);
       
   755         if ( alarmBefore > KMaxAlarmTime )
       
   756             {
       
   757             // Adjust alarm time to 30,5 half days earlier
       
   758             alarm = dueDate - KMaxAlarmTime + TTimeIntervalHours(KNoon);
       
   759             TDateTime alarmTime = alarm.DateTime();
       
   760             alarmTime.SetHour( KNoon );
       
   761             alarmTime.SetMinute( KZero );
       
   762             alarmTime.SetSecond( KZero );
       
   763             alarm = alarmTime;
       
   764             }
       
   765 
       
   766         if ( alarm > dueDate )
       
   767             {
       
   768             // Setting alarm to default value
       
   769             alarm = DefaultToDoAlarmL( dueDate );
       
   770             }
       
   771 
       
   772         TTime currentTime; 
       
   773         currentTime.HomeTime();
       
   774         if ( alarm < currentTime )
       
   775             {
       
   776             if ( !iEntry->IsStoredL() )
       
   777                 {
       
   778                 // Setting alarm to default value if entry is not stored
       
   779                 iAlarmOnOff = EFalse;
       
   780                 }
       
   781             // For stored entries the alarm can remain as it is if it 
       
   782             // not adjusted by two earlier checks.
       
   783             }
       
   784 
       
   785         SetTimeToEditor( *iAlarmTime, alarm );
       
   786         SetDateToEditor( *iAlarmDate, alarm );
       
   787 
       
   788         iCurrentAlarmTime = alarm;
       
   789         }
       
   790     }
       
   791 
       
   792 // EOF
       
   793