#!/usr/bin/perl -w
use strict;
use Gnome2::VFS;

use Test::More;

# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gnome2-VFS/t/GnomeVFSMime,v 1.8 2005/03/20 23:44:44 kaffeetisch Exp $

plan -d "$ENV{ HOME }/.gnome" ?
  (tests => 16) :
  (skip_all => "You have no ~/.gnome");

Gnome2::VFS -> init();

###############################################################################

my $monitor = Gnome2::VFS::Mime::Monitor -> get();
isa_ok($monitor, "Gnome2::VFS::Mime::Monitor");

my $type = Gnome2::VFS::Mime::Type -> new("text/html");
my $application = $type -> get_default_application_for_uri("http://www.google.com");
$application = $type -> get_default_application();

SKIP: {
  skip("you don't seem to have a default application associated with text/html", 8)
    unless (defined($application));

  isa_ok($application, "Gnome2::VFS::Mime::Application");
  ok(defined($application -> { id }));
  isa_ok($application -> { supported_uri_schemes }, "ARRAY");

  ok(Gnome2::VFS::Mime -> id_in_application_list("epiphany", $application, $application));
  isa_ok(Gnome2::VFS::Mime -> remove_application_from_list("galeon", $application, $application), "Gnome2::VFS::Mime::Application");
  is(Gnome2::VFS::Mime -> id_list_from_application_list($application), "epiphany");

  # is($application -> launch("http://gtk2-perl.sf.net"), "ok");
  # is($application -> launch_with_env(["http://gtk2-perl.sf.net"], [map { "$_=" . $ENV{ $_ } } (keys(%ENV))]), "ok");

  isa_ok(($type -> get_short_list_applications())[0], "Gnome2::VFS::Mime::Application");
  isa_ok(($type -> get_all_applications())[0], "Gnome2::VFS::Mime::Application");
  isa_ok(($type -> get_all_applications_for_uri("http://www.google.com"))[0], "Gnome2::VFS::Mime::Application");
}

TODO: {
  local $TODO = "hrm";
  isa_ok(Gnome2::VFS::Mime::Application -> new_from_id("epiphany"), "Gnome2::VFS::Mime::Application");
  isa_ok(Gnome2::VFS::Mime::Application -> new_from_desktop_id("epiphany"), "Gnome2::VFS::Mime::Application");
}

# $type -> get_icon();
# $type -> set_icon(...);

# is($type -> set_description("HTML Foo"), "ok");
# is($type -> get_description(), "HTML Foo");

# is($type -> set_can_be_executable(0), "ok");
# ok(not $type -> can_be_executable());

# is($type -> add_application_to_short_list("galeon"), "ok");
# is($type -> remove_application_from_short_list("galeon"), "ok");

# is($type -> add_extension("htm"), "ok");
# is($type -> remove_extension("htm"), "ok");

# is($type -> set_short_list_applications(qw(galeon epiphany)), "ok");

# is($type -> extend_all_applications(qw(xmms)), "ok");
# is($type -> remove_from_all_applications(qw(xmms)), "ok");

# is($type -> set_default_application("galeon"), "ok");

# is($type -> get_default_action_type(), "application");
# is($type -> set_default_action_type("none"), "ok");
# is($type -> get_default_action_type(), "none");

ok(defined Gnome2::VFS -> get_mime_type("/usr/bin/perl"));
is(Gnome2::VFS -> get_mime_type_for_data("<html></html>"), "text/html");

SKIP: {
  skip("get_all_desktop_entries and get_default_desktop_entry are new in 2.8", 4)
    unless (Gnome2::VFS -> CHECK_VERSION(2, 8, 0));

  is($type -> get_all_desktop_entries(), undef);
  is($type -> get_default_desktop_entry(), undef);

  is($type -> get_equivalence($type), "identical");
  is($type -> is_equal($type), 1);
}

###############################################################################

Gnome2::VFS -> shutdown();
