meetingrequest/mrgui/src/cesmrmixedfieldstorage.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:  Implementation of the class CESMRMixedFieldStorage
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrmixedfieldstorage.h"
       
    20 
       
    21 //<cmail>
       
    22 #include "cesmrpolicy.h"
       
    23 #include "esmrdef.h"
       
    24 //</cmail>
       
    25 
       
    26 #include "cesmrmeetingtimevalidator.h"
       
    27 #include "tesmrentryfield.h"
       
    28 #include "mesmrresponseobserver.h"
       
    29 #include "mesmrcalentry.h"
       
    30 #include "cesmrvalidatorfactory.h"
       
    31 #include "cesmrglobalnote.h"
       
    32 #include "cesmrfield.h"
       
    33 
       
    34 // Unnamed namespace for local definitions
       
    35 namespace { // codescanner::namespace
       
    36 
       
    37 /**
       
    38  * Tests, if entry has valid recurrence for editing.
       
    39  * @param aEntry Reference to entry.
       
    40  * @param aRecurrenceValue On return contains entrys recurrence
       
    41  * @return ETrue, if entry has valid recurrence for editing.
       
    42  *         EFalse, if entry hasn't valid recurrence for editing.
       
    43  */
       
    44 TBool HasValidRecurrenceForEditingL(
       
    45         const MESMRCalEntry& aEntry,
       
    46         TESMRRecurrenceValue& aRecurrenceValue )
       
    47     {
       
    48     TBool retValue( ETrue );
       
    49 
       
    50     if ( aEntry.IsRecurrentEventL() )
       
    51         {
       
    52         TTime until;
       
    53 
       
    54         aEntry.GetRecurrenceL( aRecurrenceValue, until );
       
    55 
       
    56         if ( ERecurrenceNot == aRecurrenceValue ||
       
    57              ERecurrenceUnknown == aRecurrenceValue )
       
    58             {
       
    59             // Entry has unrecognized recurrende type
       
    60             // --> Cannot be edited.
       
    61             retValue = EFalse;
       
    62             }
       
    63         }
       
    64     return retValue;
       
    65     }
       
    66 
       
    67 void ShowValidationErrorL(
       
    68         const MESMRFieldValidator::TESMRFieldValidatorError& aError,
       
    69         TESMREntryFieldId& aUpdatedFocus )
       
    70     {
       
    71     FUNC_LOG;
       
    72     TInt err( KErrArgument );
       
    73     switch ( aError )
       
    74         {
       
    75         case MESMRFieldValidator::EErrorEndEarlierThanStart:
       
    76             {
       
    77             aUpdatedFocus = EESMRFieldMeetingTime;
       
    78             CESMRGlobalNote::ExecuteL(
       
    79                     CESMRGlobalNote::EESMREntryEndEarlierThanItStart );
       
    80             }
       
    81             break;
       
    82 
       
    83         case MESMRFieldValidator::EErrorRecDifferetStartAndEnd:
       
    84             {
       
    85             aUpdatedFocus = EESMRFieldStopDate;
       
    86             CESMRGlobalNote::ExecuteL(
       
    87                     CESMRGlobalNote::EESMRRepeatDifferentStartAndEndDate );
       
    88             }
       
    89             break;
       
    90 
       
    91         case MESMRFieldValidator::EErrorRecUntilEarlierThanStart:
       
    92             {
       
    93             aUpdatedFocus = EESMRFieldRecurrenceDate;
       
    94             CESMRGlobalNote::ExecuteL(
       
    95                     CESMRGlobalNote::EESMRRepeatEndEarlierThanItStart );
       
    96             }
       
    97             break;
       
    98 
       
    99         case MESMRFieldValidator::EErrorAlarmLaterThanStart:
       
   100             {
       
   101             aUpdatedFocus = EESMRFieldAlarmDate;
       
   102             CESMRGlobalNote::ExecuteL(
       
   103                     CESMRGlobalNote::EESMRCalenLaterDate );
       
   104             }
       
   105             break;
       
   106 
       
   107         case MESMRFieldValidator::EErrorAlarmInPast:
       
   108             {
       
   109             aUpdatedFocus = EESMRFieldAlarmDate;
       
   110             CESMRGlobalNote::ExecuteL(
       
   111                     CESMRGlobalNote::EESMRAlarmAlreadyPassed );
       
   112             }
       
   113             break;
       
   114         case MESMRFieldValidator::EErrorRescheduleInstance:
       
   115             {
       
   116             CESMRGlobalNote::ExecuteL(
       
   117                                 CESMRGlobalNote::EESMRRepeatReSchedule );
       
   118             }
       
   119             break;
       
   120         default:
       
   121             err = KErrNone;
       
   122             break;
       
   123         }
       
   124 
       
   125     User::LeaveIfError( err );
       
   126     }
       
   127 
       
   128 } // namespace
       
   129 
       
   130 // ======== MEMBER FUNCTIONS ========
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CESMRMixedFieldStorage::CESMRMixedFieldStorage
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 CESMRMixedFieldStorage::CESMRMixedFieldStorage(
       
   137         MESMRFieldEventObserver& aEventObserver,
       
   138         MESMRResponseObserver* aResponseObserver,
       
   139         MESMRCalEntry& aEntry ) :
       
   140     CESMRFieldStorage( aEventObserver),
       
   141     iResponseObserver(aResponseObserver),
       
   142     iEntry(aEntry)
       
   143     {
       
   144     FUNC_LOG;
       
   145     // Do nothing
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CESMRMixedFieldStorage::~CESMRMixedFieldStorage
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 CESMRMixedFieldStorage::~CESMRMixedFieldStorage( )
       
   153     {
       
   154     FUNC_LOG;
       
   155     delete iValidator;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CESMRMixedFieldStorage::NewL
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 CESMRMixedFieldStorage* CESMRMixedFieldStorage::NewL(
       
   163         MESMRFieldEventObserver& aEventObserver,
       
   164         CESMRPolicy* aPolicy,
       
   165         MESMRResponseObserver* aResponseObserver,
       
   166         MESMRCalEntry& aEntry )
       
   167     {
       
   168     FUNC_LOG;
       
   169     CESMRMixedFieldStorage* self =
       
   170             new (ELeave) CESMRMixedFieldStorage(
       
   171                     aEventObserver,
       
   172                     aResponseObserver,
       
   173                     aEntry );
       
   174 
       
   175     CleanupStack::PushL ( self );
       
   176     self->ConstructL ( aPolicy );
       
   177     CleanupStack::Pop ( self );
       
   178 
       
   179     return self;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CESMRMixedFieldStorage::ConstructL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CESMRMixedFieldStorage::ConstructL( CESMRPolicy* aPolicy )
       
   187     {
       
   188     FUNC_LOG;
       
   189     CESMRFieldStorage::BaseConstructL();
       
   190     // FORWARD allows only attendee fields and description to be edited.
       
   191     // EDIT RECURRENT EVENT allows only start-end time and start date
       
   192     // to be edited.
       
   193 
       
   194     MESMRCalEntry::TESMRRecurrenceModifyingRule rule(
       
   195             iEntry.RecurrenceModRule() );
       
   196 
       
   197     if ( iEntry.IsRecurrentEventL() &&
       
   198          rule == MESMRCalEntry::EESMRAllInSeries  &&
       
   199          EESMREditMR == aPolicy->ViewMode())
       
   200         {
       
   201         // Contruct edit series
       
   202         // validator ownership is transferred
       
   203         MESMRFieldValidator* validator =
       
   204         CESMRValidatorFactory::CreateValidatorL (
       
   205                 aPolicy->EventType() );
       
   206 
       
   207         ConstructEditSeriesEventL(
       
   208                 aPolicy,
       
   209                 validator );
       
   210 
       
   211         iEventType = EMixedFieldStorageEditSeriesEvent;
       
   212         }
       
   213 
       
   214     else if ( aPolicy->ViewMode() != EESMRForwardMR )
       
   215         {
       
   216         MESMRFieldValidator* validator =
       
   217                 CESMRValidatorFactory::CreateValidatorL (
       
   218                             aPolicy->EventType() );
       
   219 
       
   220         ConstructRecurrentEventL ( aPolicy,
       
   221                 validator );
       
   222 
       
   223         iEventType = EMixedFieldStorageRecurrentEvent;
       
   224         }
       
   225     else
       
   226         {
       
   227         // No validator is needed because forwarding does not
       
   228         // affecto to any time fields.
       
   229         MESMRFieldValidator* validator = NULL;
       
   230         ConstructForwardEventL (
       
   231                 aPolicy,
       
   232                 validator );
       
   233 
       
   234         iEventType = EMixedFieldStorageForward;
       
   235         }
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // CESMRMixedFieldStorage::ExternalizeL
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CESMRMixedFieldStorage::ExternalizeL( MESMRCalEntry& aEntry )
       
   243     {
       
   244     FUNC_LOG;
       
   245     CESMRFieldStorage::ExternalizeL ( aEntry );
       
   246     if ( iValidator )
       
   247         {
       
   248         iValidator->StoreValuesToEntryL( aEntry );
       
   249         }
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CESMRMixedFieldStorage::InternalizeL
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CESMRMixedFieldStorage::InternalizeL( MESMRCalEntry& aEntry )
       
   257     {
       
   258     FUNC_LOG;
       
   259     CESMRFieldStorage::InternalizeL ( aEntry );
       
   260     if ( iValidator )
       
   261         {
       
   262         iValidator->ReadValuesFromEntryL( aEntry );
       
   263         }
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CESMRMixedFieldStorage::Validate
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 TInt CESMRMixedFieldStorage::Validate(
       
   271         TESMREntryFieldId& aUpdatedFocus, TBool aForceValidation )
       
   272     {
       
   273     FUNC_LOG;
       
   274     TInt err( KErrNone );
       
   275     if ( iValidator )
       
   276         {
       
   277         MESMRFieldValidator::TESMRFieldValidatorError error;
       
   278         TRAP( err, error = iValidator->ValidateL( aForceValidation ) );
       
   279 
       
   280         if ( !aForceValidation )
       
   281             {
       
   282             // If error note does not success, there is much we can do.
       
   283             TRAP( err, ShowValidationErrorL( error, aUpdatedFocus ) );
       
   284             }
       
   285         else
       
   286             {
       
   287             // Force exit is used.
       
   288             err = KErrNone;
       
   289             }
       
   290         }
       
   291     return err;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CESMRMixedFieldStorage::ConstructForwardEventL
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CESMRMixedFieldStorage::ConstructForwardEventL(
       
   299         CESMRPolicy* aPolicy,
       
   300         MESMRFieldValidator* aValidator )
       
   301     {
       
   302     FUNC_LOG;
       
   303     iValidator = aValidator;
       
   304     
       
   305     RArray< TESMREntryField > array = aPolicy->Fields();
       
   306 
       
   307     TInt fieldCount( array.Count() );
       
   308     for (TInt i(0); i < fieldCount; i++ )
       
   309         {
       
   310         CESMRField* field =  NULL;
       
   311         TBool visible = ( array[i].iFieldViewMode == EESMRFieldTypeDefault );
       
   312         switch ( array[i].iFieldId )
       
   313             {            
       
   314             case EESMRFieldAttendee: //Fall through 
       
   315             case EESMRFieldOptAttendee: //Fall through
       
   316             case EESMRFieldDescription:
       
   317                 {
       
   318                 field = CreateEditorFieldL( iValidator, array[i] );
       
   319                 CleanupStack::PushL( field );
       
   320                 }
       
   321                 break;
       
   322             default:
       
   323                 {
       
   324                 field =  
       
   325 					CreateViewerFieldL( iResponseObserver, array[i], visible );
       
   326                 CleanupStack::PushL( field );
       
   327                 }
       
   328                 break;
       
   329             }
       
   330         
       
   331         AddFieldL( field, visible );
       
   332         CleanupStack::Pop( field );
       
   333         }
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CESMRMixedFieldStorage::ConstructRecurrentEventL
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CESMRMixedFieldStorage::ConstructRecurrentEventL(
       
   341         CESMRPolicy* aPolicy,
       
   342         MESMRFieldValidator* aValidator )
       
   343     {
       
   344     FUNC_LOG;
       
   345     iValidator = aValidator;
       
   346 
       
   347     const RArray<TESMREntryField>& array = aPolicy->Fields();
       
   348     TInt fieldCount( array.Count() );
       
   349     for (TInt i(0); i < fieldCount; ++i )
       
   350         {
       
   351         CESMRField* field = NULL;
       
   352         TBool visible = array[i].iFieldViewMode == EESMRFieldTypeDefault;
       
   353         switch ( array[i].iFieldId )
       
   354             {
       
   355             case EESMRFieldRecurrence: //Fall through
       
   356             case EESMRFieldRecurrenceDate:
       
   357                 {
       
   358                 // When editing occurence --> Recurrence information
       
   359                 // is not shown
       
   360                 break;
       
   361                 }
       
   362             default:
       
   363                 field =  CreateEditorFieldL( iValidator, array[i] );
       
   364                 break;
       
   365             }
       
   366 
       
   367         if ( field )
       
   368             {
       
   369             CleanupStack::PushL( field );
       
   370             AddFieldL(field, visible );
       
   371             CleanupStack::Pop( field );
       
   372             }
       
   373         }
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CESMRMixedFieldStorage::ConstructEditSeriesEventL
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CESMRMixedFieldStorage::ConstructEditSeriesEventL(
       
   381         CESMRPolicy* aPolicy,
       
   382         MESMRFieldValidator* aValidator )
       
   383     {
       
   384     FUNC_LOG;
       
   385     TESMRRecurrenceValue recurrenceType;
       
   386     TBool validRecurrence(
       
   387             HasValidRecurrenceForEditingL(
       
   388                     iEntry,
       
   389                     recurrenceType ) );
       
   390 
       
   391     iValidator = aValidator;
       
   392     const RArray<TESMREntryField>& array = aPolicy->Fields();
       
   393     CESMRField* field =  NULL;
       
   394     
       
   395     TInt fieldCount(  array.Count() );
       
   396     for (TInt i(0); i < fieldCount; i++ )
       
   397         {
       
   398         const TESMREntryField& tfield = array[i];
       
   399         TBool visible = tfield.iFieldViewMode == EESMRFieldTypeDefault;
       
   400         switch ( tfield.iFieldId )
       
   401             {
       
   402             // Flowthrough
       
   403             case EESMRFieldRecurrence:
       
   404             case EESMRFieldRecurrenceDate:
       
   405                 {
       
   406                 if ( validRecurrence )
       
   407                     {
       
   408                     field =  CreateEditorFieldL( iValidator, tfield );
       
   409                     CleanupStack::PushL( field );
       
   410                     }
       
   411                 else
       
   412                     {
       
   413                     // Entry has unrecognized recurrende type
       
   414                     // --> Cannot be edited.
       
   415                     field = CreateViewerFieldL( 
       
   416 								iResponseObserver, tfield, visible );
       
   417                     CleanupStack::PushL( field );
       
   418                     }
       
   419                 }
       
   420                 break;
       
   421             default:
       
   422                 {
       
   423                 field =  CreateEditorFieldL( iValidator, tfield );
       
   424                 CleanupStack::PushL( field );
       
   425                 }
       
   426                 break;
       
   427             }
       
   428         
       
   429         AddFieldL( field, visible );
       
   430         CleanupStack::Pop( field );
       
   431         }
       
   432     }
       
   433 
       
   434 // EOF
       
   435