meetingrequest/mricalviewer/src/cesmricalviewerresponsetomrcmd.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25: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:  Resolving meeting request method asynchronoysly
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmricalviewerresponsetomrcmd.h"
       
    22 #include "cesmruilauncher.h"
       
    23 #include "cesmricalvieweremailasynccmd.h"
       
    24 #include "cesmricalvieweremailsynccmd.h"
       
    25 #include "esmricalviewerutils.h"
       
    26 
       
    27 //<cmail>
       
    28 #include "esmricalvieweropcodes.hrh"
       
    29 #include <calsession.h>
       
    30 #include "cfsmailclient.h"
       
    31 //</cmail>
       
    32 #include <calentry.h>
       
    33 
       
    34 #include "cesmrmrinfoicalretriever.h"
       
    35 #include "cesmrimapicalretriever.h"
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CESMRIcalViewerResponseToMRCmd::CESMRIcalViewerResponseToMRCmd
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CESMRIcalViewerResponseToMRCmd::CESMRIcalViewerResponseToMRCmd(
       
    44         MESMRIcalViewerCallback& aCallback,
       
    45         CCalSession& aCalSession,
       
    46         CFSMailClient& aMailClient,
       
    47         TESMRAttendeeStatus aAttendeeStatus )
       
    48 :   CESMRIcalViewerAsyncCommand( EESMRResponseToMR, aCalSession ),
       
    49     iCallback( aCallback ),
       
    50     iMailClient( aMailClient ),
       
    51     iAttendeeStatus( aAttendeeStatus ),
       
    52     iCurrentCbCommand( EESMREmailCommand )
       
    53     {
       
    54     FUNC_LOG;
       
    55     //do nothing
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CESMRIcalViewerResponseToMRCmd::~CESMRIcalViewerResponseToMRCmd
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CESMRIcalViewerResponseToMRCmd::~CESMRIcalViewerResponseToMRCmd()
       
    63     {
       
    64     FUNC_LOG;
       
    65     CancelCommand();
       
    66     delete iUILauncher;
       
    67 
       
    68     iMRRetrieverCommands.ResetAndDestroy();
       
    69     iMRRetrieverCommands.Close();
       
    70     delete iEmailCommand;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CESMRIcalViewerResponseToMRCmd::NewL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CESMRIcalViewerResponseToMRCmd* CESMRIcalViewerResponseToMRCmd::NewL(
       
    78         MESMRIcalViewerCallback& aCallback,
       
    79         CCalSession& aCalSession,
       
    80         CFSMailClient& aMailClient,
       
    81         TESMRAttendeeStatus aAttendeeStatus )
       
    82     {
       
    83     FUNC_LOG;
       
    84     CESMRIcalViewerResponseToMRCmd* self =
       
    85             new (ELeave) CESMRIcalViewerResponseToMRCmd(
       
    86                     aCallback,
       
    87                     aCalSession,
       
    88                     aMailClient,
       
    89                     aAttendeeStatus );
       
    90 
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL();
       
    93     CleanupStack::Pop( self );
       
    94     return self;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CESMRIcalViewerResponseToMRCmd::ConstructL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CESMRIcalViewerResponseToMRCmd::ConstructL()
       
   102     {
       
   103     FUNC_LOG;
       
   104     BaseConstructL();
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CESMRIcalViewerResponseToMRCmd::OperationCompleted
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CESMRIcalViewerResponseToMRCmd::OperationCompleted(
       
   112         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   113     {
       
   114     FUNC_LOG;
       
   115     TRAPD( err, HandleOperationCompletedL(aResult) );
       
   116     if (KErrNone != err )
       
   117         {
       
   118         aResult.iOpType = OperationType();
       
   119         aResult.iResultCode = err;
       
   120         Observer()->OperationError( aResult );
       
   121         }
       
   122     else if ( !iUILauncher && ((EESMREmailCommand == iCurrentCbCommand) ||
       
   123     		  (iCurrentCbCommand == EESMRCmdMailDelete)) )
       
   124         {
       
   125         aResult.iOpType = OperationType();
       
   126         aResult.iAttendeeStatus = iAttendeeStatus;
       
   127         Observer()->OperationCompleted( aResult );
       
   128         }
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CESMRIcalViewerResponseToMRCmd::LaunchUiL
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CESMRIcalViewerResponseToMRCmd::LaunchUiL()
       
   136     {
       
   137     FUNC_LOG;
       
   138     if ( !iUILauncher )
       
   139         {
       
   140         iUILauncher = CESMRUiLauncher::NewL(
       
   141                             CalSession(),
       
   142                             iESMRInputParams,
       
   143                             *this );
       
   144         }
       
   145 
       
   146     iUILauncher->ExecuteCommandL( *Message(), *this );
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CESMRIcalViewerResponseToMRCmd::OperationError
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CESMRIcalViewerResponseToMRCmd::OperationError(
       
   154         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   155     {
       
   156     FUNC_LOG;
       
   157     if ( aResult.iOpType == EESMRLoadMRInfoData )
       
   158         {
       
   159         if ( aResult.iResultCode == KErrNotFound && iMRRetrieverCommands.Count() > iCurrentCommand + 1 )
       
   160             {
       
   161             TRAPD( error, iMRRetrieverCommands[++iCurrentCommand]->ExecuteCommandL(
       
   162                     *Message(),
       
   163                     *this ) );
       
   164             if ( error != KErrNone )
       
   165                 {
       
   166                 aResult.iOpType = OperationType();
       
   167                 aResult.iResultCode = error;
       
   168                 aResult.iMessage = Message();
       
   169                 Observer()->OperationError( aResult );
       
   170                 }
       
   171             }
       
   172         else
       
   173             {
       
   174             aResult.iOpType  = OperationType();
       
   175             aResult.iMessage = Message();
       
   176             Observer()->OperationError( aResult );
       
   177             }
       
   178         }
       
   179     else
       
   180         {
       
   181         aResult.iOpType  = OperationType();
       
   182         aResult.iMessage = Message();
       
   183         aResult.iResultCode = KErrNotSupported;
       
   184 
       
   185         Observer()->OperationError( aResult );
       
   186         }
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CESMRIcalViewerResponseToMRCmd::ExecuteAsyncCommandL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CESMRIcalViewerResponseToMRCmd::ExecuteAsyncCommandL()
       
   194     {
       
   195     FUNC_LOG;
       
   196     CESMRInfoIcalRetrieverCmd* cmd = CESMRInfoIcalRetrieverCmd::NewL(
       
   197                 CalSession(),
       
   198                 iESMRInputParams );
       
   199 
       
   200     CleanupStack::PushL( cmd );
       
   201     User::LeaveIfError(
       
   202             iMRRetrieverCommands.Append( cmd ) );
       
   203     CleanupStack::Pop( cmd ); cmd = NULL;
       
   204 
       
   205     CESMRImapIcalRetrieverCmd* cmd2 =
       
   206         CESMRImapIcalRetrieverCmd::NewL(
       
   207             CalSession(),
       
   208             iMailClient,
       
   209             iESMRInputParams );
       
   210 
       
   211     CleanupStack::PushL( cmd2 );
       
   212     User::LeaveIfError(
       
   213             iMRRetrieverCommands.Append( cmd2 ) );
       
   214     CleanupStack::Pop( cmd2 ); cmd2 = NULL;
       
   215 
       
   216     iCurrentCommand = 0;
       
   217 
       
   218     if(iMRRetrieverCommands.Count() > iCurrentCommand)
       
   219         {
       
   220         iMRRetrieverCommands[iCurrentCommand]->ExecuteCommandL(
       
   221                        *Message(),
       
   222                        *this );
       
   223         }
       
   224     else
       
   225         {
       
   226         User::Leave(KErrOverflow);
       
   227         }
       
   228     
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CESMRIcalViewerResolveMRMethodASyncCmd::CancelAsyncCommand
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CESMRIcalViewerResponseToMRCmd::CancelAsyncCommand()
       
   236     {
       
   237     FUNC_LOG;
       
   238     TInt commandCount( iMRRetrieverCommands.Count() );
       
   239 
       
   240     for ( TInt i(0); i < commandCount; ++i )
       
   241         {
       
   242         iMRRetrieverCommands[iCurrentCommand]->CancelCommand();
       
   243         }
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CESMRIcalViewerResponseToMRCmd::ProcessCommandL
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CESMRIcalViewerResponseToMRCmd::ProcessCommandL(TInt aCommandId)
       
   251     {
       
   252     FUNC_LOG;
       
   253     ProcessCommandWithResultL( aCommandId );
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CESMRIcalViewerResponseToMRCmd::ProcessCommandWithResultL
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TInt CESMRIcalViewerResponseToMRCmd::ProcessCommandWithResultL( TInt aCommandId )
       
   261     {
       
   262     FUNC_LOG;
       
   263     TInt retValue( KErrNotSupported );
       
   264 
       
   265     if ( IsCommandAvailable( aCommandId ) )
       
   266         {
       
   267         iMRViewerCommand = aCommandId;
       
   268 
       
   269         iCurrentCbCommand =
       
   270                 ESMRIcalViewerUtils::EmailOperation(aCommandId);
       
   271 
       
   272         TBool asyncCommand(
       
   273                 ESMRIcalViewerUtils::IsAsyncEmailCommand( iCurrentCbCommand ) );
       
   274 
       
   275         if ( asyncCommand )
       
   276             {
       
   277             iEmailCommand = CESMRIcalViewerEmailAsyncCmd::NewL(
       
   278                     iCurrentCbCommand,
       
   279                     CalSession(),
       
   280                     iCallback );
       
   281             }
       
   282         else
       
   283             {
       
   284             iEmailCommand = CESMRIcalViewerEmailSyncCmd::NewL(
       
   285                                     iCurrentCbCommand,
       
   286                                     CalSession(),
       
   287                                     iCallback );
       
   288             }
       
   289 
       
   290         iEmailCommand->ExecuteCommandL( *Message(), *this );
       
   291 
       
   292         if ( !asyncCommand )
       
   293             {
       
   294             // Email specific sync command has been executed.
       
   295             iCurrentCbCommand = EESMREmailCommand;
       
   296             }
       
   297         retValue = KErrNone;
       
   298         }
       
   299 
       
   300     return retValue;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CESMRIcalViewerResponseToMRCmd::IsCommandAvailable
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 TBool CESMRIcalViewerResponseToMRCmd::IsCommandAvailable( TInt aCommandId )
       
   308     {
       
   309     FUNC_LOG;
       
   310     TESMRIcalViewerOperationType command(
       
   311              ESMRIcalViewerUtils::EmailOperation(aCommandId) );
       
   312 
       
   313     return iCallback.CanProcessCommand( command );
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CESMRIcalViewerResponseToMRCmd::HandleOperationCompletedL
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CESMRIcalViewerResponseToMRCmd::HandleOperationCompletedL(
       
   321         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   322     {
       
   323     FUNC_LOG;
       
   324     if ( EESMRLaunchUI == aResult.iOpType )
       
   325         {
       
   326         delete iUILauncher;
       
   327         iUILauncher = NULL;
       
   328         }
       
   329 
       
   330     if ( aResult.iOpType == EESMRLoadMRInfoData ||
       
   331          aResult.iOpType == EESMRLoadMRIcalData ||
       
   332          (aResult.iOpType == iCurrentCbCommand &&
       
   333           aResult.iOpType != EESMRCmdMailDelete) ) // <cmail>
       
   334         {
       
   335         // MRINFO data was parsed succesfully
       
   336         CCalEntry::TMethod method( CCalEntry::EMethodNone );
       
   337         method = iESMRInputParams.iCalEntry->MethodL();
       
   338 
       
   339         if ( CCalEntry::EMethodRequest == method )
       
   340             {
       
   341             iESMRInputParams.iMailClient = &iMailClient;
       
   342             iESMRInputParams.iMailMessage = Message();
       
   343             iESMRInputParams.iCommand = EESMRCmdAcceptMR;
       
   344             iESMRInputParams.iSpare = 0;
       
   345 
       
   346             if ( EESMRAttendeeStatusTentative == iAttendeeStatus )
       
   347                 {
       
   348                 iESMRInputParams.iCommand = EESMRCmdTentativeMR;
       
   349                 }
       
   350             else if ( EESMRAttendeeStatusDecline == iAttendeeStatus )
       
   351                 {
       
   352                 iESMRInputParams.iCommand = EESMRCmdDeclineMR;
       
   353                 }
       
   354             if ( ESMRIcalViewerUtils::ContainsAttachments(iESMRInputParams) &&
       
   355                  iMRViewerCommand != iCurrentCbCommand &&
       
   356                  aResult.iOpType == iCurrentCbCommand )
       
   357                 {
       
   358                 iCurrentCbCommand = EESMREmailCommand;
       
   359                 iESMRInputParams.iCommand =
       
   360                         ESMRIcalViewerUtils::MRResponseCommandWithoutAttachmentCheck(
       
   361                                 iMRViewerCommand);
       
   362                 }
       
   363             LaunchUiL();
       
   364             }
       
   365 
       
   366         if ( iCurrentCbCommand == EESMREmailCommand &&
       
   367              method != CCalEntry::EMethodNone &&
       
   368              !iUILauncher )
       
   369             {
       
   370             // No email command in execution --> Notify observer
       
   371             aResult.iOpType = OperationType();
       
   372             aResult.iAttendeeStatus = iAttendeeStatus;
       
   373             Observer()->OperationCompleted( aResult );
       
   374             }
       
   375         }
       
   376     }
       
   377 
       
   378 // EOF
       
   379