utilities/downloadmanager/inc/downloadcore.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 DOWNLOAD_CORE_H_
       
    18 #define DOWNLOAD_CORE_H_
       
    19 
       
    20 #include <QObject>
       
    21 #include <QNetworkReply>
       
    22 #include "dmpimpl.h"
       
    23 
       
    24 // forward declarations
       
    25 class QNetworkAccessManager;
       
    26 class DownloadCorePrivate; 
       
    27 class QNetworkProxy;
       
    28 
       
    29 // class declaration
       
    30 class  DownloadCore : public QObject
       
    31 {
       
    32     Q_OBJECT
       
    33     DM_DECLARE_PRIVATE(DownloadCore); // private implementation
       
    34 
       
    35 public:
       
    36     // to start new download transaction
       
    37     DownloadCore(const QString &aUrl);
       
    38     // to carry forward the downloads transaction which has been started already
       
    39     DownloadCore(QNetworkReply *reply);
       
    40     virtual ~DownloadCore();
       
    41 private:
       
    42     // default constructor made private to enforce creation of object only 
       
    43     // by passing url or network reply
       
    44     DownloadCore(void){};
       
    45 
       
    46 signals:
       
    47     void finished(void);
       
    48     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
       
    49     void metaDataChanged(); 
       
    50     void error(QNetworkReply::NetworkError code);
       
    51     void uploadProgress( qint64 bytesSent, qint64 bytesTotal );
       
    52 
       
    53 private slots:
       
    54     void parseHeaders(void);
       
    55 
       
    56 private: // copy constructor and assaignment operator
       
    57       DownloadCore(const DownloadCore &);
       
    58       DownloadCore &operator=(const DownloadCore &);
       
    59     
       
    60 public:
       
    61     // starts the new download transaction if it is not started already addition with
       
    62     // all necessary initialisarion or does initialisation if the transaction has been already started
       
    63     int doDownload(void);
       
    64     // for http "post" requests
       
    65     int post(const QString& url, const QByteArray& data);
       
    66     // pauses the download transaction
       
    67     int resumeDownload(qint64 startOffeset);
       
    68     // aborts the network transaction
       
    69     int abort(void);
       
    70     // sets the proxy
       
    71     void setProxy(QNetworkProxy *proxy);
       
    72     // returnts the url
       
    73     QString& url(void);
       
    74     // start download from given url
       
    75     void changeUrl(QString& url);
       
    76     // returns the network reply
       
    77     QNetworkReply* reply(void);
       
    78     // returns the network access manager
       
    79     QNetworkAccessManager* networkAccessManager(void);
       
    80     // returns the content type
       
    81     QString& contentType(void);
       
    82     // returns the content type
       
    83     QString& entityTag(void);
       
    84     // returns the total size
       
    85     qint64 sizeInHeader(void);
       
    86     // returns the last error occurred
       
    87     QNetworkReply::NetworkError lastError(void);
       
    88     // returns the last error string
       
    89     QString lastErrorString();
       
    90     // returns proxy
       
    91     QNetworkProxy* proxy();
       
    92     // returns file name from content disposition header
       
    93     QString fileNameFromContentDispositionHeader();
       
    94 
       
    95     // the following funtions used in the cases where 
       
    96     // download has loaded from persistant state. Careful 
       
    97     // while usig the following functions in normal cases
       
    98     void setContentType(const QString& contentType);
       
    99     void setEntityTag(const QString& entityTag);
       
   100     // the folowing setLastError and setLastErrorString should be used
       
   101     // together to keep the consistancy between error code and error string
       
   102     void setLastError(QNetworkReply::NetworkError code);
       
   103     void setLastErrorString(const QString& errStr); 
       
   104 };
       
   105 
       
   106 #endif /*DOWNLOAD_CORE_H_*/