meetingrequest/mrgui/src/cesmrmixedfieldstorage.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    28 #include "mesmrresponseobserver.h"
    28 #include "mesmrresponseobserver.h"
    29 #include "mesmrcalentry.h"
    29 #include "mesmrcalentry.h"
    30 #include "cesmrvalidatorfactory.h"
    30 #include "cesmrvalidatorfactory.h"
    31 #include "cesmrglobalnote.h"
    31 #include "cesmrglobalnote.h"
    32 #include "cesmrfield.h"
    32 #include "cesmrfield.h"
       
    33 #include "cesmrfieldeventqueue.h"
    33 
    34 
    34 // Unnamed namespace for local definitions
    35 // Unnamed namespace for local definitions
    35 namespace { // codescanner::namespace
    36 namespace { // codescanner::namespace
    36 
    37 
    37 /**
    38 /**
   109             aUpdatedFocus = EESMRFieldAlarmDate;
   110             aUpdatedFocus = EESMRFieldAlarmDate;
   110             CESMRGlobalNote::ExecuteL(
   111             CESMRGlobalNote::ExecuteL(
   111                     CESMRGlobalNote::EESMRAlarmAlreadyPassed );
   112                     CESMRGlobalNote::EESMRAlarmAlreadyPassed );
   112             }
   113             }
   113             break;
   114             break;
       
   115             
   114         case MESMRFieldValidator::EErrorRescheduleInstance:
   116         case MESMRFieldValidator::EErrorRescheduleInstance:
   115             {
   117             {
   116             CESMRGlobalNote::ExecuteL(
   118             CESMRGlobalNote::ExecuteL(
   117                                 CESMRGlobalNote::EESMRRepeatReSchedule );
   119                                 CESMRGlobalNote::EESMRRepeatReSchedule );
   118             }
   120             }
   119             break;
   121             break;
       
   122             
       
   123         case MESMRFieldValidator::EErrorInstanceOverlapsExistingOne:
       
   124             {
       
   125             CESMRGlobalNote::ExecuteL(
       
   126                                 CESMRGlobalNote::EESMROverlapsExistingInstance );
       
   127             }
       
   128             break;
       
   129             
       
   130         case MESMRFieldValidator::EErrorInstanceAlreadyExistsOnThisDay:
       
   131             {
       
   132             CESMRGlobalNote::ExecuteL(
       
   133                                 CESMRGlobalNote::EESMRInstanceAlreadyExistsOnThisDay );
       
   134             }
       
   135             break;
       
   136             
       
   137         case MESMRFieldValidator::EErrorInstanceOutOfSequence:
       
   138             {
       
   139             CESMRGlobalNote::ExecuteL(
       
   140                                 CESMRGlobalNote::EESMRInstanceOutOfSequence );
       
   141             }
       
   142             break;
       
   143             
   120         default:
   144         default:
   121             err = KErrNone;
   145             err = KErrNone;
   122             break;
   146             break;
   123         }
   147         }
   124 
   148 
   133 // CESMRMixedFieldStorage::CESMRMixedFieldStorage
   157 // CESMRMixedFieldStorage::CESMRMixedFieldStorage
   134 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   135 //
   159 //
   136 CESMRMixedFieldStorage::CESMRMixedFieldStorage(
   160 CESMRMixedFieldStorage::CESMRMixedFieldStorage(
   137         MESMRFieldEventObserver& aEventObserver,
   161         MESMRFieldEventObserver& aEventObserver,
   138         MESMRResponseObserver* aResponseObserver,
   162         MESMRResponseObserver* aResponseObserver ) :
   139         MESMRCalEntry& aEntry ) :
       
   140     CESMRFieldStorage( aEventObserver),
   163     CESMRFieldStorage( aEventObserver),
   141     iResponseObserver(aResponseObserver),
   164     iResponseObserver(aResponseObserver)
   142     iEntry(aEntry)
       
   143     {
   165     {
   144     FUNC_LOG;
   166     FUNC_LOG;
   145     // Do nothing
   167     // Do nothing
   146     }
   168     }
   147 
   169 
   159 // CESMRMixedFieldStorage::NewL
   181 // CESMRMixedFieldStorage::NewL
   160 // ---------------------------------------------------------------------------
   182 // ---------------------------------------------------------------------------
   161 //
   183 //
   162 CESMRMixedFieldStorage* CESMRMixedFieldStorage::NewL(
   184 CESMRMixedFieldStorage* CESMRMixedFieldStorage::NewL(
   163         MESMRFieldEventObserver& aEventObserver,
   185         MESMRFieldEventObserver& aEventObserver,
   164         CESMRPolicy* aPolicy,
   186         const CESMRPolicy& aPolicy,
   165         MESMRResponseObserver* aResponseObserver,
   187         MESMRResponseObserver* aResponseObserver,
   166         MESMRCalEntry& aEntry )
   188         MESMRCalEntry& aEntry )
   167     {
   189     {
   168     FUNC_LOG;
   190     FUNC_LOG;
   169     CESMRMixedFieldStorage* self =
   191     CESMRMixedFieldStorage* self =
   170             new (ELeave) CESMRMixedFieldStorage(
   192             new (ELeave) CESMRMixedFieldStorage(
   171                     aEventObserver,
   193                     aEventObserver,
   172                     aResponseObserver,
   194                     aResponseObserver );
   173                     aEntry );
   195 
   174 
   196     CleanupStack::PushL( self );
   175     CleanupStack::PushL ( self );
   197     self->ConstructL( aPolicy, aEntry );
   176     self->ConstructL ( aPolicy );
   198     CleanupStack::Pop( self );
   177     CleanupStack::Pop ( self );
       
   178 
   199 
   179     return self;
   200     return self;
   180     }
   201     }
   181 
   202 
   182 // ---------------------------------------------------------------------------
   203 // ---------------------------------------------------------------------------
   183 // CESMRMixedFieldStorage::ConstructL
   204 // CESMRMixedFieldStorage::ConstructL
   184 // ---------------------------------------------------------------------------
   205 // ---------------------------------------------------------------------------
   185 //
   206 //
   186 void CESMRMixedFieldStorage::ConstructL( CESMRPolicy* aPolicy )
   207 void CESMRMixedFieldStorage::ConstructL(
       
   208         const CESMRPolicy& aPolicy,
       
   209         MESMRCalEntry& aEntry )
   187     {
   210     {
   188     FUNC_LOG;
   211     FUNC_LOG;
   189     CESMRFieldStorage::BaseConstructL();
   212     CESMRFieldStorage::BaseConstructL();
   190     // FORWARD allows only attendee fields and description to be edited.
   213     
   191     // EDIT RECURRENT EVENT allows only start-end time and start date
   214     DoChangePolicyL( aPolicy, aEntry );
   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     }
   215     }
   237 
   216 
   238 // ---------------------------------------------------------------------------
   217 // ---------------------------------------------------------------------------
   239 // CESMRMixedFieldStorage::ExternalizeL
   218 // CESMRMixedFieldStorage::ExternalizeL
   240 // ---------------------------------------------------------------------------
   219 // ---------------------------------------------------------------------------
   290         }
   269         }
   291     return err;
   270     return err;
   292     }
   271     }
   293 
   272 
   294 // ---------------------------------------------------------------------------
   273 // ---------------------------------------------------------------------------
       
   274 // CESMRMixedFieldStorage::ChangePolicyL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CESMRMixedFieldStorage::ChangePolicyL(
       
   278         const CESMRPolicy& aNewPolicy,
       
   279         MESMRCalEntry& aEntry )
       
   280     {
       
   281     // Delegate to non-virtual
       
   282     DoChangePolicyL( aNewPolicy, aEntry );
       
   283     }
       
   284 
       
   285 
       
   286 // ---------------------------------------------------------------------------
   295 // CESMRMixedFieldStorage::ConstructForwardEventL
   287 // CESMRMixedFieldStorage::ConstructForwardEventL
   296 // ---------------------------------------------------------------------------
   288 // ---------------------------------------------------------------------------
   297 //
   289 //
   298 void CESMRMixedFieldStorage::ConstructForwardEventL(
   290 void CESMRMixedFieldStorage::ConstructForwardEventL(
   299         CESMRPolicy* aPolicy,
   291         const CESMRPolicy& aPolicy,
   300         MESMRFieldValidator* aValidator )
   292         MESMRFieldValidator* aValidator )
   301     {
   293     {
   302     FUNC_LOG;
   294     FUNC_LOG;
   303     iValidator = aValidator;
   295     iValidator = aValidator;
   304     
   296     
   305     RArray< TESMREntryField > array = aPolicy->Fields();
   297     RArray< TESMREntryField > array = aPolicy.Fields();
   306 
   298 
   307     TInt fieldCount( array.Count() );
   299     TInt fieldCount( array.Count() );
   308     for (TInt i(0); i < fieldCount; i++ )
   300     for (TInt i(0); i < fieldCount; i++ )
   309         {
   301         {
   310         CESMRField* field =  NULL;
   302         CESMRField* field =  NULL;
   314             case EESMRFieldAttendee: //Fall through 
   306             case EESMRFieldAttendee: //Fall through 
   315             case EESMRFieldOptAttendee: //Fall through
   307             case EESMRFieldOptAttendee: //Fall through
   316             case EESMRFieldDescription:
   308             case EESMRFieldDescription:
   317                 {
   309                 {
   318                 field = CreateEditorFieldL( iValidator, array[i] );
   310                 field = CreateEditorFieldL( iValidator, array[i] );
   319                 CleanupStack::PushL( field );
       
   320                 }
   311                 }
   321                 break;
   312                 break;
   322             default:
   313             default:
   323                 {
   314                 {
   324                 field =  
   315                 field =  
   325 					CreateViewerFieldL( iResponseObserver, array[i], visible );
   316 					CreateViewerFieldL( iResponseObserver, array[i], visible );
   326                 CleanupStack::PushL( field );
   317                 field->LockL();
   327                 }
   318                 }
   328                 break;
   319                 break;
   329             }
   320             }
   330         
   321         
   331         AddFieldL( field, visible );
   322         if( field->FieldViewMode() != EESMRFieldTypeDisabled )
   332         CleanupStack::Pop( field );
   323             {
       
   324             CleanupStack::PushL( field );
       
   325             AddFieldL( field, visible );
       
   326             CleanupStack::Pop( field );
       
   327             }
       
   328         else
       
   329             {
       
   330             delete field;
       
   331             field = NULL;
       
   332             }
   333         }
   333         }
   334     }
   334     }
   335 
   335 
   336 // ---------------------------------------------------------------------------
   336 // ---------------------------------------------------------------------------
   337 // CESMRMixedFieldStorage::ConstructRecurrentEventL
   337 // CESMRMixedFieldStorage::ConstructRecurrentEventL
   338 // ---------------------------------------------------------------------------
   338 // ---------------------------------------------------------------------------
   339 //
   339 //
   340 void CESMRMixedFieldStorage::ConstructRecurrentEventL(
   340 void CESMRMixedFieldStorage::ConstructRecurrentEventL(
   341         CESMRPolicy* aPolicy,
   341         const CESMRPolicy& aPolicy,
   342         MESMRFieldValidator* aValidator )
   342         MESMRFieldValidator* aValidator )
   343     {
   343     {
   344     FUNC_LOG;
   344     FUNC_LOG;
   345     iValidator = aValidator;
   345     iValidator = aValidator;
   346 
   346     iValidator->SetFieldEventQueue( &EventQueueL() );
   347     const RArray<TESMREntryField>& array = aPolicy->Fields();
   347 
       
   348     const RArray<TESMREntryField>& array = aPolicy.Fields();
   348     TInt fieldCount( array.Count() );
   349     TInt fieldCount( array.Count() );
   349     for (TInt i(0); i < fieldCount; ++i )
   350     for (TInt i(0); i < fieldCount; ++i )
   350         {
   351         {
   351         CESMRField* field = NULL;
   352         CESMRField* field = NULL;
   352         TBool visible = array[i].iFieldViewMode == EESMRFieldTypeDefault;
   353         TBool visible = array[i].iFieldViewMode == EESMRFieldTypeDefault;
   353         switch ( array[i].iFieldId )
   354         switch ( array[i].iFieldId )
   354             {
   355             {
   355             case EESMRFieldRecurrence: //Fall through
   356             case EESMRFieldRecurrence: //Fall through
   356             case EESMRFieldRecurrenceDate:
   357             case EESMRFieldRecurrenceDate:
   357                 {
       
   358                 // When editing occurence --> Recurrence information
       
   359                 // is not shown
       
   360                 break;
       
   361                 }
       
   362             default:
   358             default:
   363                 field =  CreateEditorFieldL( iValidator, array[i] );
   359                 field =  CreateEditorFieldL( iValidator, array[i] );
   364                 break;
   360                 break;
   365             }
   361             }
   366 
   362 
   376 // ---------------------------------------------------------------------------
   372 // ---------------------------------------------------------------------------
   377 // CESMRMixedFieldStorage::ConstructEditSeriesEventL
   373 // CESMRMixedFieldStorage::ConstructEditSeriesEventL
   378 // ---------------------------------------------------------------------------
   374 // ---------------------------------------------------------------------------
   379 //
   375 //
   380 void CESMRMixedFieldStorage::ConstructEditSeriesEventL(
   376 void CESMRMixedFieldStorage::ConstructEditSeriesEventL(
   381         CESMRPolicy* aPolicy,
   377         const CESMRPolicy& aPolicy,
   382         MESMRFieldValidator* aValidator )
   378         MESMRFieldValidator* aValidator )
   383     {
   379     {
   384     FUNC_LOG;
   380     FUNC_LOG;
   385     TESMRRecurrenceValue recurrenceType;
   381     TESMRRecurrenceValue recurrenceType;
   386     TBool validRecurrence(
   382     TBool validRecurrence(
   387             HasValidRecurrenceForEditingL(
   383             HasValidRecurrenceForEditingL(
   388                     iEntry,
   384                     *iEntry,
   389                     recurrenceType ) );
   385                     recurrenceType ) );
   390 
   386 
   391     iValidator = aValidator;
   387     iValidator = aValidator;
   392     const RArray<TESMREntryField>& array = aPolicy->Fields();
   388     iValidator->SetFieldEventQueue( &EventQueueL() );
       
   389     
       
   390     const RArray<TESMREntryField>& array = aPolicy.Fields();
   393     CESMRField* field =  NULL;
   391     CESMRField* field =  NULL;
   394     
   392     
   395     TInt fieldCount(  array.Count() );
   393     TInt fieldCount(  array.Count() );
   396     for (TInt i(0); i < fieldCount; i++ )
   394     for (TInt i(0); i < fieldCount; i++ )
   397         {
   395         {
   403             case EESMRFieldRecurrence:
   401             case EESMRFieldRecurrence:
   404             case EESMRFieldRecurrenceDate:
   402             case EESMRFieldRecurrenceDate:
   405                 {
   403                 {
   406                 if ( validRecurrence )
   404                 if ( validRecurrence )
   407                     {
   405                     {
   408                     field =  CreateEditorFieldL( iValidator, tfield );
   406                     field = CreateEditorFieldL( iValidator, tfield );
   409                     CleanupStack::PushL( field );
       
   410                     }
   407                     }
   411                 else
   408                 else
   412                     {
   409                     {
   413                     // Entry has unrecognized recurrende type
   410                     // Entry has unrecognized recurrende type
   414                     // --> Cannot be edited.
   411                     // --> Cannot be edited.
   415                     field = CreateViewerFieldL( 
   412                     field = CreateViewerFieldL( 
   416 								iResponseObserver, tfield, visible );
   413 								iResponseObserver, tfield, visible );
   417                     CleanupStack::PushL( field );
   414                     field->LockL();
   418                     }
   415                     }
   419                 }
   416                 }
   420                 break;
   417                 break;
   421             default:
   418             default:
   422                 {
   419                 {
   423                 field =  CreateEditorFieldL( iValidator, tfield );
   420                 field = CreateEditorFieldL( iValidator, tfield );
   424                 CleanupStack::PushL( field );
       
   425                 }
   421                 }
   426                 break;
   422                 break;
   427             }
   423             }
   428         
   424 
   429         AddFieldL( field, visible );
   425         if( field->FieldViewMode() != EESMRFieldTypeDisabled )
   430         CleanupStack::Pop( field );
   426             {
       
   427             CleanupStack::PushL( field );
       
   428             AddFieldL( field, visible );
       
   429             CleanupStack::Pop( field );
       
   430             }
       
   431         else
       
   432             {
       
   433             delete field;
       
   434             field = NULL;
       
   435             }
       
   436         }
       
   437     }
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // CESMRMixedFieldStorage::ConstructEditSeriesEventL
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 void CESMRMixedFieldStorage::Reset()
       
   444     {
       
   445     CESMRFieldStorage::Reset();
       
   446     delete iValidator;
       
   447     iValidator = NULL;
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // CESMRMixedFieldStorage::DoChangePolicyL
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 void CESMRMixedFieldStorage::DoChangePolicyL(
       
   455         const CESMRPolicy& aNewPolicy,
       
   456         MESMRCalEntry& aEntry )
       
   457     {
       
   458     Reset();
       
   459     iEntry = &aEntry;
       
   460     
       
   461     // FORWARD allows only attendee fields and description to be edited.
       
   462     // EDIT RECURRENT EVENT allows only start-end time and start date
       
   463     // to be edited.
       
   464 
       
   465     MESMRCalEntry::TESMRRecurrenceModifyingRule rule(
       
   466             iEntry->RecurrenceModRule() );
       
   467 
       
   468     if ( iEntry->IsRecurrentEventL() &&
       
   469          rule == MESMRCalEntry::EESMRAllInSeries  &&
       
   470          EESMREditMR == aNewPolicy.ViewMode())
       
   471         {
       
   472         // Contruct edit series
       
   473         // validator ownership is transferred
       
   474         MESMRFieldValidator* validator =
       
   475         CESMRValidatorFactory::CreateValidatorL (
       
   476                 aNewPolicy.EventType() );
       
   477 
       
   478         ConstructEditSeriesEventL(
       
   479                 aNewPolicy,
       
   480                 validator );
       
   481 
       
   482         iEventType = EMixedFieldStorageEditSeriesEvent;
       
   483         }
       
   484 
       
   485     else if ( aNewPolicy.ViewMode() != EESMRForwardMR )
       
   486         {
       
   487         MESMRFieldValidator* validator =
       
   488                 CESMRValidatorFactory::CreateValidatorL (
       
   489                         aNewPolicy.EventType() );
       
   490 
       
   491         ConstructRecurrentEventL ( aNewPolicy,
       
   492                 validator );
       
   493 
       
   494         iEventType = EMixedFieldStorageRecurrentEvent;
       
   495         }
       
   496     else
       
   497         {
       
   498         // No validator is needed because forwarding does not
       
   499         // affecto to any time fields.
       
   500         MESMRFieldValidator* validator = NULL;
       
   501         ConstructForwardEventL (
       
   502                 aNewPolicy,
       
   503                 validator );
       
   504 
       
   505         iEventType = EMixedFieldStorageForward;
   431         }
   506         }
   432     }
   507     }
   433 
   508 
   434 // EOF
   509 // EOF
   435 
   510