[gnome-calendar/wip/gbsneto/gcal-event: 3/4] shell-provider: use GcalEvent instead of event data



commit f453a0d4be4eef3181ffd4837d50d1d89637e01a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Feb 10 20:58:38 2016 -0200

    shell-provider: use GcalEvent instead of event data
    
    Following the sequence of porting commits, make the Shell's
    search provider class handle events using GcalEvent classes
    instead of the old GcalEventData structure.

 src/gcal-application.c           |    4 +-
 src/gcal-application.h           |    3 +-
 src/gcal-manager.c               |   53 ++++++++-------------------
 src/gcal-manager.h               |    3 +-
 src/gcal-shell-search-provider.c |   73 +++++++++++--------------------------
 5 files changed, 44 insertions(+), 92 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 65ef2bf..ce5aa55 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -563,8 +563,8 @@ gcal_application_set_uuid (GcalApplication *application,
 
 void
 gcal_application_set_initial_date (GcalApplication *application,
-                                   const icaltimetype *date)
+                                   GDateTime       *date)
 {
   g_free (application->initial_date);
-  application->initial_date = gcal_dup_icaltime (date);
+  application->initial_date = datetime_to_icaltime (date);
 }
diff --git a/src/gcal-application.h b/src/gcal-application.h
index a80b679..82664b3 100644
--- a/src/gcal-application.h
+++ b/src/gcal-application.h
@@ -35,8 +35,9 @@ GcalManager*      gcal_application_get_manager  (GcalApplication *app);
 GSettings*        gcal_application_get_settings (GcalApplication *app);
 void              gcal_application_set_uuid     (GcalApplication *application,
                                                  const gchar     *uuid);
+
 void              gcal_application_set_initial_date (GcalApplication *application,
-                                                     const icaltimetype *date);
+                                                     GDateTime       *date);
 
 G_END_DECLS
 
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 8b60625..8d9784c 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -17,7 +17,6 @@
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "gcal-event.h"
 #include "gcal-manager.h"
 #include "gcal-utils.h"
 
@@ -264,25 +263,6 @@ free_unit_data (GcalManagerUnit *data)
 }
 
 static gboolean
-gather_components (ECalDataModel         *data_model,
-                   ECalClient            *client,
-                   const ECalComponentId *id,
-                   ECalComponent         *comp,
-                   time_t                 instance_start,
-                   time_t                 instance_end,
-                   gpointer               user_data)
-{
-  GList **result = user_data;
-  GcalEventData *new_data = g_new0 (GcalEventData, 1);
-
-  new_data->source = e_client_get_source (E_CLIENT (client));
-  new_data->event_component = g_object_ref (comp);
-  *result = g_list_append (*result, new_data);/* FIXME: add me sorted */
-
-  return TRUE;
-}
-
-static gboolean
 gather_events (ECalDataModel         *data_model,
                ECalClient            *client,
                const ECalComponentId *id,
@@ -1112,7 +1092,7 @@ gcal_manager_get_shell_search_events (GcalManager *manager)
 
   e_cal_data_model_get_subscriber_range (manager->shell_search_data_model, 
manager->search_view_data->subscriber,
                                          &range_start, &range_end);
-  e_cal_data_model_foreach_component (manager->shell_search_data_model, range_start, range_end, 
gather_components, &list);
+  e_cal_data_model_foreach_component (manager->shell_search_data_model, range_start, range_end, 
gather_events, &list);
   return list;
 }
 
@@ -1552,39 +1532,38 @@ gcal_manager_load_completed (GcalManager *manager)
   return manager->sources_at_launch == 0;
 }
 
-GcalEventData*
+GcalEvent*
 gcal_manager_get_event_from_shell_search (GcalManager *manager,
                                           const gchar *uuid)
 {
+  GcalEvent *new_event;
+  GList *l, *list;
   time_t range_start, range_end;
-  GList *l, *list = NULL;
-  GcalEventData *data, *new_data = NULL;
-  gchar *cuuid;
+
+  list = NULL;
+  new_event = NULL;
 
   e_cal_data_model_get_subscriber_range (manager->shell_search_data_model, 
manager->search_view_data->subscriber,
                                          &range_start, &range_end);
-  e_cal_data_model_foreach_component (manager->shell_search_data_model, range_start, range_end, 
gather_components, &list);
-  if (list != NULL)
-    new_data = g_new0 (GcalEventData, 1);
+  e_cal_data_model_foreach_component (manager->shell_search_data_model, range_start, range_end, 
gather_events, &list);
 
   for (l = list; l != NULL; l = g_list_next (l))
     {
-      data = l->data;
-      cuuid = get_uuid_from_component (data->source, data->event_component);
+      GcalEvent *event;
+
+      event = g_object_ref_sink (l->data);
 
-      if (g_strcmp0 (cuuid, uuid) == 0)
+      if (g_strcmp0 (gcal_event_get_uid (event), uuid) == 0)
         {
-          new_data->source = data->source;
-          new_data->event_component = g_object_ref (data->event_component);
+          new_event = event;
+          break;
         }
 
-      g_object_unref (data->event_component);
-      g_free (data);
-      g_free (cuuid);
+      g_object_unref (event);
     }
   g_list_free (list);
 
-  return new_data;
+  return new_event;
 }
 
 gboolean
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index f12e960..0b6ef91 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -21,6 +21,7 @@
 #define __GCAL_MANAGER_H__
 
 #include "e-cal-data-model.h"
+#include "gcal-event.h"
 
 #include <libical/icaltime.h>
 #include <goa/goa.h>
@@ -134,7 +135,7 @@ GList*         gcal_manager_get_events              (GcalManager        *manager
 
 gboolean       gcal_manager_load_completed          (GcalManager        *manager);
 
-GcalEventData* gcal_manager_get_event_from_shell_search (GcalManager        *manager,
+GcalEvent*     gcal_manager_get_event_from_shell_search (GcalManager        *manager,
                                                          const gchar        *uuid);
 
 gboolean       gcal_manager_is_goa_client_ready    (GcalManager        *manager);
diff --git a/src/gcal-shell-search-provider.c b/src/gcal-shell-search-provider.c
index 19e4f13..5be3f0c 100644
--- a/src/gcal-shell-search-provider.c
+++ b/src/gcal-shell-search-provider.c
@@ -20,6 +20,7 @@
 #include "gcal-shell-search-provider-generated.h"
 
 #include "gcal-application.h"
+#include "gcal-event.h"
 #include "gcal-window.h"
 #include "gcal-utils.h"
 
@@ -54,40 +55,12 @@ G_DEFINE_TYPE_WITH_CODE (GcalShellSearchProvider, gcal_shell_search_provider, G_
                          G_ADD_PRIVATE (GcalShellSearchProvider)
                          G_IMPLEMENT_INTERFACE (E_TYPE_CAL_DATA_MODEL_SUBSCRIBER, 
gcal_subscriber_interface_init));
 
-static void
-free_event_data (gpointer data)
-{
-  GcalEventData *event_data = data;
-  g_object_unref (event_data->event_component);
-  g_free (event_data);
-}
-
 static gint
-sort_event_data (gconstpointer a,
-                 gconstpointer b,
-                 gpointer user_data)
+sort_event_data (GcalEvent *a,
+                 GcalEvent *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);
-
-  if (date1.tzid != NULL)
-    date1.value->zone = icaltimezone_get_builtin_timezone_from_tzid (date1.tzid);
-  if (date2.tzid != NULL)
-    date2.value->zone = icaltimezone_get_builtin_timezone_from_tzid (date2.tzid);
-  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;
+  return gcal_event_compare_with_current (a, b, user_data);
 }
 
 static gboolean
@@ -298,25 +271,22 @@ activate_result_cb (GcalShellSearchProvider  *search_provider,
 {
   GcalShellSearchProviderPrivate *priv;
   GApplication *application;
-  GcalEventData *data;
-  ECalComponentDateTime dtstart;
+  GcalEvent *event;
+  GDateTime *dtstart;
 
   priv = search_provider->priv;
   application = g_application_get_default ();
 
-  data = gcal_manager_get_event_from_shell_search (priv->manager, result);
-  e_cal_component_get_dtstart (data->event_component, &dtstart);
-  if (dtstart.tzid != NULL)
-    dtstart.value->zone = icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid);
+  event = gcal_manager_get_event_from_shell_search (priv->manager, result);
+  dtstart = gcal_event_get_date_start (event);
 
   gcal_application_set_uuid (GCAL_APPLICATION (application), result);
-  gcal_application_set_initial_date (GCAL_APPLICATION (application), dtstart.value);
-  e_cal_component_free_datetime (&dtstart);
+  gcal_application_set_initial_date (GCAL_APPLICATION (application), dtstart);
 
   g_application_activate (application);
 
-  g_object_unref (data->event_component);
-  g_free (data);
+  g_clear_object (&event);
+
   return TRUE;
 }
 
@@ -355,9 +325,6 @@ query_completed_cb (GcalShellSearchProvider *search_provider,
   GcalShellSearchProviderPrivate *priv = search_provider->priv;
   GList *events, *l;
   GVariantBuilder builder;
-
-  GcalEventData *data;
-  gchar *uuid;
   time_t current_time_t;
 
   g_hash_table_remove_all (priv->events);
@@ -372,15 +339,19 @@ query_completed_cb (GcalShellSearchProvider *search_provider,
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
 
   current_time_t = time (NULL);
-  events = g_list_sort_with_data (events, sort_event_data, &current_time_t);
+  events = g_list_sort_with_data (events, (GCompareDataFunc) sort_event_data, &current_time_t);
   for (l = events; l != NULL; l = g_list_next (l))
     {
-      data = l->data;
-      uuid = get_uuid_from_component (data->source, data->event_component);
+      const gchar *uid;
+
+      uid = gcal_event_get_uid (l->data);
+
+      if (g_hash_table_contains (priv->events, uid))
+        continue;
 
-      g_variant_builder_add (&builder, "s", uuid);
+      g_variant_builder_add (&builder, "s", uid);
 
-      g_hash_table_insert (priv->events, uuid, data);
+      g_hash_table_insert (priv->events, g_strdup (uid), g_object_ref_sink (l->data));
     }
   g_list_free (events);
 
@@ -456,7 +427,7 @@ gcal_shell_search_provider_init (GcalShellSearchProvider *self)
 {
   GcalShellSearchProviderPrivate *priv = gcal_shell_search_provider_get_instance_private (self);
 
-  priv->events = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_event_data);
+  priv->events = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   priv->skel = gcal_shell_search_provider2_skeleton_new ();
 
   g_signal_connect_swapped (priv->skel, "handle-get-initial-result-set", G_CALLBACK 
(get_initial_result_set_cb), self);


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