Mercurial > projects > dwt-mac
comparison dwt/browser/Download.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; | 13 module dwt.browser.Download; |
12 | 14 |
15 import Util = tango.text.Util; | |
16 import tango.text.convert.Format; | |
13 import dwt.dwthelper.utils; | 17 import dwt.dwthelper.utils; |
14 | 18 |
15 import dwt.DWT; | 19 import dwt.DWT; |
16 import dwt.internal.C; | 20 |
17 import dwt.internal.Compatibility; | 21 import dwt.browser.Mozilla; |
18 import dwt.internal.mozilla.XPCOM; | 22 |
19 import dwt.internal.mozilla.XPCOMObject; | 23 import XPCOM = dwt.internal.mozilla.XPCOM; |
24 | |
25 import dwt.internal.mozilla.prtime; | |
26 import dwt.internal.mozilla.Common; | |
20 import dwt.internal.mozilla.nsID; | 27 import dwt.internal.mozilla.nsID; |
21 import dwt.internal.mozilla.nsIDownload; | 28 import dwt.internal.mozilla.nsIDownload; |
22 import dwt.internal.mozilla.nsIHelperAppLauncher; | 29 import dwt.internal.mozilla.nsIHelperAppLauncher; |
23 import dwt.internal.mozilla.nsILocalFile; | 30 import dwt.internal.mozilla.nsILocalFile; |
24 import dwt.internal.mozilla.nsIProgressDialog; | 31 import dwt.internal.mozilla.nsIProgressDialog; |
25 import dwt.internal.mozilla.nsISupports; | 32 import dwt.internal.mozilla.nsISupports; |
26 import dwt.internal.mozilla.nsIURI; | 33 import dwt.internal.mozilla.nsIURI; |
27 import dwt.internal.mozilla.nsIWebProgressListener; | 34 import dwt.internal.mozilla.nsIWebProgressListener; |
35 import dwt.internal.mozilla.nsIMIMEInfo; | |
36 import dwt.internal.mozilla.nsIObserver; | |
37 import dwt.internal.mozilla.nsIDOMWindow; | |
38 import dwt.internal.mozilla.nsIWebProgress; | |
39 import dwt.internal.mozilla.nsIRequest; | |
40 import dwt.internal.mozilla.nsStringAPI; | |
41 import dwt.internal.mozilla.nsEmbedString; | |
42 | |
28 import dwt.layout.GridData; | 43 import dwt.layout.GridData; |
29 import dwt.layout.GridLayout; | 44 import dwt.layout.GridLayout; |
30 import dwt.widgets.Button; | 45 import dwt.widgets.Button; |
31 import dwt.widgets.Event; | 46 import dwt.widgets.Event; |
32 import dwt.widgets.Label; | 47 import dwt.widgets.Label; |
33 import dwt.widgets.Listener; | 48 import dwt.widgets.Listener; |
34 import dwt.widgets.Shell; | 49 import dwt.widgets.Shell; |
35 | 50 |
36 /** | 51 class Download : nsIProgressDialog { |
37 * This class implements the nsIDownload interface for mozilla | |
38 * versions 1.4 - 1.7.x. For mozilla version 1.8.x this interface | |
39 * is implemented by class nsIDownload_1_8. Later versions of | |
40 * mozilla do not need to call this interface. | |
41 */ | |
42 class Download { | |
43 XPCOMObject supports; | |
44 XPCOMObject download; | |
45 XPCOMObject progressDialog; | |
46 XPCOMObject webProgressListener; | |
47 nsIHelperAppLauncher helperAppLauncher; | 52 nsIHelperAppLauncher helperAppLauncher; |
48 int refCount = 0; | 53 int refCount = 0; |
49 | 54 |
50 Shell shell; | 55 Shell shell; |
51 Label status; | 56 Label status; |
52 Button cancel; | 57 Button cancel; |
53 | 58 |
54 this () { | 59 this () { |
55 createCOMInterfaces (); | 60 } |
56 } | 61 |
57 | 62 extern(System) |
58 int AddRef () { | 63 nsrefcnt AddRef () { |
59 refCount++; | 64 refCount++; |
60 return refCount; | 65 return refCount; |
61 } | 66 } |
62 | 67 |
63 void createCOMInterfaces () { | 68 extern(System) |
64 /* Create each of the interfaces that this object implements */ | 69 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
65 supports = new XPCOMObject (new int[] {2, 0, 0}) { | 70 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
66 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 71 |
67 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | 72 if (*riid == nsISupports.IID) { |
68 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | 73 *ppvObject = cast(void*)cast(nsISupports)this; |
69 }; | |
70 | |
71 download = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1}) { | |
72 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
73 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
74 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
75 public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
76 public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);} | |
77 public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);} | |
78 public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);} | |
79 public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);} | |
80 public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);} | |
81 public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);} | |
82 public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);} | |
83 public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} | |
84 public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);} | |
85 public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);} | |
86 public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);} | |
87 public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);} | |
88 }; | |
89 | |
90 progressDialog = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { | |
91 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
92 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
93 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
94 public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
95 public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);} | |
96 public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);} | |
97 public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);} | |
98 public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);} | |
99 public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);} | |
100 public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);} | |
101 public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);} | |
102 public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} | |
103 public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);} | |
104 public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);} | |
105 public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);} | |
106 public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);} | |
107 public int /*long*/ method16 (int /*long*/[] args) {return Open (args[0]);} | |
108 public int /*long*/ method17 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);} | |
109 public int /*long*/ method18 (int /*long*/[] args) {return SetCancelDownloadOnClose (cast(int)/*64*/args[0]);} | |
110 public int /*long*/ method19 (int /*long*/[] args) {return GetDialog (args[0]);} | |
111 public int /*long*/ method20 (int /*long*/[] args) {return SetDialog (args[0]);} | |
112 }; | |
113 | |
114 webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) { | |
115 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
116 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
117 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
118 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], cast(int)/*64*/args[2], cast(int)/*64*/args[3]);} | |
119 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]);} | |
120 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} | |
121 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], cast(int)/*64*/args[2], args[3]);} | |
122 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], cast(int)/*64*/args[2]);} | |
123 }; | |
124 } | |
125 | |
126 void disposeCOMInterfaces () { | |
127 if (supports !is null) { | |
128 supports.dispose (); | |
129 supports = null; | |
130 } | |
131 if (download !is null) { | |
132 download.dispose (); | |
133 download = null; | |
134 } | |
135 if (progressDialog !is null) { | |
136 progressDialog.dispose (); | |
137 progressDialog = null; | |
138 } | |
139 if (webProgressListener !is null) { | |
140 webProgressListener.dispose (); | |
141 webProgressListener = null; | |
142 } | |
143 } | |
144 | |
145 int /*long*/ getAddress () { | |
146 return progressDialog.getAddress (); | |
147 } | |
148 | |
149 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
150 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
151 nsID guid = new nsID (); | |
152 XPCOM.memmove (guid, riid, nsID.sizeof); | |
153 | |
154 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
155 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
156 AddRef(); | 74 AddRef(); |
157 return XPCOM.NS_OK; | 75 return XPCOM.NS_OK; |
158 } | 76 } |
159 if (guid.Equals (nsIDownload.NS_IDOWNLOAD_IID)) { | 77 if (*riid == nsIDownload.IID) { |
160 XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); | 78 *ppvObject = cast(void*)cast(nsIDownload)this; |
161 AddRef(); | 79 AddRef(); |
162 return XPCOM.NS_OK; | 80 return XPCOM.NS_OK; |
163 } | 81 } |
164 if (guid.Equals (nsIProgressDialog.NS_IPROGRESSDIALOG_IID)) { | 82 if (*riid == nsIProgressDialog.IID) { |
165 XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF); | 83 *ppvObject = cast(void*)cast(nsIProgressDialog)this; |
166 AddRef(); | 84 AddRef(); |
167 return XPCOM.NS_OK; | 85 return XPCOM.NS_OK; |
168 } | 86 } |
169 if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { | 87 if (*riid == nsIWebProgressListener.IID) { |
170 XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); | 88 *ppvObject = cast(void*)cast(nsIWebProgressListener)this; |
171 AddRef(); | 89 AddRef(); |
172 return XPCOM.NS_OK; | 90 return XPCOM.NS_OK; |
173 } | 91 } |
174 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | 92 *ppvObject = null; |
175 return XPCOM.NS_ERROR_NO_INTERFACE; | 93 return XPCOM.NS_ERROR_NO_INTERFACE; |
176 } | 94 } |
177 | 95 |
178 int Release () { | 96 extern(System) |
97 nsrefcnt Release () { | |
179 refCount--; | 98 refCount--; |
180 if (refCount is 0) disposeCOMInterfaces (); | 99 if (refCount is 0) return 0; // nonsensical condition: will fix later -JJR |
181 return refCount; | 100 return refCount; |
182 } | 101 } |
183 | 102 |
184 /* nsIDownload */ | 103 /* nsIDownload */ |
185 | 104 |
186 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ | 105 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ |
187 int Init (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, int /*long*/ startTime1, int /*long*/ startTime2, int /*long*/ aPersist) { | 106 /* EXCEPTION: not for D */ |
188 nsIURI source = new nsIURI (aSource); | 107 |
189 int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); | 108 extern(System) |
190 int rc = source.GetHost (aSpec); | 109 nsresult Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) { |
110 //nsIURI source = new nsIURI (aSource); | |
111 scope auto aSpec = new nsEmbedCString; | |
112 int rc = aSource.GetHost (cast(nsACString*)aSpec); | |
191 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 113 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
192 int length = XPCOM.nsEmbedCString_Length (aSpec); | 114 //int length = XPCOM.nsEmbedCString_Length (aSpec); |
193 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); | 115 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); |
194 byte[] dest = new byte[length]; | 116 //byte[] dest = new byte[length]; |
195 XPCOM.memmove (dest, buffer, length); | 117 //XPCOM.memmove (dest, buffer, length); |
196 XPCOM.nsEmbedCString_delete (aSpec); | 118 //XPCOM.nsEmbedCString_delete (aSpec); |
197 String url = new String (dest); | 119 String url = aSpec.toString; |
198 | 120 |
199 /* | 121 /* |
200 * As of mozilla 1.7 the second argument of the nsIDownload interface's | 122 * As of mozilla 1.7 the second argument of the nsIDownload interface's |
201 * Init function changed from nsILocalFile to nsIURI. Detect which of | 123 * Init function changed from nsILocalFile to nsIURI. Detect which of |
202 * these interfaces the second argument implements and act accordingly. | 124 * these interfaces the second argument implements and act accordingly. |
203 */ | 125 */ |
204 String filename = null; | 126 String filename = null; |
205 nsISupports supports = new nsISupports (aTarget); | 127 nsISupports supports = cast(nsISupports)aTarget; |
206 int /*long*/[] result = new int /*long*/[1]; | 128 nsIURI target; |
207 rc = supports.QueryInterface (nsIURI.NS_IURI_IID, result); | 129 rc = supports.QueryInterface (&nsIURI.IID, cast(void**)&target); |
208 if (rc is XPCOM.NS_OK) { /* >= 1.7 */ | 130 if (rc is 0) { /* >= 1.7 */ |
209 nsIURI target = new nsIURI (result[0]); | 131 //result[0] = 0; |
210 result[0] = 0; | 132 //int /*long*/ aPath = XPCOM.nsEmbedCString_new (); |
211 int /*long*/ aPath = XPCOM.nsEmbedCString_new (); | 133 scope auto aPath = new nsEmbedCString; |
212 rc = target.GetPath (aPath); | 134 rc = target.GetPath (cast(nsACString*)aPath); |
213 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 135 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); |
214 length = XPCOM.nsEmbedCString_Length (aPath); | 136 //length = XPCOM.nsEmbedCString_Length (aPath); |
215 buffer = XPCOM.nsEmbedCString_get (aPath); | 137 //buffer = XPCOM.nsEmbedCString_get (aPath); |
216 dest = new byte[length]; | 138 //dest = new byte[length]; |
217 XPCOM.memmove (dest, buffer, length); | 139 //XPCOM.memmove (dest, buffer, length); |
218 XPCOM.nsEmbedCString_delete (aPath); | 140 //XPCOM.nsEmbedCString_delete (aPath); |
219 filename = new String (dest); | 141 filename = aPath.toString; |
220 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ | 142 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ |
221 filename = filename.substring (separator + 1); | 143 filename = filename.substring (separator + 1); |
222 target.Release (); | 144 target.Release (); |
223 } else { /* < 1.7 */ | 145 } else { /* < 1.7 */ |
224 nsILocalFile target = new nsILocalFile (aTarget); | 146 nsILocalFile target2 = cast(nsILocalFile) aTarget; |
225 int /*long*/ aNativeTarget = XPCOM.nsEmbedCString_new (); | 147 scope auto aNativeTarget = new nsEmbedCString; |
226 rc = target.GetNativeLeafName (aNativeTarget); | 148 rc = target2.GetNativeLeafName (cast(nsACString*)aNativeTarget); |
227 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 149 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); |
228 length = XPCOM.nsEmbedCString_Length (aNativeTarget); | 150 //length = XPCOM.nsEmbedCString_Length (aNativeTarget); |
229 buffer = XPCOM.nsEmbedCString_get (aNativeTarget); | 151 //buffer = XPCOM.nsEmbedCString_get (aNativeTarget); |
230 dest = new byte[length]; | 152 //dest = new byte[length]; |
231 XPCOM.memmove (dest, buffer, length); | 153 //XPCOM.memmove (dest, buffer, length); |
232 XPCOM.nsEmbedCString_delete (aNativeTarget); | 154 //XPCOM.nsEmbedCString_delete (aNativeTarget); |
233 filename = new String (dest); | 155 filename = aNativeTarget.toString; |
234 } | 156 } |
235 | 157 |
236 Listener listener = new Listener () { | 158 Listener listener = new class() Listener { |
237 public void handleEvent (Event event) { | 159 public void handleEvent (Event event) { |
238 if (event.widget is cancel) { | 160 if (event.widget is cancel) { |
239 shell.close (); | 161 shell.close (); |
240 } | 162 } |
241 if (helperAppLauncher !is null) { | 163 if (helperAppLauncher !is null) { |
245 shell = null; | 167 shell = null; |
246 helperAppLauncher = null; | 168 helperAppLauncher = null; |
247 } | 169 } |
248 }; | 170 }; |
249 shell = new Shell (DWT.DIALOG_TRIM); | 171 shell = new Shell (DWT.DIALOG_TRIM); |
250 String msg = Compatibility.getMessage ("DWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ | 172 //String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ |
251 shell.setText (msg); | 173 shell.setText ("Download: " ~ filename); |
252 GridLayout gridLayout = new GridLayout (); | 174 GridLayout gridLayout = new GridLayout (); |
253 gridLayout.marginHeight = 15; | 175 gridLayout.marginHeight = 15; |
254 gridLayout.marginWidth = 15; | 176 gridLayout.marginWidth = 15; |
255 gridLayout.verticalSpacing = 20; | 177 gridLayout.verticalSpacing = 20; |
256 shell.setLayout(gridLayout); | 178 shell.setLayout(gridLayout); |
257 msg = Compatibility.getMessage ("DWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ | 179 //msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ |
258 new Label (shell, DWT.SIMPLE).setText (msg); | 180 auto lbl = new Label (shell, DWT.SIMPLE); |
181 lbl.setText ("Saving " ~ filename ~ " from " ~ url); | |
259 status = new Label (shell, DWT.SIMPLE); | 182 status = new Label (shell, DWT.SIMPLE); |
260 msg = Compatibility.getMessage ("DWT_Download_Started"); //$NON-NLS-1$ | 183 //msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$ |
261 status.setText (msg); | 184 status.setText ("Downloading..."); |
262 GridData data = new GridData (); | 185 GridData data = new GridData (); |
263 data.grabExcessHorizontalSpace = true; | 186 data.grabExcessHorizontalSpace = true; |
264 data.grabExcessVerticalSpace = true; | 187 data.grabExcessVerticalSpace = true; |
265 status.setLayoutData (data); | 188 status.setLayoutData (data); |
266 | 189 |
267 cancel = new Button (shell, DWT.PUSH); | 190 cancel = new Button (shell, DWT.PUSH); |
268 cancel.setText (DWT.getMessage ("DWT_Cancel")); //$NON-NLS-1$ | 191 cancel.setText ("Cancel"); //$NON-NLS-1$ |
269 data = new GridData (); | 192 data = new GridData (); |
270 data.horizontalAlignment = GridData.CENTER; | 193 data.horizontalAlignment = GridData.CENTER; |
271 cancel.setLayoutData (data); | 194 cancel.setLayoutData (data); |
272 cancel.addListener (DWT.Selection, listener); | 195 cancel.addListener (DWT.Selection, listener); |
273 shell.addListener (DWT.Close, listener); | 196 shell.addListener (DWT.Close, listener); |
274 shell.pack (); | 197 shell.pack (); |
275 shell.open (); | 198 shell.open (); |
276 return XPCOM.NS_OK; | 199 return XPCOM.NS_OK; |
277 } | 200 } |
278 | 201 |
279 int GetSource (int /*long*/ aSource) { | 202 extern(System) |
280 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 203 nsresult GetSource (nsIURI* aSource) { |
281 } | 204 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
282 | 205 } |
283 int GetTarget (int /*long*/ aTarget) { | 206 |
284 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 207 extern(System) |
285 } | 208 nsresult GetTarget (nsIURI* aTarget) { |
286 | 209 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
287 int GetPersist (int /*long*/ aPersist) { | 210 } |
288 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 211 |
289 } | 212 extern(System) |
290 | 213 nsresult GetPersist (PRBool* aPersist) { |
291 int GetPercentComplete (int /*long*/ aPercentComplete) { | 214 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
292 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 215 } |
293 } | 216 |
294 | 217 extern(System) |
295 int GetDisplayName (int /*long*/ aDisplayName) { | 218 nsresult GetPercentComplete (PRInt32* aPercentComplete) { |
296 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 219 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
297 } | 220 } |
298 | 221 |
299 int SetDisplayName (int /*long*/ aDisplayName) { | 222 extern(System) |
300 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 223 nsresult GetDisplayName (PRUnichar** aDisplayName) { |
301 } | 224 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
302 | 225 } |
303 int GetStartTime (int /*long*/ aStartTime) { | 226 |
304 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 227 extern(System) |
305 } | 228 nsresult SetDisplayName (PRUnichar* aDisplayName) { |
306 | 229 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
307 int GetMIMEInfo (int /*long*/ aMIMEInfo) { | 230 } |
308 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 231 |
309 } | 232 extern(System) |
310 | 233 nsresult GetStartTime (PRInt64* aStartTime) { |
311 int GetListener (int /*long*/ aListener) { | 234 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
312 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 235 } |
313 } | 236 |
314 | 237 extern(System) |
315 int SetListener (int /*long*/ aListener) { | 238 nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) { |
316 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 239 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
317 } | 240 } |
318 | 241 |
319 int GetObserver (int /*long*/ aObserver) { | 242 extern(System) |
320 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 243 nsresult GetListener (nsIWebProgressListener* aListener) { |
321 } | 244 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
322 | 245 } |
323 int SetObserver (int /*long*/ aObserver) { | 246 |
324 if (aObserver !is 0) { | 247 extern(System) |
325 nsISupports supports = new nsISupports (aObserver); | 248 nsresult SetListener (nsIWebProgressListener aListener) { |
326 int /*long*/[] result = new int /*long*/[1]; | 249 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
327 int rc = supports.QueryInterface (nsIHelperAppLauncher.NS_IHELPERAPPLAUNCHER_IID, result); | 250 } |
251 | |
252 extern(System) | |
253 nsresult GetObserver (nsIObserver* aObserver) { | |
254 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
255 } | |
256 | |
257 extern(System) | |
258 nsresult SetObserver (nsIObserver aObserver) { | |
259 if (aObserver !is null) { | |
260 // nsISupports supports = new nsISupports (aObserver); | |
261 nsIHelperAppLauncher result; | |
262 int rc = aObserver.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&result); | |
328 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 263 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
329 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | 264 if (result is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); |
330 helperAppLauncher = new nsIHelperAppLauncher (result[0]); | 265 helperAppLauncher = result; |
331 } | 266 } |
332 return XPCOM.NS_OK; | 267 return XPCOM.NS_OK; |
333 } | 268 } |
334 | 269 |
335 /* nsIProgressDialog */ | 270 /* nsIProgressDialog */ |
336 int Open (int /*long*/ aParent) { | 271 |
337 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 272 extern(System) |
338 } | 273 nsresult Open (nsIDOMWindow aParent) { |
339 | 274 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
340 int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) { | 275 } |
341 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 276 |
342 } | 277 extern(System) |
343 | 278 nsresult GetCancelDownloadOnClose (PRBool* aCancelDownloadOnClose) { |
344 int SetCancelDownloadOnClose (int aCancelDownloadOnClose) { | 279 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
345 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 280 } |
346 } | 281 |
347 | 282 extern(System) |
348 int GetDialog (int /*long*/ aDialog) { | 283 nsresult SetCancelDownloadOnClose (PRBool aCancelDownloadOnClose) { |
349 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 284 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
350 } | 285 } |
351 | 286 |
352 int SetDialog (int /*long*/ aDialog) { | 287 extern(System) |
288 nsresult GetDialog (nsIDOMWindow* aDialog) { | |
289 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
290 } | |
291 | |
292 extern(System) | |
293 nsresult SetDialog (nsIDOMWindow aDialog) { | |
353 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 294 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
354 } | 295 } |
355 | 296 |
356 /* nsIWebProgressListener */ | 297 /* nsIWebProgressListener */ |
357 | 298 |
358 int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateFlags, int aStatus) { | 299 extern(System) |
300 nsresult OnStateChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 aStateFlags, nsresult aStatus) { | |
359 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { | 301 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { |
360 if (helperAppLauncher !is null) helperAppLauncher.Release (); | 302 if (helperAppLauncher !is null) helperAppLauncher.Release (); |
361 helperAppLauncher = null; | 303 helperAppLauncher = null; |
362 if (shell !is null && !shell.isDisposed ()) shell.dispose (); | 304 if (shell !is null && !shell.isDisposed ()) shell.dispose (); |
363 shell = null; | 305 shell = null; |
364 } | 306 } |
365 return XPCOM.NS_OK; | 307 return XPCOM.NS_OK; |
366 } | 308 } |
367 | 309 |
368 int OnProgressChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress) { | 310 extern(System) |
311 nsresult OnProgressChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { | |
369 int currentKBytes = aCurTotalProgress / 1024; | 312 int currentKBytes = aCurTotalProgress / 1024; |
370 int totalKBytes = aMaxTotalProgress / 1024; | 313 int totalKBytes = aMaxTotalProgress / 1024; |
371 if (shell !is null && !shell.isDisposed ()) { | 314 if (shell !is null && !shell.isDisposed ()) { |
372 Object[] arguments = {new Integer (currentKBytes), new Integer (totalKBytes)}; | 315 //Object[] arguments = {new Integer (currentKBytes), new Integer (totalKBytes)}; |
373 String statusMsg = Compatibility.getMessage ("DWT_Download_Status", arguments); //$NON-NLS-1$ | 316 //String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ |
374 status.setText (statusMsg); | 317 status.setText (Format("Download: {0} KB of {1} KB", currentKBytes, totalKBytes)); |
375 shell.layout (true); | 318 shell.layout (true); |
376 shell.getDisplay ().update (); | 319 shell.getDisplay ().update (); |
377 } | 320 } |
378 return XPCOM.NS_OK; | 321 return XPCOM.NS_OK; |
379 } | 322 } |
380 | 323 |
381 int OnLocationChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aLocation) { | 324 extern(System) |
382 return XPCOM.NS_OK; | 325 nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) { |
383 } | 326 return XPCOM.NS_OK; |
384 | 327 } |
385 int OnStatusChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStatus, int /*long*/ aMessage) { | 328 |
386 return XPCOM.NS_OK; | 329 extern(System) |
387 } | 330 nsresult OnStatusChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsresult aStatus, PRUnichar* aMessage) { |
388 | 331 return XPCOM.NS_OK; |
389 int OnSecurityChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int state) { | 332 } |
390 return XPCOM.NS_OK; | 333 |
391 } | 334 extern(System) |
392 } | 335 nsresult OnSecurityChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUint32 state) { |
336 return XPCOM.NS_OK; | |
337 } | |
338 } |