[gnome-calendar] search: use new compare function



commit edec70fe0db8daa330c3fb7d2deb082c87362285
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Mon Feb 16 17:14:51 2015 -0500

    search: use new compare function

 src/gcal-search-view.c           |   27 +--------------------------
 src/gcal-shell-search-provider.c |   30 ++++++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 28 deletions(-)
---
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index 85b9e1e..005db5f 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -218,7 +218,6 @@ sort_by_event (GtkListBoxRow *row1,
   GcalEventData *ev1, *ev2;
   ECalComponentDateTime date1, date2;
   gint result;
-  time_t start1, start2, diff1, diff2;
 
   priv = gcal_search_view_get_instance_private (GCAL_SEARCH_VIEW (user_data));
 
@@ -232,31 +231,7 @@ sort_by_event (GtkListBoxRow *row1,
   e_cal_component_get_dtstart (ev1->event_component, &date1);
   e_cal_component_get_dtstart (ev2->event_component, &date2);
 
-  start1 = icaltime_as_timet_with_zone (*(date1.value), date1.value->zone != NULL ? date1.value->zone : 
e_cal_util_get_system_timezone ());
-  start2 = icaltime_as_timet_with_zone (*(date2.value), date2.value->zone != NULL ? date2.value->zone : 
e_cal_util_get_system_timezone ());
-  diff1 = start1 - priv->current_utc_date;
-  diff2 = start2 - priv->current_utc_date;
-
-  if (diff1 == diff2)
-    {
-      result = 0;
-    }
-  else
-    {
-      if (diff1 == 0)
-        result = -1;
-      else if (diff2 == 0)
-        result = 1;
-
-      if (diff1 > 0 && diff2 < 0)
-        result = -1;
-      else if (diff2 > 0 && diff1 < 0)
-        result = 1;
-      else if (diff1 < 0 && diff2 < 0)
-        result = ABS (diff1) - ABS (diff2);
-      else if (diff1 > 0 && diff2 > 0)
-        result = diff1 - diff2;
-    }
+  result = icaltime_compare_with_current (date1.value, date2.value, &(priv->current_utc_date));
 
   e_cal_component_free_datetime (&date1);
   e_cal_component_free_datetime (&date2);
diff --git a/src/gcal-shell-search-provider.c b/src/gcal-shell-search-provider.c
index 489117d..1b9b07e 100644
--- a/src/gcal-shell-search-provider.c
+++ b/src/gcal-shell-search-provider.c
@@ -62,6 +62,30 @@ free_event_data (gpointer data)
   g_free (event_data);
 }
 
+static gint
+sort_event_data (gconstpointer a,
+                 gconstpointer b,
+                 gpointer user_data)
+{
+  ECalComponent *comp1, *comp2;
+  ECalComponentDateTime date1, date2;
+  gint result;
+
+
+  comp1 = ((GcalEventData*) a)->event_component;
+  comp2 = ((GcalEventData*) b)->event_component;
+
+  e_cal_component_get_dtstart (comp1, &date1);
+  e_cal_component_get_dtstart (comp2, &date2);
+
+  result = icaltime_compare_with_current (date1.value, date2.value, user_data);
+
+  e_cal_component_free_datetime (&date1);
+  e_cal_component_free_datetime (&date2);
+
+  return result;
+}
+
 static gboolean
 execute_search (GcalShellSearchProvider *search_provider)
 {
@@ -309,6 +333,7 @@ query_completed_cb (GcalShellSearchProvider *search_provider,
 
   GcalEventData *data;
   gchar *uuid;
+  time_t current_time_t;
 
   g_hash_table_remove_all (priv->events);
 
@@ -320,8 +345,9 @@ query_completed_cb (GcalShellSearchProvider *search_provider,
     }
 
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
-  /* FIXME: add sorting and ranking */
-  //events = g_list_sort (events, search_compare_func);
+
+  current_time_t = time (NULL);
+  events = g_list_sort_with_data (events, sort_event_data, &current_time_t);
   for (l = events; l != NULL; l = g_list_next (l))
     {
       data = l->data;


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