Mercurial > projects > dwt-linux
comparison dwt/browser/HelperAppLauncherDialog_1_9.d @ 353:7f3013c93a95
Oops... Add new 3.4.1 files
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Tue, 04 Nov 2008 21:21:43 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
352:a3c5f744d03f | 353:7f3013c93a95 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2003, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Ported to the D Programming Language: | |
11 * John Reimer <terminal.node@gmail.com> | |
12 *******************************************************************************/ | |
13 module dwt.browser.HelperAppLauncherDialog_1_9; | |
14 | |
15 import tango.text.convert.Utf; | |
16 import dwt.dwthelper.utils; | |
17 | |
18 import dwt.DWT; | |
19 | |
20 import dwt.internal.mozilla.Common; | |
21 | |
22 import XPCOM = dwt.internal.mozilla.XPCOM; | |
23 | |
24 import dwt.internal.mozilla.nsEmbedString; | |
25 import dwt.internal.mozilla.nsID; | |
26 import dwt.internal.mozilla.nsIHelperAppLauncherDialog_1_9; | |
27 import dwt.internal.mozilla.nsIHelperAppLauncher_1_9; | |
28 import dwt.internal.mozilla.nsILocalFile; | |
29 import dwt.internal.mozilla.nsISupports; | |
30 import dwt.internal.mozilla.nsStringAPI; | |
31 import dwt.internal.mozilla.nsEmbedString; | |
32 | |
33 import dwt.widgets.FileDialog; | |
34 import dwt.widgets.Shell; | |
35 | |
36 import dwt.browser.Mozilla; | |
37 | |
38 class HelperAppLauncherDialog_1_9 : nsIHelperAppLauncherDialog_1_9 { | |
39 | |
40 int refCount = 0; | |
41 | |
42 this () { | |
43 } | |
44 | |
45 extern(System) | |
46 nsrefcnt AddRef () { | |
47 refCount++; | |
48 return refCount; | |
49 } | |
50 | |
51 extern(System) | |
52 nsresult QueryInterface (nsID* riid, void** ppvObject) { | |
53 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; | |
54 | |
55 if (*riid is nsISupports.IID) { | |
56 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this; | |
57 AddRef (); | |
58 return XPCOM.NS_OK; | |
59 } | |
60 if (*riid is nsIHelperAppLauncherDialog_1_9.IID) { | |
61 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this; | |
62 AddRef (); | |
63 return XPCOM.NS_OK; | |
64 } | |
65 | |
66 *ppvObject = null; | |
67 return XPCOM.NS_ERROR_NO_INTERFACE; | |
68 } | |
69 | |
70 extern(System) | |
71 nsresult Release () { | |
72 refCount--; | |
73 /* | |
74 * Note. This instance lives as long as the download it is bound to. | |
75 * Its reference count is expected to go down to 0 when the download | |
76 * has completed or when it has been cancelled. E.g. when the user | |
77 * cancels the File Dialog, cancels or closes the Download Dialog | |
78 * and when the Download Dialog goes away after the download is completed. | |
79 */ | |
80 if (refCount is 0) return 0; | |
81 return refCount; | |
82 } | |
83 | |
84 /* nsIHelperAppLauncherDialog */ | |
85 extern(System) | |
86 nsresult Show (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aContext, PRUint32 aReason) { | |
87 return aLauncher.SaveToDisk (null, 0); | |
88 } | |
89 | |
90 extern(System) | |
91 nsresult PromptForSaveToFile (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aWindowContext, PRUnichar* aDefaultFileName, PRUnichar* aSuggestedFileExtension, PRBool aForcePrompt, nsILocalFile* _retval) { | |
92 //int length = XPCOM.strlen_PRUnichar (aDefaultFileName); | |
93 //char[] dest = new char[length]; | |
94 //XPCOM.memmove (dest, aDefaultFileName, length * 2); | |
95 String defaultFile = Utf.toString(fromString16z(aDefaultFileName)); | |
96 | |
97 //length = XPCOM.strlen_PRUnichar (aSuggestedFileExtension); | |
98 //dest = new char[length]; | |
99 //XPCOM.memmove (dest, aSuggestedFileExtension, length * 2); | |
100 String suggestedFileExtension = Utf.toString(fromString16z(aSuggestedFileExtension)); | |
101 | |
102 Shell shell = new Shell (); | |
103 FileDialog fileDialog = new FileDialog (shell, DWT.SAVE); | |
104 fileDialog.setFileName (defaultFile); | |
105 String[] tmp; | |
106 tmp ~= suggestedFileExtension; | |
107 fileDialog.setFilterExtensions (tmp); | |
108 String name = fileDialog.open (); | |
109 shell.close (); | |
110 if (name is null) { | |
111 //nsIHelperAppLauncher_1_9 launcher = new nsIHelperAppLauncher_1_9 (aLauncher); | |
112 int rc = aLauncher.Cancel (XPCOM.NS_BINDING_ABORTED); | |
113 if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); | |
114 return XPCOM.NS_ERROR_FAILURE; | |
115 } | |
116 scope auto path = new nsEmbedString (name.toString16()); | |
117 | |
118 nsILocalFile localFile; | |
119 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile); | |
120 //path.dispose (); | |
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__); | |
123 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */ | |
124 *_retval = localFile; | |
125 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF); | |
126 return XPCOM.NS_OK; | |
127 } | |
128 } | |
129 | |
130 |