Mercurial > projects > dwt-linux
diff dwt/program/Program.d @ 206:3cb84407dc3e
Temporary impl for Program.getExtensions on gnome 2.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 08 Mar 2008 23:00:05 +0100 |
parents | 5db57b8ff1a9 |
children | 380bad9f6852 |
line wrap: on
line diff
--- 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;