[gnome-calendar/gbsneto/range: 10/12] event: Use GcalRange in public API
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/range: 10/12] event: Use GcalRange in public API
- Date: Tue, 14 Apr 2020 14:30:58 +0000 (UTC)
commit 3051a12d3e63747bb7455685fa8ccaa82234491b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Apr 13 20:10:35 2020 -0300
event: Use GcalRange in public API
src/core/gcal-calendar-monitor.c | 51 +++++++++++++++++++---------------------
src/core/gcal-event.c | 7 ++++--
src/core/gcal-event.h | 3 +--
src/core/gcal-timeline.c | 16 ++++---------
4 files changed, 34 insertions(+), 43 deletions(-)
---
diff --git a/src/core/gcal-calendar-monitor.c b/src/core/gcal-calendar-monitor.c
index f45ad148..9381e67f 100644
--- a/src/core/gcal-calendar-monitor.c
+++ b/src/core/gcal-calendar-monitor.c
@@ -167,20 +167,16 @@ maybe_init_event_arrays (GcalCalendarMonitor *self)
}
}
-static void
-get_monitor_ranges (GcalCalendarMonitor *self,
- GDateTime **out_range_start,
- GDateTime **out_range_end)
+static GcalRange*
+get_monitor_ranges (GcalCalendarMonitor *self)
{
- g_mutex_lock (&self->shared.mutex);
-
- if (out_range_start)
- *out_range_start = g_date_time_ref (self->shared.range_start);
-
- if (out_range_end)
- *out_range_end = g_date_time_ref (self->shared.range_end);
+ g_autoptr (GcalRange) range = NULL;
+ g_mutex_lock (&self->shared.mutex);
+ range = gcal_range_new (self->shared.range_start, self->shared.range_end);
g_mutex_unlock (&self->shared.mutex);
+
+ return g_steal_pointer (&range);
}
static void
@@ -307,14 +303,13 @@ on_client_view_objects_added_cb (ECalClientView *view,
GcalCalendarMonitor *self)
{
g_autoptr (GPtrArray) components_to_expand = NULL;
- g_autoptr (GDateTime) range_start = NULL;
- g_autoptr (GDateTime) range_end = NULL;
+ g_autoptr (GcalRange) range = NULL;
const GSList *l;
gint i;
GCAL_ENTRY;
- get_monitor_ranges (self, &range_start, &range_end);
+ range = get_monitor_ranges (self);
maybe_init_event_arrays (self);
components_to_expand = g_ptr_array_new ();
@@ -360,7 +355,7 @@ on_client_view_objects_added_cb (ECalClientView *view,
continue;
}
- if (!gcal_event_is_within_range (event, range_start, range_end))
+ if (!gcal_event_is_within_range (event, range))
continue;
event_id = g_strdup (gcal_event_get_uid (event));
@@ -381,6 +376,8 @@ on_client_view_objects_added_cb (ECalClientView *view,
if (components_to_expand->len > 0)
{
g_autoptr (GPtrArray) expanded_events = NULL;
+ g_autoptr (GDateTime) range_start = NULL;
+ g_autoptr (GDateTime) range_end = NULL;
ECalClient *client;
time_t range_start_time;
time_t range_end_time;
@@ -389,8 +386,10 @@ on_client_view_objects_added_cb (ECalClientView *view,
client = gcal_calendar_get_client (self->calendar);
+ range_start = gcal_range_get_start (range);
+ range_end = gcal_range_get_end (range);
range_start_time = g_date_time_to_unix (range_start);
- range_end_time = g_date_time_to_unix (range_end);
+ range_end_time = g_date_time_to_unix (range_end) - 1;
expanded_events = g_ptr_array_new_with_free_func (g_object_unref);
@@ -425,15 +424,13 @@ on_client_view_objects_added_cb (ECalClientView *view,
#if GCAL_ENABLE_TRACE
{
- g_autofree gchar *range_start_str = g_date_time_format_iso8601 (range_start);
- g_autofree gchar *range_end_str = g_date_time_format_iso8601 (range_end);
+ g_autofree gchar *range_str = gcal_range_to_string (range);
- GCAL_TRACE_MSG ("Component %s (%s) added %d instance(s) between %s and %s",
+ GCAL_TRACE_MSG ("Component %s (%s) added %d instance(s) between %s",
i_cal_component_get_summary (icomponent),
i_cal_component_get_uid (icomponent),
expanded_events->len - old_size,
- range_start_str,
- range_end_str);
+ range_str);
}
#endif
}
@@ -447,7 +444,7 @@ on_client_view_objects_added_cb (ECalClientView *view,
if (g_cancellable_is_cancelled (self->cancellable))
return;
- if (!gcal_event_is_within_range (event, range_start, range_end))
+ if (!gcal_event_is_within_range (event, range))
continue;
event_id = g_strdup (gcal_event_get_uid (event));
@@ -473,8 +470,6 @@ on_client_view_objects_modified_cb (ECalClientView *view,
const GSList *objects,
GcalCalendarMonitor *self)
{
- g_autoptr (GDateTime) range_start = NULL;
- g_autoptr (GDateTime) range_end = NULL;
const GSList *l;
GCAL_ENTRY;
@@ -485,8 +480,6 @@ on_client_view_objects_modified_cb (ECalClientView *view,
return;
}
- get_monitor_ranges (self, &range_start, &range_end);
-
for (l = objects; l; l = l->next)
{
g_autoptr (GcalEvent) event = NULL;
@@ -834,15 +827,19 @@ remove_events_outside_range (GcalCalendarMonitor *self,
GDateTime *range_start,
GDateTime *range_end)
{
+ g_autoptr (GcalRange) range = NULL;
GHashTableIter iter;
GcalEvent *event;
GCAL_TRACE_MSG ("Removing events outside range from monitor");
+ if (range_start && range_end)
+ range = gcal_range_new (range_start, range_end);
+
g_hash_table_iter_init (&iter, self->events);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &event))
{
- if (range_start && range_end && gcal_event_is_within_range (event, range_start, range_end))
+ if (range && gcal_event_is_within_range (event, range))
continue;
g_object_ref (event);
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index 187cbb58..1ad4ed19 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -1873,12 +1873,15 @@ gcal_event_format_date (GcalEvent *self)
gboolean
gcal_event_is_within_range (GcalEvent *self,
- GDateTime *range_start,
- GDateTime *range_end)
+ GcalRange *range)
{
+ g_autoptr (GDateTime) range_start = NULL;
+ g_autoptr (GDateTime) range_end = NULL;
GDateTime *event_start;
GDateTime *event_end;
+ range_start = gcal_range_get_start (range);
+ range_end = gcal_range_get_end (range);
event_start = gcal_event_get_date_start (self);
event_end = gcal_event_get_date_end (self);
diff --git a/src/core/gcal-event.h b/src/core/gcal-event.h
index bd036d5e..1f4b4d4c 100644
--- a/src/core/gcal-event.h
+++ b/src/core/gcal-event.h
@@ -135,8 +135,7 @@ void gcal_event_get_original_timezones (GcalEvent
gchar* gcal_event_format_date (GcalEvent *self);
gboolean gcal_event_is_within_range (GcalEvent *self,
- GDateTime *range_start,
- GDateTime *range_end);
+ GcalRange *range);
G_END_DECLS
diff --git a/src/core/gcal-timeline.c b/src/core/gcal-timeline.c
index 6e10efc4..62e20b3c 100644
--- a/src/core/gcal-timeline.c
+++ b/src/core/gcal-timeline.c
@@ -195,15 +195,11 @@ static gboolean
subscriber_contains_event (GcalTimelineSubscriber *subscriber,
GcalEvent *event)
{
- g_autoptr (GDateTime) subscriber_range_start = NULL;
- g_autoptr (GDateTime) subscriber_range_end = NULL;
g_autoptr (GcalRange) subscriber_range = NULL;
subscriber_range = gcal_timeline_subscriber_get_range (subscriber);
- subscriber_range_start = gcal_range_get_start (subscriber_range);
- subscriber_range_end = gcal_range_get_end (subscriber_range);
- return gcal_event_is_within_range (event, subscriber_range_start, subscriber_range_end);
+ return gcal_event_is_within_range (event, subscriber_range);
}
static void
@@ -364,7 +360,7 @@ calculate_changed_events (GcalTimeline *self,
{
GcalEvent *event = g_ptr_array_index (events_to_remove, i);
- if (!gcal_event_is_within_range (event, old_range_start, old_range_end))
+ if (!gcal_event_is_within_range (event, old_range))
continue;
GCAL_TRACE_MSG ("Removing event from subscriber %s due to time range change (event: '%s' (%s))",
@@ -380,7 +376,7 @@ calculate_changed_events (GcalTimeline *self,
{
GcalEvent *event = g_ptr_array_index (events_to_add, i);
- if (!gcal_event_is_within_range (event, new_range_start, new_range_end))
+ if (!gcal_event_is_within_range (event, new_range))
continue;
GCAL_TRACE_MSG ("Queueing event addition for subscriber %s (event: '%s' (%s))",
@@ -397,8 +393,6 @@ add_cached_events_to_subscriber (GcalTimeline *self,
GcalTimelineSubscriber *subscriber)
{
g_autoptr (GcalRange) subscriber_range = NULL;
- g_autoptr (GDateTime) subscriber_start = NULL;
- g_autoptr (GDateTime) subscriber_end = NULL;
g_autoptr (GPtrArray) subscriber_array = NULL;
g_autoptr (GPtrArray) events_to_add = NULL;
gint i;
@@ -406,8 +400,6 @@ add_cached_events_to_subscriber (GcalTimeline *self,
GCAL_ENTRY;
subscriber_range = gcal_timeline_subscriber_get_range (subscriber);
- subscriber_start = gcal_range_get_start (subscriber_range);
- subscriber_end = gcal_range_get_end (subscriber_range);
events_to_add = gcal_range_tree_get_data_at_range (self->events, subscriber_range);
@@ -418,7 +410,7 @@ add_cached_events_to_subscriber (GcalTimeline *self,
{
GcalEvent *event = g_ptr_array_index (events_to_add, i);
- if (!gcal_event_is_within_range (event, subscriber_start, subscriber_end))
+ if (!gcal_event_is_within_range (event, subscriber_range))
continue;
GCAL_TRACE_MSG ("Queueing event addition for subscriber %s (event: '%s' (%s))",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]