downloadmanager.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef DOWNLOADMANAGER_H
  5. #define DOWNLOADMANAGER_H
  6. #include <QObject>
  7. #include <QtNetwork/QNetworkAccessManager>
  8. #include <QtNetwork/QNetworkSession>
  9. #include <QtScript>
  10. #include "request.h"
  11. // Forward declarations
  12. class QNetworkReply;
  13. class QUrl;
  14. class Product;
  15. class DownloadManager : public QObject
  16. {
  17. Q_OBJECT
  18. public:
  19. explicit DownloadManager(QObject *parent = 0);
  20. virtual ~DownloadManager();
  21. public:
  22. void requestProductsIds(const QUrl &url);
  23. void downloadSis(QString productId, QString purchaseTicket, const QUrl &url);
  24. Request *findRequestForReply(QNetworkReply *reply);
  25. void removeRequest(Request *request);
  26. public slots:
  27. void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  28. void downloadFinished(QNetworkReply *reply);
  29. void cancel();
  30. private:
  31. QString saveFileName(const QUrl &url);
  32. bool saveToDisk(const QString &filename, QIODevice *data);
  33. void processJsonReply(Request *request, QNetworkReply *reply);
  34. signals:
  35. void productIdsCompleted(QList<QObject*>);
  36. void downloadProgress(QString productId, qint64 bytesReceived, qint64 bytesTotal);
  37. void downloadCompleted(Request::RequestType type, QString productId, QString fileName, int error);
  38. private: // Data
  39. QNetworkAccessManager *m_manager; // Owned
  40. QNetworkSession *m_session; // Owned
  41. QScriptEngine *m_scriptEngine; // Owned
  42. QList<Request*> m_currentDownloads;
  43. };
  44. #endif // DOWNLOADMANAGER_H