Mercurial > projects > dwt-mac
comparison dwt/browser/Download_1_8.d @ 125:5583f8eeee6c
Synced mozilla with dwt-linux
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 16 Jan 2009 12:49:08 +0100 |
parents | d8635bb48c7c |
children |
comparison
equal
deleted
inserted
replaced
124:540fa4e9974a | 125:5583f8eeee6c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2008 IBM Corporation and others. | 2 * Copyright (c) 2003, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * John Reimer <terminal.node@gmail.com> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.browser.Download_1_8; | 13 module dwt.browser.Download_1_8; |
12 | 14 |
13 import dwt.dwthelper.utils; | 15 import dwt.dwthelper.utils; |
16 import tango.text.convert.Format; | |
14 | 17 |
15 import dwt.DWT; | 18 import dwt.DWT; |
16 import dwt.internal.C; | 19 |
17 import dwt.internal.Compatibility; | 20 import XPCOM = dwt.internal.mozilla.XPCOM; |
18 import dwt.internal.mozilla.XPCOM; | 21 |
19 import dwt.internal.mozilla.XPCOMObject; | 22 import dwt.internal.mozilla.Common; |
23 import dwt.internal.mozilla.prtime; | |
20 import dwt.internal.mozilla.nsICancelable; | 24 import dwt.internal.mozilla.nsICancelable; |
21 import dwt.internal.mozilla.nsID; | 25 import dwt.internal.mozilla.nsID; |
22 import dwt.internal.mozilla.nsIDownload_1_8; | 26 import dwt.internal.mozilla.nsIDownload_1_8; |
23 import dwt.internal.mozilla.nsIProgressDialog_1_8; | 27 import dwt.internal.mozilla.nsIProgressDialog_1_8; |
24 import dwt.internal.mozilla.nsISupports; | 28 import dwt.internal.mozilla.nsISupports; |
25 import dwt.internal.mozilla.nsIURI; | 29 import dwt.internal.mozilla.nsIURI; |
26 import dwt.internal.mozilla.nsIWebProgressListener; | 30 import dwt.internal.mozilla.nsIWebProgressListener; |
31 import dwt.internal.mozilla.nsIMIMEInfo; | |
32 import dwt.internal.mozilla.nsIObserver; | |
33 import dwt.internal.mozilla.nsIDOMWindow; | |
34 import dwt.internal.mozilla.nsIWebProgress; | |
35 import dwt.internal.mozilla.nsIRequest; | |
36 import dwt.internal.mozilla.nsILocalFile; | |
37 import dwt.internal.mozilla.nsStringAPI; | |
38 import dwt.internal.mozilla.nsEmbedString; | |
39 | |
40 import dwt.browser.Mozilla; | |
41 | |
27 import dwt.layout.GridData; | 42 import dwt.layout.GridData; |
28 import dwt.layout.GridLayout; | 43 import dwt.layout.GridLayout; |
29 import dwt.widgets.Button; | 44 import dwt.widgets.Button; |
30 import dwt.widgets.Event; | 45 import dwt.widgets.Event; |
31 import dwt.widgets.Label; | 46 import dwt.widgets.Label; |
32 import dwt.widgets.Listener; | 47 import dwt.widgets.Listener; |
33 import dwt.widgets.Shell; | 48 import dwt.widgets.Shell; |
34 | 49 |
35 /** | 50 class Download_1_8 : nsIProgressDialog_1_8 { |
36 * This class implements the nsIDownload interface for mozilla | |
37 * version 1.8.x. For mozilla versions 1.4 - 1.7.x this interface | |
38 * is implemented by class nsIDownload. Mozilla versions later | |
39 * than 1.8.x do not need to call this interface. | |
40 */ | |
41 class Download_1_8 { | |
42 XPCOMObject supports; | |
43 XPCOMObject download; | |
44 XPCOMObject progressDialog; | |
45 XPCOMObject webProgressListener; | |
46 nsICancelable cancelable; | 51 nsICancelable cancelable; |
47 int refCount = 0; | 52 int refCount = 0; |
48 | 53 |
49 Shell shell; | 54 Shell shell; |
50 Label status; | 55 Label status; |
51 Button cancel; | 56 Button cancel; |
52 | 57 |
53 static final bool is32 = C.PTR_SIZEOF is 4; | 58 //static final bool is32 = C.PTR_SIZEOF is 4; //determine if 32 or 64 bit platform? |
54 | 59 |
55 this () { | 60 this () { |
56 createCOMInterfaces (); | 61 } |
57 } | 62 |
58 | 63 extern(System) |
59 int AddRef () { | 64 nsrefcnt AddRef () { |
60 refCount++; | 65 refCount++; |
61 return refCount; | 66 return refCount; |
62 } | 67 } |
63 | 68 |
64 void createCOMInterfaces () { | 69 extern(System) |
65 /* Create each of the interfaces that this object implements */ | 70 nsresult QueryInterface ( nsID* riid, void** ppvObject) { |
66 supports = new XPCOMObject (new int[] {2, 0, 0}) { | 71 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
67 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 72 |
68 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | 73 if (*riid == nsISupports.IID) { |
69 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | 74 *ppvObject = cast(void*)cast(nsISupports)this; |
70 }; | |
71 | |
72 download = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { | |
73 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
74 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
75 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
76 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3]);} | |
77 public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3], cast(int)/*64*/args[4], cast(int)/*64*/args[5]);} | |
78 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} | |
79 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], cast(int)/*64*/args[2], args[3]);} | |
80 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], cast(int)/*64*/args[2]);} | |
81 public int /*long*/ method8 (int /*long*/[] args) { | |
82 if (args.length is 10) { | |
83 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); | |
84 } else { | |
85 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); | |
86 } | |
87 } | |
88 public int /*long*/ method9 (int /*long*/[] args) { | |
89 if (args.length is 8) { | |
90 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | |
91 } else { | |
92 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); | |
93 } | |
94 } | |
95 public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);} | |
96 public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);} | |
97 public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);} | |
98 public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);} | |
99 public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);} | |
100 public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);} | |
101 public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);} | |
102 public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);} | |
103 public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);} | |
104 public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} | |
105 }; | |
106 | |
107 progressDialog = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { | |
108 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
109 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
110 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
111 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3]);} | |
112 public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3], cast(int)/*64*/args[4], cast(int)/*64*/args[5]);} | |
113 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} | |
114 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], cast(int)/*64*/args[2], args[3]);} | |
115 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], cast(int)/*64*/args[2]);} | |
116 public int /*long*/ method8 (int /*long*/[] args) { | |
117 if (args.length is 10) { | |
118 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); | |
119 } else { | |
120 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); | |
121 } | |
122 } | |
123 public int /*long*/ method9 (int /*long*/[] args) { | |
124 if (args.length is 8) { | |
125 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | |
126 } else { | |
127 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); | |
128 } | |
129 } | |
130 public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);} | |
131 public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);} | |
132 public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);} | |
133 public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);} | |
134 public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);} | |
135 public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);} | |
136 public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);} | |
137 public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);} | |
138 public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);} | |
139 public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} | |
140 public int /*long*/ method20 (int /*long*/[] args) {return Open (args[0]);} | |
141 public int /*long*/ method21 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);} | |
142 public int /*long*/ method22 (int /*long*/[] args) {return SetCancelDownloadOnClose (cast(int)/*64*/args[0]);} | |
143 public int /*long*/ method23 (int /*long*/[] args) {return GetObserver (args[0]);} | |
144 public int /*long*/ method24 (int /*long*/[] args) {return SetObserver (args[0]);} | |
145 public int /*long*/ method25 (int /*long*/[] args) {return GetDialog (args[0]);} | |
146 public int /*long*/ method26 (int /*long*/[] args) {return SetDialog (args[0]);} | |
147 }; | |
148 | |
149 webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) { | |
150 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
151 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
152 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
153 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3]);} | |
154 public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3], cast(int)/*64*/args[4], cast(int)/*64*/args[5]);} | |
155 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} | |
156 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], cast(int)/*64*/args[2], args[3]);} | |
157 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], cast(int)/*64*/args[2]);} | |
158 }; | |
159 } | |
160 | |
161 void disposeCOMInterfaces() { | |
162 if (supports !is null) { | |
163 supports.dispose (); | |
164 supports = null; | |
165 } | |
166 if (download !is null) { | |
167 download.dispose (); | |
168 download = null; | |
169 } | |
170 if (progressDialog !is null) { | |
171 progressDialog.dispose (); | |
172 progressDialog = null; | |
173 } | |
174 if (webProgressListener !is null) { | |
175 webProgressListener.dispose (); | |
176 webProgressListener = null; | |
177 } | |
178 } | |
179 | |
180 int /*long*/ getAddress () { | |
181 return progressDialog.getAddress (); | |
182 } | |
183 | |
184 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
185 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
186 nsID guid = new nsID (); | |
187 XPCOM.memmove (guid, riid, nsID.sizeof); | |
188 | |
189 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
190 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
191 AddRef(); | 75 AddRef(); |
192 return XPCOM.NS_OK; | 76 return XPCOM.NS_OK; |
193 } | 77 } |
194 if (guid.Equals (nsIDownload_1_8.NS_IDOWNLOAD_IID)) { | 78 if (*riid == nsIDownload_1_8.IID) { |
195 XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); | 79 *ppvObject = cast(void*)cast(nsIDownload_1_8)this; |
196 AddRef(); | 80 AddRef(); |
197 return XPCOM.NS_OK; | 81 return XPCOM.NS_OK; |
198 } | 82 } |
199 if (guid.Equals (nsIProgressDialog_1_8.NS_IPROGRESSDIALOG_IID)) { | 83 if (*riid == nsIProgressDialog_1_8.IID) { |
200 XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF); | 84 *ppvObject = cast(void*)cast(nsIProgressDialog_1_8)this; |
201 AddRef(); | 85 AddRef(); |
202 return XPCOM.NS_OK; | 86 return XPCOM.NS_OK; |
203 } | 87 } |
204 if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { | 88 if (*riid == nsIWebProgressListener.IID) { |
205 XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); | 89 *ppvObject = cast(void*)cast(nsIWebProgressListener)this; |
206 AddRef(); | 90 AddRef(); |
207 return XPCOM.NS_OK; | 91 return XPCOM.NS_OK; |
208 } | 92 } |
209 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | 93 *ppvObject = null; |
210 return XPCOM.NS_ERROR_NO_INTERFACE; | 94 return XPCOM.NS_ERROR_NO_INTERFACE; |
211 } | 95 } |
212 | 96 |
213 int Release () { | 97 extern(System) |
98 nsrefcnt Release () { | |
214 refCount--; | 99 refCount--; |
215 if (refCount is 0) disposeCOMInterfaces (); | 100 if (refCount is 0) return 0; |
216 return refCount; | 101 return refCount; |
217 } | 102 } |
218 | 103 |
219 /* nsIDownload */ | 104 /* nsIDownload */ |
220 | 105 |
221 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ | 106 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ |
222 int Init_32 (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, int /*long*/ startTime1, int /*long*/ startTime2, int /*long*/ aTempFile, int /*long*/ aCancelable) { | 107 extern(System) |
108 nsresult Init_32 (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRInt32 startTime1, PRInt32 startTime2, nsILocalFile aTempFile, nsICancelable aCancelable) { | |
223 long startTime = (startTime2 << 32) + startTime1; | 109 long startTime = (startTime2 << 32) + startTime1; |
224 return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); | 110 return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); |
225 } | 111 } |
226 | 112 |
227 int Init (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, long startTime, int /*long*/ aTempFile, int /*long*/ aCancelable) { | 113 // FIXME: I've hardcoded the string values in place of Compatibility.getMessage calls in |
228 cancelable = new nsICancelable (aCancelable); | 114 // the Init method; this will need fixing in future releases. -JJR |
229 nsIURI source = new nsIURI (aSource); | 115 extern(System) |
230 int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); | 116 nsresult Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, nsILocalFile aTempFile, nsICancelable aCancelable) { |
231 int rc = source.GetHost (aSpec); | 117 cancelable = aCancelable; |
232 if (rc !is XPCOM.NS_OK) Mozilla.error(rc); | 118 // nsIURI source = new nsIURI (aSource); |
233 int length = XPCOM.nsEmbedCString_Length (aSpec); | 119 scope auto aSpec = new nsEmbedCString; |
234 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); | 120 int rc = aSource.GetHost (cast(nsACString*)aSpec); |
235 byte[] dest = new byte[length]; | 121 if (rc !is XPCOM.NS_OK) Mozilla.error(rc,__FILE__,__LINE__); |
236 XPCOM.memmove (dest, buffer, length); | 122 //int length = XPCOM.nsEmbedCString_Length (aSpec); |
237 XPCOM.nsEmbedCString_delete (aSpec); | 123 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); |
238 String url = new String (dest); | 124 //byte[] dest = new byte[length]; |
239 | 125 //XPCOM.memmove (dest, buffer, length); |
240 nsIURI target = new nsIURI (aTarget); | 126 //XPCOM.nsEmbedCString_delete (aSpec); |
241 int /*long*/ aPath = XPCOM.nsEmbedCString_new (); | 127 String url = aSpec.toString; |
242 rc = target.GetPath (aPath); | 128 |
129 //nsIURI target = new nsIURI (aTarget); | |
130 scope auto aPath = new nsEmbedCString; | |
131 rc = aTarget.GetPath (cast(nsACString*)aPath); | |
243 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 132 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
244 length = XPCOM.nsEmbedCString_Length (aPath); | 133 //length = XPCOM.nsEmbedCString_Length (aPath); |
245 buffer = XPCOM.nsEmbedCString_get (aPath); | 134 //buffer = XPCOM.nsEmbedCString_get (aPath); |
246 dest = new byte[length]; | 135 //dest = new byte[length]; |
247 XPCOM.memmove (dest, buffer, length); | 136 //XPCOM.memmove (dest, buffer, length); |
248 XPCOM.nsEmbedCString_delete (aPath); | 137 //XPCOM.nsEmbedCString_delete (aPath); |
249 String filename = new String (dest); | 138 String filename = aPath.toString; |
139 //int separator = locatePrior(filename, System.getProperty ("file.separator")); | |
250 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ | 140 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ |
141 // NOTE: Not sure if this is correct; watch out for bugs here. -JJR | |
251 filename = filename.substring (separator + 1); | 142 filename = filename.substring (separator + 1); |
252 | 143 |
253 Listener listener = new Listener() { | 144 Listener listener = new class() Listener { |
254 public void handleEvent (Event event) { | 145 public void handleEvent (Event event) { |
255 if (event.widget is cancel) { | 146 if (event.widget is cancel) { |
256 shell.close (); | 147 shell.close (); |
257 } | 148 } |
258 if (cancelable !is null) { | 149 if (cancelable !is null) { |
259 int rc = cancelable.Cancel (XPCOM.NS_BINDING_ABORTED); | 150 int rc = cancelable.Cancel (XPCOM.NS_BINDING_ABORTED); |
260 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 151 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); |
261 } | 152 } |
262 shell = null; | 153 shell = null; |
263 cancelable = null; | 154 cancelable = null; |
264 } | 155 } |
265 }; | 156 }; |
266 shell = new Shell (DWT.DIALOG_TRIM); | 157 shell = new Shell (DWT.DIALOG_TRIM); |
267 String msg = Compatibility.getMessage ("DWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ | 158 // FIXME: A working Compatibility.getMessage has not been ported yet |
268 shell.setText (msg); | 159 // Strings hardcoded for now. |
160 //String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ | |
161 shell.setText ("Download: " ~ filename); | |
269 GridLayout gridLayout = new GridLayout (); | 162 GridLayout gridLayout = new GridLayout (); |
270 gridLayout.marginHeight = 15; | 163 gridLayout.marginHeight = 15; |
271 gridLayout.marginWidth = 15; | 164 gridLayout.marginWidth = 15; |
272 gridLayout.verticalSpacing = 20; | 165 gridLayout.verticalSpacing = 20; |
273 shell.setLayout (gridLayout); | 166 shell.setLayout (gridLayout); |
274 msg = Compatibility.getMessage ("DWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ | 167 //msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ |
275 new Label (shell, DWT.SIMPLE).setText (msg); | 168 auto lbl = new Label (shell, DWT.SIMPLE); |
169 lbl.setText ("Saving " ~ filename ~ " from " ~ url ); | |
276 status = new Label (shell, DWT.SIMPLE); | 170 status = new Label (shell, DWT.SIMPLE); |
277 msg = Compatibility.getMessage ("DWT_Download_Started"); //$NON-NLS-1$ | 171 //msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$ |
278 status.setText (msg); | 172 status.setText ("Downloading..."); |
279 GridData data = new GridData (); | 173 GridData data = new GridData (); |
280 data.grabExcessHorizontalSpace = true; | 174 data.grabExcessHorizontalSpace = true; |
281 data.grabExcessVerticalSpace = true; | 175 data.grabExcessVerticalSpace = true; |
282 status.setLayoutData (data); | 176 status.setLayoutData (data); |
283 | 177 |
284 cancel = new Button (shell, DWT.PUSH); | 178 cancel = new Button (shell, DWT.PUSH); |
285 cancel.setText (DWT.getMessage ("DWT_Cancel")); //$NON-NLS-1$ | 179 cancel.setText( "Cancel" ); |
180 //cancel.setText (DWT.getMessage ("SWT_Cancel")); //$NON-NLS-1$ | |
286 data = new GridData (); | 181 data = new GridData (); |
287 data.horizontalAlignment = GridData.CENTER; | 182 data.horizontalAlignment = GridData.CENTER; |
288 cancel.setLayoutData (data); | 183 cancel.setLayoutData (data); |
289 cancel.addListener (DWT.Selection, listener); | 184 cancel.addListener (DWT.Selection, listener); |
290 shell.addListener (DWT.Close, listener); | 185 shell.addListener (DWT.Close, listener); |
291 shell.pack (); | 186 shell.pack (); |
292 shell.open (); | 187 shell.open (); |
293 return XPCOM.NS_OK; | 188 return XPCOM.NS_OK; |
294 } | 189 } |
295 | 190 |
296 int GetAmountTransferred (int /*long*/ arg0) { | 191 extern(System) |
297 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 192 nsresult GetAmountTransferred (PRUint64* arg0) { |
298 } | 193 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
299 | 194 } |
300 int GetCancelable (int /*long*/ arg0) { | 195 |
301 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 196 extern(System) |
302 } | 197 nsresult GetCancelable (nsICancelable* arg0) { |
303 | 198 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
304 int GetDisplayName (int /*long*/ aDisplayName) { | 199 } |
305 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 200 |
306 } | 201 extern(System) |
307 | 202 nsresult GetDisplayName (PRUnichar** aDisplayName) { |
308 int GetMIMEInfo (int /*long*/ aMIMEInfo) { | 203 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
309 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 204 } |
310 } | 205 |
311 | 206 extern(System) |
312 int GetPercentComplete (int /*long*/ aPercentComplete) { | 207 nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) { |
313 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 208 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
314 } | 209 } |
315 | 210 |
316 int GetSize (int /*long*/ arg0) { | 211 extern(System) |
317 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 212 nsresult GetPercentComplete (PRInt32* aPercentComplete) { |
318 } | 213 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
319 | 214 } |
320 int GetSource (int /*long*/ aSource) { | 215 |
321 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 216 extern(System) |
322 } | 217 nsresult GetSize (PRUint64* arg0) { |
323 | 218 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
324 int GetStartTime (int /*long*/ aStartTime) { | 219 } |
325 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 220 |
326 } | 221 extern(System) |
327 | 222 nsresult GetSource (nsIURI* aSource) { |
328 int GetTarget (int /*long*/ aTarget) { | 223 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
329 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 224 } |
330 } | 225 |
331 | 226 extern(System) |
332 int GetTargetFile (int /*long*/ arg0) { | 227 nsresult GetStartTime (PRInt64* aStartTime) { |
228 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
229 } | |
230 | |
231 extern(System) | |
232 nsresult GetTarget (nsIURI* aTarget) { | |
233 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
234 } | |
235 | |
236 extern(System) | |
237 nsresult GetTargetFile (nsILocalFile* arg0) { | |
333 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 238 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
334 } | 239 } |
335 | 240 |
336 /* nsIProgressDialog */ | 241 /* nsIProgressDialog */ |
337 int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) { | 242 |
338 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 243 extern(System) |
339 } | 244 nsresult GetCancelDownloadOnClose (PRBool* aCancelDownloadOnClose) { |
340 | 245 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
341 int GetDialog (int /*long*/ aDialog) { | 246 } |
342 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 247 |
343 } | 248 extern(System) |
344 | 249 nsresult GetDialog (nsIDOMWindow* aDialog) { |
345 int GetObserver (int /*long*/ aObserver) { | 250 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
346 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 251 } |
347 } | 252 |
348 | 253 extern(System) |
349 int Open (int /*long*/ aParent) { | 254 nsresult GetObserver (nsIObserver* aObserver) { |
350 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 255 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
351 } | 256 } |
352 | 257 |
353 int SetCancelDownloadOnClose (int aCancelDownloadOnClose) { | 258 extern(System) |
354 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 259 nsresult Open (nsIDOMWindow aParent) { |
355 } | 260 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
356 | 261 } |
357 int SetDialog (int /*long*/ aDialog) { | 262 |
358 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 263 extern(System) |
359 } | 264 nsresult SetCancelDownloadOnClose (PRBool aCancelDownloadOnClose) { |
360 | 265 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
361 int SetObserver (int /*long*/ aObserver) { | 266 } |
267 | |
268 extern(System) | |
269 nsresult SetDialog (nsIDOMWindow aDialog) { | |
270 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
271 } | |
272 | |
273 extern(System) | |
274 nsresult SetObserver (nsIObserver aObserver) { | |
362 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 275 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
363 } | 276 } |
364 | 277 |
365 /* nsIWebProgressListener */ | 278 /* nsIWebProgressListener */ |
366 | 279 |
367 int OnLocationChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aLocation) { | 280 extern(System) |
368 return XPCOM.NS_OK; | 281 nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) { |
369 } | 282 return XPCOM.NS_OK; |
370 | 283 } |
371 int OnProgressChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress) { | 284 |
285 extern(System) | |
286 nsresult OnProgressChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { | |
372 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); | 287 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); |
373 } | 288 } |
374 | 289 /++ |
375 /* Note. The last 4 args in the original interface are defined as PRInt64. These each translate into two java ints. */ | 290 /* Note. The last 4 args in the original interface are defined as PRInt64. These each translate into two java ints. */ |
376 int OnProgressChange64_32 (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aCurSelfProgress1, int /*long*/ aCurSelfProgress2, int /*long*/ aMaxSelfProgress1, int /*long*/ aMaxSelfProgress2, int /*long*/ aCurTotalProgress1, int /*long*/ aCurTotalProgress2, int /*long*/ aMaxTotalProgress1, int /*long*/ aMaxTotalProgress2) { | 291 nsresult OnProgressChange64_32 (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aCurSelfProgress1, int /*long*/ aCurSelfProgress2, int /*long*/ aMaxSelfProgress1, int /*long*/ aMaxSelfProgress2, int /*long*/ aCurTotalProgress1, int /*long*/ aCurTotalProgress2, int /*long*/ aMaxTotalProgress1, int /*long*/ aMaxTotalProgress2) { |
377 long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1; | 292 long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1; |
378 long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1; | 293 long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1; |
379 long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1; | 294 long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1; |
380 long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1; | 295 long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1; |
381 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); | 296 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); |
382 } | 297 } |
383 | 298 ++/ |
384 int OnProgressChange64 (int /*long*/ aWebProgress, int /*long*/ aRequest, long aCurSelfProgress, long aMaxSelfProgress, long aCurTotalProgress, long aMaxTotalProgress) { | 299 extern(System) |
300 nsresult OnProgressChange64 (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt64 aCurSelfProgress, PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress, PRInt64 aMaxTotalProgress) { | |
385 long currentKBytes = aCurTotalProgress / 1024; | 301 long currentKBytes = aCurTotalProgress / 1024; |
386 long totalKBytes = aMaxTotalProgress / 1024; | 302 long totalKBytes = aMaxTotalProgress / 1024; |
387 if (shell !is null && !shell.isDisposed ()) { | 303 if (shell !is null && !shell.isDisposed ()) { |
388 Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)}; | 304 //Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)}; |
389 String statusMsg = Compatibility.getMessage ("DWT_Download_Status", arguments); //$NON-NLS-1$ | 305 //String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ |
306 String statusMsg = Format("Download: {0} KB of {1} KB", currentKBytes, totalKBytes); | |
390 status.setText (statusMsg); | 307 status.setText (statusMsg); |
391 shell.layout (true); | 308 shell.layout (true); |
392 shell.getDisplay ().update (); | 309 shell.getDisplay ().update (); |
393 } | 310 } |
394 return XPCOM.NS_OK; | 311 return XPCOM.NS_OK; |
395 } | 312 } |
396 | 313 |
397 int OnSecurityChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int state) { | 314 extern(System) |
398 return XPCOM.NS_OK; | 315 nsresult OnSecurityChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 state) { |
399 } | 316 return XPCOM.NS_OK; |
400 | 317 } |
401 int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateFlags, int aStatus) { | 318 |
319 extern(System) | |
320 nsresult OnStateChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 aStateFlags, nsresult aStatus) { | |
402 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { | 321 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { |
403 cancelable = null; | 322 cancelable = null; |
404 if (shell !is null && !shell.isDisposed ()) shell.dispose (); | 323 if (shell !is null && !shell.isDisposed ()) shell.dispose (); |
405 shell = null; | 324 shell = null; |
406 } | 325 } |
407 return XPCOM.NS_OK; | 326 return XPCOM.NS_OK; |
408 } | 327 } |
409 | 328 |
410 int OnStatusChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStatus, int /*long*/ aMessage) { | 329 extern(System) |
330 nsresult OnStatusChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsresult aStatus, PRUnichar* aMessage) { | |
411 return XPCOM.NS_OK; | 331 return XPCOM.NS_OK; |
412 } | 332 } |
413 } | 333 } |