[gnome-photos/gnome-3-16] Improve the responsiveness of the favorite button



commit 3013b9308ea7b7dba36c611ab3fd06c8e5d39971
Author: Alessandro Bono <shadow openaliasbox org>
Date:   Fri Oct 23 18:24:26 2015 +0200

    Improve the responsiveness of the favorite button
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757015

 src/photos-base-item.c         |    6 +++++-
 src/photos-selection-toolbar.c |   16 +++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 3b5a4eb..8116cfd 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -404,7 +404,11 @@ photos_base_item_create_thumbnail_finish (PhotosBaseItem *self, GAsyncResult *re
 static void
 photos_base_item_default_set_favorite (PhotosBaseItem *self, gboolean favorite)
 {
-  photos_utils_set_favorite (self->priv->id, favorite);
+  PhotosBaseItemPrivate *priv = self->priv;
+
+  priv->favorite = favorite;
+  photos_base_item_check_effects_and_update_info (self);
+  photos_utils_set_favorite (priv->id, favorite);
 }
 
 
diff --git a/src/photos-selection-toolbar.c b/src/photos-selection-toolbar.c
index f32118a..30bd6ca 100644
--- a/src/photos-selection-toolbar.c
+++ b/src/photos-selection-toolbar.c
@@ -108,6 +108,7 @@ photos_selection_toolbar_favorite_clicked (GtkButton *button, gpointer user_data
 {
   PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
   PhotosSelectionToolbarPrivate *priv = self->priv;
+  GList *items = NULL;
   GList *selection;
   GList *l;
 
@@ -119,14 +120,27 @@ photos_selection_toolbar_favorite_clicked (GtkButton *button, gpointer user_data
     {
       const gchar *urn = (gchar *) l->data;
       PhotosBaseItem *item;
-      gboolean favorite;
 
       item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (priv->item_mngr, urn));
+      items = g_list_prepend (items, g_object_ref (item));
+    }
+
+  /* photos_base_item_set_favorite will emit info-updated signal while
+   * looping: there is a chance that the selection will get modified
+   * while we are iterating over it. To avoid this we make a copy of
+   * the selection and work on it.
+   */
+  for (l = items; l != NULL; l = l->next)
+    {
+      PhotosBaseItem *item = PHOTOS_BASE_ITEM (l->data);
+      gboolean favorite;
+
       favorite = photos_base_item_is_favorite (item);
       photos_base_item_set_favorite (item, !favorite);
     }
 
   photos_selection_controller_set_selection_mode (priv->sel_cntrlr, FALSE);
+  g_list_free_full (items, g_object_unref);
 }
 
 


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