Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file_downloader.h 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. *
  3. * Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser.
  6. * It may not be distributed under any circumstances.
  7. *
  8. * Per Arne Vollan (pav)
  9. */
  10. #ifndef FILE_DOWNLOADER_H
  11. #define FILE_DOWNLOADER_H
  12. #ifdef AUTO_UPDATE_SUPPORT
  13. #include "modules/windowcommander/OpTransferManager.h"
  14. class FileDownloader;
  15. /**
  16. * Listener class for downloading files
  17. */
  18. class FileDownloadListener
  19. {
  20. public:
  21. virtual ~FileDownloadListener() {}
  22. /**
  23. * Called when file download is done
  24. */
  25. virtual void OnFileDownloadDone(FileDownloader* file_downloader, OpFileLength total_size) = 0;
  26. /**
  27. * Called when file download failed
  28. */
  29. virtual void OnFileDownloadFailed(FileDownloader* file_downloader) = 0;
  30. /**
  31. * Called when file download was aborted
  32. */
  33. virtual void OnFileDownloadAborted(FileDownloader* file_downloader) = 0;
  34. /**
  35. * Called when download progresses
  36. */
  37. virtual void OnFileDownloadProgress(FileDownloader* file_downloader, OpFileLength total_size, OpFileLength downloaded_size, double kbps, unsigned long time_estimate) = 0;
  38. };
  39. /**
  40. * Class for downloading files
  41. */
  42. class FileDownloader : public OpTransferListener, public MessageObject
  43. {
  44. public:
  45. FileDownloader();
  46. ~FileDownloader();
  47. void SetFileDownloadListener(FileDownloadListener* listener) { m_listener = listener; }
  48. OP_STATUS StartDownload(const OpStringC &url, const OpStringC &target_filename);
  49. OP_STATUS StopDownload();
  50. BOOL DownloadStarted() const { return m_download_started; }
  51. BOOL Downloaded() const;
  52. BOOL DownloadFailed() const;
  53. OP_STATUS GetTargetFilename(OpString &target_filename) { return target_filename.Set(m_file_name); }
  54. OpFileLength GetFileSize();
  55. OpFileLength GetHaveSize();
  56. protected:
  57. void CleanUp();
  58. OP_STATUS DeleteDownloadedFile();
  59. virtual OpFileLength GetOverridedFileLength() { return 0; }
  60. OpString m_file_name; ///< Name of the file being downloaded
  61. private:
  62. // OpTransferListener
  63. // The method handles progress messages from the transfer that the file downloader has initiated.
  64. void OnProgress(OpTransferItem* transferItem, TransferStatus status);
  65. void OnReset(OpTransferItem* transferItem) {}
  66. void OnRedirect(OpTransferItem* transferItem, URL* redirect_from, URL* redirect_to);
  67. // MessageObject override
  68. virtual void HandleCallback(OpMessage msg, MH_PARAM_1 par1, MH_PARAM_2 par2);
  69. OpTransferItem* m_transferItem; ///< A reference to the TransferItem that represents the transfer initiated by this class.
  70. FileDownloadListener* m_listener; ///< Reference to the listener object
  71. TransferStatus m_url_status; ///< Status of url loading
  72. BOOL m_download_started; ///< Set if the download has started
  73. URL m_download_url; ///< Download url
  74. OpString m_url_string; ///< String of url to be loaded
  75. };
  76. #endif //AUTO_UPDATE_SUPPORT
  77. #endif //FILE_DOWNLOADER_H