Mercurial > projects > dwt-linux
comparison dwt/browser/Download_1_8.d @ 298:eec6ddb07873
More xpcom/mozilla port
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Sun, 10 Aug 2008 22:25:43 -0700 |
parents | b0bd1789106b |
children | 942da4b6558a |
comparison
equal
deleted
inserted
replaced
297:2f204a4aebc6 | 298:eec6ddb07873 |
---|---|
14 | 14 |
15 import dwt.dwthelper.utils; | 15 import dwt.dwthelper.utils; |
16 | 16 |
17 import dwt.DWT; | 17 import dwt.DWT; |
18 | 18 |
19 import dwt.internal.Compatibility; | 19 // import dwt.internal.Compatibility; |
20 import dwt.internal.mozilla.XPCOM; | 20 import dwt.internal.mozilla.XPCOM; |
21 import dwt.internal.mozilla.nsICancelable; | 21 import dwt.internal.mozilla.nsICancelable; |
22 import dwt.internal.mozilla.nsID; | 22 import dwt.internal.mozilla.nsID; |
23 import dwt.internal.mozilla.nsIDownload_1_8; | 23 import dwt.internal.mozilla.nsIDownload_1_8; |
24 import dwt.internal.mozilla.nsIProgressDialog_1_8; | 24 import dwt.internal.mozilla.nsIProgressDialog_1_8; |
90 int Init_32 (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRInt32 startTime1, PRIn32 startTime2, nsILocalFile aTempFile, nsICancelable aCancelable) { | 90 int Init_32 (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRInt32 startTime1, PRIn32 startTime2, nsILocalFile aTempFile, nsICancelable aCancelable) { |
91 long startTime = (startTime2 << 32) + startTime1; | 91 long startTime = (startTime2 << 32) + startTime1; |
92 return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); | 92 return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); |
93 } | 93 } |
94 | 94 |
95 // FIXME: I've hardcoded the string values in place of Compatibility.getMessage calls in | |
96 // the Init method; this will need fixing in future releases. -JJR | |
97 | |
95 int Init (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, nsILocalFile aTempFile, nsICancelable aCancelable) { | 98 int Init (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, nsILocalFile aTempFile, nsICancelable aCancelable) { |
96 // cancelable = new nsICancelable (aCancelable); | 99 cancelable = aCancelable; |
97 // nsIURI source = new nsIURI (aSource); | 100 // nsIURI source = new nsIURI (aSource); |
98 scope auto aSpec = new nsEmbedCString; | 101 scope auto aSpec = new nsEmbedCString; |
99 int rc = source.GetHost (cast(nsaSpec); | 102 int rc = aSource.GetHost (cast(nsACString*)aSpec); |
100 if (rc !is XPCOM.NS_OK) Mozilla.error(rc); | 103 if (rc !is XPCOM.NS_OK) Mozilla.error(rc); |
101 int length = XPCOM.nsEmbedCString_Length (aSpec); | 104 //int length = XPCOM.nsEmbedCString_Length (aSpec); |
102 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); | 105 //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); |
103 byte[] dest = new byte[length]; | 106 //byte[] dest = new byte[length]; |
104 XPCOM.memmove (dest, buffer, length); | 107 //XPCOM.memmove (dest, buffer, length); |
105 XPCOM.nsEmbedCString_delete (aSpec); | 108 //XPCOM.nsEmbedCString_delete (aSpec); |
106 String url = new String (dest); | 109 String url = aSpec.toString; |
107 | 110 |
108 nsIURI target = new nsIURI (aTarget); | 111 //nsIURI target = new nsIURI (aTarget); |
109 int /*long*/ aPath = XPCOM.nsEmbedCString_new (); | 112 scope auto aPath = new nsEmbedCString; |
110 rc = target.GetPath (aPath); | 113 rc = aTarget.GetPath (aPath); |
111 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 114 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
112 length = XPCOM.nsEmbedCString_Length (aPath); | 115 //length = XPCOM.nsEmbedCString_Length (aPath); |
113 buffer = XPCOM.nsEmbedCString_get (aPath); | 116 //buffer = XPCOM.nsEmbedCString_get (aPath); |
114 dest = new byte[length]; | 117 //dest = new byte[length]; |
115 XPCOM.memmove (dest, buffer, length); | 118 //XPCOM.memmove (dest, buffer, length); |
116 XPCOM.nsEmbedCString_delete (aPath); | 119 //XPCOM.nsEmbedCString_delete (aPath); |
117 String filename = new String (dest); | 120 String filename = aPath.toString; |
118 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ | 121 int separator = locatePrior(filename, System.getProperty ("file.separator")); |
119 filename = filename.substring (separator + 1); | 122 //int separator = filename.lastIndexOf (System.getProperty ("file.separator")); //$NON-NLS-1$ |
123 // NOTE: Not sure if this is correct; watch out for bugs here. -JJR | |
124 filename = filename[separator + 1 .. $]; | |
120 | 125 |
121 Listener listener = new Listener() { | 126 Listener listener = new Listener() { |
122 public void handleEvent (Event event) { | 127 public void handleEvent (Event event) { |
123 if (event.widget is cancel) { | 128 if (event.widget is cancel) { |
124 shell.close (); | 129 shell.close (); |
130 shell = null; | 135 shell = null; |
131 cancelable = null; | 136 cancelable = null; |
132 } | 137 } |
133 }; | 138 }; |
134 shell = new Shell (DWT.DIALOG_TRIM); | 139 shell = new Shell (DWT.DIALOG_TRIM); |
135 String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ | 140 // FIXME: A working Compatibility.getMessage has not been ported yet |
136 shell.setText (msg); | 141 // Strings hardcoded for now. |
142 //String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ | |
143 shell.setText ("Download: " ~ filename); | |
137 GridLayout gridLayout = new GridLayout (); | 144 GridLayout gridLayout = new GridLayout (); |
138 gridLayout.marginHeight = 15; | 145 gridLayout.marginHeight = 15; |
139 gridLayout.marginWidth = 15; | 146 gridLayout.marginWidth = 15; |
140 gridLayout.verticalSpacing = 20; | 147 gridLayout.verticalSpacing = 20; |
141 shell.setLayout (gridLayout); | 148 shell.setLayout (gridLayout); |
142 msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ | 149 //msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$ |
143 new Label (shell, DWT.SIMPLE).setText (msg); | 150 new Label (shell, DWT.SIMPLE).setText ("Saving " ~ filename ~ " from " ~ url ); |
144 status = new Label (shell, DWT.SIMPLE); | 151 status = new Label (shell, DWT.SIMPLE); |
145 msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$ | 152 //msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$ |
146 status.setText (msg); | 153 status.setText ("Downloading..."); |
147 GridData data = new GridData (); | 154 GridData data = new GridData (); |
148 data.grabExcessHorizontalSpace = true; | 155 data.grabExcessHorizontalSpace = true; |
149 data.grabExcessVerticalSpace = true; | 156 data.grabExcessVerticalSpace = true; |
150 status.setLayoutData (data); | 157 status.setLayoutData (data); |
151 | 158 |
152 cancel = new Button (shell, DWT.PUSH); | 159 cancel = new Button (shell, DWT.PUSH); |
153 cancel.setText (DWT.getMessage ("SWT_Cancel")); //$NON-NLS-1$ | 160 cancel.setText( "Cancel" ); |
161 //cancel.setText (DWT.getMessage ("SWT_Cancel")); //$NON-NLS-1$ | |
154 data = new GridData (); | 162 data = new GridData (); |
155 data.horizontalAlignment = GridData.CENTER; | 163 data.horizontalAlignment = GridData.CENTER; |
156 cancel.setLayoutData (data); | 164 cancel.setLayoutData (data); |
157 cancel.addListener (DWT.Selection, listener); | 165 cancel.addListener (DWT.Selection, listener); |
158 shell.addListener (DWT.Close, listener); | 166 shell.addListener (DWT.Close, listener); |
159 shell.pack (); | 167 shell.pack (); |
160 shell.open (); | 168 shell.open (); |
161 return XPCOM.NS_OK; | 169 return XPCOM.NS_OK; |
162 } | 170 } |
163 | 171 |
164 int GetAmountTransferred (int /*long*/ arg0) { | 172 nsresult GetAmountTransferred (PRUInt64* arg0) { |
165 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 173 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
166 } | 174 } |
167 | 175 |
168 int GetCancelable (int /*long*/ arg0) { | 176 nsresult GetCancelable (nsICancelable* arg0) { |
169 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 177 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
170 } | 178 } |
171 | 179 |
172 int GetDisplayName (int /*long*/ aDisplayName) { | 180 nsresult GetDisplayName (PRUnichar** aDisplayName) { |
173 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 181 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
174 } | 182 } |
175 | 183 |
176 int GetMIMEInfo (int /*long*/ aMIMEInfo) { | 184 nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) { |
177 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 185 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
178 } | 186 } |
179 | 187 |
180 int GetPercentComplete (int /*long*/ aPercentComplete) { | 188 nsresult GetPercentComplete (PRInt32* aPercentComplete) { |
181 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 189 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
182 } | 190 } |
183 | 191 |
184 int GetSize (int /*long*/ arg0) { | 192 nsresult GetSize (PRUInt64* arg0) { |
185 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 193 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
186 } | 194 } |
187 | 195 |
188 int GetSource (int /*long*/ aSource) { | 196 nsresult GetSource (nsIURI* aSource) { |
189 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 197 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
190 } | 198 } |
191 | 199 |
192 int GetStartTime (int /*long*/ aStartTime) { | 200 nsresult GetStartTime (PRInt64* aStartTime) { |
193 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 201 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
194 } | 202 } |
195 | 203 |
196 int GetTarget (int /*long*/ aTarget) { | 204 nsresult GetTarget (nsIURI* aTarget) { |
197 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 205 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
198 } | 206 } |
199 | 207 |
200 int GetTargetFile (int /*long*/ arg0) { | 208 nsresult GetTargetFile (nsILocalFile* arg0) { |
201 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 209 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
202 } | 210 } |
203 | 211 |
204 /* nsIProgressDialog */ | 212 /* nsIProgressDialog */ |
205 int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) { | 213 nsresult GetCancelDownloadOnClose (PRBool* aCancelDownloadOnClose) { |
206 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 214 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
207 } | 215 } |
208 | 216 |
209 int GetDialog (int /*long*/ aDialog) { | 217 nsresult GetDialog (nsIDOMWindow* aDialog) { |
210 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 218 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
211 } | 219 } |
212 | 220 |
213 int GetObserver (int /*long*/ aObserver) { | 221 nsresult GetObserver (nsIOBserver* aObserver) { |
214 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 222 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
215 } | 223 } |
216 | 224 |
217 int Open (int /*long*/ aParent) { | 225 nsresult Open (nsIDOMWindow aParent) { |
218 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 226 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
219 } | 227 } |
220 | 228 |
221 int SetCancelDownloadOnClose (int aCancelDownloadOnClose) { | 229 nsresult SetCancelDownloadOnClose (PRBool aCancelDownloadOnClose) { |
222 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 230 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
223 } | 231 } |
224 | 232 |
225 int SetDialog (int /*long*/ aDialog) { | 233 nsresult SetDialog (nsIDOMWindow aDialog) { |
226 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 234 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
227 } | 235 } |
228 | 236 |
229 int SetObserver (int /*long*/ aObserver) { | 237 nsresult SetObserver (nsIOBserver aObserver) { |
230 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 238 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
231 } | 239 } |
232 | 240 |
233 /* nsIWebProgressListener */ | 241 /* nsIWebProgressListener */ |
234 | 242 |
235 int OnLocationChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aLocation) { | 243 nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) { |
236 return XPCOM.NS_OK; | 244 return XPCOM.NS_OK; |
237 } | 245 } |
238 | 246 |
239 int OnProgressChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress) { | 247 nsresult OnProgressChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) { |
240 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); | 248 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); |
241 } | 249 } |
242 | 250 /++ |
243 /* Note. The last 4 args in the original interface are defined as PRInt64. These each translate into two java ints. */ | 251 /* Note. The last 4 args in the original interface are defined as PRInt64. These each translate into two java ints. */ |
244 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) { | 252 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) { |
245 long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1; | 253 long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1; |
246 long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1; | 254 long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1; |
247 long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1; | 255 long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1; |
248 long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1; | 256 long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1; |
249 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); | 257 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); |
250 } | 258 } |
251 | 259 ++/ |
252 int OnProgressChange64 (int /*long*/ aWebProgress, int /*long*/ aRequest, long aCurSelfProgress, long aMaxSelfProgress, long aCurTotalProgress, long aMaxTotalProgress) { | 260 nsresult OnProgressChange64 (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt64 aCurSelfProgress, PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress, PRInt64 aMaxTotalProgress) { |
253 long currentKBytes = aCurTotalProgress / 1024; | 261 long currentKBytes = aCurTotalProgress / 1024; |
254 long totalKBytes = aMaxTotalProgress / 1024; | 262 long totalKBytes = aMaxTotalProgress / 1024; |
255 if (shell !is null && !shell.isDisposed ()) { | 263 if (shell !is null && !shell.isDisposed ()) { |
256 Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)}; | 264 //Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)}; |
257 String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ | 265 //String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ |
266 String statusMsg = format("Download: {0} KB of {1} KB", currentKBytes, totalKBytes); | |
258 status.setText (statusMsg); | 267 status.setText (statusMsg); |
259 shell.layout (true); | 268 shell.layout (true); |
260 shell.getDisplay ().update (); | 269 shell.getDisplay ().update (); |
261 } | 270 } |
262 return XPCOM.NS_OK; | 271 return XPCOM.NS_OK; |
263 } | 272 } |
264 | 273 |
265 int OnSecurityChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int state) { | 274 nsresult OnSecurityChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUInt32 state) { |
266 return XPCOM.NS_OK; | 275 return XPCOM.NS_OK; |
267 } | 276 } |
268 | 277 |
269 int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateFlags, int aStatus) { | 278 nsresult OnStateChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUInt32 aStateFlags, nsresult aStatus) { |
270 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { | 279 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) { |
271 cancelable = null; | 280 cancelable = null; |
272 if (shell !is null && !shell.isDisposed ()) shell.dispose (); | 281 if (shell !is null && !shell.isDisposed ()) shell.dispose (); |
273 shell = null; | 282 shell = null; |
274 } | 283 } |
275 return XPCOM.NS_OK; | 284 return XPCOM.NS_OK; |
276 } | 285 } |
277 | 286 |
278 int OnStatusChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStatus, int /*long*/ aMessage) { | 287 nsresult OnStatusChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsresult aStatus, PRUnichar* aMessage) { |
279 return XPCOM.NS_OK; | 288 return XPCOM.NS_OK; |
280 } | 289 } |
281 } | 290 } |