mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Add some examples to the GApplication docs
This commit is contained in:
parent
79790b9278
commit
499d9ba8b8
@ -70,6 +70,13 @@
|
||||
* <listitem>Application identifiers must not contain consecutive '.' (period) characters.</listitem>
|
||||
* <listitem>Application identifiers must not exceed 255 characters.</listitem>
|
||||
* </itemizedlist>
|
||||
*
|
||||
* GApplication provides convenient life cycle management by maintaining
|
||||
* a <firstterm>use count</firstterm> 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.
|
||||
*
|
||||
* <example id="gapplication-example-open"><title>Opening files with a GApplication</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-open.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
|
||||
*/
|
||||
|
||||
struct _GApplicationPrivate
|
||||
@ -912,7 +919,7 @@ g_application_register (GApplication *application,
|
||||
* 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
|
||||
* 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().
|
||||
|
@ -52,6 +52,8 @@ G_DEFINE_TYPE (GApplicationCommandLine, g_application_command_line, G_TYPE_OBJEC
|
||||
* lifecycle of the originally-invoked process is tied to the lifecycle
|
||||
* of this object (ie: the process exits when the last reference is
|
||||
* dropped).
|
||||
*
|
||||
* <example id="gapplication-example-open"><title>Handling commandline arguments with GApplication</title><programlisting><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-cmdline.c"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include></programlisting></example>
|
||||
**/
|
||||
|
||||
enum
|
||||
|
@ -85,6 +85,8 @@ SAMPLE_PROGS = \
|
||||
gdbus-connection-flush-helper \
|
||||
appinfo-test \
|
||||
proxy \
|
||||
gapplication-example-open \
|
||||
gapplication-example-cmdline \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@ -307,6 +309,12 @@ file_LDADD = $(progs_ldadd)
|
||||
gapplication_SOURCES = gapplication.c gdbus-sessionbus.c
|
||||
gapplication_LDADD = $(progs_ldadd)
|
||||
|
||||
gapplication_example_open_SOURCES = gapplication-example-open.c
|
||||
gapplication_example_open_LDADD = $(progs_ldadd)
|
||||
|
||||
gapplication_example_cmdline_SOURCES = gapplication-example-cmdline.c
|
||||
gapplication_example_cmdline_LDADD = $(progs_ldadd)
|
||||
|
||||
schema_tests = \
|
||||
schema-tests/array-default-not-in-choices.gschema.xml \
|
||||
schema-tests/bad-choice.gschema.xml \
|
||||
|
47
gio/tests/gapplication-example-cmdline.c
Normal file
47
gio/tests/gapplication-example-cmdline.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <gio/gio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
command_line (GApplication *application,
|
||||
GApplicationCommandLine *cmdline)
|
||||
{
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
gint i;
|
||||
|
||||
g_application_hold (application);
|
||||
|
||||
argv = g_application_command_line_get_arguments (cmdline, &argc);
|
||||
|
||||
g_application_command_line_print (cmdline,
|
||||
"This text is written back\n"
|
||||
"to stdout of the caller\n");
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
g_print ("argument %d: %s\n", i, argv[i]);
|
||||
|
||||
g_strfreev (argv);
|
||||
|
||||
g_application_release (application);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GApplication *app;
|
||||
int status;
|
||||
|
||||
app = g_application_new ("org.gtk.TestApplication",
|
||||
G_APPLICATION_HANDLES_COMMAND_LINE);
|
||||
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
|
||||
g_application_set_inactivity_timeout (app, 10000);
|
||||
|
||||
status = g_application_run (app, argc, argv);
|
||||
|
||||
g_object_unref (app);
|
||||
|
||||
return status;
|
||||
}
|
50
gio/tests/gapplication-example-open.c
Normal file
50
gio/tests/gapplication-example-open.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <gio/gio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
activate (GApplication *application)
|
||||
{
|
||||
g_application_hold (application);
|
||||
g_print ("activated\n");
|
||||
g_application_release (application);
|
||||
}
|
||||
|
||||
static void
|
||||
open (GApplication *application,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_application_hold (application);
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
{
|
||||
gchar *uri = g_file_get_uri (files[i]);
|
||||
g_print ("open %s\n", uri);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
g_application_release (application);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GApplication *app;
|
||||
int status;
|
||||
|
||||
app = g_application_new ("org.gtk.TestApplication",
|
||||
G_APPLICATION_HANDLES_OPEN);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
g_signal_connect (app, "open", G_CALLBACK (open), NULL);
|
||||
g_application_set_inactivity_timeout (app, 10000);
|
||||
|
||||
status = g_application_run (app, argc, argv);
|
||||
|
||||
g_object_unref (app);
|
||||
|
||||
return status;
|
||||
}
|
Loading…
Reference in New Issue
Block a user