view dstep/foundation/NSURL.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 7ff919f595d5
children b9de51448c6b
line wrap: on
line source

/**
 * 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.NSURL;

import dstep.foundation.NSCoder;
import dstep.foundation.NSData;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.foundation.NSURLHandle;
import dstep.foundation.NSValue;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;



import bindings = dstep.foundation.NSURL_bindings;

private NSString NSURLFileScheme_;

NSString NSURLFileScheme ()
{
	if (NSURLFileScheme_)
		return NSURLFileScheme_;
	
	return NSURLFileScheme_ = new NSString(bindings.NSURLFileScheme);
}

class NSURL : NSObject, INSCoding, INSCopying, INSURLHandleClient
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	Object initWithScheme (NSString scheme, NSString host, NSString path)
	{
		return invokeObjcSelf!(Object, "initWithScheme:host:path:", NSString, NSString, NSString)(scheme, host, path);
	}

	this (NSString scheme, NSString host, NSString path)
	{
		typeof(this).alloc.initWithScheme(scheme, host, path);
	}

	Object initFileURLWithPath (NSString path, bool isDir)
	{
		return invokeObjcSelf!(Object, "initFileURLWithPath:isDirectory:", NSString, bool)(path, isDir);
	}

	this (NSString path, bool isDir)
	{
		typeof(this).alloc.initFileURLWithPath(path, isDir);
	}

	Object initFileURLWithPath (NSString path)
	{
		return invokeObjcSelf!(Object, "initFileURLWithPath:", NSString)(path);
	}

	static Object fileURLWithPath (NSString path, bool isDir)
	{
		return invokeObjcSuperClass!(Object, "fileURLWithPath:isDirectory:", NSString, bool)(path, isDir);
	}

	static Object fileURLWithPath (NSString path)
	{
		return invokeObjcSuperClass!(Object, "fileURLWithPath:", NSString)(path);
	}

	Object initWithString (NSString URLString)
	{
		return invokeObjcSelf!(Object, "initWithString:", NSString)(URLString);
	}

	this (NSString URLString)
	{
		typeof(this).alloc.initWithString(URLString);
	}

	Object initWithString (NSString URLString, NSURL baseURL)
	{
		return invokeObjcSelf!(Object, "initWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL);
	}

	this (NSString URLString, NSURL baseURL)
	{
		typeof(this).alloc.initWithString(URLString, baseURL);
	}

	static Object URLWithString (NSString URLString)
	{
		return invokeObjcSuperClass!(Object, "URLWithString:", NSString)(URLString);
	}

	static Object URLWithString (NSString URLString, NSURL baseURL)
	{
		return invokeObjcSuperClass!(Object, "URLWithString:relativeToURL:", NSString, NSURL)(URLString, baseURL);
	}

	NSString absoluteString ()
	{
		return invokeObjcSelf!(NSString, "absoluteString");
	}

	NSString relativeString ()
	{
		return invokeObjcSelf!(NSString, "relativeString");
	}

	NSURL baseURL ()
	{
		id result = invokeObjcSelf!(id, "baseURL");
		return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null);
	}

	NSURL absoluteURL ()
	{
		id result = invokeObjcSelf!(id, "absoluteURL");
		return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null);
	}

	NSString scheme ()
	{
		return invokeObjcSelf!(NSString, "scheme");
	}

	NSString resourceSpecifier ()
	{
		return invokeObjcSelf!(NSString, "resourceSpecifier");
	}

	NSString host ()
	{
		return invokeObjcSelf!(NSString, "host");
	}

	NSNumber port ()
	{
		return invokeObjcSelf!(NSNumber, "port");
	}

	NSString user ()
	{
		return invokeObjcSelf!(NSString, "user");
	}

	NSString password ()
	{
		return invokeObjcSelf!(NSString, "password");
	}

	NSString path ()
	{
		return invokeObjcSelf!(NSString, "path");
	}

	NSString fragment ()
	{
		return invokeObjcSelf!(NSString, "fragment");
	}

	NSString parameterString ()
	{
		return invokeObjcSelf!(NSString, "parameterString");
	}

	NSString query ()
	{
		return invokeObjcSelf!(NSString, "query");
	}

	NSString relativePath ()
	{
		return invokeObjcSelf!(NSString, "relativePath");
	}

	bool isFileURL ()
	{
		return invokeObjcSelf!(bool, "isFileURL");
	}

	NSURL standardizedURL ()
	{
		id result = invokeObjcSelf!(id, "standardizedURL");
		return result is this.objcObject ? this : (result !is null ? new NSURL(result) : null);
	}

	void encodeWithCoder (NSCoder aCoder)
	{
		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
	}

	Object initWithCoder (NSCoder aDecoder)
	{
		return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
	}

	this (NSCoder aDecoder)
	{
		typeof(this).alloc.initWithCoder(aDecoder);
	}

	Object copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
	}

	void URLHandle (NSURLHandle sender, NSData newBytes)
	{
		return invokeObjcSelf!(void, "URLHandle:resourceDataDidBecomeAvailable:", NSURLHandle, NSData)(sender, newBytes);
	}

	void URLHandleResourceDidBeginLoading (NSURLHandle sender)
	{
		return invokeObjcSelf!(void, "URLHandleResourceDidBeginLoading:", NSURLHandle)(sender);
	}

	void URLHandleResourceDidFinishLoading (NSURLHandle sender)
	{
		return invokeObjcSelf!(void, "URLHandleResourceDidFinishLoading:", NSURLHandle)(sender);
	}

	void URLHandleResourceDidCancelLoading (NSURLHandle sender)
	{
		return invokeObjcSelf!(void, "URLHandleResourceDidCancelLoading:", NSURLHandle)(sender);
	}

	void URLHandle (NSURLHandle sender, NSString reason)
	{
		return invokeObjcSelf!(void, "URLHandle:resourceDidFailLoadingWithReason:", NSURLHandle, NSString)(sender, reason);
	}
	
	// TNSURLLoading
	NSData resourceDataUsingCache (bool shouldUseCache)
	{
		return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache);
	}
	
	void loadResourceDataNotifyingClient (Object client, bool shouldUseCache)
	{
		return invokeObjcSelf!(void, "loadResourceDataNotifyingClient:usingCache:", Object, bool)(client, shouldUseCache);
	}
	
	Object propertyForKey (NSString propertyKey)
	{
		return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey);
	}
	
	bool setResourceData (NSData data)
	{
		return invokeObjcSelf!(bool, "setResourceData:", NSData)(data);
	}
	
	bool setProperty (Object property, NSString propertyKey)
	{
		return invokeObjcSelf!(bool, "setProperty:forKey:", Object, NSString)(property, propertyKey);
	}
	
	NSURLHandle URLHandleUsingCache (bool shouldUseCache)
	{
		return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache);
	}
}

const TNSURLLoading = `

	NSData resourceDataUsingCache (bool shouldUseCache)
	{
		return invokeObjcSelf!(NSData, "resourceDataUsingCache:", bool)(shouldUseCache);
	}

	void loadResourceDataNotifyingClient (Object client, bool shouldUseCache)
	{
		return invokeObjcSelf!(void, "loadResourceDataNotifyingClient:usingCache:", Object, bool)(client, shouldUseCache);
	}

	Object propertyForKey (NSString propertyKey)
	{
		return invokeObjcSelf!(Object, "propertyForKey:", NSString)(propertyKey);
	}

	bool setResourceData (NSData data)
	{
		return invokeObjcSelf!(bool, "setResourceData:", NSData)(data);
	}

	bool setProperty (Object property, NSString propertyKey)
	{
		return invokeObjcSelf!(bool, "setProperty:forKey:", Object, NSString)(property, propertyKey);
	}

	NSURLHandle URLHandleUsingCache (bool shouldUseCache)
	{
		return invokeObjcSelf!(NSURLHandle, "URLHandleUsingCache:", bool)(shouldUseCache);
	}
`;

const TNSURLClient = `

	void URL (NSURL sender, NSData newBytes)
	{
		return invokeObjcSelf!(void, "URL:resourceDataDidBecomeAvailable:", NSURL, NSData)(sender, newBytes);
	}
			
	void URLResourceDidFinishLoading (NSURL sender)
	{
		return invokeObjcSelf!(void, "URLResourceDidFinishLoading:", NSURL)(sender);
	}
	
	void URLResourceDidCancelLoading (NSURL sender)
	{
		return invokeObjcSelf!(void, "URLResourceDidCancelLoading:", NSURL)(sender);
	}
	
	void URL (NSURL sender, NSString reason)
	{
		return invokeObjcSelf!(void, "URL:resourceDidFailLoadingWithReason:", NSURL, NSString)(sender, reason);
	}
	
	//mixin ObjcBindMethod!(URL, "URL:resourceDataDidBecomeAvailable:");
	//mixin ObjcBindMethod!(URLResourceDidFinishLoading, "URLResourceDidFinishLoading:");
	//mixin ObjcBindMethod!(URLResourceDidCancelLoading, "URLResourceDidCancelLoading:");
	//mixin ObjcBindMethod!(URL, "URL:resourceDidFailLoadingWithReason:");
`;

const TNSURLUtilities = `

	NSString stringByAddingPercentEscapesUsingEncoding (uint enc)
	{
		return invokeObjcSelf!(NSString, "stringByAddingPercentEscapesUsingEncoding:", uint)(enc);
	}

	NSString stringByReplacingPercentEscapesUsingEncoding (uint enc)
	{
		return invokeObjcSelf!(NSString, "stringByReplacingPercentEscapesUsingEncoding:", uint)(enc);
	}
`;