meetingrequest/mrgui/mrfieldbuilderplugin/src/cmrsaveattachmentcommand.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 31 Mar 2010 21:08:33 +0300
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
permissions -rw-r--r--
Revision: 201011 Kit: 201013

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
 * Contributors:
 *
 * Description:  MR save attachment command implementation
 *
 */
#include "cmrsaveattachmentcommand.h"

#include <calentry.h>
#include <calattachment.h>
#include <f32file.h>
#include <documenthandler.h>
#include <coemain.h>
#include <esmrgui.rsg>
#include <npdapi.h>
#include <aknnotewrappers.h>
#include <stringloader.h>

// DEBUG
#include "emailtrace.h"


// ======== MEMBER FUNCTIONS ========

// ---------------------------------------------------------------------------
// CMRSaveAttachmentCommand::CMRSaveAttachmentCommand
// ---------------------------------------------------------------------------
//
CMRSaveAttachmentCommand::CMRSaveAttachmentCommand(
        CDocumentHandler& aDocHandler ) :
    CMRAttachmentCommand(),
    iDocHandler( aDocHandler )
    {
    FUNC_LOG;
    }

// ---------------------------------------------------------------------------
// CMRSaveAttachmentCommand::CMRSaveAttachmentCommand
// ---------------------------------------------------------------------------
//
CMRSaveAttachmentCommand::~CMRSaveAttachmentCommand()
    {
    FUNC_LOG;
    }

// ---------------------------------------------------------------------------
// CMRSaveAttachmentCommand::NewL
// ---------------------------------------------------------------------------
//
CMRSaveAttachmentCommand* CMRSaveAttachmentCommand::NewL(
        CDocumentHandler& aDocHandler )
    {
    FUNC_LOG;

    CMRSaveAttachmentCommand* self =
            new( ELeave )CMRSaveAttachmentCommand( aDocHandler );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------------------------
// CMRSaveAttachmentCommand::ConstructL
// ---------------------------------------------------------------------------
//
void CMRSaveAttachmentCommand::ConstructL()
    {
    FUNC_LOG;
    }

// ---------------------------------------------------------------------------
// CMRSaveAttachmentCommand::ExecuteAttachmentCommandL
// ---------------------------------------------------------------------------
//
void CMRSaveAttachmentCommand::ExecuteAttachmentCommandL(
            CCalEntry& aEntry,
            TInt aAttachmentIndex )
    {
    FUNC_LOG;

    CCalAttachmentFile* attachmentFile =
       aEntry.AttachmentL( aAttachmentIndex )->FileAttachment(); // Ownership not gained

    if ( attachmentFile ) // Ignore URI attachment
        {
        RFile file;
        attachmentFile->FetchFileHandleL( file );
        CleanupClosePushL( file );

        TFileName fileName;
        file.FullName( fileName );

        TDataType type;

        // Document handler takes care of the saving process.
        TInt res = iDocHandler.CopyL( file, fileName, type, NULL );

        if ( KUserCancel == res )
            {
            User::Leave( KErrCancel );
            }

        CleanupStack::PopAndDestroy( &file );
        }
    }

// EOF