diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSURLHandle.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,166 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Aug 3, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.foundation.NSURLHandle;
+
+import dstep.foundation.NSObject;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+alias NSUInteger NSURLHandleStatus;
+
+enum
+{
+	NSURLHandleNotLoaded = 0,
+	NSURLHandleLoadSucceeded,
+	NSURLHandleLoadInProgress,
+	NSURLHandleLoadFailed
+}
+
+class NSURLHandle : NSObject
+{
+	mixin ObjcWrap;
+
+	static void registerURLHandleClass (Class anURLHandleSubclass)
+	{
+		return invokeObjcSelfClass!(void, "registerURLHandleClass:", Class)(anURLHandleSubclass);
+	}
+
+	static Class URLHandleClassForURL (NSURL anURL)
+	{
+		return invokeObjcSelfClass!(Class, "URLHandleClassForURL:", NSURL)(anURL);
+	}
+
+	uint status ()
+	{
+		return invokeObjcSelf!(uint, "status");
+	}
+
+	NSString failureReason ()
+	{
+		return invokeObjcSelf!(NSString, "failureReason");
+	}
+
+	void addClient (INSURLHandleClient client)
+	{
+		return invokeObjcSelf!(void, "addClient:", INSURLHandleClient)(client);
+	}
+
+	void removeClient (INSURLHandleClient client)
+	{
+		return invokeObjcSelf!(void, "removeClient:", INSURLHandleClient)(client);
+	}
+
+	void loadInBackground ()
+	{
+		return invokeObjcSelf!(void, "loadInBackground");
+	}
+
+	void cancelLoadInBackground ()
+	{
+		return invokeObjcSelf!(void, "cancelLoadInBackground");
+	}
+
+	NSData resourceData ()
+	{
+		return invokeObjcSelf!(NSData, "resourceData");
+	}
+
+	NSData availableResourceData ()
+	{
+		return invokeObjcSelf!(NSData, "availableResourceData");
+	}
+
+	long expectedResourceDataSize ()
+	{
+		return invokeObjcSelf!(long, "expectedResourceDataSize");
+	}
+
+	void flushCachedData ()
+	{
+		return invokeObjcSelf!(void, "flushCachedData");
+	}
+
+	void backgroundLoadDidFailWithReason (NSString reason)
+	{
+		return invokeObjcSelf!(void, "backgroundLoadDidFailWithReason:", NSString)(reason);
+	}
+
+	void didLoadBytes (NSData newBytes, bool yorn)
+	{
+		return invokeObjcSelf!(void, "didLoadBytes:loadComplete:", NSData, bool)(newBytes, yorn);
+	}
+
+	static bool canInitWithURL (NSURL anURL)
+	{
+		return invokeObjcSelfClass!(bool, "canInitWithURL:", NSURL)(anURL);
+	}
+
+	static NSURLHandle cachedHandleForURL (NSURL anURL)
+	{
+		return invokeObjcSelfClass!(NSURLHandle, "cachedHandleForURL:", NSURL)(anURLreturn result is this.objcObject ? this : (result !is null ? new NSURLHandle(result) : null);	}
+
+	Object initWithURL (NSURL anURL, bool willCache)
+	{
+		return invokeObjcSelf!(Object, "initWithURL:cached:", NSURL, bool)(anURL, willCache);
+	}
+
+	this (NSURL anURL, bool willCache)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithURL:cached:", NSURL, bool)(objcObject, anURL, willCache);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	Object propertyForKey (NSString propertyKey)
+	{
+		return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey);
+	}
+
+	Object propertyForKeyIfAvailable (NSString propertyKey)
+	{
+		return invokeObjcSelf!(Object, "propertyForKeyIfAvailable:", NSString)(propertyKey);
+	}
+
+	bool writeProperty (Object propertyValue, NSString propertyKey)
+	{
+		return invokeObjcSelf!(bool, "writeProperty:forKey:", Object, NSString)(propertyValue, propertyKey);
+	}
+
+	bool writeData (NSData data)
+	{
+		return invokeObjcSelf!(bool, "writeData:", NSData)(data);
+	}
+
+	NSData loadInForeground ()
+	{
+		return invokeObjcSelf!(NSData, "loadInForeground");
+	}
+
+	void beginLoadInBackground ()
+	{
+		return invokeObjcSelf!(void, "beginLoadInBackground");
+	}
+
+	void endLoadInBackground ()
+	{
+		return invokeObjcSelf!(void, "endLoadInBackground");
+	}
+}
+
+interface INSURLHandleClient
+{
+	void URLHandle (NSURLHandle sender, NSData newBytes);
+	void URLHandleResourceDidBeginLoading (NSURLHandle sender);
+	void URLHandleResourceDidFinishLoading (NSURLHandle sender);
+	void URLHandleResourceDidCancelLoading (NSURLHandle sender);
+	void URLHandle (NSURLHandle sender, NSString reason);
+}
+