comparison dstep/foundation/NSURLDownload.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 89f3c3ef1fd2
children b9de51448c6b
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
4 * Version: Initial created: Aug 3, 2009 4 * Version: Initial created: Aug 3, 2009
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */ 6 */
7 module dstep.foundation.NSURLDownload; 7 module dstep.foundation.NSURLDownload;
8 8
9 import dstep.AvailabilityMacros;
10 import dstep.foundation.NSData; 9 import dstep.foundation.NSData;
11 import dstep.foundation.NSError; 10 import dstep.foundation.NSError;
12 import dstep.foundation.NSObject; 11 import dstep.foundation.NSObject;
13 import dstep.foundation.NSString; 12 import dstep.foundation.NSString;
14 import dstep.foundation.NSURLAuthenticationChallenge; 13 import dstep.foundation.NSURLAuthenticationChallenge;
15 import dstep.foundation.NSURLDownloadInternal;
16 import dstep.foundation.NSURLRequest; 14 import dstep.foundation.NSURLRequest;
17 import dstep.foundation.NSURLResponse; 15 import dstep.foundation.NSURLResponse;
18 import dstep.objc.bridge.Bridge; 16 import dstep.objc.bridge.Bridge;
19 import dstep.objc.objc : id; 17 import dstep.objc.objc;
20 18
21 class NSURLDownload : NSObject 19 class NSURLDownload : NSObject
22 { 20 {
23 mixin ObjcWrap; 21 mixin (ObjcWrap);
24 22
23 this ()
24 {
25 super(typeof(this).alloc.init.objcObject);
26 }
27
28 typeof(this) init ()
29 {
30 return invokeObjcSelf!(typeof(this), "init");
31 }
32
25 static bool canResumeDownloadDecodedWithEncodingMIMEType (NSString MIMEType) 33 static bool canResumeDownloadDecodedWithEncodingMIMEType (NSString MIMEType)
26 { 34 {
27 return invokeObjcSelfClass!(bool, "canResumeDownloadDecodedWithEncodingMIMEType:", NSString)(MIMEType); 35 return invokeObjcSuperClass!(bool, "canResumeDownloadDecodedWithEncodingMIMEType:", NSString)(MIMEType);
28 } 36 }
29 37
30 Object initWithRequest (NSURLRequest request, Object delegate_) 38 Object initWithRequest (NSURLRequest request, Object delegate_)
31 { 39 {
32 return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); 40 return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
33 } 41 }
34 42
35 this (NSURLRequest request, Object delegate_) 43 this (NSURLRequest request, Object delegate_)
36 { 44 {
37 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 45 typeof(this).alloc.initWithRequest(request, delegate_);
38 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:", NSURLRequest, Object)(objcObject, request, delegate_);
39
40 if (result)
41 objcObject = ret;
42
43 dObject = this;
44 } 46 }
45 47
46 Object initWithResumeData (NSData resumeData, Object delegate_, NSString path) 48 Object initWithResumeData (NSData resumeData, Object delegate_, NSString path)
47 { 49 {
48 return invokeObjcSelf!(Object, "initWithResumeData:delegate:path:", NSData, Object, NSString)(resumeData, delegate_, path); 50 return invokeObjcSelf!(Object, "initWithResumeData:delegate:path:", NSData, Object, NSString)(resumeData, delegate_, path);
49 } 51 }
50 52
51 this (NSData resumeData, Object delegate_, NSString path) 53 this (NSData resumeData, Object delegate_, NSString path)
52 { 54 {
53 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 55 typeof(this).alloc.initWithResumeData(resumeData, delegate_, path);
54 id result = Bridge.invokeObjcMethod!(id, "initWithResumeData:delegate:path:", NSData, Object, NSString)(objcObject, resumeData, delegate_, path);
55
56 if (result)
57 objcObject = ret;
58
59 dObject = this;
60 } 56 }
61 57
62 void cancel () 58 void cancel ()
63 { 59 {
64 return invokeObjcSelf!(void, "cancel"); 60 return invokeObjcSelf!(void, "cancel");
88 { 84 {
89 return invokeObjcSelf!(bool, "deletesFileUponFailure"); 85 return invokeObjcSelf!(bool, "deletesFileUponFailure");
90 } 86 }
91 } 87 }
92 88
93 template TNSURLDownloadDelegate () 89 const TNSURLDownloadDelegate = `
94 {
95 void downloadDidBegin (NSURLDownload download);
96 NSURLRequest download (NSURLDownload download, NSURLRequest request, NSURLResponse redirectResponse);
97 void download (NSURLDownload download, NSURLAuthenticationChallenge challenge);
98 void download (NSURLDownload download, NSURLAuthenticationChallenge challenge);
99 void download (NSURLDownload download, NSURLResponse response);
100 void download (NSURLDownload download, NSURLResponse response, long startingByte);
101 void download (NSURLDownload download, NSUInteger length);
102 bool download (NSURLDownload download, NSString encodingType);
103 void download (NSURLDownload download, NSString filename);
104 void download (NSURLDownload download, NSString path);
105 void downloadDidFinish (NSURLDownload download);
106 void download (NSURLDownload download, NSError error);
107 }
108 90
91 void downloadDidBegin (NSURLDownload download)
92 {
93 return invokeObjcSelf!(void, "downloadDidBegin:", NSURLDownload)(download);
94 }
95
96 NSURLRequest download (NSURLDownload download, NSURLRequest request, NSURLResponse redirectResponse)
97 {
98 return invokeObjcSelf!(NSURLRequest, "download:willSendRequest:redirectResponse:", NSURLDownload, NSURLRequest, NSURLResponse)(download, request, redirectResponse);
99 }
100
101 void download (NSURLDownload download, NSURLAuthenticationChallenge challenge)
102 {
103 return invokeObjcSelf!(void, "download:didReceiveAuthenticationChallenge:", NSURLDownload, NSURLAuthenticationChallenge)(download, challenge);
104 }
105
106 void download_didCancelAuthenticationChallenge (NSURLDownload download, NSURLAuthenticationChallenge challenge)
107 {
108 return invokeObjcSelf!(void, "download:didCancelAuthenticationChallenge:", NSURLDownload, NSURLAuthenticationChallenge)(download, challenge);
109 }
110
111 void download (NSURLDownload download, NSURLResponse response)
112 {
113 return invokeObjcSelf!(void, "download:didReceiveResponse:", NSURLDownload, NSURLResponse)(download, response);
114 }
115
116 void download (NSURLDownload download, NSURLResponse response, long startingByte)
117 {
118 return invokeObjcSelf!(void, "download:willResumeWithResponse:fromByte:", NSURLDownload, NSURLResponse, long)(download, response, startingByte);
119 }
120
121 void download (NSURLDownload download, NSUInteger length)
122 {
123 return invokeObjcSelf!(void, "download:didReceiveDataOfLength:", NSURLDownload, NSUInteger)(download, length);
124 }
125
126 bool download (NSURLDownload download, NSString encodingType)
127 {
128 return invokeObjcSelf!(bool, "download:shouldDecodeSourceDataOfMIMEType:", NSURLDownload, NSString)(download, encodingType);
129 }
130
131 void download_decideDestinationWithSuggestedFilename (NSURLDownload download, NSString filename)
132 {
133 return invokeObjcSelf!(void, "download:decideDestinationWithSuggestedFilename:", NSURLDownload, NSString)(download, filename);
134 }
135
136 void download_didCreateDestination (NSURLDownload download, NSString path)
137 {
138 return invokeObjcSelf!(void, "download:didCreateDestination:", NSURLDownload, NSString)(download, path);
139 }
140
141 void downloadDidFinish (NSURLDownload download)
142 {
143 return invokeObjcSelf!(void, "downloadDidFinish:", NSURLDownload)(download);
144 }
145
146 void download (NSURLDownload download, NSError error)
147 {
148 return invokeObjcSelf!(void, "download:didFailWithError:", NSURLDownload, NSError)(download, error);
149 }
150
151 //mixin ObjcBindMethod!(downloadDidBegin, "downloadDidBegin:");
152 //mixin ObjcBindMethod!(download, "download:willSendRequest:redirectResponse:");
153 //mixin ObjcBindMethod!(download, "download:didReceiveAuthenticationChallenge:");
154 //mixin ObjcBindMethod!(download_didCancelAuthenticationChallenge, "download:didCancelAuthenticationChallenge:");
155 //mixin ObjcBindMethod!(download, "download:didReceiveResponse:");
156 //mixin ObjcBindMethod!(download, "download:willResumeWithResponse:fromByte:");
157 //mixin ObjcBindMethod!(download, "download:didReceiveDataOfLength:");
158 //mixin ObjcBindMethod!(download, "download:shouldDecodeSourceDataOfMIMEType:");
159 //mixin ObjcBindMethod!(download_decideDestinationWithSuggestedFilename, "download:decideDestinationWithSuggestedFilename:");
160 //mixin ObjcBindMethod!(download_didCreateDestination, "download:didCreateDestination:");
161 //mixin ObjcBindMethod!(downloadDidFinish, "downloadDidFinish:");
162 //mixin ObjcBindMethod!(download, "download:didFailWithError:");
163 `;