meetingrequest/mricalviewer/src/cesmricalviewerremovemrfromcalcmd.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 "cesmricalviewerremovemrfromcalcmd.h"
       
    22 #include "cesmruilauncher.h"
       
    23 
       
    24 //<cmail>
       
    25 #include "esmricalvieweropcodes.hrh"
       
    26 #include <calsession.h>
       
    27 #include "cfsmailclient.h"
       
    28 //</cmail>
       
    29 #include <calentry.h>
       
    30 
       
    31 #include "cesmrmrinfoicalretriever.h"
       
    32 #include "cesmrimapicalretriever.h"
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CESMRIcalViewerRemoveMRFromCalCmd::CESMRIcalViewerRemoveMRFromCalCmd
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CESMRIcalViewerRemoveMRFromCalCmd::CESMRIcalViewerRemoveMRFromCalCmd(
       
    41         CCalSession& aCalSession,
       
    42         CFSMailClient& aMailClient )
       
    43 :   CESMRIcalViewerAsyncCommand( EESMRRemoveMR, aCalSession ),
       
    44     iMailClient( aMailClient ),
       
    45     iCurrentCommand( EESMREmailCommand )
       
    46     {
       
    47     FUNC_LOG;
       
    48     //do nothing
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CESMRIcalViewerRemoveMRFromCalCmd::~CESMRIcalViewerRemoveMRFromCalCmd
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55         CESMRIcalViewerRemoveMRFromCalCmd::~CESMRIcalViewerRemoveMRFromCalCmd()
       
    56     {
       
    57     FUNC_LOG;
       
    58     CancelCommand();
       
    59     delete iUILauncher;
       
    60     iMRRetrieverCommands.ResetAndDestroy();
       
    61     iMRRetrieverCommands.Close();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CESMRIcalViewerResponseToMRCmd::NewL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CESMRIcalViewerRemoveMRFromCalCmd* CESMRIcalViewerRemoveMRFromCalCmd::NewL(
       
    69         CCalSession& aCalSession,
       
    70         CFSMailClient& aMailClient )
       
    71     {
       
    72     FUNC_LOG;
       
    73     CESMRIcalViewerRemoveMRFromCalCmd* self =
       
    74             new (ELeave) CESMRIcalViewerRemoveMRFromCalCmd(
       
    75                     aCalSession,
       
    76                     aMailClient );
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CESMRIcalViewerRemoveMRFromCalCmd::ConstructL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CESMRIcalViewerRemoveMRFromCalCmd::ConstructL()
       
    89     {
       
    90     FUNC_LOG;
       
    91     BaseConstructL();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CESMRIcalViewerRemoveMRFromCalCmd::OperationCompleted
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CESMRIcalViewerRemoveMRFromCalCmd::OperationCompleted(
       
    99         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   100     {
       
   101     FUNC_LOG;
       
   102     TRAPD( err, HandleOperationCompletedL(aResult) );
       
   103     if (KErrNone != err )
       
   104         {
       
   105         aResult.iOpType = OperationType();
       
   106         aResult.iResultCode = err;
       
   107         Observer()->OperationError( aResult );
       
   108         }
       
   109     else if ( !iUILauncher )
       
   110         {
       
   111         aResult.iOpType = OperationType();
       
   112         Observer()->OperationCompleted( aResult );
       
   113         }
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CESMRIcalViewerRemoveMRFromCalCmd::LaunchUiL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CESMRIcalViewerRemoveMRFromCalCmd::LaunchUiL()
       
   121     {
       
   122     FUNC_LOG;
       
   123     if ( !iUILauncher )
       
   124         {
       
   125         iUILauncher = CESMRUiLauncher::NewL(
       
   126                             CalSession(),
       
   127                             iESMRInputParams,
       
   128                             *this );
       
   129         }
       
   130 
       
   131     iUILauncher->ExecuteCommandL( *Message(), *this );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CESMRIcalViewerRemoveMRFromCalCmd::OperationError
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CESMRIcalViewerRemoveMRFromCalCmd::OperationError(
       
   139         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   140     {
       
   141     FUNC_LOG;
       
   142     if ( aResult.iOpType == EESMRLoadMRInfoData )
       
   143         {
       
   144         if ( aResult.iResultCode == KErrNotFound  && iMRRetrieverCommands.Count() > iCurrentCommand + 1 )
       
   145             {
       
   146             TRAPD( error, iMRRetrieverCommands[++iCurrentCommand]->ExecuteCommandL(
       
   147                     *Message(),
       
   148                     *this ) );
       
   149             if ( error != KErrNone )
       
   150                 {
       
   151                 aResult.iOpType = OperationType();
       
   152                 aResult.iResultCode = error;
       
   153                 aResult.iMessage = Message();
       
   154                 Observer()->OperationError( aResult );
       
   155                 }
       
   156             }
       
   157         else
       
   158             {
       
   159             aResult.iOpType  = OperationType();
       
   160             aResult.iMessage = Message();
       
   161             Observer()->OperationError( aResult );
       
   162             }
       
   163         }
       
   164     else
       
   165         {
       
   166         aResult.iOpType  = OperationType();
       
   167         aResult.iMessage = Message();
       
   168         Observer()->OperationError( aResult );
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CESMRIcalViewerRemoveMRFromCalCmd::ExecuteAsyncCommandL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CESMRIcalViewerRemoveMRFromCalCmd::ExecuteAsyncCommandL()
       
   177     {
       
   178     FUNC_LOG;
       
   179     CESMRInfoIcalRetrieverCmd* cmd = CESMRInfoIcalRetrieverCmd::NewL(
       
   180                 CalSession(),
       
   181                 iESMRInputParams );
       
   182 
       
   183     CleanupStack::PushL( cmd );
       
   184     User::LeaveIfError(
       
   185             iMRRetrieverCommands.Append( cmd ) );
       
   186     CleanupStack::Pop( cmd ); cmd = NULL;
       
   187 
       
   188     CESMRImapIcalRetrieverCmd* cmd2 =
       
   189         CESMRImapIcalRetrieverCmd::NewL(
       
   190             CalSession(),
       
   191             iMailClient,
       
   192             iESMRInputParams );
       
   193 
       
   194     CleanupStack::PushL( cmd2 );
       
   195     User::LeaveIfError(
       
   196             iMRRetrieverCommands.Append( cmd2 ) );
       
   197     CleanupStack::Pop( cmd2 ); cmd2 = NULL;
       
   198 
       
   199     iCurrentCommand = 0;
       
   200     
       
   201     if(iMRRetrieverCommands.Count() > iCurrentCommand)
       
   202     	{
       
   203     	iMRRetrieverCommands[iCurrentCommand]->ExecuteCommandL(
       
   204     	            *Message(),
       
   205     	            *this );
       
   206     	}
       
   207     else
       
   208         {
       
   209         User::Leave(KErrOverflow);
       
   210         }
       
   211     
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CESMRIcalViewerRemoveMRFromCalCmd::CancelAsyncCommand
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CESMRIcalViewerRemoveMRFromCalCmd::CancelAsyncCommand()
       
   219     {
       
   220     FUNC_LOG;
       
   221     TInt commandCount( iMRRetrieverCommands.Count() );
       
   222 
       
   223     for ( TInt i(0); i < commandCount; ++i )
       
   224         {
       
   225         iMRRetrieverCommands[iCurrentCommand]->CancelCommand();
       
   226         }
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CESMRIcalViewerRemoveMRFromCalCmd::ProcessCommandL
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CESMRIcalViewerRemoveMRFromCalCmd::ProcessCommandL(TInt aCommandId)
       
   234     {
       
   235     FUNC_LOG;
       
   236     ProcessCommandWithResultL( aCommandId );
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CESMRIcalViewerRemoveMRFromCalCmd::ProcessCommandWithResultL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TInt CESMRIcalViewerRemoveMRFromCalCmd::ProcessCommandWithResultL(
       
   244         TInt /*aCommandId*/  )
       
   245     {
       
   246     FUNC_LOG;
       
   247     return KErrNone;
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CESMRIcalViewerRemoveMRFromCalCmd::IsCommandAvailable
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 TBool CESMRIcalViewerRemoveMRFromCalCmd::IsCommandAvailable( TInt /*aCommandId*/ )
       
   255     {
       
   256     FUNC_LOG;
       
   257     return EFalse;
       
   258     }
       
   259 
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CESMRIcalViewerRemoveMRFromCalCmd::HandleOperationCompletedL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CESMRIcalViewerRemoveMRFromCalCmd::HandleOperationCompletedL(
       
   266             MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   267     {
       
   268     FUNC_LOG;
       
   269     if ( EESMRLaunchUI == aResult.iOpType )
       
   270         {
       
   271         delete iUILauncher;
       
   272         iUILauncher = NULL;
       
   273         }
       
   274 
       
   275     if ( aResult.iOpType == EESMRLoadMRInfoData ||
       
   276          aResult.iOpType == EESMRLoadMRIcalData )
       
   277         {
       
   278         // MRINFO data was parsed succesfully
       
   279         CCalEntry::TMethod method( CCalEntry::EMethodNone );
       
   280         method = iESMRInputParams.iCalEntry->MethodL();
       
   281 
       
   282         if ( CCalEntry::EMethodCancel == method )
       
   283             {
       
   284             // MR data is loaded
       
   285             iESMRInputParams.iMailClient = &iMailClient;
       
   286             iESMRInputParams.iMailMessage = Message();
       
   287             iESMRInputParams.iCommand = EESMRCmdRemoveFromCalendar;
       
   288             iESMRInputParams.iSpare = 0;
       
   289             LaunchUiL();
       
   290             }
       
   291         else
       
   292             {
       
   293             User::Leave( KErrNotSupported );
       
   294             }
       
   295         }
       
   296     }
       
   297 
       
   298 // EOF
       
   299