Changeset 238:380bad9f6852 for dwt/program/Program.d
- Timestamp:
- 05/04/08 18:42:55 (4 years ago)
- Files:
-
- dwt/program/Program.d (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/program/Program.d
r206 r238 178 178 */ 179 179 public final class Program { 180 char[]name;181 char[]command;182 char[]iconPath;180 String name; 181 String command; 182 String iconPath; 183 183 Display display; 184 184 … … 191 191 static int /*long*/ cdeShell; 192 192 193 static const char[][] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ];194 static const char[][] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ];195 static const char[]DESKTOP_DATA = "Program_DESKTOP";196 static const char[]ICON_THEME_DATA = "Program_GNOME_ICON_THEME";193 static const String[] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ]; 194 static const String[] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ]; 195 static const String DESKTOP_DATA = "Program_DESKTOP"; 196 static const String ICON_THEME_DATA = "Program_GNOME_ICON_THEME"; 197 197 static const int DESKTOP_UNKNOWN = 0; 198 198 static const int DESKTOP_GNOME = 1; … … 237 237 */ 238 238 if (desktop is DESKTOP_UNKNOWN) { 239 char[]gnomeName = "_NET_SUPPORTING_WM_CHECK";239 String gnomeName = "_NET_SUPPORTING_WM_CHECK"; 240 240 int /*long*/ gnome = OS.XInternAtom(xDisplay, gnomeName.ptr, true); 241 241 if (gnome !is OS.None && gnome_init()) { … … 258 258 }); 259 259 /* Check for libgnomevfs-2 version 2.4 */ 260 char[]buffer = "libgnomevfs-2.so.0";260 String buffer = "libgnomevfs-2.so.0"; 261 261 auto libgnomevfs = SharedLib.load(buffer ); 262 262 if (libgnomevfs !is null) { … … 289 289 */ 290 290 if (desktop is DESKTOP_UNKNOWN) { 291 char[]cdeName = "_DT_SM_PREFERENCES";291 String cdeName = "_DT_SM_PREFERENCES"; 292 292 int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName.ptr, true); 293 293 for (int index = 0; desktop is DESKTOP_UNKNOWN && index < property.length; index++) { … … 304 304 // PORTING CDE not supported 305 305 /+ 306 bool cde_execute( char[]fileName) {306 bool cde_execute(String fileName) { 307 307 /* Use the character encoding for the default locale */ 308 308 char* action = toStringz(command); … … 318 318 } 319 319 320 static char[] cde_getAction(char[]dataType) {321 char[]action = null;322 char[]actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST);320 static String cde_getAction(String dataType) { 321 String action = null; 322 String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); 323 323 if (actions !is null) { 324 324 int index = actions.indexOf("Open"); … … 333 333 } 334 334 335 static char[] cde_getAttribute(char[] dataType, char[]attrName) {335 static String cde_getAttribute(String dataType, String attrName) { 336 336 /* Use the character encoding for the default locale */ 337 337 byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true); … … 345 345 CDE.DtDtsFreeAttributeValue(attrValue); 346 346 /* Use the character encoding for the default locale */ 347 return new char[](Converter.mbcsToWcs(null, attrValueBuf));348 } 349 350 static char[][][ char[]] cde_getDataTypeInfo() {351 char[][][ char[]] dataTypeInfo;347 return new String(Converter.mbcsToWcs(null, attrValueBuf)); 348 } 349 350 static String[][ String ] cde_getDataTypeInfo() { 351 String[][ String ] dataTypeInfo; 352 352 int index; 353 353 int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames(); … … 362 362 OS.memmove(dataTypeBuf, dataType[0], length); 363 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 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 368 if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) && 369 369 extension !is null && cde_getAction(dataTypeName) !is null) { 370 char[][] exts;370 String[] exts; 371 371 exts ~= extension; 372 372 dataTypeInfo[ dataTypeName ] = exts; … … 380 380 } 381 381 382 static char[] cde_getExtension(char[]dataType) {383 char[]fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE);382 static String cde_getExtension(String dataType) { 383 String fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); 384 384 if (fileExt is null || fileExt.indexOf("%s.") is -1) return null; 385 385 int dot = fileExt.indexOf("."); … … 403 403 } 404 404 405 static char[] cde_getMimeType(char[]extension) {406 char[]mimeType = null;407 char[][][ char[]] mimeInfo = cde_getDataTypeInfo();405 static String cde_getMimeType(String extension) { 406 String mimeType = null; 407 String[][ String ] mimeInfo = cde_getDataTypeInfo(); 408 408 if (mimeInfo is null) return null; 409 char[][] keys = mimeInfo.keys();409 String[] keys = mimeInfo.keys(); 410 410 int keyIdx = 0; 411 411 while (mimeType is null && keyIdx < keys.length ) { 412 char[]type = keys[ keyIdx ];413 char[][] mimeExts = mimeInfo[type];412 String type = keys[ keyIdx ]; 413 String[] mimeExts = mimeInfo[type]; 414 414 for (int index = 0; index < mimeExts.length; index++){ 415 415 if (extension.equals(mimeExts[index])) { … … 423 423 } 424 424 425 static Program cde_getProgram(Display display, char[]mimeType) {425 static Program cde_getProgram(Display display, String mimeType) { 426 426 Program program = new Program(); 427 427 program.display = display; … … 458 458 +/ 459 459 460 static char[][] parseCommand(char[]cmd) {461 char[][] args;460 static String[] parseCommand(String cmd) { 461 String[] args; 462 462 int sIndex = 0; 463 463 int eIndex; … … 496 496 } 497 497 498 char[][] strings = new char[][args.length];498 String[] strings = new String[args.length]; 499 499 for (int index =0; index < args.length; index++) { 500 500 strings[index] = args[index]; … … 506 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 509 char* mimeTypeBuffer = toStringz(name); 510 510 auto ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); … … 522 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 525 char* fileNameBuffer = toStringz(fileName); 526 526 char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); … … 533 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 536 if (gnomeExpectUri) { 537 537 /* Convert the given path into a URL */ … … 545 545 546 546 /* Parse the command into its individual arguments. */ 547 char[][] args = parseCommand(command);547 String[] args = parseCommand(command); 548 548 int fileArg = -1; 549 549 int index; … … 551 551 int j = args[index].indexOf("%f"); 552 552 if (j !is -1) { 553 char[]value = args[index];553 String value = args[index]; 554 554 fileArg = index; 555 555 args[index] = value.substring(0, j) ~ fileName ~ value.substring(j + 2); … … 559 559 /* If a file name was given but the command did not have "%f" */ 560 560 if ((fileName.length > 0) && (fileArg < 0)) { 561 char[][] newArgs = new char[][args.length + 1];561 String[] newArgs = new String[args.length + 1]; 562 562 for (index = 0; index < args.length; index++) newArgs[index] = args[index]; 563 563 newArgs[args.length] = fileName; … … 590 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 593 scope file = new FileConduit ("/usr/share/mime/globs"); 594 594 scope it = new LineIterator!(char)(file); 595 595 // process file one line at a time 596 char[][][ char[]] mimeInfo;596 String[][ String ] mimeInfo; 597 597 foreach (line; it ){ 598 598 int colon = line.indexOf(':'); … … 603 603 continue; 604 604 } 605 char[]mimeType = line[0..colon].dup;606 char[]ext = line[colon+3 .. $].dup;605 String mimeType = line[0..colon].dup; 606 String ext = line[colon+3 .. $].dup; 607 607 if( auto exts = mimeType in mimeInfo ){ 608 608 mimeInfo[ mimeType ] = *exts ~ ext; … … 622 622 * a vector of the associated file extensions. 623 623 */ 624 static char[][][ char[]] gnome_getMimeInfo() {625 char[][][ char[]] mimeInfo;624 static String[][ String ] gnome_getMimeInfo() { 625 String[][ String ] mimeInfo; 626 626 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types(); 627 627 GList* mimeElement = mimeList; 628 628 while (mimeElement !is null) { 629 629 char* mimePtr = cast(char*) OS.g_list_data(mimeElement); 630 char[]mimeTypeBuffer = fromStringz(mimePtr).dup;631 char[] mimeType = mimeTypeBuffer;//new char[](Converter.mbcsToWcs(null, mimeTypeBuffer));630 String mimeTypeBuffer = fromStringz(mimePtr).dup; 631 String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer)); 632 632 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr); 633 633 if (extensionList !is null) { 634 char[][] extensions;634 String[] extensions; 635 635 GList* extensionElement = extensionList; 636 636 while (extensionElement !is null) { 637 637 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement); 638 char[]extensionBuffer = fromStringz(extensionPtr).dup;639 char[]extension = extensionBuffer;638 String extensionBuffer = fromStringz(extensionPtr).dup; 639 String extension = extensionBuffer; 640 640 extension = '.' ~ extension; 641 641 extensions ~= extension; … … 651 651 } 652 652 653 static char[] gnome_getMimeType(char[]extension) {654 char[]mimeType = null;655 char[]fileName = "swt" ~ extension;653 static String gnome_getMimeType(String extension) { 654 String mimeType = null; 655 String fileName = "swt" ~ extension; 656 656 char* extensionBuffer = toStringz(fileName); 657 657 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); … … 662 662 } 663 663 664 static Program gnome_getProgram(Display display, char[]mimeType) {664 static Program gnome_getProgram(Display display, String mimeType) { 665 665 Program program = null; 666 666 char* mimeTypeBuffer = toStringz(mimeType); … … 671 671 program.name = mimeType; 672 672 GnomeVFSMimeApplication* application = ptr; 673 char[]buffer = fromStringz(application.command).dup;673 String buffer = fromStringz(application.command).dup; 674 674 program.command = buffer; 675 675 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; … … 708 708 * </ul> 709 709 */ 710 public static Program findProgram( char[]extension) {710 public static Program findProgram(String extension) { 711 711 return findProgram(Display.getCurrent(), extension); 712 712 } … … 716 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 719 if (extension is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 720 720 if (extension.length is 0) return null; 721 721 if (extension.charAt(0) !is '.') extension = "." ~ extension; 722 722 int desktop = getDesktop(display); 723 char[]mimeType = null;723 String mimeType = null; 724 724 switch (desktop) { 725 725 case DESKTOP_GNOME_24: … … 746 746 * @return an array of extensions 747 747 */ 748 public static char[][] getExtensions() {748 public static String[] getExtensions() { 749 749 return getExtensions(Display.getCurrent()); 750 750 } … … 754 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 757 int desktop = getDesktop(display); 758 char[][][ char[]] mimeInfo = null;758 String[][ String ] mimeInfo = null; 759 759 switch (desktop) { 760 760 case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break; … … 766 766 767 767 /* Create a unique set of the file extensions. */ 768 char[][] extensions;769 char[][] keys = mimeInfo.keys;768 String[] extensions; 769 String[] keys = mimeInfo.keys; 770 770 int keyIdx = 0; 771 771 while ( keyIdx < keys.length ) { 772 char[]mimeType = keys[ keyIdx ];773 char[][] mimeExts = mimeInfo[mimeType];772 String mimeType = keys[ keyIdx ]; 773 String[] mimeExts = mimeInfo[mimeType]; 774 774 for (int index = 0; index < mimeExts.length; index++){ 775 775 if (!extensions.contains(mimeExts[index])) { … … 781 781 782 782 /* Return the list of extensions. */ 783 char[][] extStrings = new char[][]( extensions.length );783 String[] extStrings = new String[]( extensions.length ); 784 784 for (int index = 0; index < extensions.length; index++) { 785 785 extStrings[index] = extensions[index]; … … 805 805 static Program[] getPrograms(Display display) { 806 806 int desktop = getDesktop(display); 807 char[][][ char[]] mimeInfo = null;807 String[][ String ] mimeInfo = null; 808 808 switch (desktop) { 809 809 case DESKTOP_GNOME_24: break; … … 814 814 if (mimeInfo is null) return new Program[0]; 815 815 Program[] programs; 816 char[][] keys = mimeInfo.keys;816 String[] keys = mimeInfo.keys; 817 817 int keyIdx = 0; 818 818 while ( keyIdx < keys.length ) { 819 char[]mimeType = keys[ keyIdx ];819 String mimeType = keys[ keyIdx ]; 820 820 Program program = null; 821 821 switch (desktop) { … … 848 848 * </ul> 849 849 */ 850 public static bool launch( char[]fileName) {850 public static bool launch(String fileName) { 851 851 return launch(Display.getCurrent(), fileName); 852 852 } … … 856 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 859 if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 860 860 switch(getDesktop(display)) { … … 864 864 int index = fileName.lastIndexOf('.'); 865 865 if (index !is -1) { 866 char[]extension = fileName.substring (index);866 String extension = fileName.substring (index); 867 867 Program program = Program.findProgram (display, extension); 868 868 if (program !is null && program.execute (fileName)) return true; … … 908 908 * </ul> 909 909 */ 910 public bool execute( char[]fileName) {910 public bool execute(String fileName) { 911 911 if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 912 912 int desktop = getDesktop(display); … … 945 945 * @return the name of the program 946 946 */ 947 public char[]getName() {947 public String getName() { 948 948 return name; 949 949 } … … 969 969 * @return a string representation of the program 970 970 */ 971 public char[]toString() {971 public String toString() { 972 972 return Format( "Program {{{}}", name ); 973 973 }
