Index: Eclipse SWT Program/gnome/library/gnome.c =================================================================== RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome.c,v --- Eclipse SWT Program/gnome/library/gnome.c 10 Nov 2004 16:58:06 -0000 1.10 +++ Eclipse SWT Program/gnome/library/gnome.c 2 May 2005 23:50:51 -0000 @@ -98,7 +98,7 @@ GNOME_NATIVE_ENTER(env, that, _1gnome_1icon_1theme_1lookup_1icon_FUNC); if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail; if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail; - rc = (jint)gnome_icon_theme_lookup_icon((GnomeIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4); + rc = (jint)gnome_icon_theme_lookup_icon((GtkIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4); fail: if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); @@ -201,6 +201,68 @@ } #endif +#ifndef NO__1gnome_1vfs_1mime_1type_1from_1name +JNIEXPORT jint JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1type_1from_1name) + (JNIEnv *env, jclass that, jbyteArray arg0) +{ + jbyte *lparg0=NULL; + jint rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1mime_1type_1from_1name_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + rc = (jint)gnome_vfs_mime_type_from_name(lparg0); +fail: + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1mime_1type_1from_1name_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1icon_1info_1free +JNIEXPORT void JNICALL GNOME_NATIVE(_1gtk_1icon_1info_1free) + (JNIEnv *env, jclass that, jint arg0) +{ + GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1info_1free_FUNC); + gtk_icon_info_free((GtkIconInfo *)arg0); + GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1info_1free_FUNC); +} +#endif + +#ifndef NO__1gtk_1icon_1theme_1get_1default +JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1theme_1get_1default) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1theme_1get_1default_FUNC); + rc = (jint)gtk_icon_theme_get_default(); + GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1theme_1get_1default_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1icon_1info_1get_1filename +JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1info_1get_1filename) + (JNIEnv *env, jclass that, jint arg0) +{ + jint rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1info_1get_1filename_FUNC); + rc = (jint)gtk_icon_info_get_filename((GtkIconInfo *)arg0); + GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1info_1get_1filename_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1icon_1theme_1lookup_1icon +JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1theme_1lookup_1icon) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3) +{ + jint rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1theme_1lookup_1icon_FUNC); + rc = (jint)gtk_icon_theme_lookup_icon((GtkIconTheme *)arg0, (const char *)arg1, arg2, (GtkIconLookupFlags)arg3); + GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1theme_1lookup_1icon_FUNC); + return rc; +} +#endif + #ifndef NO_memmove JNIEXPORT void JNICALL GNOME_NATIVE(memmove) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2) Index: Eclipse SWT Program/gnome/library/gnome_stats.c =================================================================== RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.c,v --- Eclipse SWT Program/gnome/library/gnome_stats.c 10 Nov 2004 16:58:06 -0000 1.8 +++ Eclipse SWT Program/gnome/library/gnome_stats.c 2 May 2005 23:50:51 -0000 @@ -18,8 +18,8 @@ #ifdef NATIVE_STATS -int GNOME_nativeFunctionCount = 15; -int GNOME_nativeFunctionCallCount[15]; +int GNOME_nativeFunctionCount = 20; +int GNOME_nativeFunctionCallCount[20]; char * GNOME_nativeFunctionNames[] = { "GnomeVFSMimeApplication_1sizeof", "_1g_1free", @@ -35,6 +35,11 @@ "_1gnome_1vfs_1mime_1get_1default_1application", "_1gnome_1vfs_1mime_1get_1extensions_1list", "_1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free", + "_1gnome_1vfs_1mime_1type_1from_1name", + "_1gtk_1icon_1info_1free", + "_1gtk_1icon_1info_1get_1filename", + "_1gtk_1icon_1theme_1get_1default", + "_1gtk_1icon_1theme_1lookup_1icon", "memmove", }; Index: Eclipse SWT Program/gnome/library/gnome_stats.h =================================================================== RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.h,v --- Eclipse SWT Program/gnome/library/gnome_stats.h 10 Nov 2004 16:58:06 -0000 1.7 +++ Eclipse SWT Program/gnome/library/gnome_stats.h 2 May 2005 23:50:51 -0000 @@ -39,5 +39,10 @@ _1gnome_1vfs_1mime_1get_1default_1application_FUNC, _1gnome_1vfs_1mime_1get_1extensions_1list_FUNC, _1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free_FUNC, + _1gnome_1vfs_1mime_1type_1from_1name_FUNC, + _1gtk_1icon_1info_1free_FUNC, + _1gtk_1icon_1info_1get_1filename_FUNC, + _1gtk_1icon_1theme_1get_1default_FUNC, + _1gtk_1icon_1theme_1lookup_1icon_FUNC, memmove_FUNC, } GNOME_FUNCS; Index: Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java =================================================================== RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java,v --- Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java 10 Nov 2004 16:58:06 -0000 1.7 +++ Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java 2 May 2005 23:50:51 -0000 @@ -144,5 +144,50 @@ lock.unlock(); } } +public static final native int /*long*/ _gnome_vfs_mime_type_from_name(byte[] file); +public static final int /*long*/ gnome_vfs_mime_type_from_name(byte[] file) { + lock.lock(); + try { + return _gnome_vfs_mime_type_from_name(file); + } finally { + lock.unlock(); + } +} +public static final native void _gtk_icon_info_free(int icon_info); +public static final void gtk_icon_info_free(int icon_info) { + lock.lock(); + try { + _gtk_icon_info_free(icon_info); + } finally { + lock.unlock(); + } +} +public static final native int /*long*/ _gtk_icon_theme_get_default(); +public static final int /*long*/ gtk_icon_theme_get_default() { + lock.lock(); + try { + return _gtk_icon_theme_get_default(); + } finally { + lock.unlock(); + } +} +public static final native int /*long*/ _gtk_icon_info_get_filename(int icon_info); +public static final int /*long*/ gtk_icon_info_get_filename(int icon_info) { + lock.lock(); + try { + return _gtk_icon_info_get_filename(icon_info); + } finally { + lock.unlock(); + } +} +public static final native int /*long*/ _gtk_icon_theme_lookup_icon(int icon_theme, int icon_name, int size, int flags); +public static final int /*long*/ gtk_icon_theme_lookup_icon(int icon_theme, int icon_name, int size, int flags) { + lock.lock(); + try { + return _gtk_icon_theme_lookup_icon(icon_theme, icon_name, size, flags); + } finally { + lock.unlock(); + } +} public static final native void memmove (GnomeVFSMimeApplication dest, int /*long*/ src, int /*long*/ count); } Index: Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java =================================================================== RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java,v --- Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java 1 Mar 2005 13:08:50 -0000 1.49 +++ Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java 2 May 2005 23:50:52 -0000 @@ -11,17 +11,24 @@ package org.eclipse.swt.program; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gnome.*; -import org.eclipse.swt.internal.kde.*; -import org.eclipse.swt.internal.cde.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.widgets.*; - -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.internal.Compatibility; +import org.eclipse.swt.internal.Converter; +import org.eclipse.swt.internal.Library; +import org.eclipse.swt.internal.cde.CDE; +import org.eclipse.swt.internal.cde.DtActionArg; +import org.eclipse.swt.internal.gnome.GNOME; +import org.eclipse.swt.internal.gnome.GnomeVFSMimeApplication; +import org.eclipse.swt.internal.gtk.OS; +import org.eclipse.swt.internal.kde.KDE; +import org.eclipse.swt.widgets.Display; /** * Instances of this class represent programs and @@ -412,32 +419,41 @@ program.command = new String(Converter.mbcsToWcs(null, buffer)); program.gnomeExpectUri = application.expects_uris == GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; - length = OS.strlen(application.id); - buffer = new byte[length + 1]; - OS.memmove(buffer, application.id, length); - /* - * Note. gnome_icon_theme_new uses g_object_new to allocate the data it returns. - * Use g_object_unref to free the pointer it returns. - */ - int /*long*/ icon_theme = GNOME.gnome_icon_theme_new(); - int /*long*/ icon_name = GNOME.gnome_icon_lookup(icon_theme, 0, null, buffer, 0, mimeTypeBuffer, - GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null); - int /*long*/ path = 0; - if (icon_name != 0) path = GNOME.gnome_icon_theme_lookup_icon(icon_theme, icon_name, PREFERRED_ICON_SIZE, null, null); - GNOME.g_object_unref(icon_theme); - if (path != 0) { - length = OS.strlen(path); + setIconPath(program, mimeType, PREFERRED_ICON_SIZE); + + GNOME.gnome_vfs_mime_application_free(ptr); + } + return program; +} + +static void setIconPath(Program program, String mimeType, int iconSize) { + byte[] mimeTypeBuffer = Converter.wcsToMbcs(null, mimeType, true); + /* + * Note. gnome_icon_theme_new uses g_object_new to allocate the data it returns. + * Use g_object_unref to free the pointer it returns. + * + * Note2. gnome_icon_theme_new id deprecated. Now using gtk_icon_theme_get_default. No need to free it. + */ + int /*long*/ icon_theme = GNOME.gtk_icon_theme_get_default(); + int /*long*/ icon_name = GNOME.gnome_icon_lookup(icon_theme, 0, null, /*buffer*/ null, 0, mimeTypeBuffer, + GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null); + int icon_info = 0; + int /*long*/ path = 0; + if (icon_name != 0) icon_info = GNOME.gtk_icon_theme_lookup_icon(icon_theme, icon_name, iconSize, 0); + //GNOME.g_object_unref(icon_theme); + if (icon_info != 0) { + path = GNOME.gtk_icon_info_get_filename(icon_info); + if (path != 0) { + int length = OS.strlen(path); if (length > 0) { - buffer = new byte[length]; + byte[] buffer = new byte[length]; OS.memmove(buffer, path, length); program.iconPath = new String(Converter.mbcsToWcs(null, buffer)); } - GNOME.g_free(path); - } - if (icon_name != 0) GNOME.g_free(icon_name); - GNOME.gnome_vfs_mime_application_free(ptr); + } } - return program; + if (icon_name != 0) GNOME.g_free(icon_name); + if (icon_info != 0) GNOME.gtk_icon_info_free(icon_info); } static boolean gnome_init() { @@ -664,29 +680,8 @@ * become public and the original method above can be deprecated. */ static Program findProgram(Display display, String extension) { - if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (extension.length() == 0) return null; - if (extension.charAt(0) != '.') extension = "." + extension; int desktop = getDesktop(display); - Hashtable mimeInfo = null; - switch (desktop) { - case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break; - case DESKTOP_KDE: mimeInfo = kde_getMimeInfo(); break; - case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break; - } - if (mimeInfo == null) return null; - String mimeType = null; - Enumeration keys = mimeInfo.keys(); - while (mimeType == null && keys.hasMoreElements()) { - String type = (String)keys.nextElement(); - Vector mimeExts = (Vector)mimeInfo.get(type); - for (int index = 0; index < mimeExts.size(); index++){ - if (extension.equals(mimeExts.elementAt(index))) { - mimeType = type; - break; - } - } - } + String mimeType = getMimeTypeForExtension(display, extension); if (mimeType == null) return null; Program program = null; switch (desktop) { @@ -697,6 +692,42 @@ return program; } +static String getMimeTypeForExtension(Display display, String extension) { + int desktop = getDesktop(display); + if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (extension.length() == 0) return null; + if (extension.charAt(0) != '.') extension = "." + extension; + Hashtable mimeInfo = null; + String mimeType = null; + if (desktop == DESKTOP_CDE) { + mimeInfo = cde_getDataTypeInfo(); + if (mimeInfo == null) return null; + Enumeration keys = mimeInfo.keys(); + while (mimeType == null && keys.hasMoreElements()) { + String type = (String)keys.nextElement(); + Vector mimeExts = (Vector)mimeInfo.get(type); + for (int index = 0; index < mimeExts.size(); index++){ + if (extension.equals(mimeExts.elementAt(index))) { + mimeType = type; + break; + } + } + } + } else { + byte[] extensionBuffer = Converter.wcsToMbcs(null, extension, true); + int /*long*/ type = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); + if (type != 0) { + int length = OS.strlen(type); + if (length > 0) { + byte [] buffer = new byte[length]; + OS.memmove(buffer, type, length); + mimeType = new String(Converter.mbcsToWcs(null, buffer)); + } + } + } + return mimeType; +} + /** * Answer all program extensions in the operating system. Note * that a Display must already exist to guarantee @@ -744,6 +775,38 @@ } /** + * Finds the system image associated with an extension. + * The extension may or may not begin with a '.'. Note that + * a Display must already exist to guarantee that + * this method returns an appropriate result. + * + * @param extension the program extension + * @param iconSize the size of the icon to get + * @return ImageData, a system generic icon if the extension does not have an associated mime type, + * or null if we can't get the generic icon. + */ +public static ImageData getImageData(String extension, int iconSize) { + if (iconSize == 0) iconSize = PREFERRED_ICON_SIZE; + + Display display = Display.getCurrent(); + String mimeType = getMimeTypeForExtension(display, extension); + if (mimeType == null) { + // Try and get a 'generic' icon + mimeType = getMimeTypeForExtension(display, "unknown"); + } + if (mimeType == null) return null; // we tried... + return getImageDataForMimeType(display, mimeType, iconSize); +} + +static ImageData getImageDataForMimeType(Display display, String mimeType, int iconSize) { + if ( display == null || mimeType == null) return null; + Program program = new Program(); + program.display = display; + setIconPath(program, mimeType, iconSize); + return program.getImageData(); +} + +/** * Answers all available programs in the operating system. Note * that a Display must already exist to guarantee * that this method returns an appropriate result. @@ -786,6 +849,12 @@ return programList; } +final static String folderMimeType = "x-directory"; +public static ImageData getSystemFolderImageData(int iconSize) { + if (iconSize == 0) iconSize = PREFERRED_ICON_SIZE; + return getImageDataForMimeType(Display.getCurrent(), folderMimeType, iconSize); +} + /** * Launches the executable associated with the file in * the operating system. If the file is an executable,