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