diff 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
line wrap: on
line diff
--- a/dwt/browser/Download_1_8.d	Fri Aug 08 15:25:08 2008 +0200
+++ b/dwt/browser/Download_1_8.d	Sun Aug 10 22:25:43 2008 -0700
@@ -16,7 +16,7 @@
 
 import dwt.DWT;
 
-import dwt.internal.Compatibility;
+// import dwt.internal.Compatibility;
 import dwt.internal.mozilla.XPCOM;
 import dwt.internal.mozilla.nsICancelable;
 import dwt.internal.mozilla.nsID;
@@ -92,31 +92,36 @@
     return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable);
 }
 
+// FIXME: I've hardcoded the string values in place of Compatibility.getMessage calls in 
+// the Init method; this will need fixing in future releases. -JJR
+
 int Init (nsIURI aSource, nsIURI aTarget, nsAstring* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, nsILocalFile aTempFile, nsICancelable aCancelable) {
-    // cancelable = new nsICancelable (aCancelable);
+    cancelable = aCancelable;
     // nsIURI source = new nsIURI (aSource);
     scope auto aSpec = new nsEmbedCString;
-    int rc = source.GetHost (cast(nsaSpec);
+    int rc = aSource.GetHost (cast(nsACString*)aSpec);
     if (rc !is XPCOM.NS_OK) Mozilla.error(rc);
-    int length = XPCOM.nsEmbedCString_Length (aSpec);
-    int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
-    byte[] dest = new byte[length];
-    XPCOM.memmove (dest, buffer, length);
-    XPCOM.nsEmbedCString_delete (aSpec);
-    String url = new String (dest);
+    //int length = XPCOM.nsEmbedCString_Length (aSpec);
+    //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
+    //byte[] dest = new byte[length];
+    //XPCOM.memmove (dest, buffer, length);
+    //XPCOM.nsEmbedCString_delete (aSpec);
+    String url = aSpec.toString;
 
-    nsIURI target = new nsIURI (aTarget);
-    int /*long*/ aPath = XPCOM.nsEmbedCString_new ();
-    rc = target.GetPath (aPath);
+    //nsIURI target = new nsIURI (aTarget);
+    scope auto aPath = new nsEmbedCString;
+    rc = aTarget.GetPath (aPath);
     if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
-    length = XPCOM.nsEmbedCString_Length (aPath);
-    buffer = XPCOM.nsEmbedCString_get (aPath);
-    dest = new byte[length];
-    XPCOM.memmove (dest, buffer, length);
-    XPCOM.nsEmbedCString_delete (aPath);
-    String filename = new String (dest);
-    int separator = filename.lastIndexOf (System.getProperty ("file.separator"));   //$NON-NLS-1$
-    filename = filename.substring (separator + 1);
+    //length = XPCOM.nsEmbedCString_Length (aPath);
+    //buffer = XPCOM.nsEmbedCString_get (aPath);
+    //dest = new byte[length];
+    //XPCOM.memmove (dest, buffer, length);
+    //XPCOM.nsEmbedCString_delete (aPath);
+    String filename = aPath.toString;
+    int separator = locatePrior(filename, System.getProperty ("file.separator"));
+    //int separator = filename.lastIndexOf (System.getProperty ("file.separator"));   //$NON-NLS-1$
+    // NOTE: Not sure if this is correct; watch out for bugs here. -JJR
+    filename = filename[separator + 1 .. $];
 
     Listener listener = new Listener() {
         public void handleEvent (Event event) {
@@ -132,25 +137,28 @@
         }
     };
     shell = new Shell (DWT.DIALOG_TRIM);
-    String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$
-    shell.setText (msg);
+// FIXME: A working Compatibility.getMessage has not been ported yet
+// Strings hardcoded for now.
+    //String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$
+    shell.setText ("Download: " ~ filename);
     GridLayout gridLayout = new GridLayout ();
     gridLayout.marginHeight = 15;
     gridLayout.marginWidth = 15;
     gridLayout.verticalSpacing = 20;
     shell.setLayout (gridLayout);
-    msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$
-    new Label (shell, DWT.SIMPLE).setText (msg);
+    //msg = Compatibility.getMessage ("SWT_Download_Location", new Object[] {filename, url}); //$NON-NLS-1$
+    new Label (shell, DWT.SIMPLE).setText ("Saving " ~ filename ~ " from " ~ url );
     status = new Label (shell, DWT.SIMPLE);
-    msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$
-    status.setText (msg);
+    //msg = Compatibility.getMessage ("SWT_Download_Started"); //$NON-NLS-1$
+    status.setText ("Downloading...");
     GridData data = new GridData ();
     data.grabExcessHorizontalSpace = true;
     data.grabExcessVerticalSpace = true;
     status.setLayoutData (data);
     
     cancel = new Button (shell, DWT.PUSH);
-    cancel.setText (DWT.getMessage ("SWT_Cancel")); //$NON-NLS-1$
+    cancel.setText( "Cancel" ); 
+    //cancel.setText (DWT.getMessage ("SWT_Cancel")); //$NON-NLS-1$
     data = new GridData ();
     data.horizontalAlignment = GridData.CENTER;
     cancel.setLayoutData (data);
@@ -161,100 +169,101 @@
     return XPCOM.NS_OK;
 }
 
-int GetAmountTransferred (int /*long*/ arg0) {
+nsresult GetAmountTransferred (PRUInt64* arg0) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetCancelable (int /*long*/ arg0) {
+nsresult GetCancelable (nsICancelable* arg0) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetDisplayName (int /*long*/ aDisplayName) {
+nsresult GetDisplayName (PRUnichar** aDisplayName) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetMIMEInfo (int /*long*/ aMIMEInfo) {
+nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetPercentComplete (int /*long*/ aPercentComplete) {
+nsresult GetPercentComplete (PRInt32* aPercentComplete) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetSize (int /*long*/ arg0) {
+nsresult GetSize (PRUInt64* arg0) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetSource (int /*long*/ aSource) {
+nsresult GetSource (nsIURI* aSource) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetStartTime (int /*long*/ aStartTime) {
+nsresult GetStartTime (PRInt64* aStartTime) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetTarget (int /*long*/ aTarget) {
+nsresult GetTarget (nsIURI* aTarget) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetTargetFile (int /*long*/ arg0) {
+nsresult GetTargetFile (nsILocalFile* arg0) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* nsIProgressDialog */
-int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) {
+nsresult GetCancelDownloadOnClose (PRBool* aCancelDownloadOnClose) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetDialog (int /*long*/ aDialog) {
+nsresult GetDialog (nsIDOMWindow* aDialog) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int GetObserver (int /*long*/ aObserver) {
+nsresult GetObserver (nsIOBserver* aObserver) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int Open (int /*long*/ aParent) {
+nsresult Open (nsIDOMWindow aParent) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int SetCancelDownloadOnClose (int aCancelDownloadOnClose) {
+nsresult SetCancelDownloadOnClose (PRBool aCancelDownloadOnClose) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int SetDialog (int /*long*/ aDialog) {
+nsresult SetDialog (nsIDOMWindow aDialog) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
-int SetObserver (int /*long*/ aObserver) {
+nsresult SetObserver (nsIOBserver aObserver) {
     return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* nsIWebProgressListener */
 
-int OnLocationChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aLocation) {
+nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) {
     return XPCOM.NS_OK;
 }
 
-int OnProgressChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress) {
+nsresult OnProgressChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) {
     return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
 }
-
+/++
 /* Note. The last 4 args in the original interface are defined as PRInt64. These each translate into two java ints. */
-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) {
+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) {
     long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1;
     long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1;
     long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1;
     long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1;
     return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
 }
-
-int OnProgressChange64 (int /*long*/ aWebProgress, int /*long*/ aRequest, long aCurSelfProgress, long aMaxSelfProgress, long aCurTotalProgress, long aMaxTotalProgress) {
+++/
+nsresult OnProgressChange64 (nsIWebProgress aWebProgress, nsIRequest aRequest, PRInt64 aCurSelfProgress, PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress, PRInt64 aMaxTotalProgress) {
     long currentKBytes = aCurTotalProgress / 1024;
     long totalKBytes = aMaxTotalProgress / 1024;
     if (shell !is null && !shell.isDisposed ()) {
-        Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)};
-        String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$
+        //Object[] arguments = {new Long (currentKBytes), new Long (totalKBytes)};
+        //String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$
+        String statusMsg = format("Download:  {0} KB of {1} KB", currentKBytes, totalKBytes); 
         status.setText (statusMsg);
         shell.layout (true);
         shell.getDisplay ().update ();
@@ -262,11 +271,11 @@
     return XPCOM.NS_OK;
 }
 
-int OnSecurityChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int state) {
+nsresult OnSecurityChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUInt32 state) {
     return XPCOM.NS_OK;
 }
 
-int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateFlags, int aStatus) {
+nsresult OnStateChange (nsIWebProgress aWebProgress, nsIRequest aRequest, PRUInt32 aStateFlags, nsresult aStatus) {
     if ((aStateFlags & nsIWebProgressListener.STATE_STOP) !is 0) {
         cancelable = null;
         if (shell !is null && !shell.isDisposed ()) shell.dispose ();
@@ -275,7 +284,7 @@
     return XPCOM.NS_OK;
 }   
 
-int OnStatusChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStatus, int /*long*/ aMessage) {
+nsresult OnStatusChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsresult aStatus, PRUnichar* aMessage) {
     return XPCOM.NS_OK;
 }       
 }