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, |