# HG changeset patch # User Frank Benoit # Date 1205013605 -3600 # Node ID 3cb84407dc3ebbd6756f9def3b30ef8bc10230e7 # Parent 0fca38f4a7c0f369530658c49f1e5dcb61546e05 Temporary impl for Program.getExtensions on gnome 2.4 diff -r 0fca38f4a7c0 -r 3cb84407dc3e dwt/program/Program.d --- a/dwt/program/Program.d Sat Mar 08 22:59:15 2008 +0100 +++ b/dwt/program/Program.d Sat Mar 08 23:00:05 2008 +0100 @@ -28,6 +28,8 @@ import tango.core.Exception; import tango.core.Array; import tango.text.convert.Format; +import tango.io.FileConduit; +import tango.text.stream.LineIterator; version( build ){ pragma(link, "gnomeui-2" ); @@ -583,6 +585,34 @@ return null; } +/++ + + DWT Extension + + This is a temporary workaround until SWT will get the real implementation. + +/ +static char[][][ char[] ] 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; + foreach (line; it ){ + int colon = line.indexOf(':'); + if( colon is line.length ){ + continue; + } + if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){ + continue; + } + char[] mimeType = line[0..colon].dup; + char[] ext = line[colon+3 .. $].dup; + if( auto exts = mimeType in mimeInfo ){ + mimeInfo[ mimeType ] = *exts ~ ext; + } + else{ + mimeInfo[ mimeType ] = [ ext ]; + } + } + return mimeInfo; +} /** * GNOME - Get mime types * @@ -727,12 +757,12 @@ int desktop = getDesktop(display); char[][][ char[] ] mimeInfo = null; switch (desktop) { - case DESKTOP_GNOME_24: break; + case DESKTOP_GNOME_24: mimeInfo = gnome24_getMimeInfo(); break; case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; //case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; default: } - if (mimeInfo is null) return new char[][0]; + if (mimeInfo is null) return null; /* Create a unique set of the file extensions. */ char[][] extensions;