1#include <gio/gio.h>
2#include <stdlib.h>
3#include <string.h>
4
5static void
6activate (GApplication *application)
7{
8 g_print (format: "activated\n");
9
10 /* Note: when doing a longer-lasting action here that returns
11 * to the mainloop, you should use g_application_hold() and
12 * g_application_release() to keep the application alive until
13 * the action is completed.
14 */
15}
16
17static void
18open (GApplication *application,
19 GFile **files,
20 gint n_files,
21 const gchar *hint)
22{
23 gint i;
24
25 for (i = 0; i < n_files; i++)
26 {
27 gchar *uri = g_file_get_uri (file: files[i]);
28 g_print (format: "open %s\n", uri);
29 g_free (mem: uri);
30 }
31
32 /* Note: when doing a longer-lasting action here that returns
33 * to the mainloop, you should use g_application_hold() and
34 * g_application_release() to keep the application alive until
35 * the action is completed.
36 */
37}
38
39int
40main (int argc, char **argv)
41{
42 GApplication *app;
43 int status;
44
45 app = g_application_new (application_id: "org.gtk.TestApplication",
46 flags: G_APPLICATION_HANDLES_OPEN);
47 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
48 g_signal_connect (app, "open", G_CALLBACK (open), NULL);
49 g_application_set_inactivity_timeout (application: app, inactivity_timeout: 10000);
50
51 status = g_application_run (application: app, argc, argv);
52
53 g_object_unref (object: app);
54
55 return status;
56}
57

source code of gtk/subprojects/glib/gio/tests/gapplication-example-open.c