1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Copyright 2013, Rene Gollent <rene@gollent.com> 4 * Copyright 2015, Axel Dörfler <axeld@pinc-software.de> 5 * Distributed under the terms of the MIT License. 6 */ 7 #ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ 8 #define _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ 9 10 11 #include <Entry.h> 12 #include <File.h> 13 #include <String.h> 14 15 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 16 # include <UrlProtocolListener.h> 17 #endif 18 19 #include <package/Job.h> 20 21 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 22 using BPrivate::Network::BUrlProtocolListener; 23 using BPrivate::Network::BUrlRequest; 24 #endif 25 26 27 namespace BPackageKit { 28 29 namespace BPrivate { 30 31 32 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 33 class FetchFileJob : public BJob, public BUrlProtocolListener { 34 #else // HAIKU_TARGET_PLATFORM_HAIKU 35 class FetchFileJob : public BJob { 36 #endif // HAIKU_TARGET_PLATFORM_HAIKU 37 38 typedef BJob inherited; 39 40 public: 41 FetchFileJob(const BContext& context, 42 const BString& title, 43 const BString& fileURL, 44 const BEntry& targetEntry); 45 virtual ~FetchFileJob(); 46 47 float DownloadProgress() const; 48 const char* DownloadURL() const; 49 const char* DownloadFileName() const; 50 off_t DownloadBytes() const; 51 off_t DownloadTotalBytes() const; 52 53 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 54 virtual void DownloadProgress(BUrlRequest*, 55 off_t bytesReceived, off_t bytesTotal); 56 virtual void RequestCompleted(BUrlRequest* request, 57 bool success); 58 #endif 59 60 protected: 61 virtual status_t Execute(); 62 virtual void Cleanup(status_t jobResult); 63 64 private: 65 BString fFileURL; 66 BEntry fTargetEntry; 67 BFile fTargetFile; 68 status_t fError; 69 float fDownloadProgress; 70 off_t fBytes; 71 off_t fTotalBytes; 72 }; 73 74 75 } // namespace BPrivate 76 77 } // namespace BPackageKit 78 79 80 #endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ 81