diff dwt/internal/cocoa/NSURLHandle.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 8b48be5454ce
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/internal/cocoa/NSURLHandle.d	Sat Aug 09 17:00:02 2008 +0200
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D Programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
+ *******************************************************************************/
+module dwt.internal.cocoa.NSURLHandle;
+
+import dwt.internal.cocoa.id;
+import dwt.internal.cocoa.NSData;
+import dwt.internal.cocoa.NSInteger;
+import dwt.internal.cocoa.NSObject;
+import dwt.internal.cocoa.NSString;
+import dwt.internal.cocoa.NSURL;
+import dwt.internal.cocoa.OS;
+import objc = dwt.internal.objc.runtime;
+
+enum NSURLHandleStatus : NSUInteger
+{
+    NSURLHandleNotLoaded = 0,
+    NSURLHandleLoadSucceeded,
+    NSURLHandleLoadInProgress,
+    NSURLHandleLoadFailed
+}
+
+alias NSURLHandleStatus.NSURLHandleNotLoaded NSURLHandleNotLoaded;
+alias NSURLHandleStatus.NSURLHandleLoadSucceeded NSURLHandleLoadSucceeded;
+alias NSURLHandleStatus.NSURLHandleLoadInProgress NSURLHandleLoadInProgress;
+alias NSURLHandleStatus.NSURLHandleLoadFailed NSURLHandleLoadFailed;
+
+public class NSURLHandle : NSObject
+{
+
+    public this ()
+    {
+        super();
+    }
+
+    public this (objc.id id)
+    {
+        super(id);
+    }
+
+    public static objc.Class URLHandleClassForURL (NSURL anURL)
+    {
+        return cast(objc.Class) OS.objc_msgSend(OS.class_NSURLHandle, OS.sel_URLHandleClassForURL_1, anURL !is null ? anURL.id : null);
+    }
+
+    public void addClient (id client)
+    {
+        OS.objc_msgSend(this.id, OS.sel_addClient_1, client !is null ? client.id : null);
+    }
+
+    public NSData availableResourceData ()
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_availableResourceData);
+        return result !is null ? new NSData(result) : null;
+    }
+
+    public void backgroundLoadDidFailWithReason (NSString reason)
+    {
+        OS.objc_msgSend(this.id, OS.sel_backgroundLoadDidFailWithReason_1, reason !is null ? reason.id : null);
+    }
+
+    public void beginLoadInBackground ()
+    {
+        OS.objc_msgSend(this.id, OS.sel_beginLoadInBackground);
+    }
+
+    public static NSURLHandle cachedHandleForURL (NSURL anURL)
+    {
+        objc.id result = OS.objc_msgSend(OS.class_NSURLHandle, OS.sel_cachedHandleForURL_1, anURL !is null ? anURL.id : null);
+        return result !is null ? new NSURLHandle(result) : null;
+    }
+
+    public static bool canInitWithURL (NSURL anURL)
+    {
+        return OS.objc_msgSend(OS.class_NSURLHandle, OS.sel_canInitWithURL_1, anURL !is null ? anURL.id : null) !is null;
+    }
+
+    public void cancelLoadInBackground ()
+    {
+        OS.objc_msgSend(this.id, OS.sel_cancelLoadInBackground);
+    }
+
+    public void didLoadBytes (NSData newBytes, bool yorn)
+    {
+        OS.objc_msgSend(this.id, OS.sel_didLoadBytes_1loadComplete_1, newBytes !is null ? newBytes.id : null, yorn);
+    }
+
+    public void endLoadInBackground ()
+    {
+        OS.objc_msgSend(this.id, OS.sel_endLoadInBackground);
+    }
+
+    public long expectedResourceDataSize ()
+    {
+        return cast(long) OS.objc_msgSend(this.id, OS.sel_expectedResourceDataSize);
+    }
+
+    public NSString failureReason ()
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_failureReason);
+        return result !is null ? new NSString(result) : null;
+    }
+
+    public void flushCachedData ()
+    {
+        OS.objc_msgSend(this.id, OS.sel_flushCachedData);
+    }
+
+    public id initWithURL (NSURL anURL, bool willCache)
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithURL_1cached_1, anURL !is null ? anURL.id : null, willCache);
+        return result !is null ? new id(result) : null;
+    }
+
+    public void loadInBackground ()
+    {
+        OS.objc_msgSend(this.id, OS.sel_loadInBackground);
+    }
+
+    public NSData loadInForeground ()
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_loadInForeground);
+        return result !is null ? new NSData(result) : null;
+    }
+
+    public id propertyForKey (NSString propertyKey)
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_propertyForKey_1, propertyKey !is null ? propertyKey.id : null);
+        return result !is null ? new id(result) : null;
+    }
+
+    public id propertyForKeyIfAvailable (NSString propertyKey)
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_propertyForKeyIfAvailable_1, propertyKey !is null ? propertyKey.id : null);
+        return result !is null ? new id(result) : null;
+    }
+
+    public static void registerURLHandleClass (objc.Class anURLHandleSubclass)
+    {
+        OS.objc_msgSend(OS.class_NSURLHandle, OS.sel_registerURLHandleClass_1, anURLHandleSubclass);
+    }
+
+    public void removeClient (id client)
+    {
+        OS.objc_msgSend(this.id, OS.sel_removeClient_1, client !is null ? client.id : null);
+    }
+
+    public NSData resourceData ()
+    {
+        objc.id result = OS.objc_msgSend(this.id, OS.sel_resourceData);
+        return result !is null ? new NSData(result) : null;
+    }
+
+    public NSURLHandleStatus status ()
+    {
+        return cast(NSURLHandleStatus) OS.objc_msgSend(this.id, OS.sel_status);
+    }
+
+    public bool writeData (NSData data)
+    {
+        return OS.objc_msgSend(this.id, OS.sel_writeData_1, data !is null ? data.id : null) !is null;
+    }
+
+    public bool writeProperty (id propertyValue, NSString propertyKey)
+    {
+        return OS.objc_msgSend(this.id, OS.sel_writeProperty_1forKey_1, propertyValue !is null ? propertyValue.id : null,
+                propertyKey !is null ? propertyKey.id : null) !is null;
+    }
+
+}