Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/program/Program.d @ 113:fb3aa8075988
D2 support for the linux port.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 06 Apr 2011 21:57:23 +0200 |
parents | b397a43d66d1 |
children | 536e43f63c81 |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.program.Program; | |
14 | |
15 import org.eclipse.swt.SWT; | |
16 import org.eclipse.swt.graphics.ImageData; | |
17 import org.eclipse.swt.internal.Compatibility; | |
18 import org.eclipse.swt.internal.Converter; | |
19 import org.eclipse.swt.internal.Library; | |
20 import org.eclipse.swt.internal.gtk.OS; | |
21 import org.eclipse.swt.widgets.Display; | |
22 import org.eclipse.swt.widgets.Event; | |
23 import org.eclipse.swt.widgets.Listener; | |
24 import java.lang.all; | |
50 | 25 import java.nonstandard.SharedLib; |
25 | 26 |
48 | 27 version(Tango){ |
50 | 28 static import tango.core.Array; |
29 static import tango.io.device.File; | |
30 static import tango.io.stream.Lines; | |
48 | 31 } else { // Phobos |
50 | 32 static import std.string; |
33 static import std.file; | |
34 static import std.algorithm; | |
35 static import std.iterator; | |
48 | 36 } |
25 | 37 |
38 version( build ){ | |
39 pragma(link, "gnomeui-2" ); | |
40 } | |
41 | |
42 private extern(C) { | |
43 alias int GnomeIconLookupResultFlags; | |
44 alias int GnomeIconLookupFlags; | |
45 GnomeIconTheme *gnome_icon_theme_new (); | |
46 char *gnome_icon_lookup ( | |
47 GtkIconTheme *icon_theme, | |
48 void *thumbnail_factory, | |
49 char *file_uri, | |
50 char *custom_icon, | |
51 void *file_info, | |
52 char *mime_type, | |
53 GnomeIconLookupFlags flags, | |
54 GnomeIconLookupResultFlags *result); | |
55 int gnome_vfs_init(); | |
56 char* gnome_icon_theme_lookup_icon(GnomeIconTheme *theme,char *icon_name,int size, GnomeIconData **icon_data, int *base_size) ; | |
57 | |
58 alias void GnomeIconTheme; | |
59 alias void GnomeIconData; | |
60 | |
61 struct GnomeVFSMimeApplication{ | |
62 /*< public > */ | |
63 char *id; | |
64 char *name; | |
65 | |
66 /*< private > */ | |
67 char *command; | |
68 int can_open_multiple_files; | |
69 int expects_uris; | |
70 GList *supported_uri_schemes; | |
71 int requires_terminal; | |
72 | |
73 /* Padded to avoid future breaks in ABI compatibility */ | |
74 void * reserved1; | |
75 | |
76 void * priv; | |
77 } | |
78 } | |
79 | |
80 struct GNOME { | |
81 private static extern(C){ | |
82 enum { | |
83 GNOME_ICON_LOOKUP_FLAGS_NONE = 0, | |
84 GNOME_ICON_LOOKUP_FLAGS_EMBEDDING_TEXT = 1<<0, | |
85 GNOME_ICON_LOOKUP_FLAGS_SHOW_SMALL_IMAGES_AS_THEMSELVES = 1<<1, | |
86 GNOME_ICON_LOOKUP_FLAGS_ALLOW_SVG_AS_THEMSELVES = 1<<2 | |
87 } | |
88 enum { | |
89 GNOME_VFS_MAKE_URI_DIR_NONE = 0, | |
90 GNOME_VFS_MAKE_URI_DIR_HOMEDIR = 1 << 0, | |
91 GNOME_VFS_MAKE_URI_DIR_CURRENT = 1 << 1 | |
92 } | |
93 alias int GnomeVFSMakeURIDirs; | |
94 enum { | |
95 GNOME_VFS_OK, | |
96 GNOME_VFS_ERROR_NOT_FOUND, | |
97 GNOME_VFS_ERROR_GENERIC, | |
98 GNOME_VFS_ERROR_INTERNAL, | |
99 GNOME_VFS_ERROR_BAD_PARAMETERS, | |
100 GNOME_VFS_ERROR_NOT_SUPPORTED, | |
101 GNOME_VFS_ERROR_IO, | |
102 GNOME_VFS_ERROR_CORRUPTED_DATA, | |
103 GNOME_VFS_ERROR_WRONG_FORMAT, | |
104 GNOME_VFS_ERROR_BAD_FILE, | |
105 GNOME_VFS_ERROR_TOO_BIG, | |
106 GNOME_VFS_ERROR_NO_SPACE, | |
107 GNOME_VFS_ERROR_READ_ONLY, | |
108 GNOME_VFS_ERROR_INVALID_URI, | |
109 GNOME_VFS_ERROR_NOT_OPEN, | |
110 GNOME_VFS_ERROR_INVALID_OPEN_MODE, | |
111 GNOME_VFS_ERROR_ACCESS_DENIED, | |
112 GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES, | |
113 GNOME_VFS_ERROR_EOF, | |
114 GNOME_VFS_ERROR_NOT_A_DIRECTORY, | |
115 GNOME_VFS_ERROR_IN_PROGRESS, | |
116 GNOME_VFS_ERROR_INTERRUPTED, | |
117 GNOME_VFS_ERROR_FILE_EXISTS, | |
118 GNOME_VFS_ERROR_LOOP, | |
119 GNOME_VFS_ERROR_NOT_PERMITTED, | |
120 GNOME_VFS_ERROR_IS_DIRECTORY, | |
121 GNOME_VFS_ERROR_NO_MEMORY, | |
122 GNOME_VFS_ERROR_HOST_NOT_FOUND, | |
123 GNOME_VFS_ERROR_INVALID_HOST_NAME, | |
124 GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS, | |
125 GNOME_VFS_ERROR_LOGIN_FAILED, | |
126 GNOME_VFS_ERROR_CANCELLED, | |
127 GNOME_VFS_ERROR_DIRECTORY_BUSY, | |
128 GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY, | |
129 GNOME_VFS_ERROR_TOO_MANY_LINKS, | |
130 GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM, | |
131 GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM, | |
132 GNOME_VFS_ERROR_NAME_TOO_LONG, | |
133 GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE, | |
134 GNOME_VFS_ERROR_SERVICE_OBSOLETE, | |
135 GNOME_VFS_ERROR_PROTOCOL_ERROR, | |
136 GNOME_VFS_ERROR_NO_MASTER_BROWSER, | |
137 GNOME_VFS_ERROR_NO_DEFAULT, | |
138 GNOME_VFS_ERROR_NO_HANDLER, | |
139 GNOME_VFS_ERROR_PARSE, | |
140 GNOME_VFS_ERROR_LAUNCH, | |
141 GNOME_VFS_ERROR_TIMEOUT, | |
142 GNOME_VFS_ERROR_NAMESERVER, | |
143 GNOME_VFS_ERROR_LOCKED, | |
144 GNOME_VFS_ERROR_DEPRECATED_FUNCTION, | |
145 GNOME_VFS_ERROR_INVALID_FILENAME, | |
146 GNOME_VFS_ERROR_NOT_A_SYMBOLIC_LINK, | |
147 GNOME_VFS_NUM_ERRORS | |
148 } | |
149 alias int GnomeVFSResult; | |
150 | |
151 enum { | |
152 GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS, | |
153 GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS, | |
154 GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES | |
155 } | |
156 | |
157 alias GtkIconTheme GnomeIconTheme; | |
158 alias .gnome_icon_theme_lookup_icon gnome_icon_theme_lookup_icon; | |
159 alias .gnome_vfs_init gnome_vfs_init; | |
160 alias .gnome_icon_lookup gnome_icon_lookup; | |
161 alias .gnome_icon_theme_new gnome_icon_theme_new; | |
162 | |
163 | |
164 GnomeVFSMimeApplication * function ( char *mime_type ) gnome_vfs_mime_get_default_application; | |
165 char* function(char*, int ) gnome_vfs_make_uri_from_input_with_dirs; | |
166 GnomeVFSResult function( GnomeVFSMimeApplication*, GList*) gnome_vfs_mime_application_launch; | |
167 void function(GnomeVFSMimeApplication*) gnome_vfs_mime_application_free; | |
168 GList* function(char*) gnome_vfs_mime_get_extensions_list; | |
169 void function(GList*) gnome_vfs_mime_extensions_list_free; | |
170 void function(GList*) gnome_vfs_mime_registered_mime_type_list_free; | |
171 GnomeVFSResult function(char*) gnome_vfs_url_show; | |
172 char* function(char*) gnome_vfs_make_uri_from_input; | |
173 GList* function() gnome_vfs_get_registered_mime_types; | |
174 char* function(char*) gnome_vfs_mime_type_from_name; | |
175 } | |
113
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
176 static Symbol[] symbols; |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
177 static this () { |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
178 symbols = [ |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
179 Symbol("gnome_vfs_mime_get_default_application", cast(void**)&gnome_vfs_mime_get_default_application ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
180 Symbol("gnome_vfs_make_uri_from_input_with_dirs", cast(void**)&gnome_vfs_make_uri_from_input_with_dirs ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
181 Symbol("gnome_vfs_mime_application_launch", cast(void**)&gnome_vfs_mime_application_launch ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
182 Symbol("gnome_vfs_mime_application_free", cast(void**)&gnome_vfs_mime_application_free ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
183 Symbol("gnome_vfs_url_show", cast(void**)&gnome_vfs_url_show ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
184 Symbol("gnome_vfs_make_uri_from_input", cast(void**)&gnome_vfs_make_uri_from_input ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
185 Symbol("gnome_vfs_get_registered_mime_types", cast(void**)&gnome_vfs_get_registered_mime_types ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
186 Symbol("gnome_vfs_mime_get_extensions_list", cast(void**)&gnome_vfs_mime_get_extensions_list ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
187 Symbol("gnome_vfs_mime_extensions_list_free", cast(void**)&gnome_vfs_mime_extensions_list_free ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
188 Symbol("gnome_vfs_mime_registered_mime_type_list_free", cast(void**)&gnome_vfs_mime_registered_mime_type_list_free ), |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
189 Symbol("gnome_vfs_mime_type_from_name", cast(void**)&gnome_vfs_mime_type_from_name ) |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
190 ]; |
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
191 } |
25 | 192 } |
193 | |
194 /** | |
195 * Instances of this class represent programs and | |
196 * their associated file extensions in the operating | |
197 * system. | |
198 * | |
199 * @see <a href="http://www.eclipse.org/swt/snippets/#program">Program snippets</a> | |
200 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
201 */ | |
202 public final class Program { | |
203 String name; | |
204 String command; | |
205 String iconPath; | |
206 Display display; | |
207 | |
208 /* Gnome specific | |
209 * true if command expects a URI | |
210 * false if expects a path | |
211 */ | |
212 bool gnomeExpectUri; | |
213 | |
214 static int /*long*/ cdeShell; | |
215 | |
216 static const String[] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ]; | |
217 static const String[] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ]; | |
218 static const String DESKTOP_DATA = "Program_DESKTOP"; | |
219 static const String ICON_THEME_DATA = "Program_GNOME_ICON_THEME"; | |
220 static const String PREFIX_HTTP = "http://"; //$NON-NLS-1$ | |
221 static const String PREFIX_HTTPS = "https://"; //$NON-NLS-1$ | |
222 static const int DESKTOP_UNKNOWN = 0; | |
223 static const int DESKTOP_GNOME = 1; | |
224 static const int DESKTOP_GNOME_24 = 2; | |
225 static const int DESKTOP_CDE = 3; | |
226 static const int PREFERRED_ICON_SIZE = 16; | |
227 | |
228 /** | |
229 * Prevents uninitialized instances from being created outside the package. | |
230 */ | |
231 this() { | |
232 } | |
233 | |
234 /* Determine the desktop for the given display. */ | |
235 static int getDesktop(Display display) { | |
236 if (display is null) return DESKTOP_UNKNOWN; | |
86 | 237 Integer desktopValue = cast(Integer)display.getData(DESKTOP_DATA); |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
238 if (desktopValue !is null) return desktopValue.intValue; |
25 | 239 int desktop = DESKTOP_UNKNOWN; |
240 | |
241 /* Get the list of properties on the root window. */ | |
242 void* xDisplay = OS.GDK_DISPLAY(); | |
243 uint rootWindow = OS.XDefaultRootWindow(xDisplay); | |
244 int numProp; | |
245 uint* propList = OS.XListProperties(xDisplay, rootWindow, &numProp); | |
246 uint[] property = new uint[numProp]; | |
247 if (propList !is null) { | |
248 property[ 0 .. numProp ] = propList[ 0 .. numProp ]; | |
249 OS.XFree(propList); | |
250 } | |
251 | |
252 /* | |
253 * Feature in Linux Desktop. There is currently no official way to | |
254 * determine whether the Gnome window manager or gnome-vfs is | |
255 * available. Earlier versions including Red Hat 9 and Suse 9 provide | |
256 * a documented Gnome specific property on the root window | |
257 * WIN_SUPPORTING_WM_CHECK. This property is no longer supported in newer | |
258 * versions such as Fedora Core 2. | |
259 * The workaround is to simply check that the window manager is a | |
260 * compliant one (property _NET_SUPPORTING_WM_CHECK) and to attempt to load | |
261 * our native library that depends on gnome-vfs. | |
262 */ | |
263 if (desktop is DESKTOP_UNKNOWN) { | |
264 String gnomeName = "_NET_SUPPORTING_WM_CHECK"; | |
265 int /*long*/ gnome = OS.XInternAtom(xDisplay, gnomeName.ptr, true); | |
266 if (gnome !is OS.None && (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) && gnome_init()) { | |
267 desktop = DESKTOP_GNOME; | |
268 int icon_theme = cast(int)GNOME.gnome_icon_theme_new(); | |
86 | 269 display.setData(ICON_THEME_DATA, new Integer(icon_theme)); |
25 | 270 display.addListener(SWT.Dispose, new class(display) Listener { |
271 Display display; | |
272 this( Display display ){ this.display = display; } | |
273 public void handleEvent(Event event) { | |
86 | 274 Integer gnomeIconTheme = cast(Integer)display.getData(ICON_THEME_DATA); |
25 | 275 if (gnomeIconTheme is null) return; |
276 display.setData(ICON_THEME_DATA, null); | |
277 /* | |
278 * Note. gnome_icon_theme_new uses g_object_new to allocate the | |
279 * data it returns. Use g_object_unref to free the pointer it returns. | |
280 */ | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
281 if (gnomeIconTheme.intValue !is 0) OS.g_object_unref( cast(void*)gnomeIconTheme.intValue); |
25 | 282 } |
283 }); | |
284 /* Check for libgnomevfs-2 version 2.4 */ | |
285 String buffer = "libgnomevfs-2.so.0"; | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
286 void delegate (void*) dg = (void*){ desktop = DESKTOP_GNOME_24; }; |
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
287 SharedLib.tryUseSymbol( "gnome_vfs_url_show", buffer, dg); |
50 | 288 if( desktop is DESKTOP_GNOME_24 ){ |
289 SharedLib.loadLibSymbols( GNOME.symbols, buffer ); | |
25 | 290 } |
291 } | |
292 } | |
293 | |
294 // PORTING CDE not supported | |
295 /+ | |
296 /* | |
297 * On CDE, the atom below may exist without DTWM running. If the atom | |
298 * below is defined, the CDE database exists and the available | |
299 * applications can be queried. | |
300 */ | |
301 if (desktop is DESKTOP_UNKNOWN) { | |
302 String cdeName = "_DT_SM_PREFERENCES"; | |
303 int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName.ptr, true); | |
304 for (int index = 0; desktop is DESKTOP_UNKNOWN && index < property.length; index++) { | |
305 if (property[index] is OS.None) continue; /* do not match atoms that do not exist */ | |
306 if (property[index] is cde && cde_init(display)) desktop = DESKTOP_CDE; | |
307 } | |
308 } | |
309 +/ | |
310 | |
86 | 311 display.setData(DESKTOP_DATA, new Integer(desktop)); |
25 | 312 return desktop; |
313 } | |
314 | |
315 // PORTING CDE not supported | |
316 /+ | |
317 bool cde_execute(String fileName) { | |
318 /* Use the character encoding for the default locale */ | |
319 char* action = toStringz(command); | |
320 char* ptr = cast(char*)OS.g_malloc(fileName.length+1); | |
321 ptr[ 0 .. fileName.length ] = fileName; | |
322 ptr[ fileName.length ] = 0; | |
323 DtActionArg args = new DtActionArg(); | |
324 args.argClass = CDE.DtACTION_FILE; | |
325 args.name = ptr; | |
326 long actionID = CDE.DtActionInvoke(cdeShell, action, args, 1, null, null, null, 1, 0, 0); | |
327 OS.g_free(ptr); | |
328 return actionID !is 0; | |
329 } | |
330 | |
331 static String cde_getAction(String dataType) { | |
332 String action = null; | |
333 String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); | |
334 if (actions !is null) { | |
335 int index = actions.indexOf("Open"); | |
336 if (index !is -1) { | |
337 action = actions.substring(index, index + 4); | |
338 } else { | |
339 index = actions.indexOf(","); | |
340 action = index !is -1 ? actions.substring(0, index) : actions; | |
341 } | |
342 } | |
343 return action; | |
344 } | |
345 | |
346 static String cde_getAttribute(String dataType, String attrName) { | |
347 /* Use the character encoding for the default locale */ | |
348 byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true); | |
349 byte[] attrNameBuf = Converter.wcsToMbcs(null, attrName, true); | |
350 byte[] optNameBuf = null; | |
351 int /*long*/ attrValue = CDE.DtDtsDataTypeToAttributeValue(dataTypeBuf, attrNameBuf, optNameBuf); | |
352 if (attrValue is 0) return null; | |
353 int length = OS.strlen(attrValue); | |
354 byte[] attrValueBuf = new byte[length]; | |
355 OS.memmove(attrValueBuf, attrValue, length); | |
356 CDE.DtDtsFreeAttributeValue(attrValue); | |
357 /* Use the character encoding for the default locale */ | |
358 return new String(Converter.mbcsToWcs(null, attrValueBuf)); | |
359 } | |
360 | |
361 static String[][ String ] cde_getDataTypeInfo() { | |
362 String[][ String ] dataTypeInfo; | |
363 int index; | |
364 int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames(); | |
365 if (dataTypeList !is 0) { | |
366 /* For each data type name in the list */ | |
367 index = 0; | |
368 int /*long*/ [] dataType = new int /*long*/ [1]; | |
369 OS.memmove(dataType, dataTypeList + (index++ * 4), 4); | |
370 while (dataType[0] !is 0) { | |
371 int length = OS.strlen(dataType[0]); | |
372 byte[] dataTypeBuf = new byte[length]; | |
373 OS.memmove(dataTypeBuf, dataType[0], length); | |
374 /* Use the character encoding for the default locale */ | |
375 String dataTypeName = new String(Converter.mbcsToWcs(null, dataTypeBuf)); | |
376 | |
377 /* The data type is valid if it is not an action, and it has an extension and an action. */ | |
378 String extension = cde_getExtension(dataTypeName); | |
379 if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) && | |
380 extension !is null && cde_getAction(dataTypeName) !is null) { | |
381 String[] exts; | |
382 exts ~= extension; | |
383 dataTypeInfo[ dataTypeName ] = exts; | |
384 } | |
385 OS.memmove(dataType, dataTypeList + (index++ * 4), 4); | |
386 } | |
387 CDE.DtDtsFreeDataTypeNames(dataTypeList); | |
388 } | |
389 | |
390 return dataTypeInfo; | |
391 } | |
392 | |
393 static String cde_getExtension(String dataType) { | |
394 String fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); | |
395 if (fileExt is null || fileExt.indexOf("%s.") is -1) return null; | |
396 int dot = fileExt.indexOf("."); | |
397 return fileExt.substring(dot); | |
398 } | |
399 | |
400 /** | |
401 * CDE - Get Image Data | |
402 * | |
403 * This method returns the image data of the icon associated with | |
404 * the data type. Since CDE supports multiple sizes of icons, several | |
405 * attempts are made to locate an icon of the desired size and format. | |
406 * CDE supports the sizes: tiny, small, medium and large. The best | |
407 * search order is medium, large, small and then tiny. Althoug CDE supports | |
408 * colour and monochrome bitmaps, only colour icons are tried. (The order is | |
409 * defined by the cdeIconExt and cdeMaskExt arrays above.) | |
410 */ | |
411 ImageData cde_getImageData() { | |
412 // TODO | |
413 return null; | |
414 } | |
415 | |
416 static String cde_getMimeType(String extension) { | |
417 String mimeType = null; | |
418 String[][ String ] mimeInfo = cde_getDataTypeInfo(); | |
419 if (mimeInfo is null) return null; | |
420 String[] keys = mimeInfo.keys(); | |
421 int keyIdx = 0; | |
422 while (mimeType is null && keyIdx < keys.length ) { | |
423 String type = keys[ keyIdx ]; | |
424 String[] mimeExts = mimeInfo[type]; | |
425 for (int index = 0; index < mimeExts.length; index++){ | |
426 if (extension.equals(mimeExts[index])) { | |
427 mimeType = type; | |
428 break; | |
429 } | |
430 } | |
431 keyIdx++; | |
432 } | |
433 return mimeType; | |
434 } | |
435 | |
436 static Program cde_getProgram(Display display, String mimeType) { | |
437 Program program = new Program(); | |
438 program.display = display; | |
439 program.name = mimeType; | |
440 program.command = cde_getAction(mimeType); | |
441 program.iconPath = cde_getAttribute(program.name, CDE.DtDTS_DA_ICON); | |
442 return program; | |
443 } | |
444 | |
445 static bool cde_init(Display display) { | |
446 try { | |
447 Library.loadLibrary("swt-cde"); | |
448 } catch (Throwable e) { | |
449 return false; | |
450 } | |
451 | |
452 /* Use the character encoding for the default locale */ | |
453 CDE.XtToolkitInitialize(); | |
454 int /*long*/ xtContext = CDE.XtCreateApplicationContext (); | |
455 int /*long*/ xDisplay = OS.GDK_DISPLAY(); | |
456 byte[] appName = Converter.wcsToMbcs(null, "CDE", true); | |
457 byte[] appClass = Converter.wcsToMbcs(null, "CDE", true); | |
458 int /*long*/ [] argc = [0]; | |
459 CDE.XtDisplayInitialize(xtContext, xDisplay, appName, appClass, 0, 0, argc, 0); | |
460 int /*long*/ widgetClass = CDE.topLevelShellWidgetClass (); | |
461 cdeShell = CDE.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); | |
462 CDE.XtSetMappedWhenManaged (cdeShell, false); | |
463 CDE.XtResizeWidget (cdeShell, 10, 10, 0); | |
464 CDE.XtRealizeWidget (cdeShell); | |
465 bool initOK = CDE.DtAppInitialize(xtContext, xDisplay, cdeShell, appName, appName); | |
466 if (initOK) CDE.DtDbLoad(); | |
467 return initOK; | |
468 } | |
469 +/ | |
470 | |
471 static String[] parseCommand(String cmd) { | |
472 String[] args; | |
473 int sIndex = 0; | |
474 int eIndex; | |
475 while (sIndex < cmd.length) { | |
476 /* Trim initial white space of argument. */ | |
477 while (sIndex < cmd.length && Compatibility.isWhitespace(cmd.charAt(sIndex))) { | |
478 sIndex++; | |
479 } | |
480 if (sIndex < cmd.length) { | |
481 /* If the command is a quoted string */ | |
482 if (cmd.charAt(sIndex) is '"' || cmd.charAt(sIndex) is '\'') { | |
483 /* Find the terminating quote (or end of line). | |
484 * This code currently does not handle escaped characters (e.g., " a\"b"). | |
485 */ | |
486 eIndex = sIndex + 1; | |
487 while (eIndex < cmd.length && cmd.charAt(eIndex) !is cmd.charAt(sIndex)) eIndex++; | |
488 if (eIndex >= cmd.length) { | |
489 /* The terminating quote was not found | |
490 * Add the argument as is with only one initial quote. | |
491 */ | |
492 args ~= cmd.substring(sIndex, eIndex); | |
493 } else { | |
494 /* Add the argument, trimming off the quotes. */ | |
495 args ~= cmd.substring(sIndex + 1, eIndex); | |
496 } | |
497 sIndex = eIndex + 1; | |
498 } | |
499 else { | |
500 /* Use white space for the delimiters. */ | |
501 eIndex = sIndex; | |
502 while (eIndex < cmd.length && !Compatibility.isWhitespace( firstCodePoint( cmd[ eIndex .. $ ]))) eIndex++; | |
503 args ~= cmd.substring(sIndex, eIndex); | |
504 sIndex = eIndex + 1; | |
505 } | |
506 } | |
507 } | |
508 | |
509 String[] strings = new String[args.length]; | |
510 for (int index =0; index < args.length; index++) { | |
511 strings[index] = args[index]; | |
512 } | |
513 return strings; | |
514 } | |
515 | |
516 /** | |
517 * GNOME 2.4 - Execute the program for the given file. | |
518 */ | |
519 bool gnome_24_execute(String fileName) { | |
520 char* mimeTypeBuffer = toStringz(name); | |
521 auto ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); | |
522 char* fileNameBuffer = toStringz(fileName); | |
523 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); | |
524 GList* list = OS.g_list_append( null, uri); | |
525 int result = GNOME.gnome_vfs_mime_application_launch(ptr, list); | |
526 GNOME.gnome_vfs_mime_application_free(ptr); | |
527 OS.g_free(uri); | |
528 OS.g_list_free(list); | |
529 return result is GNOME.GNOME_VFS_OK; | |
530 } | |
531 | |
532 /** | |
533 * GNOME 2.4 - Launch the default program for the given file. | |
534 */ | |
535 static bool gnome_24_launch(String fileName) { | |
536 char* fileNameBuffer = toStringz(fileName); | |
537 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); | |
538 int result = GNOME.gnome_vfs_url_show(uri); | |
539 OS.g_free(uri); | |
540 return (result is GNOME.GNOME_VFS_OK); | |
541 } | |
542 | |
543 /** | |
544 * GNOME 2.2 - Execute the program for the given file. | |
545 */ | |
546 bool gnome_execute(String fileName) { | |
547 if (gnomeExpectUri) { | |
548 /* Convert the given path into a URL */ | |
549 char* fileNameBuffer = toStringz(fileName); | |
550 char* uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer); | |
551 if (uri !is null) { | |
50 | 552 fileName = fromStringz( uri )._idup(); |
25 | 553 OS.g_free(uri); |
554 } | |
555 } | |
556 | |
557 /* Parse the command into its individual arguments. */ | |
558 String[] args = parseCommand(command); | |
559 int fileArg = -1; | |
560 int index; | |
561 for (index = 0; index < args.length; index++) { | |
562 int j = args[index].indexOf("%f"); | |
563 if (j !is -1) { | |
564 String value = args[index]; | |
565 fileArg = index; | |
566 args[index] = value.substring(0, j) ~ fileName ~ value.substring(j + 2); | |
567 } | |
568 } | |
569 | |
570 /* If a file name was given but the command did not have "%f" */ | |
571 if ((fileName.length > 0) && (fileArg < 0)) { | |
572 String[] newArgs = new String[args.length + 1]; | |
573 for (index = 0; index < args.length; index++) newArgs[index] = args[index]; | |
574 newArgs[args.length] = fileName; | |
575 args = newArgs; | |
576 } | |
577 | |
578 /* Execute the command. */ | |
579 try { | |
580 Compatibility.exec(args); | |
581 } catch (IOException e) { | |
582 return false; | |
583 } | |
584 return true; | |
585 } | |
586 | |
587 /** | |
588 * GNOME - Get Image Data | |
589 * | |
590 */ | |
591 ImageData gnome_getImageData() { | |
592 if (iconPath is null) return null; | |
593 try { | |
594 return new ImageData(iconPath); | |
595 } catch (Exception e) {} | |
596 return null; | |
597 } | |
598 | |
599 /++ | |
600 + SWT Extension | |
601 + This is a temporary workaround until SWT will get the real implementation. | |
602 +/ | |
603 static String[][ String ] gnome24_getMimeInfo() { | |
50 | 604 version(Tango){ |
55
ea8b884d85f6
[swt lin] fixed tango compile
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
605 scope file = new tango.io.device.File.File("/usr/share/mime/globs"); |
ea8b884d85f6
[swt lin] fixed tango compile
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
606 scope it = new tango.io.stream.Lines.Lines!(char)( file ); |
50 | 607 } else { // Phobos |
608 scope it = std.string.splitlines( cast(String)std.file.read("/usr/share/mime/globs")); | |
609 } | |
25 | 610 // process file one line at a time |
611 String[][ String ] mimeInfo; | |
612 foreach (line; it ){ | |
613 int colon = line.indexOf(':'); | |
614 if( colon is line.length ){ | |
615 continue; | |
616 } | |
617 if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){ | |
618 continue; | |
619 } | |
50 | 620 String mimeType = line[0..colon]._idup(); |
621 String ext = line[colon+3 .. $]._idup(); | |
25 | 622 if( auto exts = mimeType in mimeInfo ){ |
623 mimeInfo[ mimeType ] = *exts ~ ext; | |
624 } | |
625 else{ | |
626 mimeInfo[ mimeType ] = [ ext ]; | |
627 } | |
628 } | |
629 return mimeInfo; | |
630 } | |
631 /** | |
632 * GNOME - Get mime types | |
633 * | |
634 * Obtain the registered mime type information and | |
635 * return it in a map. The key of each entry | |
636 * in the map is the mime type name. The value is | |
637 * a vector of the associated file extensions. | |
638 */ | |
639 static String[][ String ] gnome_getMimeInfo() { | |
640 String[][ String ] mimeInfo; | |
641 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types(); | |
642 GList* mimeElement = mimeList; | |
643 while (mimeElement !is null) { | |
50 | 644 auto mimePtr = cast(char*) OS.g_list_data(mimeElement); |
645 String mimeTypeBuffer = fromStringz(mimePtr)._idup(); | |
25 | 646 String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer)); |
647 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr); | |
648 if (extensionList !is null) { | |
649 String[] extensions; | |
650 GList* extensionElement = extensionList; | |
651 while (extensionElement !is null) { | |
652 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement); | |
50 | 653 String extensionBuffer = fromStringz(extensionPtr)._idup(); |
25 | 654 String extension = extensionBuffer; |
655 extension = '.' ~ extension; | |
656 extensions ~= extension; | |
657 extensionElement = OS.g_list_next(extensionElement); | |
658 } | |
659 GNOME.gnome_vfs_mime_extensions_list_free(extensionList); | |
660 if (extensions.length > 0) mimeInfo[ mimeType ] = extensions; | |
661 } | |
662 mimeElement = OS.g_list_next(mimeElement); | |
663 } | |
664 if (mimeList !is null) GNOME.gnome_vfs_mime_registered_mime_type_list_free(mimeList); | |
665 return mimeInfo; | |
666 } | |
667 | |
668 static String gnome_getMimeType(String extension) { | |
669 String mimeType = null; | |
670 String fileName = "swt" ~ extension; | |
671 char* extensionBuffer = toStringz(fileName); | |
672 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); | |
673 if (typeName !is null) { | |
50 | 674 mimeType = fromStringz(typeName)._idup(); |
25 | 675 } |
676 return mimeType; | |
677 } | |
678 | |
679 static Program gnome_getProgram(Display display, String mimeType) { | |
680 Program program = null; | |
681 char* mimeTypeBuffer = toStringz(mimeType); | |
682 GnomeVFSMimeApplication* ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); | |
683 if (ptr !is null) { | |
684 program = new Program(); | |
685 program.display = display; | |
686 program.name = mimeType; | |
687 GnomeVFSMimeApplication* application = ptr; | |
50 | 688 String buffer = fromStringz(application.command)._idup(); |
25 | 689 program.command = buffer; |
690 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; | |
691 | |
50 | 692 buffer = (fromStringz( application.id) ~ '\0')._idup(); |
86 | 693 Integer gnomeIconTheme = cast(Integer)display.getData(ICON_THEME_DATA); |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
694 char* icon_name = GNOME.gnome_icon_lookup( cast(GtkIconTheme*) gnomeIconTheme.intValue, null, null, cast(char*)buffer.ptr, null, mimeTypeBuffer, |
25 | 695 GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null); |
696 char* path = null; | |
108
b397a43d66d1
Updated swt linux for DMD 1.063 and latest Tango trunk.
Jacob Carlborg <doob@me.com>
parents:
86
diff
changeset
|
697 if (icon_name !is null) path = GNOME.gnome_icon_theme_lookup_icon(cast(GtkIconTheme*)gnomeIconTheme.intValue, icon_name, PREFERRED_ICON_SIZE, null, null); |
25 | 698 if (path !is null) { |
50 | 699 program.iconPath = fromStringz( path)._idup(); |
25 | 700 OS.g_free(path); |
701 } | |
702 if (icon_name !is null) OS.g_free(icon_name); | |
703 GNOME.gnome_vfs_mime_application_free(ptr); | |
704 } | |
705 return program; | |
706 } | |
707 | |
708 static bool gnome_init() { | |
709 return cast(bool) GNOME.gnome_vfs_init(); | |
710 } | |
711 | |
712 /** | |
713 * Finds the program that is associated with an extension. | |
714 * The extension may or may not begin with a '.'. Note that | |
715 * a <code>Display</code> must already exist to guarantee that | |
716 * this method returns an appropriate result. | |
717 * | |
718 * @param extension the program extension | |
719 * @return the program or <code>null</code> | |
720 * | |
721 */ | |
722 public static Program findProgram(String extension) { | |
723 return findProgram(Display.getCurrent(), extension); | |
724 } | |
725 | |
726 /* | |
727 * API: When support for multiple displays is added, this method will | |
728 * become public and the original method above can be deprecated. | |
729 */ | |
730 static Program findProgram(Display display, String extension) { | |
731 // SWT extension: allow null for zero length string | |
732 //if (extension is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
733 if (extension.length is 0) return null; | |
734 if (extension.charAt(0) !is '.') extension = "." ~ extension; | |
735 int desktop = getDesktop(display); | |
736 String mimeType = null; | |
737 switch (desktop) { | |
738 case DESKTOP_GNOME_24: | |
739 case DESKTOP_GNOME: mimeType = gnome_getMimeType(extension); break; | |
740 //case DESKTOP_CDE: mimeType = cde_getMimeType(extension); break; | |
741 default: | |
742 } | |
743 if (mimeType is null) return null; | |
744 Program program = null; | |
745 switch (desktop) { | |
746 case DESKTOP_GNOME_24: | |
747 case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; | |
748 //case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break; | |
749 default: | |
750 } | |
751 return program; | |
752 } | |
753 | |
754 /** | |
755 * Answer all program extensions in the operating system. Note | |
756 * that a <code>Display</code> must already exist to guarantee | |
757 * that this method returns an appropriate result. | |
758 * | |
759 * @return an array of extensions | |
760 */ | |
761 public static String[] getExtensions() { | |
762 return getExtensions(Display.getCurrent()); | |
763 } | |
764 | |
765 /* | |
766 * API: When support for multiple displays is added, this method will | |
767 * become public and the original method above can be deprecated. | |
768 */ | |
769 static String[] getExtensions(Display display) { | |
770 int desktop = getDesktop(display); | |
771 String[][ String ] mimeInfo = null; | |
772 switch (desktop) { | |
773 case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break; | |
774 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; | |
775 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; | |
776 default: | |
777 } | |
778 if (mimeInfo is null) return null; | |
779 | |
780 /* Create a unique set of the file extensions. */ | |
781 String[] extensions; | |
782 String[] keys = mimeInfo.keys; | |
783 int keyIdx = 0; | |
784 while ( keyIdx < keys.length ) { | |
785 String mimeType = keys[ keyIdx ]; | |
786 String[] mimeExts = mimeInfo[mimeType]; | |
787 for (int index = 0; index < mimeExts.length; index++){ | |
50 | 788 version(Tango){ |
55
ea8b884d85f6
[swt lin] fixed tango compile
Frank Benoit <benoit@tionex.de>
parents:
54
diff
changeset
|
789 bool contains = cast(bool)tango.core.Array.contains(extensions, mimeExts[index]); |
50 | 790 } else { // Phobos |
113
fb3aa8075988
D2 support for the linux port.
Jacob Carlborg <doob@me.com>
parents:
108
diff
changeset
|
791 bool contains = std.algorithm.canFind(extensions, mimeExts[index]); |
50 | 792 } |
793 if (!contains) { | |
25 | 794 extensions ~= mimeExts[index]; |
795 } | |
796 } | |
797 keyIdx++; | |
798 } | |
799 | |
800 /* Return the list of extensions. */ | |
801 String[] extStrings = new String[]( extensions.length ); | |
802 for (int index = 0; index < extensions.length; index++) { | |
803 extStrings[index] = extensions[index]; | |
804 } | |
805 return extStrings; | |
806 } | |
807 | |
808 /** | |
809 * Answers all available programs in the operating system. Note | |
810 * that a <code>Display</code> must already exist to guarantee | |
811 * that this method returns an appropriate result. | |
812 * | |
813 * @return an array of programs | |
814 */ | |
815 public static Program[] getPrograms() { | |
816 return getPrograms(Display.getCurrent()); | |
817 } | |
818 | |
819 /* | |
820 * API: When support for multiple displays is added, this method will | |
821 * become public and the original method above can be deprecated. | |
822 */ | |
823 static Program[] getPrograms(Display display) { | |
824 int desktop = getDesktop(display); | |
825 String[][ String ] mimeInfo = null; | |
826 switch (desktop) { | |
827 case DESKTOP_GNOME_24: break; | |
828 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; | |
829 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; | |
830 default: | |
831 } | |
832 if (mimeInfo is null) return new Program[0]; | |
833 Program[] programs; | |
834 String[] keys = mimeInfo.keys; | |
835 int keyIdx = 0; | |
836 while ( keyIdx < keys.length ) { | |
837 String mimeType = keys[ keyIdx ]; | |
838 Program program = null; | |
839 switch (desktop) { | |
840 case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; | |
841 //case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break; | |
842 default: | |
843 } | |
844 if (program !is null) programs ~= program; | |
845 keyIdx++; | |
846 } | |
847 Program[] programList = new Program[programs.length]; | |
848 for (int index = 0; index < programList.length; index++) { | |
849 programList[index] = programs[index]; | |
850 } | |
851 return programList; | |
852 } | |
853 | |
854 /** | |
855 * Launches the operating system executable associated with the file or | |
856 * URL (http:// or https://). If the file is an executable then the | |
857 * executable is launched. Note that a <code>Display</code> must already | |
858 * exist to guarantee that this method returns an appropriate result. | |
859 * | |
860 * @param fileName the file or program name or URL (http:// or https://) | |
861 * @return <code>true</code> if the file is launched, otherwise <code>false</code> | |
862 * | |
863 * @exception IllegalArgumentException <ul> | |
864 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> | |
865 * </ul> | |
866 */ | |
867 public static bool launch(String fileName) { | |
868 return launch(Display.getCurrent(), fileName); | |
869 } | |
870 | |
871 /* | |
872 * API: When support for multiple displays is added, this method will | |
873 * become public and the original method above can be deprecated. | |
874 */ | |
875 static bool launch (Display display, String fileName) { | |
876 if (fileName is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
877 switch (getDesktop (display)) { | |
878 case DESKTOP_GNOME_24: | |
879 if (gnome_24_launch (fileName)) return true; | |
880 default: | |
881 int index = fileName.lastIndexOf ('.'); | |
882 if (index !is -1) { | |
883 String extension = fileName.substring (index); | |
884 Program program = Program.findProgram (display, extension); | |
885 if (program !is null && program.execute (fileName)) return true; | |
886 } | |
887 String lowercaseName = fileName.toLowerCase (); | |
888 if (lowercaseName.startsWith (PREFIX_HTTP) || lowercaseName.startsWith (PREFIX_HTTPS)) { | |
889 Program program = Program.findProgram (display, ".html"); //$NON-NLS-1$ | |
890 if (program is null) { | |
891 program = Program.findProgram (display, ".htm"); //$NON-NLS-1$ | |
892 } | |
893 if (program !is null && program.execute (fileName)) return true; | |
894 } | |
895 break; | |
896 } | |
897 try { | |
898 Compatibility.exec (fileName); | |
899 return true; | |
900 } catch (IOException e) { | |
901 return false; | |
902 } | |
903 } | |
904 | |
905 /** | |
906 * Compares the argument to the receiver, and returns true | |
907 * if they represent the <em>same</em> object using a class | |
908 * specific comparison. | |
909 * | |
910 * @param other the object to compare with this object | |
911 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
912 * | |
913 * @see #hashCode() | |
914 */ | |
26 | 915 public override equals_t opEquals(Object other) { |
25 | 916 if (this is other) return true; |
917 if (!(cast(Program)other)) return false; | |
918 Program program = cast(Program)other; | |
919 return display is program.display && name.equals(program.name) && command.equals(program.command); | |
920 } | |
921 | |
922 /** | |
923 * Executes the program with the file as the single argument | |
924 * in the operating system. It is the responsibility of the | |
925 * programmer to ensure that the file contains valid data for | |
926 * this program. | |
927 * | |
928 * @param fileName the file or program name | |
929 * @return <code>true</code> if the file is launched, otherwise <code>false</code> | |
930 * | |
931 * @exception IllegalArgumentException <ul> | |
932 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> | |
933 * </ul> | |
934 */ | |
935 public bool execute(String fileName) { | |
936 if (fileName is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
937 int desktop = getDesktop(display); | |
938 switch (desktop) { | |
939 case DESKTOP_GNOME_24: return gnome_24_execute(fileName); | |
940 case DESKTOP_GNOME: return gnome_execute(fileName); | |
941 //case DESKTOP_CDE: return cde_execute(fileName); | |
942 default: | |
943 } | |
944 return false; | |
945 } | |
946 | |
947 /** | |
948 * Returns the receiver's image data. This is the icon | |
949 * that is associated with the receiver in the operating | |
950 * system. | |
951 * | |
952 * @return the image data for the program, may be null | |
953 */ | |
954 public ImageData getImageData() { | |
955 switch (getDesktop(display)) { | |
956 case DESKTOP_GNOME_24: | |
957 case DESKTOP_GNOME: return gnome_getImageData(); | |
958 //case DESKTOP_CDE: return cde_getImageData(); | |
959 default: | |
960 } | |
961 return null; | |
962 } | |
963 | |
964 /** | |
965 * Returns the receiver's name. This is as short and | |
966 * descriptive a name as possible for the program. If | |
967 * the program has no descriptive name, this string may | |
968 * be the executable name, path or empty. | |
969 * | |
970 * @return the name of the program | |
971 */ | |
972 public String getName() { | |
973 return name; | |
974 } | |
975 | |
976 /** | |
977 * Returns an integer hash code for the receiver. Any two | |
978 * objects that return <code>true</code> when passed to | |
979 * <code>equals</code> must return the same value for this | |
980 * method. | |
981 * | |
982 * @return the receiver's hash | |
983 * | |
984 * @see #equals(Object) | |
985 */ | |
986 public override hash_t toHash() { | |
987 return .toHash(name) ^ .toHash(command) ^ display.toHash(); | |
988 } | |
989 | |
990 /** | |
991 * Returns a string containing a concise, human-readable | |
992 * description of the receiver. | |
993 * | |
994 * @return a string representation of the program | |
995 */ | |
996 public String toString() { | |
997 return Format( "Program {{{}}", name ); | |
998 } | |
999 } |