meetingrequest/mrgui/src/cesmreditorfieldstorage.cpp
changeset 0 8466d47a6819
child 12 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 Field storage for editor dialog
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmreditorfieldstorage.h"
       
    20 
       
    21 //<cmail>
       
    22 #include "cesmrpolicy.h"
       
    23 #include "esmrdef.h"
       
    24 //</cmail>
       
    25 
       
    26 #include "mesmrfieldvalidator.h"
       
    27 #include "tesmrentryfield.h"
       
    28 #include "cesmrvalidatorfactory.h"
       
    29 #include "cesmrglobalnote.h"
       
    30 #include "cesmrfield.h"
       
    31 #include "cesmrfieldeventqueue.h"
       
    32 
       
    33 //logging
       
    34 //performance profiling
       
    35 // <cmail> Removed profiling. </cmail>
       
    36 
       
    37 // Unnamed namespace for local definitions
       
    38 namespace { // codescanner::namespace
       
    39 
       
    40 #ifdef _DEBUG
       
    41 
       
    42 // Definition for panic literal
       
    43 _LIT( KESMREditorFieldStorage, "ESMREditorFieldStorage" );
       
    44 
       
    45 /** CESMREditorFieldStorage panic codes */
       
    46 enum TSMREditorFieldStoragePanic
       
    47     {
       
    48     /** No validator defined */
       
    49     EESMREditorFieldStorageNoValidator = 0
       
    50     };
       
    51 
       
    52 void Panic( TSMREditorFieldStoragePanic aPanic )
       
    53     {
       
    54 
       
    55     User::Panic( KESMREditorFieldStorage, aPanic );
       
    56     }
       
    57 
       
    58 #endif // _DEBUG
       
    59 
       
    60 /**
       
    61  * Shows validation error.
       
    62  * @param aError Defines the validation error
       
    63  * @param aUpdatedFocus On return contains the id of the field,
       
    64  *                      which should be focused.
       
    65  */
       
    66 void ShowValidationErrorL(
       
    67         const MESMRFieldValidator::TESMRFieldValidatorError& aError,
       
    68         TESMREntryFieldId& aUpdatedFocus )
       
    69     {
       
    70     FUNC_LOG;
       
    71     TInt err( KErrArgument );
       
    72     switch ( aError )
       
    73         {
       
    74         case MESMRFieldValidator::EErrorEndEarlierThanStart:
       
    75             {
       
    76             aUpdatedFocus = EESMRFieldMeetingTime;
       
    77             CESMRGlobalNote::ExecuteL(
       
    78                     CESMRGlobalNote::EESMREntryEndEarlierThanItStart );
       
    79             break;
       
    80             }
       
    81 
       
    82         case MESMRFieldValidator::EErrorRecDifferetStartAndEnd:
       
    83             {
       
    84             aUpdatedFocus = EESMRFieldStopDate;
       
    85             CESMRGlobalNote::ExecuteL(
       
    86                     CESMRGlobalNote::EESMRRepeatDifferentStartAndEndDate );
       
    87             break;
       
    88             }
       
    89 
       
    90         case MESMRFieldValidator::EErrorRecUntilEarlierThanStart:
       
    91             {
       
    92             aUpdatedFocus = EESMRFieldRecurrenceDate;
       
    93             CESMRGlobalNote::ExecuteL(
       
    94                     CESMRGlobalNote::EESMRRepeatEndEarlierThanItStart );
       
    95             break;
       
    96             }
       
    97 
       
    98         case MESMRFieldValidator::EErrorAlarmLaterThanStart:
       
    99             {
       
   100             aUpdatedFocus = EESMRFieldAlarmDate;
       
   101             CESMRGlobalNote::ExecuteL(
       
   102                     CESMRGlobalNote::EESMRCalenLaterDate );
       
   103             break;
       
   104             }
       
   105 
       
   106         case MESMRFieldValidator::EErrorAlarmInPast:
       
   107             {
       
   108             aUpdatedFocus = EESMRFieldAlarmDate;
       
   109             CESMRGlobalNote::ExecuteL(
       
   110                     CESMRGlobalNote::EESMRAlarmAlreadyPassed );
       
   111             break;
       
   112             }
       
   113 
       
   114         case MESMRFieldValidator::EErrorAlarmTooMuchInPast:
       
   115             {
       
   116             aUpdatedFocus = EESMRFieldAlarmDate;
       
   117             CESMRGlobalNote::ExecuteL(
       
   118                     CESMRGlobalNote::EESMRDiffMoreThanMonth );
       
   119             break;
       
   120             }
       
   121 
       
   122         case MESMRFieldValidator::EErrorRelativeAlarmInPast:
       
   123             {
       
   124             aUpdatedFocus = EESMRFieldAlarm;
       
   125             CESMRGlobalNote::ExecuteL(
       
   126                     CESMRGlobalNote::EESMRAlarmAlreadyPassed );
       
   127             break;
       
   128             }
       
   129 
       
   130         case MESMRFieldValidator::EErrorRescheduleInstance:
       
   131             {
       
   132             CESMRGlobalNote::ExecuteL(
       
   133                                 CESMRGlobalNote::EESMRRepeatReSchedule );
       
   134             }
       
   135             break;
       
   136         default:
       
   137             {
       
   138             err = KErrNone;
       
   139             break;
       
   140             }
       
   141         }
       
   142 
       
   143     User::LeaveIfError( err );
       
   144     }
       
   145 
       
   146 } // namespace
       
   147 
       
   148 // ======== MEMBER FUNCTIONS ========
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CESMREditorFieldStorage::CESMREditorFieldStorage
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 CESMREditorFieldStorage::CESMREditorFieldStorage(
       
   155         MESMRFieldEventObserver& aEventObserver )
       
   156 :   CESMRFieldStorage( aEventObserver )
       
   157     {
       
   158     FUNC_LOG;
       
   159     // Do nothing
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CESMREditorFieldStorage::~CESMREditorFieldStorage
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 CESMREditorFieldStorage::~CESMREditorFieldStorage( )
       
   167     {
       
   168     FUNC_LOG;
       
   169     delete iValidator;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CESMREditorFieldStorage::NewL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 CESMREditorFieldStorage* CESMREditorFieldStorage::NewL(
       
   177         CESMRPolicy* aPolicy,
       
   178         MESMRFieldEventObserver& aEventObserver )
       
   179     {
       
   180     FUNC_LOG;
       
   181     CESMREditorFieldStorage* self =
       
   182             new (ELeave) CESMREditorFieldStorage( aEventObserver );
       
   183     CleanupStack::PushL ( self );
       
   184     self->ConstructL ( aPolicy );
       
   185     CleanupStack::Pop ( self );
       
   186     return self;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CESMREditorFieldStorage::ConstructL
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CESMREditorFieldStorage::ConstructL( CESMRPolicy* aPolicy )
       
   194     {
       
   195     FUNC_LOG;
       
   196     CESMRFieldStorage::BaseConstructL();
       
   197     iValidator =
       
   198             CESMRValidatorFactory::CreateValidatorL (
       
   199                     aPolicy->EventType() );
       
   200     
       
   201     __ASSERT_DEBUG( iValidator, Panic( EESMREditorFieldStorageNoValidator) );
       
   202 
       
   203     iValidator->SetFieldEventQueue( &EventQueueL() );
       
   204     
       
   205     RArray<TESMREntryField> fields = aPolicy->Fields();
       
   206     const TInt count(fields.Count());
       
   207     
       
   208     for (TInt i(0); i < count; i++ )
       
   209         {
       
   210         TESMREntryField entryField = fields[i];
       
   211         TBool visible( entryField.iFieldViewMode == EESMRFieldTypeDefault);
       
   212         CESMRField* field = CreateEditorFieldL( iValidator, entryField );
       
   213         
       
   214         CleanupStack::PushL( field );
       
   215         AddFieldL( field, visible );
       
   216         CleanupStack::Pop( field );
       
   217         }
       
   218     
       
   219     }
       
   220         
       
   221 // ---------------------------------------------------------------------------
       
   222 // CESMREditorFieldStorage::ExternalizeL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CESMREditorFieldStorage::ExternalizeL( MESMRCalEntry& aEntry )
       
   226     {
       
   227     FUNC_LOG;
       
   228     CESMRFieldStorage::ExternalizeL ( aEntry );
       
   229     iValidator->StoreValuesToEntryL( aEntry );
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CESMREditorFieldStorage::InternalizeL
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CESMREditorFieldStorage::InternalizeL( MESMRCalEntry& aEntry )
       
   237     {
       
   238     FUNC_LOG;
       
   239     CESMRFieldStorage::InternalizeL ( aEntry );
       
   240     iValidator->ReadValuesFromEntryL( aEntry );
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CESMREditorFieldStorage::Validate
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 TInt CESMREditorFieldStorage::Validate(
       
   248         TESMREntryFieldId& aUpdatedFocus, TBool aForceValidation )
       
   249     {
       
   250     FUNC_LOG;
       
   251     MESMRFieldValidator::TESMRFieldValidatorError error;
       
   252     TRAPD( err, error = iValidator->ValidateL( aForceValidation ) );
       
   253 
       
   254     if ( !aForceValidation )
       
   255         {
       
   256         // If error note does not success, there is much we can do.
       
   257         TRAP( err, ShowValidationErrorL( error, aUpdatedFocus ) );
       
   258         }
       
   259     else
       
   260         {
       
   261         // force exit is used.
       
   262         err = KErrNone;
       
   263         }
       
   264 
       
   265     return err;
       
   266     }
       
   267 
       
   268 // EOF
       
   269