comparison dwt/browser/Download.d @ 345:5abc6f7f7a95

Fixups
author John Reimer <terminal.node@gmail.com>
date Tue, 28 Oct 2008 22:07:01 -0700
parents 8198e6052012
children 9a4d7706df52
comparison
equal deleted inserted replaced
344:8198e6052012 345:5abc6f7f7a95
15 import Util = tango.text.Util; 15 import Util = tango.text.Util;
16 import tango.text.convert.Format; 16 import tango.text.convert.Format;
17 import dwt.dwthelper.utils; 17 import dwt.dwthelper.utils;
18 18
19 import dwt.DWT; 19 import dwt.DWT;
20
21 import dwt.browser.Mozilla;
20 22
21 //import dwt.internal.Compatibility; 23 //import dwt.internal.Compatibility;
22 import XPCOM = dwt.internal.mozilla.XPCOM; 24 import XPCOM = dwt.internal.mozilla.XPCOM;
23 //import dwt.internal.mozilla.XPCOMObject; 25 //import dwt.internal.mozilla.XPCOMObject;
24 import dwt.internal.mozilla.prtime; 26 import dwt.internal.mozilla.prtime;
35 import dwt.internal.mozilla.nsIObserver; 37 import dwt.internal.mozilla.nsIObserver;
36 import dwt.internal.mozilla.nsIDOMWindow; 38 import dwt.internal.mozilla.nsIDOMWindow;
37 import dwt.internal.mozilla.nsIWebProgress; 39 import dwt.internal.mozilla.nsIWebProgress;
38 import dwt.internal.mozilla.nsIRequest; 40 import dwt.internal.mozilla.nsIRequest;
39 import dwt.internal.mozilla.nsStringAPI; 41 import dwt.internal.mozilla.nsStringAPI;
42 import dwt.internal.mozilla.nsEmbedString;
40 43
41 import dwt.layout.GridData; 44 import dwt.layout.GridData;
42 import dwt.layout.GridLayout; 45 import dwt.layout.GridLayout;
43 import dwt.widgets.Button; 46 import dwt.widgets.Button;
44 import dwt.widgets.Event; 47 import dwt.widgets.Event;
96 } 99 }
97 100
98 /* nsIDownload */ 101 /* nsIDownload */
99 102
100 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ 103 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */
104 /* EXCEPTION: not for D */
101 nsresult Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) { 105 nsresult Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) {
102 //nsIURI source = new nsIURI (aSource); 106 //nsIURI source = new nsIURI (aSource);
103 scope auto aSpec = new nsEmbedString; 107 scope auto aSpec = new nsEmbedCString;
104 int rc = aSource.GetHost (cast(nsAString*)aSpec); 108 int rc = aSource.GetHost (cast(nsACString*)aSpec);
105 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 109 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
106 //int length = XPCOM.nsEmbedCString_Length (aSpec); 110 //int length = XPCOM.nsEmbedCString_Length (aSpec);
107 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); 111 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
108 //byte[] dest = new byte[length]; 112 //byte[] dest = new byte[length];
109 //XPCOM.memmove (dest, buffer, length); 113 //XPCOM.memmove (dest, buffer, length);
116 * these interfaces the second argument implements and act accordingly. 120 * these interfaces the second argument implements and act accordingly.
117 */ 121 */
118 String filename = null; 122 String filename = null;
119 //nsISupports supports = new nsISupports (aTarget); 123 //nsISupports supports = new nsISupports (aTarget);
120 nsIURI target = null; 124 nsIURI target = null;
121 rc = aTarget.QueryInterface (nsIURI.IID, cast(void**)&target); 125 rc = aTarget.QueryInterface (&nsIURI.IID, cast(void**)&target);
122 if (rc is 0) { /* >= 1.7 */ 126 if (rc is 0) { /* >= 1.7 */
123 //result[0] = 0; 127 //result[0] = 0;
124 //int /*long*/ aPath = XPCOM.nsEmbedCString_new (); 128 //int /*long*/ aPath = XPCOM.nsEmbedCString_new ();
125 scope auto aPath = new nsEmbedCString; 129 scope auto aPath = new nsEmbedCString;
126 rc = target.GetPath (cast(nsACString*)aPath); 130 rc = target.GetPath (cast(nsACString*)aPath);
129 //buffer = XPCOM.nsEmbedCString_get (aPath); 133 //buffer = XPCOM.nsEmbedCString_get (aPath);
130 //dest = new byte[length]; 134 //dest = new byte[length];
131 //XPCOM.memmove (dest, buffer, length); 135 //XPCOM.memmove (dest, buffer, length);
132 //XPCOM.nsEmbedCString_delete (aPath); 136 //XPCOM.nsEmbedCString_delete (aPath);
133 filename = aPath.toString; 137 filename = aPath.toString;
134 int separator = Util.locatePrior(filename, System.getProperty ("file.separator")); //$NON-NLS-1$ 138 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$
135 filename = filename[separator + 1 .. $]; 139 filename = filename.substring (separator + 1);
136 target.Release (); 140 target.Release ();
137 } else { /* < 1.7 */ 141 } else { /* < 1.7 */
142 // Earlier versions (<1.7) of Mozilla are not really supported
143 // in the D port (yet) because we depend on bindings where the interface
144 // is directly mapped, not wrapped as in the Java SWT case
145 implMissing(__FILE__,__LINE__);
146 /*
138 //nsILocalFile target = new nsILocalFile (aTarget); 147 //nsILocalFile target = new nsILocalFile (aTarget);
139 scope auto aNativeTarget = new nsEmbedCString; 148 scope auto aNativeTarget = new nsEmbedCString;
140 rc = aTarget.GetNativeLeafName (cast(nsACString*)aNativeTarget); 149 rc = aTarget.GetNativeLeafName (cast(nsACString*)aNativeTarget);
141 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 150 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
142 //length = XPCOM.nsEmbedCString_Length (aNativeTarget); 151 //length = XPCOM.nsEmbedCString_Length (aNativeTarget);
143 //buffer = XPCOM.nsEmbedCString_get (aNativeTarget); 152 //buffer = XPCOM.nsEmbedCString_get (aNativeTarget);
144 //dest = new byte[length]; 153 //dest = new byte[length];
145 //XPCOM.memmove (dest, buffer, length); 154 //XPCOM.memmove (dest, buffer, length);
146 //XPCOM.nsEmbedCString_delete (aNativeTarget); 155 //XPCOM.nsEmbedCString_delete (aNativeTarget);
147 filename = aNativeTarget.toString; 156 filename = aNativeTarget.toString;
157 */
148 } 158 }
149 159
150 Listener listener = new class() Listener { 160 Listener listener = new class() Listener {
151 public void handleEvent (Event event) { 161 public void handleEvent (Event event) {
152 if (event.widget is cancel) { 162 if (event.widget is cancel) {
213 223
214 nsresult SetDisplayName (PRUnichar* aDisplayName) { 224 nsresult SetDisplayName (PRUnichar* aDisplayName) {
215 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 225 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
216 } 226 }
217 227
218 nsresult GetStartTime (PRInt64 aStartTime) { 228 nsresult GetStartTime (PRInt64* aStartTime) {
219 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 229 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
220 } 230 }
221 231
222 nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) { 232 nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) {
223 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 233 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
237 247
238 nsresult SetObserver (nsIObserver aObserver) { 248 nsresult SetObserver (nsIObserver aObserver) {
239 if (aObserver !is null) { 249 if (aObserver !is null) {
240 // nsISupports supports = new nsISupports (aObserver); 250 // nsISupports supports = new nsISupports (aObserver);
241 nsIHelperAppLauncher result; 251 nsIHelperAppLauncher result;
242 int rc = aObserver.QueryInterface (nsIHelperAppLauncher.IID, cast(void**)&result); 252 int rc = aObserver.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&result);
243 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 253 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
244 if (result is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); 254 if (result is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
245 helperAppLauncher = result; 255 helperAppLauncher = result;
246 } 256 }
247 return XPCOM.NS_OK; 257 return XPCOM.NS_OK;