xref: /haiku/src/kits/package/FetchFileJob.h (revision 8579c7faf2111c668a31ace64d268cac00f71d59)
1106ae4ecSCodeforEvolution /*
2106ae4ecSCodeforEvolution  * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3106ae4ecSCodeforEvolution  * Copyright 2013, Rene Gollent <rene@gollent.com>
4106ae4ecSCodeforEvolution  * Copyright 2015, Axel Dörfler <axeld@pinc-software.de>
5106ae4ecSCodeforEvolution  * Distributed under the terms of the MIT License.
6106ae4ecSCodeforEvolution  */
7106ae4ecSCodeforEvolution #ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
8106ae4ecSCodeforEvolution #define _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
9106ae4ecSCodeforEvolution 
10106ae4ecSCodeforEvolution 
11106ae4ecSCodeforEvolution #include <Entry.h>
12106ae4ecSCodeforEvolution #include <File.h>
13106ae4ecSCodeforEvolution #include <String.h>
14106ae4ecSCodeforEvolution 
15106ae4ecSCodeforEvolution #ifdef HAIKU_TARGET_PLATFORM_HAIKU
16106ae4ecSCodeforEvolution #	include <UrlProtocolListener.h>
17106ae4ecSCodeforEvolution #endif
18106ae4ecSCodeforEvolution 
19106ae4ecSCodeforEvolution #include <package/Job.h>
20106ae4ecSCodeforEvolution 
21*8579c7faSNiels Sascha Reedijk #ifdef HAIKU_TARGET_PLATFORM_HAIKU
22*8579c7faSNiels Sascha Reedijk using BPrivate::Network::BUrlProtocolListener;
23*8579c7faSNiels Sascha Reedijk using BPrivate::Network::BUrlRequest;
24*8579c7faSNiels Sascha Reedijk #endif
25*8579c7faSNiels Sascha Reedijk 
26106ae4ecSCodeforEvolution 
27106ae4ecSCodeforEvolution namespace BPackageKit {
28106ae4ecSCodeforEvolution 
29106ae4ecSCodeforEvolution namespace BPrivate {
30106ae4ecSCodeforEvolution 
31106ae4ecSCodeforEvolution 
32106ae4ecSCodeforEvolution #ifdef HAIKU_TARGET_PLATFORM_HAIKU
33106ae4ecSCodeforEvolution class FetchFileJob : public BJob, public BUrlProtocolListener {
34106ae4ecSCodeforEvolution #else // HAIKU_TARGET_PLATFORM_HAIKU
35106ae4ecSCodeforEvolution class FetchFileJob : public BJob {
36106ae4ecSCodeforEvolution #endif // HAIKU_TARGET_PLATFORM_HAIKU
37106ae4ecSCodeforEvolution 
38106ae4ecSCodeforEvolution 	typedef	BJob				inherited;
39106ae4ecSCodeforEvolution 
40106ae4ecSCodeforEvolution public:
41106ae4ecSCodeforEvolution 								FetchFileJob(const BContext& context,
42106ae4ecSCodeforEvolution 									const BString& title,
43106ae4ecSCodeforEvolution 									const BString& fileURL,
44106ae4ecSCodeforEvolution 									const BEntry& targetEntry);
45106ae4ecSCodeforEvolution 	virtual						~FetchFileJob();
46106ae4ecSCodeforEvolution 
47106ae4ecSCodeforEvolution 			float				DownloadProgress() const;
48106ae4ecSCodeforEvolution 			const char*			DownloadURL() const;
49106ae4ecSCodeforEvolution 			const char*			DownloadFileName() const;
50106ae4ecSCodeforEvolution 			off_t				DownloadBytes() const;
51106ae4ecSCodeforEvolution 			off_t				DownloadTotalBytes() const;
52106ae4ecSCodeforEvolution 
53106ae4ecSCodeforEvolution #ifdef HAIKU_TARGET_PLATFORM_HAIKU
54106ae4ecSCodeforEvolution 	virtual void	DataReceived(BUrlRequest*, const char* data,
55106ae4ecSCodeforEvolution 						off_t position, ssize_t size);
56*8579c7faSNiels Sascha Reedijk 	virtual void	DownloadProgress(BUrlRequest*,
57*8579c7faSNiels Sascha Reedijk 						ssize_t bytesReceived, ssize_t bytesTotal);
58*8579c7faSNiels Sascha Reedijk 	virtual void 	RequestCompleted(BUrlRequest* request,
59*8579c7faSNiels Sascha Reedijk 						bool success);
60106ae4ecSCodeforEvolution #endif
61106ae4ecSCodeforEvolution 
62106ae4ecSCodeforEvolution protected:
63106ae4ecSCodeforEvolution 	virtual	status_t			Execute();
64106ae4ecSCodeforEvolution 	virtual	void				Cleanup(status_t jobResult);
65106ae4ecSCodeforEvolution 
66106ae4ecSCodeforEvolution private:
67106ae4ecSCodeforEvolution 			BString				fFileURL;
68106ae4ecSCodeforEvolution 			BEntry				fTargetEntry;
69106ae4ecSCodeforEvolution 			BFile				fTargetFile;
700ef0921dSFrançois Revol 			status_t			fError;
71106ae4ecSCodeforEvolution 			float				fDownloadProgress;
72106ae4ecSCodeforEvolution 			off_t				fBytes;
73106ae4ecSCodeforEvolution 			off_t				fTotalBytes;
74106ae4ecSCodeforEvolution };
75106ae4ecSCodeforEvolution 
76106ae4ecSCodeforEvolution 
77106ae4ecSCodeforEvolution }	// namespace BPrivate
78106ae4ecSCodeforEvolution 
79106ae4ecSCodeforEvolution }	// namespace BPackageKit
80106ae4ecSCodeforEvolution 
81106ae4ecSCodeforEvolution 
82106ae4ecSCodeforEvolution #endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
83