emailuis/nmailui/src/nmviewerviewnetmanager.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 27 May 2010 12:43:55 +0300
changeset 27 9ba4404ef423
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
permissions -rw-r--r--
Revision: 201019 Kit: 2010121

/*
* 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()
    : QNetworkAccessManager(),
      mMessageView(NULL)
{
}

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

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

/*!
    createRequest
*/
QNetworkReply *NmViewerViewNetManager::createRequest(
    Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
    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) {
        NmViewerViewNetReply* reply = new NmViewerViewNetReply(
            mMessageView->webView()->loadResource(QTextDocument::ImageResource, requestUrl));
        reply->setOriginalRequest(myRequest);
        return reply;
        }
    // If request is not for embedded image, forward to base class
    return QNetworkAccessManager::createRequest(op, myRequest, outgoingData);
}