event: Use GcalRange in public API
This commit is contained in:
@@ -167,20 +167,16 @@ maybe_init_event_arrays (GcalCalendarMonitor *self)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static GcalRange*
|
||||||
get_monitor_ranges (GcalCalendarMonitor *self,
|
get_monitor_ranges (GcalCalendarMonitor *self)
|
||||||
GDateTime **out_range_start,
|
|
||||||
GDateTime **out_range_end)
|
|
||||||
{
|
{
|
||||||
|
g_autoptr (GcalRange) range = NULL;
|
||||||
|
|
||||||
g_mutex_lock (&self->shared.mutex);
|
g_mutex_lock (&self->shared.mutex);
|
||||||
|
range = gcal_range_new (self->shared.range_start, self->shared.range_end, GCAL_RANGE_DEFAULT);
|
||||||
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_mutex_unlock (&self->shared.mutex);
|
g_mutex_unlock (&self->shared.mutex);
|
||||||
|
|
||||||
|
return g_steal_pointer (&range);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -307,14 +303,13 @@ on_client_view_objects_added_cb (ECalClientView *view,
|
|||||||
GcalCalendarMonitor *self)
|
GcalCalendarMonitor *self)
|
||||||
{
|
{
|
||||||
g_autoptr (GPtrArray) components_to_expand = NULL;
|
g_autoptr (GPtrArray) components_to_expand = NULL;
|
||||||
g_autoptr (GDateTime) range_start = NULL;
|
g_autoptr (GcalRange) range = NULL;
|
||||||
g_autoptr (GDateTime) range_end = NULL;
|
|
||||||
const GSList *l;
|
const GSList *l;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
get_monitor_ranges (self, &range_start, &range_end);
|
range = get_monitor_ranges (self);
|
||||||
|
|
||||||
maybe_init_event_arrays (self);
|
maybe_init_event_arrays (self);
|
||||||
components_to_expand = g_ptr_array_new ();
|
components_to_expand = g_ptr_array_new ();
|
||||||
@@ -360,7 +355,7 @@ on_client_view_objects_added_cb (ECalClientView *view,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gcal_event_is_within_range (event, range_start, range_end))
|
if (!gcal_event_is_within_range (event, range))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
event_id = g_strdup (gcal_event_get_uid (event));
|
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)
|
if (components_to_expand->len > 0)
|
||||||
{
|
{
|
||||||
g_autoptr (GPtrArray) expanded_events = NULL;
|
g_autoptr (GPtrArray) expanded_events = NULL;
|
||||||
|
g_autoptr (GDateTime) range_start = NULL;
|
||||||
|
g_autoptr (GDateTime) range_end = NULL;
|
||||||
ECalClient *client;
|
ECalClient *client;
|
||||||
time_t range_start_time;
|
time_t range_start_time;
|
||||||
time_t range_end_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);
|
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_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);
|
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
|
#if GCAL_ENABLE_TRACE
|
||||||
{
|
{
|
||||||
g_autofree gchar *range_start_str = g_date_time_format_iso8601 (range_start);
|
g_autofree gchar *range_str = gcal_range_to_string (range);
|
||||||
g_autofree gchar *range_end_str = g_date_time_format_iso8601 (range_end);
|
|
||||||
|
|
||||||
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_summary (icomponent),
|
||||||
i_cal_component_get_uid (icomponent),
|
i_cal_component_get_uid (icomponent),
|
||||||
expanded_events->len - old_size,
|
expanded_events->len - old_size,
|
||||||
range_start_str,
|
range_str);
|
||||||
range_end_str);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -447,7 +444,7 @@ on_client_view_objects_added_cb (ECalClientView *view,
|
|||||||
if (g_cancellable_is_cancelled (self->cancellable))
|
if (g_cancellable_is_cancelled (self->cancellable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!gcal_event_is_within_range (event, range_start, range_end))
|
if (!gcal_event_is_within_range (event, range))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
event_id = g_strdup (gcal_event_get_uid (event));
|
event_id = g_strdup (gcal_event_get_uid (event));
|
||||||
@@ -473,8 +470,6 @@ on_client_view_objects_modified_cb (ECalClientView *view,
|
|||||||
const GSList *objects,
|
const GSList *objects,
|
||||||
GcalCalendarMonitor *self)
|
GcalCalendarMonitor *self)
|
||||||
{
|
{
|
||||||
g_autoptr (GDateTime) range_start = NULL;
|
|
||||||
g_autoptr (GDateTime) range_end = NULL;
|
|
||||||
const GSList *l;
|
const GSList *l;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
@@ -485,8 +480,6 @@ on_client_view_objects_modified_cb (ECalClientView *view,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_monitor_ranges (self, &range_start, &range_end);
|
|
||||||
|
|
||||||
for (l = objects; l; l = l->next)
|
for (l = objects; l; l = l->next)
|
||||||
{
|
{
|
||||||
g_autoptr (GcalEvent) event = NULL;
|
g_autoptr (GcalEvent) event = NULL;
|
||||||
@@ -834,15 +827,19 @@ remove_events_outside_range (GcalCalendarMonitor *self,
|
|||||||
GDateTime *range_start,
|
GDateTime *range_start,
|
||||||
GDateTime *range_end)
|
GDateTime *range_end)
|
||||||
{
|
{
|
||||||
|
g_autoptr (GcalRange) range = NULL;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
GcalEvent *event;
|
GcalEvent *event;
|
||||||
|
|
||||||
GCAL_TRACE_MSG ("Removing events outside range from monitor");
|
GCAL_TRACE_MSG ("Removing events outside range from monitor");
|
||||||
|
|
||||||
|
if (range_start && range_end)
|
||||||
|
range = gcal_range_new (range_start, range_end, GCAL_RANGE_DEFAULT);
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, self->events);
|
g_hash_table_iter_init (&iter, self->events);
|
||||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &event))
|
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;
|
continue;
|
||||||
|
|
||||||
g_object_ref (event);
|
g_object_ref (event);
|
||||||
|
|||||||
+6
-14
@@ -1879,21 +1879,13 @@ gcal_event_format_date (GcalEvent *self)
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gcal_event_is_within_range (GcalEvent *self,
|
gcal_event_is_within_range (GcalEvent *self,
|
||||||
GDateTime *range_start,
|
GcalRange *range)
|
||||||
GDateTime *range_end)
|
|
||||||
{
|
{
|
||||||
GDateTime *event_start;
|
GcalRange *event_range;
|
||||||
GDateTime *event_end;
|
|
||||||
|
|
||||||
event_start = gcal_event_get_date_start (self);
|
g_return_val_if_fail (GCAL_IS_EVENT (self), FALSE);
|
||||||
event_end = gcal_event_get_date_end (self);
|
g_return_val_if_fail (range != NULL, FALSE);
|
||||||
|
|
||||||
if (gcal_event_get_all_day (self))
|
event_range = gcal_event_get_range (self);
|
||||||
{
|
return gcal_range_calculate_overlap (event_range, range, NULL) != GCAL_RANGE_NO_OVERLAP;
|
||||||
return gcal_date_time_compare_date (range_end, event_start) > 0 &&
|
|
||||||
gcal_date_time_compare_date (event_end, range_start) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_date_time_compare (range_end, event_start) > 0 &&
|
|
||||||
g_date_time_compare (event_end, range_start) > 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,7 @@ void gcal_event_get_original_timezones (GcalEvent
|
|||||||
gchar* gcal_event_format_date (GcalEvent *self);
|
gchar* gcal_event_format_date (GcalEvent *self);
|
||||||
|
|
||||||
gboolean gcal_event_is_within_range (GcalEvent *self,
|
gboolean gcal_event_is_within_range (GcalEvent *self,
|
||||||
GDateTime *range_start,
|
GcalRange *range);
|
||||||
GDateTime *range_end);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
@@ -195,15 +195,11 @@ static gboolean
|
|||||||
subscriber_contains_event (GcalTimelineSubscriber *subscriber,
|
subscriber_contains_event (GcalTimelineSubscriber *subscriber,
|
||||||
GcalEvent *event)
|
GcalEvent *event)
|
||||||
{
|
{
|
||||||
g_autoptr (GDateTime) subscriber_range_start = NULL;
|
|
||||||
g_autoptr (GDateTime) subscriber_range_end = NULL;
|
|
||||||
g_autoptr (GcalRange) subscriber_range = NULL;
|
g_autoptr (GcalRange) subscriber_range = NULL;
|
||||||
|
|
||||||
subscriber_range = gcal_timeline_subscriber_get_range (subscriber);
|
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
|
static void
|
||||||
@@ -364,7 +360,7 @@ calculate_changed_events (GcalTimeline *self,
|
|||||||
{
|
{
|
||||||
GcalEvent *event = g_ptr_array_index (events_to_remove, i);
|
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;
|
continue;
|
||||||
|
|
||||||
GCAL_TRACE_MSG ("Removing event from subscriber %s due to time range change (event: '%s' (%s))",
|
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);
|
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;
|
continue;
|
||||||
|
|
||||||
GCAL_TRACE_MSG ("Queueing event addition for subscriber %s (event: '%s' (%s))",
|
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)
|
GcalTimelineSubscriber *subscriber)
|
||||||
{
|
{
|
||||||
g_autoptr (GcalRange) subscriber_range = NULL;
|
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) subscriber_array = NULL;
|
||||||
g_autoptr (GPtrArray) events_to_add = NULL;
|
g_autoptr (GPtrArray) events_to_add = NULL;
|
||||||
gint i;
|
gint i;
|
||||||
@@ -406,8 +400,6 @@ add_cached_events_to_subscriber (GcalTimeline *self,
|
|||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
subscriber_range = gcal_timeline_subscriber_get_range (subscriber);
|
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);
|
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);
|
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;
|
continue;
|
||||||
|
|
||||||
GCAL_TRACE_MSG ("Queueing event addition for subscriber %s (event: '%s' (%s))",
|
GCAL_TRACE_MSG ("Queueing event addition for subscriber %s (event: '%s' (%s))",
|
||||||
|
|||||||
Reference in New Issue
Block a user