Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/browser/AppFileLocProvider.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | b6e9904989ed |
children |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2007 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 * Port to the D programming language: | |
11 * John Reimer <terminal.node@gmail.com> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.browser.AppFileLocProvider; | |
14 | |
48 | 15 version(Tango){ |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
111
diff
changeset
|
16 import tango.sys.Environment; |
48 | 17 } else { // Phobos |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
111
diff
changeset
|
18 import std.process: Environment = environment; |
48 | 19 } |
25 | 20 |
21 import java.lang.all; | |
54 | 22 import java.util.Vector; |
23 | |
25 | 24 import org.eclipse.swt.browser.Mozilla; |
25 import org.eclipse.swt.browser.SimpleEnumerator; | |
26 | |
27 import org.eclipse.swt.internal.Compatibility; | |
28 | |
29 import XPCOM = org.eclipse.swt.internal.mozilla.XPCOM; | |
30 | |
31 import org.eclipse.swt.internal.mozilla.Common; | |
32 import org.eclipse.swt.internal.mozilla.nsISimpleEnumerator; | |
33 import org.eclipse.swt.internal.mozilla.nsEmbedString; | |
34 import org.eclipse.swt.internal.mozilla.nsID; | |
35 import org.eclipse.swt.internal.mozilla.nsIDirectoryService; | |
36 import org.eclipse.swt.internal.mozilla.nsIFile; | |
37 import org.eclipse.swt.internal.mozilla.nsILocalFile; | |
38 import org.eclipse.swt.internal.mozilla.nsISupports; | |
39 import org.eclipse.swt.internal.mozilla.nsStringAPI; | |
40 | |
41 class AppFileLocProvider : nsIDirectoryServiceProvider2 { | |
42 int refCount = 0; | |
43 String mozillaPath, profilePath; | |
44 String[] pluginDirs; | |
45 bool isXULRunner; | |
46 | |
47 static String SEPARATOR_OS; | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
48 static const String CHROME_DIR = "chrome"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
49 static const String COMPONENTS_DIR = "components"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
50 static const String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
51 static const String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
52 static const String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
53 static const String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ |
25 | 54 static String USER_PLUGINS_DIR; |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
55 static const String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ |
25 | 56 |
57 static this () { | |
58 SEPARATOR_OS = System.getProperty ("file.separator"); | |
59 USER_PLUGINS_DIR = ".mozilla" ~ SEPARATOR_OS ~ "plugins"; | |
60 } | |
61 | |
62 this (String path) { | |
63 mozillaPath = path ~ SEPARATOR_OS; | |
64 } | |
65 | |
66 extern(System) | |
67 nsrefcnt AddRef () { | |
68 refCount++; | |
69 return refCount; | |
70 } | |
71 | |
72 extern(System) | |
54 | 73 nsresult QueryInterface (in cnsID* riid, void** ppvObject) { |
25 | 74 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
75 | |
76 if (*riid == nsISupports.IID) { | |
77 *ppvObject = cast(void*)cast(nsISupports)this; | |
78 AddRef (); | |
79 return XPCOM.NS_OK; | |
80 } | |
81 if (*riid == nsIDirectoryServiceProvider.IID) { | |
82 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this; | |
83 AddRef (); | |
84 return XPCOM.NS_OK; | |
85 } | |
86 if (*riid == nsIDirectoryServiceProvider2.IID) { | |
87 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this; | |
88 AddRef (); | |
89 return XPCOM.NS_OK; | |
90 } | |
91 | |
92 *ppvObject = null; | |
93 return XPCOM.NS_ERROR_NO_INTERFACE; | |
94 } | |
95 | |
96 extern(System) | |
97 nsrefcnt Release () { | |
98 refCount--; | |
99 if (refCount is 0) return 0; | |
100 return refCount; | |
101 } | |
102 | |
103 void setProfilePath (String path) { | |
104 profilePath = path; | |
105 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ | |
106 nsILocalFile file; | |
111 | 107 scope nsEmbedString pathString = new nsEmbedString (toWCharArray(path)); |
25 | 108 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &file); |
109 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
110 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
111 | |
112 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700); | |
113 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
114 file.Release (); | |
115 } | |
116 } | |
117 | |
118 /* nsIDirectoryServiceProvider2 */ | |
119 extern(System) | |
120 nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) { | |
54 | 121 String propertyName = fromStringz(prop)._idup(); |
25 | 122 String[] propertyValues = null; |
123 | |
124 if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) { | |
125 if (pluginDirs is null) { | |
126 int index = 0; | |
127 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
111
diff
changeset
|
128 String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH); |
25 | 129 if (value !is null) { |
130 if (value.length > 0) { | |
54 | 131 String separator = System.getProperty ("path.separator"); // $NON-NLS-1$ |
132 Vector segments = new Vector (); | |
133 int start, end = -1; | |
134 do { | |
135 start = end + 1; | |
136 end = value.indexOf (separator, start); | |
137 String segment; | |
138 if (end is -1) { | |
139 segment = value.substring (start); | |
140 } else { | |
141 segment = value.substring (start, end); | |
142 } | |
143 if (segment.length () > 0) segments.addElement (stringcast(segment)); | |
144 } while (end !is -1); | |
145 int segmentsSize = segments.size (); | |
146 pluginDirs = new String [segmentsSize + 2]; | |
147 for (index = 0; index < segmentsSize; index++) { | |
148 pluginDirs[index] = stringcast(segments.elementAt (index)); | |
149 } | |
25 | 150 } |
151 } | |
152 if (pluginDirs is null) { | |
153 pluginDirs = new String[2]; | |
154 } | |
155 | |
156 /* set the next value to the GRE path + "plugins" */ | |
54 | 157 pluginDirs[ index++ ] = mozillaPath ~ PLUGINS_DIR; |
25 | 158 |
159 /* set the next value to the home directory + "/.mozilla/plugins" */ | |
54 | 160 pluginDirs[ index++ ] = System.getProperty("user.home") ~ SEPARATOR_OS ~ USER_PLUGINS_DIR; |
25 | 161 } |
162 propertyValues = pluginDirs; | |
163 } | |
164 | |
165 *_retval = null; | |
166 //XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
167 if (propertyValues !is null) { | |
168 nsILocalFile localFile; | |
169 nsIFile file; | |
170 nsISupports[] files = new nsISupports [propertyValues.length]; | |
171 int index = 0; | |
172 for (int i = 0; i < propertyValues.length; i++) { | |
173 scope auto pathString = new nsEmbedString (toWCharArray(propertyValues[i])); | |
174 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); | |
175 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { | |
176 /* value appears to be a valid pathname */ | |
177 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
178 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
179 | |
180 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); | |
181 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
182 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
183 localFile.Release (); | |
184 | |
185 files[index++] = cast(nsISupports)file; | |
186 } | |
187 } | |
188 | |
189 if (index < propertyValues.length) { | |
190 /* there were some invalid values so remove the trailing empty array slots */ | |
191 files = files[0..index]; | |
192 } | |
193 | |
194 auto enumerator = new SimpleEnumerator (files); | |
195 enumerator.AddRef (); | |
196 *_retval = cast(nsISimpleEnumerator)enumerator; | |
197 return XPCOM.NS_OK; | |
198 } | |
199 | |
200 return XPCOM.NS_ERROR_FAILURE; | |
201 } | |
202 | |
203 /* nsIDirectoryServiceProvider implementation */ | |
204 extern(System) | |
205 nsresult GetFile(char* prop, PRBool* persistent, nsIFile* _retval) { | |
54 | 206 String propertyName = fromStringz( prop )._idup(); |
25 | 207 String propertyValue = null; |
208 | |
209 if (propertyName == (XPCOM.NS_APP_HISTORY_50_FILE)) { | |
210 propertyValue = profilePath ~ HISTORY_FILE; | |
211 } else if (propertyName == (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { | |
212 propertyValue = profilePath ~ MIMETYPES_FILE; | |
213 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_FILE)) { | |
214 propertyValue = profilePath ~ PREFERENCES_FILE; | |
215 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_DIR)) { | |
216 propertyValue = profilePath; | |
217 } else if (propertyName == (XPCOM.NS_APP_USER_CHROME_DIR)) { | |
218 propertyValue = profilePath ~ CHROME_DIR; | |
219 } else if (propertyName == (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { | |
220 propertyValue = profilePath; | |
221 } else if (propertyName == (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { | |
222 propertyValue = profilePath ~ LOCALSTORE_FILE; | |
223 } else if (propertyName == (XPCOM.NS_APP_CACHE_PARENT_DIR)) { | |
224 propertyValue = profilePath; | |
225 } else if (propertyName == (XPCOM.NS_OS_HOME_DIR)) { | |
226 propertyValue = System.getProperty("user.home"); //$NON-NLS-1$ | |
227 } else if (propertyName == (XPCOM.NS_OS_TEMP_DIR)) { | |
228 propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ | |
229 } else if (propertyName == (XPCOM.NS_GRE_DIR)) { | |
230 propertyValue = mozillaPath; | |
231 } else if (propertyName == (XPCOM.NS_GRE_COMPONENT_DIR)) { | |
232 propertyValue = mozillaPath ~ COMPONENTS_DIR; | |
233 } else if (propertyName == (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { | |
234 propertyValue = mozillaPath; | |
235 } else if (propertyName == (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { | |
236 propertyValue = mozillaPath; | |
237 } else if (propertyName == (XPCOM.NS_XPCOM_COMPONENT_DIR)) { | |
238 propertyValue = mozillaPath ~ COMPONENTS_DIR; | |
239 } else if (propertyName == (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { | |
240 propertyValue = mozillaPath; | |
241 } else if (propertyName == (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { | |
242 /* | |
243 * Answering a value for this property causes problems in Mozilla versions | |
244 * < 1.7. Unfortunately this property is queried early enough in the | |
245 * Browser creation process that the Mozilla version being used is not | |
246 * yet determined. However it is known if XULRunner is being used or not. | |
247 * | |
248 * For now answer a value for this property iff XULRunner is the GRE. | |
249 * If the range of Mozilla versions supported by the Browser is changed | |
250 * in the future to be >= 1.7 then this value can always be answered. | |
251 */ | |
252 if (isXULRunner) propertyValue = profilePath; | |
253 } | |
254 | |
255 *persistent = true; /* PRBool */ | |
256 *_retval = null; | |
257 if (propertyValue !is null && propertyValue.length > 0) { | |
258 nsILocalFile localFile; | |
259 scope auto pathString = new nsEmbedString (propertyValue.toWCharArray()); | |
260 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); | |
261 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
262 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
263 | |
264 nsIFile file; | |
265 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); | |
266 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
267 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | |
268 | |
269 *_retval = file; | |
270 localFile.Release (); | |
271 return XPCOM.NS_OK; | |
272 } | |
273 | |
274 return XPCOM.NS_ERROR_FAILURE; | |
275 } | |
276 } |