Class: Gio::Application

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Overview

Virtual function table for #GApplication.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_id, flags) ⇒ Gio::Application

Creates a new #GApplication instance.

If non-nil, the application id must be valid. See
g_application_id_is_valid().

If no application ID is given then some features of #GApplication
(most notably application uniqueness) will be disabled.

Parameters:

Class Method Details

.defaultGio::Application

Returns the default #GApplication instance for this process.

Normally there is only one #GApplication per process and it becomes
the default when it is created. You can exercise more control over
this by using g_application_set_default().

If there is no default application then nil is returned.

Returns:

.id_is_valid(application_id) ⇒ Boolean

Checks if application_id is a valid application identifier.

A valid ID is required for calls to g_application_new() and
g_application_set_application_id().

Application identifiers follow the same format as
D-Bus well-known bus names.
For convenience, the restrictions on application identifiers are
reproduced here:

  • Application identifiers are composed of 1 or more elements separated by a
    period (.) character. All elements must contain at least one character.

  • 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.

  • Application identifiers must contain at least one . (period) character
    (and thus at least two elements).

  • Application identifiers must not begin with a . (period) character.

  • 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
Flatpak application IDs,
the
DBusActivatable interface in the Desktop Entry Specification,
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.

Parameters:

  • application_id (String)

    a potential application identifier

Returns:

  • (Boolean)

    true if application_id is valid

Instance Method Details

#action_group=(action_group) ⇒ Gio::ActionGroup

The group of actions that the application exports.

Parameters:

Returns:

#activatenil

Activates the application.

In essence, this results in the #GApplication::activate signal being
emitted in the primary instance.

The application must be registered before calling this function.

Returns:

  • (nil)

#add_main_option(long_name, short_name, flags, arg, description, arg_description) ⇒ nil

Add an option to be handled by application.

Calling this function is the equivalent of calling
g_application_add_main_option_entries() with a single GOption::Entry
that has its arg_data member set to nil.

The parsed arguments will be packed into a GVariant::Dict which
is passed to #GApplication::handle-local-options. If
%G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also
be sent to the primary instance. See
g_application_add_main_option_entries() for more details.

See GOption::Entry for more documentation of the arguments.

Parameters:

  • long_name (String)

    the long name of an option used to specify it in a commandline

  • short_name (Gio::gchar)

    the short name of an option

  • flags (GLib::OptionFlags)

    flags from GOption::Flags

  • arg (GLib::OptionArg)

    the type of the option, as a GOption::Arg

  • description (String)

    the description for the option in --help output

  • arg_description (String)

    the placeholder to use for the extra argument
    parsed by the option in --help output

Returns:

  • (nil)

#add_main_option_entries(entries) ⇒ nil

Adds main option entries to be handled by application.

This function is comparable to g_option_context_add_main_entries().

After the commandline arguments are parsed, the
#GApplication::handle-local-options signal will be emitted. At this
point, the application can inspect the values pointed to by arg_data
in the given GOption::Entrys.

Unlike GOption::Context, #GApplication supports giving a nil
arg_data for a non-callback GOption::Entry. This results in the
argument in question being packed into a GVariant::Dict which is also
passed to #GApplication::handle-local-options, where it can be
inspected and modified. If %G_APPLICATION_HANDLES_COMMAND_LINE is
set, then the resulting dictionary is sent to the primary instance,
where g_application_command_line_get_options_dict() will return it.
As it has been passed outside the process at this point, the types of all
values in the options dict must be checked before being used.
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" #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
g_variant_dict_lookup() can be used. For local options, it is
possible to either use 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. #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
%G_APPLICATION_HANDLES_COMMAND_LINE is unset.

If #GApplication::handle-local-options needs to see the list of
filenames, then the use of %G_OPTION_REMAINING is recommended. If
arg_data is nil then %G_OPTION_REMAINING can be used as a key into
the options dictionary. If you do use %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 g_variant_dict_lookup():

  • for %G_OPTION_ARG_NONE, use b
  • for %G_OPTION_ARG_STRING, use &s
  • for %G_OPTION_ARG_INT, use i
  • for %G_OPTION_ARG_INT64, use x
  • for %G_OPTION_ARG_DOUBLE, use d
  • for %G_OPTION_ARG_FILENAME, use ^&ay
  • for %G_OPTION_ARG_STRING_ARRAY, use ^a&s
  • for %G_OPTION_ARG_FILENAME_ARRAY, use ^a&ay

Parameters:

  • entries (Array<GLib::OptionEntry>)

    the
    main options for the application

Returns:

  • (nil)

#add_option_group(group) ⇒ nil

Adds a GOption::Group to the commandline handling of application.

This function is comparable to g_option_context_add_group().

Unlike g_application_add_main_option_entries(), this function does
not deal with nil 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 #GApplication::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 GOption::Group 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
%G_APPLICATION_HANDLES_COMMAND_LINE was given.

Parameters:

  • group (GLib::OptionGroup)

    a GOption::Group

Returns:

  • (nil)

#application_idString

The unique identifier for the application.

Returns:

  • (String)

    application-id

#application_id=(application_id) ⇒ String

The unique identifier for the application.

Parameters:

  • application_id (String)

Returns:

  • (String)

    application-id

  • (String)

    application-id

#bind_busy_property(object, property) ⇒ nil

Marks application as busy (see g_application_mark_busy()) while
property on object is true.

The binding holds a reference to application while it is active, but
not to object. Instead, the binding is destroyed when object is
finalized.

Parameters:

  • object (GObject::Object)

    a #GObject

  • property (String)

    the name of a boolean property of object

Returns:

  • (nil)

#dbus_connectionGio::DBusConnection

Gets the GDBus::Connection being used by the application, or nil.

If #GApplication is using its D-Bus backend then this function will
return the GDBus::Connection being used for uniqueness and
communication with the desktop environment and other instances of the
application.

If #GApplication is not using D-Bus then this function will return
nil. 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 g_application_get_is_registered().

Returns:

#dbus_object_pathString

Gets the D-Bus object path being used by the application, or nil.

If #GApplication is using its D-Bus backend then this function will
return the D-Bus object path that #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 #GApplication is not using D-Bus then this function will return
nil. 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 g_application_get_is_registered().

Returns:

  • (String)

    the object path, or nil

#flagsGio::ApplicationFlags

Flags specifying the behaviour of the application.

Returns:

#flags=(flags) ⇒ Gio::ApplicationFlags

Flags specifying the behaviour of the application.

Parameters:

Returns:

#holdnil

Increases the use count of application.

Use this function to indicate that the application has a reason to
continue to run. For example, g_application_hold() is called by GTK
when a toplevel window is on the screen.

To cancel the hold, call g_application_release().

Returns:

  • (nil)

#inactivity_timeoutInteger

Time (in milliseconds) to stay alive after becoming idle.

Returns:

  • (Integer)

    inactivity-timeout

#inactivity_timeout=(inactivity_timeout) ⇒ Integer

Time (in milliseconds) to stay alive after becoming idle.

Parameters:

  • inactivity_timeout (Integer)

Returns:

  • (Integer)

    inactivity-timeout

  • (Integer)

    inactivity-timeout

#is_busyBoolean

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

Returns:

  • (Boolean)

    true if application is currently marked as busy

#is_busy=(is_busy) ⇒ Boolean

Whether the application is currently marked as busy through
g_application_mark_busy() or g_application_bind_busy_property().

Parameters:

  • is_busy (Boolean)

Returns:

  • (Boolean)

    is-busy

  • (Boolean)

    is-busy

#is_busy?Boolean

Whether the application is currently marked as busy through
g_application_mark_busy() or g_application_bind_busy_property().

Returns:

  • (Boolean)

    is-busy

#is_registeredBoolean

Checks if application is registered.

An application is registered if g_application_register() has been
successfully called.

Returns:

  • (Boolean)

    true if application is registered

#is_registered=(is_registered) ⇒ Boolean

Whether [methodGio.Application.register] has been called.

Parameters:

  • is_registered (Boolean)

Returns:

  • (Boolean)

    is-registered

  • (Boolean)

    is-registered

#is_registered?Boolean

Whether [methodGio.Application.register] has been called.

Returns:

  • (Boolean)

    is-registered

#is_remoteBoolean

Checks if application is remote.

If application is remote then it means that another instance of
application already exists (the 'primary' instance). Calls to
perform actions on application will result in the actions being
performed by the primary instance.

The value of this property cannot be accessed before
g_application_register() has been called. See
g_application_get_is_registered().

Returns:

  • (Boolean)

    true if application is remote

#is_remote=(is_remote) ⇒ Boolean

Whether this application instance is remote.

Parameters:

  • is_remote (Boolean)

Returns:

  • (Boolean)

    is-remote

  • (Boolean)

    is-remote

#is_remote?Boolean

Whether this application instance is remote.

Returns:

  • (Boolean)

    is-remote

#mark_busynil

Increases the busy count of 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 g_application_unmark_busy().

The application must be registered before calling this function.

Returns:

  • (nil)

#open(files, n_files, hint) ⇒ nil

Opens the given files.

In essence, this results in the #GApplication::open signal being emitted
in the primary instance.

n_files must be greater than zero.

hint is simply passed through to the ::open signal. It is
intended to be used by applications that have multiple modes for
opening files (eg: "view" vs "edit", etc). Unless you have a need
for this functionality, you should use "".

The application must be registered before calling this function
and it must have the %G_APPLICATION_HANDLES_OPEN flag set.

Parameters:

  • files (Array<Gio::File>)

    an array of #GFiles to open

  • n_files (Integer)

    the length of the files array

  • hint (String)

    a hint (or ""), but never nil

Returns:

  • (nil)

#option_context_description=(description) ⇒ nil

Adds a description to the application option context.

See g_option_context_set_description() for more information.

Parameters:

  • description (String)

    a string to be shown in --help output
    after the list of options, or nil

Returns:

  • (nil)

#option_context_parameter_string=(parameter_string) ⇒ nil

Sets the parameter string to be used by the commandline handling of application.

This function registers the argument to be passed to g_option_context_new()
when the internal GOption::Context of application is created.

See g_option_context_new() for more information about parameter_string.

Parameters:

  • parameter_string (String)

    a string which is displayed
    in the first line of --help output, after the usage summary programname [OPTION...].

Returns:

  • (nil)

#option_context_summary=(summary) ⇒ nil

Adds a summary to the application option context.

See g_option_context_set_summary() for more information.

Parameters:

  • summary (String)

    a string to be shown in --help output
    before the list of options, or nil

Returns:

  • (nil)

#quitnil

Immediately quits the application.

Upon return to the mainloop, g_application_run() will return,
calling only the 'shutdown' function before doing so.

The hold count is ignored.
Take care if your code has called g_application_hold() on the application and
is therefore still expecting it to exist.
(Note that you may have called g_application_hold() indirectly, for example
through gtk_application_add_window().)

The result of calling g_application_run() again after it returns is
unspecified.

Returns:

  • (nil)

#register(cancellable) ⇒ Boolean

Attempts registration of the application.

This is the point at which the application discovers if it is the
primary instance or merely acting as a remote for an already-existing
primary instance. This is implemented by attempting to acquire the
application identifier as a unique bus name on the session bus using
GDBus.

If there is no application ID or if %G_APPLICATION_NON_UNIQUE was
given, then this process will always become the primary instance.

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 calling this function.

If the application has already been registered then true is
returned with no work performed.

The #GApplication::startup signal is emitted if registration succeeds
and application is the primary instance (including the non-unique
case).

In the event of an error (such as cancellable being cancelled, or a
failure to connect to the session bus), false is returned and error
is set appropriately.

Note: the return value of this function is not an indicator that this
instance is or is not the primary instance of the application. See
g_application_get_is_remote() for that.

Parameters:

Returns:

  • (Boolean)

    true if registration succeeded

#releasenil

Decrease the use count of application.

When the use count reaches zero, the application will stop running.

Never call this function except to cancel the effect of a previous
call to g_application_hold().

Returns:

  • (nil)

#resource_base_pathString

The base resource path for the application.

Returns:

  • (String)

    resource-base-path

#resource_base_path=(resource_base_path) ⇒ String

The base resource path for the application.

Parameters:

  • resource_base_path (String)

Returns:

  • (String)

    resource-base-path

  • (String)

    resource-base-path

#run(argc, argv) ⇒ Integer

Runs the application.

This function is intended to be run from main() and its return value
is intended to be returned by main(). Although you are expected to pass
the argc, argv parameters from main() to this function, it is possible
to pass nil if argv is not available or commandline handling is not
required. Note that on Windows, argc and argv are ignored, and
g_win32_get_command_line() is called internally (for proper support
of Unicode commandline arguments).

#GApplication will attempt to parse the commandline arguments. You
can add commandline flags to the list of recognised options by way of
g_application_add_main_option_entries(). After this, the
#GApplication::handle-local-options signal is emitted, from which the
application can inspect the values of its GOption::Entrys.

#GApplication::handle-local-options is a good place to handle options
such as --version, where an immediate reply from the local process is
desired (instead of communicating with an already-running instance).
A #GApplication::handle-local-options handler can stop further processing
by returning a non-negative value, which then becomes the exit status of
the process.

What happens next depends on the flags: if
%G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining
commandline arguments are sent to the primary instance, where a
#GApplication::command-line signal is emitted. Otherwise, the
remaining commandline arguments are assumed to be a list of files.
If there are no files listed, the application is activated via the
#GApplication::activate signal. If there are one or more files, and
%G_APPLICATION_HANDLES_OPEN was specified then the files are opened
via the #GApplication::open signal.

If you are interested in doing more complicated local handling of the
commandline then you should implement your own #GApplication subclass
and override local_command_line(). In this case, you most likely want
to return true from your local_command_line() implementation to
suppress the default handling. See
[gapplication-example-cmdline2.c][https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-cmdline2.c]
for an example.

If, after the above is done, the use count of the application is zero
then the exit status is returned immediately. If the use count is
non-zero then the default main context is iterated until the use count
falls to zero, at which point 0 is returned.

If the %G_APPLICATION_IS_SERVICE flag is set, then the service will
run for as much as 10 seconds with a use count of zero while waiting
for the message that caused the activation to arrive. After that,
if the use count falls to zero the application will exit immediately,
except in the case that g_application_set_inactivity_timeout() is in
use.

This function sets the prgname (g_set_prgname()), if not already set,
to the basename of argv[0].

Much like g_main_loop_run(), this function will acquire the main context
for the duration that the application is running.

Since 2.40, applications that are not explicitly flagged as services
or launchers (ie: neither %G_APPLICATION_IS_SERVICE or
%G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the
default handler for local_command_line) if "--gapplication-service"
was given in the command line. If this flag is present then normal
commandline processing is interrupted and the
%G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise"
solution whereby running an application directly from the commandline
will invoke it in the normal way (which can be useful for debugging)
while still allowing applications to be D-Bus activated in service
mode. The D-Bus service file should invoke the executable with
"--gapplication-service" as the sole commandline argument. This
approach is suitable for use by most graphical applications but
should not be used from applications like editors that need precise
control over when processes invoked via the commandline will exit and
what their exit status will be.

Parameters:

  • argc (Integer)

    the argc from main() (or 0 if argv is nil)

  • argv (Array<Gio::filename>)

    the argv from main(), or nil

Returns:

  • (Integer)

    the exit status

#send_notification(id, notification) ⇒ nil

Sends a notification on behalf of application to the desktop shell.
There is no guarantee that the notification is displayed immediately,
or even at all.

Notifications may persist after the application exits. It will be
D-Bus-activated when the notification or one of its actions is
activated.

Modifying notification after this call has no effect. However, the
object can be reused for a later call to this function.

id may be any string that uniquely identifies the event for the
application. It does not need to be in any special format. For
example, "new-message" might be appropriate for a notification about
new messages.

If a previous notification was sent with the same id, it will be
replaced with notification and shown again as if it was a new
notification. This works even for notifications sent from a previous
execution of the application, as long as id is the same string.

id may be nil, but it is impossible to replace or withdraw
notifications without an id.

If notification is no longer relevant, it can be withdrawn with
g_application_withdraw_notification().

It is an error to call this function if application has no
application ID.

Parameters:

  • id (String)

    id of the notification, or nil

  • notification (Gio::Notification)

    the #GNotification to send

Returns:

  • (nil)

#set_defaultnil

Sets or unsets the default application for the process, as returned
by g_application_get_default().

This function does not take its own reference on application. If
application is destroyed then the default application will revert
back to nil.

Returns:

  • (nil)

#unbind_busy_property(object, property) ⇒ nil

Destroys a binding between property and the busy state of
application that was previously created with
g_application_bind_busy_property().

Parameters:

  • object (GObject::Object)

    a #GObject

  • property (String)

    the name of a boolean property of object

Returns:

  • (nil)

#unmark_busynil

Decreases the busy count of application.

When the busy count reaches zero, the new state will be propagated
to other processes.

This function must only be called to cancel the effect of a previous
call to g_application_mark_busy().

Returns:

  • (nil)

#versionString

The human-readable version number of the application.

Returns:

  • (String)

    version

#version=(version) ⇒ String

The human-readable version number of the application.

Parameters:

  • version (String)

Returns:

  • (String)

    version

  • (String)

    version

#withdraw_notification(id) ⇒ nil

Withdraws a notification that was sent with
g_application_send_notification().

This call does nothing if a notification with id doesn't exist or
the notification was never sent.

This function works even for notifications sent in previous
executions of this application, as long id is the same as it was for
the sent notification.

Note that notifications are dismissed when the user clicks on one
of the buttons in a notification or triggers its default action, so
there is no need to explicitly withdraw the notification in that case.

Parameters:

  • id (String)

    id of a previously sent notification

Returns:

  • (nil)