6 activate (GApplication
*application
)
8 g_application_hold (application
);
9 g_print ("activated\n");
10 g_application_release (application
);
14 activate_action (GAction
*action
,
18 GApplication
*application
= G_APPLICATION (data
);
20 g_application_hold (application
);
21 g_print ("action %s activated\n", g_action_get_name (action
));
22 g_application_release (application
);
26 activate_toggle_action (GSimpleAction
*action
,
30 GApplication
*application
= G_APPLICATION (data
);
34 g_print ("action %s activated\n", g_action_get_name (G_ACTION (action
)));
36 g_application_hold (application
);
37 state
= g_action_get_state (G_ACTION (action
));
38 b
= g_variant_get_boolean (state
);
39 g_variant_unref (state
);
40 g_simple_action_set_state (action
, g_variant_new_boolean (!b
));
41 g_print ("state change %d -> %d\n", b
, !b
);
42 g_application_release (application
);
46 add_actions (GApplication
*app
)
48 GSimpleAction
*action
;
50 action
= g_simple_action_new ("simple-action", NULL
);
51 g_signal_connect (action
, "activate", G_CALLBACK (activate_action
), app
);
52 g_action_map_add_action (G_ACTION_MAP (app
), G_ACTION (action
));
53 g_object_unref (action
);
55 action
= g_simple_action_new_stateful ("toggle-action", NULL
,
56 g_variant_new_boolean (FALSE
));
57 g_signal_connect (action
, "activate", G_CALLBACK (activate_toggle_action
), app
);
58 g_action_map_add_action (G_ACTION_MAP (app
), G_ACTION (action
));
59 g_object_unref (action
);
63 describe_and_activate_action (GActionGroup
*group
,
66 const GVariantType
*param_type
;
71 param_type
= g_action_group_get_action_parameter_type (group
, name
);
72 state
= g_action_group_get_action_state (group
, name
);
73 enabled
= g_action_group_get_action_enabled (group
, name
);
75 g_print ("action name: %s\n", name
);
76 tmp
= param_type
? g_variant_type_dup_string (param_type
) : NULL
;
77 g_print ("parameter type: %s\n", tmp
? tmp
: "<none>");
79 g_print ("state type: %s\n",
80 state
? g_variant_get_type_string (state
) : "<none>");
81 tmp
= state
? g_variant_print (state
, FALSE
) : NULL
;
82 g_print ("state: %s\n", tmp
? tmp
: "<none>");
84 g_print ("enabled: %s\n", enabled
? "true" : "false");
87 g_variant_unref (state
);
89 g_action_group_activate_action (group
, name
, NULL
);
93 main (int argc
, char **argv
)
98 app
= g_application_new ("org.gtk.TestApplication", 0);
99 g_signal_connect (app
, "activate", G_CALLBACK (activate
), NULL
);
100 g_application_set_inactivity_timeout (app
, 10000);
104 if (argc
> 1 && strcmp (argv
[1], "--simple-action") == 0)
106 g_application_register (app
, NULL
, NULL
);
107 describe_and_activate_action (G_ACTION_GROUP (app
), "simple-action");
110 else if (argc
> 1 && strcmp (argv
[1], "--toggle-action") == 0)
112 g_application_register (app
, NULL
, NULL
);
113 describe_and_activate_action (G_ACTION_GROUP (app
), "toggle-action");
117 status
= g_application_run (app
, argc
, argv
);
119 g_object_unref (app
);