From d5b6485ae8f17525ddc6e2beacb4f7a5dce73bfa Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Wed, 19 Mar 2014 17:35:47 +0000 Subject: Re-add the feature to hide the user list if com.canonical.indicator.session user-show-menu is false --- .../com.canonical.indicator.session.gschema.xml.in | 5 +++ src/service.c | 49 ++++++++++++++++++---- tests/com.canonical.indicator.session.gschema.xml | 7 +++- tests/test-service.cc | 10 +++++ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/data/com.canonical.indicator.session.gschema.xml.in b/data/com.canonical.indicator.session.gschema.xml.in index 6010b3f..38c3846 100644 --- a/data/com.canonical.indicator.session.gschema.xml.in +++ b/data/com.canonical.indicator.session.gschema.xml.in @@ -25,6 +25,11 @@ Determine the visibility of the User's real name on the panel Allow for the Removal of the users name from the panel + + true + Show the list of users + Allow for the user menu to be hidden by the user. + diff --git a/src/service.c b/src/service.c index 60ddae0..88ce6b1 100644 --- a/src/service.c +++ b/src/service.c @@ -155,6 +155,14 @@ rebuild_settings_section_soon (IndicatorSessionService * self) **** ***/ +static gboolean +show_user_list (IndicatorSessionService * self) +{ + return g_settings_get_boolean (self->priv->indicator_settings, + "user-show-menu"); +} + + static GVariant * action_state_for_header (IndicatorSessionService * self) { @@ -266,6 +274,32 @@ on_user_changed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, add_user (INDICATOR_SESSION_SERVICE(gself), uid); } +static void +maybe_add_users (IndicatorSessionService * self) +{ + if (!show_user_list (self)) + return; + + GList * uids, * l; + + uids = indicator_session_users_get_uids (self->priv->backend_users); + for (l=uids; l!=NULL; l=l->next) + add_user (self, GPOINTER_TO_UINT(l->data)); + g_list_free (uids); +} + + +static void +user_show_menu_changed (IndicatorSessionService * self) +{ + if (show_user_list (self)) + maybe_add_users (self); + else + g_hash_table_remove_all (self->priv->users); + + rebuild_switch_section_soon (self); +} + static void on_user_removed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, guint uid, @@ -541,7 +575,11 @@ create_switch_section (IndicatorSessionService * self, int profile) g_object_unref (item); } - /* build an array of all the users we know of */ + /* if we need to show the user list, build an array of all the users we know + * of, otherwise get out now */ + if (!show_user_list (self)) + return G_MENU_MODEL (menu); + users = g_ptr_array_new (); g_hash_table_iter_init (&iter, p->users); while (g_hash_table_iter_next (&iter, NULL, &guser)) @@ -1053,8 +1091,6 @@ static void /* cppcheck-suppress unusedFunction */ indicator_session_service_init (IndicatorSessionService * self) { - GList * l; - GList * uids; priv_t * p; gpointer gp; GIcon * icon; @@ -1088,10 +1124,7 @@ indicator_session_service_init (IndicatorSessionService * self) g_direct_equal, NULL, (GDestroyNotify)indicator_session_user_free); - uids = indicator_session_users_get_uids (p->backend_users); - for (l=uids; l!=NULL; l=l->next) - add_user (self, GPOINTER_TO_UINT(l->data)); - g_list_free (uids); + maybe_add_users (self); init_gactions (self); @@ -1138,6 +1171,8 @@ indicator_session_service_init (IndicatorSessionService * self) G_CALLBACK(rebuild_session_section_soon), self); g_signal_connect_swapped (gp, "changed::show-real-name-on-panel", G_CALLBACK(rebuild_header_soon), self); + g_signal_connect_swapped (gp, "changed::user-show-menu", + G_CALLBACK(user_show_menu_changed), self); /* watch for changes to the lock keybinding */ gp = p->keybinding_settings; diff --git a/tests/com.canonical.indicator.session.gschema.xml b/tests/com.canonical.indicator.session.gschema.xml index 76b2be3..60e680b 100644 --- a/tests/com.canonical.indicator.session.gschema.xml +++ b/tests/com.canonical.indicator.session.gschema.xml @@ -26,7 +26,12 @@ Determine the visibility of the User's real name on the panel Allow for the Removal of the users name from the panel + + true + Show the list of users + Allow for the user menu to be hidden by the user. + - \ No newline at end of file + diff --git a/tests/test-service.cc b/tests/test-service.cc index f14fe61..1f3272f 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -812,6 +812,16 @@ TEST_F (ServiceTest, User) check_label ("Third Doctor", switch_menu, 8); g_clear_object (&switch_menu); + /* Hide the user list */ + g_settings_set_boolean (indicator_settings, "user-show-menu", FALSE); + wait_for_menu_resync (); + // now there should be 7 menuitems: greeter + guest + the five doctors + ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", &switch_menu, &pos)); + ASSERT_EQ (0, pos); + ASSERT_EQ (2, g_menu_model_get_n_items (switch_menu)); + g_clear_object (&switch_menu); + g_settings_set_boolean (indicator_settings, "user-show-menu", TRUE); + // now switch to one of the doctors g_action_group_activate_action (G_ACTION_GROUP(action_group), "switch-to-user", -- cgit v1.2.3