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