Mercurial > projects > dstep
diff 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 |
line wrap: on
line diff
--- a/dstep/foundation/NSURLDownload.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSURLDownload.d Sun Jan 03 22:06:11 2010 +0100 @@ -6,25 +6,33 @@ */ module dstep.foundation.NSURLDownload; -import dstep.AvailabilityMacros; import dstep.foundation.NSData; import dstep.foundation.NSError; import dstep.foundation.NSObject; import dstep.foundation.NSString; import dstep.foundation.NSURLAuthenticationChallenge; -import dstep.foundation.NSURLDownloadInternal; import dstep.foundation.NSURLRequest; import dstep.foundation.NSURLResponse; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; class NSURLDownload : NSObject { - mixin ObjcWrap; - + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + static bool canResumeDownloadDecodedWithEncodingMIMEType (NSString MIMEType) { - return invokeObjcSelfClass!(bool, "canResumeDownloadDecodedWithEncodingMIMEType:", NSString)(MIMEType); + return invokeObjcSuperClass!(bool, "canResumeDownloadDecodedWithEncodingMIMEType:", NSString)(MIMEType); } Object initWithRequest (NSURLRequest request, Object delegate_) @@ -34,13 +42,7 @@ this (NSURLRequest request, Object delegate_) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:", NSURLRequest, Object)(objcObject, request, delegate_); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithRequest(request, delegate_); } Object initWithResumeData (NSData resumeData, Object delegate_, NSString path) @@ -50,13 +52,7 @@ this (NSData resumeData, Object delegate_, NSString path) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithResumeData:delegate:path:", NSData, Object, NSString)(objcObject, resumeData, delegate_, path); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithResumeData(resumeData, delegate_, path); } void cancel () @@ -90,19 +86,78 @@ } } -template TNSURLDownloadDelegate () -{ - void downloadDidBegin (NSURLDownload download); - NSURLRequest download (NSURLDownload download, NSURLRequest request, NSURLResponse redirectResponse); - void download (NSURLDownload download, NSURLAuthenticationChallenge challenge); - void download (NSURLDownload download, NSURLAuthenticationChallenge challenge); - void download (NSURLDownload download, NSURLResponse response); - void download (NSURLDownload download, NSURLResponse response, long startingByte); - void download (NSURLDownload download, NSUInteger length); - bool download (NSURLDownload download, NSString encodingType); - void download (NSURLDownload download, NSString filename); - void download (NSURLDownload download, NSString path); - void downloadDidFinish (NSURLDownload download); - void download (NSURLDownload download, NSError error); -} +const TNSURLDownloadDelegate = ` + void downloadDidBegin (NSURLDownload download) + { + return invokeObjcSelf!(void, "downloadDidBegin:", NSURLDownload)(download); + } + + NSURLRequest download (NSURLDownload download, NSURLRequest request, NSURLResponse redirectResponse) + { + return invokeObjcSelf!(NSURLRequest, "download:willSendRequest:redirectResponse:", NSURLDownload, NSURLRequest, NSURLResponse)(download, request, redirectResponse); + } + + void download (NSURLDownload download, NSURLAuthenticationChallenge challenge) + { + return invokeObjcSelf!(void, "download:didReceiveAuthenticationChallenge:", NSURLDownload, NSURLAuthenticationChallenge)(download, challenge); + } + + void download_didCancelAuthenticationChallenge (NSURLDownload download, NSURLAuthenticationChallenge challenge) + { + return invokeObjcSelf!(void, "download:didCancelAuthenticationChallenge:", NSURLDownload, NSURLAuthenticationChallenge)(download, challenge); + } + + void download (NSURLDownload download, NSURLResponse response) + { + return invokeObjcSelf!(void, "download:didReceiveResponse:", NSURLDownload, NSURLResponse)(download, response); + } + + void download (NSURLDownload download, NSURLResponse response, long startingByte) + { + return invokeObjcSelf!(void, "download:willResumeWithResponse:fromByte:", NSURLDownload, NSURLResponse, long)(download, response, startingByte); + } + + void download (NSURLDownload download, NSUInteger length) + { + return invokeObjcSelf!(void, "download:didReceiveDataOfLength:", NSURLDownload, NSUInteger)(download, length); + } + + bool download (NSURLDownload download, NSString encodingType) + { + return invokeObjcSelf!(bool, "download:shouldDecodeSourceDataOfMIMEType:", NSURLDownload, NSString)(download, encodingType); + } + + void download_decideDestinationWithSuggestedFilename (NSURLDownload download, NSString filename) + { + return invokeObjcSelf!(void, "download:decideDestinationWithSuggestedFilename:", NSURLDownload, NSString)(download, filename); + } + + void download_didCreateDestination (NSURLDownload download, NSString path) + { + return invokeObjcSelf!(void, "download:didCreateDestination:", NSURLDownload, NSString)(download, path); + } + + void downloadDidFinish (NSURLDownload download) + { + return invokeObjcSelf!(void, "downloadDidFinish:", NSURLDownload)(download); + } + + void download (NSURLDownload download, NSError error) + { + return invokeObjcSelf!(void, "download:didFailWithError:", NSURLDownload, NSError)(download, error); + } + + //mixin ObjcBindMethod!(downloadDidBegin, "downloadDidBegin:"); + //mixin ObjcBindMethod!(download, "download:willSendRequest:redirectResponse:"); + //mixin ObjcBindMethod!(download, "download:didReceiveAuthenticationChallenge:"); + //mixin ObjcBindMethod!(download_didCancelAuthenticationChallenge, "download:didCancelAuthenticationChallenge:"); + //mixin ObjcBindMethod!(download, "download:didReceiveResponse:"); + //mixin ObjcBindMethod!(download, "download:willResumeWithResponse:fromByte:"); + //mixin ObjcBindMethod!(download, "download:didReceiveDataOfLength:"); + //mixin ObjcBindMethod!(download, "download:shouldDecodeSourceDataOfMIMEType:"); + //mixin ObjcBindMethod!(download_decideDestinationWithSuggestedFilename, "download:decideDestinationWithSuggestedFilename:"); + //mixin ObjcBindMethod!(download_didCreateDestination, "download:didCreateDestination:"); + //mixin ObjcBindMethod!(downloadDidFinish, "downloadDidFinish:"); + //mixin ObjcBindMethod!(download, "download:didFailWithError:"); +`; \ No newline at end of file