| 1 |
/* This file is part of the KDE project. |
| 2 |
|
| 3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
|
| 5 |
This library is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
| 7 |
the Free Software Foundation, either version 2.1 or 3 of the License. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef PHONON_MMF_DOWNLOAD_H |
| 20 |
#define PHONON_MMF_DOWNLOAD_H |
| 21 |
|
| 22 |
#include <QtCore/QMetaType> |
| 23 |
#include <QtCore/QString> |
| 24 |
#include <QtCore/QUrl> |
| 25 |
#include <downloadmgrclient.h> |
| 26 |
|
| 27 |
QT_FORWARD_DECLARE_CLASS(QByteArray) |
| 28 |
QT_FORWARD_DECLARE_CLASS(QFile) |
| 29 |
|
| 30 |
QT_BEGIN_NAMESPACE |
| 31 |
|
| 32 |
namespace Phonon |
| 33 |
{ |
| 34 |
namespace MMF |
| 35 |
{ |
| 36 |
|
| 37 |
class Download; |
| 38 |
|
| 39 |
class DownloadPrivate : public QObject |
| 40 |
, public MHttpDownloadMgrObserver |
| 41 |
{ |
| 42 |
Q_OBJECT |
| 43 |
public: |
| 44 |
DownloadPrivate(Download *parent); |
| 45 |
~DownloadPrivate(); |
| 46 |
bool start(int iap); |
| 47 |
void resume(); |
| 48 |
signals: |
| 49 |
void error(); |
| 50 |
void targetFileNameChanged(); |
| 51 |
void lengthChanged(qint64 length); |
| 52 |
void complete(); |
| 53 |
private: |
| 54 |
// MHttpDownloadMgrObserver |
| 55 |
void HandleDMgrEventL(RHttpDownload &aDownload, THttpDownloadEvent aEvent); |
| 56 |
private: |
| 57 |
Download *m_parent; |
| 58 |
RHttpDownloadMgr m_downloadManager; |
| 59 |
RHttpDownload *m_download; |
| 60 |
qint64 m_length; |
| 61 |
}; |
| 62 |
|
| 63 |
class Download : public QObject |
| 64 |
{ |
| 65 |
Q_OBJECT |
| 66 |
friend class DownloadPrivate; |
| 67 |
public: |
| 68 |
Download(const QUrl &url, QObject *parent = 0); |
| 69 |
~Download(); |
| 70 |
const QUrl &sourceUrl() const; |
| 71 |
const QString &targetFileName() const; |
| 72 |
void start(int iap); |
| 73 |
void resume(); |
| 74 |
|
| 75 |
enum State { |
| 76 |
Idle, |
| 77 |
Initializing, |
| 78 |
Downloading, |
| 79 |
Complete, |
| 80 |
Error |
| 81 |
}; |
| 82 |
|
| 83 |
signals: |
| 84 |
void lengthChanged(qint64 length); |
| 85 |
void stateChanged(Download::State state); |
| 86 |
|
| 87 |
private: |
| 88 |
void setState(State state); |
| 89 |
|
| 90 |
// Called by DownloadPrivate |
| 91 |
void error(); |
| 92 |
void downloadStarted(const QString &targetFileName); |
| 93 |
void complete(); |
| 94 |
|
| 95 |
private: |
| 96 |
DownloadPrivate *m_private; |
| 97 |
QUrl m_sourceUrl; |
| 98 |
QString m_targetFileName; |
| 99 |
State m_state; |
| 100 |
}; |
| 101 |
|
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
QT_END_NAMESPACE |
| 106 |
|
| 107 |
Q_DECLARE_METATYPE(Phonon::MMF::Download::State) |
| 108 |
|
| 109 |
#endif |