[frogr] Moved the logic to compare two pictures by property to FrogrPicture



commit 4878d6748ab96325dd333205fcfef93ae143c691
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Tue Dec 29 17:15:17 2015 +0000

    Moved the logic to compare two pictures by property to FrogrPicture

 src/frogr-main-view.c |   70 +-----------------------------------------------
 src/frogr-picture.c   |   63 ++++++++++++++++++++++++++++++++++++++++++++
 src/frogr-picture.h   |    3 ++
 3 files changed, 68 insertions(+), 68 deletions(-)
---
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 1ba73f7..76dfcb2 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -254,9 +254,6 @@ static void _load_pictures (FrogrMainView *self, GSList *fileuris);
 static void _upload_pictures (FrogrMainView *self);
 static void _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean reversed);
 
-static gint _compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
-                                           const gchar *property_name);
-
 static void _progress_dialog_response (GtkDialog *dialog,
                                        gint response_id,
                                        gpointer data);
@@ -1903,8 +1900,8 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
   list_as_loaded = g_slist_copy (frogr_model_get_pictures (self->model));
   if (property_name)
     list_as_loaded = g_slist_sort_with_data (list_as_loaded,
-                                             (GCompareDataFunc) _compare_pictures_by_property,
-                                             (gchar*) property_name);
+                                             (GCompareDataFunc)frogr_picture_compare_by_property,
+                                             (gchar*)property_name);
   /* Update the list of pictures */
   if (self->sorted_pictures)
     {
@@ -1932,69 +1929,6 @@ _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean rever
   g_free (property_name);
 }
 
-static gint
-_compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
-                               const gchar *property_name)
-{
-  GParamSpec *pspec1 = NULL;
-  GParamSpec *pspec2 = NULL;
-  GValue value1 = { 0 };
-  GValue value2 = { 0 };
-  gint result = 0;
-
-  g_return_val_if_fail (FROGR_IS_PICTURE (p1), 0);
-  g_return_val_if_fail (FROGR_IS_PICTURE (p2), 0);
-
-  pspec1 = g_object_class_find_property (G_OBJECT_GET_CLASS (p1), property_name);
-  pspec2 = g_object_class_find_property (G_OBJECT_GET_CLASS (p2), property_name);
-
-  /* They should be the same! */
-  if (pspec1->value_type != pspec2->value_type)
-    return 0;
-
-  g_value_init (&value1, pspec1->value_type);
-  g_value_init (&value2, pspec1->value_type);
-
-  g_object_get_property (G_OBJECT (p1), property_name, &value1);
-  g_object_get_property (G_OBJECT (p2), property_name, &value2);
-
-  if (G_VALUE_HOLDS_BOOLEAN (&value1))
-    result = g_value_get_boolean (&value1) - g_value_get_boolean (&value2);
-  else if (G_VALUE_HOLDS_INT (&value1))
-    result = g_value_get_int (&value1) - g_value_get_int (&value2);
-  else if (G_VALUE_HOLDS_UINT (&value1))
-    result = g_value_get_uint (&value1) - g_value_get_uint (&value2);
-  else if (G_VALUE_HOLDS_LONG (&value1))
-    result = g_value_get_long (&value1) - g_value_get_long (&value2);
-  else if (G_VALUE_HOLDS_STRING (&value1))
-    {
-      const gchar *str1 = NULL;
-      const gchar *str2 = NULL;
-      gchar *str1_cf = NULL;
-      gchar *str2_cf = NULL;
-
-      /* Comparison of strings require some additional work to take
-         into account the different rules for each locale */
-      str1 = g_value_get_string (&value1);
-      str2 = g_value_get_string (&value2);
-
-      str1_cf = g_utf8_casefold (str1 ? str1 : "", -1);
-      str2_cf = g_utf8_casefold (str2 ? str2 : "", -1);
-
-      result = g_utf8_collate (str1_cf, str2_cf);
-
-      g_free (str1_cf);
-      g_free (str2_cf);
-    }
-  else
-    g_warning ("Unsupported type for property used for sorting");
-
-  g_value_unset (&value1);
-  g_value_unset (&value2);
-
-  return result;
-}
-
 static void
 _progress_dialog_response (GtkDialog *dialog,
                            gint response_id,
diff --git a/src/frogr-picture.c b/src/frogr-picture.c
index d51c320..f36e371 100644
--- a/src/frogr-picture.c
+++ b/src/frogr-picture.c
@@ -1181,3 +1181,66 @@ frogr_picture_in_group (FrogrPicture *self, FrogrGroup *group)
 
   return FALSE;
 }
+
+gint
+frogr_picture_compare_by_property (FrogrPicture *self, FrogrPicture *other,
+                                   const gchar *property_name)
+{
+  GParamSpec *pspec1 = NULL;
+  GParamSpec *pspec2 = NULL;
+  GValue value1 = { 0 };
+  GValue value2 = { 0 };
+  gint result = 0;
+
+  g_return_val_if_fail (FROGR_IS_PICTURE (self), 1);
+  g_return_val_if_fail (FROGR_IS_PICTURE (other), -1);
+
+  pspec1 = g_object_class_find_property (G_OBJECT_GET_CLASS (self), property_name);
+  pspec2 = g_object_class_find_property (G_OBJECT_GET_CLASS (other), property_name);
+
+  /* They should be the same! */
+  if (pspec1->value_type != pspec2->value_type)
+    return 0;
+
+  g_value_init (&value1, pspec1->value_type);
+  g_value_init (&value2, pspec1->value_type);
+
+  g_object_get_property (G_OBJECT (self), property_name, &value1);
+  g_object_get_property (G_OBJECT (other), property_name, &value2);
+
+  if (G_VALUE_HOLDS_BOOLEAN (&value1))
+    result = g_value_get_boolean (&value1) - g_value_get_boolean (&value2);
+  else if (G_VALUE_HOLDS_INT (&value1))
+    result = g_value_get_int (&value1) - g_value_get_int (&value2);
+  else if (G_VALUE_HOLDS_UINT (&value1))
+    result = g_value_get_uint (&value1) - g_value_get_uint (&value2);
+  else if (G_VALUE_HOLDS_LONG (&value1))
+    result = g_value_get_long (&value1) - g_value_get_long (&value2);
+  else if (G_VALUE_HOLDS_STRING (&value1))
+    {
+      const gchar *str1 = NULL;
+      const gchar *str2 = NULL;
+      gchar *str1_cf = NULL;
+      gchar *str2_cf = NULL;
+
+      /* Comparison of strings require some additional work to take
+         into account the different rules for each locale */
+      str1 = g_value_get_string (&value1);
+      str2 = g_value_get_string (&value2);
+
+      str1_cf = g_utf8_casefold (str1 ? str1 : "", -1);
+      str2_cf = g_utf8_casefold (str2 ? str2 : "", -1);
+
+      result = g_utf8_collate (str1_cf, str2_cf);
+
+      g_free (str1_cf);
+      g_free (str2_cf);
+    }
+  else
+    g_warning ("Unsupported type for property used for sorting");
+
+  g_value_unset (&value1);
+  g_value_unset (&value2);
+
+  return result;
+}
diff --git a/src/frogr-picture.h b/src/frogr-picture.h
index 46a1e34..68e97ba 100644
--- a/src/frogr-picture.h
+++ b/src/frogr-picture.h
@@ -124,6 +124,9 @@ void frogr_picture_add_group (FrogrPicture *self, FrogrGroup *group);
 void frogr_picture_remove_groups (FrogrPicture *self);
 gboolean frogr_picture_in_group (FrogrPicture *self, FrogrGroup *group);
 
+gint frogr_picture_compare_by_property (FrogrPicture *self, FrogrPicture *other,
+                                        const gchar *property_name);
+
 G_END_DECLS
 
 #endif


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