View | Details | Raw Unified | Return to bug 79268 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse SWT Program/gnome/library/gnome.c (-1 / +63 lines)
Lines 98-104 Link Here
98
	GNOME_NATIVE_ENTER(env, that, _1gnome_1icon_1theme_1lookup_1icon_FUNC);
98
	GNOME_NATIVE_ENTER(env, that, _1gnome_1icon_1theme_1lookup_1icon_FUNC);
99
	if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail;
99
	if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail;
100
	if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail;
100
	if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail;
101
	rc = (jint)gnome_icon_theme_lookup_icon((GnomeIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4);
101
	rc = (jint)gnome_icon_theme_lookup_icon((GtkIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4);
102
fail:
102
fail:
103
	if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0);
103
	if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0);
104
	if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0);
104
	if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0);
Lines 201-206 Link Here
201
}
201
}
202
#endif
202
#endif
203
203
204
#ifndef NO__1gnome_1vfs_1mime_1type_1from_1name
205
JNIEXPORT jint JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1type_1from_1name)
206
	(JNIEnv *env, jclass that, jbyteArray arg0)
207
{
208
	jbyte *lparg0=NULL;
209
	jint rc = 0;
210
	GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1mime_1type_1from_1name_FUNC);
211
	if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail;
212
	rc = (jint)gnome_vfs_mime_type_from_name(lparg0);
213
fail:
214
	if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
215
	GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1mime_1type_1from_1name_FUNC);
216
	return rc;
217
}
218
#endif
219
220
#ifndef NO__1gtk_1icon_1info_1free
221
JNIEXPORT void JNICALL GNOME_NATIVE(_1gtk_1icon_1info_1free)
222
	(JNIEnv *env, jclass that, jint arg0)
223
{
224
	GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1info_1free_FUNC);
225
	gtk_icon_info_free((GtkIconInfo *)arg0);
226
	GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1info_1free_FUNC);
227
}
228
#endif
229
230
#ifndef NO__1gtk_1icon_1theme_1get_1default
231
JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1theme_1get_1default)
232
	(JNIEnv *env, jclass that)
233
{
234
	jint rc = 0;
235
	GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1theme_1get_1default_FUNC);
236
	rc = (jint)gtk_icon_theme_get_default();
237
	GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1theme_1get_1default_FUNC);
238
	return rc;
239
}
240
#endif
241
242
#ifndef NO__1gtk_1icon_1info_1get_1filename
243
JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1info_1get_1filename)
244
	(JNIEnv *env, jclass that, jint arg0)
245
{
246
	jint rc = 0;
247
	GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1info_1get_1filename_FUNC);
248
	rc = (jint)gtk_icon_info_get_filename((GtkIconInfo *)arg0);
249
	GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1info_1get_1filename_FUNC);
250
	return rc;
251
}
252
#endif
253
254
#ifndef NO__1gtk_1icon_1theme_1lookup_1icon
255
JNIEXPORT jint JNICALL GNOME_NATIVE(_1gtk_1icon_1theme_1lookup_1icon)
256
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3)
257
{
258
	jint rc = 0;
259
	GNOME_NATIVE_ENTER(env, that, _1gtk_1icon_1theme_1lookup_1icon_FUNC);
260
	rc = (jint)gtk_icon_theme_lookup_icon((GtkIconTheme *)arg0, (const char *)arg1, arg2, (GtkIconLookupFlags)arg3);
261
	GNOME_NATIVE_EXIT(env, that, _1gtk_1icon_1theme_1lookup_1icon_FUNC);
262
	return rc;
263
}
264
#endif
265
204
#ifndef NO_memmove
266
#ifndef NO_memmove
205
JNIEXPORT void JNICALL GNOME_NATIVE(memmove)
267
JNIEXPORT void JNICALL GNOME_NATIVE(memmove)
206
	(JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2)
268
	(JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2)
(-)Eclipse SWT Program/gnome/library/gnome_stats.c (-2 / +7 lines)
Lines 18-25 Link Here
18
18
19
#ifdef NATIVE_STATS
19
#ifdef NATIVE_STATS
20
20
21
int GNOME_nativeFunctionCount = 15;
21
int GNOME_nativeFunctionCount = 20;
22
int GNOME_nativeFunctionCallCount[15];
22
int GNOME_nativeFunctionCallCount[20];
23
char * GNOME_nativeFunctionNames[] = {
23
char * GNOME_nativeFunctionNames[] = {
24
	"GnomeVFSMimeApplication_1sizeof",
24
	"GnomeVFSMimeApplication_1sizeof",
25
	"_1g_1free",
25
	"_1g_1free",
Lines 35-40 Link Here
35
	"_1gnome_1vfs_1mime_1get_1default_1application",
35
	"_1gnome_1vfs_1mime_1get_1default_1application",
36
	"_1gnome_1vfs_1mime_1get_1extensions_1list",
36
	"_1gnome_1vfs_1mime_1get_1extensions_1list",
37
	"_1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free",
37
	"_1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free",
38
	"_1gnome_1vfs_1mime_1type_1from_1name",
39
	"_1gtk_1icon_1info_1free",
40
	"_1gtk_1icon_1info_1get_1filename",
41
	"_1gtk_1icon_1theme_1get_1default",
42
	"_1gtk_1icon_1theme_1lookup_1icon",
38
	"memmove",
43
	"memmove",
39
};
44
};
40
45
(-)Eclipse SWT Program/gnome/library/gnome_stats.h (+5 lines)
Lines 39-43 Link Here
39
	_1gnome_1vfs_1mime_1get_1default_1application_FUNC,
39
	_1gnome_1vfs_1mime_1get_1default_1application_FUNC,
40
	_1gnome_1vfs_1mime_1get_1extensions_1list_FUNC,
40
	_1gnome_1vfs_1mime_1get_1extensions_1list_FUNC,
41
	_1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free_FUNC,
41
	_1gnome_1vfs_1mime_1registered_1mime_1type_1list_1free_FUNC,
42
	_1gnome_1vfs_1mime_1type_1from_1name_FUNC,
43
	_1gtk_1icon_1info_1free_FUNC,
44
	_1gtk_1icon_1info_1get_1filename_FUNC,
45
	_1gtk_1icon_1theme_1get_1default_FUNC,
46
	_1gtk_1icon_1theme_1lookup_1icon_FUNC,
42
	memmove_FUNC,
47
	memmove_FUNC,
43
} GNOME_FUNCS;
48
} GNOME_FUNCS;
(-)Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java (+45 lines)
Lines 144-148 Link Here
144
		lock.unlock();
144
		lock.unlock();
145
	}
145
	}
146
}
146
}
147
public static final native int /*long*/ _gnome_vfs_mime_type_from_name(byte[] file);
148
public static final int /*long*/ gnome_vfs_mime_type_from_name(byte[] file) {
149
	lock.lock();
150
	try {
151
		return _gnome_vfs_mime_type_from_name(file);
152
	} finally {
153
		lock.unlock();
154
	}
155
}
156
public static final native void _gtk_icon_info_free(int icon_info);
157
public static final void gtk_icon_info_free(int icon_info) {
158
	lock.lock();
159
	try {
160
	    _gtk_icon_info_free(icon_info);
161
	} finally {
162
		lock.unlock();
163
	}
164
}
165
public static final native int /*long*/ _gtk_icon_theme_get_default();
166
public static final int /*long*/ gtk_icon_theme_get_default() {
167
	lock.lock();
168
	try {
169
		return _gtk_icon_theme_get_default();
170
	} finally {
171
		lock.unlock();
172
	}
173
}
174
public static final native int /*long*/ _gtk_icon_info_get_filename(int icon_info);
175
public static final int /*long*/ gtk_icon_info_get_filename(int icon_info) {
176
	lock.lock();
177
	try {
178
		return _gtk_icon_info_get_filename(icon_info);
179
	} finally {
180
		lock.unlock();
181
	}
182
}
183
public static final native int /*long*/ _gtk_icon_theme_lookup_icon(int icon_theme, int icon_name, int size, int flags);
184
public static final int /*long*/ gtk_icon_theme_lookup_icon(int icon_theme, int icon_name, int size, int flags) {
185
	lock.lock();
186
	try {
187
		return _gtk_icon_theme_lookup_icon(icon_theme, icon_name, size, flags);
188
	} finally {
189
		lock.unlock();
190
	}
191
}
147
public static final native void memmove (GnomeVFSMimeApplication dest, int /*long*/ src, int /*long*/ count);
192
public static final native void memmove (GnomeVFSMimeApplication dest, int /*long*/ src, int /*long*/ count);
148
}
193
}
(-)Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java (-54 / +123 lines)
Lines 11-27 Link Here
11
package org.eclipse.swt.program;
11
package org.eclipse.swt.program;
12
12
13
13
14
import org.eclipse.swt.*;
14
import java.io.IOException;
15
import org.eclipse.swt.graphics.*;
15
import java.util.Enumeration;
16
import org.eclipse.swt.internal.*;
16
import java.util.Hashtable;
17
import org.eclipse.swt.internal.gnome.*;
17
import java.util.Vector;
18
import org.eclipse.swt.internal.kde.*;
18
19
import org.eclipse.swt.internal.cde.*;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.internal.gtk.*;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.widgets.*;
21
import org.eclipse.swt.graphics.ImageData;
22
22
import org.eclipse.swt.internal.Compatibility;
23
import java.io.*;
23
import org.eclipse.swt.internal.Converter;
24
import java.util.*;
24
import org.eclipse.swt.internal.Library;
25
import org.eclipse.swt.internal.cde.CDE;
26
import org.eclipse.swt.internal.cde.DtActionArg;
27
import org.eclipse.swt.internal.gnome.GNOME;
28
import org.eclipse.swt.internal.gnome.GnomeVFSMimeApplication;
29
import org.eclipse.swt.internal.gtk.OS;
30
import org.eclipse.swt.internal.kde.KDE;
31
import org.eclipse.swt.widgets.Display;
25
32
26
/**
33
/**
27
 * Instances of this class represent programs and
34
 * Instances of this class represent programs and
Lines 412-443 Link Here
412
		program.command = new String(Converter.mbcsToWcs(null, buffer));
419
		program.command = new String(Converter.mbcsToWcs(null, buffer));
413
		program.gnomeExpectUri = application.expects_uris == GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS;
420
		program.gnomeExpectUri = application.expects_uris == GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS;
414
		
421
		
415
		length = OS.strlen(application.id);
422
		setIconPath(program, mimeType, PREFERRED_ICON_SIZE);
416
		buffer = new byte[length + 1];
423
		
417
		OS.memmove(buffer, application.id, length);
424
		GNOME.gnome_vfs_mime_application_free(ptr);
418
		/* 
425
	}
419
		* Note.  gnome_icon_theme_new uses g_object_new to allocate the data it returns.
426
	return program;
420
		* Use g_object_unref to free the pointer it returns.
427
}
421
		*/
428
422
		int /*long*/ icon_theme = GNOME.gnome_icon_theme_new();
429
static void setIconPath(Program program, String mimeType, int iconSize) {
423
		int /*long*/ icon_name = GNOME.gnome_icon_lookup(icon_theme, 0, null, buffer, 0, mimeTypeBuffer, 
430
	byte[] mimeTypeBuffer = Converter.wcsToMbcs(null, mimeType, true);
424
				GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null);
431
    /* 
425
		int /*long*/ path = 0;
432
	* Note.  gnome_icon_theme_new uses g_object_new to allocate the data it returns.
426
		if (icon_name != 0) path = GNOME.gnome_icon_theme_lookup_icon(icon_theme, icon_name, PREFERRED_ICON_SIZE, null, null);
433
	* Use g_object_unref to free the pointer it returns.
427
		GNOME.g_object_unref(icon_theme);
434
	* 
428
		if (path != 0) {
435
	* Note2. gnome_icon_theme_new id deprecated.  Now using gtk_icon_theme_get_default. No need to free it.
429
			length = OS.strlen(path);
436
	*/
437
	int /*long*/ icon_theme = GNOME.gtk_icon_theme_get_default();
438
	int /*long*/ icon_name = GNOME.gnome_icon_lookup(icon_theme, 0, null, /*buffer*/ null, 0, mimeTypeBuffer, 
439
			GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null);
440
	int icon_info = 0;
441
	int /*long*/ path = 0;
442
	if (icon_name != 0) icon_info = GNOME.gtk_icon_theme_lookup_icon(icon_theme, icon_name, iconSize, 0);
443
	//GNOME.g_object_unref(icon_theme);
444
	if (icon_info != 0) {
445
	    path = GNOME.gtk_icon_info_get_filename(icon_info);
446
	    if (path != 0) {
447
			int length = OS.strlen(path);
430
			if (length > 0) {
448
			if (length > 0) {
431
				buffer = new byte[length];
449
				byte[] buffer = new byte[length];
432
				OS.memmove(buffer, path, length);
450
				OS.memmove(buffer, path, length);
433
				program.iconPath = new String(Converter.mbcsToWcs(null, buffer));
451
				program.iconPath = new String(Converter.mbcsToWcs(null, buffer));
434
			}
452
			}
435
			GNOME.g_free(path);
453
	    }
436
		}
437
		if (icon_name != 0) GNOME.g_free(icon_name);
438
		GNOME.gnome_vfs_mime_application_free(ptr);
439
	}
454
	}
440
	return program;
455
	if (icon_name != 0) GNOME.g_free(icon_name);
456
	if (icon_info != 0) GNOME.gtk_icon_info_free(icon_info);
441
}
457
}
442
458
443
static boolean gnome_init() {
459
static boolean gnome_init() {
Lines 664-692 Link Here
664
 *       become public and the original method above can be deprecated.
680
 *       become public and the original method above can be deprecated.
665
 */
681
 */
666
static Program findProgram(Display display, String extension) {
682
static Program findProgram(Display display, String extension) {
667
	if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
668
	if (extension.length() == 0) return null;
669
	if (extension.charAt(0) != '.') extension = "." + extension;
670
	int desktop = getDesktop(display);
683
	int desktop = getDesktop(display);
671
	Hashtable mimeInfo = null;
684
	String mimeType = getMimeTypeForExtension(display, extension);
672
	switch (desktop) {
673
		case DESKTOP_GNOME: mimeInfo = gnome_getMimeInfo(); break;
674
		case DESKTOP_KDE: mimeInfo = kde_getMimeInfo(); break;
675
		case DESKTOP_CDE: mimeInfo = cde_getDataTypeInfo(); break;
676
	}
677
	if (mimeInfo == null) return null;
678
	String mimeType = null;
679
	Enumeration keys = mimeInfo.keys();
680
	while (mimeType == null && keys.hasMoreElements()) {
681
		String type = (String)keys.nextElement();
682
		Vector mimeExts = (Vector)mimeInfo.get(type);
683
		for (int index = 0; index < mimeExts.size(); index++){
684
			if (extension.equals(mimeExts.elementAt(index))) {
685
				mimeType = type;
686
				break;
687
			}
688
		}
689
	}
690
	if (mimeType == null) return null;
685
	if (mimeType == null) return null;
691
	Program program = null;
686
	Program program = null;
692
	switch (desktop) {
687
	switch (desktop) {
Lines 697-702 Link Here
697
	return program;
692
	return program;
698
}
693
}
699
694
695
static String getMimeTypeForExtension(Display display, String extension) {
696
	int desktop = getDesktop(display);
697
	if (extension == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
698
	if (extension.length() == 0) return null;
699
	if (extension.charAt(0) != '.') extension = "." + extension;
700
	Hashtable mimeInfo = null;
701
	String mimeType = null;
702
	if (desktop == DESKTOP_CDE) {
703
	    mimeInfo = cde_getDataTypeInfo();
704
		if (mimeInfo == null) return null;
705
		Enumeration keys = mimeInfo.keys();
706
		while (mimeType == null && keys.hasMoreElements()) {
707
			String type = (String)keys.nextElement();
708
			Vector mimeExts = (Vector)mimeInfo.get(type);
709
			for (int index = 0; index < mimeExts.size(); index++){
710
				if (extension.equals(mimeExts.elementAt(index))) {
711
					mimeType = type;
712
					break;
713
				}
714
			}
715
		}
716
	} else {
717
	    byte[] extensionBuffer = Converter.wcsToMbcs(null, extension, true);
718
	    int /*long*/ type = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer);
719
	    if (type != 0) {
720
	        int length = OS.strlen(type);
721
	        if (length > 0) {
722
	            byte [] buffer = new byte[length];
723
	    		OS.memmove(buffer, type, length);
724
	    		mimeType = new String(Converter.mbcsToWcs(null, buffer));
725
	    	}
726
	    }
727
	}
728
	return mimeType;
729
}
730
700
/**
731
/**
701
 * Answer all program extensions in the operating system.  Note
732
 * Answer all program extensions in the operating system.  Note
702
 * that a <code>Display</code> must already exist to guarantee
733
 * that a <code>Display</code> must already exist to guarantee
Lines 744-749 Link Here
744
}
775
}
745
776
746
/**
777
/**
778
 * Finds the system image associated with an extension. 
779
 * The extension may or may not begin with a '.'.  Note that
780
 * a <code>Display</code> must already exist to guarantee that
781
 * this method returns an appropriate result.
782
 *
783
 * @param extension the program extension
784
 * @param iconSize the size of the icon to get
785
 * @return <code>ImageData</code>, a system generic icon if the extension does not have an associated mime type,
786
 *         or <code>null</code> if we can't get the generic icon.
787
 */
788
public static ImageData getImageData(String extension, int iconSize) {
789
    if (iconSize == 0) iconSize = PREFERRED_ICON_SIZE;
790
    
791
    Display display = Display.getCurrent();
792
	String mimeType = getMimeTypeForExtension(display, extension);
793
	if (mimeType == null) {
794
	    // Try and get a 'generic' icon
795
	    mimeType = getMimeTypeForExtension(display, "unknown");
796
	}
797
	if (mimeType == null) return null; // we tried...
798
	return getImageDataForMimeType(display, mimeType, iconSize);
799
}
800
801
static ImageData getImageDataForMimeType(Display display, String mimeType, int iconSize) {
802
    if ( display == null || mimeType == null) return null;
803
	Program program = new Program();
804
	program.display = display;
805
	setIconPath(program, mimeType, iconSize);
806
	return program.getImageData();
807
}
808
809
/**
747
 * Answers all available programs in the operating system.  Note
810
 * Answers all available programs in the operating system.  Note
748
 * that a <code>Display</code> must already exist to guarantee
811
 * that a <code>Display</code> must already exist to guarantee
749
 * that this method returns an appropriate result.
812
 * that this method returns an appropriate result.
Lines 786-791 Link Here
786
	return programList;
849
	return programList;
787
}
850
}
788
851
852
final static String folderMimeType = "x-directory";  
853
public static ImageData getSystemFolderImageData(int iconSize) {
854
    if (iconSize == 0) iconSize = PREFERRED_ICON_SIZE;
855
    return getImageDataForMimeType(Display.getCurrent(), folderMimeType, iconSize);
856
}
857
789
/**
858
/**
790
 * Launches the executable associated with the file in
859
 * Launches the executable associated with the file in
791
 * the operating system.  If the file is an executable,
860
 * the operating system.  If the file is an executable,

Return to bug 79268