[Gtk-sharp-list] Gnome Vfs bindings: the chunk.
Miguel de Icaza
miguel@ximian.com
27 Feb 2003 19:18:57 -0500
--=-1OggIBXu2xnUXoKm5rsm
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hey guys,
As promised, this is the manual chunk I did for Nat. It is not
supposed to be a good binding, it only binds what we needed at that
moment.
Miguel.
--=-1OggIBXu2xnUXoKm5rsm
Content-Disposition: attachment; filename=gnome.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=gnome.cs; charset=ISO-8859-1
using Gtk;
using System;
using System.Runtime.InteropServices;
namespace Gnome {
namespace VFS {
class Mime {
=09
[DllImport ("libgnomevfs-2")] extern static bool gnome_vfs_init =
();
[DllImport ("libgnomevfs-2")] extern static string gnome_vfs_get_mime_ty=
pe (string text_uri);
public static bool Init ()
{
return gnome_vfs_init ();
}
public static string GetMimeType (string text_uri)
{
return gnome_vfs_get_mime_type (text_uri);
}
}
[Flags]
public enum FileInfoOptions {
DEFAULT =3D 0,=20
GET_MIME_TYPE =3D 1 << 0,
FORCE_FAST_MIME_TYPE =3D 1 << 1,
FORCE_SLOW_MIME_TYPE =3D 1 << 2,
FOLLOW_LINKS =3D 1 << 3
}
public enum Result {
OK,
ERROR_NOT_FOUND,
ERROR_GENERIC,
ERROR_INTERNAL,
ERROR_BAD_PARAMETERS,
ERROR_NOT_SUPPORTED,
ERROR_IO,
ERROR_CORRUPTED_DATA,
ERROR_WRONG_FORMAT,
ERROR_BAD_FILE,
ERROR_TOO_BIG,
ERROR_NO_SPACE,
ERROR_READ_ONLY,
ERROR_INVALID_URI,
ERROR_NOT_OPEN,
ERROR_INVALID_OPEN_MODE,
ERROR_ACCESS_DENIED,
ERROR_TOO_MANY_OPEN_FILES,
ERROR_EOF,
ERROR_NOT_A_DIRECTORY,
ERROR_IN_PROGRESS,
ERROR_INTERRUPTED,
ERROR_FILE_EXISTS,
ERROR_LOOP,
ERROR_NOT_PERMITTED,
ERROR_IS_DIRECTORY,
ERROR_NO_MEMORY,
ERROR_HOST_NOT_FOUND,
ERROR_INVALID_HOST_NAME,
ERROR_HOST_HAS_NO_ADDRESS,
ERROR_LOGIN_FAILED,
ERROR_CANCELLED,
ERROR_DIRECTORY_BUSY,
ERROR_DIRECTORY_NOT_EMPTY,
ERROR_TOO_MANY_LINKS,
ERROR_READ_ONLY_FILE_SYSTEM,
ERROR_NOT_SAME_FILE_SYSTEM,
ERROR_NAME_TOO_LONG,
ERROR_SERVICE_NOT_AVAILABLE,
ERROR_SERVICE_OBSOLETE,
ERROR_PROTOCOL_ERROR,
NUM_ERRORS
}
=20
public class FileInfo {
internal IntPtr handle;
[DllImport ("libgnomevfs-2")]
extern static IntPtr gnome_vfs_file_info_new ();
[DllImport ("libgnomevfs-2")]
extern static void gnome_vfs_file_info_unref (IntPtr handle);
[DllImport ("libgnomevfs-2")]
extern static Result gnome_vfs_get_file_info (string uri, IntPtr file_i=
nfo, FileInfoOptions options);
public FileInfo ()
{
}
~FileInfo ()
{
gnome_vfs_file_info_unref (handle);
handle =3D (IntPtr) 0;
}
=20
public FileInfo (string uri, FileInfoOptions options)
{
handle =3D gnome_vfs_file_info_new ();
Result r =3D Get (uri, options);
if (r !=3D Result.OK)
throw new Exception ("VFS Error: " + r);
}
public Result Get (string uri, FileInfoOptions options)
{
return gnome_vfs_get_file_info (uri, handle, options);
}
}
}
public class ThumbnailFactory {
internal IntPtr handle;
[Flags]
public enum ThumbnailSize {
NORMAL,
LARGE,
}
=09
[DllImport ("libgnomeui-2")]
extern static IntPtr gnome_thumbnail_factory_new (ThumbnailSize size);
public ThumbnailFactory (ThumbnailSize size)
{
handle =3D gnome_thumbnail_factory_new (size);
if (handle =3D=3D (IntPtr) 0) {
Console.WriteLine ("Null handle returned");
}
Console.WriteLine ("Thumbnail factory created");
}
}
public class Icon {
[Flags]
public enum LookupFlags {
NONE =3D 0,
EMBEDDING_TEXT =3D 1,
SHOW_SMALL_IMAGES_AS_THEMSELVES =3D 2,
}
[Flags]
public enum LookupResultFlags {
NONE =3D 0,
THUMBNAIL =3D 1
}
[DllImport ("libgnomeui-2")]
extern static IntPtr gnome_icon_theme_new ();
[DllImport ("libgnomeui-2")]
extern static string gnome_icon_theme_lookup_icon (IntPtr theme, string =
icon_name, int size, IntPtr icon_data, out int base_size);
=20
[DllImport ("libgnomeui-2")]
extern static string gnome_icon_lookup (IntPtr theme, IntPtr factory, =
string uri,
string custom_icon, IntPtr file_info_handle,
string mime_type, LookupFlags flags,
out LookupResultFlags flags_result);
static IntPtr icon_theme =3D gnome_icon_theme_new ();
static Gnome.ThumbnailFactory thumbnail_factory =3D new Gnome.ThumbnailFa=
ctory (Gnome.ThumbnailFactory.ThumbnailSize.NORMAL);
public static string Lookup (string uri, string custom_icon=
, Gnome.VFS.FileInfo fi, string mime_type)
{
LookupResultFlags out_flags;
string icon_name;
icon_name =3D gnome_icon_lookup (
icon_theme,
thumbnail_factory.handle,
uri,
custom_icon,
fi =3D=3D null ? (IntPtr) 0 : fi.handle,
mime_type,
LookupFlags.SHOW_SMALL_IMAGES_AS_THEMSELVES,
out out_flags);
string icon_data;
if (icon_name.IndexOf ("/") =3D=3D 0) {
icon_data =3D icon_name;
} else {
int base_size;
icon_data =3D gnome_icon_theme_lookup_icon (icon_theme, icon_name, 48, =
(IntPtr) 0, out base_size);
}
return icon_data;
}
public static string Lookup (string uri, string custom_icon=
, string mime_type)
{
return Lookup (uri, custom_icon, null, mime_type);
}
public static string Lookup (string mime_type)
{
return Lookup (null, null, mime_type);
}
public static string LookupByURI (string uri)
{
string mime_type =3D Gnome.VFS.Mime.GetMimeType (uri);
VFS.FileInfo fi;
fi =3D new VFS.FileInfo (uri, 0);
return Lookup (uri, null, fi, mime_type);
}
public static string LookupByPath (string path)
{
return LookupByURI ("file://" + path);
}
}
=20
}
--=-1OggIBXu2xnUXoKm5rsm--