comparison dstep/foundation/NSURLHandle.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.NSURLHandle;
8
9 import dstep.foundation.NSObject;
10 import dstep.objc.bridge.Bridge;
11 import dstep.objc.objc : id;
12
13 alias NSUInteger NSURLHandleStatus;
14
15 enum
16 {
17 NSURLHandleNotLoaded = 0,
18 NSURLHandleLoadSucceeded,
19 NSURLHandleLoadInProgress,
20 NSURLHandleLoadFailed
21 }
22
23 class NSURLHandle : NSObject
24 {
25 mixin ObjcWrap;
26
27 static void registerURLHandleClass (Class anURLHandleSubclass)
28 {
29 return invokeObjcSelfClass!(void, "registerURLHandleClass:", Class)(anURLHandleSubclass);
30 }
31
32 static Class URLHandleClassForURL (NSURL anURL)
33 {
34 return invokeObjcSelfClass!(Class, "URLHandleClassForURL:", NSURL)(anURL);
35 }
36
37 uint status ()
38 {
39 return invokeObjcSelf!(uint, "status");
40 }
41
42 NSString failureReason ()
43 {
44 return invokeObjcSelf!(NSString, "failureReason");
45 }
46
47 void addClient (INSURLHandleClient client)
48 {
49 return invokeObjcSelf!(void, "addClient:", INSURLHandleClient)(client);
50 }
51
52 void removeClient (INSURLHandleClient client)
53 {
54 return invokeObjcSelf!(void, "removeClient:", INSURLHandleClient)(client);
55 }
56
57 void loadInBackground ()
58 {
59 return invokeObjcSelf!(void, "loadInBackground");
60 }
61
62 void cancelLoadInBackground ()
63 {
64 return invokeObjcSelf!(void, "cancelLoadInBackground");
65 }
66
67 NSData resourceData ()
68 {
69 return invokeObjcSelf!(NSData, "resourceData");
70 }
71
72 NSData availableResourceData ()
73 {
74 return invokeObjcSelf!(NSData, "availableResourceData");
75 }
76
77 long expectedResourceDataSize ()
78 {
79 return invokeObjcSelf!(long, "expectedResourceDataSize");
80 }
81
82 void flushCachedData ()
83 {
84 return invokeObjcSelf!(void, "flushCachedData");
85 }
86
87 void backgroundLoadDidFailWithReason (NSString reason)
88 {
89 return invokeObjcSelf!(void, "backgroundLoadDidFailWithReason:", NSString)(reason);
90 }
91
92 void didLoadBytes (NSData newBytes, bool yorn)
93 {
94 return invokeObjcSelf!(void, "didLoadBytes:loadComplete:", NSData, bool)(newBytes, yorn);
95 }
96
97 static bool canInitWithURL (NSURL anURL)
98 {
99 return invokeObjcSelfClass!(bool, "canInitWithURL:", NSURL)(anURL);
100 }
101
102 static NSURLHandle cachedHandleForURL (NSURL anURL)
103 {
104 return invokeObjcSelfClass!(NSURLHandle, "cachedHandleForURL:", NSURL)(anURLreturn result is this.objcObject ? this : (result !is null ? new NSURLHandle(result) : null); }
105
106 Object initWithURL (NSURL anURL, bool willCache)
107 {
108 return invokeObjcSelf!(Object, "initWithURL:cached:", NSURL, bool)(anURL, willCache);
109 }
110
111 this (NSURL anURL, bool willCache)
112 {
113 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
114 id result = Bridge.invokeObjcMethod!(id, "initWithURL:cached:", NSURL, bool)(objcObject, anURL, willCache);
115
116 if (result)
117 objcObject = ret;
118
119 dObject = this;
120 }
121
122 Object propertyForKey (NSString propertyKey)
123 {
124 return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey);
125 }
126
127 Object propertyForKeyIfAvailable (NSString propertyKey)
128 {
129 return invokeObjcSelf!(Object, "propertyForKeyIfAvailable:", NSString)(propertyKey);
130 }
131
132 bool writeProperty (Object propertyValue, NSString propertyKey)
133 {
134 return invokeObjcSelf!(bool, "writeProperty:forKey:", Object, NSString)(propertyValue, propertyKey);
135 }
136
137 bool writeData (NSData data)
138 {
139 return invokeObjcSelf!(bool, "writeData:", NSData)(data);
140 }
141
142 NSData loadInForeground ()
143 {
144 return invokeObjcSelf!(NSData, "loadInForeground");
145 }
146
147 void beginLoadInBackground ()
148 {
149 return invokeObjcSelf!(void, "beginLoadInBackground");
150 }
151
152 void endLoadInBackground ()
153 {
154 return invokeObjcSelf!(void, "endLoadInBackground");
155 }
156 }
157
158 interface INSURLHandleClient
159 {
160 void URLHandle (NSURLHandle sender, NSData newBytes);
161 void URLHandleResourceDidBeginLoading (NSURLHandle sender);
162 void URLHandleResourceDidFinishLoading (NSURLHandle sender);
163 void URLHandleResourceDidCancelLoading (NSURLHandle sender);
164 void URLHandle (NSURLHandle sender, NSString reason);
165 }
166