From b3938a1f14b687d62ad1d6e4e27bac47f58722de Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 25 Jun 2013 11:16:34 -0500 Subject: in IndicatorSessionUsers, use the uid as the user's key. Users.ActivateUser is now green. --- src/backend-dbus/users.c | 73 +++++++++++++++++------------------------------- src/service.c | 40 +++++++++++++------------- src/users.c | 38 ++++++++++++------------- src/users.h | 30 ++++++++++---------- 4 files changed, 79 insertions(+), 102 deletions(-) (limited to 'src') diff --git a/src/backend-dbus/users.c b/src/backend-dbus/users.c index c135610..48de06c 100644 --- a/src/backend-dbus/users.c +++ b/src/backend-dbus/users.c @@ -53,33 +53,22 @@ G_DEFINE_TYPE (IndicatorSessionUsersDbus, **** ***/ -static const gchar * -get_public_key_for_uid (guint uid) -{ - static char buf[16]; - g_snprintf (buf, sizeof(buf), "%u", uid); - return buf; -} - static void emit_user_added (IndicatorSessionUsersDbus * self, guint uid) { - const gchar * const public_key = get_public_key_for_uid (uid); - indicator_session_users_added (INDICATOR_SESSION_USERS(self), public_key); + indicator_session_users_added (INDICATOR_SESSION_USERS(self), uid); } static void emit_user_changed (IndicatorSessionUsersDbus * self, guint uid) { - const gchar * const public_key = get_public_key_for_uid (uid); - indicator_session_users_changed (INDICATOR_SESSION_USERS(self), public_key); + indicator_session_users_changed (INDICATOR_SESSION_USERS(self), uid); } static void emit_user_removed (IndicatorSessionUsersDbus * self, guint uid) { - const gchar * const public_key = get_public_key_for_uid (uid); - indicator_session_users_removed (INDICATOR_SESSION_USERS(self), public_key); + indicator_session_users_removed (INDICATOR_SESSION_USERS(self), uid); } /*** @@ -124,22 +113,22 @@ static void set_logins (IndicatorSessionUsersDbus * self, GHashTable * logins) { GHashTable * old_logins = self->priv->logins; - gpointer key; + gpointer uid; GHashTableIter iter; self->priv->logins = logins; /* fire 'user changed' event for users who logged out */ g_hash_table_iter_init (&iter, old_logins); - while ((g_hash_table_iter_next (&iter, &key, NULL))) - if (!g_hash_table_contains (logins, key)) - emit_user_changed (self, GPOINTER_TO_INT(key)); + while ((g_hash_table_iter_next (&iter, &uid, NULL))) + if (!g_hash_table_contains (logins, uid)) + emit_user_changed (self, GPOINTER_TO_UINT(uid)); /* fire 'user changed' event for users who logged in */ g_hash_table_iter_init (&iter, logins); - while ((g_hash_table_iter_next (&iter, &key, NULL))) - if (!g_hash_table_contains (old_logins, key)) - emit_user_changed (self, GPOINTER_TO_INT(key)); + while ((g_hash_table_iter_next (&iter, &uid, NULL))) + if (!g_hash_table_contains (old_logins, uid)) + emit_user_changed (self, GPOINTER_TO_UINT(uid)); g_hash_table_destroy (old_logins); } @@ -205,12 +194,6 @@ get_user_for_uid (IndicatorSessionUsersDbus * self, guint uid) return g_hash_table_lookup (p->uid_to_account, GUINT_TO_POINTER(uid)); } -static AccountsUser * -get_user_for_public_key (IndicatorSessionUsersDbus * self, const char * public_key) -{ - return get_user_for_uid (self, g_ascii_strtoull (public_key, NULL, 10)); -} - /*** **** User Account Tracking ***/ @@ -520,19 +503,19 @@ set_display_manager_seat (IndicatorSessionUsersDbus * self, /* switch to (or create) a session for the specified user */ static void -my_activate_user (IndicatorSessionUsers * users, const char * public_key) +my_activate_user (IndicatorSessionUsers * users, guint uid) { IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS(users); priv_t * p = self->priv; AccountsUser * au; const char * username; - au = get_user_for_public_key (self, public_key); + au = get_user_for_uid (self, uid); username = au ? accounts_user_get_user_name (au) : NULL; if (!username) { - g_warning ("%s %s can't find user for '%s'", G_STRLOC, G_STRFUNC, public_key); + g_warning ("%s %s can't find user '%u'", G_STRLOC, G_STRFUNC, uid); } else { @@ -556,36 +539,31 @@ my_is_live_session (IndicatorSessionUsers * users) return INDICATOR_SESSION_USERS_DBUS(users)->priv->is_live; } -/* get a list of public keys for the users that we know about */ -static GStrv -my_get_keys (IndicatorSessionUsers * users) +/* get a list of our user ids */ +static GList * +my_get_uids (IndicatorSessionUsers * users) { - int i; priv_t * p; - gchar ** keys; + GList * uids; GHashTableIter iter; gpointer uid; gpointer user; - GHashTable * h; g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_DBUS(users), NULL); p = INDICATOR_SESSION_USERS_DBUS (users)->priv; - i = 0; - h = p->uid_to_account; - keys = g_new (gchar*, g_hash_table_size(h)+1); - g_hash_table_iter_init (&iter, h); + uids = NULL; + g_hash_table_iter_init (&iter, p->uid_to_account); while (g_hash_table_iter_next (&iter, &uid, &user)) if (!accounts_user_get_system_account (user)) - keys[i++] = g_strdup (get_public_key_for_uid ((guint)uid)); - keys[i] = NULL; + uids = g_list_prepend (uids, uid); - return keys; + return uids; } /* build a new struct populated with info on the specified user */ static IndicatorSessionUser * -my_get_user (IndicatorSessionUsers * users, const gchar * public_key) +my_get_user (IndicatorSessionUsers * users, guint uid) { IndicatorSessionUsersDbus * self = INDICATOR_SESSION_USERS_DBUS (users); priv_t * p = self->priv; @@ -593,11 +571,10 @@ my_get_user (IndicatorSessionUsers * users, const gchar * public_key) AccountsUser * au; ret = NULL; - au = get_user_for_public_key (self, public_key); - + au = get_user_for_uid (self, uid); if (au && !accounts_user_get_system_account(au)) { - const guint uid = accounts_user_get_uid (au); + g_assert (uid == accounts_user_get_uid (au)); ret = g_new0 (IndicatorSessionUser, 1); ret->uid = uid; @@ -662,7 +639,7 @@ indicator_session_users_dbus_class_init (IndicatorSessionUsersDbusClass * klass) users_class = INDICATOR_SESSION_USERS_CLASS (klass); users_class->is_live_session = my_is_live_session; - users_class->get_keys = my_get_keys; + users_class->get_uids = my_get_uids; users_class->get_user = my_get_user; users_class->activate_user = my_activate_user; diff --git a/src/service.c b/src/service.c index e41cca6..1fcbd07 100644 --- a/src/service.c +++ b/src/service.c @@ -206,13 +206,13 @@ update_header_action (IndicatorSessionService * self) static GMenuModel * create_switch_section (IndicatorSessionService * self); static void -add_user (IndicatorSessionService * self, const gchar * key) +add_user (IndicatorSessionService * self, guint uid) { IndicatorSessionUser * u; /* update our user table */ - u = indicator_session_users_get_user (self->priv->backend_users, key); - g_hash_table_insert (self->priv->users, g_strdup(key), u); + u = indicator_session_users_get_user (self->priv->backend_users, uid); + g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(uid), u); /* enqueue rebuilds for the affected sections */ rebuild_switch_section_soon (self); @@ -222,30 +222,30 @@ add_user (IndicatorSessionService * self, const gchar * key) static void on_user_added (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, - const char * key, + guint uid, gpointer gself) { - add_user (INDICATOR_SESSION_SERVICE(gself), key); + add_user (INDICATOR_SESSION_SERVICE(gself), uid); } static void on_user_changed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, - const char * key, + guint uid, gpointer gself) { - add_user (INDICATOR_SESSION_SERVICE(gself), key); + add_user (INDICATOR_SESSION_SERVICE(gself), uid); } static void on_user_removed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, - const char * key, + guint uid, gpointer gself) { IndicatorSessionService * self = INDICATOR_SESSION_SERVICE (gself); g_return_if_fail (self != NULL); /* update our user table */ - g_hash_table_remove (self->priv->users, key); + g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid)); /* enqueue rebuilds for the affected sections */ rebuild_switch_section_soon (self); @@ -334,13 +334,13 @@ create_user_switcher_state (IndicatorSessionService * self) GVariantBuilder * b; GVariant * val; GHashTableIter ht_iter; - gpointer ht_key, ht_value; + gpointer ht_value; const char * current_user; current_user = ""; a = g_variant_builder_new (G_VARIANT_TYPE("as")); g_hash_table_iter_init (&ht_iter, self->priv->users); - while (g_hash_table_iter_next (&ht_iter, &ht_key, &ht_value)) + while (g_hash_table_iter_next (&ht_iter, NULL, &ht_value)) { const IndicatorSessionUser * u = ht_value; @@ -950,8 +950,8 @@ static void /* cppcheck-suppress unusedFunction */ indicator_session_service_init (IndicatorSessionService * self) { - int i; - GStrv keys; + GList * l; + GList * uids; priv_t * p; gpointer gp; @@ -970,14 +970,14 @@ indicator_session_service_init (IndicatorSessionService * self) &p->backend_guest); /* init our key-to-User table */ - p->users = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, + p->users = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, (GDestroyNotify)indicator_session_user_free); - keys = indicator_session_users_get_keys (p->backend_users); - for (i=0; keys && keys[i]; ++i) - add_user (self, keys[i]); - g_strfreev (keys); + 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); init_gactions (self); diff --git a/src/users.c b/src/users.c index 4b9c0ad..5e4d910 100644 --- a/src/users.c +++ b/src/users.c @@ -75,24 +75,24 @@ indicator_session_users_class_init (IndicatorSessionUsersClass * klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_added), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); signals[USER_REMOVED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_removed), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); signals[USER_CHANGED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_changed), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); properties[PROP_IS_LIVE_SESSION] = @@ -115,30 +115,30 @@ indicator_session_users_init (IndicatorSessionUsers * self G_GNUC_UNUSED) **** Virtual Functions ***/ -GStrv -indicator_session_users_get_keys (IndicatorSessionUsers * self) +GList * +indicator_session_users_get_uids (IndicatorSessionUsers * self) { g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL); - return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_keys (self); + return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_uids (self); } IndicatorSessionUser * indicator_session_users_get_user (IndicatorSessionUsers * self, - const char * key) + guint uid) { g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL); - return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_user (self, key); + return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_user (self, uid); } void indicator_session_users_activate_user (IndicatorSessionUsers * self, - const char * key) + guint uid) { g_return_if_fail (INDICATOR_IS_SESSION_USERS (self)); - INDICATOR_SESSION_USERS_GET_CLASS (self)->activate_user (self, key); + INDICATOR_SESSION_USERS_GET_CLASS (self)->activate_user (self, uid); } gboolean @@ -165,27 +165,27 @@ indicator_session_user_free (IndicatorSessionUser * user) ***/ void -indicator_session_users_added (IndicatorSessionUsers * self, const char * key) +indicator_session_users_added (IndicatorSessionUsers * self, guint uid) { g_return_if_fail (INDICATOR_IS_SESSION_USERS (self)); - g_signal_emit (self, signals[USER_ADDED], 0, key); + g_signal_emit (self, signals[USER_ADDED], 0, uid); } void -indicator_session_users_removed (IndicatorSessionUsers * self, const char * key) +indicator_session_users_removed (IndicatorSessionUsers * self, guint uid) { g_return_if_fail (INDICATOR_IS_SESSION_USERS (self)); - g_signal_emit (self, signals[USER_REMOVED], 0, key); + g_signal_emit (self, signals[USER_REMOVED], 0, uid); } void -indicator_session_users_changed (IndicatorSessionUsers * self, const char * key) +indicator_session_users_changed (IndicatorSessionUsers * self, guint uid) { g_return_if_fail (INDICATOR_IS_SESSION_USERS (self)); - g_signal_emit (self, signals[USER_CHANGED], 0, key); + g_signal_emit (self, signals[USER_CHANGED], 0, uid); } void diff --git a/src/users.h b/src/users.h index f2d7404..9871766 100644 --- a/src/users.h +++ b/src/users.h @@ -72,13 +72,13 @@ struct _IndicatorSessionUsersClass /* signals */ void (* user_added) (IndicatorSessionUsers * self, - const gchar * key); + guint uid); void (* user_removed) (IndicatorSessionUsers * self, - const gchar * key); + guint uid); void (* user_changed) (IndicatorSessionUsers * self, - const gchar * key); + guint uid); /* pure virtual functions */ @@ -86,13 +86,13 @@ struct _IndicatorSessionUsersClass gboolean (* is_live_session) (IndicatorSessionUsers * self); - GStrv (* get_keys) (IndicatorSessionUsers * self); + GList* (* get_uids) (IndicatorSessionUsers * self); IndicatorSessionUser * (* get_user) (IndicatorSessionUsers * self, - const gchar * key); + guint uid); void ( * activate_user) (IndicatorSessionUsers * self, - const gchar * key); + guint uid); }; /*** @@ -103,15 +103,15 @@ GType indicator_session_users_get_type (void); /* emits the "user-added" signal */ void indicator_session_users_added (IndicatorSessionUsers * self, - const gchar * key); + guint uid); /* emits the "user-removed" signal */ void indicator_session_users_removed (IndicatorSessionUsers * self, - const gchar * key); + guint uid); /* emits the "user-changed" signal */ void indicator_session_users_changed (IndicatorSessionUsers * self, - const gchar * key); + guint uid); /* notify listeners of a change to the 'is-live-session' property */ void indicator_session_users_notify_is_live_session (IndicatorSessionUsers * self); @@ -125,12 +125,12 @@ void indicator_session_users_notify_is_live_session (IndicatorSessionUsers * sel gboolean indicator_session_users_is_live_session (IndicatorSessionUsers * users); /** - * Get a list of user keys. + * Get a list of the users to show in the indicator * - * Return value: (transfer full): a NULL-terminated array of user keys. - * Free with g_strfreev() when done. + * Return value: (transfer container): a GList of guint user ids. + * Free with g_slist_free() when done. */ -GStrv indicator_session_users_get_keys (IndicatorSessionUsers * users); +GList * indicator_session_users_get_uids (IndicatorSessionUsers * users); /** * Get information about a particular user. @@ -141,14 +141,14 @@ GStrv indicator_session_users_get_keys (IndicatorSessionUsers * users); */ IndicatorSessionUser * indicator_session_users_get_user (IndicatorSessionUsers * users, - const gchar * key); + guint uid); /* frees a IndicatorSessionUser struct */ void indicator_session_user_free (IndicatorSessionUser * user); /* activate to a different session */ void indicator_session_users_activate_user (IndicatorSessionUsers * self, - const char * key); + guint uid); G_END_DECLS -- cgit v1.2.3