comparison dwt/program/Program.d @ 238:380bad9f6852

reverted char[] to String
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:42:55 +0200
parents 3cb84407dc3e
children ce446666f5a2
comparison
equal deleted inserted replaced
237:98b80b00af79 238:380bad9f6852
175 * Instances of this class represent programs and 175 * Instances of this class represent programs and
176 * their associated file extensions in the operating 176 * their associated file extensions in the operating
177 * system. 177 * system.
178 */ 178 */
179 public final class Program { 179 public final class Program {
180 char[] name; 180 String name;
181 char[] command; 181 String command;
182 char[] iconPath; 182 String iconPath;
183 Display display; 183 Display display;
184 184
185 /* Gnome specific 185 /* Gnome specific
186 * true if command expects a URI 186 * true if command expects a URI
187 * false if expects a path 187 * false if expects a path
188 */ 188 */
189 bool gnomeExpectUri; 189 bool gnomeExpectUri;
190 190
191 static int /*long*/ cdeShell; 191 static int /*long*/ cdeShell;
192 192
193 static const char[][] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ]; 193 static const String[] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ];
194 static const char[][] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ]; 194 static const String[] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ];
195 static const char[] DESKTOP_DATA = "Program_DESKTOP"; 195 static const String DESKTOP_DATA = "Program_DESKTOP";
196 static const char[] ICON_THEME_DATA = "Program_GNOME_ICON_THEME"; 196 static const String ICON_THEME_DATA = "Program_GNOME_ICON_THEME";
197 static const int DESKTOP_UNKNOWN = 0; 197 static const int DESKTOP_UNKNOWN = 0;
198 static const int DESKTOP_GNOME = 1; 198 static const int DESKTOP_GNOME = 1;
199 static const int DESKTOP_GNOME_24 = 2; 199 static const int DESKTOP_GNOME_24 = 2;
200 static const int DESKTOP_CDE = 3; 200 static const int DESKTOP_CDE = 3;
201 static const int PREFERRED_ICON_SIZE = 16; 201 static const int PREFERRED_ICON_SIZE = 16;
234 * The workaround is to simply check that the window manager is a 234 * The workaround is to simply check that the window manager is a
235 * compliant one (property _NET_SUPPORTING_WM_CHECK) and to attempt to load 235 * compliant one (property _NET_SUPPORTING_WM_CHECK) and to attempt to load
236 * our native library that depends on gnome-vfs. 236 * our native library that depends on gnome-vfs.
237 */ 237 */
238 if (desktop is DESKTOP_UNKNOWN) { 238 if (desktop is DESKTOP_UNKNOWN) {
239 char[] gnomeName = "_NET_SUPPORTING_WM_CHECK"; 239 String gnomeName = "_NET_SUPPORTING_WM_CHECK";
240 int /*long*/ gnome = OS.XInternAtom(xDisplay, gnomeName.ptr, true); 240 int /*long*/ gnome = OS.XInternAtom(xDisplay, gnomeName.ptr, true);
241 if (gnome !is OS.None && gnome_init()) { 241 if (gnome !is OS.None && gnome_init()) {
242 desktop = DESKTOP_GNOME; 242 desktop = DESKTOP_GNOME;
243 int icon_theme = cast(int)GNOME.gnome_icon_theme_new(); 243 int icon_theme = cast(int)GNOME.gnome_icon_theme_new();
244 display.setData(ICON_THEME_DATA, new ValueWrapperInt(icon_theme)); 244 display.setData(ICON_THEME_DATA, new ValueWrapperInt(icon_theme));
255 */ 255 */
256 if (gnomeIconTheme.value !is 0) OS.g_object_unref( cast(void*)gnomeIconTheme.value); 256 if (gnomeIconTheme.value !is 0) OS.g_object_unref( cast(void*)gnomeIconTheme.value);
257 } 257 }
258 }); 258 });
259 /* Check for libgnomevfs-2 version 2.4 */ 259 /* Check for libgnomevfs-2 version 2.4 */
260 char[] buffer = "libgnomevfs-2.so.0"; 260 String buffer = "libgnomevfs-2.so.0";
261 auto libgnomevfs = SharedLib.load(buffer ); 261 auto libgnomevfs = SharedLib.load(buffer );
262 if (libgnomevfs !is null) { 262 if (libgnomevfs !is null) {
263 buffer = "gnome_vfs_url_show"; 263 buffer = "gnome_vfs_url_show";
264 void* gnome_vfs_url_show = libgnomevfs.getSymbol( buffer.ptr ); 264 void* gnome_vfs_url_show = libgnomevfs.getSymbol( buffer.ptr );
265 if (gnome_vfs_url_show !is null) { 265 if (gnome_vfs_url_show !is null) {
286 * On CDE, the atom below may exist without DTWM running. If the atom 286 * On CDE, the atom below may exist without DTWM running. If the atom
287 * below is defined, the CDE database exists and the available 287 * below is defined, the CDE database exists and the available
288 * applications can be queried. 288 * applications can be queried.
289 */ 289 */
290 if (desktop is DESKTOP_UNKNOWN) { 290 if (desktop is DESKTOP_UNKNOWN) {
291 char[] cdeName = "_DT_SM_PREFERENCES"; 291 String cdeName = "_DT_SM_PREFERENCES";
292 int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName.ptr, true); 292 int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName.ptr, true);
293 for (int index = 0; desktop is DESKTOP_UNKNOWN && index < property.length; index++) { 293 for (int index = 0; desktop is DESKTOP_UNKNOWN && index < property.length; index++) {
294 if (property[index] is OS.None) continue; /* do not match atoms that do not exist */ 294 if (property[index] is OS.None) continue; /* do not match atoms that do not exist */
295 if (property[index] is cde && cde_init(display)) desktop = DESKTOP_CDE; 295 if (property[index] is cde && cde_init(display)) desktop = DESKTOP_CDE;
296 } 296 }
301 return desktop; 301 return desktop;
302 } 302 }
303 303
304 // PORTING CDE not supported 304 // PORTING CDE not supported
305 /+ 305 /+
306 bool cde_execute(char[] fileName) { 306 bool cde_execute(String fileName) {
307 /* Use the character encoding for the default locale */ 307 /* Use the character encoding for the default locale */
308 char* action = toStringz(command); 308 char* action = toStringz(command);
309 char* ptr = cast(char*)OS.g_malloc(fileName.length+1); 309 char* ptr = cast(char*)OS.g_malloc(fileName.length+1);
310 ptr[ 0 .. fileName.length ] = fileName; 310 ptr[ 0 .. fileName.length ] = fileName;
311 ptr[ fileName.length ] = 0; 311 ptr[ fileName.length ] = 0;
315 long actionID = CDE.DtActionInvoke(cdeShell, action, args, 1, null, null, null, 1, 0, 0); 315 long actionID = CDE.DtActionInvoke(cdeShell, action, args, 1, null, null, null, 1, 0, 0);
316 OS.g_free(ptr); 316 OS.g_free(ptr);
317 return actionID !is 0; 317 return actionID !is 0;
318 } 318 }
319 319
320 static char[] cde_getAction(char[] dataType) { 320 static String cde_getAction(String dataType) {
321 char[] action = null; 321 String action = null;
322 char[] actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); 322 String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST);
323 if (actions !is null) { 323 if (actions !is null) {
324 int index = actions.indexOf("Open"); 324 int index = actions.indexOf("Open");
325 if (index !is -1) { 325 if (index !is -1) {
326 action = actions.substring(index, index + 4); 326 action = actions.substring(index, index + 4);
327 } else { 327 } else {
330 } 330 }
331 } 331 }
332 return action; 332 return action;
333 } 333 }
334 334
335 static char[] cde_getAttribute(char[] dataType, char[] attrName) { 335 static String cde_getAttribute(String dataType, String attrName) {
336 /* Use the character encoding for the default locale */ 336 /* Use the character encoding for the default locale */
337 byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true); 337 byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true);
338 byte[] attrNameBuf = Converter.wcsToMbcs(null, attrName, true); 338 byte[] attrNameBuf = Converter.wcsToMbcs(null, attrName, true);
339 byte[] optNameBuf = null; 339 byte[] optNameBuf = null;
340 int /*long*/ attrValue = CDE.DtDtsDataTypeToAttributeValue(dataTypeBuf, attrNameBuf, optNameBuf); 340 int /*long*/ attrValue = CDE.DtDtsDataTypeToAttributeValue(dataTypeBuf, attrNameBuf, optNameBuf);
342 int length = OS.strlen(attrValue); 342 int length = OS.strlen(attrValue);
343 byte[] attrValueBuf = new byte[length]; 343 byte[] attrValueBuf = new byte[length];
344 OS.memmove(attrValueBuf, attrValue, length); 344 OS.memmove(attrValueBuf, attrValue, length);
345 CDE.DtDtsFreeAttributeValue(attrValue); 345 CDE.DtDtsFreeAttributeValue(attrValue);
346 /* Use the character encoding for the default locale */ 346 /* Use the character encoding for the default locale */
347 return new char[](Converter.mbcsToWcs(null, attrValueBuf)); 347 return new String(Converter.mbcsToWcs(null, attrValueBuf));
348 } 348 }
349 349
350 static char[][][ char[] ] cde_getDataTypeInfo() { 350 static String[][ String ] cde_getDataTypeInfo() {
351 char[][][ char[] ] dataTypeInfo; 351 String[][ String ] dataTypeInfo;
352 int index; 352 int index;
353 int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames(); 353 int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames();
354 if (dataTypeList !is 0) { 354 if (dataTypeList !is 0) {
355 /* For each data type name in the list */ 355 /* For each data type name in the list */
356 index = 0; 356 index = 0;
359 while (dataType[0] !is 0) { 359 while (dataType[0] !is 0) {
360 int length = OS.strlen(dataType[0]); 360 int length = OS.strlen(dataType[0]);
361 byte[] dataTypeBuf = new byte[length]; 361 byte[] dataTypeBuf = new byte[length];
362 OS.memmove(dataTypeBuf, dataType[0], length); 362 OS.memmove(dataTypeBuf, dataType[0], length);
363 /* Use the character encoding for the default locale */ 363 /* Use the character encoding for the default locale */
364 char[] dataTypeName = new char[](Converter.mbcsToWcs(null, dataTypeBuf)); 364 String dataTypeName = new String(Converter.mbcsToWcs(null, dataTypeBuf));
365 365
366 /* The data type is valid if it is not an action, and it has an extension and an action. */ 366 /* The data type is valid if it is not an action, and it has an extension and an action. */
367 char[] extension = cde_getExtension(dataTypeName); 367 String extension = cde_getExtension(dataTypeName);
368 if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) && 368 if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) &&
369 extension !is null && cde_getAction(dataTypeName) !is null) { 369 extension !is null && cde_getAction(dataTypeName) !is null) {
370 char[][] exts; 370 String[] exts;
371 exts ~= extension; 371 exts ~= extension;
372 dataTypeInfo[ dataTypeName ] = exts; 372 dataTypeInfo[ dataTypeName ] = exts;
373 } 373 }
374 OS.memmove(dataType, dataTypeList + (index++ * 4), 4); 374 OS.memmove(dataType, dataTypeList + (index++ * 4), 4);
375 } 375 }
377 } 377 }
378 378
379 return dataTypeInfo; 379 return dataTypeInfo;
380 } 380 }
381 381
382 static char[] cde_getExtension(char[] dataType) { 382 static String cde_getExtension(String dataType) {
383 char[] fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); 383 String fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE);
384 if (fileExt is null || fileExt.indexOf("%s.") is -1) return null; 384 if (fileExt is null || fileExt.indexOf("%s.") is -1) return null;
385 int dot = fileExt.indexOf("."); 385 int dot = fileExt.indexOf(".");
386 return fileExt.substring(dot); 386 return fileExt.substring(dot);
387 } 387 }
388 388
400 ImageData cde_getImageData() { 400 ImageData cde_getImageData() {
401 // TODO 401 // TODO
402 return null; 402 return null;
403 } 403 }
404 404
405 static char[] cde_getMimeType(char[] extension) { 405 static String cde_getMimeType(String extension) {
406 char[] mimeType = null; 406 String mimeType = null;
407 char[][][ char[] ] mimeInfo = cde_getDataTypeInfo(); 407 String[][ String ] mimeInfo = cde_getDataTypeInfo();
408 if (mimeInfo is null) return null; 408 if (mimeInfo is null) return null;
409 char[][] keys = mimeInfo.keys(); 409 String[] keys = mimeInfo.keys();
410 int keyIdx = 0; 410 int keyIdx = 0;
411 while (mimeType is null && keyIdx < keys.length ) { 411 while (mimeType is null && keyIdx < keys.length ) {
412 char[] type = keys[ keyIdx ]; 412 String type = keys[ keyIdx ];
413 char[][] mimeExts = mimeInfo[type]; 413 String[] mimeExts = mimeInfo[type];
414 for (int index = 0; index < mimeExts.length; index++){ 414 for (int index = 0; index < mimeExts.length; index++){
415 if (extension.equals(mimeExts[index])) { 415 if (extension.equals(mimeExts[index])) {
416 mimeType = type; 416 mimeType = type;
417 break; 417 break;
418 } 418 }
420 keyIdx++; 420 keyIdx++;
421 } 421 }
422 return mimeType; 422 return mimeType;
423 } 423 }
424 424
425 static Program cde_getProgram(Display display, char[] mimeType) { 425 static Program cde_getProgram(Display display, String mimeType) {
426 Program program = new Program(); 426 Program program = new Program();
427 program.display = display; 427 program.display = display;
428 program.name = mimeType; 428 program.name = mimeType;
429 program.command = cde_getAction(mimeType); 429 program.command = cde_getAction(mimeType);
430 program.iconPath = cde_getAttribute(program.name, CDE.DtDTS_DA_ICON); 430 program.iconPath = cde_getAttribute(program.name, CDE.DtDTS_DA_ICON);
455 if (initOK) CDE.DtDbLoad(); 455 if (initOK) CDE.DtDbLoad();
456 return initOK; 456 return initOK;
457 } 457 }
458 +/ 458 +/
459 459
460 static char[][] parseCommand(char[] cmd) { 460 static String[] parseCommand(String cmd) {
461 char[][] args; 461 String[] args;
462 int sIndex = 0; 462 int sIndex = 0;
463 int eIndex; 463 int eIndex;
464 while (sIndex < cmd.length) { 464 while (sIndex < cmd.length) {
465 /* Trim initial white space of argument. */ 465 /* Trim initial white space of argument. */
466 while (sIndex < cmd.length && Compatibility.isWhitespace(cmd.charAt(sIndex))) { 466 while (sIndex < cmd.length && Compatibility.isWhitespace(cmd.charAt(sIndex))) {
493 sIndex = eIndex + 1; 493 sIndex = eIndex + 1;
494 } 494 }
495 } 495 }
496 } 496 }
497 497
498 char[][] strings = new char[][args.length]; 498 String[] strings = new String[args.length];
499 for (int index =0; index < args.length; index++) { 499 for (int index =0; index < args.length; index++) {
500 strings[index] = args[index]; 500 strings[index] = args[index];
501 } 501 }
502 return strings; 502 return strings;
503 } 503 }
504 504
505 /** 505 /**
506 * GNOME 2.4 - Execute the program for the given file. 506 * GNOME 2.4 - Execute the program for the given file.
507 */ 507 */
508 bool gnome_24_execute(char[] fileName) { 508 bool gnome_24_execute(String fileName) {
509 char* mimeTypeBuffer = toStringz(name); 509 char* mimeTypeBuffer = toStringz(name);
510 auto ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); 510 auto ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer);
511 char* fileNameBuffer = toStringz(fileName); 511 char* fileNameBuffer = toStringz(fileName);
512 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); 512 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT);
513 GList* list = OS.g_list_append( null, uri); 513 GList* list = OS.g_list_append( null, uri);
519 } 519 }
520 520
521 /** 521 /**
522 * GNOME 2.4 - Launch the default program for the given file. 522 * GNOME 2.4 - Launch the default program for the given file.
523 */ 523 */
524 static bool gnome_24_launch(char[] fileName) { 524 static bool gnome_24_launch(String fileName) {
525 char* fileNameBuffer = toStringz(fileName); 525 char* fileNameBuffer = toStringz(fileName);
526 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); 526 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT);
527 int result = GNOME.gnome_vfs_url_show(uri); 527 int result = GNOME.gnome_vfs_url_show(uri);
528 OS.g_free(uri); 528 OS.g_free(uri);
529 return (result is GNOME.GNOME_VFS_OK); 529 return (result is GNOME.GNOME_VFS_OK);
530 } 530 }
531 531
532 /** 532 /**
533 * GNOME 2.2 - Execute the program for the given file. 533 * GNOME 2.2 - Execute the program for the given file.
534 */ 534 */
535 bool gnome_execute(char[] fileName) { 535 bool gnome_execute(String fileName) {
536 if (gnomeExpectUri) { 536 if (gnomeExpectUri) {
537 /* Convert the given path into a URL */ 537 /* Convert the given path into a URL */
538 char* fileNameBuffer = toStringz(fileName); 538 char* fileNameBuffer = toStringz(fileName);
539 char* uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer); 539 char* uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer);
540 if (uri !is null) { 540 if (uri !is null) {
542 OS.g_free(uri); 542 OS.g_free(uri);
543 } 543 }
544 } 544 }
545 545
546 /* Parse the command into its individual arguments. */ 546 /* Parse the command into its individual arguments. */
547 char[][] args = parseCommand(command); 547 String[] args = parseCommand(command);
548 int fileArg = -1; 548 int fileArg = -1;
549 int index; 549 int index;
550 for (index = 0; index < args.length; index++) { 550 for (index = 0; index < args.length; index++) {
551 int j = args[index].indexOf("%f"); 551 int j = args[index].indexOf("%f");
552 if (j !is -1) { 552 if (j !is -1) {
553 char[] value = args[index]; 553 String value = args[index];
554 fileArg = index; 554 fileArg = index;
555 args[index] = value.substring(0, j) ~ fileName ~ value.substring(j + 2); 555 args[index] = value.substring(0, j) ~ fileName ~ value.substring(j + 2);
556 } 556 }
557 } 557 }
558 558
559 /* If a file name was given but the command did not have "%f" */ 559 /* If a file name was given but the command did not have "%f" */
560 if ((fileName.length > 0) && (fileArg < 0)) { 560 if ((fileName.length > 0) && (fileArg < 0)) {
561 char[][] newArgs = new char[][args.length + 1]; 561 String[] newArgs = new String[args.length + 1];
562 for (index = 0; index < args.length; index++) newArgs[index] = args[index]; 562 for (index = 0; index < args.length; index++) newArgs[index] = args[index];
563 newArgs[args.length] = fileName; 563 newArgs[args.length] = fileName;
564 args = newArgs; 564 args = newArgs;
565 } 565 }
566 566
587 587
588 /++ 588 /++
589 + DWT Extension 589 + DWT Extension
590 + This is a temporary workaround until SWT will get the real implementation. 590 + This is a temporary workaround until SWT will get the real implementation.
591 +/ 591 +/
592 static char[][][ char[] ] gnome24_getMimeInfo() { 592 static String[][ String ] gnome24_getMimeInfo() {
593 scope file = new FileConduit ("/usr/share/mime/globs"); 593 scope file = new FileConduit ("/usr/share/mime/globs");
594 scope it = new LineIterator!(char)(file); 594 scope it = new LineIterator!(char)(file);
595 // process file one line at a time 595 // process file one line at a time
596 char[][][ char[] ] mimeInfo; 596 String[][ String ] mimeInfo;
597 foreach (line; it ){ 597 foreach (line; it ){
598 int colon = line.indexOf(':'); 598 int colon = line.indexOf(':');
599 if( colon is line.length ){ 599 if( colon is line.length ){
600 continue; 600 continue;
601 } 601 }
602 if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){ 602 if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){
603 continue; 603 continue;
604 } 604 }
605 char[] mimeType = line[0..colon].dup; 605 String mimeType = line[0..colon].dup;
606 char[] ext = line[colon+3 .. $].dup; 606 String ext = line[colon+3 .. $].dup;
607 if( auto exts = mimeType in mimeInfo ){ 607 if( auto exts = mimeType in mimeInfo ){
608 mimeInfo[ mimeType ] = *exts ~ ext; 608 mimeInfo[ mimeType ] = *exts ~ ext;
609 } 609 }
610 else{ 610 else{
611 mimeInfo[ mimeType ] = [ ext ]; 611 mimeInfo[ mimeType ] = [ ext ];
619 * Obtain the registered mime type information and 619 * Obtain the registered mime type information and
620 * return it in a map. The key of each entry 620 * return it in a map. The key of each entry
621 * in the map is the mime type name. The value is 621 * in the map is the mime type name. The value is
622 * a vector of the associated file extensions. 622 * a vector of the associated file extensions.
623 */ 623 */
624 static char[][][ char[] ] gnome_getMimeInfo() { 624 static String[][ String ] gnome_getMimeInfo() {
625 char[][][ char[] ] mimeInfo; 625 String[][ String ] mimeInfo;
626 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types(); 626 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types();
627 GList* mimeElement = mimeList; 627 GList* mimeElement = mimeList;
628 while (mimeElement !is null) { 628 while (mimeElement !is null) {
629 char* mimePtr = cast(char*) OS.g_list_data(mimeElement); 629 char* mimePtr = cast(char*) OS.g_list_data(mimeElement);
630 char[] mimeTypeBuffer = fromStringz(mimePtr).dup; 630 String mimeTypeBuffer = fromStringz(mimePtr).dup;
631 char[] mimeType = mimeTypeBuffer;//new char[](Converter.mbcsToWcs(null, mimeTypeBuffer)); 631 String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer));
632 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr); 632 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr);
633 if (extensionList !is null) { 633 if (extensionList !is null) {
634 char[][] extensions; 634 String[] extensions;
635 GList* extensionElement = extensionList; 635 GList* extensionElement = extensionList;
636 while (extensionElement !is null) { 636 while (extensionElement !is null) {
637 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement); 637 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement);
638 char[] extensionBuffer = fromStringz(extensionPtr).dup; 638 String extensionBuffer = fromStringz(extensionPtr).dup;
639 char[] extension = extensionBuffer; 639 String extension = extensionBuffer;
640 extension = '.' ~ extension; 640 extension = '.' ~ extension;
641 extensions ~= extension; 641 extensions ~= extension;
642 extensionElement = OS.g_list_next(extensionElement); 642 extensionElement = OS.g_list_next(extensionElement);
643 } 643 }
644 GNOME.gnome_vfs_mime_extensions_list_free(extensionList); 644 GNOME.gnome_vfs_mime_extensions_list_free(extensionList);
648 } 648 }
649 if (mimeList !is null) GNOME.gnome_vfs_mime_registered_mime_type_list_free(mimeList); 649 if (mimeList !is null) GNOME.gnome_vfs_mime_registered_mime_type_list_free(mimeList);
650 return mimeInfo; 650 return mimeInfo;
651 } 651 }
652 652
653 static char[] gnome_getMimeType(char[] extension) { 653 static String gnome_getMimeType(String extension) {
654 char[] mimeType = null; 654 String mimeType = null;
655 char[] fileName = "swt" ~ extension; 655 String fileName = "swt" ~ extension;
656 char* extensionBuffer = toStringz(fileName); 656 char* extensionBuffer = toStringz(fileName);
657 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); 657 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer);
658 if (typeName !is null) { 658 if (typeName !is null) {
659 mimeType = fromStringz(typeName).dup; 659 mimeType = fromStringz(typeName).dup;
660 } 660 }
661 return mimeType; 661 return mimeType;
662 } 662 }
663 663
664 static Program gnome_getProgram(Display display, char[] mimeType) { 664 static Program gnome_getProgram(Display display, String mimeType) {
665 Program program = null; 665 Program program = null;
666 char* mimeTypeBuffer = toStringz(mimeType); 666 char* mimeTypeBuffer = toStringz(mimeType);
667 GnomeVFSMimeApplication* ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); 667 GnomeVFSMimeApplication* ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer);
668 if (ptr !is null) { 668 if (ptr !is null) {
669 program = new Program(); 669 program = new Program();
670 program.display = display; 670 program.display = display;
671 program.name = mimeType; 671 program.name = mimeType;
672 GnomeVFSMimeApplication* application = ptr; 672 GnomeVFSMimeApplication* application = ptr;
673 char[] buffer = fromStringz(application.command).dup; 673 String buffer = fromStringz(application.command).dup;
674 program.command = buffer; 674 program.command = buffer;
675 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; 675 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS;
676 676
677 buffer = fromStringz( application.id) ~ \0; 677 buffer = fromStringz( application.id) ~ \0;
678 ValueWrapperInt gnomeIconTheme = cast(ValueWrapperInt)display.getData(ICON_THEME_DATA); 678 ValueWrapperInt gnomeIconTheme = cast(ValueWrapperInt)display.getData(ICON_THEME_DATA);
705 * 705 *
706 * @exception IllegalArgumentException <ul> 706 * @exception IllegalArgumentException <ul>
707 * <li>ERROR_NULL_ARGUMENT when extension is null</li> 707 * <li>ERROR_NULL_ARGUMENT when extension is null</li>
708 * </ul> 708 * </ul>
709 */ 709 */
710 public static Program findProgram(char[] extension) { 710 public static Program findProgram(String extension) {
711 return findProgram(Display.getCurrent(), extension); 711 return findProgram(Display.getCurrent(), extension);
712 } 712 }
713 713
714 /* 714 /*
715 * API: When support for multiple displays is added, this method will 715 * API: When support for multiple displays is added, this method will
716 * become public and the original method above can be deprecated. 716 * become public and the original method above can be deprecated.
717 */ 717 */
718 static Program findProgram(Display display, char[] extension) { 718 static Program findProgram(Display display, String extension) {
719 if (extension is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 719 if (extension is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
720 if (extension.length is 0) return null; 720 if (extension.length is 0) return null;
721 if (extension.charAt(0) !is '.') extension = "." ~ extension; 721 if (extension.charAt(0) !is '.') extension = "." ~ extension;
722 int desktop = getDesktop(display); 722 int desktop = getDesktop(display);
723 char[] mimeType = null; 723 String mimeType = null;
724 switch (desktop) { 724 switch (desktop) {
725 case DESKTOP_GNOME_24: 725 case DESKTOP_GNOME_24:
726 case DESKTOP_GNOME: mimeType = gnome_getMimeType(extension); break; 726 case DESKTOP_GNOME: mimeType = gnome_getMimeType(extension); break;
727 //case DESKTOP_CDE: mimeType = cde_getMimeType(extension); break; 727 //case DESKTOP_CDE: mimeType = cde_getMimeType(extension); break;
728 default: 728 default:
743 * that a <code>Display</code> must already exist to guarantee 743 * that a <code>Display</code> must already exist to guarantee
744 * that this method returns an appropriate result. 744 * that this method returns an appropriate result.
745 * 745 *
746 * @return an array of extensions 746 * @return an array of extensions
747 */ 747 */
748 public static char[][] getExtensions() { 748 public static String[] getExtensions() {
749 return getExtensions(Display.getCurrent()); 749 return getExtensions(Display.getCurrent());
750 } 750 }
751 751
752 /* 752 /*
753 * API: When support for multiple displays is added, this method will 753 * API: When support for multiple displays is added, this method will
754 * become public and the original method above can be deprecated. 754 * become public and the original method above can be deprecated.
755 */ 755 */
756 static char[][] getExtensions(Display display) { 756 static String[] getExtensions(Display display) {
757 int desktop = getDesktop(display); 757 int desktop = getDesktop(display);
758 char[][][ char[] ] mimeInfo = null; 758 String[][ String ] mimeInfo = null;
759 switch (desktop) { 759 switch (desktop) {
760 case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break; 760 case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break;
761 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; 761 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break;
762 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; 762 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break;
763 default: 763 default:
764 } 764 }
765 if (mimeInfo is null) return null; 765 if (mimeInfo is null) return null;
766 766
767 /* Create a unique set of the file extensions. */ 767 /* Create a unique set of the file extensions. */
768 char[][] extensions; 768 String[] extensions;
769 char[][] keys = mimeInfo.keys; 769 String[] keys = mimeInfo.keys;
770 int keyIdx = 0; 770 int keyIdx = 0;
771 while ( keyIdx < keys.length ) { 771 while ( keyIdx < keys.length ) {
772 char[] mimeType = keys[ keyIdx ]; 772 String mimeType = keys[ keyIdx ];
773 char[][] mimeExts = mimeInfo[mimeType]; 773 String[] mimeExts = mimeInfo[mimeType];
774 for (int index = 0; index < mimeExts.length; index++){ 774 for (int index = 0; index < mimeExts.length; index++){
775 if (!extensions.contains(mimeExts[index])) { 775 if (!extensions.contains(mimeExts[index])) {
776 extensions ~= mimeExts[index]; 776 extensions ~= mimeExts[index];
777 } 777 }
778 } 778 }
779 keyIdx++; 779 keyIdx++;
780 } 780 }
781 781
782 /* Return the list of extensions. */ 782 /* Return the list of extensions. */
783 char[][] extStrings = new char[][]( extensions.length ); 783 String[] extStrings = new String[]( extensions.length );
784 for (int index = 0; index < extensions.length; index++) { 784 for (int index = 0; index < extensions.length; index++) {
785 extStrings[index] = extensions[index]; 785 extStrings[index] = extensions[index];
786 } 786 }
787 return extStrings; 787 return extStrings;
788 } 788 }
802 * API: When support for multiple displays is added, this method will 802 * API: When support for multiple displays is added, this method will
803 * become public and the original method above can be deprecated. 803 * become public and the original method above can be deprecated.
804 */ 804 */
805 static Program[] getPrograms(Display display) { 805 static Program[] getPrograms(Display display) {
806 int desktop = getDesktop(display); 806 int desktop = getDesktop(display);
807 char[][][ char[] ] mimeInfo = null; 807 String[][ String ] mimeInfo = null;
808 switch (desktop) { 808 switch (desktop) {
809 case DESKTOP_GNOME_24: break; 809 case DESKTOP_GNOME_24: break;
810 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; 810 case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break;
811 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; 811 //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break;
812 default: 812 default:
813 } 813 }
814 if (mimeInfo is null) return new Program[0]; 814 if (mimeInfo is null) return new Program[0];
815 Program[] programs; 815 Program[] programs;
816 char[][] keys = mimeInfo.keys; 816 String[] keys = mimeInfo.keys;
817 int keyIdx = 0; 817 int keyIdx = 0;
818 while ( keyIdx < keys.length ) { 818 while ( keyIdx < keys.length ) {
819 char[] mimeType = keys[ keyIdx ]; 819 String mimeType = keys[ keyIdx ];
820 Program program = null; 820 Program program = null;
821 switch (desktop) { 821 switch (desktop) {
822 case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; 822 case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break;
823 //case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break; 823 //case DESKTOP_CDE: program = cde_getProgram(display, mimeType); break;
824 default: 824 default:
845 * 845 *
846 * @exception IllegalArgumentException <ul> 846 * @exception IllegalArgumentException <ul>
847 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> 847 * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
848 * </ul> 848 * </ul>
849 */ 849 */
850 public static bool launch(char[] fileName) { 850 public static bool launch(String fileName) {
851 return launch(Display.getCurrent(), fileName); 851 return launch(Display.getCurrent(), fileName);
852 } 852 }
853 853
854 /* 854 /*
855 * API: When support for multiple displays is added, this method will 855 * API: When support for multiple displays is added, this method will
856 * become public and the original method above can be deprecated. 856 * become public and the original method above can be deprecated.
857 */ 857 */
858 static bool launch(Display display, char[] fileName) { 858 static bool launch(Display display, String fileName) {
859 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 859 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
860 switch(getDesktop(display)) { 860 switch(getDesktop(display)) {
861 case DESKTOP_GNOME_24: 861 case DESKTOP_GNOME_24:
862 if (gnome_24_launch (fileName)) return true; 862 if (gnome_24_launch (fileName)) return true;
863 default: 863 default:
864 int index = fileName.lastIndexOf('.'); 864 int index = fileName.lastIndexOf('.');
865 if (index !is -1) { 865 if (index !is -1) {
866 char[] extension = fileName.substring (index); 866 String extension = fileName.substring (index);
867 Program program = Program.findProgram (display, extension); 867 Program program = Program.findProgram (display, extension);
868 if (program !is null && program.execute (fileName)) return true; 868 if (program !is null && program.execute (fileName)) return true;
869 } 869 }
870 break; 870 break;
871 } 871 }
905 * 905 *
906 * @exception IllegalArgumentException <ul> 906 * @exception IllegalArgumentException <ul>
907 * <li>ERROR_NULL_ARGUMENT when fileName is null</li> 907 * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
908 * </ul> 908 * </ul>
909 */ 909 */
910 public bool execute(char[] fileName) { 910 public bool execute(String fileName) {
911 if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 911 if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
912 int desktop = getDesktop(display); 912 int desktop = getDesktop(display);
913 switch (desktop) { 913 switch (desktop) {
914 case DESKTOP_GNOME_24: return gnome_24_execute(fileName); 914 case DESKTOP_GNOME_24: return gnome_24_execute(fileName);
915 case DESKTOP_GNOME: return gnome_execute(fileName); 915 case DESKTOP_GNOME: return gnome_execute(fileName);
942 * the program has no descriptive name, this string may 942 * the program has no descriptive name, this string may
943 * be the executable name, path or empty. 943 * be the executable name, path or empty.
944 * 944 *
945 * @return the name of the program 945 * @return the name of the program
946 */ 946 */
947 public char[] getName() { 947 public String getName() {
948 return name; 948 return name;
949 } 949 }
950 950
951 /** 951 /**
952 * Returns an integer hash code for the receiver. Any two 952 * Returns an integer hash code for the receiver. Any two
966 * Returns a string containing a concise, human-readable 966 * Returns a string containing a concise, human-readable
967 * description of the receiver. 967 * description of the receiver.
968 * 968 *
969 * @return a string representation of the program 969 * @return a string representation of the program
970 */ 970 */
971 public char[] toString() { 971 public String toString() {
972 return Format( "Program {{{}}", name ); 972 return Format( "Program {{{}}", name );
973 } 973 }
974 } 974 }