QtFileDownloader.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This program 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 GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this program; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #ifndef QtFileDownloader_h
  21. #define QtFileDownloader_h
  22. #include <QNetworkReply>
  23. #include <QNetworkRequest>
  24. #include <wtf/OwnPtr.h>
  25. #include <wtf/PassOwnPtr.h>
  26. QT_BEGIN_NAMESPACE
  27. class QFile;
  28. class QNetworkAccessManager;
  29. class QNetworkRequest;
  30. QT_END_NAMESPACE
  31. namespace WebCore {
  32. class ResourceError;
  33. }
  34. namespace WebKit {
  35. class Download;
  36. class QtFileDownloader : public QObject {
  37. Q_OBJECT
  38. public:
  39. QtFileDownloader(Download*, PassOwnPtr<QNetworkReply>);
  40. virtual ~QtFileDownloader();
  41. void cancel();
  42. void init();
  43. void startTransfer(const QString& destination);
  44. enum DownloadError {
  45. DownloadErrorAborted = 0,
  46. DownloadErrorCannotWriteToFile,
  47. DownloadErrorCannotOpenFile,
  48. DownloadErrorDestinationAlreadyExists,
  49. DownloadErrorCancelled,
  50. DownloadErrorCannotDetermineFilename,
  51. DownloadErrorNetworkFailure
  52. };
  53. private Q_SLOTS:
  54. void onReadyRead();
  55. void onFinished();
  56. void onError(QNetworkReply::NetworkError);
  57. private:
  58. void abortDownloadWritingAndEmitError(QtFileDownloader::DownloadError);
  59. QString determineFilename();
  60. void handleDownloadResponse();
  61. Download* m_download;
  62. OwnPtr<QNetworkReply> m_reply;
  63. OwnPtr<QFile> m_destinationFile;
  64. QNetworkReply::NetworkError m_error;
  65. bool m_headersRead;
  66. };
  67. } // namespace WebKit
  68. #endif