aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Russell <crussell@canonical.com>2009-09-24 01:21:50 -0500
committerCody Russell <crussell@canonical.com>2009-09-24 01:21:50 -0500
commit7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17 (patch)
treeb1de20976e08e894b8d69a0012d06cebe66d73b5
parent3427b4a7054aa66f1aaa20aed56ad445aecd5ec4 (diff)
downloadayatana-indicator-session-7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17.tar.gz
ayatana-indicator-session-7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17.tar.bz2
ayatana-indicator-session-7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17.zip
don't load all the users unless needed
-rw-r--r--src/users-service-dbus.c197
-rw-r--r--src/users-service-dbus.h3
-rw-r--r--src/users-service.c23
3 files changed, 140 insertions, 83 deletions
diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c
index 6051e4e..018469c 100644
--- a/src/users-service-dbus.c
+++ b/src/users-service-dbus.c
@@ -635,16 +635,80 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy,
}
static void
+sync_users (UsersServiceDbus *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)
+ {
+ GArray *uids = NULL;
+ GPtrArray *users_info = NULL;
+ GError *error = NULL;
+ gint i;
+
+ uids = g_array_new (FALSE, FALSE, sizeof (gint64));
+
+ if (!org_gnome_DisplayManager_UserManager_get_user_list (priv->gdm_proxy,
+ &uids,
+ &error))
+ {
+ g_warning ("failed to retrieve user list: %s", error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ users_info = g_ptr_array_new ();
+
+ if (!org_gnome_DisplayManager_UserManager_get_users_info (priv->gdm_proxy,
+ uids,
+ &users_info,
+ &error))
+ {
+ g_warning ("failed to retrieve user info: %s", error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ for (i = 0; i < users_info->len; i++)
+ {
+ GValueArray *values;
+ UserData *user;
+
+ values = g_ptr_array_index (users_info, i);
+
+ user = g_new0 (UserData, 1);
+
+ user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0));
+ user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1)));
+ user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2)));
+ user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3)));
+ user->login_count = g_value_get_int (g_value_array_get_nth (values, 4));
+ user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5)));
+
+ g_hash_table_insert (priv->users,
+ g_strdup (user->user_name),
+ user);
+
+ add_sessions_for_user (self, user);
+ }
+ }
+}
+
+static void
users_loaded (DBusGProxy *proxy,
gpointer user_data)
{
UsersServiceDbus *service;
UsersServiceDbusPrivate *priv;
GError *error = NULL;
- GArray *uids = NULL;
- GPtrArray *users_info = NULL;
gint count;
- int i;
service = (UsersServiceDbus *)user_data;
priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
@@ -661,53 +725,7 @@ users_loaded (DBusGProxy *proxy,
priv->count = count;
- uids = g_array_new (FALSE, FALSE, sizeof (gint64));
-
- if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy,
- &uids,
- &error))
- {
- g_warning ("failed to retrieve user list: %s", error->message);
- g_error_free (error);
-
- return;
- }
-
- users_info = g_ptr_array_new ();
-
- if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy,
- uids,
- &users_info,
- &error))
- {
- g_warning ("failed to retrieve user info: %s", error->message);
- g_error_free (error);
-
- return;
- }
-
- for (i = 0; i < users_info->len; i++)
- {
- GValueArray *values;
- UserData *user;
-
- values = g_ptr_array_index (users_info, i);
-
- user = g_new0 (UserData, 1);
-
- user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0));
- user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1)));
- user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2)));
- user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3)));
- user->login_count = g_value_get_int (g_value_array_get_nth (values, 4));
- user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5)));
-
- g_hash_table_insert (priv->users,
- g_strdup (user->user_name),
- user);
-
- add_sessions_for_user (service, user);
- }
+ sync_users (service);
}
static gboolean
@@ -908,30 +926,40 @@ user_added (DBusGProxy *proxy,
priv->count++;
- if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy,
- uid,
- &user->user_name,
- &user->real_name,
- &user->shell,
- &user->login_count,
- &user->icon_url,
- &error))
+ if (priv->count < MAXIMUM_USERS)
{
- g_warning ("unable to retrieve user info: %s", error->message);
- g_error_free (error);
-
- g_free (user);
-
- return;
+ if ((priv->count - g_hash_table_size (priv->users)) > 1)
+ {
+ sync_users (service);
+ }
+ else
+ {
+ if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy,
+ uid,
+ &user->user_name,
+ &user->real_name,
+ &user->shell,
+ &user->login_count,
+ &user->icon_url,
+ &error))
+ {
+ g_warning ("unable to retrieve user info: %s", error->message);
+ g_error_free (error);
+
+ g_free (user);
+
+ return;
+ }
+
+ user->uid = uid;
+
+ g_hash_table_insert (priv->users,
+ g_strdup (user->user_name),
+ user);
+
+ g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE);
+ }
}
-
- user->uid = uid;
-
- g_hash_table_insert (priv->users,
- g_strdup (user->user_name),
- user);
-
- g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE);
}
static gboolean
@@ -950,15 +978,28 @@ user_removed (DBusGProxy *proxy,
UsersServiceDbus *service = (UsersServiceDbus *)user_data;
UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service);
UserData *user;
+ gint size;
- user = g_hash_table_find (priv->users,
- compare_users_by_uid,
- GUINT_TO_POINTER (uid));
-
- g_hash_table_remove (priv->users,
- user->user_name);
+ size = g_hash_table_size (priv->users);
priv->count--;
+
+ if (size == 0 || (size - priv->count) > 1)
+ {
+ sync_users (service);
+ }
+ else
+ {
+ user = g_hash_table_find (priv->users,
+ compare_users_by_uid,
+ GUINT_TO_POINTER (uid));
+
+ if (user != NULL)
+ {
+ g_hash_table_remove (priv->users,
+ user->user_name);
+ }
+ }
}
static void
diff --git a/src/users-service-dbus.h b/src/users-service-dbus.h
index e156520..201445e 100644
--- a/src/users-service-dbus.h
+++ b/src/users-service-dbus.h
@@ -50,6 +50,9 @@ struct _UserData
UsersServiceDbus *service;
};
+#define MINIMUM_USERS 1
+#define MAXIMUM_USERS 7
+
struct _UsersServiceDbus {
GObject parent;
};
diff --git a/src/users-service.c b/src/users-service.c
index 9dbf218..9f240da 100644
--- a/src/users-service.c
+++ b/src/users-service.c
@@ -37,8 +37,6 @@
#include "users-service-dbus.h"
#define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch"
-#define MINIMUM_USERS 1
-#define MAXIMUM_USERS 7
typedef struct _ActivateData ActivateData;
struct _ActivateData
@@ -193,6 +191,23 @@ rebuild_items (DbusmenuMenuitem *root,
if (count > 1 && count < 7)
{
+ if (count > MINIMUM_USERS && count < MAXIMUM_USERS)
+ {
+ if (users != NULL)
+ {
+ GList *l = NULL;
+
+ for (l = users; l != NULL; l = l->next)
+ {
+ users = g_list_delete_link (users, l);
+ }
+
+ users = NULL;
+ }
+
+ users = users_service_dbus_get_user_list (service);
+ }
+
for (u = users; u != NULL; u = g_list_next (u))
{
user = u->data;
@@ -222,7 +237,6 @@ user_added (UsersServiceDbus *service,
{
DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data;
- users = g_list_append (users, user);
count++;
rebuild_items (root, service);
@@ -235,7 +249,6 @@ user_removed (UsersServiceDbus *service,
{
DbusmenuMenuitem *root = (DbusmenuMenuitem *)user_data;
- users = g_list_remove (users, user);
count--;
rebuild_items (root, service);
@@ -248,7 +261,7 @@ create_items (DbusmenuMenuitem *root,
g_return_if_fail (IS_USERS_SERVICE_DBUS (service));
count = users_service_dbus_get_user_count (service);
- if (count > 1 && count < 7)
+ if (count > MINIMUM_USERS && count < MAXIMUM_USERS)
{
users = users_service_dbus_get_user_list (service);
}