Mercurial > projects > dstep
comparison dstep/foundation/NSURL.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 7ff919f595d5 |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSURL; | |
8 | |
9 import dstep.foundation.NSData; | |
10 import dstep.foundation.NSDictionary; | |
11 import dstep.foundation.NSNumber; | |
12 import dstep.foundation.NSObject; | |
13 import dstep.foundation.NSString; | |
14 import dstep.foundation.NSURLHandle; | |
15 import dstep.objc.bridge.Bridge; | |
16 import dstep.objc.objc : id; | |
17 | |
18 import bindings = dstep.foundation.NSURL_bindings; | |
19 | |
20 NSString NSURLFileScheme; | |
21 | |
22 static this () | |
23 { | |
24 NSURLFileScheme = new NSString(bindings.NSURLFileScheme); | |
25 } | |
26 | |
27 class NSURL : NSObject, INSCoding, INSCopying, INSURLHandleClient | |
28 { | |
29 mixin ObjcWrap; | |
30 mixin TNSURLLoading; | |
31 | |
32 Object initWithScheme (NSString scheme, NSString host, NSString path) | |
33 { | |
34 return invokeObjcSelf!(Object, "initWithScheme:host:path:", NSString, NSString, NSString)(scheme, host, path); | |
35 } | |
36 | |
37 this (NSString scheme, NSString host, NSString path) | |
38 { | |
39 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
40 id result = Bridge.invokeObjcMethod!(id, "initWithScheme:host:path:", NSString, NSString, NSString)(objcObject, scheme, host, path); | |
41 | |
42 if (result) | |
43 objcObject = ret; | |
44 | |
45 dObject = this; | |
46 } | |
47 | |
48 Object initFileURLWithPath (NSString path, bool isDir) | |
49 { | |
50 return invokeObjcSelf!(Object, "initFileURLWithPath:isDirectory:", NSString, bool)(path, isDir); | |
51 } | |
52 | |
53 this (NSString path, bool isDir) | |
54 { | |
55 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
56 id result = Bridge.invokeObjcMethod!(id, "initFileURLWithPath:isDirectory:", NSString, bool)(objcObject, path, isDir); | |
57 | |
58 if (result) | |
59 objcObject = ret; | |
60 | |
61 dObject = this; | |
62 } | |
63 | |
64 Object initFileURLWithPath (NSString path) | |
65 { | |
66 return invokeObjcSelf!(Object, "initFileURLWithPath:", NSString)(path); | |
67 } | |
68 | |
69 this (NSString path) | |
70 { | |
71 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
72 id result = Bridge.invokeObjcMethod!(id, "initFileURLWithPath:", NSString)(objcObject, path); | |
73 | |
74 if (result) | |
75 objcObject = ret; | |
76 | |
77 dObject = this; | |
78 } | |
79 | |
80 static Object fileURLWithPath (NSString path, bool isDir) | |
81 { | |
82 return invokeObjcSelfClass!(Object, "fileURLWithPath:isDirectory:", NSString, bool)(path, isDir); | |
83 } | |
84 | |
85 static Object fileURLWithPath (NSString path) | |
86 { | |
87 return invokeObjcSelfClass!(Object, "fileURLWithPath:", NSString)(path); | |
88 } | |
89 | |
90 Object initWithString (NSString URLString) | |
91 { | |
92 return invokeObjcSelf!(Object, "initWithString:", NSString)(URLString); | |
93 } | |
94 | |
95 this (NSString URLString) | |
96 { | |
97 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
98 id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, URLString); | |
99 | |
100 if (result) | |
101 objcObject = ret; | |
102 | |
103 dObject = this; | |
104 } | |
105 | |
106 Object initWithString (NSString URLString, NSURL baseURL) | |
107 { | |
108 return invokeObjcSelf!(Object, "initWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); | |
109 } | |
110 | |
111 this (NSString URLString, NSURL baseURL) | |
112 { | |
113 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
114 id result = Bridge.invokeObjcMethod!(id, "initWithString:relativeToURL:", NSString, NSURL)(objcObject, URLString, baseURL); | |
115 | |
116 if (result) | |
117 objcObject = ret; | |
118 | |
119 dObject = this; | |
120 } | |
121 | |
122 static Object URLWithString (NSString URLString) | |
123 { | |
124 return invokeObjcSelfClass!(Object, "URLWithString:", NSString)(URLString); | |
125 } | |
126 | |
127 static Object URLWithString (NSString URLString, NSURL baseURL) | |
128 { | |
129 return invokeObjcSelfClass!(Object, "URLWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL); | |
130 } | |
131 | |
132 NSString absoluteString () | |
133 { | |
134 return invokeObjcSelf!(NSString, "absoluteString"); | |
135 } | |
136 | |
137 NSString relativeString () | |
138 { | |
139 return invokeObjcSelf!(NSString, "relativeString"); | |
140 } | |
141 | |
142 NSURL baseURL () | |
143 { | |
144 id result = invokeObjcSelf!(id, "baseURL"return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null); } | |
145 | |
146 NSURL absoluteURL () | |
147 { | |
148 id result = invokeObjcSelf!(id, "absoluteURL"return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null); } | |
149 | |
150 NSString scheme () | |
151 { | |
152 return invokeObjcSelf!(NSString, "scheme"); | |
153 } | |
154 | |
155 NSString resourceSpecifier () | |
156 { | |
157 return invokeObjcSelf!(NSString, "resourceSpecifier"); | |
158 } | |
159 | |
160 NSString host () | |
161 { | |
162 return invokeObjcSelf!(NSString, "host"); | |
163 } | |
164 | |
165 NSNumber port () | |
166 { | |
167 return invokeObjcSelf!(NSNumber, "port"); | |
168 } | |
169 | |
170 NSString user () | |
171 { | |
172 return invokeObjcSelf!(NSString, "user"); | |
173 } | |
174 | |
175 NSString password () | |
176 { | |
177 return invokeObjcSelf!(NSString, "password"); | |
178 } | |
179 | |
180 NSString path () | |
181 { | |
182 return invokeObjcSelf!(NSString, "path"); | |
183 } | |
184 | |
185 NSString fragment () | |
186 { | |
187 return invokeObjcSelf!(NSString, "fragment"); | |
188 } | |
189 | |
190 NSString parameterString () | |
191 { | |
192 return invokeObjcSelf!(NSString, "parameterString"); | |
193 } | |
194 | |
195 NSString query () | |
196 { | |
197 return invokeObjcSelf!(NSString, "query"); | |
198 } | |
199 | |
200 NSString relativePath () | |
201 { | |
202 return invokeObjcSelf!(NSString, "relativePath"); | |
203 } | |
204 | |
205 bool isFileURL () | |
206 { | |
207 return invokeObjcSelf!(bool, "isFileURL"); | |
208 } | |
209 | |
210 NSURL standardizedURL () | |
211 { | |
212 id result = invokeObjcSelf!(id, "standardizedURL"return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null); } | |
213 | |
214 void encodeWithCoder (NSCoder aCoder) | |
215 { | |
216 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
217 } | |
218 | |
219 Object initWithCoder (NSCoder aDecoder) | |
220 { | |
221 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
222 } | |
223 | |
224 this (NSCoder aDecoder) | |
225 { | |
226 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
227 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
228 | |
229 if (result) | |
230 objcObject = ret; | |
231 | |
232 dObject = this; | |
233 } | |
234 | |
235 Object copyWithZone (NSZone* zone) | |
236 { | |
237 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
238 } | |
239 | |
240 void URLHandle (NSURLHandle sender, NSData newBytes) | |
241 { | |
242 return invokeObjcSelf!(void, "URLHandle:resourceDataDidBecomeAvailable:", NSURLHandle, NSData)(sender, newBytes); | |
243 } | |
244 | |
245 void URLHandleResourceDidBeginLoading (NSURLHandle sender) | |
246 { | |
247 return invokeObjcSelf!(void, "URLHandleResourceDidBeginLoading:", NSURLHandle)(sender); | |
248 } | |
249 | |
250 void URLHandleResourceDidFinishLoading (NSURLHandle sender) | |
251 { | |
252 return invokeObjcSelf!(void, "URLHandleResourceDidFinishLoading:", NSURLHandle)(sender); | |
253 } | |
254 | |
255 void URLHandleResourceDidCancelLoading (NSURLHandle sender) | |
256 { | |
257 return invokeObjcSelf!(void, "URLHandleResourceDidCancelLoading:", NSURLHandle)(sender); | |
258 } | |
259 | |
260 void URLHandle (NSURLHandle sender, NSString reason) | |
261 { | |
262 return invokeObjcSelf!(void, "URLHandle:resourceDidFailLoadingWithReason:", NSURLHandle, NSString)(sender, reason); | |
263 } | |
264 } | |
265 | |
266 template TNSURLLoading () | |
267 { | |
268 NSData resourceDataUsingCache (bool shouldUseCache) | |
269 { | |
270 return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache); | |
271 } | |
272 | |
273 void loadResourceDataNotifyingClient (Object client, bool shouldUseCache) | |
274 { | |
275 return invokeObjcSelf!(void, "loadResourceDataNotifyingClient:usingCache:", Object, bool)(client, shouldUseCache); | |
276 } | |
277 | |
278 Object propertyForKey (NSString propertyKey) | |
279 { | |
280 return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey); | |
281 } | |
282 | |
283 bool setResourceData (NSData data) | |
284 { | |
285 return invokeObjcSelf!(bool, "setResourceData:", NSData)(data); | |
286 } | |
287 | |
288 bool setProperty (Object property, NSString propertyKey) | |
289 { | |
290 return invokeObjcSelf!(bool, "setProperty:forKey:", Object, NSString)(property, propertyKey); | |
291 } | |
292 | |
293 NSURLHandle URLHandleUsingCache (bool shouldUseCache) | |
294 { | |
295 return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache); | |
296 } | |
297 } | |
298 | |
299 template TNSURLClient () | |
300 { | |
301 void URL (NSURL sender, NSData newBytes); | |
302 void URLResourceDidFinishLoading (NSURL sender); | |
303 void URLResourceDidCancelLoading (NSURL sender); | |
304 void URL (NSURL sender, NSString reason); | |
305 } | |
306 | |
307 template TNSURLUtilities () | |
308 { | |
309 NSString stringByAddingPercentEscapesUsingEncoding (uint enc) | |
310 { | |
311 return invokeObjcSelf!(NSString, "stringByAddingPercentEscapesUsingEncoding:", uint)(enc); | |
312 } | |
313 | |
314 NSString stringByReplacingPercentEscapesUsingEncoding (uint enc) | |
315 { | |
316 return invokeObjcSelf!(NSString, "stringByReplacingPercentEscapesUsingEncoding:", uint)(enc); | |
317 } | |
318 } | |
319 |