const string uri_to_open = "file:///path/to/file.tar.gz";

bool ephy_file_launch_application (AppInfo app, List files, uint32 user_time)
{
  var context = new Gdk.AppLaunchContext ();
  unowned Gdk.Display display = Gdk.Display.get_default ();
  unowned Gdk.Screen screen = Gdk.Screen.get_default ();
  context.set_display (display);
  context.set_screen (screen);
  context.set_timestamp (user_time);

  try
    {
      // the problem should be here
      return app.launch (files, context);
    }
  catch (Error e)
  {
    error (e.message);
    return false;
  }
}

void ephy_file_launch_handler (File file, uint32 user_time)
{
  try
    {
      var info = file.query_info (FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0);
      assert (info != null);
      var type = info.get_content_type ();
      message ("Content-Type: %s", type);
      assert (type != null && type != "");
      // there's a missing check on mime safety, but I'm sure the code is reached otherwise strace won't shot "file-roller" stuff
      unowned AppInfo app = AppInfo.get_default_for_type (type, false);
      var list = new List<File>();
      list.append (file);
      ephy_file_launch_application (app, list, user_time);
    }
  catch (Error e)
  {
    error (e.message);
  }
}

void main (string[] argv)
{
  Gtk.init (ref argv);

  // simulate "Open"
  var w = new Gtk.Window ();
  var b = new Gtk.Button.with_label ("Press me");
  w.add (b);
  w.show_all ();

  b.clicked.connect (() => {
      var file = File.new_for_uri (uri_to_open);
      unowned Gdk.Display d = w.get_display ();
      var ut = Gdk.x11_display_get_user_time (d);
      ephy_file_launch_handler (file, ut);
    });

  Gtk.main ();
}
