[frogr] Properly reorder pictures list in model in reverse order



commit 9adc033131e13704bc0fd5c87a70a959ae904ca6
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Mon Apr 25 22:13:00 2011 -0700

    Properly reorder pictures list in model in reverse order

 src/frogr-main-view-model.c |   30 ++++++++++++++----------------
 src/frogr-main-view-model.h |    2 +-
 src/frogr-main-view.c       |    2 +-
 3 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/src/frogr-main-view-model.c b/src/frogr-main-view-model.c
index bdcbe6e..4ed9d23 100644
--- a/src/frogr-main-view-model.c
+++ b/src/frogr-main-view-model.c
@@ -39,6 +39,7 @@ struct _FrogrMainViewModelPrivate
 {
   GSList *pictures_list;
   guint n_pictures;
+  gboolean pictures_list_reversed;
 
   GSList *sets_list;
   guint n_sets;
@@ -66,8 +67,8 @@ static guint signals[N_SIGNALS] = { 0 };
 /* Private API */
 
 static gint
-_compare_pictures_by_property_asc (FrogrPicture *p1, FrogrPicture *p2,
-                                   const gchar *property_name)
+_compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
+                               const gchar *property_name)
 {
   g_return_val_if_fail (FROGR_IS_PICTURE (p1), 0);
   g_return_val_if_fail (FROGR_IS_PICTURE (p2), 0);
@@ -108,13 +109,6 @@ _compare_pictures_by_property_asc (FrogrPicture *p1, FrogrPicture *p2,
   return result;
 }
 
-static gint
-_compare_pictures_by_property_desc (FrogrPicture *p1, FrogrPicture *p2,
-                                   const gchar *property_name)
-{
-  return _compare_pictures_by_property_asc (p2, p1, property_name);
-}
-
 static void
 _frogr_main_view_model_dispose (GObject* object)
 {
@@ -211,6 +205,7 @@ frogr_main_view_model_init (FrogrMainViewModel *self)
   /* Init private data */
   priv->pictures_list = NULL;
   priv->n_pictures = 0;
+  priv->pictures_list_reversed = FALSE;
 
   priv->sets_list = NULL;
   priv->n_sets = 0;
@@ -291,12 +286,11 @@ frogr_main_view_model_get_pictures (FrogrMainViewModel *self)
 void
 frogr_main_view_model_reorder_pictures (FrogrMainViewModel *self,
                                         const gchar *property_name,
-                                        gboolean ascending)
+                                        gboolean reversed)
 {
   g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
 
   FrogrMainViewModelPrivate *priv = NULL;
-  GCompareDataFunc compare_func = NULL;
   GSList *old_list = NULL;
   GSList *old_item = NULL;
   gint *new_order = 0;
@@ -310,15 +304,19 @@ frogr_main_view_model_reorder_pictures (FrogrMainViewModel *self,
   old_list = g_slist_copy (priv->pictures_list);
   new_order = g_new0 (gint, g_slist_length (old_list));
 
-  if (ascending)
-    compare_func = (GCompareDataFunc) _compare_pictures_by_property_asc;
-  else
-    compare_func = (GCompareDataFunc) _compare_pictures_by_property_desc;
+  /* If list was reversed, re-reverse it before sorting */
+  if (priv->pictures_list_reversed)
+    priv->pictures_list = g_slist_reverse (priv->pictures_list);
 
+  priv->pictures_list_reversed = reversed;
   priv->pictures_list = g_slist_sort_with_data (priv->pictures_list,
-                                                compare_func,
+                                                (GCompareDataFunc) _compare_pictures_by_property,
                                                 (gchar*) property_name);
 
+  /* If we're reordering in reverse order, reverse the result list */
+  if (reversed)
+    priv->pictures_list = g_slist_reverse (priv->pictures_list);
+
   /* Build the new_order array */
   old_pos = 0;
   for (old_item = old_list; old_item; old_item = g_slist_next (old_item))
diff --git a/src/frogr-main-view-model.h b/src/frogr-main-view-model.h
index b856d43..edbbade 100644
--- a/src/frogr-main-view-model.h
+++ b/src/frogr-main-view-model.h
@@ -68,7 +68,7 @@ GSList *frogr_main_view_model_get_pictures (FrogrMainViewModel *self);
 
 void frogr_main_view_model_reorder_pictures (FrogrMainViewModel *self,
                                              const gchar *property_name,
-                                             gboolean ascending);
+                                             gboolean reversed);
 
 void frogr_main_view_model_add_set (FrogrMainViewModel *self,
                                     FrogrPhotoSet *fset);
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 29ab767..dac574b 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -1333,7 +1333,7 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, SortingDirecti
 
   if (property_name)
     {
-      frogr_main_view_model_reorder_pictures (priv->model, property_name, ascending);
+      frogr_main_view_model_reorder_pictures (priv->model, property_name, !ascending);
       g_free (property_name);
     }
 }



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