meetingrequest/mrgui/mrfieldbuilderplugin/src/cmropenattachmentcommand.cpp
branchRCL_3
changeset 16 4ce476e64c59
child 24 b5fbb9b25d57
equal deleted inserted replaced
13:0396474f30f5 16: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 attahcment field implementation
       
    15  *
       
    16  */
       
    17 #include "cmropenattachmentcommand.h"
       
    18 
       
    19 #include <calentry.h>
       
    20 #include <calattachment.h>
       
    21 #include <f32file.h>
       
    22 #include <esmrgui.rsg>
       
    23 #include <npdapi.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <stringloader.h>
       
    26 #include <documenthandler.h>
       
    27 
       
    28 // DEBUG
       
    29 #include "emailtrace.h"
       
    30 
       
    31 // Unnamed namespace for local definitions
       
    32 namespace { // codescanner::namespace
       
    33 
       
    34 // Notepad data type
       
    35 _LIT8( KNotePadTextDataType, "text/plain" );
       
    36 
       
    37 }
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CMROpenAttachmentCommand::CMROpenAttachmentCommand
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CMROpenAttachmentCommand::CMROpenAttachmentCommand(
       
    46         CDocumentHandler& aDocHandler )
       
    47     : iDocHandler( aDocHandler )
       
    48     {
       
    49     FUNC_LOG;
       
    50     }
       
    51     
       
    52 // ---------------------------------------------------------------------------
       
    53 // CMROpenAttachmentCommand::CMROpenAttachmentCommand
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CMROpenAttachmentCommand::~CMROpenAttachmentCommand()
       
    57     {
       
    58     FUNC_LOG;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CMROpenAttachmentCommand::NewL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CMROpenAttachmentCommand* CMROpenAttachmentCommand::NewL(
       
    66         CDocumentHandler& aDocHandler )
       
    67     {
       
    68     FUNC_LOG;
       
    69     
       
    70     CMROpenAttachmentCommand* self =
       
    71             new (ELeave) CMROpenAttachmentCommand( aDocHandler );
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop( self );
       
    75     return self;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CMROpenAttachmentCommand::ConstructL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CMROpenAttachmentCommand::ConstructL()
       
    83     {
       
    84     FUNC_LOG;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CMROpenAttachmentCommand::ExecuteAttachmentCommandL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CMROpenAttachmentCommand::ExecuteAttachmentCommandL(
       
    92             CCalEntry& aEntry,
       
    93             TInt aAttachmentIndex )
       
    94     {
       
    95     FUNC_LOG;
       
    96     
       
    97     // Ownership not gained
       
    98     CCalAttachmentFile* attachmentFile =
       
    99             aEntry.AttachmentL( aAttachmentIndex )->FileAttachment(); 
       
   100 
       
   101     RFile file;
       
   102     attachmentFile->FetchFileHandleL( file );
       
   103     CleanupClosePushL( file );
       
   104     
       
   105     TDataType datatype( 
       
   106             aEntry.AttachmentL( aAttachmentIndex )->MimeType() );
       
   107     
       
   108     TInt err( KErrNone );
       
   109     if( datatype == KNotePadTextDataType() )
       
   110         {
       
   111         // Notepad will try to open text/plain type data
       
   112         err = CNotepadApi::ExecFileViewerL( 
       
   113                 file,
       
   114                 NULL,
       
   115                ETrue,
       
   116                EFalse,
       
   117                KCharacterSetIdentifierIso88591 );
       
   118         }
       
   119     else
       
   120         {
       
   121         // Doc handler will try to open other than text files
       
   122         TRAP( err, iDocHandler.OpenFileEmbeddedL( file, datatype ) );
       
   123         }
       
   124     
       
   125     CleanupStack::PopAndDestroy( &file );
       
   126 
       
   127     if( err != KErrNone )
       
   128         {
       
   129         CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
   130         CleanupStack::PushL( note );
       
   131         HBufC* buf = StringLoader::LoadLC(
       
   132                 R_MEET_REQ_INFO_CANNOT_OPEN_ATTACHMENT );
       
   133         note->ExecuteLD( *buf );
       
   134         CleanupStack::PopAndDestroy( buf );
       
   135         CleanupStack::Pop( note );
       
   136         }
       
   137     }
       
   138 
       
   139 // EOF