### ----------------------------------------------------
### -- Gnome::Gio
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: lib/Gnome/Gio/Application.rakumod
### ----------------------------------------------------
### -- Chunk 1 of 2
#TL:1:Gnome::Gio::Application:

use v6;
#-------------------------------------------------------------------------------
=begin pod

=head1 Gnome::Gio::Application

Core application class

=comment ![](images/X.png)

=head1 Description

A B<Gnome::Gio::Application> is the foundation of an application.  It wraps some low-level platform-specific services and is intended to act as the foundation for higher-level application classes such as B<Gnome::Gtk3::Application>. In general, you should not use this class outside of a higher level framework.

B<Gnome::Gio::Application> provides convenient life cycle management by maintaining a "use count" for the primary application instance. The use count can be changed using C<hold()> and C<release()>. If it drops to zero, the application exits. Higher-level classes such as B<Gnome::Gtk3::Application> employ the use count to ensure that the application stays alive as long as it has any opened windows.

Another feature that B<Gnome::Gio::Application> (optionally) provides is process uniqueness. Applications can make use of this functionality by providing a unique application ID. If given, only one application with this ID can be running at a time per session. The session concept is platform-dependent, but corresponds roughly to a graphical desktop login. When your application is launched again, its arguments are passed through platform communication to the already running program. The already running instance of the program is called the "primary instance"; for non-unique applications this is the always the current instance. On Linux, the D-Bus session bus is used for communication.

The use of B<Gnome::Gio::Application> differs from some other commonly-used uniqueness libraries (such as libunique) in important ways. The application is not expected to manually register itself and check if it is the primary instance. Instead, the Raku main program of a B<Gnome::Gio::Application> based application should do very little more than instantiating the application instance, possibly connecting signal handlers, then calling C<run()>. All checks for uniqueness are done internally. If the application is the primary instance then the startup signal is emitted and the mainloop runs. If the application is not the primary instance then a signal is sent to the primary instance and C<run()> promptly returns.
=comment See the code examples below.

If used, the expected form of an application identifier is the same as that of of a L<D-Bus well-known bus name|https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus>. Examples include: `com.example.MyApp`, `org.example.internal_apps.Calculator`, `org._7_zip.Archiver`. For details on valid application identifiers, see C<id-is-valid()>. Note; the Raku implementation of C<new(:app-id)> checks the id using that routine.

On Linux, the application identifier is claimed as a well-known bus name on the user's session bus.  This means that the uniqueness of your application is scoped to the current session.  It also means that your application may provide additional services (through registration of other object paths) at that bus name.  The registration of these object paths should be done with the shared GDBus session bus.  Note that due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running).  For this reason, you must ensure that any object paths that you wish to register are registered before B<Gnome::Gio::Application> attempts to acquire the bus name of your application (which happens in C<register()>).  Unfortunately, this means that you cannot use C<get-is-remote()> to decide if you want to register object paths.

B<Gnome::Gio::Application> also implements the B<Gnome::Gio::ActionGroup> and B<Gnome::Gio::ActionMap> interfaces and lets you easily export actions by adding them with C<add-action()>. When invoking an action by calling C<activate-action()> on the application, it is always invoked in the primary instance. The actions are also exported on the session bus, and GIO provides the B<Gnome::Gio::DBusActionGroup> wrapper to conveniently access them remotely. GIO provides a B<Gnome::Gio::DBusMenuModel> wrapper for remote access to exported GMenuModels.

There is a number of different entry points into a B<Gnome::Gio::Application>:

=item via 'Activate' (i.e. just starting the application)
=comment item via 'Open' (i.e. opening some files).
=item by handling a command-line
=item via activating an action

The  I<startup> signal lets you handle the application initialization for all of these in a single place.

=comment Regardless of which of these entry points is used to start the application, B<Gnome::Gio::Application> passes some "platform data from the launching instance to the primary instance, in the form of a B<GVariant> dictionary mapping strings to variants. To use platform data, override the I<before_emit> or I<after_emit> virtual functions in your B<Gnome::Gio::Application> subclass.

When dealing with B<Gnome::Gio::ApplicationCommandLine> objects, the platform data is directly available via C<get-cwd()>, C<get-environ()> and C<get-platform-data()> in that object.

As the name indicates, the platform data may vary depending on the operating system, but it always includes the current directory
=comment (key "cwd")
, and optionally the environment (ie the set of environment variables and their values) of the calling process
=comment (key "environ")
. The environment is only added to the platform data if the C<G_APPLICATION_SEND_ENVIRONMENT> flag is set.
=comment B<Gnome::Gio::Application> subclasses can add their own platform data by overriding the I<add_platform_data> virtual function. For instance, B<Gnome::Gtk3::Application> adds startup notification data in this way.

=comment To parse commandline arguments you may handle the I<command-line> signal or override the C<local_command_line()> vfunc, to parse them in either the primary instance or the local instance, respectively.

=comment For an example of opening files with a B<Gnome::Gio::Application>, see [Gnome::Gio::Application-example-open.c](https://git.gnome.org/browse/glib/tree/gio/tests/Gnome::Gio::Application-example-open.c).

=comment For an example of using actions with Gnome::Gio::Application, see [Gnome::Gio::Application-example-actions.c](https://git.gnome.org/browse/glib/tree/gio/tests/Gnome::Gio::Application-example-actions.c).

=comment For an example of using extra D-Bus hooks with Gnome::Gio::Application, see [Gnome::Gio::Application-example-dbushooks.c](https://git.gnome.org/browse/glib/tree/gio/tests/Gnome::Gio::Application-example-dbushooks.c).

=head2 See Also
=item L<Application tutorial|/gnome-gtk3/content-docs/tutorial/Application/introduction.html>

=head1 Synopsis
=head2 Declaration

  unit class Gnome::Gio::Application;
  also is Gnome::GObject::Object;
  also does Gnome::Gio::ActionMap;
  also does Gnome::Gio::ActionGroup;


=head2 Uml Diagram
![](plantuml/Application.svg)


=comment head2 Example

=end pod
#-------------------------------------------------------------------------------
use NativeCall;

#use Gnome::N::X:api<1>;
use Gnome::N::NativeLib:api<1>;
use Gnome::N::N-GObject:api<1>;
use Gnome::N::GlibToRakuTypes:api<1>;

use Gnome::Glib::Error:api<1>;

use Gnome::GObject::Object:api<1>;

use Gnome::Gio::Enums:api<1>;
use Gnome::Gio::File:api<1>;
use Gnome::Gio::ActionMap:api<1>;
use Gnome::Gio::ActionGroup:api<1>;
use Gnome::Gio::Notification:api<1>;

#-------------------------------------------------------------------------------
unit class Gnome::Gio::Application:auth<github:MARTIMM>:api<1>;
also is Gnome::GObject::Object;
also does Gnome::Gio::ActionMap;
also does Gnome::Gio::ActionGroup;

#-------------------------------------------------------------------------------
my Bool $signals-added = False;

#`{{
#-------------------------------------------------------------------------------
# next GOptionFlags and GOptionArg copied from GOptionContext to use in
# g_application_add_main_option without implementing a Raku module
=begin pod
=head2 enum GOptionFlags

Flags which modify individual options.

=item G_OPTION_FLAG_NONE: No flags.
=item G_OPTION_FLAG_HIDDEN: The option doesn't appear in `--help` output.
=item G_OPTION_FLAG_IN_MAIN: The option appears in the main section of the `--help` output, even if it is defined in a group.
=item G_OPTION_FLAG_REVERSE: For options of the C<G_OPTION_ARG_NONE> kind, this flag indicates that the sense of the option is reversed.
=item G_OPTION_FLAG_NO_ARG: For options of the C<G_OPTION_ARG_CALLBACK> kind, this flag indicates that the callback does not take any argument (like a C<G_OPTION_ARG_NONE> option).
=item G_OPTION_FLAG_FILENAME: For options of the C<G_OPTION_ARG_CALLBACK> kind, this flag indicates that the argument should be passed to the callback in the GLib filename encoding rather than UTF-8.
=item G_OPTION_FLAG_OPTIONAL_ARG: For options of the C<G_OPTION_ARG_CALLBACK>  kind, this flag indicates that the argument supply is optional. If no argument is given then data of C<N-GOptionParseFunc> will be set to NULL.
=item G_OPTION_FLAG_NOALIAS: This flag turns off the automatic conflict resolution which prefixes long option names with `groupname-` if  there is a conflict. This option should only be used in situations where aliasing is necessary to model some legacy commandline interface. It is not safe to use this option, unless all option groups are under your direct control.

=end pod

# TE:1:GOptionFlags:
enum GOptionFlags is export (
  'G_OPTION_FLAG_NONE'            => 0,
  'G_OPTION_FLAG_HIDDEN'		      => 1 +< 0,
  'G_OPTION_FLAG_IN_MAIN'		      => 1 +< 1,
  'G_OPTION_FLAG_REVERSE'		      => 1 +< 2,
  'G_OPTION_FLAG_NO_ARG'		      => 1 +< 3,
  'G_OPTION_FLAG_FILENAME'	      => 1 +< 4,
  'G_OPTION_FLAG_OPTIONAL_ARG'    => 1 +< 5,
  'G_OPTION_FLAG_NOALIAS'	        => 1 +< 6
);

#-------------------------------------------------------------------------------
=begin pod
=head2 enum GOptionArg

The B<GOptionArg> enum values determine which type of extra argument the
options expect to find. If an option expects an extra argument, it can
be specified in several ways; with a short option: `-x arg`, with a long
option: `--name arg` or combined in a single argument: `--name=arg`.


=item G_OPTION_ARG_NONE: No extra argument. This is useful for simple flags.
=item G_OPTION_ARG_STRING: The option takes a string argument.
=item G_OPTION_ARG_INT: The option takes an integer argument.
=item G_OPTION_ARG_CALLBACK: The option provides a callback (of type B<N-GOptionArgFunc>) to parse the extra argument.
=item G_OPTION_ARG_FILENAME: The option takes a filename as argument.
=item G_OPTION_ARG_STRING_ARRAY: The option takes a string argument, multiple uses of the option are collected into an array of strings.
=item G_OPTION_ARG_FILENAME_ARRAY: The option takes a filename as argument,  multiple uses of the option are collected into an array of strings.
=item G_OPTION_ARG_DOUBLE: The option takes a double argument. The argument can be formatted either for the user's locale or for the "C" locale.
=item G_OPTION_ARG_INT64: The option takes a 64-bit integer. Like C<G_OPTION_ARG_INT> but for larger numbers. The number can be in decimal base, or in hexadecimal (when prefixed with `0x`, for example, `0xffffffff`).


=end pod

# TE:1:GOptionArg:
enum GOptionArg is export (
  'G_OPTION_ARG_NONE',
  'G_OPTION_ARG_STRING',
  'G_OPTION_ARG_INT',
  'G_OPTION_ARG_CALLBACK',
  'G_OPTION_ARG_FILENAME',
  'G_OPTION_ARG_STRING_ARRAY',
  'G_OPTION_ARG_FILENAME_ARRAY',
  'G_OPTION_ARG_DOUBLE',
  'G_OPTION_ARG_INT64'
);
}}

#-------------------------------------------------------------------------------
=begin pod
=head1 Methods
=head2 new

=head3 default, no options

Create a new Application object with an empty application id and flags set to G_APPLICATION_FLAGS_NONE.

  multi method new ( )


=head3 :default

Sets the default B<GApplication> instance for this process.

Normally there is only one B<GApplication> per process and it becomes the default when it is created. You can exercise more control over this by using C<set-default()>. If there is no default application then this object becomes invalid.

  multi method new ( :default! )


=head3 :app-id, :flags

Create a new object with a valid application id and a mask of GApplicationFlags values.

  multi method new (
    Bool :$app-id!, Int :$flags = G_APPLICATION_FLAGS_NONE
  )


=head3 :native-object

Create an object using a native object from elsewhere.

  multi method new ( N-GObject :$native-object! )

=end pod
#TM:1:new(:app-id):
#TM:4:new(:native-object):Gnome::N::TopLevelClassSupport
submethod BUILD ( *%options ) {

  # add signal info in the form of group<signal-name>.
  # groups are e.g. signal, event, nativeobject etc
  $signals-added = self.add-signal-types( $?CLASS.^name,
    :w0<startup shutdown activate name-lost>,
    :w1<command-line handle-local-options>,
    :w3<open>,
  ) unless $signals-added;


  # prevent creating wrong widgets
  if self.^name eq 'Gnome::Gio::Application' {

    # check if native object is set by a parent class
    if self.is-valid { }

    # check if common options are handled by some parent
    elsif %options<native-object>:exists { }


    # process all named arguments
    else {
      my $no;

      if ? %options<app-id> {
        if g_application_id_is_valid(%options<app-id>) {
          my GApplicationFlags $f = %options<flags> // G_APPLICATION_FLAGS_NONE;
          $no = _g_application_new( %options<app-id>, $f);
        }

        else {
          die X::Gnome.new(
            :message("Invalid application id: %options<app-id>")
          );
        }
      }

      elsif %options<default>:exists {
        $no = _g_application_get_default;
      }


      #`{{ use this when the module is not made inheritable
      # check if there are unknown options
      elsif %options.elems {
        die X::Gnome.new(
          :message(
            'Unsupported, undefined, incomplete or wrongly typed options for ' ~
            self.^name ~ ': ' ~ %options.keys.join(', ')
          )
        );
      }
      }}

      #`{{ when there are no defaults use this
      # check if there are any options
      elsif %options.elems == 0 {
        die X::Gnome.new(:message('No options specified ' ~ self.^name));
      }
      }}

      #`{{ when there are defaults use this instead
      # create default object
      else {
        $no = _g_application_new( '', G_APPLICATION_FLAGS_NONE);
      }
      }}

      self._set-native-object($no);
    }

    # only after creating the widget, the gtype is known
    self._set-class-info('GApplication');
  }
}

#`{{
#-------------------------------------------------------------------------------
# no pod. user does not have to know about it.
method _fallback ( $native-sub is copy --> Callable ) {

  my Callable $s;
  try { $s = &::("g_application_$native-sub"); } unless ?$s;
  try { $s = &::("g_$native-sub"); } unless ?$s;
  try { $s = &::($native-sub); }

  self._set-class-name-of-sub('GApplication');

  $s = callsame unless ?$s;

  $s;
}
}}

#-------------------------------------------------------------------------------
#TM:1:activate:
=begin pod
=head2 activate

Activates the application. In essence, this results in the I<activate> signal being emitted in the primary instance.  The application must be registered before calling this function.

  method activate ( )

=end pod

method activate ( ) {
  g_application_activate(self._get-native-object-no-reffing);
}

sub g_application_activate ( N-GObject $application  )
  is native(&gio-lib)
  { * }

#`{{ it works but we can better use Raku option management modules
#-------------------------------------------------------------------------------
#TM:1:add-main-option:
=begin pod
=head2 add-main-option

Add an option to be handled by the application.
=comment Calling this function is the equivalent of calling C<add-main-option-entries()> with a single B<GOptionEntry> that has its arg_data member set to C<undefined>.

The parsed arguments will be packed into a B<GVariantDict> which is passed to  I<handle-local-options>. If C<G_APPLICATION_HANDLES_COMMAND_LINE> is set, then it will also be sent to the primary instance.
=comment See C<g_application_add_main_option_entries()> for more details.  See B<GOptionEntry> for more documentation of the arguments.

  method add-main-option ( Str $long_name, Str $short_name, GOptionFlags $flags,
    GOptionArg $arg, Str $description, Str $arg_description?
  )

=item Str $long_name; the long name of an option used to specify it in a commandline
=item Str $short_name; the short name of an option, C<I<B<ONE>>> ascii character.
=item GOptionFlags $flags; flags from B<GOptionFlags>
=item GOptionArg $arg; the type of the option, as a B<GOptionArg>
=item Str $description; the description for the option in `--help` output
=item Str $arg_description; the placeholder to use for the extra argument parsed by the option in `--help` output

=head3 Example

  $app.add-main-option(
    'flip-it', 'f', G_OPTION_FLAG_IN_MAIN,
    G_OPTION_ARG_NONE, 'flips it to the other side'
  );

=end pod

method add-main-option ( Str $long_name, Str $short_name, GOptionFlags $flags,
  GOptionArg $arg, Str $description, Str $arg_description?
) {

  g_application_add_main_option(
    self._get-native-object-no-reffing, $long_name, $short_name.encode[0],
    $flags.Int, $arg, $description, $arg_description
  );
}

sub g_application_add_main_option ( N-GObject $application, gchar-ptr $long_name, gchar $short_name, GEnum $flags, GEnum $arg, gchar-ptr $description, gchar-ptr $arg_description
) is native(&gio-lib)
  { * }
}}

#`{{
#-------------------------------------------------------------------------------
# TM:0:add-main-option-entries:
=begin pod
=head2 add-main-option-entries

Adds main option entries to be handled by the application.

This function is comparable to C<g_option_context_add_main_entries()>.

After the commandline arguments are parsed, the  I<handle-local-options> signal will be emitted.  At this point, the application can inspect the values pointed to by I<arg_data> in the given B<GOptionEntrys>.

Unlike B<GOptionContext>, B<GApplication> supports giving a C<undefined> I<arg_data> for a non-callback B<GOptionEntry>.  This results in the argument in question being packed into a B<GVariantDict> which is also passed to  I<handle-local-options>, where it can be inspected and modified.  If C<G_APPLICATION_HANDLES_COMMAND_LINE> is set, then the resulting dictionary is sent to the primary instance, where C<g_application_command_line_get_options_dict()> will return it. This "packing" is done according to the type of the argument -- booleans for normal flags, strings for strings, bytestrings for filenames, etc.  The packing only occurs if the flag is given (ie: we do not pack a "false" B<GVariant> in the case that a flag is missing).

In general, it is recommended that all commandline arguments are parsed locally.  The options dictionary should then be used to transmit the result of the parsing to the primary instance, where C<g_variant_dict_lookup()> can be used.  For local options, it is possible to either use I<arg_data> in the usual way, or to consult (and potentially remove) the option from the options dictionary.

This function is new in GLib 2.40.  Before then, the only real choice was to send all of the commandline arguments (options and all) to the primary instance for handling.  B<GApplication> ignored them completely on the local side.  Calling this function "opts in" to the new behaviour, and in particular, means that unrecognised options will be treated as errors.  Unrecognised options have never been ignored when C<G_APPLICATION_HANDLES_COMMAND_LINE> is unset.

If  I<handle-local-options> needs to see the list of filenames, then the use of C<G_OPTION_REMAINING> is recommended.  If I<arg_data> is C<undefined> then C<G_OPTION_REMAINING> can be used as a key into the options dictionary.  If you do use C<G_OPTION_REMAINING> then you need to handle these arguments for yourself because once they are consumed, they will no longer be visible to the default handling (which treats them as filenames to be opened).

It is important to use the proper GVariant format when retrieving the options with C<g_variant_dict_lookup()>:
=item for C<G_OPTION_ARG_NONE>, use b
=item for C<G_OPTION_ARG_STRING>, use &s
=item for C<G_OPTION_ARG_INT>, use i
=item for C<G_OPTION_ARG_INT64>, use x
=item for C<G_OPTION_ARG_DOUBLE>, use d
=item for C<G_OPTION_ARG_FILENAME>, use ^ay
=item for C<G_OPTION_ARG_STRING_ARRAY>, use &as
=item for C<G_OPTION_ARG_FILENAME_ARRAY>, use ^aay

  method add-main-option-entries ( GOptionEntry $entries )

=item GOptionEntry $entries; (array zero-terminated=1) (element-type GOptionEntry) a C<undefined>-terminated list of B<GOptionEntrys>

=end pod

method add-main-option-entries ( GOptionEntry $entries ) {

  g_application_add_main_option_entries(
    self._get-native-object-no-reffing, $entries
  );
}

sub g_application_add_main_option_entries ( N-GObject $application, GOptionEntry $entries  )
  is native(&gio-lib)
  { * }
}}
#`{{
#-------------------------------------------------------------------------------
# TM:0:add-option-group:
=begin pod
=head2 add-option-group

Adds a B<GOptionGroup> to the commandline handling of the application.  This function is comparable to C<g_option_context_add_group()>.  Unlike C<g_application_add_main_option_entries()>, this function does not deal with C<undefined> I<arg_data> and never transmits options to the primary instance.  The reason for that is because, by the time the options arrive at the primary instance, it is typically too late to do anything with them. Taking the GTK option group as an example: GTK will already have been initialised by the time the  I<command-line> handler runs. In the case that this is not the first-running instance of the application, the existing instance may already have been running for a very long time.  This means that the options from B<GOptionGroup> are only really usable in the case that the instance of the application being run is the first instance.  Passing options like `--display=` or `--gdk-debug=` on future runs will have no effect on the existing primary instance.  Calling this function will cause the options in the supplied option group to be parsed, but it does not cause you to be "opted in" to the new functionality whereby unrecognised options are rejected even if C<G_APPLICATION_HANDLES_COMMAND_LINE> was given.

  method add-option-group ( GOptionGroup $group )

=item GOptionGroup $group; (transfer full): a B<GOptionGroup>

=end pod

method add-option-group ( GOptionGroup $group ) {

  g_application_add_option_group(
    self._get-native-object-no-reffing, $group
  );
}

sub g_application_add_option_group ( N-GObject $application, GOptionGroup $group  )
  is native(&gio-lib)
  { * }
}}

#`{{
#-------------------------------------------------------------------------------
# TM:0:bind-busy-property:
=begin pod
=head2 bind-busy-property

Marks the application as busy (see C<g_application_mark_busy()>) while I<$property> on I<$object> is C<True>.  The binding holds a reference to the application while it is active, but not to I<object>. Instead, the binding is destroyed when I<$object> is finalized.

  method bind-busy-property ( Pointer $object, Str $property )

=item Pointer $object; (type GObject.Object): a B<GObject>
=item Str $property; the name of a boolean property of I<object>

=end pod

method bind-busy-property ( Pointer $object, Str $property ) {

  g_application_bind_busy_property(
    self._get-native-object-no-reffing, $object, $property
  );
}

sub g_application_bind_busy_property ( N-GObject $application, gpointer $object, gchar-ptr $property  )
  is native(&gio-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:1:get-application-id:
=begin pod
=head2 get-application-id

Gets the unique identifier for the application.

Returns: the identifier for the application, owned by the application

  method get-application-id ( --> Str )

=end pod

method get-application-id ( --> Str ) {

  g_application_get_application_id(
    self._get-native-object-no-reffing,
  );
}

sub g_application_get_application_id ( N-GObject $application --> gchar-ptr )
  is native(&gio-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:get-dbus-connection:
=begin pod
=head2 get-dbus-connection

Gets the B<GDBusConnection> being used by the application, or C<undefined>.  If B<GApplication> is using its D-Bus backend then this function will return the B<GDBusConnection> being used for uniqueness and communication with the desktop environment and other instances of the application.  If B<GApplication> is not using D-Bus then this function will return C<undefined>.  This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.  This function must not be called before the application has been registered.  See C<g_application_get_is_registered()>.

Returns: (transfer none): a B<GDBusConnection>, or C<undefined>

  method get-dbus-connection ( --> GDBusConnection )


=end pod

method get-dbus-connection ( --> GDBusConnection ) {

  g_application_get_dbus_connection(
    self._get-native-object-no-reffing,
  );
}

sub g_application_get_dbus_connection ( N-GObject $application --> GDBusConnection )
  is native(&gio-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:4:get-dbus-object-path:ex-application.raku
=begin pod
=head2 get-dbus-object-path

Gets the D-Bus object path being used by the application, or C<undefined>.  If B<GApplication> is using its D-Bus backend then this function will return the D-Bus object path that B<GApplication> is using.  If the application is the primary instance then there is an object published at this path.  If the application is not the primary instance then the result of this function is undefined.  If B<GApplication> is not using D-Bus then this function will return C<undefined>.  This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus.  This function must not be called before the application has been registered.  See C<g_application_get_is_registered()>.

Returns: the object path, or C<undefined>

  method get-dbus-object-path ( --> Str )


=end pod

method get-dbus-object-path ( --> Str ) {

  g_application_get_dbus_object_path(
    self._get-native-object-no-reffing,
  );
}

sub g_application_get_dbus_object_path ( N-GObject $application --> gchar-ptr )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#`{{
#TM:0:_get-default:
=begin pod
=head2 get-default

Returns the default B<GApplication> instance for this process.

Normally there is only one B<GApplication> per process and it becomes the default when it is created. You can exercise more control over this by using C<set_default()>. If there is no default application then C<undefined> is returned.

Returns: the default application for this process, or C<undefined>

  method get-default ( --> GApplication )

=end pod

method get-default ( --> N-GObject ) {

  g_application_get_default( );
}
}}

sub _g_application_get_default ( --> N-GObject )
  is native(&gio-lib)
  is symbol('g_application_get_default')
  { * }

#-------------------------------------------------------------------------------
#TM:1:get-flags:
=begin pod
=head2 get-flags

Gets the flags for the application.  See B<GApplicationFlags>.

Returns: a mask of ored GApplicationFlags flags for the application

  method get-flags ( --> Int )

=end pod

method get-flags ( --> Int ) {

  g_application_get_flags(self._get-native-object-no-reffing)
}

sub g_application_get_flags ( N-GObject $application --> GEnum )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:get-inactivity-timeout:
=begin pod
=head2 get-inactivity-timeout

Gets the current inactivity timeout for the application. This is the amount of time (in milliseconds) after the last call to C<release()> before the application stops running.

Returns: the timeout, in milliseconds

  method get-inactivity-timeout ( --> UInt )


=end pod

method get-inactivity-timeout ( --> UInt ) {

  g_application_get_inactivity_timeout(
    self._get-native-object-no-reffing,
  );
}

sub g_application_get_inactivity_timeout ( N-GObject $application --> guint )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-is-busy:
=begin pod
=head2 get-is-busy

Gets the application's current busy state, as set through C<g_application_mark_busy()> or C<g_application_bind_busy_property()>.

Returns: C<True> if the application is currenty marked as busy

  method get-is-busy ( --> Int )


=end pod

method get-is-busy ( --> Int ) {

  g_application_get_is_busy(
    self._get-native-object-no-reffing,
  );
}

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

#-------------------------------------------------------------------------------
#TM:5:get-is-registered:g_application_get_is_registered
=begin pod
=head2 get-is-registered

Checks if the application is registered.  An application is registered if C<g_application_register()> has been successfully called.

Returns: C<True> if the application is registered

  method get-is-registered ( --> Bool )

=end pod

method get-is-registered ( --> Bool ) {
  g_application_get_is_registered(self._get-native-object-no-reffing).Bool
}

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

#-------------------------------------------------------------------------------
#TM:4:get-is-remote:ex-application.raku
=begin pod
=head2 get-is-remote

Checks if the application is remote.  If the application is remote then it means that another instance of application already exists (the 'primary' instance).  Calls to perform actions on the application will result in the actions being performed by the primary instance.  The value of this property cannot be accessed before C<register()> has been called.  See C<get-is-registered()>.

Returns: C<True> if the application is remote

  method get-is-remote ( --> Bool )

=end pod

method get-is-remote ( --> Bool ) {

  g_application_get_is_remote(
    self._get-native-object-no-reffing,
  ).Bool
}

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

#-------------------------------------------------------------------------------
#TM:1:get-resource-base-path:
=begin pod
=head2 get-resource-base-path

Gets the resource base path of the application.  See C<g_application_set_resource_base_path()> for more information.

Returns: (nullable): the base resource path, if one is set

  method get-resource-base-path ( --> Str )


=end pod

method get-resource-base-path ( --> Str ) {

  g_application_get_resource_base_path(
    self._get-native-object-no-reffing,
  );
}

sub g_application_get_resource_base_path ( N-GObject $application --> gchar-ptr )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:hold:
=begin pod
=head2 hold

Increases the use count of the application.  Use this function to indicate that the application has a reason to continue to run.  For example, C<hold()> is called by GTK+ when a toplevel window is on the screen.  To cancel the hold, call C<release()>.

  method hold ( )


=end pod

method hold ( ) {

  g_application_hold(
    self._get-native-object-no-reffing,
  );
}

sub g_application_hold ( N-GObject $application  )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:id-is-valid:
=begin pod
=head2 id-is-valid

Checks if I<$application_id> is a valid application identifier.
A valid ID is required for calls to C<new(:app-id)> and C<set-application-id()>.
Application identifiers follow the same format as L<D-Bus well-known bus names|https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus>. For convenience, the restrictions on application identifiers are reproduced here:
=item Application identifiers are composed of 1 or more elements separated by a period (`.`) character. All elements must contain at least one character.
=item Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_-`, with `-` discouraged in new application identifiers. Each element must not begin with a digit.
=item Application identifiers must contain at least one `.` (period) character (and thus at least two elements).
=item Application identifiers must not begin with a `.` (period) character.
=item Application identifiers must not exceed 255 characters.

Note that the hyphen (`-`) character is allowed in application identifiers, but is problematic or not allowed in various specifications and APIs that refer to D-Bus, such as L<Flatpak application IDs|http://docs.flatpak.org/en/latest/introduction.html#identifiers>, the L<DBusActivatable interface in the Desktop Entry Specification|https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus>, and the convention that an application's "main" interface and object path resemble its application identifier and bus name. To avoid situations that require special-case handling, it is recommended that new application identifiers consistently replace hyphens with underscores.

Like D-Bus interface names, application identifiers should start with the reversed DNS domain name of the author of the interface (in lower-case), and it is conventional for the rest of the application identifier to consist of words run together, with initial capital letters.

As with D-Bus interface names, if the author's DNS domain name contains hyphen/minus characters they should be replaced by underscores, and if it contains leading digits they should be escaped by prepending an underscore. For example, if the owner of 7-zip.org used an application identifier for an archiving application, it might be named `org._7_zip.Archiver`.

Returns: C<True> if I<$application_id> is valid

  method id-is-valid ( Str $application_id --> Bool )

=item Str $application_id; a potential application identifier

=end pod

method id-is-valid ( Str $application_id --> Bool ) {

  g_application_id_is_valid($application_id).Bool;
}

sub g_application_id_is_valid ( gchar-ptr $application_id --> gboolean )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:mark-busy:
=begin pod
=head2 mark-busy

Increases the busy count of the application.  Use this function to indicate that the application is busy, for instance while a long running operation is pending.  The busy state will be exposed to other processes, so a session shell will use that information to indicate the state to the user (e.g. with a spinner).  To cancel the busy indication, use C<g_application_unmark_busy()>.

  method mark-busy ( )


=end pod

method mark-busy ( ) {

  g_application_mark_busy(
    self._get-native-object-no-reffing,
  );
}

sub g_application_mark_busy ( N-GObject $application  )
  is native(&gio-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:open