meetingrequest/mrgui/mrfieldbuilderplugin/src/cmrsaveandopenattachmentcommand.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 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:  MR save and open attachment command implementation
       
    15  *
       
    16  */
       
    17 #include "cmrsaveandopenattachmentcommand.h"
       
    18 
       
    19 #include <calentry.h>
       
    20 #include <calattachment.h>
       
    21 #include <f32file.h>
       
    22 #include <DocumentHandler.h>
       
    23 #include <coemain.h>
       
    24 #include <esmrgui.rsg>
       
    25 #include <aknnotewrappers.h>
       
    26 #include <StringLoader.h>
       
    27 
       
    28 // DEBUG
       
    29 #include "emailtrace.h"
       
    30 
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand(
       
    39         CDocumentHandler& aDocHandler )
       
    40     : CMRAttachmentCommand(),
       
    41       iDocHandler( aDocHandler )
       
    42     {
       
    43     FUNC_LOG;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CMRSaveAndOpenAttachmentCommand::~CMRSaveAndOpenAttachmentCommand()
       
    51     {
       
    52     FUNC_LOG;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CMRSaveAndOpenAttachmentCommand::NewL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CMRSaveAndOpenAttachmentCommand* CMRSaveAndOpenAttachmentCommand::NewL(
       
    60         CDocumentHandler& aDocHandler )
       
    61     {
       
    62     FUNC_LOG;
       
    63 
       
    64     CMRSaveAndOpenAttachmentCommand* self =
       
    65             new( ELeave )CMRSaveAndOpenAttachmentCommand( aDocHandler );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CMRSaveAndOpenAttachmentCommand::ConstructL
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CMRSaveAndOpenAttachmentCommand::ConstructL()
       
    77     {
       
    78     FUNC_LOG;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CMRSaveAndOpenAttachmentCommand::ExecuteAttachmentCommandL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CMRSaveAndOpenAttachmentCommand::ExecuteAttachmentCommandL(
       
    86             CCalEntry& aEntry,
       
    87             TInt aAttachmentIndex )
       
    88     {
       
    89     FUNC_LOG;
       
    90 
       
    91     CCoeEnv* coeEnv = CCoeEnv::Static();
       
    92     ASSERT( coeEnv );
       
    93 
       
    94     TDataType type;
       
    95 
       
    96     // Ownership not gained
       
    97     CCalAttachmentFile* attachmentFile =
       
    98        aEntry.AttachmentL( aAttachmentIndex )->FileAttachment();
       
    99 
       
   100     RFile file;
       
   101     attachmentFile->FetchFileHandleL( file );
       
   102     CleanupClosePushL( file );
       
   103 
       
   104     TFileName fileName;
       
   105     file.FullName( fileName );
       
   106 
       
   107     // Document handler takes care of the saving process. Return value does
       
   108     // not require any action
       
   109     iDocHandler.CopyL( file, fileName, type, NULL );
       
   110 
       
   111     TFileName copiedFileName;
       
   112     iDocHandler.GetPath(copiedFileName);
       
   113 
       
   114     RFs& fsSession = coeEnv->FsSession();
       
   115     User::LeaveIfError( fsSession.ShareProtected() );
       
   116 
       
   117     RFile copiedFile;
       
   118     TInt err = copiedFile.Open(
       
   119                     fsSession,
       
   120                     copiedFileName,
       
   121                     EFileRead | EFileShareReadersOnly);
       
   122     User::LeaveIfError( err );
       
   123 
       
   124     CleanupClosePushL( copiedFile );
       
   125 
       
   126     TDataType datatype(
       
   127             aEntry.AttachmentL( aAttachmentIndex )->MimeType() );
       
   128 
       
   129     // Doc handler will try to open file
       
   130     TRAP( err, iDocHandler.OpenFileEmbeddedL( copiedFile, datatype ) );
       
   131 
       
   132     CleanupStack::PopAndDestroy( &copiedFile );
       
   133     CleanupStack::PopAndDestroy( &file );
       
   134 
       
   135     if( err != KErrNone )
       
   136         {
       
   137         CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   138         CleanupStack::PushL( note );
       
   139         HBufC* buf = StringLoader::LoadLC(
       
   140                 R_MEET_REQ_INFO_CANNOT_OPEN_ATTACHMENT );
       
   141         note->ExecuteLD( *buf );
       
   142         CleanupStack::PopAndDestroy( buf );
       
   143         CleanupStack::Pop( note );
       
   144         }
       
   145     }
       
   146 
       
   147 // EOF