g-icon: Fix memory leak in test
[platform/upstream/glib.git] / gio / tests / basic-application.c
1 #include <gio/gio.h>
2 #include <string.h>
3
4 static void
5 activate (GApplication *application)
6 {
7   g_application_hold (application);
8   g_print ("activated\n");
9   g_application_release (application);
10 }
11
12 static void
13 open (GApplication  *application,
14       GFile        **files,
15       gint           n_files,
16       const gchar   *hint)
17 {
18   gint i;
19
20   g_application_hold (application);
21   g_print ("open");
22
23   for (i = 0; i < n_files; i++)
24     {
25       gchar *uri = g_file_get_uri (files[i]);
26       g_print (" %s", uri);
27       g_free (uri);
28     }
29   g_application_release (application);
30
31   g_print ("\n");
32 }
33
34 int
35 main (int argc, char **argv)
36 {
37   GApplication *app;
38   int status;
39
40   app = g_application_new ("org.gtk.TestApplication",
41                            G_APPLICATION_SEND_ENVIRONMENT |
42                            G_APPLICATION_HANDLES_OPEN |
43                            (g_strcmp0 (argv[1], "./cmd") == 0 ?
44                              G_APPLICATION_HANDLES_COMMAND_LINE
45                            : 0));
46   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
47   g_signal_connect (app, "open", G_CALLBACK (open), NULL);
48 #ifdef STANDALONE
49   g_application_set_inactivity_timeout (app, 10000);
50 #else
51   g_application_set_inactivity_timeout (app, 1000);
52 #endif
53   status = g_application_run (app, argc - 1, argv + 1);
54
55   g_object_unref (app);
56
57   g_print ("exit status: %d\n", status);
58
59   return 0;
60 }