2 * Vfs.cs (from MonoTagEditor)
4 * Copyright (C) 2003, Mariano Cano PĂ©rez <mariano.cano@hispalinux.es>
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
9 * 1.Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 * 2.Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 * 3.The name of the author may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
24 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 using System
.Runtime
.InteropServices
;
32 namespace Beagle
.Util
{
34 public enum GnomeVFSMimeApplicationArgumentType
41 [StructLayout(LayoutKind
.Sequential
)]
42 public struct GnomeVFSMimeApplication
46 public string command
;
47 public bool can_open_multiple_files
;
48 public GnomeVFSMimeApplicationArgumentType expects_uris
;
49 //public List supported_uri_schemes;
50 private IntPtr supported_uri_schemes
;
51 public bool requires_terminal
;
53 public IntPtr reserved1
;
54 public IntPtr reserved2
;
56 public static GnomeVFSMimeApplication Zero
= new GnomeVFSMimeApplication ();
58 public static GnomeVFSMimeApplication
New (IntPtr raw
)
60 if(raw
== IntPtr
.Zero
)
62 return GnomeVFSMimeApplication
.Zero
;
64 GnomeVFSMimeApplication self
= new GnomeVFSMimeApplication();
65 self
= (GnomeVFSMimeApplication
) Marshal
.PtrToStructure (raw
, self
.GetType ());
69 //Fixme: Create the supported uri schemes struct
70 public List SupportedUriSchemes
{
72 List list
= new List (supported_uri_schemes
);
77 public static bool operator == (GnomeVFSMimeApplication a
, GnomeVFSMimeApplication b
)
82 public static bool operator != (GnomeVFSMimeApplication a
, GnomeVFSMimeApplication b
)
84 return ! a
.Equals (b
);
87 public override bool Equals (object o
)
89 //if (!(o is GnomeVFSMimeApplication))
91 return base.Equals(o
) ;
94 public override int GetHashCode ()
96 return base.GetHashCode ();
100 public enum GnomeIconLookupFlags
107 public enum GnomeIconLookupResultsFlags
113 public class GnomeIconLookup
{
115 [DllImport("libgnomeui-2")]
116 static extern IntPtr
gnome_icon_lookup (IntPtr icon_theme
,
117 IntPtr thumbnail_factory
,
122 GnomeIconLookupFlags flags
,
123 ref GnomeIconLookupResultsFlags result
);
124 [DllImport("libgnomeui-2")]
125 static extern IntPtr
gnome_icon_theme_lookup_icon (IntPtr icon_theme
,
128 ref IntPtr icon_data
,
131 [DllImport("libgnomeui-2")]
132 static extern void gnome_icon_data_free (IntPtr icon_data
);
134 [DllImport("libgnomeui-2")]
135 static extern IntPtr
gnome_icon_theme_new ();
137 [DllImport("libgnomevfs-2")]
138 static extern IntPtr
gnome_vfs_mime_type_from_name (string mime_type
);
140 [DllImport("libgnomevfs-2")]
141 static extern IntPtr
gnome_vfs_get_file_mime_type (string filename
,
142 IntPtr optional_stat_info
,
145 [DllImport("libgnomevfs-2")]
146 static extern IntPtr
gnome_vfs_application_registry_get_applications(string mime_type
);
148 [DllImport("libgnomevfs-2")]
149 static extern IntPtr
gnome_vfs_mime_get_default_application(string mime_type
);
151 static IntPtr icon_theme
= IntPtr
.Zero
;
153 public static string LookupMimeIcon(string mime
,IconSize size
)
155 string icon_name
=String
.Empty
;
156 string icon_path
=String
.Empty
;
157 GnomeIconLookupResultsFlags result
=0;
158 IntPtr icon_data
=IntPtr
.Zero
;
161 if (icon_theme
== IntPtr
.Zero
) {
162 icon_theme
= gnome_icon_theme_new ();
165 if(icon_theme
==IntPtr
.Zero
)
170 icon_name
=GLib
.Marshaller
.PtrToStringGFree (gnome_icon_lookup(
177 GnomeIconLookupFlags
.None
,
180 if(icon_name
.Length
>0)
182 icon_path
=GLib
.Marshaller
.PtrToStringGFree (gnome_icon_theme_lookup_icon (
192 public static string LookupFileIcon(string file
,IconSize size
)
194 string mime
= Marshal
.PtrToStringAnsi (gnome_vfs_mime_type_from_name(file
));
197 return LookupMimeIcon(mime
,size
);
202 public static string GetMimeType(string file
)
204 return Marshal
.PtrToStringAnsi (gnome_vfs_mime_type_from_name(file
));
207 public static string GetFileMimeType (string file
)
209 return Marshal
.PtrToStringAnsi (gnome_vfs_get_file_mime_type (file
, (IntPtr
)null, false));
212 public static GLib
.List
GetApplications(string mime_type
)
214 IntPtr raw_ret
= gnome_vfs_application_registry_get_applications(mime_type
);
215 GLib
.List app
= new GLib
.List(raw_ret
);
219 public static GnomeVFSMimeApplication
GetDefaultAction(string mime_type
)
221 IntPtr ptr
= gnome_vfs_mime_get_default_application(mime_type
);
222 GnomeVFSMimeApplication ret
= GnomeVFSMimeApplication
.New(ptr
);