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