Mercurial > projects > dstep
diff dstep/foundation/NSURLDownload.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/foundation/NSURLDownload.d Mon Aug 03 15:23:15 2009 +0200 @@ -0,0 +1,108 @@ +/** + * 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.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; + +class NSURLDownload : NSObject +{ + mixin ObjcWrap; + + static bool canResumeDownloadDecodedWithEncodingMIMEType (NSString MIMEType) + { + return invokeObjcSelfClass!(bool, "canResumeDownloadDecodedWithEncodingMIMEType:", NSString)(MIMEType); + } + + Object initWithRequest (NSURLRequest request, Object delegate_) + { + return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); + } + + 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; + } + + Object initWithResumeData (NSData resumeData, Object delegate_, NSString path) + { + return invokeObjcSelf!(Object, "initWithResumeData:delegate:path:", NSData, Object, NSString)(resumeData, delegate_, path); + } + + 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; + } + + void cancel () + { + return invokeObjcSelf!(void, "cancel"); + } + + void setDestination (NSString path, bool allowOverwrite) + { + return invokeObjcSelf!(void, "setDestination:allowOverwrite:", NSString, bool)(path, allowOverwrite); + } + + NSURLRequest request () + { + return invokeObjcSelf!(NSURLRequest, "request"); + } + + NSData resumeData () + { + return invokeObjcSelf!(NSData, "resumeData"); + } + + void setDeletesFileUponFailure (bool deletesFileUponFailure) + { + return invokeObjcSelf!(void, "setDeletesFileUponFailure:", bool)(deletesFileUponFailure); + } + + bool deletesFileUponFailure () + { + return invokeObjcSelf!(bool, "deletesFileUponFailure"); + } +} + +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); +} +