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.
First, the local_command_line() virtual function is invoked.
This function always runs on the local instance. It gets passed a pointer
to a NULL-terminated copy of argv and is expected to remove the arguments
that it handled (shifting up remaining arguments). See
Example 23, “Split commandline handling” for an example of
parsing argv manually. Alternatively, you may use the GOptionContext API,
after setting argc = g_strv_length (argv);.
The last argument to local_command_line() is a pointer to the status
variable which can used to set the exit status that is returned from
g_application_run().
If local_command_line() returns TRUE, the command line is expected
to be completely handled, including possibly registering as the primary
instance, calling g_application_activate() or g_application_open(), etc.
If local_command_line() returns FALSE then the application is registered
and the "command-line" signal is emitted in the primary
instance (which may or may not be this instance). The signal handler
gets passed a GApplicationCommandLine object that (among other things)
contains the remaining commandline arguments that have not been handled
by local_command_line().
If the application has the G_APPLICATION_HANDLES_COMMAND_LINE
flag set then the default implementation of local_command_line()
always returns FALSE immediately, resulting in the commandline
always being handled in the primary instance.
Otherwise, the default implementation of local_command_line() tries
to do a couple of things that are probably reasonable for most
applications. First, g_application_register() is called to attempt
to register the application. If that works, then the command line
arguments are inspected. If no commandline arguments are given, then
g_application_activate() is called. If commandline arguments are
given and the G_APPLICATION_HANDLES_OPEN flag is set then they
are assumed to be filenames and g_application_open() is called.
If you need to handle commandline arguments that are not filenames,
and you don't mind commandline handling to happen in the primary
instance, you should set G_APPLICATION_HANDLES_COMMAND_LINE and
process the commandline arguments in your "command-line"
signal handler, either manually or using the GOptionContext API.
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
Example 23, “Split commandline handling” 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]. Since 2.38, if G_APPLICATION_IS_SERVICE
is specified, the prgname is set to the application ID. The main
impact of this is is that the wmclass of windows created by Gtk+ will
be set accordingly, which helps the window manager determine which
application is showing the window.
Since 2.28
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. First, the local_command_line() virtual function is invoked. This function always runs on the local instance. It gets passed a pointer to a NULL-terminated copy of argv and is expected to remove the arguments that it handled (shifting up remaining arguments). See Example 23, “Split commandline handling” for an example of parsing argv manually. Alternatively, you may use the GOptionContext API, after setting argc = g_strv_length (argv);. The last argument to local_command_line() is a pointer to the status variable which can used to set the exit status that is returned from g_application_run(). If local_command_line() returns TRUE, the command line is expected to be completely handled, including possibly registering as the primary instance, calling g_application_activate() or g_application_open(), etc. If local_command_line() returns FALSE then the application is registered and the "command-line" signal is emitted in the primary instance (which may or may not be this instance). The signal handler gets passed a GApplicationCommandLine object that (among other things) contains the remaining commandline arguments that have not been handled by local_command_line(). If the application has the G_APPLICATION_HANDLES_COMMAND_LINE flag set then the default implementation of local_command_line() always returns FALSE immediately, resulting in the commandline always being handled in the primary instance. Otherwise, the default implementation of local_command_line() tries to do a couple of things that are probably reasonable for most applications. First, g_application_register() is called to attempt to register the application. If that works, then the command line arguments are inspected. If no commandline arguments are given, then g_application_activate() is called. If commandline arguments are given and the G_APPLICATION_HANDLES_OPEN flag is set then they are assumed to be filenames and g_application_open() is called. If you need to handle commandline arguments that are not filenames, and you don't mind commandline handling to happen in the primary instance, you should set G_APPLICATION_HANDLES_COMMAND_LINE and process the commandline arguments in your "command-line" signal handler, either manually or using the GOptionContext API. 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 Example 23, “Split commandline handling” 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]. Since 2.38, if G_APPLICATION_IS_SERVICE is specified, the prgname is set to the application ID. The main impact of this is is that the wmclass of windows created by Gtk+ will be set accordingly, which helps the window manager determine which application is showing the window. Since 2.28