meetingrequest/mricalviewer/src/cesmricalviewerresolvemrmethodasync.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:  Resolving meeting request method asynchronoysly
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmricalviewerresolvemrmethodasync.h"
       
    22 #include "esmricalviewerutils.h"
       
    23 //<cmail>
       
    24 #include "esmricalvieweropcodes.hrh"
       
    25 #include <calsession.h>
       
    26 #include "CFSMailClient.h"
       
    27 //</cmail>
       
    28 #include <calentry.h>
       
    29 
       
    30 #include "cesmrmrinfoicalretriever.h"
       
    31 #include "cesmrimapicalretriever.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CESMRIcalViewerResolveMRMethodASyncCmd::CESMRIcalViewerResolveMRMethodASyncCmd
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CESMRIcalViewerResolveMRMethodASyncCmd::CESMRIcalViewerResolveMRMethodASyncCmd(
       
    40         CCalSession& aCalSession,
       
    41         CFSMailClient& aMailClient )
       
    42 :   CESMRIcalViewerAsyncCommand( EESMRResolveMRMethod, aCalSession ),
       
    43     iMailClient( aMailClient ),
       
    44     iMRMethod( EESMRMeetingRequestMethodUnknown )
       
    45     {
       
    46     FUNC_LOG;
       
    47     //do nothing
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CESMRIcalViewerResolveMRMethodASyncCmd::~CESMRIcalViewerResolveMRMethodASyncCmd
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CESMRIcalViewerResolveMRMethodASyncCmd::~CESMRIcalViewerResolveMRMethodASyncCmd()
       
    55     {
       
    56     FUNC_LOG;
       
    57     CancelCommand();
       
    58     iMRRetrieverCommands.ResetAndDestroy();
       
    59     iMRRetrieverCommands.Close();
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CESMRIcalViewerResolveMRMethodASyncCmd::NewL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CESMRIcalViewerResolveMRMethodASyncCmd* CESMRIcalViewerResolveMRMethodASyncCmd::NewL(
       
    67         CCalSession& aCalSession,
       
    68         CFSMailClient& aMailClient )
       
    69     {
       
    70     FUNC_LOG;
       
    71     CESMRIcalViewerResolveMRMethodASyncCmd* self =
       
    72             new (ELeave) CESMRIcalViewerResolveMRMethodASyncCmd(
       
    73                     aCalSession, aMailClient  );
       
    74 
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CESMRIcalViewerResolveMRMethodASyncCmd::ConstructL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CESMRIcalViewerResolveMRMethodASyncCmd::ConstructL()
       
    86     {
       
    87     FUNC_LOG;
       
    88     BaseConstructL();
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CESMRIcalViewerResolveMRMethodASyncCmd::OperationCompleted
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CESMRIcalViewerResolveMRMethodASyncCmd::OperationCompleted(
       
    96         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
    97     {
       
    98     FUNC_LOG;
       
    99     if ( aResult.iOpType == EESMRLoadMRInfoData ||
       
   100          aResult.iOpType == EESMRLoadMRIcalData         )
       
   101         {
       
   102         // MRINFO data was parsed succesfully
       
   103         CCalEntry::TMethod method( CCalEntry::EMethodNone );
       
   104         // If this leaves we just go to case default.
       
   105         TRAP_IGNORE( method = iESMRInputParams.iCalEntry->MethodL() );
       
   106 
       
   107         switch ( method )
       
   108             {
       
   109             case CCalEntry::EMethodRequest:
       
   110                 {
       
   111                 iMRMethod = EESMRMeetingRequestMethodRequest;
       
   112                 }
       
   113                 break;
       
   114             case CCalEntry::EMethodReply:
       
   115                 {
       
   116                 iMRMethod = EESMRMeetingRequestMethodResponse;
       
   117                 }
       
   118                 break;
       
   119             case CCalEntry::EMethodCancel:
       
   120                 {
       
   121                 iMRMethod = EESMRMeetingRequestMethodCancellation;
       
   122                 }
       
   123                 break;
       
   124             default:
       
   125                 {
       
   126                 iMRMethod = EESMRMeetingRequestMethodUnknown;
       
   127                 }
       
   128                 break;
       
   129             }
       
   130 
       
   131         aResult.iOpType  = OperationType();
       
   132         aResult.iMethod  = iMRMethod;
       
   133         aResult.iMessage = Message();
       
   134 
       
   135         TBool isAttendee = EFalse;
       
   136         TRAP_IGNORE( isAttendee = ESMRIcalViewerUtils::IsMailboxOwnerAttendeeL(
       
   137                             *(iESMRInputParams.iCalEntry),
       
   138                             iMailClient,
       
   139                             *Message() )) ;
       
   140 
       
   141         if ( !isAttendee )
       
   142             {
       
   143             iMRMethod = EESMRMeetingRequestMethodUnknown;
       
   144             aResult.iMethod = EESMRMeetingRequestMethodUnknown;
       
   145             }
       
   146 
       
   147         Observer()->OperationCompleted( aResult );
       
   148         }
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CESMRIcalViewerResolveMRMethodASyncCmd::OperationError
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CESMRIcalViewerResolveMRMethodASyncCmd::OperationError(
       
   156         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   157     {
       
   158     FUNC_LOG;
       
   159     if ( aResult.iOpType == EESMRLoadMRInfoData )
       
   160         {
       
   161         if ( aResult.iResultCode == KErrNotFound && iMRRetrieverCommands.Count() > iCurrentCommand + 1)
       
   162             {
       
   163             TRAPD( error, iMRRetrieverCommands[++iCurrentCommand]->ExecuteCommandL(
       
   164                     *Message(),
       
   165                     *this ) );
       
   166             if ( error != KErrNone )
       
   167                 {
       
   168                 aResult.iOpType = OperationType();
       
   169                 aResult.iResultCode = error;
       
   170                 aResult.iMethod  = iMRMethod;
       
   171                 aResult.iMessage = Message();
       
   172                 Observer()->OperationError( aResult );
       
   173                 }
       
   174             }
       
   175         else
       
   176             {
       
   177             aResult.iOpType  = OperationType();
       
   178             aResult.iMethod  = iMRMethod;
       
   179             aResult.iMessage = Message();
       
   180 
       
   181             Observer()->OperationError( aResult );
       
   182             }
       
   183         }
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CESMRIcalViewerResolveMRMethodASyncCmd::ExecuteAsyncCommandL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CESMRIcalViewerResolveMRMethodASyncCmd::ExecuteAsyncCommandL()
       
   191     {
       
   192     FUNC_LOG;
       
   193     CESMRInfoIcalRetrieverCmd* cmd = CESMRInfoIcalRetrieverCmd::NewL(
       
   194                 CalSession(),
       
   195                 iESMRInputParams );
       
   196 
       
   197     CleanupStack::PushL( cmd );
       
   198     User::LeaveIfError(
       
   199             iMRRetrieverCommands.Append( cmd ) );
       
   200     CleanupStack::Pop( cmd ); cmd = NULL;
       
   201 
       
   202     CESMRImapIcalRetrieverCmd* cmd2 =
       
   203         CESMRImapIcalRetrieverCmd::NewL(
       
   204             CalSession(),
       
   205             iMailClient,
       
   206             iESMRInputParams );
       
   207 
       
   208     CleanupStack::PushL( cmd2 );
       
   209     User::LeaveIfError(
       
   210             iMRRetrieverCommands.Append( cmd2 ) );
       
   211     CleanupStack::Pop( cmd2 ); cmd2 = NULL;
       
   212 
       
   213     iCurrentCommand = 0;
       
   214    
       
   215     if(iMRRetrieverCommands.Count() > iCurrentCommand)
       
   216         {
       
   217         iMRRetrieverCommands[iCurrentCommand]->ExecuteCommandL(
       
   218                     *Message(),
       
   219                     *this );
       
   220         }
       
   221     else
       
   222        	{
       
   223        	User::Leave(KErrOverflow);
       
   224        	}
       
   225     
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CESMRIcalViewerResolveMRMethodASyncCmd::CancelAsyncCommand
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CESMRIcalViewerResolveMRMethodASyncCmd::CancelAsyncCommand()
       
   233     {
       
   234     FUNC_LOG;
       
   235     TInt commandCount( iMRRetrieverCommands.Count() );
       
   236 
       
   237     for ( TInt i(0); i < commandCount; ++i )
       
   238         {
       
   239         iMRRetrieverCommands[iCurrentCommand]->CancelCommand();
       
   240         }
       
   241     }
       
   242 
       
   243 // EOF
       
   244