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