utilities/downloadmanager/inc/clientdownload.h
changeset 16 3c88a81ff781
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
       
     1 /**
       
     2    This file is part of CWRT package **
       
     3 
       
     4    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). **
       
     5 
       
     6    This program is free software: you can redistribute it and/or modify
       
     7    it under the terms of the GNU (Lesser) General Public License as 
       
     8    published by the Free Software Foundation, version 2.1 of the License. 
       
     9    This program is distributed in the hope that it will be useful, but
       
    10    WITHOUT ANY WARRANTY; without even the implied warranty of 
       
    11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
       
    12    (Lesser) General Public License for more details. You should have 
       
    13    received a copy of the GNU (Lesser) General Public License along 
       
    14    with this program. If not, see <http://www.gnu.org/licenses/>.
       
    15 */
       
    16 
       
    17 #ifndef CLIENTDOWNLOAD_H
       
    18 #define CLIENTDOWNLOAD_H
       
    19 
       
    20 #include "dmcommon.h"
       
    21 #include "dmpimpl.h"
       
    22 #include "downloadevent.h"
       
    23 #include "download.h"
       
    24 #include <QObject>
       
    25 
       
    26 class DownloadManager;
       
    27 class QNetworkReply;
       
    28 class DownloadInfo;
       
    29 class ClientDownloadPrivate;
       
    30 
       
    31 typedef QList<QObject*> EventReceiverList; 
       
    32 
       
    33 // class declaration
       
    34 class ClientDownload : public Download
       
    35 {
       
    36     Q_OBJECT
       
    37     DM_DECLARE_PRIVATE(ClientDownload);
       
    38 public:
       
    39     // client download constructor
       
    40     // note that parentdlId is applicable in parent-child relationship where
       
    41     // parent download can be oma download and childs can be media downloads
       
    42     ClientDownload(DownloadManager *mgr, const QString& url
       
    43                                        , int dlId 
       
    44                                        , DownloadType type = Parallel
       
    45                                        , int parentdlId =INVALID_DL_ID); 
       
    46     ClientDownload(DownloadManager *mgr, QNetworkReply *reply
       
    47                                        ,int dlId
       
    48                                        , int parentdlId =INVALID_DL_ID); 
       
    49     ClientDownload(DownloadManager *mgr, int dlId, int parentdlId = INVALID_DL_ID); 
       
    50     ~ClientDownload();
       
    51 
       
    52     // starts the download
       
    53     int start();
       
    54     // id of the download
       
    55     int id();
       
    56     // sets the attributes for the download
       
    57     int setAttribute(DownloadAttribute attr, const QVariant& value);
       
    58     // fetches the attributes of download
       
    59     QVariant getAttribute(DownloadAttribute attr);
       
    60     // pauses the download
       
    61     int pause();
       
    62     // resumes the download
       
    63     int resume();
       
    64     // cancels the download
       
    65     int cancel();
       
    66     // registers the event listener
       
    67     void registerEventReceiver(QObject *receiver);
       
    68     // unregisters the event listener
       
    69     void unregisterEventReceiver(QObject *receiver);
       
    70     // returns the download manager
       
    71     DownloadManager *downloadManager();
       
    72     // returns the list of child downloads
       
    73     void getChildren(QList<Download*>& list);
       
    74     // to indicate download is created by perstistant stored info
       
    75     bool isCreatedByDlInfo(void);
       
    76    
       
    77 private:
       
    78     // returns the event listeners
       
    79     EventReceiverList& eventReceivers();
       
    80     // returns the download info
       
    81     DownloadInfo* downloadInfo();
       
    82     // posts the event to recievers event loop
       
    83     void postEvent(DEventType type, DlEventAttributeMap* attrMap);
       
    84     // sets the error string
       
    85     void setError(const QString& errorStr);
       
    86     //sets the download state
       
    87     void setDownloadState(DownloadState state);
       
    88     // sets the id of the parent download
       
    89     void setParentId(int parentId);
       
    90     // parent id
       
    91     int parentId();
       
    92     // returns the attribute map
       
    93     // note that these attributes are the only once which are 'set'able by clients
       
    94     QMap<DownloadAttribute, QVariant>& attributes(void);
       
    95     // actually starts the download
       
    96     int startDownload();
       
    97     // actually pauses the download
       
    98     int pauseDownload();
       
    99     // actually resumes the download
       
   100     int resumeDownload();
       
   101     // actually cancels the download
       
   102     int cancelDownload();
       
   103 
       
   104 private slots:
       
   105     // creates the concrete download implementation based on content type
       
   106     void createDownloadImplementation();
       
   107 
       
   108     friend class DownloadBackend; 
       
   109     friend class OMADownloadBackend;
       
   110     friend class HttpDownloadBackend;
       
   111     friend class OMA2DownloadBackend;
       
   112 #if defined(RD_WMDRM_DLA_ENABLERS) && defined(Q_OS_SYMBIAN)
       
   113     friend class WMDRMDownloadBackend;
       
   114 #endif
       
   115     friend class FileStorage;
       
   116     friend class DrmStorage;
       
   117     friend class SequentialDownloadManager;
       
   118     friend class ParallelDownloadManager;
       
   119 };
       
   120 
       
   121 #endif