Package ch.bailu.gtk.gio
Class Application
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.Application
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
Application
A #GApplication 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
#GtkApplication or #MxApplication. In general, you should not use
this class outside of a higher level framework.
GApplication provides convenient life cycle management by maintaining
a "use count" for the primary application instance. The use count can
be changed using g_application_hold() and g_application_release(). If
it drops to zero, the application exits. Higher-level classes such as
#GtkApplication employ the use count to ensure that the application
stays alive as long as it has any opened windows.
Another feature that GApplication (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
always the current instance. On Linux, the D-Bus session bus
is used for communication.
The use of #GApplication 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 main() function of a
#GApplication should do very little more than instantiating the
application instance, possibly connecting signal handlers, then
calling g_application_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 g_application_run() promptly returns. See the code
examples below.
If used, the expected form of an application identifier is the same as
that of of a
[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 g_application_id_is_valid().
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 #GApplication
attempts to acquire the bus name of your application (which happens in
g_application_register()). Unfortunately, this means that you cannot use
g_application_get_is_remote() to decide if you want to register object paths.
GApplication also implements the #GActionGroup and #GActionMap
interfaces and lets you easily export actions by adding them with
g_action_map_add_action(). When invoking an action by calling
g_action_group_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 #GDBusActionGroup wrapper to
conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper
for remote access to exported #GMenuModels.
There is a number of different entry points into a GApplication:
- via 'Activate' (i.e. just starting the application)
- via 'Open' (i.e. opening some files)
- by handling a command-line
- via activating an action
The #GApplication::startup signal lets you handle the application
initialization for all of these in a single place.
Regardless of which of these entry points is used to start the
application, GApplication passes some ‘platform data’ from the
launching instance to the primary instance, in the form of a
#GVariant dictionary mapping strings to variants. To use platform
data, override the @before_emit or @after_emit virtual functions
in your #GApplication subclass. When dealing with
#GApplicationCommandLine objects, the platform data is
directly available via g_application_command_line_get_cwd(),
g_application_command_line_get_environ() and
g_application_command_line_get_platform_data().
As the name indicates, the platform data may vary depending on the
operating system, but it always includes the current directory (key
"cwd"), and optionally the environment (ie the set of environment
variables and their values) of the calling process (key "environ").
The environment is only added to the platform data if the
%G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses
can add their own platform data by overriding the @add_platform_data
virtual function. For instance, #GtkApplication adds startup notification
data in this way.
To parse commandline arguments you may handle the
#GApplication::command-line signal or override the local_command_line()
vfunc, to parse them in either the primary instance or the local instance,
respectively.
For an example of opening files with a GApplication, see
[gapplication-example-open.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-open.c).
For an example of using actions with GApplication, see
[gapplication-example-actions.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-actions.c).
For an example of using extra D-Bus hooks with GApplication, see
[gapplication-example-dbushooks.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-dbushooks.c).
low-level platform-specific services and is intended to act as the
foundation for higher-level application classes such as
#GtkApplication or #MxApplication. In general, you should not use
this class outside of a higher level framework.
GApplication provides convenient life cycle management by maintaining
a "use count" for the primary application instance. The use count can
be changed using g_application_hold() and g_application_release(). If
it drops to zero, the application exits. Higher-level classes such as
#GtkApplication employ the use count to ensure that the application
stays alive as long as it has any opened windows.
Another feature that GApplication (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
always the current instance. On Linux, the D-Bus session bus
is used for communication.
The use of #GApplication 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 main() function of a
#GApplication should do very little more than instantiating the
application instance, possibly connecting signal handlers, then
calling g_application_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 g_application_run() promptly returns. See the code
examples below.
If used, the expected form of an application identifier is the same as
that of of a
[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 g_application_id_is_valid().
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 #GApplication
attempts to acquire the bus name of your application (which happens in
g_application_register()). Unfortunately, this means that you cannot use
g_application_get_is_remote() to decide if you want to register object paths.
GApplication also implements the #GActionGroup and #GActionMap
interfaces and lets you easily export actions by adding them with
g_action_map_add_action(). When invoking an action by calling
g_action_group_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 #GDBusActionGroup wrapper to
conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper
for remote access to exported #GMenuModels.
There is a number of different entry points into a GApplication:
- via 'Activate' (i.e. just starting the application)
- via 'Open' (i.e. opening some files)
- by handling a command-line
- via activating an action
The #GApplication::startup signal lets you handle the application
initialization for all of these in a single place.
Regardless of which of these entry points is used to start the
application, GApplication passes some ‘platform data’ from the
launching instance to the primary instance, in the form of a
#GVariant dictionary mapping strings to variants. To use platform
data, override the @before_emit or @after_emit virtual functions
in your #GApplication subclass. When dealing with
#GApplicationCommandLine objects, the platform data is
directly available via g_application_command_line_get_cwd(),
g_application_command_line_get_environ() and
g_application_command_line_get_platform_data().
As the name indicates, the platform data may vary depending on the
operating system, but it always includes the current directory (key
"cwd"), and optionally the environment (ie the set of environment
variables and their values) of the calling process (key "environ").
The environment is only added to the platform data if the
%G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses
can add their own platform data by overriding the @add_platform_data
virtual function. For instance, #GtkApplication adds startup notification
data in this way.
To parse commandline arguments you may handle the
#GApplication::command-line signal or override the local_command_line()
vfunc, to parse them in either the primary instance or the local instance,
respectively.
For an example of opening files with a GApplication, see
[gapplication-example-open.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-open.c).
For an example of using actions with GApplication, see
[gapplication-example-actions.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-actions.c).
For an example of using extra D-Bus hooks with GApplication, see
[gapplication-example-dbushooks.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-dbushooks.c).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionApplication
(PointerContainer pointer) Application
(Str application_id, int flags) Creates a new #GApplication instance.Application
(String application_id, int flags) Creates a new #GApplication instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activates the application.void
addOptionGroup
(OptionGroup group) Adds a #GOptionGroup to the commandline handling of @application.Implements interfaceActionGroup
.Implements interfaceActionMap
.void
bindBusyProperty
(Pointer object, Str property) Marks @application as busy (see g_application_mark_busy()) while
@property on @object is %TRUE.void
bindBusyProperty
(Pointer object, String property) Marks @application as busy (see g_application_mark_busy()) while
@property on @object is %TRUE.Gets the unique identifier for @application.static ClassHandler
Gets the #GDBusConnection being used by the application, or %NULL.Gets the D-Bus object path being used by the application, or %NULL.static Application
Returns the default #GApplication instance for this process.int
getFlags()
Gets the flags for @application.int
Gets the current inactivity timeout for the application.static int
boolean
Gets the application's current busy state, as set through
g_application_mark_busy() or g_application_bind_busy_property().boolean
Checks if @application is registered.boolean
Checks if @application is remote.static long
static TypeSystem.TypeSize
Gets the resource base path of @application.static long
static TypeSystem.TypeSize
void
hold()
Increases the use count of @application.static boolean
Checks if @application_id is a valid application identifier.void
markBusy()
Increases the busy count of @application.onActivate
(Application.OnActivate signal) Connect to signal "activate".Connect to signal "command-line".Connect to signal "handle-local-options".onNameLost
(Application.OnNameLost signal) Connect to signal "name-lost".onOpen
(Application.OnOpen signal) Connect to signal "open".onShutdown
(Application.OnShutdown signal) Connect to signal "shutdown".onStartup
(Application.OnStartup signal) Connect to signal "startup".void
quit()
Immediately quits the application.boolean
register
(Cancellable cancellable) Attempts registration of the application.void
release()
Decrease the use count of @application.int
Runs the application.void
sendNotification
(Str id, Notification notification) Sends a notification on behalf of @application to the desktop shell.void
sendNotification
(String id, Notification notification) Sends a notification on behalf of @application to the desktop shell.void
setApplicationId
(Str application_id) Sets the unique identifier for @application.void
setApplicationId
(String application_id) Sets the unique identifier for @application.void
Sets or unsets the default application for the process, as returned
by g_application_get_default().void
setFlags
(int flags) Sets the flags for @application.void
setInactivityTimeout
(int inactivity_timeout) Sets the current inactivity timeout for the application.void
setOptionContextDescription
(Str description) Adds a description to the @application option context.void
setOptionContextDescription
(String description) Adds a description to the @application option context.void
setOptionContextParameterString
(Str parameter_string) Sets the parameter string to be used by the commandline handling of @application.void
setOptionContextParameterString
(String parameter_string) Sets the parameter string to be used by the commandline handling of @application.void
setOptionContextSummary
(Str summary) Adds a summary to the @application option context.void
setOptionContextSummary
(String summary) Adds a summary to the @application option context.void
setResourceBasePath
(Str resource_path) Sets (or unsets) the base resource path of @application.void
setResourceBasePath
(String resource_path) Sets (or unsets) the base resource path of @application.void
unbindBusyProperty
(Pointer object, Str property) Destroys a binding between @property and the busy state of
@application that was previously created with
g_application_bind_busy_property().void
unbindBusyProperty
(Pointer object, String property) Destroys a binding between @property and the busy state of
@application that was previously created with
g_application_bind_busy_property().void
Decreases the busy count of @application.void
Withdraws a notification that was sent with
g_application_send_notification().void
Withdraws a notification that was sent with
g_application_send_notification().Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE
- See Also:
-
SIGNAL_ON_COMMAND_LINE
- See Also:
-
SIGNAL_ON_HANDLE_LOCAL_OPTIONS
- See Also:
-
SIGNAL_ON_NAME_LOST
- See Also:
-
SIGNAL_ON_OPEN
- See Also:
-
SIGNAL_ON_SHUTDOWN
- See Also:
-
SIGNAL_ON_STARTUP
- See Also:
-
-
Constructor Details
-
Application
-
Application
Creates a new #GApplication instance.
If non-%NULL, 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:
application_id
- the application idflags
- the application flags
-
Application
Creates a new #GApplication instance.
If non-%NULL, 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:
application_id
- the application idflags
- the application flags
-
-
Method Details
-
getClassHandler
-
activate
public void activate()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. -
addOptionGroup
Adds a #GOptionGroup 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 %NULL @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 #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
%G_APPLICATION_HANDLES_COMMAND_LINE was given.- Parameters:
group
- a #GOptionGroup
-
bindBusyProperty
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
- a #GObjectproperty
- the name of a boolean property of @object
-
bindBusyProperty
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
- a #GObjectproperty
- the name of a boolean property of @object
-
getApplicationId
Gets the unique identifier for @application.- Returns:
- the identifier for @application, owned by @application
-
getDbusConnection
Gets the #GDBusConnection being used by the application, or %NULL.
If #GApplication is using its D-Bus backend then this function will
return the #GDBusConnection 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
%NULL. 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:
- a #GDBusConnection, or %NULL
-
getDbusObjectPath
Gets the D-Bus object path being used by the application, or %NULL.
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
%NULL. 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:
- the object path, or %NULL
-
getFlags
public int getFlags()Gets the flags for @application.
See #GApplicationFlags.- Returns:
- the flags for @application
-
getInactivityTimeout
public int getInactivityTimeout()Gets the current inactivity timeout for the application.
This is the amount of time (in milliseconds) after the last call to
g_application_release() before the application stops running.- Returns:
- the timeout, in milliseconds
-
getIsBusy
public boolean getIsBusy()Gets the application's current busy state, as set through
g_application_mark_busy() or g_application_bind_busy_property().- Returns:
- %TRUE if @application is currently marked as busy
-
getIsRegistered
public boolean getIsRegistered()Checks if @application is registered.
An application is registered if g_application_register() has been
successfully called.- Returns:
- %TRUE if @application is registered
-
getIsRemote
public boolean getIsRemote()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:
- %TRUE if @application is remote
-
getResourceBasePath
Gets the resource base path of @application.
See g_application_set_resource_base_path() for more information.- Returns:
- the base resource path, if one is set
-
hold
public void hold()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(). -
markBusy
public void markBusy()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. -
quit
public void quit()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. -
register
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:
cancellable
- a #GCancellable, or %NULL- Returns:
- %TRUE if registration succeeded
- Throws:
AllocationError
-
release
public void release()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(). -
run
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 %NULL 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 #GOptionEntrys.
#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
- the argc from main() (or 0 if @argv is %NULL)argv
- the argv from main(), or %NULL- Returns:
- the exit status
-
sendNotification
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 %NULL, 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().- Parameters:
id
- id of the notification, or %NULLnotification
- the #GNotification to send
-
sendNotification
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 %NULL, 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().- Parameters:
id
- id of the notification, or %NULLnotification
- the #GNotification to send
-
setApplicationId
Sets the unique identifier for @application.
The application id can only be modified if @application has not yet
been registered.
If non-%NULL, the application id must be valid. See
g_application_id_is_valid().- Parameters:
application_id
- the identifier for @application
-
setApplicationId
Sets the unique identifier for @application.
The application id can only be modified if @application has not yet
been registered.
If non-%NULL, the application id must be valid. See
g_application_id_is_valid().- Parameters:
application_id
- the identifier for @application
-
setDefault
public void setDefault()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 %NULL. -
setFlags
public void setFlags(int flags) Sets the flags for @application.
The flags can only be modified if @application has not yet been
registered.
See #GApplicationFlags.- Parameters:
flags
- the flags for @application
-
setInactivityTimeout
public void setInactivityTimeout(int inactivity_timeout) Sets the current inactivity timeout for the application.
This is the amount of time (in milliseconds) after the last call to
g_application_release() before the application stops running.
This call has no side effects of its own. The value set here is only
used for next time g_application_release() drops the use count to
zero. Any timeouts currently in progress are not impacted.- Parameters:
inactivity_timeout
- the timeout, in milliseconds
-
setOptionContextDescription
Adds a description to the @application option context.
See g_option_context_set_description() for more information.- Parameters:
description
- a string to be shown in `--help` output after the list of options, or %NULL
-
setOptionContextDescription
Adds a description to the @application option context.
See g_option_context_set_description() for more information.- Parameters:
description
- a string to be shown in `--help` output after the list of options, or %NULL
-
setOptionContextParameterString
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 #GOptionContext of @application is created.
See g_option_context_new() for more information about @parameter_string.- Parameters:
parameter_string
- a string which is displayed in the first line of `--help` output, after the usage summary `programname [OPTION...]`.
-
setOptionContextParameterString
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 #GOptionContext of @application is created.
See g_option_context_new() for more information about @parameter_string.- Parameters:
parameter_string
- a string which is displayed in the first line of `--help` output, after the usage summary `programname [OPTION...]`.
-
setOptionContextSummary
Adds a summary to the @application option context.
See g_option_context_set_summary() for more information.- Parameters:
summary
- a string to be shown in `--help` output before the list of options, or %NULL
-
setOptionContextSummary
Adds a summary to the @application option context.
See g_option_context_set_summary() for more information.- Parameters:
summary
- a string to be shown in `--help` output before the list of options, or %NULL
-
setResourceBasePath
Sets (or unsets) the base resource path of @application.
The path is used to automatically load various [application
resources][gresource] such as menu layouts and action descriptions.
The various types of resources will be found at fixed names relative
to the given base path.
By default, the resource base path is determined from the application
ID by prefixing '/' and replacing each '.' with '/'. This is done at
the time that the #GApplication object is constructed. Changes to
the application ID after that point will not have an impact on the
resource base path.
As an example, if the application has an ID of "org.example.app" then
the default resource base path will be "/org/example/app". If this
is a #GtkApplication (and you have not manually changed the path)
then Gtk will then search for the menus of the application at
"/org/example/app/gtk/menus.ui".
See #GResource for more information about adding resources to your
application.
You can disable automatic resource loading functionality by setting
the path to %NULL.
Changing the resource base path once the application is running is
not recommended. The point at which the resource path is consulted
for forming paths for various purposes is unspecified. When writing
a sub-class of #GApplication you should either set the
#GApplication:resource-base-path property at construction time, or call
this function during the instance initialization. Alternatively, you
can call this function in the #GApplicationClass.startup virtual function,
before chaining up to the parent implementation.- Parameters:
resource_path
- the resource path to use
-
setResourceBasePath
Sets (or unsets) the base resource path of @application.
The path is used to automatically load various [application
resources][gresource] such as menu layouts and action descriptions.
The various types of resources will be found at fixed names relative
to the given base path.
By default, the resource base path is determined from the application
ID by prefixing '/' and replacing each '.' with '/'. This is done at
the time that the #GApplication object is constructed. Changes to
the application ID after that point will not have an impact on the
resource base path.
As an example, if the application has an ID of "org.example.app" then
the default resource base path will be "/org/example/app". If this
is a #GtkApplication (and you have not manually changed the path)
then Gtk will then search for the menus of the application at
"/org/example/app/gtk/menus.ui".
See #GResource for more information about adding resources to your
application.
You can disable automatic resource loading functionality by setting
the path to %NULL.
Changing the resource base path once the application is running is
not recommended. The point at which the resource path is consulted
for forming paths for various purposes is unspecified. When writing
a sub-class of #GApplication you should either set the
#GApplication:resource-base-path property at construction time, or call
this function during the instance initialization. Alternatively, you
can call this function in the #GApplicationClass.startup virtual function,
before chaining up to the parent implementation.- Parameters:
resource_path
- the resource path to use
-
unbindBusyProperty
Destroys a binding between @property and the busy state of
@application that was previously created with
g_application_bind_busy_property().- Parameters:
object
- a #GObjectproperty
- the name of a boolean property of @object
-
unbindBusyProperty
Destroys a binding between @property and the busy state of
@application that was previously created with
g_application_bind_busy_property().- Parameters:
object
- a #GObjectproperty
- the name of a boolean property of @object
-
unmarkBusy
public void unmarkBusy()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(). -
withdrawNotification
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
- id of a previously sent notification
-
withdrawNotification
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
- id of a previously sent notification
-
onActivate
Connect to signal "activate".
SeeApplication.OnActivate.onActivate()
for signal description.
FieldSIGNAL_ON_ACTIVATE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onCommandLine
Connect to signal "command-line".
SeeApplication.OnCommandLine.onCommandLine(ch.bailu.gtk.gio.ApplicationCommandLine)
for signal description.
FieldSIGNAL_ON_COMMAND_LINE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onHandleLocalOptions
Connect to signal "handle-local-options".
SeeApplication.OnHandleLocalOptions.onHandleLocalOptions(ch.bailu.gtk.glib.VariantDict)
for signal description.
FieldSIGNAL_ON_HANDLE_LOCAL_OPTIONS
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onNameLost
Connect to signal "name-lost".
SeeApplication.OnNameLost.onNameLost()
for signal description.
FieldSIGNAL_ON_NAME_LOST
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onOpen
Connect to signal "open".
SeeApplication.OnOpen.onOpen(ch.bailu.gtk.type.Pointer, int, ch.bailu.gtk.type.Str)
for signal description.
FieldSIGNAL_ON_OPEN
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onShutdown
Connect to signal "shutdown".
SeeApplication.OnShutdown.onShutdown()
for signal description.
FieldSIGNAL_ON_SHUTDOWN
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onStartup
Connect to signal "startup".
SeeApplication.OnStartup.onStartup()
for signal description.
FieldSIGNAL_ON_STARTUP
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getDefault
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 %NULL is returned.- Returns:
- the default application for this process, or %NULL
-
idIsValid
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](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus).
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](http://docs.flatpak.org/en/latest/introduction.html#identifiers),
the
[`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`.- Parameters:
application_id
- a potential application identifier- Returns:
- %TRUE if @application_id is valid
-
asActionGroup
Implements interfaceActionGroup
. Call this to get access to interface functions.- Returns:
ActionGroup
-
asActionMap
Implements interfaceActionMap
. Call this to get access to interface functions.- Returns:
ActionMap
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-