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 | argv = g_application_command_line_get_arguments (cmdline, argc: &argc); |
14 | |
15 | g_application_command_line_print (cmdline, |
16 | format: "This text is written back\n" |
17 | "to stdout of the caller\n" ); |
18 | |
19 | for (i = 0; i < argc; i++) |
20 | g_print (format: "argument %d: %s\n" , i, argv[i]); |
21 | |
22 | g_strfreev (str_array: argv); |
23 | |
24 | return 0; |
25 | } |
26 | |
27 | int |
28 | main (int argc, char **argv) |
29 | { |
30 | GApplication *app; |
31 | int status; |
32 | |
33 | app = g_application_new (application_id: "org.gtk.TestApplication" , |
34 | flags: G_APPLICATION_HANDLES_COMMAND_LINE); |
35 | g_signal_connect (app, "command-line" , G_CALLBACK (command_line), NULL); |
36 | g_application_set_inactivity_timeout (application: app, inactivity_timeout: 10000); |
37 | |
38 | status = g_application_run (application: app, argc, argv); |
39 | |
40 | g_object_unref (object: app); |
41 | |
42 | return status; |
43 | } |
44 | |