emailuis/nmframeworkadapter/src/nmfwamessagepartfetchingoperation.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 14:51:52 +0300
changeset 18 578830873419
child 20 ecc8def7944a
permissions -rw-r--r--
Revision: 201011 Kit: 201015

/*
 * Copyright (c) 2010 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:
 *
 */

#include "nmframeworkadapterheaders.h"

/*!

 */
NmFwaMessagePartFetchingOperation::NmFwaMessagePartFetchingOperation(
        const NmId &mailboxId,
        const NmId &folderId,
        const NmId &messageId,
        const NmId &messagePartId,
        CFSMailClient &mailClient,
        QObject *parent) : 
    NmOperation(parent),
    mMailboxId(mailboxId), 
    mFolderId(folderId), 
    mMessageId(messageId), 
    mMessagePartId(messagePartId),
    mMailClient(mailClient), 
    mLastProgressValue(0), 
    mRequestId(0)

{
    
}

/*!

 */
NmFwaMessagePartFetchingOperation::~NmFwaMessagePartFetchingOperation()
{
    doCancelOperation();
}

/*!

 */
void NmFwaMessagePartFetchingOperation::RequestResponseL(TFSProgress aEvent, TInt aRequestId)
{
    if (aRequestId == mRequestId) {
        if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete ) {
            completeOperation(aEvent.iError);
        }
        else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled) {
            // emit cancelled
            operationCancelled();
        }
        else if (aEvent.iProgressStatus == TFSProgress::EFSStatus_Status) {
            int progress = 0;
            if (aEvent.iMaxCount > 0) {
                // calculate progress per cents
                qreal counterValue = aEvent.iCounter;
                qreal maxCount = aEvent.iMaxCount;
                progress = (counterValue / maxCount)*100;
            }
            if (progress > mLastProgressValue) {
                // send only increasing values to prevent downward changing percentage
                mLastProgressValue = progress;
                updateOperationProgress(mLastProgressValue);
            }
        }
    }
}

/*!

 */
void NmFwaMessagePartFetchingOperation::runAsyncOperation()
{
    TRAPD(err, runAsyncOperationL());
    if (err != KErrNone) {
        completeOperation(NmGeneralError);
    }
}

/*!
    Leaving version from runAsyncOperation
 */
void NmFwaMessagePartFetchingOperation::runAsyncOperationL()
{
    const TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32());
    const TFSMailMsgId folderId(mFolderId.pluginId32(), mFolderId.id32());
    const TFSMailMsgId messageId(mMessageId.pluginId32(), mMessageId.id32());
    const TFSMailMsgId messagePartId(mMessagePartId.pluginId32(), mMessagePartId.id32());

    CFSMailMessage *message(NULL);
    message = mMailClient.GetMessageByUidL(mailboxId, folderId, messageId, EFSMsgDataEnvelope);
    CleanupStack::PushL(message);
   
    if (message) {
        CFSMailMessagePart* messagePart = message->ChildPartL( messagePartId );
        CleanupStack::PushL(messagePart);
        if (messagePart) {            
            mRequestId = messagePart->FetchMessagePartL(messagePartId, *this, 0);
        }
        else {
            completeOperation(NmNotFoundError);
        }
        CleanupStack::PopAndDestroy(messagePart);
    }
    else {
        completeOperation(NmNotFoundError);
    }
    CleanupStack::PopAndDestroy(message);
}

/*!

 */
void NmFwaMessagePartFetchingOperation::doCancelOperation()
{
    TRAP_IGNORE(mMailClient.CancelL(mRequestId));
}