Mercurial > projects > dwt-linux
diff 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 |
line wrap: on
line diff
--- a/dwt/program/Program.d Sat Apr 26 10:01:30 2008 +0200 +++ b/dwt/program/Program.d Mon May 05 00:42:55 2008 +0200 @@ -177,9 +177,9 @@ * system. */ public final class Program { - char[] name; - char[] command; - char[] iconPath; + String name; + String command; + String iconPath; Display display; /* Gnome specific @@ -190,10 +190,10 @@ static int /*long*/ cdeShell; - static const char[][] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ]; - static const char[][] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ]; - static const char[] DESKTOP_DATA = "Program_DESKTOP"; - static const char[] ICON_THEME_DATA = "Program_GNOME_ICON_THEME"; + static const String[] CDE_ICON_EXT = [ ".m.pm"[], ".l.pm", ".s.pm", ".t.pm" ]; + static const String[] CDE_MASK_EXT = [ ".m_m.bm"[], ".l_m.bm", ".s_m.bm", ".t_m.bm" ]; + static const String DESKTOP_DATA = "Program_DESKTOP"; + static const String ICON_THEME_DATA = "Program_GNOME_ICON_THEME"; static const int DESKTOP_UNKNOWN = 0; static const int DESKTOP_GNOME = 1; static const int DESKTOP_GNOME_24 = 2; @@ -236,7 +236,7 @@ * our native library that depends on gnome-vfs. */ if (desktop is DESKTOP_UNKNOWN) { - char[] gnomeName = "_NET_SUPPORTING_WM_CHECK"; + String gnomeName = "_NET_SUPPORTING_WM_CHECK"; int /*long*/ gnome = OS.XInternAtom(xDisplay, gnomeName.ptr, true); if (gnome !is OS.None && gnome_init()) { desktop = DESKTOP_GNOME; @@ -257,7 +257,7 @@ } }); /* Check for libgnomevfs-2 version 2.4 */ - char[] buffer = "libgnomevfs-2.so.0"; + String buffer = "libgnomevfs-2.so.0"; auto libgnomevfs = SharedLib.load(buffer ); if (libgnomevfs !is null) { buffer = "gnome_vfs_url_show"; @@ -288,7 +288,7 @@ * applications can be queried. */ if (desktop is DESKTOP_UNKNOWN) { - char[] cdeName = "_DT_SM_PREFERENCES"; + String cdeName = "_DT_SM_PREFERENCES"; int /*long*/ cde = OS.XInternAtom(xDisplay, cdeName.ptr, true); for (int index = 0; desktop is DESKTOP_UNKNOWN && index < property.length; index++) { if (property[index] is OS.None) continue; /* do not match atoms that do not exist */ @@ -303,7 +303,7 @@ // PORTING CDE not supported /+ -bool cde_execute(char[] fileName) { +bool cde_execute(String fileName) { /* Use the character encoding for the default locale */ char* action = toStringz(command); char* ptr = cast(char*)OS.g_malloc(fileName.length+1); @@ -317,9 +317,9 @@ return actionID !is 0; } -static char[] cde_getAction(char[] dataType) { - char[] action = null; - char[] actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); +static String cde_getAction(String dataType) { + String action = null; + String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); if (actions !is null) { int index = actions.indexOf("Open"); if (index !is -1) { @@ -332,7 +332,7 @@ return action; } -static char[] cde_getAttribute(char[] dataType, char[] attrName) { +static String cde_getAttribute(String dataType, String attrName) { /* Use the character encoding for the default locale */ byte[] dataTypeBuf = Converter.wcsToMbcs(null, dataType, true); byte[] attrNameBuf = Converter.wcsToMbcs(null, attrName, true); @@ -344,11 +344,11 @@ OS.memmove(attrValueBuf, attrValue, length); CDE.DtDtsFreeAttributeValue(attrValue); /* Use the character encoding for the default locale */ - return new char[](Converter.mbcsToWcs(null, attrValueBuf)); + return new String(Converter.mbcsToWcs(null, attrValueBuf)); } -static char[][][ char[] ] cde_getDataTypeInfo() { - char[][][ char[] ] dataTypeInfo; +static String[][ String ] cde_getDataTypeInfo() { + String[][ String ] dataTypeInfo; int index; int /*long*/ dataTypeList = CDE.DtDtsDataTypeNames(); if (dataTypeList !is 0) { @@ -361,13 +361,13 @@ byte[] dataTypeBuf = new byte[length]; OS.memmove(dataTypeBuf, dataType[0], length); /* Use the character encoding for the default locale */ - char[] dataTypeName = new char[](Converter.mbcsToWcs(null, dataTypeBuf)); + String dataTypeName = new String(Converter.mbcsToWcs(null, dataTypeBuf)); /* The data type is valid if it is not an action, and it has an extension and an action. */ - char[] extension = cde_getExtension(dataTypeName); + String extension = cde_getExtension(dataTypeName); if (!CDE.DtDtsDataTypeIsAction(dataTypeBuf) && extension !is null && cde_getAction(dataTypeName) !is null) { - char[][] exts; + String[] exts; exts ~= extension; dataTypeInfo[ dataTypeName ] = exts; } @@ -379,8 +379,8 @@ return dataTypeInfo; } -static char[] cde_getExtension(char[] dataType) { - char[] fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); +static String cde_getExtension(String dataType) { + String fileExt = cde_getAttribute(dataType, CDE.DtDTS_DA_NAME_TEMPLATE); if (fileExt is null || fileExt.indexOf("%s.") is -1) return null; int dot = fileExt.indexOf("."); return fileExt.substring(dot); @@ -402,15 +402,15 @@ return null; } -static char[] cde_getMimeType(char[] extension) { - char[] mimeType = null; - char[][][ char[] ] mimeInfo = cde_getDataTypeInfo(); +static String cde_getMimeType(String extension) { + String mimeType = null; + String[][ String ] mimeInfo = cde_getDataTypeInfo(); if (mimeInfo is null) return null; - char[][] keys = mimeInfo.keys(); + String[] keys = mimeInfo.keys(); int keyIdx = 0; while (mimeType is null && keyIdx < keys.length ) { - char[] type = keys[ keyIdx ]; - char[][] mimeExts = mimeInfo[type]; + String type = keys[ keyIdx ]; + String[] mimeExts = mimeInfo[type]; for (int index = 0; index < mimeExts.length; index++){ if (extension.equals(mimeExts[index])) { mimeType = type; @@ -422,7 +422,7 @@ return mimeType; } -static Program cde_getProgram(Display display, char[] mimeType) { +static Program cde_getProgram(Display display, String mimeType) { Program program = new Program(); program.display = display; program.name = mimeType; @@ -457,8 +457,8 @@ } +/ -static char[][] parseCommand(char[] cmd) { - char[][] args; +static String[] parseCommand(String cmd) { + String[] args; int sIndex = 0; int eIndex; while (sIndex < cmd.length) { @@ -495,7 +495,7 @@ } } - char[][] strings = new char[][args.length]; + String[] strings = new String[args.length]; for (int index =0; index < args.length; index++) { strings[index] = args[index]; } @@ -505,7 +505,7 @@ /** * GNOME 2.4 - Execute the program for the given file. */ -bool gnome_24_execute(char[] fileName) { +bool gnome_24_execute(String fileName) { char* mimeTypeBuffer = toStringz(name); auto ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); char* fileNameBuffer = toStringz(fileName); @@ -521,7 +521,7 @@ /** * GNOME 2.4 - Launch the default program for the given file. */ -static bool gnome_24_launch(char[] fileName) { +static bool gnome_24_launch(String fileName) { char* fileNameBuffer = toStringz(fileName); char* uri = GNOME.gnome_vfs_make_uri_from_input_with_dirs(fileNameBuffer, GNOME.GNOME_VFS_MAKE_URI_DIR_CURRENT); int result = GNOME.gnome_vfs_url_show(uri); @@ -532,7 +532,7 @@ /** * GNOME 2.2 - Execute the program for the given file. */ -bool gnome_execute(char[] fileName) { +bool gnome_execute(String fileName) { if (gnomeExpectUri) { /* Convert the given path into a URL */ char* fileNameBuffer = toStringz(fileName); @@ -544,13 +544,13 @@ } /* Parse the command into its individual arguments. */ - char[][] args = parseCommand(command); + String[] args = parseCommand(command); int fileArg = -1; int index; for (index = 0; index < args.length; index++) { int j = args[index].indexOf("%f"); if (j !is -1) { - char[] value = args[index]; + String value = args[index]; fileArg = index; args[index] = value.substring(0, j) ~ fileName ~ value.substring(j + 2); } @@ -558,7 +558,7 @@ /* If a file name was given but the command did not have "%f" */ if ((fileName.length > 0) && (fileArg < 0)) { - char[][] newArgs = new char[][args.length + 1]; + String[] newArgs = new String[args.length + 1]; for (index = 0; index < args.length; index++) newArgs[index] = args[index]; newArgs[args.length] = fileName; args = newArgs; @@ -589,11 +589,11 @@ + DWT Extension + This is a temporary workaround until SWT will get the real implementation. +/ -static char[][][ char[] ] gnome24_getMimeInfo() { +static String[][ String ] gnome24_getMimeInfo() { scope file = new FileConduit ("/usr/share/mime/globs"); scope it = new LineIterator!(char)(file); // process file one line at a time - char[][][ char[] ] mimeInfo; + String[][ String ] mimeInfo; foreach (line; it ){ int colon = line.indexOf(':'); if( colon is line.length ){ @@ -602,8 +602,8 @@ if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){ continue; } - char[] mimeType = line[0..colon].dup; - char[] ext = line[colon+3 .. $].dup; + String mimeType = line[0..colon].dup; + String ext = line[colon+3 .. $].dup; if( auto exts = mimeType in mimeInfo ){ mimeInfo[ mimeType ] = *exts ~ ext; } @@ -621,22 +621,22 @@ * in the map is the mime type name. The value is * a vector of the associated file extensions. */ -static char[][][ char[] ] gnome_getMimeInfo() { - char[][][ char[] ] mimeInfo; +static String[][ String ] gnome_getMimeInfo() { + String[][ String ] mimeInfo; GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types(); GList* mimeElement = mimeList; while (mimeElement !is null) { char* mimePtr = cast(char*) OS.g_list_data(mimeElement); - char[] mimeTypeBuffer = fromStringz(mimePtr).dup; - char[] mimeType = mimeTypeBuffer;//new char[](Converter.mbcsToWcs(null, mimeTypeBuffer)); + String mimeTypeBuffer = fromStringz(mimePtr).dup; + String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer)); GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr); if (extensionList !is null) { - char[][] extensions; + String[] extensions; GList* extensionElement = extensionList; while (extensionElement !is null) { char* extensionPtr = cast(char*) OS.g_list_data(extensionElement); - char[] extensionBuffer = fromStringz(extensionPtr).dup; - char[] extension = extensionBuffer; + String extensionBuffer = fromStringz(extensionPtr).dup; + String extension = extensionBuffer; extension = '.' ~ extension; extensions ~= extension; extensionElement = OS.g_list_next(extensionElement); @@ -650,9 +650,9 @@ return mimeInfo; } -static char[] gnome_getMimeType(char[] extension) { - char[] mimeType = null; - char[] fileName = "swt" ~ extension; +static String gnome_getMimeType(String extension) { + String mimeType = null; + String fileName = "swt" ~ extension; char* extensionBuffer = toStringz(fileName); char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); if (typeName !is null) { @@ -661,7 +661,7 @@ return mimeType; } -static Program gnome_getProgram(Display display, char[] mimeType) { +static Program gnome_getProgram(Display display, String mimeType) { Program program = null; char* mimeTypeBuffer = toStringz(mimeType); GnomeVFSMimeApplication* ptr = GNOME.gnome_vfs_mime_get_default_application(mimeTypeBuffer); @@ -670,7 +670,7 @@ program.display = display; program.name = mimeType; GnomeVFSMimeApplication* application = ptr; - char[] buffer = fromStringz(application.command).dup; + String buffer = fromStringz(application.command).dup; program.command = buffer; program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; @@ -707,7 +707,7 @@ * <li>ERROR_NULL_ARGUMENT when extension is null</li> * </ul> */ -public static Program findProgram(char[] extension) { +public static Program findProgram(String extension) { return findProgram(Display.getCurrent(), extension); } @@ -715,12 +715,12 @@ * API: When support for multiple displays is added, this method will * become public and the original method above can be deprecated. */ -static Program findProgram(Display display, char[] extension) { +static Program findProgram(Display display, String extension) { if (extension is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); if (extension.length is 0) return null; if (extension.charAt(0) !is '.') extension = "." ~ extension; int desktop = getDesktop(display); - char[] mimeType = null; + String mimeType = null; switch (desktop) { case DESKTOP_GNOME_24: case DESKTOP_GNOME: mimeType = gnome_getMimeType(extension); break; @@ -745,7 +745,7 @@ * * @return an array of extensions */ -public static char[][] getExtensions() { +public static String[] getExtensions() { return getExtensions(Display.getCurrent()); } @@ -753,9 +753,9 @@ * API: When support for multiple displays is added, this method will * become public and the original method above can be deprecated. */ -static char[][] getExtensions(Display display) { +static String[] getExtensions(Display display) { int desktop = getDesktop(display); - char[][][ char[] ] mimeInfo = null; + String[][ String ] mimeInfo = null; switch (desktop) { case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break; case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; @@ -765,12 +765,12 @@ if (mimeInfo is null) return null; /* Create a unique set of the file extensions. */ - char[][] extensions; - char[][] keys = mimeInfo.keys; + String[] extensions; + String[] keys = mimeInfo.keys; int keyIdx = 0; while ( keyIdx < keys.length ) { - char[] mimeType = keys[ keyIdx ]; - char[][] mimeExts = mimeInfo[mimeType]; + String mimeType = keys[ keyIdx ]; + String[] mimeExts = mimeInfo[mimeType]; for (int index = 0; index < mimeExts.length; index++){ if (!extensions.contains(mimeExts[index])) { extensions ~= mimeExts[index]; @@ -780,7 +780,7 @@ } /* Return the list of extensions. */ - char[][] extStrings = new char[][]( extensions.length ); + String[] extStrings = new String[]( extensions.length ); for (int index = 0; index < extensions.length; index++) { extStrings[index] = extensions[index]; } @@ -804,7 +804,7 @@ */ static Program[] getPrograms(Display display) { int desktop = getDesktop(display); - char[][][ char[] ] mimeInfo = null; + String[][ String ] mimeInfo = null; switch (desktop) { case DESKTOP_GNOME_24: break; case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; @@ -813,10 +813,10 @@ } if (mimeInfo is null) return new Program[0]; Program[] programs; - char[][] keys = mimeInfo.keys; + String[] keys = mimeInfo.keys; int keyIdx = 0; while ( keyIdx < keys.length ) { - char[] mimeType = keys[ keyIdx ]; + String mimeType = keys[ keyIdx ]; Program program = null; switch (desktop) { case DESKTOP_GNOME: program = gnome_getProgram(display, mimeType); break; @@ -847,7 +847,7 @@ * <li>ERROR_NULL_ARGUMENT when fileName is null</li> * </ul> */ -public static bool launch(char[] fileName) { +public static bool launch(String fileName) { return launch(Display.getCurrent(), fileName); } @@ -855,7 +855,7 @@ * API: When support for multiple displays is added, this method will * become public and the original method above can be deprecated. */ -static bool launch(Display display, char[] fileName) { +static bool launch(Display display, String fileName) { if (fileName is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); switch(getDesktop(display)) { case DESKTOP_GNOME_24: @@ -863,7 +863,7 @@ default: int index = fileName.lastIndexOf('.'); if (index !is -1) { - char[] extension = fileName.substring (index); + String extension = fileName.substring (index); Program program = Program.findProgram (display, extension); if (program !is null && program.execute (fileName)) return true; } @@ -907,7 +907,7 @@ * <li>ERROR_NULL_ARGUMENT when fileName is null</li> * </ul> */ -public bool execute(char[] fileName) { +public bool execute(String fileName) { if (fileName is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); int desktop = getDesktop(display); switch (desktop) { @@ -944,7 +944,7 @@ * * @return the name of the program */ -public char[] getName() { +public String getName() { return name; } @@ -968,7 +968,7 @@ * * @return a string representation of the program */ -public char[] toString() { +public String toString() { return Format( "Program {{{}}", name ); } }