meetingrequest/mrgui/mrfieldbuilderplugin/src/cmrsaveandopenattachmentcommand.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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 <npdapi.h>
       
    26 #include <aknnotewrappers.h>
       
    27 #include <stringloader.h>
       
    28 
       
    29 // DEBUG
       
    30 #include "emailtrace.h"
       
    31 
       
    32 
       
    33 namespace { // codescanner::namespace
       
    34 
       
    35 // Notepad data type
       
    36 _LIT8( KNotePadTextDataType, "text/plain" );
       
    37 
       
    38 }
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand(
       
    47         CDocumentHandler& aDocHandler )
       
    48     : CMRAttachmentCommand(),
       
    49       iDocHandler( aDocHandler )
       
    50     {
       
    51     FUNC_LOG;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CMRSaveAndOpenAttachmentCommand::CMRSaveAndOpenAttachmentCommand
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CMRSaveAndOpenAttachmentCommand::~CMRSaveAndOpenAttachmentCommand()
       
    59     {
       
    60     FUNC_LOG;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CMRSaveAndOpenAttachmentCommand::NewL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CMRSaveAndOpenAttachmentCommand* CMRSaveAndOpenAttachmentCommand::NewL(
       
    68         CDocumentHandler& aDocHandler )
       
    69     {
       
    70     FUNC_LOG;
       
    71 
       
    72     CMRSaveAndOpenAttachmentCommand* self =
       
    73             new( ELeave )CMRSaveAndOpenAttachmentCommand( aDocHandler );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CMRSaveAndOpenAttachmentCommand::ConstructL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CMRSaveAndOpenAttachmentCommand::ConstructL()
       
    85     {
       
    86     FUNC_LOG;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CMRSaveAndOpenAttachmentCommand::ExecuteAttachmentCommandL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CMRSaveAndOpenAttachmentCommand::ExecuteAttachmentCommandL(
       
    94             CCalEntry& aEntry,
       
    95             TInt aAttachmentIndex )
       
    96     {
       
    97     FUNC_LOG;
       
    98 
       
    99     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   100     ASSERT( coeEnv );
       
   101 
       
   102     TDataType type;
       
   103 
       
   104     // Ownership not gained
       
   105     CCalAttachmentFile* attachmentFile =
       
   106        aEntry.AttachmentL( aAttachmentIndex )->FileAttachment();
       
   107 
       
   108     RFile file;
       
   109     attachmentFile->FetchFileHandleL( file );
       
   110     CleanupClosePushL( file );
       
   111 
       
   112     TFileName fileName;
       
   113     file.FullName( fileName );
       
   114 
       
   115     // Document handler takes care of the saving process. Return value does
       
   116     // not require any action
       
   117     iDocHandler.CopyL( file, fileName, type, NULL );
       
   118 
       
   119     TFileName copiedFileName;
       
   120     iDocHandler.GetPath(copiedFileName);
       
   121 
       
   122     RFs& fsSession = coeEnv->FsSession();
       
   123     User::LeaveIfError( fsSession.ShareProtected() );
       
   124 
       
   125     RFile copiedFile;
       
   126     TInt err = copiedFile.Open(
       
   127                     fsSession,
       
   128                     copiedFileName,
       
   129                     EFileRead | EFileShareReadersOnly);
       
   130     User::LeaveIfError( err );
       
   131 
       
   132     CleanupClosePushL( copiedFile );
       
   133 
       
   134     TDataType datatype(
       
   135             aEntry.AttachmentL( aAttachmentIndex )->MimeType() );
       
   136 
       
   137     if( datatype == KNotePadTextDataType() )
       
   138         {
       
   139         // Notepad will try to open text/plain type data
       
   140         err = CNotepadApi::ExecFileViewerL(
       
   141                 copiedFile,
       
   142                 NULL,
       
   143                ETrue,
       
   144                EFalse,
       
   145                KCharacterSetIdentifierIso88591 );
       
   146         }
       
   147     else
       
   148         {
       
   149         // Doc handler will try to open other than text files
       
   150         TRAP( err, iDocHandler.OpenFileEmbeddedL( copiedFile, datatype ) );
       
   151         }
       
   152 
       
   153     CleanupStack::PopAndDestroy( &copiedFile );
       
   154     CleanupStack::PopAndDestroy( &file );
       
   155 
       
   156     if( err != KErrNone )
       
   157         {
       
   158         CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   159         CleanupStack::PushL( note );
       
   160         HBufC* buf = StringLoader::LoadLC(
       
   161                 R_MEET_REQ_INFO_CANNOT_OPEN_ATTACHMENT );
       
   162         note->ExecuteLD( *buf );
       
   163         CleanupStack::PopAndDestroy( buf );
       
   164         CleanupStack::Pop( note );
       
   165         }
       
   166     }
       
   167 
       
   168 // EOF