[accounts-dialog] Make initial loading async



commit 0e95d89cd0987145c46b32d627a2a42e7685dfb8
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 19 17:02:22 2010 -0500

    Make initial loading async
    
    Also add a users-loaded signal to the user manager.

 src/main.c            |   62 ++++++++++++++++++++++++++++--------------------
 src/um-user-manager.c |   47 +++++++++++++++++++++++++++++--------
 src/um-user-manager.h |    1 +
 3 files changed, 74 insertions(+), 36 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 7748919..ab8d571 100644
--- a/src/main.c
+++ b/src/main.c
@@ -933,6 +933,41 @@ dont_select_headings (GtkTreeSelection *selection,
 }
 
 static void
+users_loaded (UmUserManager     *manager,
+              UserAccountDialog *d)
+{
+        GSList *list, *l;
+        UmUser *user;
+        GtkWidget *dialog;
+
+        if (um_user_manager_no_service (d->um)) {
+                dialog = gtk_message_dialog_new (GTK_WINDOW (d->main_window),
+                                                 GTK_DIALOG_MODAL,
+                                                 GTK_MESSAGE_OTHER,
+                                                 GTK_BUTTONS_CLOSE,
+                                                 _("Failed to contact the accounts service"));
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                          _("Please make sure that the AccountService is installed and enabled."));
+                g_signal_connect (dialog, "response",
+                                  G_CALLBACK (gtk_main_quit), NULL);
+                gtk_widget_show (dialog);
+        }
+
+        list = um_user_manager_list_users (d->um);
+        g_debug ("Got %d users\n", g_slist_length (list));
+        for (l = list; l; l = l->next) {
+                user = l->data;
+                g_debug ("adding user %s\n", um_user_get_real_name (user));
+                user_added (d->um, user, d);
+        }
+        g_slist_free (list);
+
+        g_signal_connect (d->um, "user-added", G_CALLBACK (user_added), d);
+        g_signal_connect (d->um, "user-removed", G_CALLBACK (user_removed), d);
+        g_signal_connect (d->um, "user-changed", G_CALLBACK (user_changed), d);
+}
+
+static void
 setup_main_window (UserAccountDialog *d)
 {
         GtkWidget *window;
@@ -943,7 +978,6 @@ setup_main_window (UserAccountDialog *d)
         GtkCellRenderer *cell;
         GtkTreeSelection *selection;
         GtkWidget *button;
-        GSList *list, *l;
         GtkTreeIter iter;
         gint expander_size;
 
@@ -964,9 +998,7 @@ setup_main_window (UserAccountDialog *d)
         gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
         gtk_tree_view_set_model (GTK_TREE_VIEW (userlist), model);
 
-        g_signal_connect (d->um, "user-added", G_CALLBACK (user_added), d);
-        g_signal_connect (d->um, "user-removed", G_CALLBACK (user_removed), d);
-        g_signal_connect (d->um, "user-changed", G_CALLBACK (user_changed), d);
+        g_signal_connect (d->um, "users-loaded", G_CALLBACK (users_loaded), d);
 
         gtk_widget_style_get (userlist, "expander-size", &expander_size, NULL);
         gtk_tree_view_set_level_indentation (GTK_TREE_VIEW (userlist), - (expander_size + 6));
@@ -984,14 +1016,6 @@ setup_main_window (UserAccountDialog *d)
                             SORT_KEY_COL, 2,
                             -1);
 
-        list = um_user_manager_list_users (d->um);
-        g_debug ("Got %d users\n", g_slist_length (list));
-        for (l = list; l; l = l->next) {
-                g_debug ("adding user %s\n", um_user_get_real_name (l->data));
-                user_added (d->um, l->data, d);
-        }
-        g_slist_free (list);
-
         column = gtk_tree_view_column_new ();
         cell = gtk_cell_renderer_pixbuf_new ();
         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
@@ -1148,7 +1172,6 @@ main (int argc, char *argv[])
         UniqueApp *app;
         GError *error;
         const gchar *filename;
-        GtkWidget *dialog;
         GtkWidget *button;
         GOptionContext *context;
         static gboolean do_debug;
@@ -1237,19 +1260,6 @@ main (int argc, char *argv[])
         d->main_window = get_widget (d, "user-account-window");
         gtk_widget_show (d->main_window);
 
-        if (um_user_manager_no_service (d->um)) {
-                dialog = gtk_message_dialog_new (GTK_WINDOW (d->main_window),
-                                                 GTK_DIALOG_MODAL,
-                                                 GTK_MESSAGE_OTHER,
-                                                 GTK_BUTTONS_CLOSE,
-                                                 _("Failed to contact the accounts service"));
-                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                          _("Please make sure that the AccountService is installed and enabled."));
-                g_signal_connect (dialog, "response",
-                                  G_CALLBACK (gtk_main_quit), NULL);
-                gtk_widget_show (dialog);
-        }
-
         gtk_main ();
 
         return 0;
diff --git a/src/um-user-manager.c b/src/um-user-manager.c
index 00c92ff..4f45eff 100644
--- a/src/um-user-manager.c
+++ b/src/um-user-manager.c
@@ -44,6 +44,7 @@
 #include "um-user-manager.h"
 
 enum {
+        USERS_LOADED,
         USER_ADDED,
         USER_REMOVED,
         USER_CHANGED,
@@ -67,6 +68,15 @@ um_user_manager_class_init (UmUserManagerClass *klass)
 
         object_class->finalize = um_user_manager_finalize;
 
+       signals [USERS_LOADED] =
+                g_signal_new ("users-loaded",
+                              G_TYPE_FROM_CLASS (klass),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (UmUserManagerClass, users_loaded),
+                              NULL, NULL,
+                              g_cclosure_marshal_VOID__VOID,
+                              G_TYPE_NONE, 0);
+
         signals [USER_ADDED] =
                 g_signal_new ("user-added",
                               G_TYPE_FROM_CLASS (klass),
@@ -145,26 +155,43 @@ add_user (const gchar   *object_path,
 }
 
 static void
-get_users (UmUserManager *manager)
+got_users (DBusGProxy     *proxy,
+           DBusGProxyCall *call_id,
+           gpointer        data)
 {
+        UmUserManager *manager = data;
         GError *error = NULL;
         GPtrArray *paths;
 
-        if (!dbus_g_proxy_call (manager->proxy,
-                                "ListCachedUsers",
-                                &error,
-                                G_TYPE_INVALID,
-                                dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &paths,
-                                G_TYPE_INVALID)) {
-		manager->no_service = TRUE;
+        if (!dbus_g_proxy_end_call (proxy,
+                                    call_id,
+                                    &error,
+                                    dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &paths,
+                                    G_TYPE_INVALID)) {
+                manager->no_service = TRUE;
                 g_error_free (error);
-                return;
+                goto done;
         }
 
         g_ptr_array_foreach (paths, (GFunc)add_user, manager);
 
         g_ptr_array_foreach (paths, (GFunc)g_free, NULL);
         g_ptr_array_free (paths, TRUE);
+
+ done:
+        g_signal_emit (G_OBJECT (manager), signals[USERS_LOADED], 0);
+}
+
+static void
+get_users (UmUserManager *manager)
+{
+        g_debug ("calling 'ListCachedUsers'");
+        dbus_g_proxy_begin_call (manager->proxy,
+                                 "ListCachedUsers",
+                                 got_users,
+                                 manager,
+                                 NULL,
+                                 G_TYPE_INVALID);
 }
 
 static void
@@ -282,5 +309,5 @@ um_user_manager_get_user (UmUserManager *manager,
 gboolean
 um_user_manager_no_service (UmUserManager *manager)
 {
-	return manager->no_service;
+        return manager->no_service;
 }
diff --git a/src/um-user-manager.h b/src/um-user-manager.h
index 6ad6001..0c263ef 100644
--- a/src/um-user-manager.h
+++ b/src/um-user-manager.h
@@ -52,6 +52,7 @@ typedef struct
 {
         GObjectClass   parent_class;
 
+        void          (* users_loaded)              (UmUserManager *user_managaer);
         void          (* user_added)                (UmUserManager *user_manager,
                                                      UmUser        *user);
         void          (* user_removed)              (UmUserManager *user_manager,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]