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 22 namespace BPackageKit { 23 24 namespace BPrivate { 25 26 27 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 28 class FetchFileJob : public BJob, public BUrlProtocolListener { 29 #else // HAIKU_TARGET_PLATFORM_HAIKU 30 class FetchFileJob : public BJob { 31 #endif // HAIKU_TARGET_PLATFORM_HAIKU 32 33 typedef BJob inherited; 34 35 public: 36 FetchFileJob(const BContext& context, 37 const BString& title, 38 const BString& fileURL, 39 const BEntry& targetEntry); 40 virtual ~FetchFileJob(); 41 42 float DownloadProgress() const; 43 const char* DownloadURL() const; 44 const char* DownloadFileName() const; 45 off_t DownloadBytes() const; 46 off_t DownloadTotalBytes() const; 47 48 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 49 virtual void DataReceived(BUrlRequest*, const char* data, 50 off_t position, ssize_t size); 51 virtual void DownloadProgress(BUrlRequest*, ssize_t bytesReceived, 52 ssize_t bytesTotal); 53 virtual void RequestCompleted(BUrlRequest*, bool success); 54 #endif 55 56 protected: 57 virtual status_t Execute(); 58 virtual void Cleanup(status_t jobResult); 59 60 private: 61 BString fFileURL; 62 BEntry fTargetEntry; 63 BFile fTargetFile; 64 bool fSuccess; 65 float fDownloadProgress; 66 off_t fBytes; 67 off_t fTotalBytes; 68 }; 69 70 71 } // namespace BPrivate 72 73 } // namespace BPackageKit 74 75 76 #endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ 77