meetingrequest/mrprocessor/mrprocessorplugin/src/cesmrentryprocessor.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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 entry processor implementation
       
    15 *  Version     : %version: e002sa33#14 %
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "cesmrentryprocessor.h"
       
    23 #include "esmrinternaluid.h"
       
    24 #include "mesmrcalentry.h"
       
    25 #include "esmrhelper.h"
       
    26 #include "esmrentryhelper.h"
       
    27 #include "cesmrfsmailboxutils.h"
       
    28 #include "cesmrmeetingrequestentry.h"
       
    29 #include "cesmrconflictchecker.h"
       
    30 #include "FreestyleEmailUiConstants.h"
       
    31 #include "cesmrrecurrenceinfohandler.h"
       
    32 #include "emailtrace.h"
       
    33 
       
    34 #include <e32std.h>
       
    35 #include <calentry.h>
       
    36 #include <calinstance.h>
       
    37 #include <calrrule.h>
       
    38 #include <caluser.h>
       
    39 #include <caltime.h>
       
    40 #include <caleninterimutils2.h>
       
    41 #include <cmrmailboxutils.h>
       
    42 #include <magnentryui.h>
       
    43 #include <ct/rcpointerarray.h>
       
    44 
       
    45 /// Unnamed namespace for local definitions
       
    46 namespace {
       
    47 
       
    48 #ifdef _DEBUG
       
    49 
       
    50 // Definition for module panic text
       
    51 _LIT( KESMRProcessorPanicTxt, "ESMREntryProcessor" );
       
    52 
       
    53 /**
       
    54  * ESMREntryProcessor panic codes
       
    55  */
       
    56 enum TESMREntryProcessorPanic
       
    57     {
       
    58     // Input entry array is empty
       
    59     EESMRProcessorEmptyEntryArray = 1,
       
    60     // Too many input entries
       
    61     EESMRProcessorTooManyEntries = 2,
       
    62     // entries are not processed
       
    63     EESMRProcessorEntriesNotProcessed,
       
    64     // View mode for policy resolving
       
    65     // cannot be check.
       
    66     EESMRProcessorCannotCheckViewMode,
       
    67     // Invalid processor mode
       
    68     EESMRProcessorInvalidMode
       
    69     };
       
    70 
       
    71 /**
       
    72  * Raises panic.
       
    73  * @param aPanic Panic code
       
    74  */
       
    75 void Panic(TESMREntryProcessorPanic aPanic)
       
    76     {
       
    77     User::Panic( KESMRProcessorPanicTxt(), aPanic);
       
    78     }
       
    79 
       
    80 #endif // _DEBUG
       
    81 
       
    82 }  // namespace
       
    83 
       
    84 // ======== MEMBER FUNCTIONS ========
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CESMREntryProcessor::CESMREntryProcessor
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CESMREntryProcessor::CESMREntryProcessor(
       
    91         MESMRCalDbMgr& aDbMgr )
       
    92 :   iDbMgr( aDbMgr )
       
    93     {
       
    94     FUNC_LOG;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CESMREntryProcessor::~CESMREntryProcessor
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CESMREntryProcessor::~CESMREntryProcessor()
       
   102     {
       
   103     FUNC_LOG;
       
   104     delete iMRMailboxUtils;
       
   105     delete iESMREntry;
       
   106     delete iMbUtils;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CESMREntryProcessor::ConstructL
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CESMREntryProcessor::ConstructL()
       
   114     {
       
   115     FUNC_LOG;
       
   116     iMRMailboxUtils = CMRMailboxUtils::NewL();
       
   117     iMbUtils = CESMRFsMailboxUtils::NewL( *iMRMailboxUtils );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CESMREntryProcessor::NewL
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CESMREntryProcessor* CESMREntryProcessor::NewL(
       
   125         TAny* aDbMgr )
       
   126     {
       
   127     FUNC_LOG;
       
   128 
       
   129     MESMRCalDbMgr* dbMgr = static_cast<MESMRCalDbMgr*>(aDbMgr);
       
   130     return CreateL( *dbMgr );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CESMREntryProcessor::CreateL
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CESMREntryProcessor* CESMREntryProcessor::CreateL(
       
   138             MESMRCalDbMgr& aDbMgr )
       
   139     {
       
   140     FUNC_LOG;
       
   141 
       
   142     CESMREntryProcessor* self = new (ELeave) CESMREntryProcessor( aDbMgr );
       
   143     CleanupStack::PushL( self );
       
   144     self->ConstructL();
       
   145     CleanupStack::Pop( self );
       
   146 
       
   147     return self;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CESMREntryProcessor::ScenarioData
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 const TESMRScenarioData& CESMREntryProcessor::ScenarioData() const
       
   155     {
       
   156     FUNC_LOG;
       
   157     return iScenData;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CESMREntryProcessor::ContainsProcessedEntry
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 TBool CESMREntryProcessor::ContainsProcessedEntry() const
       
   165     {
       
   166     FUNC_LOG;
       
   167     return (iESMREntry != NULL);
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CESMREntryProcessor::ProcessL
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CESMREntryProcessor::ProcessL(
       
   175         const MAgnEntryUi::TAgnEntryUiInParams* aParams,
       
   176         RPointerArray<CCalEntry>* aEntries )
       
   177     {
       
   178     FUNC_LOG;
       
   179 
       
   180     iParams = aParams;
       
   181     ProcessL( aEntries );
       
   182     CheckViewModeL();
       
   183 
       
   184     if ( !IsDataOk() )
       
   185         {
       
   186         // Data is not ok --> Leave
       
   187         User::Leave( KErrArgument );
       
   188         }
       
   189 
       
   190     // Check mail parameters
       
   191     if ( iParams && iParams->iSpare )
       
   192         {
       
   193         CCalEntry* entry = &iESMREntry->Entry();
       
   194         if(entry)
       
   195             {
       
   196             TBool recurrent(EFalse);
       
   197             recurrent = iESMREntry->IsRecurrentEventL();
       
   198 
       
   199             if(recurrent)
       
   200                 {
       
   201                 if ( !ESMREntryHelper::IsModifyingEntryL(*entry) )
       
   202                     {
       
   203                     iESMREntry->SetModifyingRuleL( MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   204 
       
   205                     SetPhoneOwnerToOwnEntryL();
       
   206                     }
       
   207                 }
       
   208             }
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CESMREntryProcessor::ProcessL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CESMREntryProcessor::ProcessL(
       
   217             const MAgnEntryUi::TAgnEntryUiInParams* aParams,
       
   218             CCalEntry& aEntry,
       
   219             TBool aSetDefaultValuesToEntry,
       
   220             const TBool aTypeChanging)
       
   221     {
       
   222     FUNC_LOG
       
   223 
       
   224     iParams = aParams;
       
   225     iMREntries = NULL;
       
   226     iCalEntry = &aEntry;
       
   227 
       
   228     // Set initial values to scenario data
       
   229     iScenData.iRole       = EESMRRoleUndef;
       
   230     iScenData.iViewMode   = EESMRViewUndef;
       
   231     iScenData.iCallingApp = EESMRAppUndef;
       
   232 
       
   233     SetPhoneOwnerL( aEntry, aEntry );
       
   234 
       
   235     CreateESMREntryL( aEntry, aSetDefaultValuesToEntry );
       
   236     CheckOrganizerL( aEntry );
       
   237 
       
   238     // When creating a new repeating meeting and adding participants,
       
   239     // meeting request editor is opened and all occurences should be edited
       
   240     if ( ( iESMREntry->IsRecurrentEventL() &&
       
   241             MAgnEntryUi::ECreateNewEntry == iParams->iEditorMode ) ||
       
   242          ( ESMREntryHelper::IsRepeatingMeetingL( aEntry ) && aTypeChanging ) )  
       
   243         {
       
   244         iESMREntry->SetModifyingRuleL(
       
   245                     MESMRMeetingRequestEntry::EESMRAllInSeries, aTypeChanging );
       
   246         }
       
   247     else //Default case
       
   248         {
       
   249         iESMREntry->SetModifyingRuleL(
       
   250                     MESMRMeetingRequestEntry::EESMRThisOnly, aTypeChanging );
       
   251         }
       
   252 
       
   253     if ( iParams && MAgnEntryUi::ECreateNewEntry ==
       
   254             iParams->iEditorMode &&
       
   255                 aSetDefaultValuesToEntry )
       
   256         {
       
   257         iESMREntry->SetDefaultValuesToEntryL();
       
   258         }
       
   259 
       
   260 
       
   261     CheckViewModeL();
       
   262 
       
   263     if ( !IsDataOk() )
       
   264         {
       
   265         // Data is not ok --> Leave
       
   266         User::Leave( KErrArgument );
       
   267         }
       
   268 
       
   269     // Check mail parameters
       
   270     if ( iParams && iParams->iSpare )
       
   271         {
       
   272         CCalEntry* entry = &iESMREntry->Entry();
       
   273         if(entry)
       
   274             {
       
   275             TBool recurrent(EFalse);
       
   276             recurrent = iESMREntry->IsRecurrentEventL();
       
   277 
       
   278             if(recurrent)
       
   279                 {
       
   280                 if ( !ESMREntryHelper::IsModifyingEntryL(*entry) )
       
   281                     {
       
   282                     iESMREntry->SetModifyingRuleL( MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   283 
       
   284                     SetPhoneOwnerToOwnEntryL();
       
   285                     }
       
   286                 }
       
   287             }
       
   288         }
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // CESMREntryProcessor::ProcessL
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CESMREntryProcessor::ProcessL(
       
   296             RPointerArray<CCalEntry>* aEntries )
       
   297     {
       
   298     FUNC_LOG;
       
   299 
       
   300     __ASSERT_DEBUG( aEntries->Count() > 0,
       
   301                     Panic( EESMRProcessorEmptyEntryArray ) );
       
   302 
       
   303     iMREntries = aEntries;
       
   304     iCalEntry = (*iMREntries)[ 0 ];
       
   305 
       
   306     // Set initial values to scenario data
       
   307     iScenData.iRole       = EESMRRoleUndef;
       
   308     iScenData.iViewMode   = EESMRViewUndef;
       
   309     iScenData.iCallingApp = EESMRAppUndef;
       
   310 
       
   311     for ( TInt i = 0; i < iMREntries->Count(); ++i )
       
   312         {
       
   313         SetPhoneOwnerL( *(*iMREntries)[ i ], *iCalEntry );
       
   314         }
       
   315 
       
   316     CreateESMREntryL( *iCalEntry, ETrue );
       
   317     CheckOrganizerL( *iCalEntry );
       
   318 
       
   319     // When creating a new repeating meeting and adding participants,
       
   320     // meeting request editor is opened and all occurences should be edited
       
   321     if ( iESMREntry->IsRecurrentEventL()
       
   322          && iParams
       
   323          && MAgnEntryUi::ECreateNewEntry == iParams->iEditorMode )
       
   324     	{
       
   325     	iESMREntry->SetModifyingRuleL(
       
   326     			    MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   327     	}
       
   328     else //Default case
       
   329     	{
       
   330     	iESMREntry->SetModifyingRuleL(
       
   331     	            MESMRMeetingRequestEntry::EESMRThisOnly );
       
   332     	}
       
   333 
       
   334     if ( iParams && MAgnEntryUi::ECreateNewEntry == iParams->iEditorMode )
       
   335         {
       
   336         iESMREntry->SetDefaultValuesToEntryL();
       
   337         }
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CESMREntryProcessor::ProcessL
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CESMREntryProcessor::ProcessL(
       
   345             CCalInstance& aInstance )
       
   346     {
       
   347     FUNC_LOG;
       
   348 
       
   349     RCPointerArray<CCalEntry> entries;
       
   350     CleanupClosePushL( entries );
       
   351 
       
   352     // Fetches parent entry. We need to construct entry with
       
   353     // correct time.
       
   354     CCalEntry &entry = aInstance.Entry();
       
   355     CCalEntry* instanceEntry = ESMRHelper::CopyEntryL(
       
   356             entry,
       
   357             entry.MethodL(),
       
   358             ESMRHelper::ECopyFull );
       
   359 
       
   360     entries.Append(instanceEntry);
       
   361 
       
   362     // Setting start and end time for child entry
       
   363     ESMREntryHelper::CheckRepeatUntilValidityL(
       
   364             *instanceEntry,
       
   365             aInstance.StartTimeL() );
       
   366 
       
   367     ESMREntryHelper::SetInstanceStartAndEndL(
       
   368             *instanceEntry,
       
   369             entry,
       
   370             aInstance.StartTimeL() );
       
   371 
       
   372     // Filling child with correct data
       
   373     // This can be replaced withCCalenInterimUtils2::PopulateChildFromParentL
       
   374     // after its memory leak has been fixed.
       
   375     ESMRHelper::PopulateChildFromParentL(
       
   376             *instanceEntry,
       
   377             entry );
       
   378 
       
   379     ProcessL( &entries );
       
   380 
       
   381     if ( !iESMREntry )
       
   382         {
       
   383         User::Leave( KErrArgument );
       
   384         }
       
   385 
       
   386     // Mark only this entry to be affected.
       
   387     iESMREntry->SetModifyingRuleL(
       
   388             MESMRMeetingRequestEntry::EESMRThisOnly );
       
   389 
       
   390     // entries
       
   391     CleanupStack::PopAndDestroy();
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CESMREntryProcessor::SwitchProcessorToModeL
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CESMREntryProcessor::SwitchProcessorToModeL(
       
   399         TMRProcessorMode aMode )
       
   400     {
       
   401     FUNC_LOG;
       
   402 
       
   403     switch ( aMode )
       
   404         {
       
   405         case EMRProcessorModeView:
       
   406             SwitchToViewL();
       
   407             break;
       
   408         case EMRProcessorModeEdit:
       
   409             SwitchToEditL();
       
   410             break;
       
   411         case EMRProcessorModeForward:
       
   412             SwitchToForwardL();
       
   413             break;
       
   414         case EMRProcessorModeTrack:
       
   415             SwitchToTrackL();
       
   416             break;
       
   417         default:
       
   418             __ASSERT_DEBUG( EFalse, Panic( EESMRProcessorInvalidMode) );
       
   419         }
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CESMREntryProcessor::ESMREntryL
       
   424 // ---------------------------------------------------------------------------
       
   425 //
       
   426 MESMRCalEntry& CESMREntryProcessor::ESMREntryL()
       
   427     {
       
   428     FUNC_LOG;
       
   429 
       
   430     CreateESMREntryL( *iCalEntry, ETrue );
       
   431     return *iESMREntry;
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // CESMREntryProcessor::ResetL
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 void CESMREntryProcessor::ResetL()
       
   439     {
       
   440     FUNC_LOG;
       
   441 
       
   442     iScenData.iRole       = EESMRRoleUndef;
       
   443     iScenData.iViewMode   = EESMRViewUndef;
       
   444     iScenData.iCallingApp = EESMRAppUndef;
       
   445 
       
   446     delete iESMREntry;
       
   447     iESMREntry = NULL;
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------------------------
       
   451 // CESMREntryProcessor::ProcessOutputParametersL
       
   452 // ---------------------------------------------------------------------------
       
   453 //
       
   454 void CESMREntryProcessor::ProcessOutputParametersL(
       
   455         MAgnEntryUi::TAgnEntryUiOutParams& aOutParams,
       
   456         TESMRCommand aCommand )
       
   457     {
       
   458     FUNC_LOG;
       
   459 
       
   460     __ASSERT_DEBUG( iESMREntry, Panic(EESMRProcessorEntriesNotProcessed) );
       
   461 
       
   462     if ( !iParams  ||
       
   463          EESMRForwardMR == iScenData.iViewMode  ||
       
   464          EESMRViewUndef == iScenData.iViewMode )
       
   465         {
       
   466         // No input parameters supplied --> Output parameters cannot be set
       
   467         return;
       
   468         }
       
   469 
       
   470     TBool handlingInstanceOnly(
       
   471             iESMREntry->IsRecurrentEventL() &&
       
   472             MESMRCalEntry::EESMRThisOnly == iESMREntry->RecurrenceModRule() );
       
   473 
       
   474     switch ( aCommand )
       
   475         {
       
   476         case EESMRCmdSendMR:
       
   477         case EESMRCmdSendMRUpdate:
       
   478         case EESMRCmdSaveMR:
       
   479         case EESMRCmdAcceptMR:
       
   480         case EESMRCmdTentativeMR:
       
   481             {
       
   482             aOutParams.iAction = MAgnEntryUi::EMeetingSaved;
       
   483             if ( handlingInstanceOnly )
       
   484                 {
       
   485                 aOutParams.iAction = MAgnEntryUi::EInstanceRescheduled;
       
   486                 }
       
   487             }
       
   488             break;
       
   489 
       
   490         case EESMRCmdDeclineMR:
       
   491         case EESMRCmdDeleteMR:
       
   492             {
       
   493             aOutParams.iAction = MAgnEntryUi::EMeetingDeleted;
       
   494             if ( handlingInstanceOnly )
       
   495                 {
       
   496                 aOutParams.iAction = MAgnEntryUi::EInstanceDeleted;
       
   497                 }
       
   498             }
       
   499             break;
       
   500 
       
   501         default:
       
   502             {
       
   503             aOutParams.iAction = MAgnEntryUi::ENoAction;
       
   504             }
       
   505             break;
       
   506         }
       
   507 
       
   508     if ( handlingInstanceOnly )
       
   509         {
       
   510         aOutParams.iNewInstanceDate =
       
   511                 iESMREntry->Entry().StartTimeL();
       
   512         }
       
   513     else if ( MAgnEntryUi::ENoAction != aOutParams.iAction )
       
   514         {
       
   515         //Copy entry LocalUid to input entry
       
   516         iCalEntry->SetLocalUidL( iESMREntry->Entry().LocalUidL() );
       
   517 
       
   518         TCalTime instanceTime = iESMREntry->Entry().StartTimeL();
       
   519 
       
   520         if ( MESMRCalEntry::EESMRAllInSeries == iESMREntry->RecurrenceModRule() )
       
   521             {
       
   522             // For recurrent event there might be exceptions
       
   523             // and therefore the first possible start time
       
   524             // is set to putput params
       
   525             TCalTime end;
       
   526             CESMRRecurrenceInfoHandler* recurrenceHandler =
       
   527                     CESMRRecurrenceInfoHandler::NewLC( iESMREntry->Entry() );
       
   528 
       
   529             recurrenceHandler->GetFirstInstanceTimeL(
       
   530                     instanceTime,
       
   531                     end );
       
   532 
       
   533             CleanupStack::PopAndDestroy( recurrenceHandler );
       
   534             recurrenceHandler = NULL;
       
   535             aOutParams.iNewInstanceDate = instanceTime;
       
   536             }
       
   537         else
       
   538             {
       
   539             aOutParams.iNewInstanceDate.SetTimeLocalL(
       
   540                     iESMREntry->Entry().StartTimeL().TimeLocalL() );
       
   541             }
       
   542         }
       
   543     else
       
   544         {
       
   545         aOutParams.iNewInstanceDate.SetTimeLocalL( Time::NullTTime() );
       
   546         }
       
   547     }
       
   548 
       
   549 // ---------------------------------------------------------------------------
       
   550 // CESMREntryProcessor::SetPhoneOwnerL
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 void CESMREntryProcessor::SetPhoneOwnerL( CCalEntry& aEntry,
       
   554                                           CCalEntry& aBaseEntry )
       
   555     {
       
   556     FUNC_LOG;
       
   557 
       
   558     TESMRInputParams* inputParams = NULL;
       
   559     if ( iParams )
       
   560         {
       
   561         inputParams = (TESMRInputParams*)(iParams->iSpare);
       
   562         }
       
   563 
       
   564     TInt err(KErrNone);
       
   565     if ( inputParams &&
       
   566          inputParams->iMailClient &&
       
   567          inputParams->iMailMessage )
       
   568         {
       
   569         err = iMbUtils->SetPhoneOwnerL(
       
   570                     aEntry,
       
   571                     *(inputParams->iMailClient),
       
   572                     *(inputParams->iMailMessage) );
       
   573         }
       
   574     else if ( iParams )
       
   575         {
       
   576         err = iMbUtils->SetPhoneOwnerL(
       
   577                     aEntry,
       
   578                     iParams->iMailBoxId );
       
   579         }
       
   580     else
       
   581         {
       
   582         err = iMbUtils->SetPhoneOwnerL( aEntry );
       
   583         }
       
   584 
       
   585     if ( KErrNone != err )
       
   586         {
       
   587         User::Leave( KErrArgument );
       
   588         }
       
   589 
       
   590     // set iOwnerRole, use entry at index zero:
       
   591     if ( iMRMailboxUtils->IsOrganizerL( aBaseEntry ) )
       
   592         {
       
   593         iScenData.iRole = EESMRRoleOrganizer;
       
   594         }
       
   595     else
       
   596         {
       
   597         // We are not organizer. Let's see if we are in attendee list
       
   598         // or not.
       
   599         CCalAttendee* thisAttendee =
       
   600             iMRMailboxUtils->ThisAttendeeL( aBaseEntry );
       
   601         if ( thisAttendee )
       
   602             {
       
   603             switch ( thisAttendee->RoleL() )
       
   604                 {
       
   605                 case CCalAttendee::EOptParticipant:
       
   606                     {
       
   607                     iScenData.iRole = EESMRRoleOptionalAttendee;
       
   608                     break;
       
   609                     }
       
   610                 case CCalAttendee::ENonParticipant:
       
   611                     {
       
   612                     iScenData.iRole = EESMRRoleNonParticipant;
       
   613                     break;
       
   614                     }
       
   615                 case CCalAttendee::EReqParticipant: // fall through
       
   616                 case CCalAttendee::EChair: // fall through
       
   617                 default:
       
   618                     { // Note: chair MUST NOT be interpreted as organizer
       
   619                       // Req.participant is not correct either but has less
       
   620                       // side effects.
       
   621                     iScenData.iRole = EESMRRoleRequiredAttendee;
       
   622                     break;
       
   623                     }
       
   624                 }
       
   625             }
       
   626         else
       
   627             {
       
   628             // Phone owner cannot be set --> Leave
       
   629             User::Leave( KErrCorrupt );
       
   630             }
       
   631         }
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------------------------
       
   635 // CESMREntryProcessor::CheckViewModeL
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 void CESMREntryProcessor::CheckViewModeL()
       
   639     {
       
   640     FUNC_LOG;
       
   641 
       
   642     // View mode cannot be checked
       
   643     __ASSERT_DEBUG(
       
   644             iESMREntry,
       
   645             Panic(EESMRProcessorCannotCheckViewMode) );
       
   646 
       
   647     TInt32 callingAppUid = 0;
       
   648     if( iParams )
       
   649     	{
       
   650 		callingAppUid = iParams->iCallingApp.iUid;
       
   651     	}
       
   652     
       
   653     switch ( callingAppUid )
       
   654         {
       
   655         case KUidCalendarApplication:
       
   656             {
       
   657             iScenData.iCallingApp = EESMRAppCalendar;
       
   658             iScenData.iViewMode = EESMRViewMR;
       
   659             if ( iParams && ( MAgnEntryUi::EViewEntry == iParams->iEditorMode ))
       
   660                 {
       
   661                 if ( iESMREntry->IsAllDayEventL() )
       
   662                     {
       
   663                     iScenData.iViewMode = EESMRViewAllDayMR;
       
   664                     }
       
   665                 }
       
   666             else
       
   667                 {
       
   668                 iScenData.iViewMode = EESMREditMR;
       
   669                 }
       
   670             break;
       
   671             }
       
   672         case KUidMceMailApplication:
       
   673         case KUidEsMailApplication:
       
   674         case KUidBVAApplication:
       
   675             {
       
   676             iScenData.iCallingApp = EESMRAppESEmail;
       
   677             iScenData.iViewMode = EESMRViewMR;
       
   678 
       
   679             if ( iESMREntry->IsAllDayEventL() )
       
   680                 {
       
   681                 iScenData.iViewMode = EESMRViewAllDayMR;
       
   682                 }
       
   683             break;
       
   684             }
       
   685         default:
       
   686             {
       
   687             //error situation, should never come here
       
   688             // Setting data to undef --> will leave later on.
       
   689             iScenData.iViewMode =  EESMRViewUndef;
       
   690             break;
       
   691             }
       
   692         }
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // CESMREntryProcessor::SetPhoneOwnerL
       
   697 // ---------------------------------------------------------------------------
       
   698 //
       
   699 TBool CESMREntryProcessor::IsDataOk() const
       
   700     {
       
   701     FUNC_LOG;
       
   702 
       
   703     TBool retVal(ETrue);
       
   704 
       
   705     // Check that all values has been set and there is no
       
   706     // undefined values. Policies cannot be resolved, if
       
   707     // scenario data is undefined.
       
   708     if ( EESMRRoleUndef == iScenData.iRole ||
       
   709          EESMRViewUndef == iScenData.iViewMode ||
       
   710          EESMRAppUndef == iScenData.iCallingApp )
       
   711         {
       
   712         retVal = EFalse;
       
   713         }
       
   714 
       
   715     return retVal;
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // CESMREntryProcessor::CreateESMREntryL
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 void CESMREntryProcessor::CreateESMREntryL( CCalEntry& aEntry,
       
   723                                             TBool aSetDefaultValuesToEntry )
       
   724     {
       
   725     FUNC_LOG;
       
   726 
       
   727     if ( !iESMREntry )
       
   728         {
       
   729         // ES MR Entry is created
       
   730         //CCalEntry& base = *((*iMREntries)[KFirstEntryIndex]);
       
   731         HBufC* description = NULL;
       
   732         TRAPD( err, description = aEntry.DescriptionL().AllocL() );
       
   733         CleanupStack::PushL( description );
       
   734         if ( KErrNone != err )
       
   735             {
       
   736             User::Leave( KErrCorrupt );
       
   737             }
       
   738         CleanupStack::PopAndDestroy( description );
       
   739         description = NULL;
       
   740 
       
   741         CCalEntry* entry =
       
   742                 ESMRHelper::CopyEntryLC(
       
   743                         aEntry,
       
   744                         aEntry.MethodL(),
       
   745                         ESMRHelper::ECopyFull );
       
   746 
       
   747         CESMRConflictChecker* conflictChecker =
       
   748                 CESMRConflictChecker::NewL(iDbMgr);
       
   749         CleanupStack::PushL( conflictChecker );
       
   750 
       
   751         RCPointerArray<CCalEntry> conflicts;
       
   752         CleanupClosePushL( conflicts );
       
   753 
       
   754         conflictChecker->FindConflictsL( *entry, conflicts );
       
   755         TBool conflictsExists( conflicts.Count() );
       
   756 
       
   757         if ( iParams &&
       
   758              KUidCalendarApplication == iParams->iCallingApp.iUid
       
   759              && aSetDefaultValuesToEntry )
       
   760             {
       
   761             // Setting start and end time for child entry
       
   762             ESMREntryHelper::CheckRepeatUntilValidityL(
       
   763                     *entry,
       
   764                     iParams->iInstanceDate );
       
   765 
       
   766             ESMREntryHelper::SetInstanceStartAndEndL(
       
   767                 *entry,
       
   768                 aEntry,
       
   769                 iParams->iInstanceDate );
       
   770             }
       
   771 
       
   772         TESMRInputParams* inputParams = NULL;
       
   773         if ( iParams )
       
   774             {
       
   775             inputParams = (TESMRInputParams*)(iParams->iSpare);
       
   776             }
       
   777 
       
   778         iESMREntry =
       
   779             CESMRMeetingRequestEntry::NewL(
       
   780                 *entry,
       
   781                 *iMRMailboxUtils,
       
   782                 iDbMgr,
       
   783                 conflictsExists,
       
   784                 inputParams );
       
   785 
       
   786         // conflicts
       
   787         CleanupStack::PopAndDestroy();
       
   788         CleanupStack::PopAndDestroy( conflictChecker );
       
   789         CleanupStack::PopAndDestroy( entry );
       
   790 
       
   791         SetPhoneOwnerToOwnEntryL();
       
   792         }
       
   793 
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------------------------
       
   797 // CESMREntryProcessor::CheckOrganizerL
       
   798 // ---------------------------------------------------------------------------
       
   799 //
       
   800 void CESMREntryProcessor::CheckOrganizerL( CCalEntry& aEntry )
       
   801     {
       
   802     FUNC_LOG;
       
   803 
       
   804     if ( EESMRRoleOrganizer == iScenData.iRole )
       
   805         {
       
   806         CCalUser *phoneOwner = aEntry.PhoneOwnerL();
       
   807 
       
   808         if ( !phoneOwner )
       
   809             {
       
   810             User::Leave( KErrCorrupt );
       
   811             }
       
   812 
       
   813         CCalUser* organizer = ESMRHelper::CopyUserLC( *phoneOwner );
       
   814 
       
   815         // Ownership is transferred
       
   816         aEntry.SetOrganizerL( organizer );
       
   817         CleanupStack::Pop( organizer );
       
   818         }
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // CESMREntryProcessor::SetPhoneOwnerToOwnEntryL
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 void CESMREntryProcessor::SetPhoneOwnerToOwnEntryL()
       
   826     {
       
   827     FUNC_LOG;
       
   828 
       
   829     // Phone owner cannot be checked
       
   830     __ASSERT_DEBUG(
       
   831             iESMREntry,
       
   832             Panic(EESMRProcessorEntriesNotProcessed) );
       
   833 
       
   834     TESMRInputParams* inputParams = NULL;
       
   835     if ( iParams )
       
   836         {
       
   837         inputParams = (TESMRInputParams*)(iParams->iSpare);
       
   838         }
       
   839 
       
   840     TInt err(KErrNone);
       
   841     if ( inputParams &&
       
   842          inputParams->iMailClient &&
       
   843          inputParams->iMailMessage )
       
   844         {
       
   845         err = iMbUtils->SetPhoneOwnerL(
       
   846                     iESMREntry->Entry(),
       
   847                     *(inputParams->iMailClient),
       
   848                     *(inputParams->iMailMessage) );
       
   849         }
       
   850     else if ( iParams )
       
   851         {
       
   852         err = iMbUtils->SetPhoneOwnerL(
       
   853                 iESMREntry->Entry(),
       
   854                     iParams->iMailBoxId );
       
   855         }
       
   856     else
       
   857         {
       
   858         err = iMbUtils->SetPhoneOwnerL( iESMREntry->Entry() );
       
   859         }
       
   860 
       
   861     User::LeaveIfError( err );
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // CESMREntryProcessor::SwitchToForwardL
       
   866 // ---------------------------------------------------------------------------
       
   867 //
       
   868 void CESMREntryProcessor::SwitchToForwardL()
       
   869     {
       
   870     FUNC_LOG;
       
   871 
       
   872     if ( !iESMREntry )
       
   873         {
       
   874         // No entries has been processed yet.
       
   875         User::Leave( KErrNotReady );
       
   876         }
       
   877 
       
   878     iESMREntry->SwitchToForwardL();
       
   879 
       
   880     // Rest of the scenario data remains as it is
       
   881     iScenData.iViewMode   = EESMRForwardMR;
       
   882     }
       
   883 
       
   884 // ---------------------------------------------------------------------------
       
   885 // CESMREntryProcessor::SwitchToViewL
       
   886 // ---------------------------------------------------------------------------
       
   887 //
       
   888 void CESMREntryProcessor::SwitchToEditL()
       
   889     {
       
   890     FUNC_LOG;
       
   891 
       
   892     if ( !iESMREntry )
       
   893         {
       
   894         // No entries has been processed yet.
       
   895         User::Leave( KErrNotReady );
       
   896         }
       
   897 
       
   898     iESMREntry->SwitchToOrginalL();
       
   899 
       
   900     // Rest of the scenario data remains as it is
       
   901     iScenData.iViewMode   = EESMREditMR;
       
   902 
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------------------------
       
   906 // CESMREntryProcessor::SwitchToViewL
       
   907 // ---------------------------------------------------------------------------
       
   908 //
       
   909 void CESMREntryProcessor::SwitchToViewL()
       
   910     {
       
   911     FUNC_LOG;
       
   912 
       
   913     if ( !iESMREntry )
       
   914         {
       
   915         // No entries has been processed yet.
       
   916         User::Leave( KErrNotReady );
       
   917         }
       
   918 
       
   919     iESMREntry->SwitchToOrginalL();
       
   920 
       
   921     // Rest of the scenario data remains as it is
       
   922     iScenData.iViewMode   = EESMRViewMR;
       
   923 
       
   924     }
       
   925 
       
   926 // ---------------------------------------------------------------------------
       
   927 // CESMREntryProcessor::SwitchToTrackL
       
   928 // ---------------------------------------------------------------------------
       
   929 //
       
   930 void CESMREntryProcessor::SwitchToTrackL()
       
   931     {
       
   932     FUNC_LOG;
       
   933 
       
   934     if ( !iESMREntry )
       
   935         {
       
   936         // No entries has been processed yet.
       
   937         User::Leave( KErrNotReady );
       
   938         }
       
   939 
       
   940     iESMREntry->SwitchToOrginalL();
       
   941 
       
   942     // Rest of the scenario data remains as it is
       
   943     iScenData.iViewMode   = EESMRTrackingViewMR;
       
   944     iScenData.iRole       = EESMRRoleOrganizer;
       
   945     iScenData.iEntryType  = EESMREventTypeAppt;
       
   946 
       
   947     }
       
   948 
       
   949 // EOF
       
   950