[gnome-calendar/wip/gbsneto/gcal-event: 5/13] shell-provider: use GcalEvent instead of event data
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/gcal-event: 5/13] shell-provider: use GcalEvent instead of event data
- Date: Sun, 14 Feb 2016 14:20:02 +0000 (UTC)
commit eb360dc80962d71a2f532dbbae214378b332b3f1
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 | 126 ++++++++++---------------------------
5 files changed, 56 insertions(+), 133 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..675c3ca 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;
- if (g_strcmp0 (cuuid, uuid) == 0)
+ event = l->data;
+
+ 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;
}
- 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..c13e505 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
@@ -214,22 +187,14 @@ get_result_metas_cb (GcalShellSearchProvider *search_provider,
GcalShellSearchProvider2 *skel)
{
GcalShellSearchProviderPrivate *priv;
- gint i;
- gchar *uuid, *desc;
- const gchar* location;
-
- g_autoptr(GTimeZone) tz;
- g_autoptr (GDateTime) datetime;
- g_autoptr (GDateTime) local_datetime;
- ECalComponentDateTime dtstart;
- gchar *start_date;
-
- ECalComponentText summary;
- GdkRGBA color;
+ GDateTime *local_datetime;
GVariantBuilder abuilder, builder;
GVariant *icon_variant;
- GcalEventData *data;
+ GcalEvent *event;
GdkPixbuf *gicon;
+ gchar *uuid, *desc;
+ gchar *start_date;
+ gint i;
priv = search_provider->priv;
@@ -237,50 +202,29 @@ get_result_metas_cb (GcalShellSearchProvider *search_provider,
for (i = 0; i < g_strv_length (results); i++)
{
uuid = results[i];
- data = g_hash_table_lookup (priv->events, uuid);
+ event = g_hash_table_lookup (priv->events, uuid);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "id", g_variant_new_string (uuid));
+ g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (gcal_event_get_summary
(event)));
- e_cal_component_get_summary (data->event_component, &summary);
- g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (summary.value));
-
- get_color_name_from_source (data->source, &color);
- gicon = get_circle_pixbuf_from_color (&color, 128);
+ gicon = get_circle_pixbuf_from_color (gcal_event_get_color (event), 128);
icon_variant = g_icon_serialize (G_ICON (gicon));
g_variant_builder_add (&builder, "{sv}", "icon", icon_variant);
g_object_unref (gicon);
g_variant_unref (icon_variant);
- e_cal_component_get_dtstart (data->event_component, &dtstart);
-
- if (dtstart.tzid != NULL)
- tz = g_time_zone_new (dtstart.tzid);
- else if (dtstart.value->zone != NULL)
- tz = g_time_zone_new (icaltimezone_get_tzid ((icaltimezone*) dtstart.value->zone));
- else
- tz = g_time_zone_new_local ();
-
- datetime = g_date_time_new (tz,
- dtstart.value->year, dtstart.value->month, dtstart.value->day,
- dtstart.value->hour, dtstart.value->minute, dtstart.value->second);
- local_datetime = g_date_time_to_local (datetime);
+ local_datetime = g_date_time_to_local (gcal_event_get_date_start (event));
/* FIXME: respect 24h time format */
- start_date = g_date_time_format (local_datetime,
- (dtstart.value->is_date == 1) ? "%x" : "%c");
- e_cal_component_free_datetime (&dtstart);
+ start_date = g_date_time_format (local_datetime, gcal_event_get_all_day (event) ? "%x" : "%c");
- e_cal_component_get_location (data->event_component, &location);
- if (location != NULL)
- desc = g_strconcat (start_date, ". ", location, NULL);
+ if (gcal_event_get_location (event))
+ desc = g_strconcat (start_date, ". ", gcal_event_get_location (event), NULL);
else
desc = g_strdup (start_date);
g_variant_builder_add (&builder, "{sv}", "description", g_variant_new_string (desc));
- g_free (start_date);
- g_free (desc);
-
g_variant_builder_add_value (&abuilder, g_variant_builder_end (&builder));
}
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aa{sv})", &abuilder));
@@ -298,25 +242,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 +296,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 +310,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, ¤t_time_t);
+ events = g_list_sort_with_data (events, (GCompareDataFunc) sort_event_data, ¤t_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), l->data);
}
g_list_free (events);
@@ -456,7 +398,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]