comparison org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/program/Program.d @ 50:d5075f5226e5

[swt lin]
author Frank Benoit <benoit@tionex.de>
date Fri, 27 Mar 2009 15:30:20 +0100
parents ddbfe84d86df
children c01d033c633a
comparison
equal deleted inserted replaced
49:7a2dd761a8b2 50:d5075f5226e5
20 import org.eclipse.swt.internal.gtk.OS; 20 import org.eclipse.swt.internal.gtk.OS;
21 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.swt.widgets.Event;
23 import org.eclipse.swt.widgets.Listener; 23 import org.eclipse.swt.widgets.Listener;
24 import java.lang.all; 24 import java.lang.all;
25 import java.nonstandard.SharedLib;
25 26
26 version(Tango){ 27 version(Tango){
27 import tango.sys.SharedLib; 28 static import tango.core.Array;
28 import tango.core.Array; 29 static import tango.io.device.File;
29 import tango.io.device.File; 30 static import tango.io.stream.Lines;
30 import tango.io.stream.Lines;
31 } else { // Phobos 31 } else { // Phobos
32 static import std.string;
33 static import std.file;
34 static import std.algorithm;
35 static import std.iterator;
32 } 36 }
33 37
34 version( build ){ 38 version( build ){
35 pragma(link, "gnomeui-2" ); 39 pragma(link, "gnomeui-2" );
36 } 40 }
167 GnomeVFSResult function(char*) gnome_vfs_url_show; 171 GnomeVFSResult function(char*) gnome_vfs_url_show;
168 char* function(char*) gnome_vfs_make_uri_from_input; 172 char* function(char*) gnome_vfs_make_uri_from_input;
169 GList* function() gnome_vfs_get_registered_mime_types; 173 GList* function() gnome_vfs_get_registered_mime_types;
170 char* function(char*) gnome_vfs_mime_type_from_name; 174 char* function(char*) gnome_vfs_mime_type_from_name;
171 } 175 }
176 Symbol symbols[] = [
177 { "gnome_vfs_mime_get_default_application", cast(void**)&gnome_vfs_mime_get_default_application },
178 { "gnome_vfs_make_uri_from_input_with_dirs", cast(void**)&gnome_vfs_make_uri_from_input_with_dirs },
179 { "gnome_vfs_mime_application_launch", cast(void**)&gnome_vfs_mime_application_launch },
180 { "gnome_vfs_mime_application_free", cast(void**)&gnome_vfs_mime_application_free },
181 { "gnome_vfs_url_show", cast(void**)&gnome_vfs_url_show },
182 { "gnome_vfs_make_uri_from_input", cast(void**)&gnome_vfs_make_uri_from_input },
183 { "gnome_vfs_get_registered_mime_types", cast(void**)&gnome_vfs_get_registered_mime_types },
184 { "gnome_vfs_mime_get_extensions_list", cast(void**)&gnome_vfs_mime_get_extensions_list },
185 { "gnome_vfs_mime_extensions_list_free", cast(void**)&gnome_vfs_mime_extensions_list_free },
186 { "gnome_vfs_mime_registered_mime_type_list_free", cast(void**)&gnome_vfs_mime_registered_mime_type_list_free },
187 { "gnome_vfs_mime_type_from_name", cast(void**)&gnome_vfs_mime_type_from_name }
188 ];
172 } 189 }
173 190
174 /** 191 /**
175 * Instances of this class represent programs and 192 * Instances of this class represent programs and
176 * their associated file extensions in the operating 193 * their associated file extensions in the operating
261 if (gnomeIconTheme.value !is 0) OS.g_object_unref( cast(void*)gnomeIconTheme.value); 278 if (gnomeIconTheme.value !is 0) OS.g_object_unref( cast(void*)gnomeIconTheme.value);
262 } 279 }
263 }); 280 });
264 /* Check for libgnomevfs-2 version 2.4 */ 281 /* Check for libgnomevfs-2 version 2.4 */
265 String buffer = "libgnomevfs-2.so.0"; 282 String buffer = "libgnomevfs-2.so.0";
266 auto libgnomevfs = SharedLib.load(buffer ); 283 SharedLib.tryUseSymbol( "gnome_vfs_url_show", buffer, (void*){
267 if (libgnomevfs !is null) {
268 buffer = "gnome_vfs_url_show";
269 void* gnome_vfs_url_show = libgnomevfs.getSymbol( buffer.ptr );
270 if (gnome_vfs_url_show !is null) {
271 desktop = DESKTOP_GNOME_24; 284 desktop = DESKTOP_GNOME_24;
272 } 285 });
273 *cast(void**)&GNOME.gnome_vfs_mime_get_default_application = libgnomevfs.getSymbol( "gnome_vfs_mime_get_default_application" ); 286 if( desktop is DESKTOP_GNOME_24 ){
274 *cast(void**)&GNOME.gnome_vfs_make_uri_from_input_with_dirs = libgnomevfs.getSymbol( "gnome_vfs_make_uri_from_input_with_dirs" ); 287 SharedLib.loadLibSymbols( GNOME.symbols, buffer );
275 *cast(void**)&GNOME.gnome_vfs_mime_application_launch = libgnomevfs.getSymbol( "gnome_vfs_mime_application_launch" );
276 *cast(void**)&GNOME.gnome_vfs_mime_application_free = libgnomevfs.getSymbol( "gnome_vfs_mime_application_free" );
277 *cast(void**)&GNOME.gnome_vfs_url_show = libgnomevfs.getSymbol( "gnome_vfs_url_show" );
278 *cast(void**)&GNOME.gnome_vfs_make_uri_from_input = libgnomevfs.getSymbol( "gnome_vfs_make_uri_from_input" );
279 *cast(void**)&GNOME.gnome_vfs_get_registered_mime_types = libgnomevfs.getSymbol( "gnome_vfs_get_registered_mime_types" );
280 *cast(void**)&GNOME.gnome_vfs_mime_get_extensions_list = libgnomevfs.getSymbol( "gnome_vfs_mime_get_extensions_list" );
281 *cast(void**)&GNOME.gnome_vfs_mime_extensions_list_free = libgnomevfs.getSymbol( "gnome_vfs_mime_extensions_list_free" );
282 *cast(void**)&GNOME.gnome_vfs_mime_registered_mime_type_list_free = libgnomevfs.getSymbol( "gnome_vfs_mime_registered_mime_type_list_free" );
283 *cast(void**)&GNOME.gnome_vfs_mime_type_from_name = libgnomevfs.getSymbol( "gnome_vfs_mime_type_from_name" );
284 } 288 }
285 } 289 }
286 } 290 }
287 291
288 // PORTING CDE not supported 292 // PORTING CDE not supported
541 if (gnomeExpectUri) { 545 if (gnomeExpectUri) {
542 /* Convert the given path into a URL */ 546 /* Convert the given path into a URL */
543 char* fileNameBuffer = toStringz(fileName); 547 char* fileNameBuffer = toStringz(fileName);
544 char* uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer); 548 char* uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer);
545 if (uri !is null) { 549 if (uri !is null) {
546 fileName = fromStringz( uri ).dup; 550 fileName = fromStringz( uri )._idup();
547 OS.g_free(uri); 551 OS.g_free(uri);
548 } 552 }
549 } 553 }
550 554
551 /* Parse the command into its individual arguments. */ 555 /* Parse the command into its individual arguments. */
593 /++ 597 /++
594 + SWT Extension 598 + SWT Extension
595 + This is a temporary workaround until SWT will get the real implementation. 599 + This is a temporary workaround until SWT will get the real implementation.
596 +/ 600 +/
597 static String[][ String ] gnome24_getMimeInfo() { 601 static String[][ String ] gnome24_getMimeInfo() {
598 scope file = new tango.io.device.File.File ("/usr/share/mime/globs"); 602 version(Tango){
599 scope it = new Lines!(char)(file); 603 scope it = new Lines!(char)(tango.io.device.File.get("/usr/share/mime/globs"));
604 } else { // Phobos
605 scope it = std.string.splitlines( cast(String)std.file.read("/usr/share/mime/globs"));
606 }
600 // process file one line at a time 607 // process file one line at a time
601 String[][ String ] mimeInfo; 608 String[][ String ] mimeInfo;
602 foreach (line; it ){ 609 foreach (line; it ){
603 int colon = line.indexOf(':'); 610 int colon = line.indexOf(':');
604 if( colon is line.length ){ 611 if( colon is line.length ){
605 continue; 612 continue;
606 } 613 }
607 if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){ 614 if( line.length < colon+3 || line[colon+1 .. colon+3 ] != "*." ){
608 continue; 615 continue;
609 } 616 }
610 String mimeType = line[0..colon].dup; 617 String mimeType = line[0..colon]._idup();
611 String ext = line[colon+3 .. $].dup; 618 String ext = line[colon+3 .. $]._idup();
612 if( auto exts = mimeType in mimeInfo ){ 619 if( auto exts = mimeType in mimeInfo ){
613 mimeInfo[ mimeType ] = *exts ~ ext; 620 mimeInfo[ mimeType ] = *exts ~ ext;
614 } 621 }
615 else{ 622 else{
616 mimeInfo[ mimeType ] = [ ext ]; 623 mimeInfo[ mimeType ] = [ ext ];
629 static String[][ String ] gnome_getMimeInfo() { 636 static String[][ String ] gnome_getMimeInfo() {
630 String[][ String ] mimeInfo; 637 String[][ String ] mimeInfo;
631 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types(); 638 GList* mimeList = GNOME.gnome_vfs_get_registered_mime_types();
632 GList* mimeElement = mimeList; 639 GList* mimeElement = mimeList;
633 while (mimeElement !is null) { 640 while (mimeElement !is null) {
634 char* mimePtr = cast(char*) OS.g_list_data(mimeElement); 641 auto mimePtr = cast(char*) OS.g_list_data(mimeElement);
635 String mimeTypeBuffer = fromStringz(mimePtr).dup; 642 String mimeTypeBuffer = fromStringz(mimePtr)._idup();
636 String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer)); 643 String mimeType = mimeTypeBuffer;//new String(Converter.mbcsToWcs(null, mimeTypeBuffer));
637 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr); 644 GList* extensionList = GNOME.gnome_vfs_mime_get_extensions_list(mimePtr);
638 if (extensionList !is null) { 645 if (extensionList !is null) {
639 String[] extensions; 646 String[] extensions;
640 GList* extensionElement = extensionList; 647 GList* extensionElement = extensionList;
641 while (extensionElement !is null) { 648 while (extensionElement !is null) {
642 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement); 649 char* extensionPtr = cast(char*) OS.g_list_data(extensionElement);
643 String extensionBuffer = fromStringz(extensionPtr).dup; 650 String extensionBuffer = fromStringz(extensionPtr)._idup();
644 String extension = extensionBuffer; 651 String extension = extensionBuffer;
645 extension = '.' ~ extension; 652 extension = '.' ~ extension;
646 extensions ~= extension; 653 extensions ~= extension;
647 extensionElement = OS.g_list_next(extensionElement); 654 extensionElement = OS.g_list_next(extensionElement);
648 } 655 }
659 String mimeType = null; 666 String mimeType = null;
660 String fileName = "swt" ~ extension; 667 String fileName = "swt" ~ extension;
661 char* extensionBuffer = toStringz(fileName); 668 char* extensionBuffer = toStringz(fileName);
662 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer); 669 char* typeName = GNOME.gnome_vfs_mime_type_from_name(extensionBuffer);
663 if (typeName !is null) { 670 if (typeName !is null) {
664 mimeType = fromStringz(typeName).dup; 671 mimeType = fromStringz(typeName)._idup();
665 } 672 }
666 return mimeType; 673 return mimeType;
667 } 674 }
668 675
669 static Program gnome_getProgram(Display display, String mimeType) { 676 static Program gnome_getProgram(Display display, String mimeType) {
673 if (ptr !is null) { 680 if (ptr !is null) {
674 program = new Program(); 681 program = new Program();
675 program.display = display; 682 program.display = display;
676 program.name = mimeType; 683 program.name = mimeType;
677 GnomeVFSMimeApplication* application = ptr; 684 GnomeVFSMimeApplication* application = ptr;
678 String buffer = fromStringz(application.command).dup; 685 String buffer = fromStringz(application.command)._idup();
679 program.command = buffer; 686 program.command = buffer;
680 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS; 687 program.gnomeExpectUri = application.expects_uris is GNOME.GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS;
681 688
682 buffer = fromStringz( application.id) ~ '\0'; 689 buffer = (fromStringz( application.id) ~ '\0')._idup();
683 ValueWrapperInt gnomeIconTheme = cast(ValueWrapperInt)display.getData(ICON_THEME_DATA); 690 ValueWrapperInt gnomeIconTheme = cast(ValueWrapperInt)display.getData(ICON_THEME_DATA);
684 char* icon_name = GNOME.gnome_icon_lookup( cast(GtkIconTheme*) gnomeIconTheme.value, null, null, buffer.ptr, null, mimeTypeBuffer, 691 char* icon_name = GNOME.gnome_icon_lookup( cast(GtkIconTheme*) gnomeIconTheme.value, null, null, cast(char*)buffer.ptr, null, mimeTypeBuffer,
685 GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null); 692 GNOME.GNOME_ICON_LOOKUP_FLAGS_NONE, null);
686 char* path = null; 693 char* path = null;
687 if (icon_name !is null) path = GNOME.gnome_icon_theme_lookup_icon(cast(GtkIconTheme*)gnomeIconTheme.value, icon_name, PREFERRED_ICON_SIZE, null, null); 694 if (icon_name !is null) path = GNOME.gnome_icon_theme_lookup_icon(cast(GtkIconTheme*)gnomeIconTheme.value, icon_name, PREFERRED_ICON_SIZE, null, null);
688 if (path !is null) { 695 if (path !is null) {
689 program.iconPath = fromStringz( path).dup; 696 program.iconPath = fromStringz( path)._idup();
690 OS.g_free(path); 697 OS.g_free(path);
691 } 698 }
692 if (icon_name !is null) OS.g_free(icon_name); 699 if (icon_name !is null) OS.g_free(icon_name);
693 GNOME.gnome_vfs_mime_application_free(ptr); 700 GNOME.gnome_vfs_mime_application_free(ptr);
694 } 701 }
773 int keyIdx = 0; 780 int keyIdx = 0;
774 while ( keyIdx < keys.length ) { 781 while ( keyIdx < keys.length ) {
775 String mimeType = keys[ keyIdx ]; 782 String mimeType = keys[ keyIdx ];
776 String[] mimeExts = mimeInfo[mimeType]; 783 String[] mimeExts = mimeInfo[mimeType];
777 for (int index = 0; index < mimeExts.length; index++){ 784 for (int index = 0; index < mimeExts.length; index++){
778 if (!extensions.contains(mimeExts[index])) { 785 version(Tango){
786 bool contains = extensions.contains(mimeExts[index]);
787 } else { // Phobos
788 bool contains = std.algorithm.find(extensions, mimeExts[index]) != std.iterator.end(extension);
789 }
790 if (!contains) {
779 extensions ~= mimeExts[index]; 791 extensions ~= mimeExts[index];
780 } 792 }
781 } 793 }
782 keyIdx++; 794 keyIdx++;
783 } 795 }