comparison dwt/browser/HelperAppLauncherDialog_1_9.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
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 * Ported to the D Programming Language:
11 * John Reimer <terminal.node@gmail.com>
10 *******************************************************************************/ 12 *******************************************************************************/
11 module dwt.browser.HelperAppLauncherDialog_1_9; 13 module dwt.browser.HelperAppLauncherDialog_1_9;
12 14
15 import tango.text.convert.Utf;
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
15 import dwt.DWT; 18 import dwt.DWT;
16 import dwt.internal.C; 19
17 import dwt.internal.mozilla.XPCOM; 20 import dwt.internal.mozilla.Common;
18 import dwt.internal.mozilla.XPCOMObject; 21
22 import XPCOM = dwt.internal.mozilla.XPCOM;
23
19 import dwt.internal.mozilla.nsEmbedString; 24 import dwt.internal.mozilla.nsEmbedString;
20 import dwt.internal.mozilla.nsID; 25 import dwt.internal.mozilla.nsID;
21 import dwt.internal.mozilla.nsIHelperAppLauncherDialog_1_9; 26 import dwt.internal.mozilla.nsIHelperAppLauncherDialog_1_9;
22 import dwt.internal.mozilla.nsIHelperAppLauncher_1_9; 27 import dwt.internal.mozilla.nsIHelperAppLauncher_1_9;
28 import dwt.internal.mozilla.nsILocalFile;
23 import dwt.internal.mozilla.nsISupports; 29 import dwt.internal.mozilla.nsISupports;
30 import dwt.internal.mozilla.nsStringAPI;
31 import dwt.internal.mozilla.nsEmbedString;
32
24 import dwt.widgets.FileDialog; 33 import dwt.widgets.FileDialog;
25 import dwt.widgets.Shell; 34 import dwt.widgets.Shell;
26 35
27 /** 36 import dwt.browser.Mozilla;
28 * This class implements the nsIHelperAppLauncherDialog interface for mozilla 37
29 * versions >= 1.9. For mozilla versions 1.4 - 1.8.x this interface is 38 class HelperAppLauncherDialog_1_9 : nsIHelperAppLauncherDialog_1_9 {
30 * implemented by class HelperAppLauncherDialog. HelperAppLauncherDialogFactory 39
31 * determines at runtime which of these classes to instantiate.
32 */
33 class HelperAppLauncherDialog_1_9 {
34 XPCOMObject supports;
35 XPCOMObject helperAppLauncherDialog;
36 int refCount = 0; 40 int refCount = 0;
37 41
38 HelperAppLauncherDialog_1_9 () { 42 this () {
39 createCOMInterfaces ();
40 } 43 }
41 44
42 int AddRef () { 45 extern(System)
46 nsrefcnt AddRef () {
43 refCount++; 47 refCount++;
44 return refCount; 48 return refCount;
45 } 49 }
46 50
47 void createCOMInterfaces () { 51 extern(System)
48 /* Create each of the interfaces that this object implements */ 52 nsresult QueryInterface (nsID* riid, void** ppvObject) {
49 supports = new XPCOMObject (new int[] {2, 0, 0}) { 53 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
50 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
51 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
52 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
53 };
54
55 helperAppLauncherDialog = new XPCOMObject (new int[] {2, 0, 0, 3, 6}) {
56 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
57 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
58 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
59 public int /*long*/ method3 (int /*long*/[] args) {return Show (args[0], args[1], (int)/*64*/args[2]);}
60 public int /*long*/ method4 (int /*long*/[] args) {return PromptForSaveToFile (args[0], args[1], args[2], args[3], (int)/*64*/args[4], args[5]);}
61 };
62 }
63 54
64 void disposeCOMInterfaces () { 55 if (*riid is nsISupports.IID) {
65 if (supports !is null) { 56 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this;
66 supports.dispose ();
67 supports = null;
68 }
69 if (helperAppLauncherDialog !is null) {
70 helperAppLauncherDialog.dispose ();
71 helperAppLauncherDialog = null;
72 }
73 }
74
75 int /*long*/ getAddress () {
76 return helperAppLauncherDialog.getAddress ();
77 }
78
79 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
80 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
81 nsID guid = new nsID ();
82 XPCOM.memmove (guid, riid, nsID.sizeof);
83
84 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
85 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
86 AddRef (); 57 AddRef ();
87 return XPCOM.NS_OK; 58 return XPCOM.NS_OK;
88 } 59 }
89 if (guid.Equals (nsIHelperAppLauncherDialog_1_9.NS_IHELPERAPPLAUNCHERDIALOG_IID)) { 60 if (*riid is nsIHelperAppLauncherDialog_1_9.IID) {
90 XPCOM.memmove (ppvObject, new int /*long*/[] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF); 61 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this;
91 AddRef (); 62 AddRef ();
92 return XPCOM.NS_OK; 63 return XPCOM.NS_OK;
93 } 64 }
94 65
95 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); 66 *ppvObject = null;
96 return XPCOM.NS_ERROR_NO_INTERFACE; 67 return XPCOM.NS_ERROR_NO_INTERFACE;
97 } 68 }
98 69
99 int Release () { 70 extern(System)
71 nsresult Release () {
100 refCount--; 72 refCount--;
101 /* 73 /*
102 * Note. This instance lives as long as the download it is bound to. 74 * Note. This instance lives as long as the download it is bound to.
103 * Its reference count is expected to go down to 0 when the download 75 * Its reference count is expected to go down to 0 when the download
104 * has completed or when it has been cancelled. E.g. when the user 76 * has completed or when it has been cancelled. E.g. when the user
105 * cancels the File Dialog, cancels or closes the Download Dialog 77 * cancels the File Dialog, cancels or closes the Download Dialog
106 * and when the Download Dialog goes away after the download is completed. 78 * and when the Download Dialog goes away after the download is completed.
107 */ 79 */
108 if (refCount is 0) disposeCOMInterfaces (); 80 if (refCount is 0) return 0;
109 return refCount; 81 return refCount;
110 } 82 }
111 83
112 /* nsIHelperAppLauncherDialog */ 84 /* nsIHelperAppLauncherDialog */
113 85 extern(System)
114 int Show (int /*long*/ aLauncher, int /*long*/ aContext, int aReason) { 86 nsresult Show (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aContext, PRUint32 aReason) {
115 nsIHelperAppLauncher_1_9 helperAppLauncher = new nsIHelperAppLauncher_1_9 (aLauncher); 87 return aLauncher.SaveToDisk (null, 0);
116 return helperAppLauncher.SaveToDisk (0, 0);
117 } 88 }
118 89
119 int PromptForSaveToFile (int /*long*/ aLauncher, int /*long*/ aWindowContext, int /*long*/ aDefaultFileName, int /*long*/ aSuggestedFileExtension, int aForcePrompt, int /*long*/ _retval) { 90 extern(System)
120 int length = XPCOM.strlen_PRUnichar (aDefaultFileName); 91 nsresult PromptForSaveToFile (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aWindowContext, PRUnichar* aDefaultFileName, PRUnichar* aSuggestedFileExtension, PRBool aForcePrompt, nsILocalFile* _retval) {
121 char[] dest = new char[length]; 92 //int length = XPCOM.strlen_PRUnichar (aDefaultFileName);
122 XPCOM.memmove (dest, aDefaultFileName, length * 2); 93 //char[] dest = new char[length];
123 String defaultFile = new String (dest); 94 //XPCOM.memmove (dest, aDefaultFileName, length * 2);
95 String defaultFile = Utf.toString(fromString16z(aDefaultFileName));
124 96
125 length = XPCOM.strlen_PRUnichar (aSuggestedFileExtension); 97 //length = XPCOM.strlen_PRUnichar (aSuggestedFileExtension);
126 dest = new char[length]; 98 //dest = new char[length];
127 XPCOM.memmove (dest, aSuggestedFileExtension, length * 2); 99 //XPCOM.memmove (dest, aSuggestedFileExtension, length * 2);
128 String suggestedFileExtension = new String (dest); 100 String suggestedFileExtension = Utf.toString(fromString16z(aSuggestedFileExtension));
129 101
130 Shell shell = new Shell (); 102 Shell shell = new Shell ();
131 FileDialog fileDialog = new FileDialog (shell, DWT.SAVE); 103 FileDialog fileDialog = new FileDialog (shell, DWT.SAVE);
132 fileDialog.setFileName (defaultFile); 104 fileDialog.setFileName (defaultFile);
133 fileDialog.setFilterExtensions (new String[] {suggestedFileExtension}); 105 String[] tmp;
106 tmp ~= suggestedFileExtension;
107 fileDialog.setFilterExtensions (tmp);
134 String name = fileDialog.open (); 108 String name = fileDialog.open ();
135 shell.close (); 109 shell.close ();
136 if (name is null) { 110 if (name is null) {
137 nsIHelperAppLauncher_1_9 launcher = new nsIHelperAppLauncher_1_9 (aLauncher); 111 //nsIHelperAppLauncher_1_9 launcher = new nsIHelperAppLauncher_1_9 (aLauncher);
138 int rc = launcher.Cancel (XPCOM.NS_BINDING_ABORTED); 112 int rc = aLauncher.Cancel (XPCOM.NS_BINDING_ABORTED);
139 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 113 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__);
140 return XPCOM.NS_ERROR_FAILURE; 114 return XPCOM.NS_ERROR_FAILURE;
141 } 115 }
142 nsEmbedString path = new nsEmbedString (name); 116 scope auto path = new nsEmbedString (name.toString16());
143 int /*long*/[] result = new int /*long*/[1]; 117
144 int rc = XPCOM.NS_NewLocalFile (path.getAddress (), 1, result); 118 nsILocalFile localFile;
145 path.dispose (); 119 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile);
146 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 120 //path.dispose ();
147 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); 121 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__);
122 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER,__FILE__,__LINE__);
148 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */ 123 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */
149 XPCOM.memmove (_retval, result, C.PTR_SIZEOF); 124 *_retval = localFile;
125 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF);
150 return XPCOM.NS_OK; 126 return XPCOM.NS_OK;
151 } 127 }
152 } 128 }
129
130