emailuis/nmailui/src/nmviewerviewnetmanager.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 13:27:14 +0300
changeset 30 759dc5235cdb
parent 23 2dc6caa42ec3
child 47 f83bd4ae1fe3
child 54 997a02608b3a
permissions -rw-r--r--
Revision: 201021 Kit: 2010123

/*
* 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:
*
*/

#include "nmuiheaders.h"

static const QString NmViewerViewNetManagerScheme("cid");

/*!
	\class NmViewerViewNetManager
	\brief Mail viewer network access manager class
*/


/*!
    Constructor
*/
NmViewerViewNetManager::NmViewerViewNetManager(NmUiEngine &uiEngine)
    : QNetworkAccessManager(),
      mUiEngine(uiEngine),
      mMessageView(NULL)
{
    NM_FUNCTION;
}

/*!
    Destructor
*/
NmViewerViewNetManager::~NmViewerViewNetManager()
{
    NM_FUNCTION;
}

/*!
    Setter for view.
*/
void NmViewerViewNetManager::setView(NmViewerView *viewerView)
{
    NM_FUNCTION;
    
    mMessageView=viewerView;
}

/*!
    createRequest
*/
QNetworkReply *NmViewerViewNetManager::createRequest(
    Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
    NM_FUNCTION;
    
    QNetworkRequest myRequest(request);
    // Set request attribute to prefer cachevar  
    const QVariant cacheControl((int)QNetworkRequest::PreferCache);
    myRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, 
                         cacheControl);
    const QUrl requestUrl = myRequest.url();
    // Check whether request is for embedded image
    if (mMessageView&&mMessageView->webView()&&op==QNetworkAccessManager::GetOperation
        && requestUrl.scheme()==NmViewerViewNetManagerScheme) {
        QString id = requestUrl.path();
        NmId partId;
        bool isFetched = false;
        NmMessage *message = mMessageView->message();
        if (message) {
            QVariant data = mMessageView->webView()->loadResource(
                    QTextDocument::ImageResource, requestUrl, partId, isFetched);
            NmViewerViewNetReply* reply = NULL;
            if (isFetched) {
                reply = new NmViewerViewNetReply(data, mUiEngine);
            }
            else  {
                reply = new NmViewerViewNetReply(data, mUiEngine,
                        message->envelope().mailboxId(), message->envelope().folderId(),
                        message->envelope().messageId(), partId);
            }
            reply->setOriginalRequest(myRequest);
            return reply;
        }
    }
    // If request is not for embedded image, forward to base class
    return QNetworkAccessManager::createRequest(op, myRequest, outgoingData);
}