[gdm/gnome-2-30] Only load icons for visible items



commit 03b43b90827dc7f391a4d7e78f9d12ef86c6c4ec
Author: William Jon McCann <jmccann redhat com>
Date:   Tue Jun 8 19:01:42 2010 -0400

    Only load icons for visible items
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621045

 gui/simple-greeter/gdm-chooser-widget.c          |   66 ++++++++++++-
 gui/simple-greeter/gdm-chooser-widget.h          |    8 ++-
 gui/simple-greeter/gdm-language-chooser-widget.c |    4 +-
 gui/simple-greeter/gdm-layout-chooser-widget.c   |    4 +-
 gui/simple-greeter/gdm-user-chooser-widget.c     |  117 +++++++++++++---------
 5 files changed, 147 insertions(+), 52 deletions(-)
---
diff --git a/gui/simple-greeter/gdm-chooser-widget.c b/gui/simple-greeter/gdm-chooser-widget.c
index 6ffaf69..8cda723 100644
--- a/gui/simple-greeter/gdm-chooser-widget.c
+++ b/gui/simple-greeter/gdm-chooser-widget.c
@@ -139,6 +139,8 @@ enum {
         CHOOSER_TIMER_DURATION_COLUMN,
         CHOOSER_TIMER_VALUE_COLUMN,
         CHOOSER_ID_COLUMN,
+        CHOOSER_LOAD_FUNC_COLUMN,
+        CHOOSER_LOAD_DATA_COLUMN,
         NUMBER_OF_CHOOSER_COLUMNS
 };
 
@@ -598,9 +600,49 @@ update_separator_visibility (GdmChooserWidget *widget)
                             -1);
 }
 
+static void
+update_visible_items (GdmChooserWidget *widget)
+{
+        GtkTreePath *path;
+        GtkTreePath *end;
+        GtkTreeIter  iter;
+
+        if (! gtk_tree_view_get_visible_range (GTK_TREE_VIEW (widget->priv->items_view), &path, &end)) {
+                g_debug ("Unable to get visible range");
+                return;
+        }
+
+        for (; gtk_tree_path_compare (path, end) <= 0; gtk_tree_path_next (path)) {
+                char                        *id;
+                gpointer                     user_data;
+                GdmChooserWidgetItemLoadFunc func;
+
+                if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (widget->priv->model_sorter), &iter, path))
+                        break;
+
+                id = NULL;
+                gtk_tree_model_get (GTK_TREE_MODEL (widget->priv->model_sorter),
+                                    &iter,
+                                    CHOOSER_ID_COLUMN, &id,
+                                    CHOOSER_LOAD_FUNC_COLUMN, &func,
+                                    CHOOSER_LOAD_DATA_COLUMN, &user_data,
+                                    -1);
+                if (id != NULL && func != NULL) {
+                        func (widget, id, user_data);
+                }
+
+                g_free (id);
+        }
+
+        gtk_tree_path_free (path);
+        gtk_tree_path_free (end);
+}
+
 static gboolean
 update_chooser_visibility (GdmChooserWidget *widget)
 {
+        update_visible_items (widget);
+
         if (gdm_chooser_widget_get_number_of_items (widget) > 0) {
                 gtk_widget_show (widget->priv->frame);
         } else {
@@ -1783,11 +1825,20 @@ on_selection_changed (GtkTreeSelection *selection,
 }
 
 static void
+on_adjustment_value_changed (GtkAdjustment    *adjustment,
+                             GdmChooserWidget *widget)
+{
+        g_debug ("Treeview scrolled");
+        update_visible_items (widget);
+}
+
+static void
 gdm_chooser_widget_init (GdmChooserWidget *widget)
 {
         GtkTreeViewColumn *column;
         GtkTreeSelection  *selection;
         GtkCellRenderer   *renderer;
+        GtkAdjustment     *adjustment;
 
         widget->priv = GDM_CHOOSER_WIDGET_GET_PRIVATE (widget);
 
@@ -1841,7 +1892,7 @@ gdm_chooser_widget_init (GdmChooserWidget *widget)
 
         g_signal_connect (selection, "changed", G_CALLBACK (on_selection_changed), widget);
 
-        g_assert (NUMBER_OF_CHOOSER_COLUMNS == 11);
+        g_assert (NUMBER_OF_CHOOSER_COLUMNS == 13);
         widget->priv->list_store = gtk_list_store_new (NUMBER_OF_CHOOSER_COLUMNS,
                                                        GDK_TYPE_PIXBUF,
                                                        G_TYPE_STRING,
@@ -1853,7 +1904,9 @@ gdm_chooser_widget_init (GdmChooserWidget *widget)
                                                        G_TYPE_DOUBLE,
                                                        G_TYPE_DOUBLE,
                                                        G_TYPE_DOUBLE,
-                                                       G_TYPE_STRING);
+                                                       G_TYPE_STRING,
+                                                       G_TYPE_POINTER,
+                                                       G_TYPE_POINTER);
 
         widget->priv->model_filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (widget->priv->list_store), NULL));
 
@@ -1936,6 +1989,9 @@ gdm_chooser_widget_init (GdmChooserWidget *widget)
 
         add_separator (widget);
         queue_column_visibility_update (widget);
+
+        adjustment = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (widget->priv->items_view));
+        g_signal_connect (adjustment, "value-changed", G_CALLBACK (on_adjustment_value_changed), widget);
 }
 
 static void
@@ -2070,7 +2126,9 @@ gdm_chooser_widget_add_item (GdmChooserWidget *widget,
                              const char       *comment,
                              gulong            priority,
                              gboolean          in_use,
-                             gboolean          keep_separate)
+                             gboolean          keep_separate,
+                             GdmChooserWidgetItemLoadFunc load_func,
+                             gpointer                     load_data)
 {
         gboolean is_visible;
 
@@ -2105,6 +2163,8 @@ gdm_chooser_widget_add_item (GdmChooserWidget *widget,
                                            CHOOSER_ITEM_IS_SEPARATED_COLUMN, keep_separate,
                                            CHOOSER_ITEM_IS_VISIBLE_COLUMN, is_visible,
                                            CHOOSER_ID_COLUMN, id,
+                                           CHOOSER_LOAD_FUNC_COLUMN, load_func,
+                                           CHOOSER_LOAD_DATA_COLUMN, load_data,
                                            -1);
 
         queue_move_cursor_to_top (widget);
diff --git a/gui/simple-greeter/gdm-chooser-widget.h b/gui/simple-greeter/gdm-chooser-widget.h
index 7e3e59c..11a6456 100644
--- a/gui/simple-greeter/gdm-chooser-widget.h
+++ b/gui/simple-greeter/gdm-chooser-widget.h
@@ -57,6 +57,10 @@ typedef enum {
         GDM_CHOOSER_WIDGET_POSITION_BOTTOM,
 } GdmChooserWidgetPosition;
 
+typedef void     (*GdmChooserWidgetItemLoadFunc)         (GdmChooserWidget *widget,
+                                                          const char       *id,
+                                                          gpointer          data);
+
 typedef gboolean (*GdmChooserUpdateForeachFunc)          (GdmChooserWidget *widget,
                                                           const char       *id,
                                                           GdkPixbuf       **image,
@@ -78,7 +82,9 @@ void         gdm_chooser_widget_add_item                     (GdmChooserWidget *
                                                               const char       *comment,
                                                               gulong            priority,
                                                               gboolean          is_in_use,
-                                                              gboolean          keep_separate);
+                                                              gboolean          keep_separate,
+                                                              GdmChooserWidgetItemLoadFunc load_func,
+                                                              gpointer                     load_data);
 
 void         gdm_chooser_widget_update_foreach_item          (GdmChooserWidget           *widget,
                                                               GdmChooserUpdateForeachFunc cb,
diff --git a/gui/simple-greeter/gdm-language-chooser-widget.c b/gui/simple-greeter/gdm-language-chooser-widget.c
index 7594cf7..305044a 100644
--- a/gui/simple-greeter/gdm-language-chooser-widget.c
+++ b/gui/simple-greeter/gdm-language-chooser-widget.c
@@ -121,7 +121,9 @@ gdm_language_chooser_widget_add_language (GdmLanguageChooserWidget *widget,
                                              readable_language,
                                              0,
                                              FALSE,
-                                             FALSE);
+                                             FALSE,
+                                             NULL,
+                                             NULL);
                 g_free (language);
         }
         g_free (readable_language);
diff --git a/gui/simple-greeter/gdm-layout-chooser-widget.c b/gui/simple-greeter/gdm-layout-chooser-widget.c
index f3d66a4..9d85eb1 100644
--- a/gui/simple-greeter/gdm-layout-chooser-widget.c
+++ b/gui/simple-greeter/gdm-layout-chooser-widget.c
@@ -108,7 +108,9 @@ gdm_layout_chooser_widget_add_layout (GdmLayoutChooserWidget *widget,
                                              NULL,
                                              0,
                                              FALSE,
-                                             FALSE);
+                                             FALSE,
+                                             NULL,
+                                             NULL);
                 g_free (escaped);
                 g_free (layout);
         }
diff --git a/gui/simple-greeter/gdm-user-chooser-widget.c b/gui/simple-greeter/gdm-user-chooser-widget.c
index aaa33ab..bb0087f 100644
--- a/gui/simple-greeter/gdm-user-chooser-widget.c
+++ b/gui/simple-greeter/gdm-user-chooser-widget.c
@@ -168,6 +168,63 @@ queue_update_other_user_visibility (GdmUserChooserWidget *widget)
 }
 
 static void
+update_item_for_user (GdmUserChooserWidget *widget,
+                      GdmUser              *user)
+{
+        GdkPixbuf    *pixbuf;
+        char         *tooltip;
+        gboolean      is_logged_in;
+        int           size;
+
+
+        size = get_icon_height_for_widget (GTK_WIDGET (widget));
+        pixbuf = gdm_user_render_icon (user, size);
+
+        if (pixbuf == NULL && widget->priv->stock_person_pixbuf != NULL) {
+                pixbuf = g_object_ref (widget->priv->stock_person_pixbuf);
+        }
+
+        tooltip = g_strdup_printf (_("Log in as %s"),
+                                   gdm_user_get_user_name (user));
+
+        is_logged_in = gdm_user_is_logged_in (user);
+
+        g_debug ("GdmUserChooserWidget: User added name:%s logged-in:%d pixbuf:%p",
+                 gdm_user_get_user_name (user),
+                 is_logged_in,
+                 pixbuf);
+
+        gdm_chooser_widget_update_item (GDM_CHOOSER_WIDGET (widget),
+                                        gdm_user_get_user_name (user),
+                                        pixbuf,
+                                        gdm_user_get_real_name (user),
+                                        tooltip,
+                                        gdm_user_get_login_frequency (user),
+                                        is_logged_in,
+                                        FALSE);
+        g_free (tooltip);
+
+        if (pixbuf != NULL) {
+                g_object_unref (pixbuf);
+        }
+}
+
+static void
+on_item_load (GdmChooserWidget     *widget,
+              const char           *id,
+              GdmUserChooserWidget *user_chooser)
+{
+        GdmUser *user;
+
+        g_debug ("GdmUserChooserWidget: Loading item for id=%s", id);
+
+        user = gdm_user_manager_get_user (user_chooser->priv->manager, id);
+        if (user != NULL) {
+                update_item_for_user (user_chooser, user);
+        }
+}
+
+static void
 add_user_other (GdmUserChooserWidget *widget)
 {
         widget->priv->has_user_other = TRUE;
@@ -183,7 +240,9 @@ add_user_other (GdmUserChooserWidget *widget)
                                      _("Choose a different account"),
                                      0,
                                      FALSE,
-                                     TRUE);
+                                     TRUE,
+                                     (GdmChooserWidgetItemLoadFunc) on_item_load,
+                                     widget);
 }
 
 static void
@@ -196,7 +255,9 @@ add_user_guest (GdmUserChooserWidget *widget)
                                      _("Login as a temporary guest"),
                                      0,
                                      FALSE,
-                                     TRUE);
+                                     TRUE,
+                                     (GdmChooserWidgetItemLoadFunc) on_item_load,
+                                     widget);
         queue_update_other_user_visibility (widget);
 }
 
@@ -210,7 +271,9 @@ add_user_auto (GdmUserChooserWidget *widget)
                                      _("Automatically login to the system after selecting options"),
                                      0,
                                      FALSE,
-                                     TRUE);
+                                     TRUE,
+                                     (GdmChooserWidgetItemLoadFunc) on_item_load,
+                                     widget);
         queue_update_other_user_visibility (widget);
 }
 
@@ -386,18 +449,12 @@ add_user (GdmUserChooserWidget *widget,
         GdkPixbuf    *pixbuf;
         char         *tooltip;
         gboolean      is_logged_in;
-        int           size;
 
         if (!widget->priv->show_normal_users) {
                 return;
         }
 
-        size = get_icon_height_for_widget (GTK_WIDGET (widget));
-        pixbuf = gdm_user_render_icon (user, size);
-        if (pixbuf == NULL && widget->priv->stock_person_pixbuf != NULL) {
-                pixbuf = g_object_ref (widget->priv->stock_person_pixbuf);
-        }
-
+        pixbuf = NULL;
         tooltip = g_strdup_printf (_("Log in as %s"),
                                    gdm_user_get_user_name (user));
 
@@ -415,7 +472,9 @@ add_user (GdmUserChooserWidget *widget,
                                      tooltip,
                                      gdm_user_get_login_frequency (user),
                                      is_logged_in,
-                                     FALSE);
+                                     FALSE,
+                                     (GdmChooserWidgetItemLoadFunc) on_item_load,
+                                     widget);
         g_free (tooltip);
 
         if (pixbuf != NULL) {
@@ -481,11 +540,6 @@ on_user_changed (GdmUserManager       *manager,
                  GdmUser              *user,
                  GdmUserChooserWidget *widget)
 {
-        GdkPixbuf    *pixbuf;
-        char         *tooltip;
-        gboolean      is_logged_in;
-        int           size;
-
         /* wait for all users to be loaded */
         if (! widget->priv->loaded) {
                 return;
@@ -494,36 +548,7 @@ on_user_changed (GdmUserManager       *manager,
                 return;
         }
 
-        size = get_icon_height_for_widget (GTK_WIDGET (widget));
-        pixbuf = gdm_user_render_icon (user, size);
-
-        if (pixbuf == NULL && widget->priv->stock_person_pixbuf != NULL) {
-                pixbuf = g_object_ref (widget->priv->stock_person_pixbuf);
-        }
-
-        tooltip = g_strdup_printf (_("Log in as %s"),
-                                   gdm_user_get_user_name (user));
-
-        is_logged_in = gdm_user_is_logged_in (user);
-
-        g_debug ("GdmUserChooserWidget: User added name:%s logged-in:%d pixbuf:%p",
-                 gdm_user_get_user_name (user),
-                 is_logged_in,
-                 pixbuf);
-
-        gdm_chooser_widget_update_item (GDM_CHOOSER_WIDGET (widget),
-                                        gdm_user_get_user_name (user),
-                                        pixbuf,
-                                        gdm_user_get_real_name (user),
-                                        tooltip,
-                                        gdm_user_get_login_frequency (user),
-                                        is_logged_in,
-                                        FALSE);
-        g_free (tooltip);
-
-        if (pixbuf != NULL) {
-                g_object_unref (pixbuf);
-        }
+        update_item_for_user (widget, user);
 }
 
 static void



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