45
|
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
|
125
|
10 * Ported to the D Programming Language:
|
|
11 * John Reimer <terminal.node@gmail.com>
|
45
|
12 *******************************************************************************/
|
|
13 module dwt.browser.HelperAppLauncherDialog_1_9;
|
|
14
|
125
|
15 import tango.text.convert.Utf;
|
45
|
16 import dwt.dwthelper.utils;
|
|
17
|
|
18 import dwt.DWT;
|
125
|
19
|
|
20 import dwt.internal.mozilla.Common;
|
|
21
|
|
22 import XPCOM = dwt.internal.mozilla.XPCOM;
|
|
23
|
45
|
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;
|
125
|
28 import dwt.internal.mozilla.nsILocalFile;
|
45
|
29 import dwt.internal.mozilla.nsISupports;
|
125
|
30 import dwt.internal.mozilla.nsStringAPI;
|
|
31 import dwt.internal.mozilla.nsEmbedString;
|
|
32
|
45
|
33 import dwt.widgets.FileDialog;
|
|
34 import dwt.widgets.Shell;
|
|
35
|
125
|
36 import dwt.browser.Mozilla;
|
|
37
|
|
38 class HelperAppLauncherDialog_1_9 : nsIHelperAppLauncherDialog_1_9 {
|
|
39
|
45
|
40 int refCount = 0;
|
|
41
|
125
|
42 this () {
|
45
|
43 }
|
|
44
|
125
|
45 extern(System)
|
|
46 nsrefcnt AddRef () {
|
45
|
47 refCount++;
|
|
48 return refCount;
|
|
49 }
|
|
50
|
125
|
51 extern(System)
|
|
52 nsresult QueryInterface (nsID* riid, void** ppvObject) {
|
|
53 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
|
45
|
54
|
125
|
55 if (*riid is nsISupports.IID) {
|
|
56 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this;
|
45
|
57 AddRef ();
|
|
58 return XPCOM.NS_OK;
|
|
59 }
|
125
|
60 if (*riid is nsIHelperAppLauncherDialog_1_9.IID) {
|
|
61 *ppvObject = cast(void*)cast(nsIHelperAppLauncherDialog_1_9)this;
|
45
|
62 AddRef ();
|
|
63 return XPCOM.NS_OK;
|
|
64 }
|
|
65
|
125
|
66 *ppvObject = null;
|
45
|
67 return XPCOM.NS_ERROR_NO_INTERFACE;
|
|
68 }
|
125
|
69
|
|
70 extern(System)
|
|
71 nsresult Release () {
|
45
|
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 */
|
125
|
80 if (refCount is 0) return 0;
|
45
|
81 return refCount;
|
|
82 }
|
|
83
|
|
84 /* nsIHelperAppLauncherDialog */
|
125
|
85 extern(System)
|
|
86 nsresult Show (nsIHelperAppLauncher_1_9 aLauncher, nsISupports aContext, PRUint32 aReason) {
|
|
87 return aLauncher.SaveToDisk (null, 0);
|
45
|
88 }
|
|
89
|
125
|
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));
|
45
|
96
|
125
|
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));
|
45
|
101
|
|
102 Shell shell = new Shell ();
|
|
103 FileDialog fileDialog = new FileDialog (shell, DWT.SAVE);
|
|
104 fileDialog.setFileName (defaultFile);
|
125
|
105 String[] tmp;
|
|
106 tmp ~= suggestedFileExtension;
|
|
107 fileDialog.setFilterExtensions (tmp);
|
45
|
108 String name = fileDialog.open ();
|
|
109 shell.close ();
|
|
110 if (name is null) {
|
125
|
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__);
|
45
|
114 return XPCOM.NS_ERROR_FAILURE;
|
|
115 }
|
125
|
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__);
|
45
|
123 /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */
|
125
|
124 *_retval = localFile;
|
|
125 //XPCOM.memmove (_retval, result, C.PTR_SIZEOF);
|
45
|
126 return XPCOM.NS_OK;
|
|
127 }
|
|
128 }
|
125
|
129
|
|
130
|