utilities/downloadmanager/inc/downloadbackend.h
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
#ifndef DOWNLOADBACKEND_H
hgs
parents:
diff changeset
    18
#define DOWNLOADBACKEND_H
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include "dmpimpl.h"
hgs
parents:
diff changeset
    21
#include "downloadinfo.h"
hgs
parents:
diff changeset
    22
#include "downloadevent.h"
hgs
parents:
diff changeset
    23
#include <QObject>
hgs
parents:
diff changeset
    24
#include <QNetworkReply>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// forward declarations
hgs
parents:
diff changeset
    27
class DownloadBackendPrivate;
hgs
parents:
diff changeset
    28
class DownloadCore;
hgs
parents:
diff changeset
    29
class Download;
hgs
parents:
diff changeset
    30
class ClientDownload;
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
// class declaration
hgs
parents:
diff changeset
    33
class DownloadBackend : public QObject
hgs
parents:
diff changeset
    34
{
hgs
parents:
diff changeset
    35
    Q_OBJECT
hgs
parents:
diff changeset
    36
    DM_DECLARE_PRIVATE(DownloadBackend);
hgs
parents:
diff changeset
    37
public:
hgs
parents:
diff changeset
    38
    DownloadBackend(DownloadCore *dlCore, ClientDownload *dl);
hgs
parents:
diff changeset
    39
    virtual ~DownloadBackend();
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
    // pauses the download
hgs
parents:
diff changeset
    42
    virtual int pause() ;
hgs
parents:
diff changeset
    43
    // resumes the download
hgs
parents:
diff changeset
    44
    virtual int resume() ;
hgs
parents:
diff changeset
    45
    // cancels the download
hgs
parents:
diff changeset
    46
    virtual int cancel() ;
hgs
parents:
diff changeset
    47
    // fetches the attributes
hgs
parents:
diff changeset
    48
    virtual QVariant getAttribute(DownloadAttribute attr);
hgs
parents:
diff changeset
    49
    // sets the attributes
hgs
parents:
diff changeset
    50
    virtual int setAttribute(DownloadAttribute attr, const QVariant& value);
hgs
parents:
diff changeset
    51
    // stores the data in storage
hgs
parents:
diff changeset
    52
    // derived classes expected to have their own implementation
hgs
parents:
diff changeset
    53
    virtual void store(QByteArray data, bool lastChunk=false) = 0;
hgs
parents:
diff changeset
    54
    // deletes the storage
hgs
parents:
diff changeset
    55
    // derived classes expected to have their own implementation
hgs
parents:
diff changeset
    56
    virtual void deleteStore() = 0;
hgs
parents:
diff changeset
    57
    // returns the size of stored data
hgs
parents:
diff changeset
    58
    // derived classes expected to have their own implementation
hgs
parents:
diff changeset
    59
    virtual qint64 storedDataSize()= 0;
hgs
parents:
diff changeset
    60
    //returns the list of child downloads
hgs
parents:
diff changeset
    61
    virtual void getChildren(QList<Download*>&) { }
hgs
parents:
diff changeset
    62
    // initialises the download by reading from persistant storage
hgs
parents:
diff changeset
    63
    virtual void init() { return; }
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
private: // copy constructor and assaignment operator
hgs
parents:
diff changeset
    66
      DownloadBackend(const DownloadBackend &);
hgs
parents:
diff changeset
    67
      DownloadBackend &operator=(const DownloadBackend &);
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
public:
hgs
parents:
diff changeset
    70
    // functions which will store and retrieve the download persistant data
hgs
parents:
diff changeset
    71
    int setValue(DownloadInfo::Key aKey, const QString& aStrValue);
hgs
parents:
diff changeset
    72
    int setValue(DownloadInfo::Key aKey, long aIntValue);
hgs
parents:
diff changeset
    73
    int setValue(DownloadInfo::Key aKey, const QList<QVariant>& aChildIds);
hgs
parents:
diff changeset
    74
    int setValueForChild(DownloadInfo::Key aKey, const QString& aStrValue, int aChildId = INVALID_DL_ID);
hgs
parents:
diff changeset
    75
    int setValueForChild(DownloadInfo::Key aKey, long aIntValue, int aChildId = INVALID_DL_ID);
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
    int getValue(DownloadInfo::Key aKey, QString& aStrValue);
hgs
parents:
diff changeset
    78
    int getValue(DownloadInfo::Key aKey, long& aIntValue);
hgs
parents:
diff changeset
    79
    int getValue(DownloadInfo::Key aKey, QList<QVariant>& aChildIds);
hgs
parents:
diff changeset
    80
    int getValueForChild(DownloadInfo::Key aKey, QString& aStrValue, int aChildId = INVALID_DL_ID);
hgs
parents:
diff changeset
    81
    int getValueForChild(DownloadInfo::Key aKey, long& aIntValue, int aChildId = INVALID_DL_ID);
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
    // deletes the persistant data of download
hgs
parents:
diff changeset
    84
    int deleteInfo();
hgs
parents:
diff changeset
    85
    // posts the event to recievers event loop
hgs
parents:
diff changeset
    86
    void postEvent(DEventType type, DlEventAttributeMap* attrMap);
hgs
parents:
diff changeset
    87
    // download state
hgs
parents:
diff changeset
    88
    DownloadState downloadState(void);
hgs
parents:
diff changeset
    89
    // sets the download state
hgs
parents:
diff changeset
    90
    void setDownloadState(DownloadState state);
hgs
parents:
diff changeset
    91
    // sets the current downloaded data size
hgs
parents:
diff changeset
    92
    void setDownloadedDataSize(qint64 size);
hgs
parents:
diff changeset
    93
    // set total download size
hgs
parents:
diff changeset
    94
    void setTotalSize(qint64 size);
hgs
parents:
diff changeset
    95
    // returns the download object
hgs
parents:
diff changeset
    96
    ClientDownload* download(void);
hgs
parents:
diff changeset
    97
    // sets the start time
hgs
parents:
diff changeset
    98
    void setStartTime();
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
private:
hgs
parents:
diff changeset
   101
    void postDownloadEvent(DEventType type, DlEventAttributeMap* attrMap);
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
public slots:
hgs
parents:
diff changeset
   104
    virtual void bytesRecieved(qint64 bytesRecieved, qint64 bytesTotal);
hgs
parents:
diff changeset
   105
    virtual void handleFinished();
hgs
parents:
diff changeset
   106
    virtual void error(QNetworkReply::NetworkError);
hgs
parents:
diff changeset
   107
    virtual void headerReceived(){}
hgs
parents:
diff changeset
   108
    virtual void bytesUploaded(qint64, qint64){}
hgs
parents:
diff changeset
   109
};    
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
#endif