[glib] Add debug output to GApplication actions example
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add debug output to GApplication actions example
- Date: Wed, 18 May 2011 20:12:29 +0000 (UTC)
commit 0e10116b3b2c26a30722317ebf4347f1c2d964a9
Author: Ryan Lortie <desrt desrt ca>
Date: Wed May 18 16:12:04 2011 -0400
Add debug output to GApplication actions example
Enough to clearly demonstrate bug #650236.
gio/tests/gapplication-example-actions.c | 43 ++++++++++++++++++++++++++++-
1 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/gapplication-example-actions.c b/gio/tests/gapplication-example-actions.c
index 0b8be94..a8b1677 100644
--- a/gio/tests/gapplication-example-actions.c
+++ b/gio/tests/gapplication-example-actions.c
@@ -5,7 +5,9 @@
static void
activate (GApplication *application)
{
+ g_application_hold (application);
g_print ("activated\n");
+ g_application_release (application);
}
static void
@@ -13,7 +15,11 @@ activate_action (GAction *action,
GVariant *parameter,
gpointer data)
{
+ GApplication *application = G_APPLICATION (data);
+
+ g_application_hold (application);
g_print ("action %s activated\n", g_action_get_name (action));
+ g_application_release (application);
}
static void
@@ -21,16 +27,19 @@ activate_toggle_action (GAction *action,
GVariant *parameter,
gpointer data)
{
+ GApplication *application = G_APPLICATION (data);
GVariant *state;
gboolean b;
g_print ("action %s activated\n", g_action_get_name (action));
+ g_application_hold (application);
state = g_action_get_state (action);
b = g_variant_get_boolean (state);
g_variant_unref (state);
g_action_set_state (action, g_variant_new_boolean (!b));
g_print ("state change %d -> %d\n", b, !b);
+ g_application_release (application);
}
static void
@@ -56,6 +65,36 @@ add_actions (GApplication *app)
g_object_unref (actions);
}
+static void
+describe_and_activate_action (GActionGroup *group,
+ const gchar *name)
+{
+ const GVariantType *param_type;
+ GVariant *state;
+ gboolean enabled;
+ gchar *tmp;
+
+ param_type = g_action_group_get_action_parameter_type (group, name);
+ state = g_action_group_get_action_state (group, name);
+ enabled = g_action_group_get_action_enabled (group, name);
+
+ g_print ("action name: %s\n", name);
+ tmp = param_type ? g_variant_type_dup_string (param_type) : NULL;
+ g_print ("parameter type: %s\n", tmp ? tmp : "<none>");
+ g_free (tmp);
+ g_print ("state type: %s\n",
+ state ? g_variant_get_type_string (state) : "<none>");
+ tmp = state ? g_variant_print (state, FALSE) : NULL;
+ g_print ("state: %s\n", tmp ? tmp : "<none>");
+ g_free (tmp);
+ g_print ("enabled: %s\n", enabled ? "true" : "false");
+
+ if (state != NULL)
+ g_variant_unref (state);
+
+ g_action_group_activate_action (group, name, NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -71,13 +110,13 @@ main (int argc, char **argv)
if (argc > 1 && strcmp (argv[1], "--simple-action") == 0)
{
g_application_register (app, NULL, NULL);
- g_action_group_activate_action (G_ACTION_GROUP (app), "simple-action", NULL);
+ describe_and_activate_action (G_ACTION_GROUP (app), "simple-action");
exit (0);
}
else if (argc > 1 && strcmp (argv[1], "--toggle-action") == 0)
{
g_application_register (app, NULL, NULL);
- g_action_group_activate_action (G_ACTION_GROUP (app), "toggle-action", NULL);
+ describe_and_activate_action (G_ACTION_GROUP (app), "toggle-action");
exit (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]