meetingrequest/mricalviewer/src/cesmricalvieweropenmrcmd.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
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:  Open meeting request command implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmricalvieweropenmrcmd.h"
       
    22 #include "cesmricalviewerloadmrdatacmd.h"
       
    23 #include "cesmricalvieweremailasynccmd.h"
       
    24 #include "cesmricalvieweremailsynccmd.h"
       
    25 #include "cesmruilauncher.h"
       
    26 #include "cesmrattachmentinfo.h"
       
    27 #include "esmricalviewerutils.h"
       
    28 
       
    29 //<cmail>
       
    30 #include "esmricalvieweropcodes.hrh"
       
    31 //</cmail>
       
    32 #include <calsession.h>
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 // -----------------------------------------------------------------------------
       
    36 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd(
       
    40         MESMRIcalViewerCallback& aCallback,
       
    41         CFSMailClient& aMailClient,
       
    42         CCalSession& aCalSession )
       
    43 :   CESMRIcalViewerAsyncCommand( EESMRViewLaunch, aCalSession ),
       
    44     iCallback( aCallback ),
       
    45     iMailClient( aMailClient ),
       
    46     iCurrentCbCommand( EESMREmailCommand )
       
    47     {
       
    48     FUNC_LOG;
       
    49     iResult.iResultCode = KErrNone;
       
    50     iResult.iOpType = OperationType();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CESMRIcalViewerOpenMRCmd::~CESMRIcalViewerOpenMRCmd()
       
    58     {
       
    59     FUNC_LOG;
       
    60     CancelCommand();
       
    61     delete iLoadMRDataCmd;
       
    62     delete iUILauncher;
       
    63     
       
    64     // <cmail>
       
    65     if( iEmailCommand )
       
    66         {
       
    67         delete iEmailCommand;
       
    68         iEmailCommand = NULL;
       
    69         }
       
    70     // </cmail>
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CESMRIcalViewerOpenMRCmd* CESMRIcalViewerOpenMRCmd::NewL(
       
    78         MESMRIcalViewerCallback& aCallback,
       
    79         CFSMailClient& aMailClient,
       
    80         CCalSession& aCalSession )
       
    81     {
       
    82     FUNC_LOG;
       
    83     CESMRIcalViewerOpenMRCmd* self =
       
    84             new (ELeave) CESMRIcalViewerOpenMRCmd(
       
    85                     aCallback,
       
    86                     aMailClient,
       
    87                     aCalSession );
       
    88 
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop( self );
       
    92     return self;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRIcalViewerOpenMRCmd::ConstructL()
       
   100     {
       
   101     FUNC_LOG;
       
   102     BaseConstructL();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CESMRIcalViewerOpenMRCmd::ExecuteAsyncCommandL()
       
   110     {
       
   111     FUNC_LOG;
       
   112     iResult.iOpType = OperationType();
       
   113     iResult.iMessage = Message();
       
   114     iResult.iResultCode = KErrNone;
       
   115 
       
   116     iLoadMRDataCmd =
       
   117             CESMRIcalViewerLoadMRDataCmd::NewL(
       
   118                     CalSession(),
       
   119                     iMailClient,
       
   120                     iInputParameters );
       
   121 
       
   122     iLoadMRDataCmd->ExecuteCommandL( *Message(), *this );
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CESMRIcalViewerOpenMRCmd::CancelAsyncCommand()
       
   130     {
       
   131     FUNC_LOG;
       
   132     if ( iLoadMRDataCmd )
       
   133         {
       
   134         iLoadMRDataCmd->CancelCommand();
       
   135         }
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CESMRIcalViewerOpenMRCmd::OperationCompleted(
       
   143          MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   144     {
       
   145     FUNC_LOG;
       
   146     TRAPD( err, HandleOperationCompeletedL( aResult ) );
       
   147     HandleError( err );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CESMRIcalViewerOpenMRCmd::CESMRIcalViewerOpenMRCmd
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CESMRIcalViewerOpenMRCmd::OperationError(
       
   155         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   156     {
       
   157     FUNC_LOG;
       
   158     iResult = aResult;
       
   159     iResult.iOpType = OperationType();
       
   160 
       
   161     if ( EESMRLaunchUI == aResult.iOpType )
       
   162         {
       
   163         delete iUILauncher;
       
   164         iUILauncher = NULL;
       
   165         }
       
   166     if ( !iUILauncher &&
       
   167           EESMREmailCommand == iCurrentCbCommand &&
       
   168           KErrCancel == aResult.iResultCode )
       
   169         {
       
   170         // We would like to launch mr again
       
   171         iInputParameters.iMailClient = &iMailClient;
       
   172         iInputParameters.iMailMessage = Message();
       
   173         iInputParameters.iCommand = EESMRCmdUndefined;
       
   174         iInputParameters.iSpare = 0;
       
   175         TRAPD( err, LaunchUIL() );
       
   176         iResult.iResultCode = err;
       
   177 
       
   178         if ( err != KErrNone )
       
   179             {
       
   180             Observer()->OperationError( iResult );
       
   181             }
       
   182         }
       
   183     else
       
   184         {
       
   185         Observer()->OperationError( iResult );
       
   186         }
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CESMRIcalViewerOpenMRCmd::ProcessCommandL
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CESMRIcalViewerOpenMRCmd::ProcessCommandL(TInt aCommandId)
       
   194     {
       
   195     FUNC_LOG;
       
   196     ProcessCommandWithResultL( aCommandId );
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CESMRIcalViewerOpenMRCmd::ProcessCommandWithResultL
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TInt CESMRIcalViewerOpenMRCmd::ProcessCommandWithResultL( TInt aCommandId )
       
   204     {
       
   205     FUNC_LOG;
       
   206 
       
   207     TInt retValue( KErrNotSupported );
       
   208 
       
   209     if ( IsCommandAvailable( aCommandId ) )
       
   210         {
       
   211         iMRViewerCommand = aCommandId;
       
   212 
       
   213         iCurrentCbCommand =
       
   214                 ESMRIcalViewerUtils::EmailOperation(aCommandId);
       
   215 
       
   216         TBool asyncCommand(
       
   217                 ESMRIcalViewerUtils::IsAsyncEmailCommand( iCurrentCbCommand ) );
       
   218 
       
   219 // <cmail>
       
   220         if( iEmailCommand )
       
   221             {
       
   222             delete iEmailCommand;
       
   223             iEmailCommand = NULL;
       
   224             }
       
   225 // </cmail>
       
   226 
       
   227         if ( asyncCommand )
       
   228             {
       
   229             iEmailCommand = CESMRIcalViewerEmailAsyncCmd::NewL(
       
   230                     iCurrentCbCommand,
       
   231                     CalSession(),
       
   232                     iCallback );
       
   233             }
       
   234         else
       
   235             {
       
   236             iEmailCommand = CESMRIcalViewerEmailSyncCmd::NewL(
       
   237                                     iCurrentCbCommand,
       
   238                                     CalSession(),
       
   239                                     iCallback );
       
   240             }
       
   241 
       
   242         iEmailCommand->ExecuteCommandL( *Message(), *this );
       
   243 
       
   244         if ( !asyncCommand )
       
   245             {
       
   246             // Email specific sync command has been executed.
       
   247             iCurrentCbCommand = EESMREmailCommand;
       
   248             }
       
   249         retValue = KErrNone;
       
   250         }
       
   251 
       
   252 
       
   253     return retValue;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CESMRIcalViewerOpenMRCmd::IsCommandAvailable
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TBool CESMRIcalViewerOpenMRCmd::IsCommandAvailable( TInt aCommandId )
       
   261     {
       
   262     FUNC_LOG;
       
   263 
       
   264     TESMRIcalViewerOperationType command(
       
   265              ESMRIcalViewerUtils::EmailOperation(aCommandId) );
       
   266 
       
   267     TBool canProcessCommand( iCallback.CanProcessCommand( command  ) );
       
   268 
       
   269     return canProcessCommand;
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CESMRIcalViewerOpenMRCmd::HandleOperationCompeletedL
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CESMRIcalViewerOpenMRCmd::HandleOperationCompeletedL(
       
   277         MESMRIcalViewerObserver::TIcalViewerOperationResult aResult )
       
   278     {
       
   279     FUNC_LOG;
       
   280 
       
   281 
       
   282     if ( EESMRLaunchUI == aResult.iOpType )
       
   283             {
       
   284             delete iUILauncher;
       
   285             iUILauncher = NULL;
       
   286             }
       
   287     else if ( aResult.iOpType == EESMRLoadMRData )
       
   288         {
       
   289         // MR data is loaded
       
   290         iInputParameters.iMailClient = &iMailClient;
       
   291         iInputParameters.iMailMessage = Message();
       
   292         iInputParameters.iCommand = EESMRCmdUndefined;
       
   293         iInputParameters.iSpare = 0;
       
   294         LaunchUIL();
       
   295         }
       
   296     else if ( aResult.iOpType == iCurrentCbCommand )
       
   297         {
       
   298         TBool asyncCommand( ESMRIcalViewerUtils::IsAsyncEmailCommand(iCurrentCbCommand) );
       
   299 
       
   300         switch ( aResult.iOpType )
       
   301             {
       
   302             case EESMRCmdOpenAttachment://fallthrough
       
   303             case EESMRCmdOpenAttachmentView://fallthrough
       
   304 // <cmail>
       
   305             case EESMRCmdDownloadAttachment://fallthrough
       
   306             case EESMRCmdDownloadAllAttachments://fallthrough
       
   307             case EESMRCmdSaveAttachment://fallthrough
       
   308             case EESMRCmdSaveAllAttachments://fallthrough
       
   309 // </cmail>
       
   310                 {
       
   311                 if ( ESMRIcalViewerUtils::ContainsAttachments(iInputParameters) &&
       
   312                      iMRViewerCommand != iCurrentCbCommand )
       
   313                     {
       
   314                     iInputParameters.iCommand =
       
   315                             ESMRIcalViewerUtils::MRResponseCommandWithoutAttachmentCheck(
       
   316                                     iMRViewerCommand);
       
   317                     }
       
   318                 iCurrentCbCommand = EESMREmailCommand;
       
   319                 //LaunchUIL();
       
   320                 }
       
   321                 break;
       
   322 
       
   323             case EESMRCmdMailForwardAsMessage://fallthrough
       
   324             case EESMRCmdMailCopyMessage://fallthrough
       
   325             case EESMRCmdMailComposeMessage://fallthrough
       
   326             case EESMRCmdMailMessageDetails://fallthrough
       
   327             case EESMRCmdDownloadManager://fallthrough
       
   328             case EESMRCmdMailReply://fallthrough
       
   329             case EESMRCmdMailReplyAll://fallthrough
       
   330                 {
       
   331                 // Ui needs to be relaunched
       
   332                 iCurrentCbCommand = EESMREmailCommand;
       
   333                 LaunchUIL();
       
   334                 }
       
   335                 break;
       
   336 
       
   337             case EESMRCmdMailMoveMessage:
       
   338                 {
       
   339                 iCurrentCbCommand = EESMREmailCommand;
       
   340                 if ( KErrCancel == aResult.iResultCode )
       
   341                     {
       
   342                     LaunchUIL();
       
   343                     }
       
   344                 }
       
   345                 break;
       
   346 
       
   347             case EESMRCmdMailPreviousMessage:
       
   348             case EESMRCmdMailNextMessage:
       
   349             case EESMRCmdMailMoveMessageToDrafts:
       
   350             case EESMRCmdMailDelete:
       
   351                 {
       
   352                 //ui won't be relaunched
       
   353                 iCurrentCbCommand = EESMREmailCommand;
       
   354                 }
       
   355                 break;
       
   356             default:
       
   357                 break;
       
   358             }
       
   359         }
       
   360 
       
   361     if ( !iUILauncher &&
       
   362          EESMREmailCommand == iCurrentCbCommand )
       
   363         {
       
   364         iResult.iAttendeeStatus =
       
   365                 ESMRIcalViewerUtils::UserResponsedToMRL(
       
   366                         *iInputParameters.iCalEntry );
       
   367         Observer()->OperationCompleted( iResult );
       
   368         }
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CESMRIcalViewerOpenMRCmd::HandleError
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CESMRIcalViewerOpenMRCmd::HandleError( TInt aError )
       
   376     {
       
   377     FUNC_LOG;
       
   378     if ( KErrNone != aError )
       
   379         {
       
   380         iResult.iResultCode = aError;
       
   381         Observer()->OperationError( iResult );
       
   382         }
       
   383     }
       
   384 
       
   385 // ---------------------------------------------------------------------------
       
   386 // CESMRIcalViewerOpenMRCmd::LaunchUIL
       
   387 // ---------------------------------------------------------------------------
       
   388 //
       
   389 void CESMRIcalViewerOpenMRCmd::LaunchUIL()
       
   390     {
       
   391     FUNC_LOG;
       
   392     if ( !iUILauncher )
       
   393         {
       
   394         iUILauncher = CESMRUiLauncher::NewL(
       
   395                             CalSession(),
       
   396                             iInputParameters,
       
   397                             *this );
       
   398         }
       
   399 
       
   400     iUILauncher->ExecuteCommandL( *Message(), *this );
       
   401     }
       
   402 
       
   403 // EOF
       
   404