utilities/downloadmanager/src/downloadfactory.cpp
author hgs
Fri, 15 Oct 2010 17:30:59 -0400
changeset 16 3c88a81ff781
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
hgs
parents:
diff changeset
     1
/**
hgs
parents:
diff changeset
     2
   This file is part of CWRT package **
hgs
parents:
diff changeset
     3
hgs
parents:
diff changeset
     4
   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). **
hgs
parents:
diff changeset
     5
hgs
parents:
diff changeset
     6
   This program is free software: you can redistribute it and/or modify
hgs
parents:
diff changeset
     7
   it under the terms of the GNU (Lesser) General Public License as 
hgs
parents:
diff changeset
     8
   published by the Free Software Foundation, version 2.1 of the License. 
hgs
parents:
diff changeset
     9
   This program is distributed in the hope that it will be useful, but
hgs
parents:
diff changeset
    10
   WITHOUT ANY WARRANTY; without even the implied warranty of 
hgs
parents:
diff changeset
    11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
hgs
parents:
diff changeset
    12
   (Lesser) General Public License for more details. You should have 
hgs
parents:
diff changeset
    13
   received a copy of the GNU (Lesser) General Public License along 
hgs
parents:
diff changeset
    14
   with this program. If not, see <http://www.gnu.org/licenses/>.
hgs
parents:
diff changeset
    15
*/
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
#include "downloadmanager.h"
hgs
parents:
diff changeset
    18
#include "downloadfactory.h"
hgs
parents:
diff changeset
    19
#include "clientdownload.h"
hgs
parents:
diff changeset
    20
#include "downloadcore.h"
hgs
parents:
diff changeset
    21
#include "downloadstore.h"
hgs
parents:
diff changeset
    22
#include "filestorage.h"
hgs
parents:
diff changeset
    23
#include "downloadbackend.h"
hgs
parents:
diff changeset
    24
#include "httpdownloadbackend.h"
hgs
parents:
diff changeset
    25
#include "omadownloadbackend.h"
hgs
parents:
diff changeset
    26
#include "oma2downloadbackend.h"
hgs
parents:
diff changeset
    27
#include <QNetworkReply>
hgs
parents:
diff changeset
    28
#include <QNetworkRequest>
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
#ifdef __SYMBIAN32__
hgs
parents:
diff changeset
    31
#include <bldvariant.hrh>
hgs
parents:
diff changeset
    32
#include "drmstorage.h"
hgs
parents:
diff changeset
    33
#ifdef RD_WMDRM_DLA_ENABLERS
hgs
parents:
diff changeset
    34
#include "wmdrmdownloadbackend.h"
hgs
parents:
diff changeset
    35
#endif
hgs
parents:
diff changeset
    36
#endif
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// This is responsible for creation of concrete download download implementation class
hgs
parents:
diff changeset
    39
// based on the content type
hgs
parents:
diff changeset
    40
DownloadBackend* DownloadAbstractFactory::createDownloadImplementation(DownloadCore *dlCore, ClientDownload *dl)
hgs
parents:
diff changeset
    41
{
hgs
parents:
diff changeset
    42
    QString contentType = dlCore->contentType();
hgs
parents:
diff changeset
    43
    if(contentType == "")
hgs
parents:
diff changeset
    44
    {
hgs
parents:
diff changeset
    45
        QNetworkReply *reply = dlCore->reply();
hgs
parents:
diff changeset
    46
        if(reply)
hgs
parents:
diff changeset
    47
        {
hgs
parents:
diff changeset
    48
            contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
hgs
parents:
diff changeset
    49
        }
hgs
parents:
diff changeset
    50
    }
hgs
parents:
diff changeset
    51
    
hgs
parents:
diff changeset
    52
    QString clientName = dl->downloadManager()->getAttribute(DlMgrClientName).toString();
hgs
parents:
diff changeset
    53
    DownloadBackend *dlBackend = NULL;
hgs
parents:
diff changeset
    54
    DownloadStore* store = NULL;
hgs
parents:
diff changeset
    55
    if(contentType == OMA_CONTENT_TYPE) {
hgs
parents:
diff changeset
    56
        dlBackend = new OMADownloadBackend(dlCore, dl);
hgs
parents:
diff changeset
    57
    }
hgs
parents:
diff changeset
    58
    else if(contentType == OMA2_CONTENT_TYPE) {
hgs
parents:
diff changeset
    59
        dlBackend = new OMA2DownloadBackend(dlCore, dl);
hgs
parents:
diff changeset
    60
    }
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
#ifdef __SYMBIAN32__
hgs
parents:
diff changeset
    63
    else if(contentType == OMA_DRM_MESSAGE_CONTENT_TYPE) {
hgs
parents:
diff changeset
    64
        store = new DrmStorage(clientName, dl);
hgs
parents:
diff changeset
    65
        dlBackend = new HttpDownloadBackend(dlCore, dl, store);
hgs
parents:
diff changeset
    66
    }
hgs
parents:
diff changeset
    67
#ifdef RD_WMDRM_DLA_ENABLERS
hgs
parents:
diff changeset
    68
    else if(contentType.contains(WMDRM_CONTENT_TYPE, Qt::CaseInsensitive))
hgs
parents:
diff changeset
    69
        dlBackend = new WMDRMDownloadBackend(dlCore, dl);
hgs
parents:
diff changeset
    70
#endif
hgs
parents:
diff changeset
    71
#endif
hgs
parents:
diff changeset
    72
    //we can have other if-else cases for different type of downloads
hgs
parents:
diff changeset
    73
    // by default the download is http download
hgs
parents:
diff changeset
    74
    else {
hgs
parents:
diff changeset
    75
        store = new FileStorage(clientName, dl);
hgs
parents:
diff changeset
    76
        dlBackend = new HttpDownloadBackend(dlCore, dl, store);
hgs
parents:
diff changeset
    77
    }
hgs
parents:
diff changeset
    78
    return dlBackend;
hgs
parents:
diff changeset
    79
}
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83