Mercurial > projects > dwt-linux
diff dwt/browser/Download.d @ 298:eec6ddb07873
More xpcom/mozilla port
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Sun, 10 Aug 2008 22:25:43 -0700 |
parents | 44258e0b6687 |
children | 942da4b6558a |
line wrap: on
line diff
--- a/dwt/browser/Download.d Fri Aug 08 15:25:08 2008 +0200 +++ b/dwt/browser/Download.d Sun Aug 10 22:25:43 2008 -0700 @@ -12,11 +12,13 @@ *******************************************************************************/ module dwt.browser.Download; +import Util = tango.text.Util; +import tango.text.convert.Format; import dwt.dwthelper.utils; import dwt.DWT; -import dwt.internal.Compatibility; +//import dwt.internal.Compatibility; import dwt.internal.mozilla.XPCOM; import dwt.internal.mozilla.XPCOMObject; import dwt.internal.mozilla.nsID; @@ -46,12 +48,12 @@ this () { } -int AddRef () { +nsrefcnt AddRef () { refCount++; return refCount; } -int QueryInterface (nsID* riid, void** ppvObject) { +nsresult QueryInterface (nsID* riid, void** ppvObject) { if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; if (*riid == nsISupports.IID)) { @@ -78,9 +80,9 @@ return XPCOM.NS_ERROR_NO_INTERFACE; } -int Release () { +nsrefcnt Release () { refCount--; - if (refCount is 0) return 0; + if (refCount is 0) return 0; // nonsensical condition: will fix later -JJR return refCount; } @@ -88,16 +90,16 @@ /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ int Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) { - nsIURI source = new nsIURI (aSource); + //nsIURI source = new nsIURI (aSource); scope auto aSpec = new nsEmbedString; - int rc = source.GetHost (cast(nsAString*)aSpec); + int rc = aSource.GetHost (cast(nsAString*)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; /* * As of mozilla 1.7 the second argument of the nsIDownload interface's @@ -105,35 +107,35 @@ * these interfaces the second argument implements and act accordingly. */ String filename = null; - nsISupports supports = new nsISupports (aTarget); - int /*long*/[] result = new int /*long*/[1]; - rc = supports.QueryInterface (nsIURI.NS_IURI_IID, result); + //nsISupports supports = new nsISupports (aTarget); + nsIURI target = null; + rc = aTarget.QueryInterface (nsIURI.IID, cast(void**)&target); if (rc is 0) { /* >= 1.7 */ - nsIURI target = new nsIURI (result[0]); - result[0] = 0; - int /*long*/ aPath = XPCOM.nsEmbedCString_new (); - rc = target.GetPath (aPath); + //result[0] = 0; + //int /*long*/ aPath = XPCOM.nsEmbedCString_new (); + scope auto aPath = new nsEmbedCString; + rc = target.GetPath (cast(nsACString*)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); - 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); + filename = aPath.toString; + int separator = Util.locatePrior(filename, System.getProperty ("file.separator")); //$NON-NLS-1$ + filename = filename[separator + 1 .. $]; target.Release (); } else { /* < 1.7 */ - nsILocalFile target = new nsILocalFile (aTarget); - int /*long*/ aNativeTarget = XPCOM.nsEmbedCString_new (); - rc = target.GetNativeLeafName (aNativeTarget); + //nsILocalFile target = new nsILocalFile (aTarget); + scope auto aNativeTarget = new nsEmbedCString; + rc = aTarget.GetNativeLeafName (cast(nsACString*)aNativeTarget); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - length = XPCOM.nsEmbedCString_Length (aNativeTarget); - buffer = XPCOM.nsEmbedCString_get (aNativeTarget); - dest = new byte[length]; - XPCOM.memmove (dest, buffer, length); - XPCOM.nsEmbedCString_delete (aNativeTarget); - filename = new String (dest); + //length = XPCOM.nsEmbedCString_Length (aNativeTarget); + //buffer = XPCOM.nsEmbedCString_get (aNativeTarget); + //dest = new byte[length]; + //XPCOM.memmove (dest, buffer, length); + //XPCOM.nsEmbedCString_delete (aNativeTarget); + filename = aNativeTarget.toString; } Listener listener = new Listener () { @@ -150,25 +152,25 @@ } }; shell = new Shell (DWT.DIALOG_TRIM); - String msg = Compatibility.getMessage ("SWT_Download_File", new Object[] {filename}); //$NON-NLS-1$ - shell.setText (msg); + //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"); //$NON-NLS-1$ data = new GridData (); data.horizontalAlignment = GridData.CENTER; cancel.setLayoutData (data); @@ -179,43 +181,43 @@ return XPCOM.NS_OK; } -int GetSource (int /*long*/ aSource) { +nsresult GetSource (nsIURI* aSource) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetTarget (int /*long*/ aTarget) { +nsresult GetTarget (nsIURI* aTarget) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetPersist (PRBool* aPersist) { +nsresult GetPersist (PRBool* aPersist) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetPercentComplete (int /*long*/ aPercentComplete) { +nsresult GetPercentComplete (PRInt32* aPercentComplete) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetDisplayName (int /*long*/ aDisplayName) { +nsresult GetDisplayName (PRUnichar** aDisplayName) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int SetDisplayName (int /*long*/ aDisplayName) { +nsresult SetDisplayName (PRUNichar* aDisplayName) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetStartTime (int /*long*/ aStartTime) { +nsresult GetStartTime (PRInt64 aStartTime) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetMIMEInfo (int /*long*/ aMIMEInfo) { +nsresult GetMIMEInfo (nsIMIMEInfo* aMIMEInfo) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetListener (int /*long*/ aListener) { +nsresult GetListener (nsIWebProgressListener* aListener) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int SetListener (int /*long*/ aListener) { +nsresult SetListener (nsIWebProgressListener aListener) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } @@ -224,41 +226,41 @@ } nsresult SetObserver (nsIOBserver aObserver) { - if (aObserver !is 0) { - nsISupports supports = new nsISupports (aObserver); - int /*long*/[] result = new int /*long*/[1]; - int rc = supports.QueryInterface (nsIHelperAppLauncher.NS_IHELPERAPPLAUNCHER_IID, result); + if (aObserver !is null) { + // nsISupports supports = new nsISupports (aObserver); + nsIHelperAppLauncher result; + int rc = aObserver.QueryInterface (nsIHelperAppLauncher.IID, cast(void**)&result); if (rc !is XPCOM.NS_OK) Mozilla.error (rc); - if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); - helperAppLauncher = new nsIHelperAppLauncher (result[0]); + if (result is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); + helperAppLauncher = result; } return XPCOM.NS_OK; } /* nsIProgressDialog */ -nsresult Open (int /*long*/ aParent) { +nsresult Open (nsIDOMWindow aParent) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) { +nsresult GetCancelDownloadOnClose (PRBool* aCancelDownloadOnClose) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int SetCancelDownloadOnClose (int aCancelDownloadOnClose) { +nsresult SetCancelDownloadOnClose (PRBool aCancelDownloadOnClose) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int GetDialog (int /*long*/ aDialog) { +nsresult GetDialog (nsIDOMWindow* aDialog) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } -int SetDialog (int /*long*/ aDialog) { +nsresult SetDialog (nsIDOMWindow aDialog) { return XPCOM.NS_ERROR_NOT_IMPLEMENTED; } /* nsIWebProgressListener */ -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) { if (helperAppLauncher !is null) helperAppLauncher.Release (); helperAppLauncher = null; @@ -268,28 +270,28 @@ 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) { int currentKBytes = aCurTotalProgress / 1024; int totalKBytes = aMaxTotalProgress / 1024; if (shell !is null && !shell.isDisposed ()) { - Object[] arguments = {new Integer (currentKBytes), new Integer (totalKBytes)}; - String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ - status.setText (statusMsg); + //Object[] arguments = {new Integer (currentKBytes), new Integer (totalKBytes)}; + //String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); //$NON-NLS-1$ + status.setText (Format("Download: {0} KB of {1} KB", currentKBytes, totalKBytes)); shell.layout (true); shell.getDisplay ().update (); } return XPCOM.NS_OK; } -int OnLocationChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int /*long*/ aLocation) { +nsresult OnLocationChange (nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation) { 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; } -int OnSecurityChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int state) { +nsresult OnSecurityChange (nsIWebProgresss aWebProgress, nsIRequest aRequest, PRUint32 state) { return XPCOM.NS_OK; } }