From 733c32bb8d9619109ad47ab599c2f960cf19308b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 19 Aug 2011 18:10:09 +0100 Subject: users now dynamically responsive to addition and deletion of users --- src/users-service-dbus.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index e7507a4..434bab8 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -711,11 +711,6 @@ sync_users (UsersServiceDbus *self) g_return_if_fail(IS_USERS_SERVICE_DBUS(self)); UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - if (g_hash_table_size (priv->users) > 0) - { - return; - } - if (priv->count > MINIMUM_USERS && priv->count < MAXIMUM_USERS) { GPtrArray *users = NULL; @@ -758,7 +753,13 @@ sync_users (UsersServiceDbus *self) continue; } - + // Double check we havent processed this user already + if (users_service_dbus_get_user_by_username (self, + g_value_get_string (g_hash_table_lookup (properties, "UserName"))) != NULL) + { + continue; + } + user = g_new0 (UserData, 1); user->uid = g_value_get_uint64 (g_hash_table_lookup (properties, "Uid")); @@ -788,13 +789,19 @@ user_added (DBusGProxy *proxy, { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - + g_debug ("user added in the service dbus"); priv->count++; if (priv->count < MAXIMUM_USERS) { + g_debug ("syncing users"); sync_users (service); } + + g_signal_emit (service, + signals[USER_ADDED], + 0, + user_id); } static void @@ -802,11 +809,19 @@ user_deleted (DBusGProxy *proxy, const gchar *user_id, gpointer user_data) { + g_debug ("user deleted in the service dbus"); + UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); priv->count--; g_hash_table_remove (priv->users, user_id); + + g_signal_emit (service, + signals[USER_DELETED], + 0, + user_id); + } UserData * -- cgit v1.2.3 From 2d97d089958309db8115a5c9cfd9ffa4cb5ff39d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 19 Aug 2011 18:14:59 +0100 Subject: remove the debugs --- src/users-service-dbus.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 434bab8..03d1144 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -789,12 +789,10 @@ user_added (DBusGProxy *proxy, { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - g_debug ("user added in the service dbus"); priv->count++; if (priv->count < MAXIMUM_USERS) { - g_debug ("syncing users"); sync_users (service); } @@ -808,9 +806,7 @@ static void user_deleted (DBusGProxy *proxy, const gchar *user_id, gpointer user_data) -{ - g_debug ("user deleted in the service dbus"); - +{ UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); -- cgit v1.2.3 From faa1e437d22814566c4e8e0cc9db9c2546192cbe Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 22 Aug 2011 20:21:29 +0100 Subject: changed around the sync users so as it can be used to refresh the user list on any given event --- src/users-service-dbus.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 03d1144..07ce889 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -58,6 +58,8 @@ static void user_added (DBusGProxy *proxy static void user_deleted (DBusGProxy *proxy, const gchar *user_id, gpointer user_data); +static void user_changed (DBusGProxy *proxy, + gpointer user_data); static void seat_proxy_session_added (DBusGProxy *seat_proxy, const gchar *session_id, UsersServiceDbus *service); @@ -753,21 +755,37 @@ sync_users (UsersServiceDbus *self) continue; } + + user = g_hash_table_lookup (priv->users, id); // Double check we havent processed this user already - if (users_service_dbus_get_user_by_username (self, - g_value_get_string (g_hash_table_lookup (properties, "UserName"))) != NULL) + if (user != NULL) { - continue; + g_free(user->user_name); + g_free(user->real_name); + g_free(user->icon_file); + user->real_name_conflict = FALSE; + //continue; } - - user = g_new0 (UserData, 1); - + else + { + user = g_new0 (UserData, 1); + } + // Can't subscribe to the Changed signal on each individual user path + // for some reason. + /*dbus_g_proxy_add_signal (proxy, + "Changed", + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (proxy, "Changed", + G_CALLBACK(user_changed), + self, + NULL);*/ user->uid = g_value_get_uint64 (g_hash_table_lookup (properties, "Uid")); user->user_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "UserName"))); user->real_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "RealName"))); user->icon_file = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "IconFile"))); user->real_name_conflict = FALSE; - user->menuitem = NULL; + user->menuitem = NULL; g_hash_table_unref (properties); @@ -782,6 +800,15 @@ sync_users (UsersServiceDbus *self) } } +static void +user_changed (DBusGProxy *proxy, + gpointer user_data) +{ + g_debug ("JUST RESYNCED THE USERS FROM A USER CHANGE"); + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + sync_users (service); +} + static void user_added (DBusGProxy *proxy, const gchar *user_id, -- cgit v1.2.3 From ca8ee2aec023d95d73e3563d45bc1b660a548f40 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 22 Aug 2011 20:24:56 +0100 Subject: uncomment signal subscription that doesn't work --- src/users-service-dbus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 07ce889..4b41f4b 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -772,14 +772,14 @@ sync_users (UsersServiceDbus *self) } // Can't subscribe to the Changed signal on each individual user path // for some reason. - /*dbus_g_proxy_add_signal (proxy, + dbus_g_proxy_add_signal (proxy, "Changed", G_TYPE_INVALID); dbus_g_proxy_connect_signal (proxy, "Changed", G_CALLBACK(user_changed), self, - NULL);*/ + NULL); user->uid = g_value_get_uint64 (g_hash_table_lookup (properties, "Uid")); user->user_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "UserName"))); user->real_name = g_strdup (g_value_get_string (g_hash_table_lookup (properties, "RealName"))); -- cgit v1.2.3