2004-11-05 17:40:03 +00:00
|
|
|
// MimeType.cs - Mime-type bindings.
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// Authors: Jeroen Zwartepoorte <jeroen@xs4all.nl>
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// Copyright (c) 2004 Jeroen Zwartepoorte
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
|
|
// Public License as published by the Free Software Foundation.
|
2004-10-29 20:33:07 +00:00
|
|
|
//
|
2004-11-05 17:40:03 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace Gnome.Vfs {
|
|
|
|
public class MimeType {
|
|
|
|
public static readonly string UnknownMimeType = "application/octet-stream";
|
|
|
|
private string mimetype;
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern IntPtr gnome_vfs_get_mime_type (IntPtr uri);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public MimeType (Uri uri)
|
|
|
|
{
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr uri_native = GLib.Marshaller.StringToPtrGStrdup (uri.ToString ());
|
|
|
|
mimetype = GLib.Marshaller.PtrToStringGFree (gnome_vfs_get_mime_type (uri_native));
|
|
|
|
GLib.Marshaller.Free (uri_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern bool gnome_vfs_mime_type_is_known (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public MimeType (string mimetype)
|
|
|
|
{
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
if (!gnome_vfs_mime_type_is_known (mimetype_native))
|
2004-10-29 20:33:07 +00:00
|
|
|
throw new ArgumentException ("Unknown mimetype");
|
|
|
|
this.mimetype = mimetype;
|
2006-03-27 19:43:53 +00:00
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern IntPtr gnome_vfs_get_mime_type_for_data (ref byte data, int size);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public MimeType (byte[] buffer, int size)
|
|
|
|
{
|
2006-03-27 19:43:53 +00:00
|
|
|
mimetype = GLib.Marshaller.Utf8PtrToString (gnome_vfs_get_mime_type_for_data (ref buffer[0], size));
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern MimeActionType gnome_vfs_mime_get_default_action_type (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern Result gnome_vfs_mime_set_default_action_type (IntPtr mime_type, MimeActionType action_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public MimeActionType DefaultActionType {
|
|
|
|
get {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
MimeActionType result = gnome_vfs_mime_get_default_action_type (mimetype_native);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
return result;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
set {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
Result result = gnome_vfs_mime_set_default_action_type (mimetype_native, value);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
Vfs.ThrowException (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern MimeAction gnome_vfs_mime_get_default_action (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public MimeAction DefaultAction {
|
|
|
|
get {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
MimeAction result = gnome_vfs_mime_get_default_action (mimetype_native);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
return result;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern IntPtr gnome_vfs_mime_get_description (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern Result gnome_vfs_mime_set_description (IntPtr mime_type, IntPtr description);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public string Description {
|
|
|
|
get {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
string result = GLib.Marshaller.Utf8PtrToString (gnome_vfs_mime_get_description (mimetype_native));
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
return result;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
set {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
IntPtr desc_native = GLib.Marshaller.StringToPtrGStrdup (value);
|
|
|
|
Result result = gnome_vfs_mime_set_description (mimetype_native, desc_native);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
GLib.Marshaller.Free (desc_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
Vfs.ThrowException (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern IntPtr gnome_vfs_mime_get_icon (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern Result gnome_vfs_mime_set_icon (IntPtr mime_type, IntPtr filename);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public string Icon {
|
|
|
|
get {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
string result = GLib.Marshaller.Utf8PtrToString (gnome_vfs_mime_get_icon (mimetype_native));
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
return result;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
set {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
IntPtr icon_native = GLib.Marshaller.StringToPtrGStrdup (value);
|
|
|
|
Result result = gnome_vfs_mime_set_icon (mimetype_native, icon_native);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
GLib.Marshaller.Free (icon_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
Vfs.ThrowException (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern bool gnome_vfs_mime_can_be_executable (IntPtr mime_type);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
[DllImport ("gnomevfs-2")]
|
2006-03-27 19:43:53 +00:00
|
|
|
static extern Result gnome_vfs_mime_set_can_be_executable (IntPtr mime_type, bool value);
|
2004-10-29 20:33:07 +00:00
|
|
|
|
|
|
|
public bool CanBeExecutable {
|
|
|
|
get {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
bool result = gnome_vfs_mime_can_be_executable (mimetype_native);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
|
|
|
return result;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
set {
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr mimetype_native = GLib.Marshaller.StringToPtrGStrdup (mimetype);
|
|
|
|
Result result = gnome_vfs_mime_set_can_be_executable (mimetype_native, value);
|
|
|
|
GLib.Marshaller.Free (mimetype_native);
|
2004-10-29 20:33:07 +00:00
|
|
|
Vfs.ThrowException (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name {
|
|
|
|
get {
|
|
|
|
return mimetype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString ()
|
|
|
|
{
|
|
|
|
return mimetype;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetMimeTypeForUri (string uri)
|
|
|
|
{
|
2006-03-27 19:43:53 +00:00
|
|
|
IntPtr uri_native = GLib.Marshaller.StringToPtrGStrdup (uri.ToString ());
|
|
|
|
string mimetype = GLib.Marshaller.PtrToStringGFree (gnome_vfs_get_mime_type (uri_native));
|
|
|
|
GLib.Marshaller.Free (uri_native);
|
|
|
|
return mimetype;
|
2004-10-29 20:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|