xref: /haiku/src/kits/package/FetchFileJob.h (revision 08b9db66ac0a5d4fa92dcb82820e1435f203ea42)
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	DataReceived(BUrlRequest*, const char* data,
55 						off_t position, ssize_t size);
56 	virtual void	DownloadProgress(BUrlRequest*,
57 						off_t bytesReceived, off_t bytesTotal);
58 	virtual void 	RequestCompleted(BUrlRequest* request,
59 						bool success);
60 #endif
61 
62 protected:
63 	virtual	status_t			Execute();
64 	virtual	void				Cleanup(status_t jobResult);
65 
66 private:
67 			BString				fFileURL;
68 			BEntry				fTargetEntry;
69 			BFile				fTargetFile;
70 			status_t			fError;
71 			float				fDownloadProgress;
72 			off_t				fBytes;
73 			off_t				fTotalBytes;
74 };
75 
76 
77 }	// namespace BPrivate
78 
79 }	// namespace BPackageKit
80 
81 
82 #endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
83