### ----------------------------------------------------
### -- Gnome::Gio
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: lib/Gnome/Gio/AppInfo.rakumod
### ----------------------------------------------------
### -- Chunk 2 of 2
#TM:0:launch-uris-finish:
=begin pod
=head2 launch-uris-finish

Finishes a C<launch-uris-async()> operation.

Returns: C<True> on successful launch, C<False> otherwise.

  method launch-uris-finish ( GAsyncResult $result, N-GError $error --> Bool )

=item GAsyncResult $result; a B<Gnome::Gio::AsyncResult>
=item N-GError $error; a B<Gnome::Gio::Error>
=end pod

method launch-uris-finish ( GAsyncResult $result, $error is copy --> Bool ) {
  $error .= _get-native-object-no-reffing unless $error ~~ N-GError;

  g_app_info_launch_uris_finish(
    self._get-native-object-no-reffing, $result, $error
  ).Bool
}

sub g_app_info_launch_uris_finish (
  N-GObject $appinfo, GAsyncResult $result, N-GError $error --> gboolean
) is native(&gio-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:1:remove-supports-type:
=begin pod
=head2 remove-supports-type

Removes a supported type from an application, if possible.

Returns: C<True> on success, C<False> on error.

  method remove-supports-type ( Str $content-type --> Bool )

Returns C<True> if successful, C<False> if an error is set. When False, Check the error attribute C<$.last-error> for failures.

=item Str $content-type; a string.
=end pod

method remove-supports-type ( Str $content-type --> Bool ) {
  my CArray[N-GError] $error .= new(N-GError);

  my Bool $r = g_app_info_remove_supports_type(
    self._get-native-object-no-reffing, $content-type, $error
  ).Bool;

  $!last-error .= new(:native-object($r ?? N-GError !! $error[0]));

  $r
}

sub g_app_info_remove_supports_type (
  N-GObject $appinfo, gchar-ptr $content-type,
  CArray[N-GError] $error --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:reset-type-associations:
=begin pod
=head2 reset-type-associations

Removes all changes to the type associations done by C<.set_as_default_for_type()>, C<.set_as_default_for_extension()>, C<.add_supports_type()> or C<.remove_supports_type()>.

  method reset-type-associations ( Str $content-type )

=item Str $content-type;
=end pod

method reset-type-associations ( Str $content-type ) {
  g_app_info_reset_type_associations($content-type);
}

sub g_app_info_reset_type_associations (
  gchar-ptr $content-type
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-as-default-for-extension:
=begin pod
=head2 set-as-default-for-extension

Sets the application as the default handler for the given file extension.

Returns: C<True> on success, C<False> on error. When False, Check the error attribute C<$.last-error> for failures.

  method set-as-default-for-extension ( Str $extension --> Bool )

=item Str $extension; a string containing the file extension (without the dot).
=end pod

method set-as-default-for-extension ( Str $extension --> Bool ) {
  my CArray[N-GError] $error .= new(N-GError);

  my Bool $r = g_app_info_set_as_default_for_extension(
    self._get-native-object-no-reffing, $extension, $error
  ).Bool;

  $!last-error .= new(:native-object($error[0] // N-GError));

  $r;
}

sub g_app_info_set_as_default_for_extension (
  N-GObject $appinfo, gchar-ptr $extension, CArray[N-GError] $error --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-as-default-for-type:
=begin pod
=head2 set-as-default-for-type

Sets the application as the default handler for a given type.

Sets the C<$.last-error> attribute which will be invalid on successful launch, valid otherwise and the error object must be checked for the error. Check the C<.message()> of this object to see what happened.

  method set-as-default-for-type ( Str $content-type --> Bool )

=head3 Example

This example shows how to set the default command of a jpeg image to the execution of C<ls -m>, a unix directory list command.

  $ai .= new( :command-line('ls -m'), :application-name('ls'));
  die $ai.last-error.message
    unless $ai.set-as-default-for-type('image/jpeg');

=item Str $content-type; the content type.
=end pod

method set-as-default-for-type ( Str $content-type --> Bool ) {
  my CArray[N-GError] $error .= new(N-GError);

  my Bool $r = g_app_info_set_as_default_for_type(
    self._get-native-object-no-reffing, $content-type, $error
  ).Bool;

  $!last-error .= new(:native-object($r ?? N-GError !! $error[0]));

  $r
}

sub g_app_info_set_as_default_for_type (
  N-GObject $appinfo, gchar-ptr $content-type, CArray[N-GError] $error --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-as-last-used-for-type:
=begin pod
=head2 set-as-last-used-for-type

Sets the application as the last used application for a given type. This will make the application appear as first in the list returned by C<get-recommended-for-type()>, regardless of the default application for that content type.

Returns C<True> if successful, C<False> if an error is set. When False, Check the error attribute C<$.last-error> for failures.

  method set-as-last-used-for-type ( Str $content-type --> Bool )

=item Str $content-type; the content type.
=end pod

method set-as-last-used-for-type ( Str $content-type --> Bool ) {
  my CArray[N-GError] $error .= new(N-GError);

  my Bool $r = g_app_info_set_as_last_used_for_type(
    self._get-native-object-no-reffing, $content-type, $error
  ).Bool;

  $!last-error .= new(:native-object($r ?? N-GError !! $error[0]));

  $r
}

sub g_app_info_set_as_last_used_for_type (
  N-GObject $appinfo, gchar-ptr $content-type, CArray[N-GError] $error
  --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:should-show:
=begin pod
=head2 should-show

Checks if the application info should be shown in menus that list available applications.

Returns: C<True> if the I<appinfo> should be shown, C<False> otherwise.

  method should-show ( --> Bool )

=end pod

method should-show ( --> Bool ) {
  g_app_info_should_show(self._get-native-object-no-reffing).Bool
}

sub g_app_info_should_show (
  N-GObject $appinfo --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:supports-files:
=begin pod
=head2 supports-files

Checks if the application accepts files as arguments.

Returns: C<True> if the I<appinfo> supports files.

  method supports-files ( --> Bool )

=end pod

method supports-files ( --> Bool ) {
  g_app_info_supports_files(self._get-native-object-no-reffing).Bool
}

sub g_app_info_supports_files (
  N-GObject $appinfo --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:supports-uris:
=begin pod
=head2 supports-uris

Checks if the application supports reading files and directories from URIs.

Returns: C<True> if the I<appinfo> supports URIs.

  method supports-uris ( --> Bool )

=end pod

method supports-uris ( --> Bool ) {
  g_app_info_supports_uris(self._get-native-object-no-reffing).Bool
}

sub g_app_info_supports_uris (
  N-GObject $appinfo --> gboolean
) is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:_g_app_info_create_from_commandline:
#`{{
=begin pod
=head2 create-from-commandline

  method create-from-commandline ( Str $commandline, Str $application_name, UInt $flags --> N-GObject )

=item Str $commandline;
=item Str $application_name;
=item UInt $flags; a mask with bits from GAppInfoCreateFlags.
=end pod

method _create-from-commandline (
  Str $commandline, Str $application_name, GFlag $flags, $error is copy
  --> N-GObject
) {
  my CArray[N-GError] $error .= new(N-GError);
  g_app_info_create_from_commandline(
    self._get-native-object-no-reffing, $commandline, $application_name, $flags, $error
  )
}
}}

sub _g_app_info_create_from_commandline (
  gchar-ptr $commandline, gchar-ptr $application_name, GFlag $flags,
  CArray[N-GError] $error --> N-GObject
) is native(&gio-lib)
is symbol('g_app_info_create_from_commandline')
  { * }






=finish

#-------------------------------------------------------------------------------
=begin pod
=head1 Signals

There are two ways to connect to a signal. The first option you have is to use C<register-signal()> from B<Gnome::GObject::Object>. The second option is to use C<connect-object()> directly from B<Gnome::GObject::Signal>.

=head2 First method

The positional arguments of the signal handler are all obligatory as well as their types. The named attributes C<:$widget> and user data are optional.

  # handler method
  method mouse-event ( GdkEvent $event, :$widget ) { ... }

  # connect a signal on window object
  my Gnome::Gtk3::Window $w .= new( ... );
  $w.register-signal( self, 'mouse-event', 'button-press-event');

=head2 Second method

  my Gnome::Gtk3::Window $w .= new( ... );
  my Callable $handler = sub (
    N-GObject $native, GdkEvent $event, OpaquePointer $data
  ) {
    ...
  }

  $w.connect-object( 'button-press-event', $handler);

Also here, the types of positional arguments in the signal handler are important. This is because both methods C<register-signal()> and C<connect-object()> are using the signatures of the handler routines to setup the native call interface.

=head2 Supported signals


=comment -----------------------------------------------------------------------
=comment #TS:0:changed:
=head3 changed

  method handler (
    Int :$_handle_id,
    Gnome::GObject::Object :_widget($appinfo),
    *%user-options
  );

=item $appinfo;
=item $_handle_id; the registered event handler id

=comment -----------------------------------------------------------------------
=comment #TS:0:launch-failed:
=head3 launch-failed

  method handler (
    Str $str,
    Int :$_handle_id,
    Gnome::GObject::Object :_widget($appinfo),
    *%user-options
  );

=item $appinfo;
=item $str;
=item $_handle_id; the registered event handler id

=comment -----------------------------------------------------------------------
=comment #TS:0:launched:
=head3 launched

  method handler (
    N-GObject g_type_app_info,
    N-GObject g_type_variant,
    Int :$_handle_id,
    Gnome::GObject::Object :_widget($appinfo),
    *%user-options
  );

=item $appinfo;
=item $unknown type g_type_app_info;
=item $unknown type g_type_variant;
=item $_handle_id; the registered event handler id

=end pod


