Add some more cases to the app-id unit tests
[glib.git] / gio / tests / gapplication-example-cmdline2.c
blobdc25e9540ef3f3f007b3aeab72e77ff65e5a5b0e
1 #include <gio/gio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 static int
6 command_line (GApplication *application,
7 GApplicationCommandLine *cmdline)
9 gchar **argv;
10 gint argc;
11 gint i;
13 argv = g_application_command_line_get_arguments (cmdline, &argc);
15 for (i = 0; i < argc; i++)
16 g_print ("handling argument %s remotely\n", argv[i]);
18 g_strfreev (argv);
20 return 0;
23 static gboolean
24 test_local_cmdline (GApplication *application,
25 gchar ***arguments,
26 gint *exit_status)
28 gint i, j;
29 gchar **argv;
31 argv = *arguments;
33 i = 1;
34 while (argv[i])
36 if (g_str_has_prefix (argv[i], "--local-"))
38 g_print ("handling argument %s locally\n", argv[i]);
39 g_free (argv[i]);
40 for (j = i; argv[j]; j++)
41 argv[j] = argv[j + 1];
43 else
45 g_print ("not handling argument %s locally\n", argv[i]);
46 i++;
50 *exit_status = 0;
52 return FALSE;
55 typedef GApplication TestApplication;
56 typedef GApplicationClass TestApplicationClass;
58 static GType test_application_get_type (void);
59 G_DEFINE_TYPE (TestApplication, test_application, G_TYPE_APPLICATION)
61 static void
62 test_application_finalize (GObject *object)
64 G_OBJECT_CLASS (test_application_parent_class)->finalize (object);
67 static void
68 test_application_init (TestApplication *app)
72 static void
73 test_application_class_init (TestApplicationClass *class)
75 G_OBJECT_CLASS (class)->finalize = test_application_finalize;
76 G_APPLICATION_CLASS (class)->local_command_line = test_local_cmdline;
79 static GApplication *
80 test_application_new (const gchar *application_id,
81 GApplicationFlags flags)
83 g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
85 return g_object_new (test_application_get_type (),
86 "application-id", application_id,
87 "flags", flags,
88 NULL);
91 int
92 main (int argc, char **argv)
94 GApplication *app;
95 int status;
97 app = test_application_new ("org.gtk.TestApplication", 0);
98 g_application_set_inactivity_timeout (app, 10000);
99 g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
101 status = g_application_run (app, argc, argv);
103 g_object_unref (app);
105 return status;