From 843fa1f19c2d6c1072ab3479c0969eb0b6b73076 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 8 Aug 2013 16:00:42 -0500 Subject: as discussed with dednick and ted, have a header action state type of a{sv} rather than the obsoleted (sssb) --- src/service.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/service.c b/src/service.c index 74acd89..41dba10 100644 --- a/src/service.c +++ b/src/service.c @@ -143,29 +143,28 @@ rebuild_settings_section_soon (IndicatorSessionService * self) **** ***/ -static void -update_header_action (IndicatorSessionService * self) +static GVariant * +action_state_for_header (IndicatorSessionService * self) { - gchar * a11y; + const priv_t * const p = self->priv; gboolean need_attn; + GIcon * icon; gboolean show_name; - GVariant * variant; const gchar * real_name; const gchar * label; - const gchar * iconstr; - const priv_t * const p = self->priv; - - g_return_if_fail (p->header_action != NULL); + gchar * a11y; + GVariantBuilder b; + GVariant * state; if (indicator_session_actions_has_online_account_error (p->backend_actions)) { need_attn = TRUE; - iconstr = ICON_ALERT; + icon = g_themed_icon_new (ICON_ALERT); } else { need_attn = FALSE; - iconstr = ICON_DEFAULT; + icon = g_themed_icon_new (ICON_DEFAULT); } show_name = g_settings_get_boolean (p->indicator_settings, @@ -194,9 +193,27 @@ update_header_action (IndicatorSessionService * self) a11y = g_strdup (_("System")); } - variant = g_variant_new ("(sssb)", label, iconstr, a11y, TRUE); - g_simple_action_set_state (p->header_action, variant); + /* build the state */ + g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add (&b, "{sv}", "accessible-desc", g_variant_new_string (a11y)); + g_variant_builder_add (&b, "{sv}", "icon", g_icon_serialize (icon)); + if (label && *label) + g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label)); + g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE)); + state = g_variant_builder_end (&b); +g_message ("---\n%s\n---\n", g_variant_print(state, TRUE)); + + /* cleanup */ g_free (a11y); + g_object_unref (G_OBJECT (icon)); + + return state; +} + +static void +update_header_action (IndicatorSessionService * self) +{ + g_simple_action_set_state (self->priv->header_action, action_state_for_header (self)); } /*** @@ -763,8 +780,7 @@ init_gactions (IndicatorSessionService * self) p->user_switcher_action = a; /* add the header action */ - v = g_variant_new ("(sssb)", "label", ICON_DEFAULT, "a11y", TRUE); - a = g_simple_action_new_stateful ("_header", NULL, v); + a = g_simple_action_new_stateful ("_header", NULL, action_state_for_header (self)); g_simple_action_group_insert (p->actions, G_ACTION(a)); p->header_action = a; -- cgit v1.2.3 From a699afab31403d69bbd6f20c45a6f601b1ea3dc5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 8 Aug 2013 16:02:22 -0500 Subject: remove debugging stub --- src/service.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/service.c b/src/service.c index 41dba10..a097876 100644 --- a/src/service.c +++ b/src/service.c @@ -201,7 +201,6 @@ action_state_for_header (IndicatorSessionService * self) g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label)); g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE)); state = g_variant_builder_end (&b); -g_message ("---\n%s\n---\n", g_variant_print(state, TRUE)); /* cleanup */ g_free (a11y); -- cgit v1.2.3 From d31e14e5afc14259f81efd54852f990ffe053889 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 12 Aug 2013 12:45:35 -0500 Subject: sync tests to look for a header action state of type a{sv} instead of (sssb) --- tests/test-service.cc | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/tests/test-service.cc b/tests/test-service.cc index e69b574..b199175 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -318,28 +318,44 @@ class ServiceTest: public GTestDBusFixture void check_header (const char * expected_label, const char * expected_icon, const char * expected_a11y) { - GVariant * variant; - const gchar * label = NULL; - const gchar * icon = NULL; - const gchar * a11y = NULL; - gboolean visible; - - variant = g_action_group_get_action_state (G_ACTION_GROUP(action_group), "_header"); - g_variant_get (variant, "(&s&s&sb)", &label, &icon, &a11y, &visible); + GVariant * state = g_action_group_get_action_state (G_ACTION_GROUP(action_group), "_header"); + ASSERT_TRUE (state != NULL); + ASSERT_TRUE (g_variant_is_of_type (state, G_VARIANT_TYPE ("a{sv}"))); if (expected_label != NULL) - ASSERT_STREQ (expected_label, label); - - if (expected_icon != NULL) - ASSERT_STREQ (expected_icon, icon); + { + GVariant * v = g_variant_lookup_value (state, "label", G_VARIANT_TYPE_STRING); + if (!v) // if no label in the state, expected_label must be an empty string + ASSERT_FALSE (*expected_label); + else + ASSERT_STREQ (expected_label, g_variant_get_string (v, NULL)); + } if (expected_a11y != NULL) - ASSERT_STREQ (expected_a11y, a11y); + { + GVariant * v = g_variant_lookup_value (state, "accessible-desc", G_VARIANT_TYPE_STRING); + ASSERT_TRUE (v != NULL); + ASSERT_STREQ (expected_a11y, g_variant_get_string (v, NULL)); + g_variant_unref (v); + } + + if (expected_icon != NULL) + { + GVariant * v = g_variant_lookup_value (state, "icon", NULL); + GIcon * expected = g_themed_icon_new (expected_icon); + GIcon * actual = g_icon_deserialize (v); + ASSERT_TRUE (g_icon_equal (expected, actual)); + g_object_unref (actual); + g_object_unref (expected); + g_variant_unref (v); + } // the session menu is always visible... + gboolean visible = false; + g_variant_lookup (state, "visible", "b", &visible); ASSERT_TRUE (visible); - g_variant_unref (variant); + g_variant_unref (state); } void check_label (const char * expected_label, GMenuModel * model, int pos) -- cgit v1.2.3