meetingrequest/mrviewer/src/cesmrviewerctrl.cpp
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     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 esmviewer controller implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 //<cmail>
       
    20 #include "emailtrace.h"
       
    21 #include "cesmrpolicy.h"
       
    22 #include "esmrdef.h"
       
    23 #include "cesmrpolicymanager.h"
       
    24 //</cmail>
       
    25 
       
    26 #include "cesmrviewerctrl.h"
       
    27 #include "cmrentryprocessor.h"
       
    28 #include "mesmrmeetingrequestentry.h"
       
    29 #include "mesmrtaskextension.h"
       
    30 #include "esmrentryhelper.h"
       
    31 #include "esmrhelper.h"
       
    32 #include "cesmruifactory.h"
       
    33 
       
    34 #include "mesmruibase.h"
       
    35 #include "tesmrinputparams.h"
       
    36 #include "tmroutputparams.h"
       
    37 #include "esmrconfig.hrh"
       
    38 #include "cesmrconfirmationquery.h"
       
    39 #include "cesmrutils.h"
       
    40 #include "cesmrcaluserutil.h"
       
    41 #include "cesmrlistquery.h"
       
    42 #include "cesmrcaldbmgr.h"
       
    43 
       
    44 #include "cesmrtaskfactory.h"
       
    45 #include "cesmrtaskextensionimpl.h"
       
    46 
       
    47 // Logging utilities
       
    48 
       
    49 // From System
       
    50 //<cmail>
       
    51 #include <CMRUtils.h>
       
    52 #include "esmrutilsapiext.h"
       
    53 //</cmail>
       
    54 #include <msvstd.h>
       
    55 #include <msvids.h>
       
    56 //<cmail>
       
    57 #include "FreestyleEmailUiConstants.h"
       
    58 //</cmail>
       
    59 #include <eikappui.h>
       
    60 #include <eikenv.h>
       
    61 #include <calentry.h>
       
    62 #include <CalenInterimUtils2.h>
       
    63 #include <calcommon.h>
       
    64 
       
    65 // CONSTANTS
       
    66 /// Unnamed namespace for local definitions
       
    67 namespace { // codescanner::namespace
       
    68 
       
    69 #if defined(_DEBUG)
       
    70 
       
    71 // Definition for MR VIEWER ctrl panic text
       
    72 _LIT(KMRViewerCtrlPanicTxt, "ESMRViewerCtrl" );
       
    73 
       
    74 // MR VIEWER ctrl panic codes
       
    75 enum TMRViewerCtrlPanicCode
       
    76     {
       
    77     EESMRViewerCtrlSyncher = 0, // Syncher is not created,
       
    78     EESMRViewerCtrlProcessor,
       
    79     EESMRViewerCtrlTaskExt,
       
    80     EESMRViewerCtrlPolicyMgr,
       
    81     EESMRViewerCtrlInvalidModifyingRule,
       
    82     EESMRViewerCtrlInvalidEntryType
       
    83     };
       
    84 
       
    85 void Panic(TMRViewerCtrlPanicCode aPanicCode)
       
    86     {
       
    87     User::Panic( KMRViewerCtrlPanicTxt, aPanicCode );
       
    88     }
       
    89 
       
    90 #endif
       
    91 
       
    92 /**
       
    93  * Maps calendar entry type to MR entry type
       
    94  * @param aEntryType to be mapped to MR entry type
       
    95  * @return MR event type
       
    96  */
       
    97 TESMRCalendarEventType MapType( const CCalEntry& aEntry )
       
    98     {
       
    99     TESMRCalendarEventType type( EESMREventTypeNone );
       
   100 
       
   101     switch ( aEntry.EntryTypeL() )
       
   102         {
       
   103         case CCalEntry::EAppt:
       
   104             {
       
   105             if( CCalenInterimUtils2::IsMeetingRequestL( 
       
   106                     ( const_cast<CCalEntry&>( aEntry ) ) ) )
       
   107                 {
       
   108                 type = EESMREventTypeMeetingRequest;
       
   109                 }
       
   110             else
       
   111                 {
       
   112                 type = EESMREventTypeAppt;
       
   113                 }
       
   114             break;
       
   115             }
       
   116         case CCalEntry::ETodo:
       
   117             {
       
   118             type = EESMREventTypeETodo;
       
   119             break;
       
   120             }
       
   121         case CCalEntry::EEvent:
       
   122             {
       
   123             type = EESMREventTypeEEvent;
       
   124             break;
       
   125             }
       
   126         case CCalEntry::EReminder:
       
   127             {
       
   128             type = EESMREventTypeEReminder;
       
   129             break;
       
   130             }
       
   131         case CCalEntry::EAnniv:
       
   132             {
       
   133             type = EESMREventTypeEAnniv;
       
   134             break;
       
   135             }
       
   136         default:
       
   137             {
       
   138             __ASSERT_DEBUG( EFalse, Panic( EESMRViewerCtrlInvalidEntryType ) );
       
   139             }
       
   140         }
       
   141 
       
   142     return type;
       
   143     }
       
   144 
       
   145 /**
       
   146  * Creates calendar entry
       
   147  * @param required parameters for creating an entry
       
   148  * @return CCalEntry Created entry.
       
   149  */
       
   150 CCalEntry* CreateEntryL(
       
   151         CCalEntry::TType aType,
       
   152         const TDesC8& aUid,
       
   153         CCalEntry::TMethod aMethod,
       
   154         CalCommon::TRecurrenceRange aRange )
       
   155     {
       
   156     HBufC8* guid = aUid.AllocLC();
       
   157     CCalEntry* entry = CCalEntry::NewL( aType, guid, aMethod, aRange );
       
   158     CleanupStack::Pop( guid );
       
   159 
       
   160     return entry;
       
   161     }
       
   162 
       
   163 /**
       
   164  * Converts to-do specific priority to normal priority
       
   165  * @param Calendar entry, which priority is converted
       
   166  * @return The converted priority
       
   167  */
       
   168 TInt ConvertTodoPriorityToNormalL( const CCalEntry& entry )
       
   169     {
       
   170     FUNC_LOG;
       
   171     TInt priority( 0 );
       
   172     if( entry.PriorityL() == EFSCalenTodoPriorityHigh )
       
   173         {
       
   174         priority = EFSCalenMRPriorityHigh;
       
   175         }
       
   176     
       
   177     else if( entry.PriorityL() == EFSCalenTodoPriorityNormal )
       
   178         {
       
   179         priority = EFSCalenMRPriorityNormal;
       
   180         }
       
   181     
       
   182     else if( entry.PriorityL() == EFSCalenTodoPriorityLow )
       
   183         {
       
   184         priority = EFSCalenMRPriorityLow;
       
   185         }
       
   186     
       
   187     else
       
   188         {
       
   189         // Priority unknown, let's set it to normal then
       
   190         priority = EFSCalenMRPriorityNormal;
       
   191         }
       
   192 
       
   193     return priority;
       
   194     }
       
   195 
       
   196 /**
       
   197  * Converts normal priority to to-do specific priority
       
   198  * @param Calendar entry, which priority is converted
       
   199  * @return The converted priority
       
   200  */
       
   201 TInt ConvertNormalPriorityToTodoL( const CCalEntry& entry )
       
   202     {
       
   203     FUNC_LOG;
       
   204     TInt priority( 0 );
       
   205     if( entry.PriorityL() == EFSCalenMRPriorityHigh )
       
   206         {
       
   207         priority = EFSCalenTodoPriorityHigh;
       
   208         }
       
   209     
       
   210     else if( entry.PriorityL() == EFSCalenMRPriorityNormal )
       
   211         {
       
   212         priority = EFSCalenTodoPriorityNormal;
       
   213         }
       
   214     
       
   215     else if( entry.PriorityL() == EFSCalenMRPriorityLow )
       
   216         {
       
   217         priority = EFSCalenTodoPriorityLow;
       
   218         }
       
   219     
       
   220     else
       
   221         {
       
   222         // Priority unknown, let's set it to normal then
       
   223         priority = EFSCalenMRPriorityNormal;
       
   224         }
       
   225 
       
   226     return priority;
       
   227     }
       
   228 
       
   229 }  // namespace
       
   230 
       
   231 // ============================ MEMBER FUNCTIONS ===============================
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CESMRViewerController::CESMRViewerController
       
   235 // C++ default constructor can NOT contain any code, that
       
   236 // might leave.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 CESMRViewerController::CESMRViewerController(
       
   240     RPointerArray<CCalEntry>& aEntries,
       
   241     const MAgnEntryUi::TAgnEntryUiInParams& aParams,
       
   242     MAgnEntryUi::TAgnEntryUiOutParams& aOutParams,
       
   243     MAgnEntryUiCallback& aCallback )
       
   244     : iInParams( aParams ),
       
   245       iOutParams( aOutParams ),
       
   246       iCallback( aCallback ),
       
   247       iEntries( aEntries )
       
   248     {
       
   249     FUNC_LOG;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CESMRViewerController::~CESMRViewerController
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C CESMRViewerController::~CESMRViewerController()
       
   257     {
       
   258     FUNC_LOG;    
       
   259     delete iCtrlSyncher;
       
   260     delete iGuiFactory;
       
   261     delete iCalEntry;
       
   262     delete iESMRUtils;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CESMRViewerController::NewL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C CESMRViewerController* CESMRViewerController::NewL(
       
   270     const TDesC8& aMtmuid,
       
   271     RPointerArray<CCalEntry>& aEntries,
       
   272     const MAgnEntryUi::TAgnEntryUiInParams& aParams,
       
   273     MAgnEntryUi::TAgnEntryUiOutParams& aOutParams,
       
   274     MAgnEntryUiCallback& aCallback )
       
   275     {
       
   276     FUNC_LOG;
       
   277 
       
   278     CESMRViewerController* self =
       
   279         new( ELeave ) CESMRViewerController( aEntries,
       
   280                                              aParams,
       
   281                                              aOutParams,
       
   282                                              aCallback );
       
   283 
       
   284     CleanupStack::PushL( self );
       
   285     self->ConstructL(aMtmuid);
       
   286     CleanupStack::Pop( self );
       
   287 
       
   288     return self;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CESMRViewerController::ConstructL
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CESMRViewerController::ConstructL(const TDesC8& /*aMtmUid */)
       
   296     {
       
   297     FUNC_LOG;
       
   298     // This will create ESMR UTILS. Initialization is asynchronous.
       
   299     // Competion is signaled via CESMRViewerController::HandleCalEngStatus.
       
   300     iESMRUtils = CESMRUtils::NewL( *this );
       
   301     iESMRUtils->SessionSetupL(
       
   302             iInParams.iCalSession,
       
   303             iInParams.iMsgSession );
       
   304 
       
   305     iESMRUtils->CreateExtensionsL(
       
   306             ESMREntryHelper::EventTypeL( *(iEntries[0]) ) );
       
   307 
       
   308     iGuiFactory = CESMRUiFactory::NewL();
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CESMRViewerController::ExecuteL
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 EXPORT_C void CESMRViewerController::ExecuteL()
       
   316     {
       
   317     FUNC_LOG;
       
   318 
       
   319     iExecutionError = KErrNone;
       
   320 
       
   321     // Initialization waiter is needed because MR VIEWER user expects
       
   322     // MR VIEWER operation to be synchronous.
       
   323     iCtrlSyncher = new (ELeave) CActiveSchedulerWait;
       
   324 
       
   325     // MR UTILS calls CESMRViewerController::HandleCalEngStatus after init is
       
   326     // complete. CESMRViewerController::HandleCalEngStatus also sets
       
   327     // iExectionError if there occurs error during MR UTILS init.
       
   328     iCtrlSyncher->Start();
       
   329 
       
   330     User::LeaveIfError( iExecutionError );
       
   331 
       
   332     iEntryProcessor =
       
   333         static_cast<CMREntryProcessor*>(
       
   334                 iESMRUtils->ExtensionL(
       
   335                         TUid::Uid(KESMRMREntryProcessorUid) ) );
       
   336 
       
   337     iPolicyMgr =
       
   338         static_cast<CESMRPolicyManager*>(
       
   339                 iESMRUtils->ExtensionL(
       
   340                         TUid::Uid(KESMRPolicyMgrUid) ) );
       
   341 
       
   342     iTaskExt =
       
   343         static_cast<MESMRTaskExtension*>(
       
   344                 iESMRUtils->ExtensionL(
       
   345                         TUid::Uid(KESMRTaskExtensionUid) ) );
       
   346 
       
   347     // Check that all extensions are found
       
   348     if ( !iEntryProcessor || !iPolicyMgr || !iTaskExt )
       
   349         {
       
   350         // All extensions are not found --> Leave
       
   351         User::Leave( KErrNotSupported );
       
   352         }
       
   353 
       
   354     iEntryProcessor->ProcessL(
       
   355             &iInParams,
       
   356             &iEntries );
       
   357 
       
   358     LaunchCorrectOperationModeL();
       
   359 
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CESMRViewerController::IsCommandAvailable
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 TBool CESMRViewerController::IsCommandAvailable( TInt aCommandId )
       
   367     {
       
   368     FUNC_LOG;
       
   369 
       
   370 
       
   371     TBool retValue( EFalse );
       
   372 
       
   373     if ( KFSEmailUiUid == iInParams.iCallingApp )
       
   374         {
       
   375         retValue = iCallback.IsCommandAvailable( aCommandId );
       
   376         }
       
   377 
       
   378 
       
   379     return retValue;
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CESMRViewerController::ProcessCommandWithResultL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 TInt CESMRViewerController::ProcessCommandWithResultL( TInt aCommandId )
       
   387     {
       
   388     FUNC_LOG;
       
   389 
       
   390     TInt result = ProcessCommandWithResultInternalL(aCommandId);
       
   391 
       
   392 
       
   393     return result;
       
   394     }
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // CESMRViewerController::ProcessCommandL
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CESMRViewerController::ProcessCommandL( TInt aCommandId )
       
   401     {
       
   402     FUNC_LOG;
       
   403 
       
   404     ProcessCommandWithResultL( aCommandId );
       
   405 
       
   406     }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // CESMRViewerController::HandleCalEngStatus
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CESMRViewerController::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus )
       
   413     {
       
   414     FUNC_LOG;
       
   415 
       
   416 
       
   417     __ASSERT_DEBUG( iCtrlSyncher, Panic(EESMRViewerCtrlSyncher) );
       
   418 
       
   419     if ( ENotReady == aStatus )
       
   420         {
       
   421         // cal db is not ready
       
   422         iExecutionError = KErrNotReady;
       
   423         }
       
   424     else if (ENotAvailable == aStatus )
       
   425         {
       
   426         // cal db cannot be found
       
   427         iExecutionError = KErrNotFound;
       
   428         }
       
   429 
       
   430 // <cmail>
       
   431     if ( iCtrlSyncher &&
       
   432             iCtrlSyncher->IsStarted() &&
       
   433             iCtrlSyncher->CanStopNow() )
       
   434 // </cmail>
       
   435         {
       
   436         // Exection continues in CESMRViewerController::ExecuteL
       
   437         iCtrlSyncher->AsyncStop();
       
   438         }
       
   439 
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CESMRViewerController::HandleOperation
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CESMRViewerController::HandleOperation(
       
   447         TInt /*aType*/,
       
   448         TInt /*aPercentageCompleted*/,
       
   449         TInt /*aStatus*/ )
       
   450     {
       
   451     FUNC_LOG;
       
   452 
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CESMRViewerController::PolicyProvider
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 MMRPolicyProvider& CESMRViewerController::PolicyProvider() const
       
   460     {
       
   461     return *iPolicyMgr;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CESMRViewerController::EntryL
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 MESMRCalEntry* CESMRViewerController::EntryL()
       
   469     {
       
   470     return &iEntryProcessor->ESMREntryL();
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CESMRViewerController::ProcessCommandWithResultInternalL
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 TInt CESMRViewerController::ProcessCommandWithResultInternalL(
       
   478         TInt aCommandId )
       
   479     {
       
   480     FUNC_LOG;
       
   481 
       
   482     TInt ret = ProcessDefaultCommandL( aCommandId );
       
   483 
       
   484     if ( ret == KErrNotSupported )
       
   485         {
       
   486         ret = ProcessMeetingRequestCommandL( aCommandId );
       
   487         }
       
   488 
       
   489     return ret;
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CESMRViewerController::ProcessDefaultCommandL
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 TInt CESMRViewerController::ProcessDefaultCommandL( TInt aCommandId )
       
   497     {
       
   498     FUNC_LOG;
       
   499 
       
   500     TESMRCommand command = static_cast<TESMRCommand>(aCommandId);
       
   501     TBool needToProcessOutputParams( ETrue );
       
   502 
       
   503     MESMRCalEntry& entry = iEntryProcessor->ESMREntryL();
       
   504     TInt ret = KErrNone;
       
   505 
       
   506     MESMRCalDbMgr& dbMgr = entry.GetDBMgr();
       
   507     switch( aCommandId )
       
   508         {
       
   509         case EESMRCmdSaveMR:            // Saves Entry
       
   510         case EESMRCmdCalEntryUISave:
       
   511             {
       
   512             // If we are editing an existing entry.
       
   513             if ( entry.IsStoredL() )
       
   514                 {
       
   515                 // If entry is type changed.
       
   516                 if ( entry.IsEntryTypeChangedL() )
       
   517                     {
       
   518                     // If entry is type changed, delete the old entry first
       
   519                     // from db ... 
       
   520 
       
   521                     CCalEntry* lastStoredEntry = 
       
   522                             dbMgr.FetchEntryL( 
       
   523                                     entry.Entry().UidL(), 
       
   524                                     entry.Entry().RecurrenceIdL() );
       
   525                     ASSERT( lastStoredEntry );
       
   526                     CleanupStack::PushL( lastStoredEntry );
       
   527                     
       
   528                     if( CCalenInterimUtils2::IsMeetingRequestL( 
       
   529                                     *lastStoredEntry ) )
       
   530                         {
       
   531                         // Last stored entry was MR. If MR is sent, it needs to be 
       
   532                         // also cancelled before deleting
       
   533                         CancelAndDeleteMRInEntryTypeChangeL( 
       
   534                                 *lastStoredEntry,dbMgr );
       
   535                         }
       
   536                     else
       
   537                         {
       
   538                         // Use right taskExtension                        
       
   539                         CESMRTaskFactory* taskFactory = CESMRTaskFactory::NewL(
       
   540                         		MapType( *lastStoredEntry ),
       
   541                         		dbMgr );
       
   542                         CleanupStack::PushL( taskFactory );                        
       
   543                         
       
   544                         MESMRTaskExtension* taskExtension =
       
   545                             CESMRTaskExtenstionImpl::NewL( *taskFactory );
       
   546                         CleanupDeletePushL( taskExtension );
       
   547                         
       
   548                         taskExtension->DeleteEntryFromLocalDBL(
       
   549                                 EESMRCmdCalEntryUIDelete,
       
   550                                 entry );
       
   551                         
       
   552                         CleanupStack::PopAndDestroy( taskExtension );                         
       
   553                         CleanupStack::PopAndDestroy( taskFactory );                                                
       
   554                         }
       
   555                     
       
   556                     // ... and then store the new (edited) entry to db.
       
   557                     iTaskExt->StoreEntryToLocalDBL(
       
   558                             command,
       
   559                             entry );
       
   560                     
       
   561                     CleanupStack::PopAndDestroy( lastStoredEntry );
       
   562                     }
       
   563                 
       
   564                 // If we are saving entry that previously existed in 
       
   565                 // different db.
       
   566                 else if ( dbMgr.EntryViewL( entry.Entry() ) != NULL
       
   567                           && dbMgr.EntryViewL( entry.Entry() ) != dbMgr.EntryView() )
       
   568                     {
       
   569                     iTaskExt->MoveEntryToCurrentDBL( command, entry );
       
   570                     }
       
   571                 
       
   572                 // And if none of the above conditions apply, we are just editing 
       
   573                 // an entry and want to save it.
       
   574                 else
       
   575                     {
       
   576                     iTaskExt->StoreEntryToLocalDBL(
       
   577                                             command,
       
   578                                             entry );
       
   579                     }
       
   580                 }
       
   581             
       
   582             // Store new entry to db.
       
   583             else
       
   584                 {
       
   585                 iTaskExt->StoreEntryToLocalDBL(
       
   586                         command,
       
   587                         entry );
       
   588                 }
       
   589             }
       
   590             break;
       
   591 
       
   592         case EESMRCmdCalEntryUIDelete:           // Deletes Entry
       
   593             {
       
   594             iTaskExt->DeleteEntryFromLocalDBL(
       
   595                     command,
       
   596                     entry );
       
   597 
       
   598             }
       
   599             break;
       
   600 
       
   601         case EESMRCmdEdit:              // Edit MR
       
   602         case EESMRCmdEditLocal:         // Locally edit meeting request
       
   603         case EESMRCmdCalEntryUIEdit:    // Edit calendar entries
       
   604             {
       
   605             iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeEdit );
       
   606             iPolicyMgr->PushPolicyL();
       
   607             LaunchUIL();
       
   608 
       
   609             // No need to process parameters because the view is closed
       
   610             // and editing view has processed to parameters
       
   611             needToProcessOutputParams = EFalse;
       
   612             iPolicyMgr->PopPolicy();
       
   613 
       
   614             iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeView );
       
   615             }
       
   616             break;
       
   617 
       
   618         case EESMRCmdCalEntryUISend:      // Send calendar entry item
       
   619         case EESMRCmdCalEntryUIAddParticipants:  // Add participants to meeting item
       
   620             {
       
   621             ASSERT( EFalse );
       
   622             }
       
   623             break;
       
   624 
       
   625         case EESMRCmdEditorInitializationComplete:
       
   626             {
       
   627             if ( iCallback.IsCommandAvailable( EESMRCmdEditorInitializationComplete ) )
       
   628                 {
       
   629                 iCallback.ProcessCommandL( EESMRCmdEditorInitializationComplete );
       
   630                 }
       
   631             break;
       
   632             }
       
   633 
       
   634         case EMRCommandSwitchToMR:
       
   635         case EMRCommandSwitchToMeeting:
       
   636         case EMRCommandSwitchToMemo:
       
   637         case EMRCommandSwitchToAnniversary:
       
   638         case EMRCommandSwitchToTodo:
       
   639             {
       
   640             ChangeEntryTypeL( aCommandId );
       
   641             needToProcessOutputParams = EFalse;
       
   642             }
       
   643             break;
       
   644 
       
   645         /*
       
   646         case EMRLaunchAttachmentsView:
       
   647         case EMRViewAttachmentInCorrespondingApp:
       
   648             {
       
   649             iCallback.ProcessCommandL( command );
       
   650             }
       
   651             break;
       
   652 */
       
   653         case EESMRCmdTodoMarkAsDone:
       
   654             {
       
   655             iTaskExt->MarkTodoAsDoneL( command,
       
   656                     iEntryProcessor->ESMREntryL() );
       
   657             }
       
   658             break;
       
   659 
       
   660         case EESMRCmdTodoMarkAsNotDone:
       
   661             {
       
   662             iTaskExt->MarkTodoAsNotDoneL( command,
       
   663                     iEntryProcessor->ESMREntryL() );
       
   664             }
       
   665             break;
       
   666 
       
   667         default:
       
   668             ret = KErrNotSupported;
       
   669             needToProcessOutputParams = EFalse;
       
   670             break;
       
   671         }
       
   672 
       
   673     if ( needToProcessOutputParams )
       
   674         {
       
   675         iEntryProcessor->ProcessOutputParametersL(
       
   676                 iOutParams,
       
   677                 command );
       
   678         }
       
   679 
       
   680 
       
   681     return ret;
       
   682     }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CESMRViewerController::ProcessMeetingRequestCommandL
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 TInt CESMRViewerController::ProcessMeetingRequestCommandL( TInt aCommandId )
       
   689     {
       
   690     FUNC_LOG;
       
   691 
       
   692     TESMRCommand command = static_cast<TESMRCommand>(aCommandId);
       
   693     TBool needToProcessOutputParams( ETrue );
       
   694 
       
   695     MESMRCalEntry* tmpEntry = &iEntryProcessor->ESMREntryL();
       
   696 
       
   697     ASSERT( tmpEntry->Type() == EESMREventTypeMeetingRequest );
       
   698 
       
   699     if ( tmpEntry->Type() != EESMREventTypeMeetingRequest )
       
   700         {
       
   701         User::Leave( KErrNotSupported );
       
   702         }
       
   703 
       
   704     MESMRMeetingRequestEntry& entry( *static_cast<MESMRMeetingRequestEntry*>( tmpEntry ) );
       
   705     MESMRCalDbMgr& dbMgr = entry.GetDBMgr();
       
   706 
       
   707     switch( aCommandId )
       
   708         {
       
   709         case EESMRCmdSendMR:            // Send Meeting request
       
   710         case EESMRCmdSendMRUpdate:      // Send MR update
       
   711             {
       
   712             entry.ConfirmEntryL();
       
   713 
       
   714             if( entry.IsStoredL() )
       
   715                 {
       
   716                 if( entry.IsEntryTypeChangedL() ||
       
   717                         ( ( dbMgr.EntryViewL( entry.Entry() ) != NULL ) &&
       
   718                         ( dbMgr.EntryViewL( entry.Entry() ) != dbMgr.EntryView() ) ) )
       
   719                     {
       
   720                     if(!entry.IsEntryTypeChangedL())
       
   721                     	{
       
   722                     	entry.SetSendCanellationAvailable( EFalse );
       
   723                     	}
       
   724                     iTaskExt->DeleteEntryFromLocalDBL(
       
   725                             EESMRCmdDeleteMR,
       
   726                             entry );
       
   727                     }
       
   728                 }
       
   729             iTaskExt->SendAndStoreMRL(
       
   730                             command,
       
   731                             entry );
       
   732             }
       
   733             break;
       
   734 
       
   735         case EESMRCmdAcceptMR:          // Accept received MR
       
   736         case EESMRCmdTentativeMR:       // Tentatively accept MR
       
   737         case EESMRCmdDeclineMR:         // Decline MR
       
   738             {
       
   739 			entry.ConfirmEntryL();
       
   740 			iTaskExt->SendAndStoreResponseL(
       
   741 					command,
       
   742 					entry );
       
   743             }
       
   744             break;
       
   745 
       
   746         case EESMRAcceptWithoutAttachmentCheck:
       
   747         case EESMRTentativeWithoutAttachmentCheck:
       
   748         case EESMRDeclineWithoutAttachmentCheck:
       
   749             {
       
   750             entry.ConfirmEntryL();
       
   751             iTaskExt->SendAndStoreResponseL(
       
   752                     command,
       
   753                     entry );
       
   754             }
       
   755             break;
       
   756 
       
   757         case EESMRCmdDeleteMR:           // Deletes MR
       
   758         case EESMRCmdRemoveFromCalendar: // Removes MR from calendar
       
   759         case EESMRCmdMailDelete:         // Mail specific delete command
       
   760             {
       
   761             if ( EESMRCmdDeleteMR == command ||
       
   762                  EESMRCmdMailDelete == command  )
       
   763                 {
       
   764                 entry.MarkMeetingCancelledL();
       
   765                 }
       
   766 
       
   767             iTaskExt->DeleteAndSendMRL(
       
   768                     command,
       
   769                     entry );
       
   770 
       
   771             if ( entry.IsOpenedFromMail() )
       
   772                 {
       
   773                 // Triggering mail delete command also
       
   774                 needToProcessOutputParams = EFalse;
       
   775                 iCallback.ProcessCommandL( aCommandId );
       
   776                 }
       
   777             }
       
   778             break;
       
   779 
       
   780         case EESMRCmdViewTrack:
       
   781             {
       
   782             TESMRViewMode viewMode = iEntryProcessor->ScenarioData().iViewMode;
       
   783             // iEntryProcessor->SwitchToTrackL();
       
   784             iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeTrack );
       
   785             iPolicyMgr->PushPolicyL();
       
   786             LaunchUIL();
       
   787 
       
   788             //go back to original view depending on where we came from
       
   789             if (viewMode == EESMREditMR)
       
   790                 {
       
   791                 //iEntryProcessor->SwitchToEditL();
       
   792                 iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeEdit );
       
   793                 }
       
   794             else
       
   795                 {
       
   796                 // iEntryProcessor->SwitchToViewL();
       
   797                 iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeView );
       
   798                 }
       
   799 
       
   800             LaunchUIL();
       
   801             iPolicyMgr->PopPolicy();
       
   802             }
       
   803             break;
       
   804         case EESMRCmdForwardAsMeeting:   // Forward MR as meeting
       
   805             {
       
   806             // iEntryProcessor->SwitchToForwardL();
       
   807             iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeForward );
       
   808             iPolicyMgr->PushPolicyL();
       
   809             LaunchUIL();
       
   810             iPolicyMgr->PopPolicy();
       
   811             // iEntryProcessor->SwitchToViewL();
       
   812             iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeView );
       
   813             }
       
   814             break;
       
   815 
       
   816         case EESMRCmdForwardAsMail:      // Forward MR as mail
       
   817             {
       
   818             if ( entry.IsOpenedFromMail() )
       
   819                 {
       
   820                 needToProcessOutputParams = EFalse;
       
   821                 iCallback.ProcessCommandL(
       
   822                         EESMRCmdMailForwardAsMessage );
       
   823                 }
       
   824             else
       
   825                 {
       
   826                 iTaskExt->ForwardMRAsEmailL(
       
   827                         command,
       
   828                         entry );
       
   829                 }
       
   830             }
       
   831             break;
       
   832 
       
   833         case EESMRCmdReply:      // Forward MR as mail
       
   834         case EESMRCmdReplyAll:   //Flow through
       
   835             {
       
   836             if ( entry.IsOpenedFromMail() )
       
   837                 {
       
   838                 TInt emailCommand( EESMRCmdMailReply );
       
   839                 if ( EESMRCmdReplyAll == aCommandId )
       
   840                     {
       
   841                     emailCommand = EESMRCmdMailReplyAll;
       
   842                     }
       
   843                 needToProcessOutputParams = EFalse;
       
   844                 iCallback.ProcessCommandL(
       
   845                         emailCommand );
       
   846                 }
       
   847             else
       
   848                 {
       
   849                 iTaskExt->ReplyAsEmailL(
       
   850                         command,
       
   851                         entry );
       
   852                 }
       
   853             }
       
   854             break;
       
   855 
       
   856         // Email commands
       
   857         case EESMRCmdMailMarkUnread:
       
   858         case EESMRCmdMailMarkRead:
       
   859         case EESMRCmdMailForwardAsMessage:
       
   860         case EESMRCmdMailMoveMessage:
       
   861         case EESMRCmdMailCopyMessage:
       
   862         case EESMRCmdMailFlagMessage:
       
   863         case EESMRCmdMailComposeMessage:
       
   864         case EESMRCmdMailMessageDetails:
       
   865         case EESMRCmdMailPreviousMessage:
       
   866         case EESMRCmdMailNextMessage:
       
   867         case EESMRCmdMailMoveMessageToDrafts:
       
   868         case EESMRCmdOpenAttachment:
       
   869         case EESMRCmdOpenAttachmentView:
       
   870         case EESMRCmdDownloadAttachment:
       
   871         case EESMRCmdDownloadAllAttachments:
       
   872         case EESMRCmdSaveAttachment:
       
   873         case EESMRCmdSaveAllAttachments:
       
   874         case EESMRCmdDownloadManager:
       
   875             {
       
   876             needToProcessOutputParams = EFalse;
       
   877             iCallback.ProcessCommandL( aCommandId );
       
   878             }
       
   879             break;
       
   880 
       
   881         default:
       
   882             User::Leave( KErrNotSupported );
       
   883         }
       
   884 
       
   885     if ( needToProcessOutputParams )
       
   886         {
       
   887         iEntryProcessor->ProcessOutputParametersL(
       
   888                 iOutParams,
       
   889                 command );
       
   890         }
       
   891 
       
   892     return KErrNone;
       
   893     }
       
   894 
       
   895 // -----------------------------------------------------------------------------
       
   896 // CESMRViewerController::ChangeEntryTypeL
       
   897 // -----------------------------------------------------------------------------
       
   898 //
       
   899 void CESMRViewerController::ChangeEntryTypeL( TInt aCommandId )
       
   900     {
       
   901     TESMRCalendarEventType type = EESMREventTypeNone;
       
   902 
       
   903     switch ( aCommandId )
       
   904         {
       
   905         case EMRCommandSwitchToMR:
       
   906             {
       
   907             type = EESMREventTypeMeetingRequest;
       
   908             break;
       
   909             }
       
   910 
       
   911         case EMRCommandSwitchToMeeting:
       
   912             {
       
   913             type = EESMREventTypeAppt;
       
   914             break;
       
   915             }
       
   916 
       
   917         case EMRCommandSwitchToMemo:
       
   918             {
       
   919             type = EESMREventTypeEEvent;
       
   920             break;
       
   921             }
       
   922 
       
   923         case EMRCommandSwitchToAnniversary:
       
   924             {
       
   925             type = EESMREventTypeEAnniv;
       
   926             break;
       
   927             }
       
   928 
       
   929         case EMRCommandSwitchToTodo:
       
   930             {
       
   931             type = EESMREventTypeETodo;
       
   932             break;
       
   933             }
       
   934 
       
   935         default:
       
   936             {
       
   937             break;
       
   938             }
       
   939         }    
       
   940    
       
   941     // Original entry is needed for creating new comparative entry
       
   942     CCalEntry* originalEntry =
       
   943             ESMRHelper::CopyEntryL(
       
   944                     iEntryProcessor->ESMREntryL().OriginalEntry(),
       
   945                     iEntryProcessor->ESMREntryL().OriginalEntry().MethodL(),
       
   946                     ESMRHelper::ECopyFull );
       
   947     
       
   948     CleanupStack::PushL( originalEntry );
       
   949     
       
   950     // Create a new entry by cloning the existing entry. 
       
   951     // This also does the type conversion and judges what
       
   952     // entry information will be copied from the old entry
       
   953     // to the new entry
       
   954     CCalEntry* newEntry =
       
   955         iEntryProcessor->ESMREntryL().CloneEntryLC(
       
   956                 MESMRCalEntry::TESMRCalEntryType( type ) );
       
   957     
       
   958     iESMRUtils->CreateExtensionsL( type );
       
   959     
       
   960     iEntryProcessor =
       
   961             static_cast<CMREntryProcessor*>(
       
   962                     iESMRUtils->ExtensionL(
       
   963                             TUid::Uid( KESMRMREntryProcessorUid ) ) );
       
   964 
       
   965     iPolicyMgr =
       
   966         static_cast<CESMRPolicyManager*>(
       
   967                 iESMRUtils->ExtensionL(
       
   968                         TUid::Uid( KESMRPolicyMgrUid ) ) );
       
   969 
       
   970     iTaskExt =
       
   971         static_cast<MESMRTaskExtension*>(
       
   972                 iESMRUtils->ExtensionL(
       
   973                         TUid::Uid( KESMRTaskExtensionUid ) ) );
       
   974     
       
   975     // Process entry
       
   976     iEntryProcessor->ResetL();
       
   977     iEntryProcessor->ProcessL( &iInParams, *newEntry, EFalse, ETrue );
       
   978 
       
   979     if ( iInParams.iEditorMode == MAgnEntryUi::EViewEntry )
       
   980         {
       
   981         // If user has been viewing original entry, switch processor to editor.
       
   982         iEntryProcessor->SwitchProcessorToModeL( EMRProcessorModeEdit );
       
   983         }
       
   984 
       
   985     // Resolve new policy
       
   986     iPolicyMgr->ResolvePolicyL( iEntryProcessor->ScenarioData(),
       
   987                                 iEntryProcessor->ESMREntryL(),
       
   988                                 NULL );
       
   989 
       
   990     if ( iCalEntry )
       
   991         {
       
   992         delete iCalEntry;
       
   993         }
       
   994 
       
   995     iCalEntry = newEntry;
       
   996     CleanupStack::Pop( newEntry );
       
   997     newEntry = NULL;
       
   998 
       
   999     // Comparative entry needs to be updated also, otherwise
       
  1000     // type changed entry's saving won't function correctly
       
  1001     UpdateComparativeEntryInTypeChangeL( *originalEntry );
       
  1002     
       
  1003     iEntryProcessor->ESMREntryL().SetTypeChanged( ETrue );
       
  1004     
       
  1005     CleanupStack::PopAndDestroy( originalEntry );
       
  1006     }
       
  1007 
       
  1008 // -----------------------------------------------------------------------------
       
  1009 // CESMRViewerController::LaunchUIL
       
  1010 // -----------------------------------------------------------------------------
       
  1011 //
       
  1012 void CESMRViewerController::LaunchUIL()
       
  1013     {
       
  1014     FUNC_LOG;
       
  1015     iPolicyMgr->ResolvePolicyL(
       
  1016         iEntryProcessor->ScenarioData(),
       
  1017         iEntryProcessor->ESMREntryL(),
       
  1018         NULL ); // Passing NULL --> Default policy resolver is used
       
  1019 
       
  1020     MESMRUiBase* uibase =
       
  1021             iGuiFactory->CreateUIL(
       
  1022             *this,
       
  1023             *this );
       
  1024 
       
  1025     TInt retValue = uibase->ExecuteViewLD();
       
  1026 
       
  1027     if ( retValue == EAknCmdExit  )
       
  1028         {
       
  1029         MESMRCalEntry* calEntry = &iEntryProcessor->ESMREntryL();
       
  1030         
       
  1031         if( CCalenInterimUtils2::IsMeetingRequestL( calEntry->Entry() ) )
       
  1032             {
       
  1033             // Cast safe, after we have identified the entry as mr 
       
  1034             MESMRMeetingRequestEntry& mrEntry( 
       
  1035                     *static_cast< MESMRMeetingRequestEntry* >( calEntry ) );
       
  1036             
       
  1037             if( mrEntry.IsOpenedFromMail() )
       
  1038                 {
       
  1039                 CEikAppUi* appUi =
       
  1040                     CEikonEnv::Static()->EikAppUi(); // codescanner::eikonenvstatic
       
  1041                 // Exit application
       
  1042                 static_cast<MEikCommandObserver*>( appUi )->ProcessCommandL( 
       
  1043                         EAknCmdExit );
       
  1044                 }
       
  1045             else
       
  1046                 {
       
  1047                 // Let's inform via output parameters that 
       
  1048                 // exit is desired.
       
  1049                 TMROutputParams* outputParams = 
       
  1050                    reinterpret_cast< TMROutputParams* >( iOutParams.iSpare );
       
  1051                 outputParams->iCommand = EMRDialogOptionsMenuExit;
       
  1052                 }
       
  1053             }
       
  1054         else
       
  1055             {
       
  1056             // Let's inform via output parameters that 
       
  1057             // exit is desired.
       
  1058             TMROutputParams* outputParams = 
       
  1059                reinterpret_cast< TMROutputParams* >( iOutParams.iSpare );
       
  1060             outputParams->iCommand = EMRDialogOptionsMenuExit;
       
  1061             }
       
  1062         }
       
  1063     }
       
  1064 
       
  1065 // -----------------------------------------------------------------------------
       
  1066 // CESMRViewerController::LaunchCorrectOperationModeL
       
  1067 // -----------------------------------------------------------------------------
       
  1068 //
       
  1069 void CESMRViewerController::LaunchCorrectOperationModeL()
       
  1070     {
       
  1071     FUNC_LOG;
       
  1072     TESMRInputParams* esmrInputParams = (TESMRInputParams*)(iInParams.iSpare);
       
  1073 
       
  1074     if ( esmrInputParams &&
       
  1075             EESMRCmdUndefined != esmrInputParams->iCommand )
       
  1076         {
       
  1077         ProcessCommandWithResultL( esmrInputParams->iCommand );
       
  1078         }
       
  1079     else
       
  1080         {
       
  1081         LaunchUIL();
       
  1082         }
       
  1083     }
       
  1084 
       
  1085 // -----------------------------------------------------------------------------
       
  1086 // CESMRViewerController::UpdateComparativeEntryInTypeChangeL
       
  1087 // -----------------------------------------------------------------------------
       
  1088 //
       
  1089 void CESMRViewerController::UpdateComparativeEntryInTypeChangeL(
       
  1090         const CCalEntry& aOriginalEntry  )
       
  1091     {
       
  1092     /* 
       
  1093      * This is needed because if user creates an entry and only type changes
       
  1094      * the entry, but does  not input any data, we cannot save the entry.
       
  1095      */
       
  1096 
       
  1097     CCalEntry& esmrEntry = iEntryProcessor->ESMREntryL().Entry();
       
  1098 
       
  1099     TESMRCalendarEventType type = MapType( aOriginalEntry );
       
  1100     
       
  1101     // Let's create new comparative entry based on the current 
       
  1102     // type changed entry
       
  1103     CCalEntry* newComparativeEntry = CreateEntryL(         
       
  1104             iCalEntry->EntryTypeL(),
       
  1105             iCalEntry->UidL(),
       
  1106             CCalEntry::EMethodNone,
       
  1107             CalCommon::EThisOnly );
       
  1108 
       
  1109     CleanupStack::PushL( newComparativeEntry );
       
  1110     
       
  1111     newComparativeEntry->CopyFromL( *iCalEntry );
       
  1112 
       
  1113     // New comparative entry needs still data from original entry.
       
  1114     // Use case:
       
  1115     // - User opens entry to editor
       
  1116     // - User changes values
       
  1117     // - User changes entry type
       
  1118     // -> We need to determine if entry values have changed from the original
       
  1119     newComparativeEntry->SetSummaryL(
       
  1120             aOriginalEntry.SummaryL() );
       
  1121     newComparativeEntry->SetLocationL(
       
  1122             aOriginalEntry.LocationL() );
       
  1123     newComparativeEntry->SetDescriptionL(
       
  1124             aOriginalEntry.DescriptionL() );
       
  1125     newComparativeEntry->SetReplicationStatusL(
       
  1126             aOriginalEntry.ReplicationStatusL() );
       
  1127     
       
  1128     // If original and new entries are both appointments,
       
  1129     // then also start and end times can be copied from original entry
       
  1130     // to comparative entry
       
  1131     if( aOriginalEntry.EntryTypeL() == CCalEntry::EAppt &&
       
  1132             esmrEntry.EntryTypeL() == CCalEntry::EAppt )
       
  1133         {
       
  1134         newComparativeEntry->SetStartAndEndTimeL(
       
  1135                 aOriginalEntry.StartTimeL(),
       
  1136                 aOriginalEntry.EndTimeL() );
       
  1137         }
       
  1138 
       
  1139     // Time stamp must be the same as in esmrEntry
       
  1140     newComparativeEntry->SetDTStampL( esmrEntry.DTStampL() );
       
  1141 
       
  1142     // If neither the original entry, nor the new entry
       
  1143     // are To-do's, we can also copy the priority from
       
  1144     // the original entry, since priority value is then compatible
       
  1145     // between the old and the new entry types
       
  1146     if( aOriginalEntry.EntryTypeL() != CCalEntry::ETodo && 
       
  1147             iCalEntry->EntryTypeL() != CCalEntry::ETodo )
       
  1148         {
       
  1149         newComparativeEntry->SetPriorityL( 
       
  1150                 aOriginalEntry.PriorityL() );
       
  1151         }
       
  1152     // One of the entries, original or new, are to-do's,
       
  1153     // so the priority value is not compatible between them.
       
  1154     // we need to convert that
       
  1155     else
       
  1156         {
       
  1157         if( aOriginalEntry.EntryTypeL() == CCalEntry::ETodo )
       
  1158             {
       
  1159             newComparativeEntry->SetPriorityL( 
       
  1160                     ConvertTodoPriorityToNormalL( aOriginalEntry ) );
       
  1161             }
       
  1162         else if( iCalEntry->EntryTypeL() == CCalEntry::ETodo )
       
  1163             {
       
  1164             newComparativeEntry->SetPriorityL( 
       
  1165                     ConvertNormalPriorityToTodoL( aOriginalEntry ) );
       
  1166             }
       
  1167         }
       
  1168     
       
  1169     // If new entry is meeting request, let's also
       
  1170     // copy the same phone owner to the comparative entry
       
  1171     if( iCalEntry->MethodL() == CCalEntry::EMethodRequest )
       
  1172         {
       
  1173         CCalUser* temp = esmrEntry.OrganizerL(); // Ownership not transfered
       
  1174         CCalUser* organizer = ESMRHelper::CopyUserL( *temp );
       
  1175 
       
  1176         newComparativeEntry->SetOrganizerL( organizer );
       
  1177         newComparativeEntry->SetPhoneOwnerL(
       
  1178                 newComparativeEntry->OrganizerL() );
       
  1179         }
       
  1180     
       
  1181     // Attachment information is also needed from original entry
       
  1182     if( aOriginalEntry.AttachmentCountL() == 0 )
       
  1183         {
       
  1184         // Original entry did not have attachments, so let's 
       
  1185         // remove possible attachments from comparative entry also
       
  1186         TInt count = newComparativeEntry->AttachmentCountL();
       
  1187         
       
  1188         // Attachments need to be deleted in reversed order
       
  1189         for( TInt i = ( count - 1 ); i == 0; --i )
       
  1190             {
       
  1191             newComparativeEntry->DeleteAttachmentL( 
       
  1192                     *( newComparativeEntry->AttachmentL( i ) ) );
       
  1193             }
       
  1194         
       
  1195         // If original entry does have attachments, we do nothing ->
       
  1196         // If original entry has attachments, it has been already saved 
       
  1197         // and now type changed, which means that it needs to be saved 
       
  1198         // anyway.
       
  1199         }
       
  1200 
       
  1201     iEntryProcessor->ESMREntryL().UpdateComparativeEntry(
       
  1202             newComparativeEntry ); // Takes ownership
       
  1203 
       
  1204     CleanupStack::Pop( newComparativeEntry );
       
  1205     }
       
  1206 
       
  1207 // -----------------------------------------------------------------------------
       
  1208 // CESMRViewerController::CancelAndDeleteMRInEntryTypeChangeL
       
  1209 // -----------------------------------------------------------------------------
       
  1210 //
       
  1211 void CESMRViewerController::CancelAndDeleteMRInEntryTypeChangeL( 
       
  1212         CCalEntry& aEntry, MESMRCalDbMgr& aDbMgr )
       
  1213 	{
       
  1214 	FUNC_LOG;
       
  1215 	// We need new task factor, processor and task extension
       
  1216 	// for this temporary MR action.
       
  1217     CESMRTaskFactory* taskFactory = CESMRTaskFactory::NewL(
       
  1218             EESMREventTypeMeetingRequest,
       
  1219             aDbMgr );
       
  1220     CleanupStack::PushL( taskFactory );
       
  1221     
       
  1222     CMREntryProcessor* entryProcessor = CMREntryProcessor::NewL(
       
  1223             EESMREventTypeMeetingRequest,
       
  1224             aDbMgr );
       
  1225     CleanupStack::PushL( entryProcessor );
       
  1226     
       
  1227     MESMRTaskExtension* taskExtension =
       
  1228         CESMRTaskExtenstionImpl::NewL( *taskFactory );
       
  1229     CleanupDeletePushL( taskExtension );
       
  1230     
       
  1231     entryProcessor->ProcessL( &iInParams, aEntry, EFalse, ETrue );
       
  1232     MESMRCalEntry& entry = entryProcessor->ESMREntryL();
       
  1233 
       
  1234     // Cast safe, because entry is always MR
       
  1235     MESMRMeetingRequestEntry& mrEntry( 
       
  1236             static_cast<MESMRMeetingRequestEntry&>( entry ) );
       
  1237     
       
  1238     if ( EESMRRoleOrganizer == mrEntry.RoleL() )
       
  1239         {
       
  1240         CCalEntry::TStatus status( mrEntry.Entry().StatusL() );
       
  1241         if ( CCalEntry::ENullStatus != status )
       
  1242             {
       
  1243             // We are changing entry type from MR to some other type
       
  1244             // And we have sent the MR invitation to attendees.
       
  1245             // We provide possibility for user to send
       
  1246             // cancellation message to attendees.
       
  1247             mrEntry.MarkMeetingCancelledL();
       
  1248 
       
  1249             taskExtension->DeleteAndSendMRL(
       
  1250                     EESMRCmdDeleteMR,
       
  1251                     mrEntry );
       
  1252             }
       
  1253         else
       
  1254             {
       
  1255             taskExtension->DeleteEntryFromLocalDBL(
       
  1256                     EESMRCmdDeleteMR,
       
  1257                     mrEntry );
       
  1258             }
       
  1259         }
       
  1260     
       
  1261     CleanupStack::PopAndDestroy( taskExtension );
       
  1262     CleanupStack::PopAndDestroy( entryProcessor );
       
  1263     CleanupStack::PopAndDestroy( taskFactory );
       
  1264 	}
       
  1265 
       
  1266 //  End of File