Add some examples to the GApplication docs
[platform/upstream/glib.git] / gio / tests / gapplication-example-cmdline.c
1 #include <gio/gio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 static int
6 command_line (GApplication            *application,
7               GApplicationCommandLine *cmdline)
8 {
9   gchar **argv;
10   gint argc;
11   gint i;
12
13   g_application_hold (application);
14
15   argv = g_application_command_line_get_arguments (cmdline, &argc);
16
17   g_application_command_line_print (cmdline,
18                                     "This text is written back\n"
19                                     "to stdout of the caller\n");
20
21   for (i = 0; i < argc; i++)
22     g_print ("argument %d: %s\n", i, argv[i]);
23
24   g_strfreev (argv);
25
26   g_application_release (application);
27
28   return 0;
29 }
30
31 int
32 main (int argc, char **argv)
33 {
34   GApplication *app;
35   int status;
36
37   app = g_application_new ("org.gtk.TestApplication",
38                            G_APPLICATION_HANDLES_COMMAND_LINE);
39   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
40   g_application_set_inactivity_timeout (app, 10000);
41
42   status = g_application_run (app, argc, argv);
43
44   g_object_unref (app);
45
46   return status;
47 }