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