meetingrequest/mricalviewer/src/cesmricalviewercmdhandler.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ESMR esmricalviewer implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "emailtrace.h"
       
    22 #include "cesmricalviewercmdhandler.h"
       
    23 #include "cesmricalvieweropenmrcmd.h"
       
    24 #include "cesmricalviewercanviewmr.h"
       
    25 #include "cesmricalviewerresolvemrmethodsync.h"
       
    26 #include "cesmricalviewerresolvemrmethodasync.h"
       
    27 #include "cesmricalviewerresponsetomrcmd.h"
       
    28 #include "cesmricalviewerremovemrfromcalcmd.h"
       
    29 
       
    30 #include <calsession.h>
       
    31 //<cmail>
       
    32 #include "CFSMailClient.h"
       
    33 #include "esmricalvieweropcodes.hrh"
       
    34 #include "esmricalviewerdefs.hrh"
       
    35 //</cmail>
       
    36 #include <eikenv.h>
       
    37 
       
    38 /// Unnamed namespace for local definitions
       
    39 namespace {
       
    40 
       
    41 #ifdef _DEBUG
       
    42 
       
    43 // Panic literal
       
    44 _LIT( KESMRIcalViewerCmdHandler, "ESMRIcalViewerCmdHandler" );
       
    45 
       
    46 enum TESMRIcalViewerCmdHandlerPanic
       
    47     {
       
    48     EInvalidCommand = 0, // Trying to execute invalid command
       
    49     EInvalidObserverCall
       
    50     };
       
    51 
       
    52 void Panic( TESMRIcalViewerCmdHandlerPanic aPanic )
       
    53     {
       
    54     User::Panic( KESMRIcalViewerCmdHandler, aPanic );
       
    55     }
       
    56 
       
    57 #endif // _DEBUG
       
    58 
       
    59 }  // namespace
       
    60 
       
    61 // ======== MEMBER FUNCTIONS ========
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CESMRIcalViewerCmdHandler::CESMRIcalViewerCmdHandler
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CESMRIcalViewerCmdHandler::CESMRIcalViewerCmdHandler(
       
    68         MESMRIcalViewerCallback& aCallback )
       
    69 :   iCallback( aCallback )
       
    70     {
       
    71     FUNC_LOG;
       
    72     //do nothing
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CESMRIcalViewerCmdHandler::~CESMRIcalViewerCmdHandler
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CESMRIcalViewerCmdHandler::~CESMRIcalViewerCmdHandler()
       
    80     {
       
    81     FUNC_LOG;
       
    82     CancelOperation();
       
    83 
       
    84     delete iCommand;
       
    85     delete iMessage;
       
    86     if ( iMailClient )
       
    87         {
       
    88         iMailClient->Close();
       
    89         }
       
    90     delete iCalSession;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CESMRIcalViewerCmdHandler::NewL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CESMRIcalViewerCmdHandler* CESMRIcalViewerCmdHandler::NewL(
       
    98         MESMRIcalViewerCallback& aCallback )
       
    99     {
       
   100     FUNC_LOG;
       
   101     CESMRIcalViewerCmdHandler* self =
       
   102             new (ELeave) CESMRIcalViewerCmdHandler( aCallback );
       
   103     CleanupStack::PushL( self );
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop( self );
       
   106     return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CESMRIcalViewerCmdHandler::ConstructL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CESMRIcalViewerCmdHandler::ConstructL()
       
   114     {
       
   115     FUNC_LOG;
       
   116     iCalSession = CCalSession::NewL();
       
   117     iCalSession->OpenL( KNullDesC );
       
   118     iMailClient = CFSMailClient::NewL();
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CESMRIcalViewerCmdHandler::ExecuteCommandL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CESMRIcalViewerCmdHandler::ExecuteCommandL(
       
   126         TESMRIcalViewerOperationType aOpType,
       
   127         MESMRIcalViewerObserver* aObserver,
       
   128         CFSMailMessage& aMessage )
       
   129     {
       
   130     FUNC_LOG;
       
   131     ExecuteCommandL( aOpType, aObserver, aMessage, NULL );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CESMRIcalViewerCmdHandler::ExecuteCommandL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CESMRIcalViewerCmdHandler::ExecuteCommandL(
       
   139         TESMRIcalViewerOperationType aOpType,
       
   140         MESMRIcalViewerObserver* aObserver,
       
   141         CFSMailMessage& aMessage,
       
   142         TAny* aParam )
       
   143     {
       
   144     FUNC_LOG;
       
   145     TRAPD( err, ExecuteCommandInternalL( aOpType,
       
   146                                         aObserver,
       
   147                                         aMessage,
       
   148                                         aParam ) );
       
   149     
       
   150     if ( KErrNone != err && EIdle != iState )
       
   151         {
       
   152         // Make sure that error is notified to caller in all cases
       
   153         if ( iObserver)
       
   154             {
       
   155             iResult.iMessage = &aMessage;
       
   156             iResult.iResultCode = err;
       
   157             iResult.iOpType = aOpType;        
       
   158             iObserver->OperationError( iResult );
       
   159             }
       
   160         iState = EIdle;
       
   161         }
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CESMRIcalViewerCmdHandler::CancelOperation
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CESMRIcalViewerCmdHandler::CancelOperation()
       
   169     {
       
   170     FUNC_LOG;
       
   171     if ( iCommand )
       
   172         {
       
   173         iCommand->CancelCommand();
       
   174         }
       
   175 
       
   176     iState = EIdle;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CESMRIcalViewerCmdHandler::OperationCompleted
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CESMRIcalViewerCmdHandler::OperationCompleted(
       
   184         TIcalViewerOperationResult aResult )
       
   185     {
       
   186     FUNC_LOG;
       
   187     __ASSERT_DEBUG( iCommand, Panic(EInvalidObserverCall) );
       
   188     __ASSERT_DEBUG(
       
   189             iCommand->OperationType() == aResult.iOpType,
       
   190             Panic(EInvalidObserverCall) );
       
   191 
       
   192     if ( iObserver )
       
   193         {
       
   194         aResult.iOpType = iCommand->OperationType();
       
   195         iObserver->OperationCompleted( aResult );
       
   196         }
       
   197 
       
   198     iState = EIdle;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CESMRIcalViewerCmdHandler::OperationError
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CESMRIcalViewerCmdHandler::OperationError(
       
   206                 TIcalViewerOperationResult aResult )
       
   207     {
       
   208     FUNC_LOG;
       
   209     __ASSERT_DEBUG( iCommand, Panic(EInvalidObserverCall) );
       
   210     __ASSERT_DEBUG(
       
   211             iCommand->OperationType() == aResult.iOpType,
       
   212             Panic(EInvalidObserverCall) );
       
   213 
       
   214     if ( iObserver )
       
   215         {
       
   216         aResult.iOpType = iCommand->OperationType();
       
   217         iObserver->OperationError( aResult );
       
   218         }
       
   219 
       
   220     iState = EIdle;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CESMRIcalViewerCmdHandler::ExecuteCommandInternalL
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CESMRIcalViewerCmdHandler::ExecuteCommandInternalL( 
       
   228         TESMRIcalViewerOperationType aOpType,
       
   229         MESMRIcalViewerObserver* aObserver,
       
   230         CFSMailMessage& aMessage,
       
   231         TAny* aParam )
       
   232     {
       
   233     FUNC_LOG;
       
   234     if ( EExecuting == iState )
       
   235         {
       
   236         User::Leave( KErrInUse );
       
   237         }
       
   238 
       
   239     delete iCommand; iCommand = NULL;
       
   240 
       
   241     iState = EExecuting;
       
   242     iObserver = aObserver;
       
   243 
       
   244     // Get own copy of the message before executing commands
       
   245     delete iMessage; iMessage = NULL;
       
   246     iMessage = iMailClient->GetMessageByUidL(
       
   247             aMessage.GetMailBoxId(),
       
   248             aMessage.GetFolderId(),
       
   249             aMessage.GetMessageId(),
       
   250             EFSMsgDataStructure );
       
   251 
       
   252     switch ( aOpType )
       
   253         {
       
   254         case EESMRViewLaunch:
       
   255             {
       
   256             iCommand = CESMRIcalViewerOpenMRCmd:: NewL(
       
   257                     iCallback,
       
   258                     *iMailClient,
       
   259                     *iCalSession );
       
   260             }
       
   261             break;
       
   262 
       
   263         case EESMRCanViewMR:
       
   264             {
       
   265             TBool* flag = static_cast<TBool*>( aParam );
       
   266             iCommand = CESMRIcalViewerCanViewMsgCmd:: NewL(
       
   267                     *iCalSession,
       
   268                     *flag );
       
   269             }
       
   270             break;
       
   271 
       
   272         case EESMRResolveMRMethod:
       
   273             {
       
   274             iCommand = CESMRIcalViewerResolveMRMethodASyncCmd::NewL(
       
   275                                 *iCalSession,
       
   276                                 *iMailClient );
       
   277             }
       
   278             break;
       
   279 
       
   280         case EESMRResolveMRMethodSync:
       
   281             {
       
   282             TESMRMeetingRequestMethod* mrMethod =
       
   283                     static_cast<TESMRMeetingRequestMethod*>( aParam );
       
   284 
       
   285             iCommand = CESMRIcalViewerResolveMRMethodSyncCmd::NewL(
       
   286                                     *iCalSession,
       
   287                                     *iMailClient,
       
   288                                     *mrMethod );
       
   289             }
       
   290             break;
       
   291 
       
   292         case EESMRResponseToMR:
       
   293             {
       
   294             TESMRAttendeeStatus* attendeeStatus =
       
   295                     static_cast<TESMRAttendeeStatus*>( aParam );
       
   296 
       
   297             iCommand = CESMRIcalViewerResponseToMRCmd::NewL(
       
   298                             iCallback,
       
   299                             *iCalSession,
       
   300                             *iMailClient,
       
   301                             *attendeeStatus);
       
   302 
       
   303             }
       
   304             break;
       
   305 
       
   306         case EESMRRemoveMR:
       
   307             {
       
   308             iCommand = CESMRIcalViewerRemoveMRFromCalCmd::NewL(
       
   309                             *iCalSession,
       
   310                             *iMailClient );
       
   311             }
       
   312             break;
       
   313 
       
   314         default:
       
   315             break;
       
   316         }
       
   317 
       
   318     __ASSERT_DEBUG( iCommand, Panic( EInvalidCommand) );
       
   319     iCommand->ExecuteCommandL( *iMessage, *this );
       
   320     }
       
   321 
       
   322 // EOF
       
   323