Don't use deprecated GApplication api in examples
[platform/upstream/glib.git] / gio / tests / gapplication-example-menu.c
1 #include <gio/gio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 static void
6 activate (GApplication *application)
7 {
8   g_application_hold (application);
9   g_print ("activated\n");
10   g_application_release (application);
11 }
12
13 static void
14 show_help (GSimpleAction *action,
15            GVariant      *parameter,
16            gpointer       data)
17 {
18   g_print ("Want help, eh ?!\n");
19 }
20
21 static void
22 show_about (GSimpleAction *action,
23             GVariant      *parameter,
24             gpointer       user_data)
25 {
26   g_print ("Not much to say, really.\nJust a stupid example\n");
27 }
28
29 static void
30 quit_app (GSimpleAction *action,
31           GVariant      *parameter,
32           gpointer       user_data)
33 {
34   g_print ("Quitting...\n");
35   g_application_release (g_application_get_default ());
36 }
37
38 static GActionEntry entries[] = {
39   { "help",  show_help,  NULL, NULL, NULL },
40   { "about", show_about, NULL, NULL, NULL },
41   { "quit",  quit_app,   NULL, NULL, NULL }
42 };
43
44 static void
45 add_actions (GApplication *app)
46 {
47   g_action_map_add_action_entries (G_ACTION_MAP (app),
48                                    entries, G_N_ELEMENTS (entries),
49                                    NULL);
50 }
51
52 static void
53 add_menu (GApplication *app)
54 {
55   GMenu *menu;
56
57   menu = g_menu_new ();
58
59   g_menu_append (menu, "Help", "help");
60   g_menu_append (menu, "About Example", "about");
61   g_menu_append (menu, "Quit", "quit");
62
63   g_application_set_app_menu (app, G_MENU_MODEL (menu));
64
65   g_object_unref (menu);
66 }
67
68 int
69 main (int argc, char **argv)
70 {
71   GApplication *app;
72   int status;
73
74   app = g_application_new ("org.gtk.TestApplication", 0);
75   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
76
77   add_actions (app);
78   add_menu (app);
79
80   g_application_hold (app);
81
82   status = g_application_run (app, argc, argv);
83
84   g_object_unref (app);
85
86   return status;
87 }